yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::gfx::Bitmap Class Reference

Represents a bitmap image optimized for SNES ROM hacking. More...

#include <bitmap.h>

Collaboration diagram for yaze::gfx::Bitmap:

Classes

struct  BitmapMetadata
 Metadata for tracking bitmap source format and palette requirements. More...
 
struct  DirtyRegion
 

Public Member Functions

 Bitmap ()=default
 
 Bitmap (int width, int height, int depth, const std::vector< uint8_t > &data)
 Create a bitmap with the given dimensions and raw pixel data.
 
 Bitmap (int width, int height, int depth, const std::vector< uint8_t > &data, const SnesPalette &palette)
 Create a bitmap with the given dimensions, data, and SNES palette.
 
 Bitmap (const Bitmap &other)
 Copy constructor - creates a deep copy.
 
Bitmapoperator= (const Bitmap &other)
 Copy assignment operator.
 
 Bitmap (Bitmap &&other) noexcept
 Move constructor.
 
Bitmapoperator= (Bitmap &&other) noexcept
 Move assignment operator.
 
 ~Bitmap ()=default
 Destructor.
 
void Create (int width, int height, int depth, std::span< uint8_t > data)
 Create a bitmap with the given dimensions and data.
 
void Create (int width, int height, int depth, const std::vector< uint8_t > &data)
 Create a bitmap with the given dimensions and data.
 
void Create (int width, int height, int depth, int format, const std::vector< uint8_t > &data)
 Create a bitmap with the given dimensions, format, and data.
 
void Reformat (int format)
 Reformat the bitmap to use a different pixel format.
 
void Fill (uint8_t value)
 Fill the bitmap with a specific value.
 
void CreateTexture ()
 Creates the underlying SDL_Texture to be displayed.
 
void UpdateTexture ()
 Updates the underlying SDL_Texture when it already exists.
 
void QueueTextureUpdate (IRenderer *renderer)
 Queue texture update for batch processing (improved performance)
 
void UpdateTextureData ()
 Updates the texture data from the surface.
 
void SetPalette (const SnesPalette &palette)
 Set the palette for the bitmap using SNES palette format.
 
void SetPaletteWithTransparent (const SnesPalette &palette, size_t index, int length=7)
 Set the palette with a transparent color.
 
void ApplyPaletteByMetadata (const SnesPalette &palette, int sub_palette_index=0)
 Apply palette using metadata-driven strategy Chooses between SetPalette and SetPaletteWithTransparent based on metadata.
 
void ApplyStoredPalette ()
 Apply the stored palette to the surface (internal helper)
 
void UpdateSurfacePixels ()
 Update SDL surface with current pixel data from data_ vector Call this after modifying pixel data via mutable_data()
 
void SetPalette (const std::vector< SDL_Color > &palette)
 Set the palette using SDL colors (direct surface palette access)
 
void WriteToPixel (int position, uint8_t value)
 Write a value to a pixel at the given position.
 
void WriteToPixel (int x, int y, uint8_t value)
 Write a palette index to a pixel at the given x,y coordinates.
 
uint8_t GetPixel (int x, int y) const
 Get the palette index at the given x,y coordinates.
 
void WriteColor (int position, const ImVec4 &color)
 Write a color to a pixel at the given position.
 
void SetPixel (int x, int y, const SnesColor &color)
 Set a pixel at the given x,y coordinates with SNES color.
 
void Resize (int new_width, int new_height)
 Resize the bitmap to new dimensions (preserves existing data)
 
void InvalidatePaletteCache ()
 Invalidate the palette lookup cache (call when palette changes)
 
uint8_t FindColorIndex (const SnesColor &color)
 Find color index in palette using optimized hash map lookup.
 
bool ValidateDataSurfaceSync ()
 Validate that bitmap data and surface pixels are synchronized.
 
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 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)
 
const SnesPalettepalette () const
 
SnesPalettemutable_palette ()
 
BitmapMetadatametadata ()
 
const BitmapMetadatametadata () const
 
int width () const
 
int height () const
 
int depth () const
 
auto size () const
 
const uint8_tdata () const
 
std::vector< uint8_t > & mutable_data ()
 
SDL_Surfacesurface () const
 
TextureHandle texture () const
 
const std::vector< uint8_t > & vector () const
 
uint8_t at (int i) const
 
bool modified () const
 
bool is_active () const
 
uint32_t generation () const
 
void set_active (bool active)
 
void set_data (const std::vector< uint8_t > &data)
 
void set_modified (bool modified)
 
void set_texture (TextureHandle texture)
 

Static Private Member Functions

static uint32_t HashColor (const ImVec4 &color)
 Hash a color for cache lookup.
 

Private Attributes

int width_ = 0
 
int height_ = 0
 
int depth_ = 0
 
bool active_ = false
 
bool modified_ = false
 
uint32_t generation_ = 0
 
voidtexture_pixels = nullptr
 
uint8_tpixel_data_ = nullptr
 
gfx::SnesPalette palette_
 Internal SNES palette storage (may be empty!)
 
BitmapMetadata metadata_
 
std::vector< uint8_tdata_
 
SDL_Surfacesurface_ = nullptr
 SDL surface for rendering (contains the authoritative palette)
 
TextureHandle texture_ = nullptr
 
std::unordered_map< uint32_t, uint8_tcolor_to_index_cache_
 
struct yaze::gfx::Bitmap::DirtyRegion dirty_region_
 

Static Private Attributes

static uint32_t next_generation_ = 1
 

Detailed Description

Represents a bitmap image optimized for SNES ROM hacking.

The Bitmap class provides functionality to create, manipulate, and display bitmap images specifically designed for Link to the Past ROM editing. It supports:

Key Features:

  • SNES-specific pixel formats (4BPP, 8BPP, indexed)
  • Palette management with transparent color support
  • Tile extraction (8x8, 16x16) for ROM tile editing
  • Memory-efficient surface/texture management via Arena
  • Real-time editing with immediate visual feedback

Performance Optimizations:

  • Lazy texture creation (textures only created when needed)
  • Modified flag tracking to avoid unnecessary updates
  • Arena-based resource pooling to reduce allocation overhead
  • Direct pixel data manipulation for fast editing operations

ROM Hacking Specific:

  • SNES color format conversion (15-bit RGB to 8-bit indexed)
  • Tile-based editing for 8x8 and 16x16 SNES tiles
  • Palette index management for ROM palette editing
  • Support for multiple graphics sheets (223 total in YAZE)

