refactor Bitmap class: rename ConvertSurfaceToPNG to ConvertSurfaceToPng and streamline GetPngData method
This commit is contained in:
@@ -51,7 +51,7 @@ void PngReadCallback(png_structp png_ptr, png_bytep outBytes,
|
||||
|
||||
} // namespace png_internal
|
||||
|
||||
bool ConvertSurfaceToPNG(SDL_Surface *surface, std::vector<uint8_t> &buffer) {
|
||||
bool ConvertSurfaceToPng(SDL_Surface *surface, std::vector<uint8_t> &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<uint8_t> &png_data,
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Bitmap::GetPngData() {
|
||||
ConvertSurfaceToPNG(surface_.get(), png_data_);
|
||||
return png_data_;
|
||||
std::vector<uint8_t> 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<uint8_t>(data_size, 0));
|
||||
}
|
||||
|
||||
void Bitmap::Create(int width, int height, int depth, std::span<uint8_t> data) {
|
||||
data_ = std::vector<uint8_t>(data.begin(), data.end());
|
||||
Create(width, height, depth, data_);
|
||||
}
|
||||
|
||||
void Bitmap::Create(int width, int height, int depth,
|
||||
const std::vector<uint8_t> &data) {
|
||||
Create(width, height, depth, kIndexed, data);
|
||||
@@ -482,5 +479,4 @@ void Bitmap::WriteColor(int position, const ImVec4 &color) {
|
||||
}
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
} // namespace yaze
|
||||
|
||||
@@ -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<uint8_t> data);
|
||||
void Create(int width, int height, int depth,
|
||||
const std::vector<uint8_t> &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<uint8_t> data_;
|
||||
|
||||
std::vector<uint8_t> png_data_;
|
||||
|
||||
gfx::SnesPalette palette_;
|
||||
std::shared_ptr<SDL_Texture> texture_ = nullptr;
|
||||
std::shared_ptr<SDL_Surface> surface_ = nullptr;
|
||||
@@ -213,7 +202,6 @@ class Bitmap {
|
||||
using BitmapTable = std::unordered_map<int, gfx::Bitmap>;
|
||||
|
||||
} // namespace gfx
|
||||
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_APP_GFX_BITMAP_H
|
||||
|
||||
Reference in New Issue
Block a user