Refactor tile data access in Bitmap and update color writing in WriteColor method

This commit is contained in:
scawful
2024-12-08 08:09:36 -05:00
parent 4060d1bc70
commit 4da4a48aed
2 changed files with 5 additions and 8 deletions

View File

@@ -437,9 +437,8 @@ void Bitmap::Get8x8Tile(int tile_index, int x, int y,
int tile_x = (x * 8) % width_;
int tile_y = (y * 8) % height_;
for (int i = 0; i < 8; i++) {
int row_offset = tile_offset + ((tile_y + i) * width_);
for (int j = 0; j < 8; j++) {
int pixel_offset = row_offset + (tile_x + j);
int pixel_offset = tile_offset + (tile_y + i) * width_ + tile_x + j;
int pixel_value = data_[pixel_offset];
tile_data[tile_data_offset] = pixel_value;
tile_data_offset++;
@@ -478,6 +477,8 @@ void Bitmap::WriteColor(int position, const ImVec4 &color) {
// Write the color index to the pixel data
pixel_data_[position] = index;
data_[position] = ConvertRgbToSnes(color);
modified_ = true;
}

View File

@@ -45,8 +45,8 @@ class Tilesheet {
int sheet_offset = 0);
void ModifyTile16(const std::vector<uint8_t>& graphics_buffer,
const TileInfo& top_left, const TileInfo& top_right,
const TileInfo& bottom_left, const TileInfo& bottom_right, int tile_id,
int sheet_offset = 0);
const TileInfo& bottom_left, const TileInfo& bottom_right,
int tile_id, int sheet_offset = 0);
void ComposeAndPlaceTilePart(const std::vector<uint8_t>& graphics_buffer,
const TileInfo& tile_info, int baseX, int baseY);
@@ -61,16 +61,12 @@ class Tilesheet {
}
Bitmap GetTile16(int tile_id) {
std::cout << "GetTile16: " << tile_id << std::endl;
int tiles_per_row = bitmap_->width() / tile_width_;
int tile_x = (tile_id % tiles_per_row) * tile_width_;
int tile_y = (tile_id / tiles_per_row) * tile_height_;
std::cout << "Tile X: " << tile_x << " Tile Y: " << tile_y << std::endl;
std::vector<uint8_t> tile_data(tile_width_ * tile_height_, 0x00);
int tile_data_offset = 0;
bitmap_->Get16x16Tile(tile_x, tile_y, tile_data, tile_data_offset);
return Bitmap(16, 16, bitmap_->depth(), tile_data);
}