Definition at line 67 of file bitmap.h.

Constructor & Destructor Documentation

◆ Bitmap() [1/5]

yaze::gfx::Bitmap::Bitmap ( )
default

◆ Bitmap() [2/5]

yaze::gfx::Bitmap::Bitmap ( int width,
int height,
int depth,
const std::vector< uint8_t > & data )

Create a bitmap with the given dimensions and raw pixel data.

Parameters
widthWidth in pixels (typically 128, 256, or 512 for SNES tilesheets)
heightHeight in pixels (typically 32, 64, or 128 for SNES tilesheets)
depthColor depth in bits per pixel (4, 8, or 16 for SNES)
dataRaw pixel data (indexed color values for SNES graphics)

Definition at line 46 of file bitmap.cc.

References Create(), data(), depth(), height(), and width().

◆ Bitmap() [3/5]

yaze::gfx::Bitmap::Bitmap ( int width,
int height,
int depth,
const std::vector< uint8_t > & data,
const SnesPalette & palette )

Create a bitmap with the given dimensions, data, and SNES palette.

Parameters
widthWidth in pixels
heightHeight in pixels
depthColor depth in bits per pixel
dataRaw pixel data (indexed color values)
paletteSNES palette for color mapping (15-bit RGB format)

Definition at line 52 of file bitmap.cc.

References Create(), data(), depth(), height(), palette(), SetPalette(), and width().

◆ Bitmap() [4/5]

◆ Bitmap() [5/5]

yaze::gfx::Bitmap::Bitmap ( Bitmap && other)
noexcept

Move constructor.

Definition at line 133 of file bitmap.cc.

◆ ~Bitmap()

yaze::gfx::Bitmap::~Bitmap ( )
default

Destructor.

Member Function Documentation

◆ operator=() [1/2]

◆ operator=() [2/2]

Bitmap & yaze::gfx::Bitmap::operator= ( Bitmap && other)
noexcept

Move assignment operator.

Definition at line 159 of file bitmap.cc.

References yaze::gfx::Arena::FreeSurface(), and yaze::gfx::Arena::Get().

Here is the call graph for this function:

◆ Create() [1/3]

void yaze::gfx::Bitmap::Create ( int width,
int height,
int depth,
std::span< uint8_t > data )

Create a bitmap with the given dimensions and data.

Definition at line 199 of file bitmap.cc.

References Create(), data(), data_, depth(), height(), and width().

Referenced by Bitmap(), Bitmap(), yaze::zelda3::Inventory::BuildTileset(), yaze::zelda3::RoomLayerManager::CompositeToOutput(), yaze::editor::Tile16Editor::CopyTile16ToClipboard(), Create(), Create(), yaze::zelda3::OverworldMapScreen::Create(), yaze::zelda3::Inventory::Create(), yaze::zelda3::TitleScreen::Create(), yaze::editor::GraphicsEditor::DecompressImportData(), yaze::gfx::BackgroundBuffer::DrawBackground(), yaze::editor::GraphicsEditor::DrawCgxImport(), yaze::gfx::BackgroundBuffer::DrawFloor(), yaze::editor::MessageEditor::DrawMessagePreview(), yaze::editor::OverworldEditor::DrawScratchSpace(), yaze::editor::GraphicsEditor::DrawScrImport(), yaze::gfx::BackgroundBuffer::EnsureBitmapInitialized(), yaze::editor::Tile16Editor::FlipTile16Horizontal(), yaze::editor::Tile16Editor::FlipTile16Vertical(), yaze::editor::MessageEditor::Initialize(), yaze::editor::Tile16Editor::Initialize(), yaze::editor::ScreenEditor::Load(), yaze::zelda3::LoadDungeonMapTile16(), yaze::LoadFontGraphics(), yaze::zelda3::LoadFontGraphics(), yaze::editor::OverworldEditor::LoadGraphics(), yaze::editor::Tile16Editor::LoadTile16FromScratchSpace(), yaze::editor::Tile16Editor::PasteTile16FromClipboard(), yaze::editor::Tile16Editor::PreviewPaletteChange(), yaze::editor::Tile16Editor::RegenerateTile16BitmapFromROM(), yaze::editor::SpriteEditor::RenderVanillaSprite(), yaze::editor::SpriteEditor::RenderZSpriteFrame(), yaze::editor::Tile16Editor::RotateTile16(), yaze::test::RomDependentTestSuite::RunTile16EditorTest(), yaze::editor::OverworldEditor::SaveCurrentSelectionToScratch(), yaze::editor::Tile16Editor::SaveUndoState(), yaze::editor::Tile16Editor::SetCurrentTile(), yaze::gui::DungeonObjectEmulatorPreview::TriggerStaticRender(), yaze::editor::Tile16Editor::Undo(), yaze::editor::Tile16Editor::UpdateLivePreview(), and yaze::editor::Tile16Editor::UpdateTile16Edit().

◆ Create() [2/3]

void yaze::gfx::Bitmap::Create ( int width,
int height,
int depth,
const std::vector< uint8_t > & data )

Create a bitmap with the given dimensions and data.

Definition at line 204 of file bitmap.cc.

References Create(), data(), depth(), height(), yaze::gfx::kIndexed, and width().

◆ Create() [3/3]

void yaze::gfx::Bitmap::Create ( int width,
int height,
int depth,
int format,
const std::vector< uint8_t > & data )

Create a bitmap with the given dimensions, format, and data.

Create a bitmap with specified format and data.

Parameters
widthWidth in pixels
heightHeight in pixels
depthColor depth in bits per pixel
formatPixel format (0=indexed, 1=4BPP, 2=8BPP)
dataRaw pixel data

Performance Notes:

  • Uses Arena for efficient surface allocation
  • Copies data to avoid external pointer dependencies
  • Validates data size against surface dimensions
  • Sets active flag for rendering pipeline

Definition at line 223 of file bitmap.cc.

References active_, yaze::gfx::Arena::AllocateSurface(), ApplyStoredPalette(), data(), data_, depth(), depth_, yaze::gfx::SnesPalette::empty(), yaze::platform::EnsureSurfacePalette256(), generation_, yaze::gfx::Arena::Get(), yaze::gfx::GetSnesPixelFormat(), height(), height_, yaze::gfx::kIndexed, next_generation_, palette_, pixel_data_, surface_, vector(), width(), and width_.

◆ Reformat()

◆ Fill()

void yaze::gfx::Bitmap::Fill ( uint8_t value)
inline

