From 4da4a48aeda3477a41cf7f52816cba08afe00758 Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 8 Dec 2024 08:09:36 -0500 Subject: [PATCH] Refactor tile data access in Bitmap and update color writing in WriteColor method --- src/app/gfx/bitmap.cc | 5 +++-- src/app/gfx/tilesheet.h | 8 ++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/app/gfx/bitmap.cc b/src/app/gfx/bitmap.cc index 890574a0..3f357bae 100644 --- a/src/app/gfx/bitmap.cc +++ b/src/app/gfx/bitmap.cc @@ -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; } diff --git a/src/app/gfx/tilesheet.h b/src/app/gfx/tilesheet.h index 31639b4d..3107b3ad 100644 --- a/src/app/gfx/tilesheet.h +++ b/src/app/gfx/tilesheet.h @@ -45,8 +45,8 @@ class Tilesheet { int sheet_offset = 0); void ModifyTile16(const std::vector& 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& 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 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); }