1#ifndef YAZE_APP_GFX_BITMAP_H
2#define YAZE_APP_GFX_BITMAP_H
8#include <unordered_map>
24 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1);
27 SDL_PIXELTYPE_INDEX8, 0,
31 SDL_PIXELTYPE_INDEX8, 0,
124 const std::vector<uint8_t> &
data);
130 const std::vector<uint8_t> &
data);
Represents a bitmap image optimized for SNES ROM hacking.
const uint8_t * data() const
void set_texture(TextureHandle texture)
const SnesPalette & palette() const
Bitmap & operator=(const Bitmap &other)
Copy assignment operator.
void WriteToPixel(int position, uint8_t value)
Write a value to a pixel at the given position.
void Create(int width, int height, int depth, std::span< uint8_t > data)
Create a bitmap with the given dimensions and data.
TextureHandle texture() const
~Bitmap()=default
Destructor.
bool ValidateDataSurfaceSync()
Validate that bitmap data and surface pixels are synchronized.
const std::vector< uint8_t > & vector() const
std::unordered_map< uint32_t, uint8_t > color_to_index_cache_
void Reformat(int format)
Reformat the bitmap to use a different pixel format.
static uint32_t HashColor(const ImVec4 &color)
Hash a color for cache lookup.
void Get8x8Tile(int tile_index, int x, int y, std::vector< uint8_t > &tile_data, int &tile_data_offset)
Extract an 8x8 tile from the bitmap (SNES standard tile size)
void CreateTexture()
Creates the underlying SDL_Texture to be displayed.
SnesPalette * mutable_palette()
void QueueTextureUpdate(IRenderer *renderer)
Queue texture update for batch processing (improved performance)
void set_modified(bool modified)
void set_active(bool active)
void WriteColor(int position, const ImVec4 &color)
Write a color to a pixel at the given position.
void set_data(const std::vector< uint8_t > &data)
void Resize(int new_width, int new_height)
Resize the bitmap to new dimensions (preserves existing data)
void SetPixel(int x, int y, const SnesColor &color)
Set a pixel at the given x,y coordinates with SNES color.
void SetPalette(const SnesPalette &palette)
Set the palette for the bitmap.
void ApplyStoredPalette()
Apply the stored palette to the surface (internal helper)
std::vector< uint8_t > data_
void InvalidatePaletteCache()
Invalidate the palette lookup cache (call when palette changes)
void SetPaletteWithTransparent(const SnesPalette &palette, size_t index, int length=7)
Set the palette with a transparent color.
std::vector< uint8_t > & mutable_data()
struct yaze::gfx::Bitmap::DirtyRegion dirty_region_
SDL_Surface * surface() const
void Get16x16Tile(int tile_x, int tile_y, std::vector< uint8_t > &tile_data, int &tile_data_offset)
Extract a 16x16 tile from the bitmap (SNES metatile size)
uint8_t FindColorIndex(const SnesColor &color)
Find color index in palette using optimized hash map lookup.
void UpdateTexture()
Updates the underlying SDL_Texture when it already exists.
gfx::SnesPalette palette_
void UpdateTextureData()
Updates the texture data from the surface.
Defines an abstract interface for all rendering operations.
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
constexpr Uint32 SNES_PIXELFORMAT_8BPP
constexpr Uint32 SNES_PIXELFORMAT_INDEXED
void * TextureHandle
An abstract handle representing a texture.
constexpr Uint32 SNES_PIXELFORMAT_4BPP
Uint32 GetSnesPixelFormat(int format)
Convert bitmap format enum to SDL pixel format.
std::unordered_map< int, gfx::Bitmap > BitmapTable
Main namespace for the application.
void AddPoint(int x, int y)