Fill the bitmap with a specific value.

Definition at line 143 of file bitmap.h.

References data_, and modified_.

Referenced by yaze::zelda3::RoomLayerManager::CompositeToOutput().

◆ CreateTexture()

void yaze::gfx::Bitmap::CreateTexture ( )

Creates the underlying SDL_Texture to be displayed.

Definition at line 291 of file bitmap.cc.

References yaze::gfx::Arena::CREATE, yaze::gfx::Arena::Get(), and yaze::gfx::Arena::QueueTextureCommand().

Referenced by yaze::gfx::AtlasRenderer::AddBitmapWithBppOptimization(), and yaze::gfx::RenderTilesBatch().

Here is the call graph for this function:

◆ UpdateTexture()

void yaze::gfx::Bitmap::UpdateTexture ( )

Updates the underlying SDL_Texture when it already exists.

Definition at line 295 of file bitmap.cc.

References yaze::gfx::Arena::Get(), yaze::gfx::Arena::QueueTextureCommand(), and yaze::gfx::Arena::UPDATE.

Referenced by yaze::gui::Canvas::ConvertBitmapFormat(), and yaze::gui::Canvas::UpdateColorPainter().

Here is the call graph for this function:

◆ QueueTextureUpdate()

void yaze::gfx::Bitmap::QueueTextureUpdate ( IRenderer * renderer)

Queue texture update for batch processing (improved performance)

Parameters
rendererSDL renderer for texture operations
Note
Use this for better performance when multiple textures need updating

◆ UpdateTextureData()

void yaze::gfx::Bitmap::UpdateTextureData ( )

Updates the texture data from the surface.

◆ SetPalette() [1/2]

void yaze::gfx::Bitmap::SetPalette ( const SnesPalette & palette)

Set the palette for the bitmap using SNES palette format.

This method stores the palette in the internal palette_ member AND applies it to the SDL surface via ApplyStoredPalette().

Note
IMPORTANT: There are two palette storage mechanisms in Bitmap:
  1. **Internal SnesPalette (palette_ member)**: Stores the SNES color format for serialization and palette editing. Accessible via palette().
  2. **SDL Surface Palette (surface_->format->palette)**: Used by SDL for actual rendering. When converting indexed pixels to RGBA for textures, SDL uses THIS palette, not the internal one.

Both are updated when calling SetPalette(SnesPalette). However, some code paths (like dungeon room rendering) use SetPalette(vector<SDL_Color>) which ONLY sets the SDL surface palette, leaving the internal palette_ empty.

When compositing bitmaps or copying palettes between bitmaps, you may need to extract the palette from the SDL surface directly rather than using palette() which may be empty. See RoomLayerManager::CompositeToOutput() for an example of proper palette extraction from SDL surfaces.

Parameters
paletteSNES palette to apply (15-bit RGB format)
See also
SetPalette(const std::vector<SDL_Color>&) for direct SDL palette access

Definition at line 382 of file bitmap.cc.

References ApplyStoredPalette(), modified_, palette(), and palette_.

Referenced by ApplyPaletteByMetadata(), yaze::gui::CanvasUtils::ApplyPaletteGroup(), yaze::gui::PaletteEditorWidget::ApplyROMPalette(), yaze::zelda3::anonymous_namespace{room_layer_manager.cc}::ApplySDLPaletteToBitmap(), Bitmap(), yaze::zelda3::Inventory::BuildTileset(), yaze::zelda3::TitleScreen::BuildTileset(), yaze::editor::Tile16Editor::CopyTile16ToClipboard(), yaze::zelda3::OverworldMapScreen::Create(), yaze::zelda3::Inventory::Create(), yaze::gfx::CreateTilemap(), yaze::editor::GraphicsEditor::DecompressImportData(), yaze::editor::GraphicsEditor::DrawCgxImport(), yaze::editor::ScreenEditor::DrawDungeonMapScreen(), yaze::editor::ScreenEditor::DrawDungeonMapsRoomGfx(), yaze::editor::MessageEditor::DrawMessagePreview(), yaze::editor::OverworldEditor::DrawScratchSpace(), yaze::editor::GraphicsEditor::DrawScrImport(), yaze::gfx::BackgroundBuffer::EnsureBitmapInitialized(), yaze::editor::MessageEditor::Initialize(), yaze::editor::Tile16Editor::Initialize(), yaze::editor::ScreenEditor::Load(), yaze::zelda3::LoadDungeonMapTile16(), yaze::editor::OverworldEditor::LoadGraphics(), yaze::editor::Tile16Editor::LoadTile16FromScratchSpace(), yaze::zelda3::TitleScreen::LoadTitleScreen(), yaze::editor::Tile16Editor::PasteTile16FromClipboard(), Reformat(), yaze::editor::Tile16Editor::RefreshAllPalettes(), yaze::editor::OverworldEditor::RefreshMapPalette(), yaze::editor::OverworldEditor::RefreshTile16Blockset(), yaze::zelda3::Room::RenderRoomGraphics(), yaze::editor::SpriteEditor::RenderVanillaSprite(), yaze::editor::SpriteEditor::RenderZSpriteFrame(), yaze::test::RomDependentTestSuite::RunTile16EditorTest(), yaze::editor::OverworldEditor::SaveCurrentSelectionToScratch(), yaze::editor::Tile16Editor::SaveUndoState(), and yaze::editor::Tile16Editor::Undo().

Here is the call graph for this function:

◆ SetPaletteWithTransparent()

void yaze::gfx::Bitmap::SetPaletteWithTransparent ( const SnesPalette & palette,
size_t index,
int length = 7 )

Set the palette with a transparent color.

Apply a sub-palette with automatic transparency for SNES rendering.

This method extracts a sub-palette from a larger palette and applies it to the SDL surface with proper SNES transparency handling.

SNES Transparency Model:

  • The SNES hardware automatically treats palette index 0 as transparent
  • This is a hardware feature, not stored in ROM data
  • This method creates a transparent color 0 for proper SNES emulation

Usage:

  • Extract 8-color sub-palette from position 'index' in source palette
  • Color 0: Always set to transparent black (0,0,0,0)
  • Colors 1-7: Taken from palette[index] through palette[index+6]
  • If palette has fewer than 7 colors, fills with opaque black

Example: palette has colors [c0, c1, c2, c3, c4, c5, c6, c7, c8, ...] SetPaletteWithTransparent(palette, 0, 7) creates: [transparent_black, c0, c1, c2, c3, c4, c5, c6]

