add BitmapFormat enum, update Reformat

This commit is contained in:
scawful
2024-08-06 18:01:24 -04:00
parent a630fd0f23
commit 7488551335
2 changed files with 13 additions and 6 deletions

View File

@@ -241,6 +241,9 @@ void Bitmap::Reformat(int format) {
GetSnesPixelFormat(format)), GetSnesPixelFormat(format)),
SDL_Surface_Deleter()); SDL_Surface_Deleter());
surface_->pixels = pixel_data_; surface_->pixels = pixel_data_;
if (!ApplyPalette(palette_).ok()) {
// Some sort of error occurred, throw an exception?
}
active_ = true; active_ = true;
} }

View File

@@ -22,6 +22,10 @@ namespace app {
*/ */
namespace gfx { namespace gfx {
// Same as SDL_PIXELFORMAT_INDEX8 for reference
constexpr Uint32 SNES_PIXELFORMAT_INDEXED =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1);
constexpr Uint32 SNES_PIXELFORMAT_2BPP = SDL_DEFINE_PIXELFORMAT( constexpr Uint32 SNES_PIXELFORMAT_2BPP = SDL_DEFINE_PIXELFORMAT(
/*type=*/SDL_PIXELTYPE_INDEX8, /*order=*/0, /*type=*/SDL_PIXELTYPE_INDEX8, /*order=*/0,
/*layouts=*/0, /*bits=*/2, /*bytes=*/1); /*layouts=*/0, /*bits=*/2, /*bytes=*/1);
@@ -34,12 +38,12 @@ constexpr Uint32 SNES_PIXELFORMAT_8BPP = SDL_DEFINE_PIXELFORMAT(
/*type=*/SDL_PIXELTYPE_INDEX8, /*order=*/0, /*type=*/SDL_PIXELTYPE_INDEX8, /*order=*/0,
/*layouts=*/0, /*bits=*/8, /*bytes=*/1); /*layouts=*/0, /*bits=*/8, /*bytes=*/1);
// SDL_PIXELFORMAT_INDEX8 = enum BitmapFormat {
// SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1), kIndexed = 0,
k2bpp = 1,
constexpr int kFormat2bppIndexed = 1; k4bpp = 2,
constexpr int kFormat4bppIndexed = 2; k8bpp = 3,
constexpr int kFormat8bppIndexed = 3; };
/** /**
* @brief Convert SDL_Surface to PNG image data. * @brief Convert SDL_Surface to PNG image data.