1#ifndef YAZE_APP_GFX_BITMAP_H
2#define YAZE_APP_GFX_BITMAP_H
9#include <unordered_map>
25 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1);
28 SDL_PIXELTYPE_INDEX8, 0,
32 SDL_PIXELTYPE_INDEX8, 0,
127 const std::vector<uint8_t>&
data);
133 const std::vector<uint8_t>&
data);
211 int sub_palette_index = 0);
335 void Get8x8Tile(
int tile_index,
int x,
int y, std::vector<uint8_t>& tile_data,
497using BitmapTable = std::unordered_map<int, std::unique_ptr<gfx::Bitmap>>;
Represents a bitmap image optimized for SNES ROM hacking.
const uint8_t * data() const
void set_texture(TextureHandle texture)
const SnesPalette & palette() const
SDL_Surface * surface_
SDL surface for rendering (contains the authoritative palette)
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
void UpdateSurfacePixels()
Update SDL surface with current pixel data from data_ vector Call this after modifying pixel data via...
std::unordered_map< uint32_t, uint8_t > color_to_index_cache_
void Reformat(int format)
Reformat the bitmap to use a different pixel format.
void WriteToPixel(int x, int y, uint8_t value)
Write a palette index to a pixel at the given x,y coordinates.
const BitmapMetadata & metadata() const
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)
BitmapMetadata & metadata()
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)
static uint32_t next_generation_
void Fill(uint8_t value)
Fill the bitmap with a specific value.
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 using SNES palette format.
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)
uint32_t generation() const
uint8_t GetPixel(int x, int y) const
Get the palette index at the given x,y coordinates.
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_
void ApplyPaletteByMetadata(const SnesPalette &palette, int sub_palette_index=0)
Apply palette using metadata-driven strategy Chooses between SetPalette and SetPaletteWithTransparent...
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_
Internal SNES palette storage (may be empty!)
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).
std::unordered_map< int, std::unique_ptr< gfx::Bitmap > > BitmapTable
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.
SDL2/SDL3 compatibility layer.
void AddPoint(int x, int y)