IMPORTANT: Source palette data is NOT modified

  • The full palette is stored in palette_ member for reference
  • Only the SDL surface palette is updated with the 8-color subset
  • This allows proper palette editing while maintaining SNES rendering
Parameters
paletteSource palette (can be 7, 8, 64, 128, or 256 colors)
indexStart index in source palette (0-based)
lengthNumber of colors to extract (default 7, max 7)

Definition at line 454 of file bitmap.cc.

References yaze::platform::GetSurfacePalette(), InvalidatePaletteCache(), palette(), palette_, yaze::gfx::SnesPalette::size(), surface_, and vector().

Referenced by ApplyPaletteByMetadata(), yaze::gui::CanvasUtils::ApplyPaletteGroup(), yaze::editor::Tile16Editor::ApplyPaletteToCurrentTile16Bitmap(), yaze::gui::PaletteEditorWidget::ApplyROMPalette(), yaze::editor::Tile16Editor::PreviewPaletteChange(), yaze::editor::Tile16Editor::RefreshAllPalettes(), yaze::editor::Tile16Editor::SetCurrentTile(), yaze::editor::Tile16Editor::UpdateLivePreview(), and yaze::editor::Tile16Editor::UpdateTile16Edit().

◆ ApplyPaletteByMetadata()

void yaze::gfx::Bitmap::ApplyPaletteByMetadata ( const SnesPalette & palette,
int sub_palette_index = 0 )

Apply palette using metadata-driven strategy Chooses between SetPalette and SetPaletteWithTransparent based on metadata.

Apply palette using metadata-driven strategy.

Uses bitmap metadata to determine the appropriate palette application method:

  • palette_format == 0: Full palette (SetPalette)
  • palette_format == 1: Sub-palette with transparent color 0 (SetPaletteWithTransparent)

This ensures correct rendering for different bitmap types:

  • 3BPP graphics sheets → sub-palette with transparent
  • 4BPP full palettes → full palette
  • Mode 7 graphics → full palette
Parameters
paletteSource palette to apply
sub_palette_indexIndex within palette for sub-palette extraction (default 0)

Definition at line 410 of file bitmap.cc.

References metadata_, palette(), yaze::gfx::Bitmap::BitmapMetadata::palette_format, SetPalette(), and SetPaletteWithTransparent().

Here is the call graph for this function:

◆ ApplyStoredPalette()

void yaze::gfx::Bitmap::ApplyStoredPalette ( )

Apply the stored palette to the surface (internal helper)

Apply the stored palette to the SDL surface.

This method applies the palette_ member to the SDL surface's palette.

IMPORTANT: Transparency handling

  • ROM palette data does NOT have transparency flags set
  • Transparency is only applied if explicitly marked (via set_transparent)
  • For SNES rendering, use SetPaletteWithTransparent which creates transparent color 0 automatically
  • This method preserves the transparency state of each color

Color format notes:

  • SnesColor.rgb() returns 0-255 values stored in ImVec4 (unconventional!)
  • We cast these directly to Uint8 for SDL

Definition at line 315 of file bitmap.cc.

References yaze::gfx::SnesPalette::empty(), yaze::platform::GetSurfacePalette(), InvalidatePaletteCache(), palette_, yaze::gfx::SnesPalette::size(), surface_, and vector().

Referenced by Bitmap(), Create(), operator=(), and SetPalette().

◆ UpdateSurfacePixels()

void yaze::gfx::Bitmap::UpdateSurfacePixels ( )

Update SDL surface with current pixel data from data_ vector Call this after modifying pixel data via mutable_data()

Definition at line 367 of file bitmap.cc.

References data_, surface_, and vector().

Referenced by yaze::zelda3::RoomLayerManager::CompositeToOutput(), yaze::zelda3::TitleScreen::RenderBG1Layer(), yaze::zelda3::TitleScreen::RenderBG2Layer(), yaze::zelda3::TitleScreen::RenderCompositeLayer(), yaze::zelda3::OverworldMapScreen::RenderMapLayer(), and yaze::editor::Tile16Editor::UpdateTile16Edit().

Here is the call graph for this function:

◆ SetPalette() [2/2]

void yaze::gfx::Bitmap::SetPalette ( const std::vector< SDL_Color > & palette)

Set the palette using SDL colors (direct surface palette access)

This method ONLY sets the SDL surface palette for rendering. It does NOT update the internal palette_ member (SnesPalette).

Use this method when:

  • You have pre-converted colors in SDL_Color format
  • You're copying a palette from another SDL surface
  • Performance is critical (avoids SNES→SDL color conversion)
  • You don't need to preserve the palette for serialization
Warning
After calling this method, palette() will return an empty or stale SnesPalette. If you need to copy the palette to another bitmap, extract it from the SDL surface directly:
SDL_Palette* pal = src_bitmap.surface()->format->palette;
std::vector<SDL_Color> colors(pal->colors, pal->colors + pal->ncolors);
dst_bitmap.SetPalette(colors);
const std::vector< uint8_t > & vector() const
Definition bitmap.h:381
Parameters
paletteVector of SDL_Color values (256 colors for 8-bit indexed)
See also
SetPalette(const SnesPalette&) for full palette storage

Definition at line 534 of file bitmap.cc.

References yaze::platform::EnsureSurfacePalette256(), yaze::platform::GetSurfacePalette(), palette(), yaze::gfx::SnesPalette::size(), surface_, and vector().

◆ WriteToPixel() [1/2]

◆ WriteToPixel() [2/2]

void yaze::gfx::Bitmap::WriteToPixel ( int x,
int y,
uint8_t value )
inline

Write a palette index to a pixel at the given x,y coordinates.

Parameters
xX coordinate (0 to width-1)
yY coordinate (0 to height-1)
valuePalette index (0-255)

Definition at line 262 of file bitmap.h.

References height_, vector(), width_, and WriteToPixel().

Here is the call graph for this function:

◆ GetPixel()

uint8_t yaze::gfx::Bitmap::GetPixel ( int x,
int y ) const
inline

Get the palette index at the given x,y coordinates.

Parameters
xX coordinate (0 to width-1)
yY coordinate (0 to height-1)
Returns
Palette index at the position, or 0 if out of bounds

Definition at line 274 of file bitmap.h.

References data_, height_, vector(), and width_.

Referenced by yaze::editor::PixelEditorPanel::DrawPixelInfoTooltip().

Here is the call graph for this function:

◆ WriteColor()

