1#ifndef YAZE_APP_GFX_TILESHEET_H
2#define YAZE_APP_GFX_TILESHEET_H
38 void ComposeTile16(
const std::vector<uint8_t>& graphics_buffer,
48 int tileDataOffset = 0;
50 tileData, tileDataOffset);
51 return Bitmap(bmp_width, bmp_height,
bitmap_->depth(), tileData);
56 int tileDataOffset = 0;
57 bitmap_->Get16x16Tile(tile_x, tile_y, tile_data, tileDataOffset);
63 int tile_x = (tile_id % tiles_per_row) *
tile_width_;
69 void CopyTile(
int srcX,
int srcY,
int destX,
int destY,
bool mirrorX =
false,
70 bool mirrorY =
false) {
72 auto destTileData = srcTile.vector();
95 const std::vector<uint8_t>& graphics_buffer,
int tile_id) {
96 const int tileWidth = 8;
97 const int tileHeight = 8;
98 const int bufferWidth = 128;
99 const int sheetHeight = 32;
101 const int tilesPerRow = bufferWidth / tileWidth;
102 const int rowsPerSheet = sheetHeight / tileHeight;
103 const int tilesPerSheet = tilesPerRow * rowsPerSheet;
106 std::vector<uint8_t> tile_data(0x40, 0x00);
107 int sheet = (tile_id / tilesPerSheet) % 4 + 212;
108 int positionInSheet = tile_id % tilesPerSheet;
109 int rowInSheet = positionInSheet / tilesPerRow;
110 int columnInSheet = positionInSheet % tilesPerRow;
113 assert(sheet >= 212 && sheet <= 215);
116 for (
int y = 0; y < 8; ++y) {
117 for (
int x = 0; x < 8; ++x) {
120 int srcX = columnInSheet * tileWidth + x;
121 int srcY = (sheet * sheetHeight) + (rowInSheet * tileHeight) + y;
123 int src_index = (srcY * bufferWidth) + srcX;
124 int dest_index = y * tileWidth + x;
126 tile_data[dest_index] = graphics_buffer[src_index];
134 std::vector<uint8_t> tile_data_copy = tileData;
135 for (
int i = 0; i < 8; ++i) {
136 for (
int j = 0; j < 8; ++j) {
137 int src_index = i * 8 + j;
138 int dest_index = (7 - i) * 8 + j;
139 tile_data_copy[dest_index] = tileData[src_index];
142 tileData = tile_data_copy;
146 std::vector<uint8_t> tile_data_copy = tileData;
147 for (
int i = 0; i < 8; ++i) {
148 for (
int j = 0; j < 8; ++j) {
149 int src_index = i * 8 + j;
150 int dest_index = i * 8 + (7 - j);
151 tile_data_copy[dest_index] = tileData[src_index];
154 tileData = tile_data_copy;
160 std::vector tile_data_copy = tileData;
167 tileData = tile_data_copy;
170 void WriteTile(
int x,
int y,
const std::vector<uint8_t>& tileData) {
171 int tileDataOffset = 0;
173 const_cast<std::vector<uint8_t>&
>(tileData),
191 const uint8_t* graphics_buffer,
int width,
int height,
TileType tile_type,
Represents a bitmap image.
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Tile composition of four 8x8 tiles.
SNES 16-bit tile metadata container.
Represents a tilesheet, which is a collection of tiles stored in a bitmap.
auto set_palette(gfx::SnesPalette &palette)
std::vector< InternalTile16 > tile_info_
std::vector< uint8_t > FetchTileDataFromGraphicsBuffer(const std::vector< uint8_t > &graphics_buffer, int tile_id)
gfx::SnesPalette palette_
void ComposeAndPlaceTilePart(const std::vector< uint8_t > &graphics_buffer, const TileInfo &tile_info, int baseX, int baseY)
Tilesheet(std::shared_ptr< Bitmap > bitmap, int tileWidth, int tileHeight, TileType tile_type)
void WriteTile(int x, int y, const std::vector< uint8_t > &tileData)
void MirrorTileDataHorizontally(std::vector< uint8_t > &tileData)
void Init(int width, int height, TileType tile_type)
Bitmap GetTile16(int tile_x, int tile_y)
Bitmap GetTile16(int tile_id)
void MirrorTileDataVertically(std::vector< uint8_t > &tileData)
void MirrorTileData(std::vector< uint8_t > &tileData, bool mirrorX, bool mirrorY)
void ComposeTile16(const std::vector< uint8_t > &graphics_buffer, const TileInfo &top_left, const TileInfo &top_right, const TileInfo &bottom_left, const TileInfo &bottom_right)
Bitmap GetTile(int tileX, int tileY, int bmp_width, int bmp_height)
int CalculateTileIndex(int x, int y)
std::vector< uint8_t > internal_data_
void CopyTile(int srcX, int srcY, int destX, int destY, bool mirrorX=false, bool mirrorY=false)
std::shared_ptr< Bitmap > bitmap_
absl::StatusOr< Tilesheet > CreateTilesheetFromGraphicsBuffer(const uint8_t *graphics_buffer, int width, int height, TileType tile_type, int sheet_id)
std::array< TileInfo, 4 > tiles