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

Represents a bitmap image. More...

#include <bitmap.h>

Collaboration diagram for yaze::gfx::Bitmap:

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 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 palette.
 
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 CreateTexture (SDL_Renderer *renderer)
 Creates the underlying SDL_Texture to be displayed.
 
void UpdateTexture (SDL_Renderer *renderer)
 Updates the underlying SDL_Texture when it already exists.
 
void UpdateTextureData ()
 Updates the texture data from the surface.
 
void SetPalette (const SnesPalette &palette)
 Set the palette for the bitmap.
 
void SetPaletteWithTransparent (const SnesPalette &palette, size_t index, int length=7)
 Set the palette with a transparent color.
 
void SetPalette (const std::vector< SDL_Color > &palette)
 Set the palette using SDL colors.
 
void WriteToPixel (int position, uint8_t value)
 Write a value to a pixel at the given position.
 
void WriteColor (int position, const ImVec4 &color)
 Write a color to a pixel at the given position.
 
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.
 
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.
 
const SnesPalettepalette () const
 
SnesPalettemutable_palette ()
 
int width () const
 
int height () const
 
int depth () const
 
auto size () const
 
const uint8_t * data () const
 
std::vector< uint8_t > & mutable_data ()
 
SDL_Surface * surface () const
 
SDL_Texture * texture () const
 
const std::vector< uint8_t > & vector () const
 
uint8_t at (int i) const
 
bool modified () const
 
bool is_active () const
 
void set_active (bool active)
 
void set_data (const std::vector< uint8_t > &data)
 
void set_modified (bool modified)
 

Private Attributes

int width_ = 0
 
int height_ = 0
 
int depth_ = 0
 
bool active_ = false
 
bool modified_ = false
 
void * texture_pixels = nullptr
 
uint8_t * pixel_data_ = nullptr
 
gfx::SnesPalette palette_
 
std::vector< uint8_t > data_
 
SDL_Surface * surface_ = nullptr
 
SDL_Texture * texture_ = nullptr
 

Detailed Description

Represents a bitmap image.

The Bitmap class provides functionality to create, manipulate, and display bitmap images. It supports various operations such as creating a bitmap object, creating and updating textures, applying palettes, and accessing pixel data.

Definition at line 59 of file bitmap.h.

Constructor & Destructor Documentation

◆ Bitmap() [1/3]

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

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

◆ Bitmap() [2/3]

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

Create a bitmap with the given dimensions and data.

Definition at line 201 of file bitmap.cc.

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

◆ Bitmap() [3/3]

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 palette.

Definition at line 207 of file bitmap.cc.

References Create(), data(), data_, depth(), depth_, height(), height_, palette(), palette_, SetPalette(), width(), and width_.

Member Function Documentation

◆ 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 218 of file bitmap.cc.

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

Referenced by Bitmap(), Bitmap(), Create(), Create(), yaze::core::Renderer::CreateAndRenderBitmap(), yaze::zelda3::LoadDungeonMapTile16(), and yaze::LoadFontGraphics().

◆ 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 223 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.

Definition at line 228 of file bitmap.cc.

References active_, yaze::gfx::Arena::AllocateSurface(), data(), data_, depth(), depth_, yaze::gfx::Arena::Get(), yaze::gfx::GetSnesPixelFormat(), height(), height_, pixel_data_, surface_, width(), and width_.

◆ Reformat()

void yaze::gfx::Bitmap::Reformat ( int format)

Reformat the bitmap to use a different pixel format.

Definition at line 258 of file bitmap.cc.

References active_, yaze::gfx::Arena::AllocateSurface(), depth_, yaze::gfx::Arena::Get(), yaze::gfx::GetSnesPixelFormat(), height_, palette_, pixel_data_, SetPalette(), surface_, and width_.

Here is the call graph for this function:

◆ CreateTexture()

void yaze::gfx::Bitmap::CreateTexture ( SDL_Renderer * renderer)

Creates the underlying SDL_Texture to be displayed.

Definition at line 275 of file bitmap.cc.

References yaze::gfx::Arena::AllocateTexture(), yaze::gfx::Arena::Get(), height_, texture_, UpdateTextureData(), and width_.

Referenced by yaze::core::Renderer::RenderBitmap(), and UpdateTexture().

Here is the call graph for this function:

◆ UpdateTexture()

void yaze::gfx::Bitmap::UpdateTexture ( SDL_Renderer * renderer)

Updates the underlying SDL_Texture when it already exists.

Definition at line 266 of file bitmap.cc.

References CreateTexture(), data_, yaze::gfx::Arena::Get(), surface_, texture_, and yaze::gfx::Arena::UpdateTexture().

Referenced by yaze::core::Renderer::UpdateBitmap().

Here is the call graph for this function:

◆ UpdateTextureData()

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

Updates the texture data from the surface.

Definition at line 298 of file bitmap.cc.

References yaze::gfx::Arena::Get(), modified_, surface_, texture_, and yaze::gfx::Arena::UpdateTexture().

Referenced by CreateTexture().

Here is the call graph for this function:

◆ SetPalette() [1/2]

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

Set the palette for the bitmap.

Definition at line 307 of file bitmap.cc.

References palette(), palette_, and surface_.

Referenced by Bitmap(), yaze::core::Renderer::CreateAndRenderBitmap(), yaze::gfx::CreateTilemap(), yaze::zelda3::LoadDungeonMapTile16(), and Reformat().

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.

Definition at line 333 of file bitmap.cc.

References palette(), palette_, and surface_.

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.

Definition at line 372 of file bitmap.cc.

References palette(), and surface_.

Here is the call graph for this function:

◆ WriteToPixel()

void yaze::gfx::Bitmap::WriteToPixel ( int position,
uint8_t value )

Write a value to a pixel at the given position.

Definition at line 383 of file bitmap.cc.

References data_, modified_, and pixel_data_.

Referenced by yaze::gfx::anonymous_namespace{tilemap.cc}::ComposeAndPlaceTilePart(), and yaze::editor::OverworldEditor::RenderUpdatedMapBitmap().

◆ WriteColor()

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

Write a color to a pixel at the given position.

Definition at line 392 of file bitmap.cc.

References yaze::gfx::ConvertRgbToSnes(), data_, modified_, pixel_data_, and surface_.

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

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.

Definition at line 411 of file bitmap.cc.

References data_, height_, and width_.

◆ 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.

Definition at line 427 of file bitmap.cc.

References data_, and width_.

Referenced by yaze::gfx::RenderTile16(), and yaze::gfx::UpdateTile16().

◆ palette()

◆ mutable_palette()

SnesPalette * yaze::gfx::Bitmap::mutable_palette ( )
inline

Definition at line 150 of file bitmap.h.

References palette_.

◆ width()

◆ height()

◆ depth()

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

Definition at line 153 of file bitmap.h.

References depth_.

Referenced by Bitmap(), Bitmap(), Bitmap(), Create(), Create(), Create(), and yaze::editor::Tile16Editor::Initialize().

◆ size()

auto yaze::gfx::Bitmap::size ( ) const
inline

Definition at line 154 of file bitmap.h.

References data_.

◆ data()

const uint8_t * yaze::gfx::Bitmap::data ( ) const
inline

Definition at line 155 of file bitmap.h.

References data_.

Referenced by Bitmap(), Bitmap(), Bitmap(), Create(), Create(), Create(), and set_data().

◆ mutable_data()

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

Definition at line 156 of file bitmap.h.

References data_.

◆ surface()

SDL_Surface * yaze::gfx::Bitmap::surface ( ) const
inline

Definition at line 157 of file bitmap.h.

References surface_.

◆ texture()

SDL_Texture * yaze::gfx::Bitmap::texture ( ) const
inline

◆ vector()

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

Definition at line 159 of file bitmap.h.

References data_.

Referenced by yaze::gfx::GetTilemapData(), and yaze::editor::Tile16Editor::Initialize().

◆ at()

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

Definition at line 160 of file bitmap.h.

References data_.

◆ modified()

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

Definition at line 161 of file bitmap.h.

References modified_.

Referenced by set_modified().

◆ is_active()

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

◆ set_active()

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

Definition at line 163 of file bitmap.h.

References active_.

◆ set_data()

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

Definition at line 164 of file bitmap.h.

References data(), and data_.

Referenced by yaze::gfx::UpdateTilemap().

Here is the call graph for this function:

◆ set_modified()

void yaze::gfx::Bitmap::set_modified ( bool modified)
inline

Definition at line 165 of file bitmap.h.

References modified(), and modified_.

Referenced by yaze::editor::OverworldEditor::RenderUpdatedMapBitmap().

Here is the call graph for this function:

Member Data Documentation

◆ width_

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

Definition at line 172 of file bitmap.h.

Referenced by Bitmap(), Bitmap(), Create(), CreateTexture(), Get16x16Tile(), Get8x8Tile(), Reformat(), and width().

◆ height_

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

Definition at line 173 of file bitmap.h.

Referenced by Bitmap(), Bitmap(), Create(), CreateTexture(), Get8x8Tile(), height(), and Reformat().

◆ depth_

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

Definition at line 174 of file bitmap.h.

Referenced by Bitmap(), Bitmap(), Create(), depth(), and Reformat().

◆ active_

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

Definition at line 176 of file bitmap.h.

Referenced by Create(), is_active(), Reformat(), and set_active().

◆ modified_

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

Definition at line 177 of file bitmap.h.

Referenced by modified(), set_modified(), UpdateTextureData(), WriteColor(), and WriteToPixel().

◆ texture_pixels

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

Definition at line 180 of file bitmap.h.

◆ pixel_data_

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

Definition at line 183 of file bitmap.h.

Referenced by Create(), Reformat(), WriteColor(), and WriteToPixel().

◆ palette_

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

◆ data_

std::vector<uint8_t> yaze::gfx::Bitmap::data_
private

◆ surface_

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

◆ texture_

SDL_Texture* yaze::gfx::Bitmap::texture_ = nullptr
private

Definition at line 195 of file bitmap.h.

Referenced by CreateTexture(), texture(), UpdateTexture(), and UpdateTextureData().


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