void yaze::gfx::Bitmap::WriteColor ( int position,
const ImVec4 & color )

Write a color to a pixel at the given position.

Definition at line 630 of file bitmap.cc.

References active_, yaze::gfx::ConvertRgbToSnes(), data_, yaze::platform::MapRGB(), modified_, pixel_data_, surface_, and vector().

Referenced by yaze::gui::Canvas::DrawTileOnBitmap().

Here is the call graph for this function:

◆ SetPixel()

void yaze::gfx::Bitmap::SetPixel ( int x,
int y,
const SnesColor & color )

Set a pixel at the given x,y coordinates with SNES color.

Set a pixel at the given coordinates with SNES color.

Parameters
xX coordinate (0 to width-1)
yY coordinate (0 to height-1)
colorSNES color (15-bit RGB format)
Note
Automatically finds closest palette index and marks bitmap as modified
Parameters
xX coordinate (0 to width-1)
yY coordinate (0 to height-1)
colorSNES color (15-bit RGB format)

Performance Notes:

  • Bounds checking for safety
  • O(1) palette lookup using hash map cache (100x faster than linear search)
  • Dirty region tracking for efficient texture updates
  • Direct pixel data manipulation for speed

Optimizations Applied:

  • Hash map palette lookup instead of linear search
  • Dirty region tracking to minimize texture update area

Definition at line 724 of file bitmap.cc.

References yaze::gfx::Bitmap::DirtyRegion::AddPoint(), data_, dirty_region_, FindColorIndex(), height_, modified_, pixel_data_, surface_, vector(), and width_.

Referenced by yaze::cli::Tile16ProposalGenerator::GenerateDiff(), yaze::zelda3::DungeonObjectEditor::RenderLayerVisualization(), and yaze::zelda3::DungeonObjectEditor::RenderSelectionHighlight().

Here is the call graph for this function:

◆ Resize()

void yaze::gfx::Bitmap::Resize ( int new_width,
int new_height )

Resize the bitmap to new dimensions (preserves existing data)

Parameters
new_widthNew width in pixels
new_heightNew height in pixels
Note
Expands with black pixels, crops excess data

Definition at line 752 of file bitmap.cc.

References active_, yaze::gfx::Arena::AllocateSurface(), data_, depth_, yaze::gfx::Arena::Get(), yaze::gfx::GetSnesPixelFormat(), height_, yaze::gfx::kIndexed, modified_, pixel_data_, surface_, vector(), and width_.

Here is the call graph for this function:

◆ InvalidatePaletteCache()

void yaze::gfx::Bitmap::InvalidatePaletteCache ( )

Invalidate the palette lookup cache (call when palette changes)

Note
This must be called whenever the palette is modified to maintain cache consistency
This must be called whenever the palette is modified to maintain cache consistency

Performance Notes:

  • Clears existing cache to force rebuild
  • Rebuilds cache with current palette colors
  • O(n) operation but only called when palette changes

Definition at line 823 of file bitmap.cc.

References color_to_index_cache_, HashColor(), palette_, yaze::gfx::SnesPalette::size(), and vector().

Referenced by ApplyStoredPalette(), and SetPaletteWithTransparent().

Here is the call graph for this function:

◆ FindColorIndex()

uint8_t yaze::gfx::Bitmap::FindColorIndex ( const SnesColor & color)

Find color index in palette using optimized hash map lookup.

Parameters
colorSNES color to find index for
Returns
Palette index (0 if not found)
Note
O(1) lookup time vs O(n) linear search
Parameters
colorSNES color to find index for
Returns
Palette index (0 if not found)
Note
O(1) lookup time vs O(n) linear search

Performance Notes:

  • Hash map lookup for O(1) performance
  • 100x faster than linear search for large palettes
  • Falls back to index 0 if color not found

Definition at line 844 of file bitmap.cc.

References color_to_index_cache_, HashColor(), yaze::gfx::SnesColor::rgb(), and vector().

Referenced by SetPixel().

Here is the call graph for this function:

◆ ValidateDataSurfaceSync()

bool yaze::gfx::Bitmap::ValidateDataSurfaceSync ( )

Validate that bitmap data and surface pixels are synchronized.

Returns
true if synchronized, false if there are issues
Note
This method helps debug surface synchronization problems

Definition at line 872 of file bitmap.cc.

References data_, surface_, and vector().

Here is the call graph for this function:

◆ Get8x8Tile()

void yaze::gfx::Bitmap::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)

Parameters
tile_indexIndex of the tile in the tilesheet
xX offset within the tile (0-7)
yY offset within the tile (0-7)
tile_dataOutput buffer for tile pixel data (64 bytes for 8x8)
tile_data_offsetCurrent offset in tile_data buffer
Note
Used for ROM tile editing and tile extraction

Definition at line 674 of file bitmap.cc.

References data_, height_, vector(), and width_.

Here is the call graph for this function:

◆ Get16x16Tile()

void yaze::gfx::Bitmap::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)

Parameters
tile_xX coordinate of tile in tilesheet
tile_yY coordinate of tile in tilesheet
tile_dataOutput buffer for tile pixel data (256 bytes for 16x16)
tile_data_offsetCurrent offset in tile_data buffer
Note
Used for ROM metatile editing and large tile extraction

Definition at line 690 of file bitmap.cc.

References data_, vector(), and width_.

Referenced by yaze::editor::ScreenEditor::DrawDungeonMapScreen(), and yaze::gfx::UpdateTile16().

Here is the call graph for this function:

◆ palette()

◆ mutable_palette()

◆ metadata() [1/2]

◆ metadata() [2/2]

const BitmapMetadata & yaze::gfx::Bitmap::metadata ( ) const
inline

Definition at line 371 of file bitmap.h.

References metadata_.

◆ width()

int yaze::gfx::Bitmap::width ( ) const
inline

Definition at line 373 of file bitmap.h.

References width_.

