Refactor bitmap handling and remove unused functions for improved clarity

- Simplified pixel format handling by removing the 2BPP format and adjusting related cases.
- Eliminated unused texture tracking variables from the Bitmap class.
- Removed the ExtractTile8Bitmaps function to streamline bitmap processing and reduce complexity.
This commit is contained in:
scawful
2025-05-08 19:42:20 -04:00
parent 2901c9a486
commit 5167bb7206
2 changed files with 3 additions and 74 deletions

View File

@@ -185,10 +185,8 @@ Uint32 GetSnesPixelFormat(int format) {
case 0:
return SDL_PIXELFORMAT_INDEX8;
case 1:
return SNES_PIXELFORMAT_2BPP;
case 2:
return SNES_PIXELFORMAT_4BPP;
case 3:
case 2:
return SNES_PIXELFORMAT_8BPP;
}
return SDL_PIXELFORMAT_INDEX8;
@@ -288,8 +286,6 @@ void Bitmap::CreateTexture(SDL_Renderer *renderer) {
return;
}
texture_in_use_ = true;
last_used_time_ = SDL_GetTicks64();
UpdateTextureData();
}
@@ -446,53 +442,5 @@ std::vector<uint8_t> Bitmap::GetPngData() {
}
#endif
std::vector<gfx::Bitmap> ExtractTile8Bitmaps(const gfx::Bitmap &source_bmp,
const gfx::SnesPalette &palette,
uint8_t palette_index) {
constexpr int kTileCount = 1024;
constexpr int kTileSize = 8;
std::vector<gfx::Bitmap> tile_bitmaps;
tile_bitmaps.reserve(kTileCount);
std::vector<std::future<gfx::Bitmap>> futures;
for (int index = 0; index < kTileCount; ++index) {
futures.emplace_back(std::async(
std::launch::async, [&source_bmp, &palette, palette_index, index]() {
std::array<uint8_t, 0x40> tile_data;
int num_columns = source_bmp.width() / kTileSize;
for (int ty = 0; ty < kTileSize; ++ty) {
for (int tx = 0; tx < kTileSize; ++tx) {
int tile_data_pos = tx + (ty * kTileSize);
int src_x = (index % num_columns) * kTileSize + tx;
int src_y = (index / num_columns) * kTileSize + ty;
int gfx_position = src_x + (src_y * 0x100);
uint8_t value = source_bmp.data()[gfx_position];
if (value & 0x80) {
value -= 0x88;
}
tile_data[tile_data_pos] = value;
}
}
gfx::Bitmap tile_bitmap;
tile_bitmap.Create(kTileSize, kTileSize, 8, tile_data);
tile_bitmap.SetPaletteWithTransparent(palette, palette_index);
return tile_bitmap;
}));
}
for (auto &future : futures) {
tile_bitmaps.push_back(future.get());
}
return tile_bitmaps;
}
} // namespace gfx
} // namespace yaze

View File

@@ -5,7 +5,6 @@
#include <cstdint>
#include <span>
#include <string_view>
#include <vector>
#include "app/gfx/snes_palette.h"
@@ -22,10 +21,6 @@ namespace gfx {
constexpr Uint32 SNES_PIXELFORMAT_INDEXED =
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1);
constexpr Uint32 SNES_PIXELFORMAT_2BPP = SDL_DEFINE_PIXELFORMAT(
/*type=*/SDL_PIXELTYPE_INDEX8, /*order=*/0,
/*layouts=*/0, /*bits=*/2, /*bytes=*/1);
constexpr Uint32 SNES_PIXELFORMAT_4BPP = SDL_DEFINE_PIXELFORMAT(
/*type=*/SDL_PIXELTYPE_INDEX8, /*order=*/0,
/*layouts=*/0, /*bits=*/4, /*bytes=*/1);
@@ -36,9 +31,8 @@ constexpr Uint32 SNES_PIXELFORMAT_8BPP = SDL_DEFINE_PIXELFORMAT(
enum BitmapFormat {
kIndexed = 0,
k2bpp = 1,
k4bpp = 2,
k8bpp = 3,
k4bpp = 1,
k8bpp = 2,
};
#if YAZE_LIB_PNG == 1
@@ -183,12 +177,6 @@ class Bitmap {
bool active_ = false;
bool modified_ = false;
// Track if this texture is currently in use
bool texture_in_use_ = false;
// Track the last time this texture was used
uint64_t last_used_time_ = 0;
// Pointer to the texture pixels
void *texture_pixels = nullptr;
@@ -211,13 +199,6 @@ class Bitmap {
// Type alias for a table of bitmaps
using BitmapTable = std::unordered_map<int, gfx::Bitmap>;
/**
* @brief Extract 8x8 tiles from a source bitmap
*/
std::vector<gfx::Bitmap> ExtractTile8Bitmaps(const gfx::Bitmap &source_bmp,
const gfx::SnesPalette &palette,
uint8_t palette_index);
/**
* @brief Get the SDL pixel format for a given bitmap format
*/