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 Initialize (int width, int height, int depth, std::span< uint8_t > &data)
 Initialize the bitmap with the given dimensions and data.
 
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 SaveSurfaceToFile (std::string_view filename)
 Save the bitmap surface to a file.
 
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 CleanupUnusedTexture (uint64_t current_time, uint64_t timeout)
 Clean up unused textures after a timeout.
 
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 SetPaletteFromPaletteGroup (const SnesPalette &palette, int palette_id)
 Set the palette from a palette group.
 
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.
 
void Cleanup ()
 Clean up the bitmap resources.
 
void Clear ()
 Clear the bitmap data.
 
const SnesPalettepalette () const
 
SnesPalettemutable_palette ()
 
int width () const
 
int height () const
 
int depth () const
 
int 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
 
int data_size_ = 0
 
bool active_ = false
 
bool modified_ = false
 
bool texture_in_use_ = false
 
uint64_t last_used_time_ = 0
 
void * texture_pixels = nullptr
 
uint8_t * pixel_data_ = nullptr
 
gfx::SnesPalette palette_
 
std::vector< uint8_t > data_
 
std::shared_ptr< SDL_Surface > surface_ = nullptr
 
std::shared_ptr< 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 66 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 228 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 234 of file bitmap.cc.

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

Member Function Documentation

◆ Initialize()

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

Initialize the bitmap with the given dimensions and data.

Definition at line 249 of file bitmap.cc.

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

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

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

Referenced by Bitmap(), Bitmap(), Create(), Create(), yaze::core::Renderer::CreateAndRenderBitmap(), and yaze::gfx::ExtractTile8Bitmaps().

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

References active_, yaze::gfx::AllocateSurface(), data(), data_, data_size_, depth(), depth_, 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 299 of file bitmap.cc.

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

Here is the call graph for this function:

◆ SaveSurfaceToFile()

void yaze::gfx::Bitmap::SaveSurfaceToFile ( std::string_view filename)

Save the bitmap surface to a file.

Definition at line 245 of file bitmap.cc.

References surface_.

◆ CreateTexture()

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

Creates the underlying SDL_Texture to be displayed.

Converts the surface from a RGB to ARGB format. Uses SDL_TEXTUREACCESS_STREAMING to allow for live updates.

Definition at line 323 of file bitmap.cc.

References yaze::gfx::TexturePool::GetInstance(), yaze::gfx::TexturePool::GetTexture(), height_, last_used_time_, yaze::gfx::TexturePool::ReturnTexture(), texture_, texture_in_use_, UpdateTextureData(), and width_.

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

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

References surface_, texture_, and texture_pixels.

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

◆ UpdateTextureData()

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

Updates the texture data from the surface.

Definition at line 367 of file bitmap.cc.

References modified_, surface_, and texture_.

Referenced by CreateTexture().

◆ CleanupUnusedTexture()

void yaze::gfx::Bitmap::CleanupUnusedTexture ( uint64_t current_time,
uint64_t timeout )

Clean up unused textures after a timeout.

Definition at line 395 of file bitmap.cc.

References last_used_time_, texture_, and texture_in_use_.

◆ SetPalette() [1/2]

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

Set the palette for the bitmap.

Definition at line 403 of file bitmap.cc.

References palette(), palette_, and surface_.

Referenced by Bitmap(), yaze::core::Renderer::CreateAndRenderBitmap(), 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 451 of file bitmap.cc.

References palette(), palette_, and surface_.

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

Here is the call graph for this function:

◆ SetPaletteFromPaletteGroup()

void yaze::gfx::Bitmap::SetPaletteFromPaletteGroup ( const SnesPalette & palette,
int palette_id )

Set the palette from a palette group.

Definition at line 429 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 490 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 501 of file bitmap.cc.

References data_, modified_, and pixel_data_.

Referenced by 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 509 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 528 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 544 of file bitmap.cc.

References data_, and width_.

◆ Cleanup()

void yaze::gfx::Bitmap::Cleanup ( )

Clean up the bitmap resources.

Definition at line 561 of file bitmap.cc.

References active_, data_size_, depth_, height_, palette_, and width_.

◆ Clear()

void yaze::gfx::Bitmap::Clear ( )

Clear the bitmap data.

Definition at line 570 of file bitmap.cc.

References active_, data_, data_size_, depth_, height_, pixel_data_, texture_pixels, and width_.

◆ palette()

const SnesPalette & yaze::gfx::Bitmap::palette ( ) const
inline

◆ mutable_palette()

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

Definition at line 195 of file bitmap.h.

References palette_.

◆ width()

◆ height()

◆ depth()

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

Definition at line 198 of file bitmap.h.

References depth_.

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

◆ size()

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

Definition at line 199 of file bitmap.h.

References data_size_.

◆ data()

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

Definition at line 200 of file bitmap.h.

References data_.

Referenced by Bitmap(), Bitmap(), Bitmap(), Create(), Create(), Create(), yaze::gfx::ExtractTile8Bitmaps(), Initialize(), and set_data().

◆ mutable_data()

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

Definition at line 201 of file bitmap.h.

References data_.

◆ surface()

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

Definition at line 202 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 204 of file bitmap.h.

References data_.

Referenced by yaze::editor::Tile16Editor::Initialize().

◆ at()

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

Definition at line 205 of file bitmap.h.

References data_.

◆ modified()

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

Definition at line 206 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 208 of file bitmap.h.

References active_.

◆ set_data()

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

Definition at line 209 of file bitmap.h.

References data(), and data_.

Here is the call graph for this function:

◆ set_modified()

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

Definition at line 210 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

◆ height_

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

◆ depth_

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

Definition at line 222 of file bitmap.h.

Referenced by Bitmap(), Bitmap(), Cleanup(), Clear(), Create(), depth(), Initialize(), and Reformat().

◆ data_size_

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

Definition at line 223 of file bitmap.h.

Referenced by Cleanup(), Clear(), Create(), and size().

◆ active_

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

Definition at line 225 of file bitmap.h.

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

◆ modified_

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

Definition at line 226 of file bitmap.h.

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

◆ texture_in_use_

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

Definition at line 229 of file bitmap.h.

Referenced by CleanupUnusedTexture(), and CreateTexture().

◆ last_used_time_

uint64_t yaze::gfx::Bitmap::last_used_time_ = 0
private

Definition at line 232 of file bitmap.h.

Referenced by CleanupUnusedTexture(), and CreateTexture().

◆ texture_pixels

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

Definition at line 235 of file bitmap.h.

Referenced by Clear(), and UpdateTexture().

◆ pixel_data_

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

Definition at line 238 of file bitmap.h.

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

◆ palette_

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

◆ data_

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

◆ surface_

std::shared_ptr<SDL_Surface> yaze::gfx::Bitmap::surface_ = nullptr
private

◆ texture_

std::shared_ptr<SDL_Texture> yaze::gfx::Bitmap::texture_ = nullptr
private

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