Referenced by yaze::gfx::AtlasRenderer::AddBitmap(), yaze::gfx::AtlasRenderer::AddBitmapWithBppOptimization(), yaze::editor::Tile16Editor::AnalyzeTile8SourceData(), Bitmap(), Bitmap(), yaze::gui::BppComparisonTool::CalculateMetrics(), yaze::editor::Tile16Editor::CommitChangesToOverworld(), yaze::gfx::anonymous_namespace{tilemap.cc}::ComposeAndPlaceTilePart(), yaze::gfx::ComposeTile16(), yaze::zelda3::RoomLayerManager::CompositeToOutput(), yaze::gui::Canvas::ConvertBitmapFormat(), Create(), Create(), Create(), yaze::gfx::BackgroundBuffer::DrawBackground(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::DrawBitmap(), yaze::gui::Canvas::DrawBitmapGroup(), yaze::gui::DrawBitmapPreview(), yaze::gui::DrawBitmapViewer(), yaze::zelda3::ObjectDrawer::DrawDoorIndicator(), yaze::editor::ScreenEditor::DrawDungeonMapScreen(), yaze::editor::ScreenEditor::DrawDungeonMapsRoomGfx(), yaze::gfx::BackgroundBuffer::DrawFloor(), yaze::editor::PixelEditorPanel::DrawPixelInfoTooltip(), yaze::editor::SheetBrowserPanel::DrawSheetThumbnail(), yaze::editor::SpriteDrawer::DrawTile8x8(), yaze::gui::DrawTilemapPainter(), yaze::gui::CanvasInteractionHandler::DrawTilemapPainter(), yaze::gui::Canvas::DrawTileOnBitmap(), yaze::zelda3::ObjectDrawer::DrawTileToBitmap(), yaze::gfx::BackgroundBuffer::EnsureBitmapInitialized(), yaze::gui::BppComparisonTool::GenerateComparisons(), yaze::gui::Canvas::GetCurrentBppFormat(), yaze::gfx::GetTilemapData(), yaze::editor::Tile16Editor::Initialize(), yaze::editor::Tile16Editor::LoadTile8(), yaze::gfx::ModifyTile16(), yaze::gfx::AtlasRenderer::PackBitmap(), yaze::gfx::TextureAtlas::PackBitmap(), yaze::gui::CanvasModals::RenderAdvancedPropertiesModal(), yaze::gui::BppFormatUI::RenderAnalysisPanel(), yaze::gui::RenderBitmapGroup(), yaze::gui::RenderBitmapOnCanvas(), yaze::gui::RenderBitmapOnCanvas(), yaze::gui::RenderBitmapOnCanvas(), yaze::gui::CanvasContextMenu::RenderBitmapOperationsMenu(), yaze::gui::BppFormatUI::RenderConversionPreview(), yaze::gui::BppFormatUI::RenderFormatSelector(), yaze::zelda3::DungeonObjectEditor::RenderLayerVisualization(), yaze::gui::RenderPreviewPanel(), yaze::gui::CanvasModals::RenderScalingControlsModal(), yaze::zelda3::DungeonObjectEditor::RenderSelectionHighlight(), yaze::gfx::RenderTile16(), yaze::zelda3::PaletteDebugger::SamplePixelAt(), yaze::editor::Tile16Editor::SetCurrentTile(), yaze::gui::Canvas::SetZoomToFit(), yaze::gui::Canvas::ShowAdvancedCanvasProperties(), yaze::gui::PaletteEditorWidget::ShowColorAnalysis(), yaze::gui::Canvas::ShowScalingControls(), yaze::gui::TableCanvasPipeline(), yaze::gui::DungeonObjectEmulatorPreview::TriggerStaticRender(), yaze::gfx::AtlasRenderer::UpdateBitmap(), yaze::editor::Tile16Editor::UpdateBlocksetBitmap(), yaze::editor::OverworldEditor::UpdateBlocksetWithPendingTileChanges(), yaze::editor::Tile16Editor::UpdateOverworldTilemap(), yaze::gui::BppConversionDialog::UpdatePreview(), yaze::editor::OverworldEditor::UpdateScratchBitmapTile(), yaze::gfx::UpdateTile16(), and yaze::editor::Tile16Editor::UpdateTile16Edit().

◆ height()

int yaze::gfx::Bitmap::height ( ) const
inline

Definition at line 374 of file bitmap.h.

References height_.

Referenced by yaze::gfx::AtlasRenderer::AddBitmap(), yaze::gfx::AtlasRenderer::AddBitmapWithBppOptimization(), yaze::editor::Tile16Editor::AnalyzeTile8SourceData(), Bitmap(), Bitmap(), yaze::gui::BppComparisonTool::CalculateMetrics(), yaze::zelda3::RoomLayerManager::CompositeToOutput(), yaze::gui::Canvas::ConvertBitmapFormat(), Create(), Create(), Create(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::DrawBitmap(), yaze::gui::Canvas::DrawBitmapGroup(), yaze::gui::DrawBitmapPreview(), yaze::gui::DrawBitmapViewer(), yaze::zelda3::ObjectDrawer::DrawDoorIndicator(), yaze::gfx::BackgroundBuffer::DrawFloor(), yaze::editor::PixelEditorPanel::DrawPixelInfoTooltip(), yaze::editor::SheetBrowserPanel::DrawSheetThumbnail(), yaze::editor::SpriteDrawer::DrawTile8x8(), yaze::gui::DrawTilemapPainter(), yaze::gui::CanvasInteractionHandler::DrawTilemapPainter(), yaze::zelda3::ObjectDrawer::DrawTileToBitmap(), yaze::gui::BppComparisonTool::GenerateComparisons(), yaze::gui::Canvas::GetCurrentBppFormat(), yaze::gfx::GetTilemapData(), yaze::editor::Tile16Editor::Initialize(), yaze::editor::Tile16Editor::LoadTile8(), yaze::gfx::AtlasRenderer::PackBitmap(), yaze::gfx::TextureAtlas::PackBitmap(), yaze::gui::CanvasModals::RenderAdvancedPropertiesModal(), yaze::gui::BppFormatUI::RenderAnalysisPanel(), yaze::gui::RenderBitmapGroup(), yaze::gui::RenderBitmapOnCanvas(), yaze::gui::RenderBitmapOnCanvas(), yaze::gui::RenderBitmapOnCanvas(), yaze::gui::CanvasContextMenu::RenderBitmapOperationsMenu(), yaze::gui::BppFormatUI::RenderConversionPreview(), yaze::gui::BppFormatUI::RenderFormatSelector(), yaze::zelda3::DungeonObjectEditor::RenderLayerVisualization(), yaze::gui::RenderPreviewPanel(), yaze::gui::CanvasModals::RenderScalingControlsModal(), yaze::zelda3::DungeonObjectEditor::RenderSelectionHighlight(), yaze::gfx::RenderTile16(), yaze::zelda3::PaletteDebugger::SamplePixelAt(), yaze::gui::Canvas::SetZoomToFit(), yaze::gui::Canvas::ShowAdvancedCanvasProperties(), yaze::gui::PaletteEditorWidget::ShowColorAnalysis(), yaze::gui::Canvas::ShowScalingControls(), yaze::gui::TableCanvasPipeline(), yaze::gfx::AtlasRenderer::UpdateBitmap(), yaze::editor::OverworldEditor::UpdateBlocksetWithPendingTileChanges(), yaze::gui::BppConversionDialog::UpdatePreview(), and yaze::editor::OverworldEditor::UpdateScratchBitmapTile().

◆ depth()

◆ size()

◆ data()

◆ mutable_data()

◆ surface()

◆ texture()

◆ vector()

const std::vector< uint8_t > & yaze::gfx::Bitmap::vector ( ) const
inline

Definition at line 381 of file bitmap.h.

References data_.

Referenced by yaze::gfx::AtlasRenderer::AddBitmap(), yaze::gfx::AtlasRenderer::AddBitmapWithBppOptimization(), ApplyStoredPalette(), Bitmap(), yaze::gui::Canvas::ConvertBitmapFormat(), Create(), yaze::editor::OverworldEditor::DrawOverworldEdits(), FindColorIndex(), yaze::gui::BppComparisonTool::GenerateComparisons(), Get16x16Tile(), Get8x8Tile(), yaze::gui::Canvas::GetCurrentBppFormat(), GetPixel(), yaze::gfx::GetTilemapData(), HashColor(), yaze::editor::Tile16Editor::Initialize(), InvalidatePaletteCache(), operator=(), yaze::editor::Tile16Editor::PasteTile16FromClipboard(), yaze::editor::Tile16Editor::PreviewPaletteChange(), Reformat(), yaze::gui::BppFormatUI::RenderAnalysisPanel(), yaze::zelda3::TitleScreen::RenderBG1Layer(), yaze::zelda3::TitleScreen::RenderBG2Layer(), yaze::zelda3::TitleScreen::RenderCompositeLayer(), yaze::gui::BppFormatUI::RenderConversionPreview(), yaze::gui::BppFormatUI::RenderFormatSelector(), yaze::zelda3::OverworldMapScreen::RenderMapLayer(), yaze::gfx::RenderTile(), yaze::gfx::RenderTile16(), Resize(), yaze::editor::Tile16Editor::SaveTile16ToScratchSpace(), yaze::editor::Tile16Editor::SaveUndoState(), set_data(), SetPalette(), SetPaletteWithTransparent(), SetPixel(), yaze::gui::PaletteEditorWidget::ShowColorAnalysis(), yaze::editor::Tile16Editor::Undo(), yaze::editor::OverworldEditor::UpdateBlocksetWithPendingTileChanges(), yaze::editor::Tile16Editor::UpdateLivePreview(), yaze::gui::BppConversionDialog::UpdatePreview(), UpdateSurfacePixels(), ValidateDataSurfaceSync(), WriteColor(), WriteToPixel(), and WriteToPixel().

◆ at()

uint8_t yaze::gfx::Bitmap::at ( int i) const
inline

Definition at line 382 of file bitmap.h.

References data_.

◆ modified()

bool yaze::gfx::Bitmap::modified ( ) const
inline

Definition at line 383 of file bitmap.h.

References modified_.

Referenced by yaze::editor::Tile16Editor::CommitChangesToBlockset(), and set_modified().

◆ is_active()

bool yaze::gfx::Bitmap::is_active ( ) const
inline

Definition at line 384 of file bitmap.h.

References active_.

Referenced by yaze::gfx::AtlasRenderer::AddBitmap(), yaze::gfx::AtlasRenderer::AddBitmapWithBppOptimization(), yaze::editor::Tile16Editor::AnalyzeTile8SourceData(), yaze::editor::Tile16Editor::ApplyPaletteToCurrentTile16Bitmap(), yaze::editor::OverworldEditor::CheckForCurrentMap(), yaze::editor::SpriteDrawer::ClearBitmap(), yaze::editor::OverworldEditor::ClearScratchSpace(), yaze::editor::Tile16Editor::ClearTile16(), yaze::editor::Tile16Editor::CommitChangesToOverworld(), yaze::gfx::CreateTilemap(), yaze::gfx::BackgroundBuffer::DrawBackground(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::Canvas::DrawBitmapGroup(), yaze::gfx::BackgroundBuffer::DrawFloor(), yaze::editor::MessageEditor::DrawMessagePreview(), yaze::editor::SpriteDrawer::DrawOamTile(), yaze::editor::OverworldEditor::DrawOverworldEdits(), yaze::editor::OverworldEditor::DrawScratchSpace(), yaze::editor::SheetBrowserPanel::DrawSheetThumbnail(), yaze::editor::SpriteEditor::DrawSpriteCanvas(), yaze::editor::OverworldEditor::DrawTile16Selector(), yaze::gui::DrawTilemapPainter(), yaze::gui::CanvasInteractionHandler::DrawTilemapPainter(), yaze::gui::Canvas::DrawTilePainter(), yaze::gui::CanvasInteractionHandler::DrawTilePainter(), yaze::zelda3::ObjectDrawer::DrawTileToBitmap(), yaze::editor::Tile16Editor::DrawToCurrentTile16(), yaze::gfx::BackgroundBuffer::EnsureBitmapInitialized(), yaze::editor::Tile16Editor::FlipTile16Horizontal(), yaze::editor::Tile16Editor::FlipTile16Vertical(), yaze::gfx::GetTilemapData(), yaze::gui::HandleTilemapPaint(), yaze::gui::HandleTilePaintWithPreview(), yaze::editor::OverworldEditor::LoadGraphics(), yaze::editor::Tile16Editor::LoadTile8(), yaze::gfx::TextureAtlas::PackBitmap(), yaze::editor::Tile16Editor::PreviewPaletteChange(), yaze::editor::Tile16Editor::RefreshAllPalettes(), yaze::editor::OverworldEditor::RefreshMapPalette(), yaze::editor::OverworldEditor::RefreshTile16Blockset(), yaze::gui::TileSelectorWidget::Render(), yaze::gui::RenderBitmapGroup(), yaze::gui::RenderBitmapOnCanvas(), yaze::gui::RenderBitmapOnCanvas(), yaze::gui::RenderBitmapOnCanvas(), yaze::gfx::RenderTile(), yaze::gfx::RenderTile16(), yaze::gfx::RenderTilesBatch(), yaze::editor::OverworldEditor::RenderUpdatedMapBitmap(), yaze::editor::SpriteEditor::RenderVanillaSprite(), yaze::editor::SpriteEditor::RenderZSpriteFrame(), yaze::editor::Tile16Editor::RotateTile16(), yaze::editor::Tile16Editor::SaveTile16ToROM(), yaze::editor::Tile16Editor::SaveUndoState(), yaze::editor::Tile16Editor::set_palette(), yaze::editor::Tile16Editor::SetCurrentTile(), yaze::gui::Canvas::SetZoomToFit(), yaze::gui::PaletteEditorWidget::ShowColorAnalysis(), yaze::gui::TableCanvasPipeline(), yaze::editor::Tile16Editor::UpdateBlocksetBitmap(), yaze::editor::OverworldEditor::UpdateBlocksetWithPendingTileChanges(), yaze::editor::Tile16Editor::UpdateLivePreview(), yaze::editor::Tile16Editor::UpdateOverworldTilemap(), yaze::gfx::UpdateTile16(), yaze::editor::Tile16Editor::UpdateTile16Edit(), and yaze::gfx::UpdateTilemap().

◆ generation()

uint32_t yaze::gfx::Bitmap::generation ( ) const
inline

Definition at line 385 of file bitmap.h.

References generation_.

Referenced by yaze::gfx::Arena::QueueTextureCommand().

◆ set_active()

void yaze::gfx::Bitmap::set_active ( bool active)
inline

◆ set_data()

◆ set_modified()

◆ set_texture()

void yaze::gfx::Bitmap::set_texture ( TextureHandle texture)
inline

Definition at line 389 of file bitmap.h.

References texture(), and texture_.

Here is the call graph for this function:

◆ HashColor()

uint32_t yaze::gfx::Bitmap::HashColor ( const ImVec4 & color)
staticprivate

Hash a color for cache lookup.

Parameters
colorImVec4 color to hash
Returns
32-bit hash value
Parameters
colorImVec4 color to hash
Returns
32-bit hash value

Performance Notes:

  • Simple hash combining RGBA components
  • Fast integer operations for cache key generation
  • Collision-resistant for typical SNES palette sizes

Definition at line 802 of file bitmap.cc.

References vector().

Referenced by FindColorIndex(), and InvalidatePaletteCache().

Here is the call graph for this function:

Member Data Documentation

◆ width_

int yaze::gfx::Bitmap::width_ = 0
private

◆ height_

int yaze::gfx::Bitmap::height_ = 0
private

◆ depth_

int yaze::gfx::Bitmap::depth_ = 0
private

Definition at line 394 of file bitmap.h.

Referenced by Bitmap(), Create(), depth(), operator=(), Reformat(), and Resize().

◆ active_

bool yaze::gfx::Bitmap::active_ = false
private

◆ modified_

bool yaze::gfx::Bitmap::modified_ = false
private

◆ generation_

uint32_t yaze::gfx::Bitmap::generation_ = 0
private

Definition at line 401 of file bitmap.h.

Referenced by Create(), generation(), and operator=().

◆ next_generation_

uint32_t yaze::gfx::Bitmap::next_generation_ = 1
inlinestaticprivate

Definition at line 402 of file bitmap.h.

Referenced by Create(), and operator=().

◆ texture_pixels

void* yaze::gfx::Bitmap::texture_pixels = nullptr
private

Definition at line 405 of file bitmap.h.

◆ pixel_data_

uint8_t* yaze::gfx::Bitmap::pixel_data_ = nullptr
private

◆ palette_

gfx::SnesPalette yaze::gfx::Bitmap::palette_
private

Internal SNES palette storage (may be empty!)

This stores the palette in SNES 15-bit RGB format for serialization and palette editing. It is populated by SetPalette(SnesPalette) but NOT by SetPalette(vector<SDL_Color>).

Warning
This may be EMPTY for bitmaps that had their palette set via SetPalette(vector<SDL_Color>). To reliably get the active palette, extract it from the SDL surface: surface_->format->palette->colors
See also
SetPalette(const SnesPalette&) - populates this member
SetPalette(const std::vector<SDL_Color>&) - does NOT populate this

Definition at line 424 of file bitmap.h.

Referenced by ApplyStoredPalette(), Bitmap(), Create(), InvalidatePaletteCache(), mutable_palette(), operator=(), palette(), Reformat(), SetPalette(), and SetPaletteWithTransparent().

◆ metadata_

BitmapMetadata yaze::gfx::Bitmap::metadata_
private

Definition at line 427 of file bitmap.h.

Referenced by ApplyPaletteByMetadata(), metadata(), and metadata().

◆ data_

◆ surface_

SDL_Surface* yaze::gfx::Bitmap::surface_ = nullptr
private

SDL surface for rendering (contains the authoritative palette)

For 8-bit indexed bitmaps, the surface contains:

  • pixels: Raw indexed pixel data (same as data_ after UpdateSurfacePixels)
  • format->palette: The SDL_Palette used for rendering to textures

The SDL palette (surface_->format->palette) is the authoritative source for color data when rendering. When SDL converts indexed pixels to RGBA for texture creation, it uses this palette.

Note
To copy a palette between bitmaps:
SDL_Palette* src_pal = src.surface()->format->palette;
std::vector<SDL_Color> colors(src_pal->ncolors);
for (int i = 0; i < src_pal->ncolors; ++i) {
colors[i] = src_pal->colors[i];
}
dst.SetPalette(colors);
See also
RoomLayerManager::CompositeToOutput() for palette extraction example

Definition at line 455 of file bitmap.h.

Referenced by ApplyStoredPalette(), Bitmap(), Create(), operator=(), Reformat(), Resize(), set_data(), SetPalette(), SetPaletteWithTransparent(), SetPixel(), surface(), UpdateSurfacePixels(), ValidateDataSurfaceSync(), WriteColor(), and WriteToPixel().

◆ texture_

TextureHandle yaze::gfx::Bitmap::texture_ = nullptr
private

Definition at line 458 of file bitmap.h.

Referenced by operator=(), set_texture(), and texture().

◆ color_to_index_cache_

std::unordered_map<uint32_t, uint8_t> yaze::gfx::Bitmap::color_to_index_cache_
private

Definition at line 461 of file bitmap.h.

Referenced by FindColorIndex(), and InvalidatePaletteCache().

◆ dirty_region_

struct yaze::gfx::Bitmap::DirtyRegion yaze::gfx::Bitmap::dirty_region_
private

Referenced by SetPixel().


The documentation for this class was generated from the following files: