13 const uint8_t* graphics_buffer,
int width,
int height,
TileType tile_type,
18 int sheet_offset = sheet_id * width * height;
21 tilesheet.
Init(width, height, tile_type);
24 for (
int row = 0; row < height; ++row) {
25 for (
int col = 0; col < width; ++col) {
27 int tile_index = sheet_offset + (row * width + col) * 64;
30 for (
int y = 0; y < 8; ++y) {
31 for (
int x = 0; x < 8; ++x) {
32 int src_index = tile_index + (y * 8 + x);
33 int dest_x = col * 8 + x;
34 int dest_y = row * 8 + y;
35 int dest_index = (dest_y * width * 8) + dest_x;
37 graphics_buffer[src_index];
47 bitmap_ = std::make_shared<Bitmap>(width, height, 8, 0x20000);
63 const TileInfo& bottom_right,
int sheet_offset) {
68 int tile16_column =
num_tiles_ % tiles_per_row;
79 tile_info_.push_back({top_left, top_right, bottom_left, bottom_right});
88 const TileInfo& bottom_right,
int tile_id,
93 int tile16_row = tile_id / tiles_per_row;
94 int tile16_column = tile_id % tiles_per_row;
105 tile_info_[tile_id] = {top_left, top_right, bottom_left, bottom_right};
110 int base_x,
int base_y) {
111 std::vector<uint8_t> tile_data =
122 for (
int y = 0; y < 8; ++y) {
123 for (
int x = 0; x < 8; ++x) {
124 int src_index = y * 8 + x;
125 int dest_x = base_x + x;
126 int dest_y = base_y + y;
127 int dest_index = (dest_y *
bitmap_->width()) + dest_x;
136 const std::vector<uint8_t>& graphics_buffer,
int tile_id) {
139 const int buffer_width = 128;
140 const int sheet_height = 32;
142 const int tiles_per_row = buffer_width /
tile_width;
143 const int rows_per_sheet = sheet_height /
tile_height;
144 const int tiles_per_sheet = tiles_per_row * rows_per_sheet;
147 std::vector<uint8_t> tile_data(0x40, 0x00);
149 int position_in_sheet = tile_id % tiles_per_sheet;
150 int row_in_sheet = position_in_sheet / tiles_per_row;
151 int column_in_sheet = position_in_sheet % tiles_per_row;
157 for (
int y = 0; y < 8; ++y) {
158 for (
int x = 0; x < 8; ++x) {
161 int src_y = (sheet * sheet_height) + (row_in_sheet *
tile_height) + y;
163 int src_index = (src_y * buffer_width) + src_x;
166 tile_data[dest_index] = graphics_buffer[src_index];
174 std::vector<uint8_t> tile_data_copy = tile_data;
175 for (
int i = 0; i < 8; ++i) {
176 for (
int j = 0; j < 8; ++j) {
177 int src_index = i * 8 + j;
178 int dest_index = (7 - i) * 8 + j;
179 tile_data_copy[dest_index] = tile_data[src_index];
182 tile_data = tile_data_copy;
186 std::vector<uint8_t> tile_data_copy = tile_data;
187 for (
int i = 0; i < 8; ++i) {
188 for (
int j = 0; j < 8; ++j) {
189 int src_index = i * 8 + j;
190 int dest_index = i * 8 + (7 - j);
191 tile_data_copy[dest_index] = tile_data[src_index];
194 tile_data = tile_data_copy;
199 std::vector tile_data_copy = tile_data;
206 tile_data = tile_data_copy;
SNES 16-bit tile metadata container.
Represents a tilesheet, which is a collection of tiles stored in a bitmap.
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, int sheet_offset=0)
std::vector< uint8_t > internal_data_
std::shared_ptr< Bitmap > bitmap_
void MirrorTileDataVertically(std::vector< uint8_t > &tileData)
std::vector< uint8_t > FetchTileDataFromGraphicsBuffer(const std::vector< uint8_t > &graphics_buffer, int tile_id)
std::vector< InternalTile16 > tile_info_
void ComposeAndPlaceTilePart(const std::vector< uint8_t > &graphics_buffer, const TileInfo &tile_info, int baseX, int baseY)
void MirrorTileDataHorizontally(std::vector< uint8_t > &tileData)
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)
void Init(int width, int height, TileType tile_type)
void MirrorTileData(std::vector< uint8_t > &tileData, bool mirror_x, bool mirror_y)
Contains classes for handling graphical data.
absl::StatusOr< Tilesheet > CreateTilesheetFromGraphicsBuffer(const uint8_t *graphics_buffer, int width, int height, TileType tile_type, int sheet_id)
Main namespace for the application.