Represents a bitmap image. More...
#include <bitmap.h>
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 SnesPalette & | palette () const |
SnesPalette * | mutable_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 |
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.
yaze::gfx::Bitmap::Bitmap | ( | int | width, |
int | height, | ||
int | depth, | ||
const std::vector< uint8_t > & | data ) |
yaze::gfx::Bitmap::Bitmap | ( | int | width, |
int | height, | ||
int | depth, | ||
const std::vector< uint8_t > & | data, | ||
const SnesPalette & | palette ) |
void yaze::gfx::Bitmap::Initialize | ( | int | width, |
int | height, | ||
int | depth, | ||
std::span< uint8_t > & | data ) |
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().
void yaze::gfx::Bitmap::Create | ( | int | width, |
int | height, | ||
int | depth, | ||
const std::vector< uint8_t > & | data ) |
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_.
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_.
void yaze::gfx::Bitmap::SaveSurfaceToFile | ( | std::string_view | filename | ) |
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().
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().
void yaze::gfx::Bitmap::UpdateTextureData | ( | ) |
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_.
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().
void yaze::gfx::Bitmap::SetPaletteWithTransparent | ( | const SnesPalette & | palette, |
size_t | index, | ||
int | length = 7 ) |
void yaze::gfx::Bitmap::SetPaletteFromPaletteGroup | ( | const SnesPalette & | palette, |
int | palette_id ) |
void yaze::gfx::Bitmap::SetPalette | ( | const std::vector< SDL_Color > & | palette | ) |
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().
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().
void yaze::gfx::Bitmap::Get8x8Tile | ( | int | tile_index, |
int | x, | ||
int | y, | ||
std::vector< uint8_t > & | tile_data, | ||
int & | tile_data_offset ) |
void yaze::gfx::Bitmap::Get16x16Tile | ( | int | tile_x, |
int | tile_y, | ||
std::vector< uint8_t > & | tile_data, | ||
int & | tile_data_offset ) |
void yaze::gfx::Bitmap::Cleanup | ( | ) |
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_.
|
inline |
Definition at line 194 of file bitmap.h.
References palette_.
Referenced by Bitmap(), Bitmap(), yaze::editor::Tile16Editor::Initialize(), SetPalette(), SetPalette(), SetPaletteFromPaletteGroup(), and SetPaletteWithTransparent().
|
inline |
|
inline |
Definition at line 196 of file bitmap.h.
References width_.
Referenced by Bitmap(), Bitmap(), Bitmap(), Create(), Create(), Create(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::DrawBitmapViewer(), yaze::gui::Canvas::DrawTileOnBitmap(), yaze::gfx::ExtractTile8Bitmaps(), yaze::editor::Tile16Editor::Initialize(), and Initialize().
|
inline |
Definition at line 197 of file bitmap.h.
References height_.
Referenced by Bitmap(), Bitmap(), Bitmap(), Create(), Create(), Create(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::DrawBitmapViewer(), yaze::editor::Tile16Editor::Initialize(), and Initialize().
|
inline |
|
inline |
Definition at line 199 of file bitmap.h.
References data_size_.
|
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().
|
inline |
|
inline |
|
inline |
Definition at line 203 of file bitmap.h.
References texture_.
Referenced by yaze::gui::Canvas::DrawBitmap(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::Canvas::DrawBitmap(), yaze::gui::DrawBitmapViewer(), and yaze::gui::Canvas::DrawTilePainter().
|
inline |
Definition at line 204 of file bitmap.h.
References data_.
Referenced by yaze::editor::Tile16Editor::Initialize().
|
inline |
|
inline |
|
inline |
Definition at line 207 of file bitmap.h.
References active_.
Referenced by yaze::gui::Canvas::DrawBitmap(), yaze::gui::Canvas::DrawBitmap(), and yaze::gui::Canvas::DrawTilePainter().
|
inline |
|
inline |
|
inline |
Definition at line 210 of file bitmap.h.
References modified(), and modified_.
Referenced by yaze::editor::OverworldEditor::RenderUpdatedMapBitmap().
|
private |
Definition at line 220 of file bitmap.h.
Referenced by Bitmap(), Bitmap(), Cleanup(), Clear(), Create(), CreateTexture(), Get16x16Tile(), Get8x8Tile(), Initialize(), Reformat(), and width().
|
private |
Definition at line 221 of file bitmap.h.
Referenced by Bitmap(), Bitmap(), Cleanup(), Clear(), Create(), CreateTexture(), Get8x8Tile(), height(), Initialize(), and Reformat().
|
private |
Definition at line 222 of file bitmap.h.
Referenced by Bitmap(), Bitmap(), Cleanup(), Clear(), Create(), depth(), Initialize(), and Reformat().
|
private |
|
private |
Definition at line 225 of file bitmap.h.
Referenced by Cleanup(), Clear(), Create(), is_active(), Reformat(), and set_active().
|
private |
Definition at line 226 of file bitmap.h.
Referenced by modified(), set_modified(), UpdateTextureData(), WriteColor(), and WriteToPixel().
|
private |
Definition at line 229 of file bitmap.h.
Referenced by CleanupUnusedTexture(), and CreateTexture().
|
private |
Definition at line 232 of file bitmap.h.
Referenced by CleanupUnusedTexture(), and CreateTexture().
|
private |
Definition at line 235 of file bitmap.h.
Referenced by Clear(), and UpdateTexture().
|
private |
Definition at line 238 of file bitmap.h.
Referenced by Clear(), Create(), Reformat(), WriteColor(), and WriteToPixel().
|
private |
Definition at line 241 of file bitmap.h.
Referenced by Bitmap(), Cleanup(), mutable_palette(), palette(), Reformat(), SetPalette(), SetPaletteFromPaletteGroup(), and SetPaletteWithTransparent().
|
private |
Definition at line 244 of file bitmap.h.
Referenced by at(), Bitmap(), Bitmap(), Clear(), Create(), Create(), data(), Get16x16Tile(), Get8x8Tile(), Initialize(), mutable_data(), set_data(), vector(), WriteColor(), and WriteToPixel().
|
private |
Definition at line 247 of file bitmap.h.
Referenced by Create(), Reformat(), SaveSurfaceToFile(), SetPalette(), SetPalette(), SetPaletteFromPaletteGroup(), SetPaletteWithTransparent(), surface(), UpdateTexture(), UpdateTextureData(), and WriteColor().
|
private |
Definition at line 250 of file bitmap.h.
Referenced by CleanupUnusedTexture(), CreateTexture(), texture(), UpdateTexture(), and UpdateTextureData().