16 const uint8_t* graphics_buffer,
int width,
int height,
TileType tile_type,
21 int sheet_offset = sheet_id * width * height;
24 tilesheet.
Init(width, height, tile_type);
27 for (
int row = 0; row < height; ++row) {
28 for (
int col = 0; col < width; ++col) {
30 int tile_index = sheet_offset + (row * width + col) * 64;
33 for (
int y = 0; y < 8; ++y) {
34 for (
int x = 0; x < 8; ++x) {
35 int src_index = tile_index + (y * 8 + x);
36 int dest_x = col * 8 + x;
37 int dest_y = row * 8 + y;
38 int dest_index = (dest_y * width * 8) + dest_x;
40 graphics_buffer[src_index];
50 bitmap_ = std::make_shared<Bitmap>(width, height, 8, 0x20000);
66 const TileInfo& bottom_right,
int sheet_offset) {
71 int tile16_column =
num_tiles_ % tiles_per_row;
82 tile_info_.push_back({top_left, top_right, bottom_left, bottom_right});
91 const TileInfo& bottom_right,
int tile_id,
96 int tile16_row = tile_id / tiles_per_row;
97 int tile16_column = tile_id % tiles_per_row;
108 tile_info_[tile_id] = {top_left, top_right, bottom_left, bottom_right};
112 const std::vector<uint8_t>& graphics_buffer,
const TileInfo& tile_info,
113 int base_x,
int base_y) {
114 std::vector<uint8_t> tile_data =
125 for (
int y = 0; y < 8; ++y) {
126 for (
int x = 0; x < 8; ++x) {
127 int src_index = y * 8 + x;
128 int dest_x = base_x + x;
129 int dest_y = base_y + y;
130 int dest_index = (dest_y *
bitmap_->width()) + dest_x;
139 const std::vector<uint8_t>& graphics_buffer,
int tile_id) {
142 const int buffer_width = 128;
143 const int sheet_height = 32;
145 const int tiles_per_row = buffer_width /
tile_width;
146 const int rows_per_sheet = sheet_height /
tile_height;
147 const int tiles_per_sheet = tiles_per_row * rows_per_sheet;
150 std::vector<uint8_t> tile_data(0x40, 0x00);
152 int position_in_sheet = tile_id % tiles_per_sheet;
153 int row_in_sheet = position_in_sheet / tiles_per_row;
154 int column_in_sheet = position_in_sheet % tiles_per_row;
160 for (
int y = 0; y < 8; ++y) {
161 for (
int x = 0; x < 8; ++x) {
164 int src_y = (sheet * sheet_height) + (row_in_sheet *
tile_height) + y;
166 int src_index = (src_y * buffer_width) + src_x;
169 tile_data[dest_index] = graphics_buffer[src_index];
177 std::vector<uint8_t> tile_data_copy = tile_data;
178 for (
int i = 0; i < 8; ++i) {
179 for (
int j = 0; j < 8; ++j) {
180 int src_index = i * 8 + j;
181 int dest_index = (7 - i) * 8 + j;
182 tile_data_copy[dest_index] = tile_data[src_index];
185 tile_data = tile_data_copy;
189 std::vector<uint8_t> tile_data_copy = tile_data;
190 for (
int i = 0; i < 8; ++i) {
191 for (
int j = 0; j < 8; ++j) {
192 int src_index = i * 8 + j;
193 int dest_index = i * 8 + (7 - j);
194 tile_data_copy[dest_index] = tile_data[src_index];
197 tile_data = tile_data_copy;
202 std::vector tile_data_copy = tile_data;
209 tile_data = tile_data_copy;
SNES 16-bit tile metadata container.
Represents a tilesheet, which is a collection of tiles stored in a bitmap.
std::vector< InternalTile16 > tile_info_
std::vector< uint8_t > FetchTileDataFromGraphicsBuffer(const std::vector< uint8_t > &graphics_buffer, int tile_id)
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 Init(int width, int height, TileType tile_type)
void MirrorTileDataVertically(std::vector< uint8_t > &tileData)
void MirrorTileData(std::vector< uint8_t > &tileData, bool mirror_x, bool mirror_y)
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)
std::vector< uint8_t > internal_data_
std::shared_ptr< Bitmap > 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)
absl::StatusOr< Tilesheet > CreateTilesheetFromGraphicsBuffer(const uint8_t *graphics_buffer, int width, int height, TileType tile_type, int sheet_id)