1#ifndef YAZE_APP_GFX_BITMAP_H
2#define YAZE_APP_GFX_BITMAP_H
9#include "absl/container/flat_hash_map.h"
10#include "absl/status/status.h"
11#include "absl/status/statusor.h"
12#include "absl/strings/str_cat.h"
28 SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1);
31 SDL_PIXELTYPE_INDEX8, 0,
35 SDL_PIXELTYPE_INDEX8, 0,
39 SDL_PIXELTYPE_INDEX8, 0,
53bool ConvertSurfaceToPNG(SDL_Surface *surface, std::vector<uint8_t> &buffer);
58void ConvertPngToSurface(
const std::vector<uint8_t> &png_data,
59 SDL_Surface **outSurface);
88 std::cerr <<
"Error applying palette in bitmap constructor." << std::endl;
93 std::vector<uint8_t> GetPngData();
102 const std::vector<uint8_t> &
data);
104 const std::vector<uint8_t> &
data);
121 void UpdateTexture(SDL_Renderer *renderer,
bool use_sdl_update =
false);
128 size_t index,
int length = 7);
133 void Get8x8Tile(
int tile_index,
int x,
int y, std::vector<uint8_t> &tile_data,
134 int &tile_data_offset);
137 std::vector<uint8_t> &tile_data,
int &tile_data_offset);
138 void Get16x16Tile(
int tile_x,
int tile_y, std::vector<uint8_t> &tile_data,
139 int &tile_data_offset);
158 void WriteColor(
int position,
const ImVec4 &color);
171 throw std::runtime_error(
"Surface is null.");
Represents a bitmap image.
void Reformat(int format)
auto mutable_converted_surface()
std::shared_ptr< SDL_Surface > surface_
void Get16x16Tile(int tile_index, int x, int y, std::vector< uint8_t > &tile_data, int &tile_data_offset)
absl::Status ApplyPaletteWithTransparent(const SnesPalette &palette, size_t index, int length=7)
auto palette_size() const
void set_active(bool active)
void Get8x8Tile(int tile_index, int x, int y, std::vector< uint8_t > &tile_data, int &tile_data_offset)
Bitmap(int width, int height, int depth, const std::vector< uint8_t > &data)
std::vector< uint8_t > png_data_
void SaveSurfaceToFile(std::string_view filename)
void CreateTexture(std::shared_ptr< SDL_Renderer > renderer)
Creates the underlying SDL_Texture to be displayed.
absl::Status ApplyPalette(const SnesPalette &palette)
Copy color data from the SnesPalette into the SDL_Palette.
std::vector< uint8_t > data_
auto mutable_pixel_data()
void Create(int width, int height, int depth, const std::vector< uint8_t > &data)
Creates a bitmap object with the provided graphical data.
void set_data(const std::vector< uint8_t > &data)
Bitmap(int width, int height, int depth, const std::vector< uint8_t > &data, const SnesPalette &palette)
void WriteToPixel(int position, uchar value)
auto converted_surface() const
absl::Status ApplyPaletteFromPaletteGroup(const SnesPalette &palette, int palette_id)
gfx::SnesPalette palette_
void WriteWordToPixel(int position, uint16_t value)
std::shared_ptr< SDL_Surface > converted_surface_
void UpdateTexture(std::shared_ptr< SDL_Renderer > renderer)
Updates the underlying SDL_Texture when it already exists.
void WriteColor(int position, const ImVec4 &color)
std::shared_ptr< SDL_Texture > texture_
void set_modified(bool modified)
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
constexpr Uint32 SNES_PIXELFORMAT_4BPP
constexpr Uint32 SNES_PIXELFORMAT_2BPP
std::unordered_map< int, gfx::Bitmap > BitmapTable
constexpr Uint32 SNES_PIXELFORMAT_8BPP
constexpr Uint32 SNES_PIXELFORMAT_INDEXED