From d711a84ed35a489972f59908fdae48dffaf477e5 Mon Sep 17 00:00:00 2001 From: scawful Date: Wed, 1 Jan 2025 15:53:17 -0500 Subject: [PATCH] refactor Bitmap class: rename ConvertSurfaceToPNG to ConvertSurfaceToPng and streamline GetPngData method --- src/app/gfx/bitmap.cc | 22 +++++++++------------- src/app/gfx/bitmap.h | 14 +------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/app/gfx/bitmap.cc b/src/app/gfx/bitmap.cc index 78be9d45..3b4c38bd 100644 --- a/src/app/gfx/bitmap.cc +++ b/src/app/gfx/bitmap.cc @@ -51,7 +51,7 @@ void PngReadCallback(png_structp png_ptr, png_bytep outBytes, } // namespace png_internal -bool ConvertSurfaceToPNG(SDL_Surface *surface, std::vector &buffer) { +bool ConvertSurfaceToPng(SDL_Surface *surface, std::vector &buffer) { png_structp png_ptr = png_create_write_struct("1.6.40", NULL, NULL, NULL); if (!png_ptr) { SDL_Log("Failed to create PNG write struct"); @@ -187,22 +187,14 @@ void ConvertPngToSurface(const std::vector &png_data, } std::vector Bitmap::GetPngData() { - ConvertSurfaceToPNG(surface_.get(), png_data_); - return png_data_; + std::vector png_data; + ConvertSurfaceToPng(surface_.get(), png_data); + return png_data; } #endif // YAZE_LIB_PNG namespace { - -void GrayscalePalette(SDL_Palette *palette) { - for (int i = 0; i < 8; i++) { - palette->colors[i].r = i * 31; - palette->colors[i].g = i * 31; - palette->colors[i].b = i * 31; - } -} - Uint32 GetSnesPixelFormat(int format) { switch (format) { case 0: @@ -226,6 +218,11 @@ Bitmap::Bitmap(int width, int height, int depth, int data_size) { Create(width, height, depth, std::vector(data_size, 0)); } +void Bitmap::Create(int width, int height, int depth, std::span data) { + data_ = std::vector(data.begin(), data.end()); + Create(width, height, depth, data_); +} + void Bitmap::Create(int width, int height, int depth, const std::vector &data) { Create(width, height, depth, kIndexed, data); @@ -482,5 +479,4 @@ void Bitmap::WriteColor(int position, const ImVec4 &color) { } } // namespace gfx - } // namespace yaze diff --git a/src/app/gfx/bitmap.h b/src/app/gfx/bitmap.h index 7ea9a144..d628e979 100644 --- a/src/app/gfx/bitmap.h +++ b/src/app/gfx/bitmap.h @@ -94,6 +94,7 @@ class Bitmap { /** * @brief Creates a bitmap object with the provided graphical data. */ + void Create(int width, int height, int depth, std::span data); void Create(int width, int height, int depth, const std::vector &data); void Create(int width, int height, int depth, int format, @@ -138,15 +139,6 @@ class Bitmap { modified_ = true; } - void WriteWordToPixel(int position, uint16_t value) { - if (pixel_data_ == nullptr) { - pixel_data_ = data_.data(); - } - pixel_data_[position] = value & 0xFF; - pixel_data_[position + 1] = (value >> 8) & 0xFF; - modified_ = true; - } - void WriteColor(int position, const ImVec4 &color); void Cleanup() { @@ -174,7 +166,6 @@ class Bitmap { auto size() const { return data_size_; } auto data() const { return data_.data(); } auto &mutable_data() { return data_; } - auto mutable_pixel_data() { return pixel_data_; } auto surface() const { return surface_.get(); } auto mutable_surface() { return surface_.get(); } auto converted_surface() const { return converted_surface_.get(); } @@ -202,8 +193,6 @@ class Bitmap { uint8_t *pixel_data_ = nullptr; std::vector data_; - std::vector png_data_; - gfx::SnesPalette palette_; std::shared_ptr texture_ = nullptr; std::shared_ptr surface_ = nullptr; @@ -213,7 +202,6 @@ class Bitmap { using BitmapTable = std::unordered_map; } // namespace gfx - } // namespace yaze #endif // YAZE_APP_GFX_BITMAP_H