29 assert(bpp >= 1 && bpp <= 8);
30 unsigned int bpp_pos[8];
31 for (
int col = 0; col < 8; col++) {
32 for (
int row = 0; row < 8; row++) {
34 tile.
data[col * 8 + row] = (data[offset + col] >> (7 - row)) & 0x01;
41 bpp_pos[0] = offset + col * 2;
42 bpp_pos[1] = offset + col * 2 + 1;
43 char mask = 1 << (7 - row);
44 tile.
data[col * 8 + row] = (data[bpp_pos[0]] & mask) == mask;
45 tile.
data[col * 8 + row] |= (uint8_t)((data[bpp_pos[1]] & mask) == mask)
50 bpp_pos[2] = offset + 16 + col;
51 tile.
data[col * 8 + row] |= (uint8_t)((data[bpp_pos[2]] & mask) == mask)
57 bpp_pos[2] = offset + 16 + col * 2;
58 bpp_pos[3] = offset + 16 + col * 2 + 1;
59 tile.
data[col * 8 + row] |= (uint8_t)((data[bpp_pos[2]] & mask) == mask)
61 tile.
data[col * 8 + row] |= (uint8_t)((data[bpp_pos[3]] & mask) == mask)
65 bpp_pos[4] = offset + 32 + col * 2;
66 bpp_pos[5] = offset + 32 + col * 2 + 1;
67 bpp_pos[6] = offset + 48 + col * 2;
68 bpp_pos[7] = offset + 48 + col * 2 + 1;
69 tile.
data[col * 8 + row] |= (uint8_t)((data[bpp_pos[4]] & mask) == mask)
71 tile.
data[col * 8 + row] |= (uint8_t)((data[bpp_pos[5]] & mask) == mask)
73 tile.
data[col * 8 + row] |= (uint8_t)((data[bpp_pos[6]] & mask) == mask)
75 tile.
data[col * 8 + row] |= (uint8_t)((data[bpp_pos[7]] & mask) == mask)
85 std::vector<uint8_t> output(bpp * 8, 0);
86 unsigned maxcolor = 2 << bpp;
89 for (
unsigned int col = 0; col < 8; col++) {
90 for (
unsigned int row = 0; row < 8; row++) {
91 uint8_t color = tile.
data[col * 8 + row];
92 if (color > maxcolor) {
93 throw std::invalid_argument(
"Invalid color value.");
97 if (bpp == 1) output[col] += (uint8_t)((color & 1) << (7 - row));
101 output[col * 2] += (uint8_t)((color & 1) << (7 - row));
102 output[col * 2 + 1] +=
103 (uint8_t)((uint8_t)((color & 2) == 2) << (7 - row));
108 output[16 + col] += (uint8_t)(((color & 4) == 4) << (7 - row));
112 output[16 + col * 2] += (uint8_t)(((color & 4) == 4) << (7 - row));
113 output[16 + col * 2 + 1] += (uint8_t)(((color & 8) == 8) << (7 - row));
118 output[32 + col * 2] += (uint8_t)(((color & 16) == 16) << (7 - row));
119 output[32 + col * 2 + 1] +=
120 (uint8_t)(((color & 32) == 32) << (7 - row));
121 output[48 + col * 2] += (uint8_t)(((color & 64) == 64) << (7 - row));
122 output[48 + col * 2 + 1] +=
123 (uint8_t)(((color & 128) == 128) << (7 - row));
130std::vector<uint8_t>
ConvertBpp(
const std::vector<uint8_t>& tiles,
131 uint32_t from_bpp, uint32_t to_bpp) {
132 unsigned int nb_tile = tiles.size() / (from_bpp * 8);
133 std::vector<uint8_t> converted(nb_tile * to_bpp * 8);
135 for (
unsigned int i = 0; i < nb_tile; i++) {
137 std::vector<uint8_t> packed_tile =
PackBppTile(tile, to_bpp);
138 std::memcpy(converted.data() + i * to_bpp * 8, packed_tile.data(),
159 int buffer_size = 0x1000;
164 buffer_size = 0x2000;
165 }
else if (bpp == 3) {
167 }
else if (bpp == 4) {
169 buffer_size = 0x4000;
170 }
else if (bpp == 8) {
174 if (num_sheets != 1) {
175 num_tiles *= num_sheets;
176 buffer_size *= num_sheets;
179 std::vector<uint8_t> sheet_buffer_out(buffer_size);
181 for (
int i = 0; i < num_tiles; i++) {
182 for (
int y = 0; y < 8; y++) {
183 for (
int x = 0; x < 8; x++) {
194 if (b3 != 0 && bpp != 16) {
197 sheet_buffer_out[x + xx + (y * 128) + (yy * 1024)] = b;
209 return sheet_buffer_out;
225 auto buffer = std::vector<uint8_t>(data.size());
226 std::vector<std::vector<uint8_t>> bitmap_data;
227 bitmap_data.resize(0x80);
228 for (
auto& each : bitmap_data) {
235 const uint16_t sheet_width = 128;
241 for (
int i = 0; i < 4096; i++) {
243 for (
int y = 0; y < 8; y++) {
245 for (
int x = 0; x < 8; x++) {
246 const uint16_t bitmask[] = {0x80, 0x40, 0x20, 0x10,
247 0x08, 0x04, 0x02, 0x01};
248 auto b1 = (data[(y * 2) + ((bpp * 8) * pos)] & (bitmask[x]));
249 auto b2 = (data[((y * 2) + ((bpp * 8) * pos)) + 1] & (bitmask[x]));
250 auto b3 = (data[(y * 2) + ((bpp * 8) * pos) + 16] & (bitmask[x]));
251 auto b4 = (data[(y * 2) + ((bpp * 8) * pos) + 17] & (bitmask[x]));
252 auto b5 = (data[(y * 2) + ((bpp * 8) * pos) + 32] & (bitmask[x]));
253 auto b6 = (data[(y * 2) + ((bpp * 8) * pos) + 33] & (bitmask[x]));
254 auto b7 = (data[(y * 2) + ((bpp * 8) * pos) + 48] & (bitmask[x]));
255 auto b8 = (data[(y * 2) + ((bpp * 8) * pos) + 49] & (bitmask[x]));
287 bitmap_data[x + xx][y + (yy * 8)] = b;
302 for (
int y = 0; y < (data.size() / 64); y++) {
303 for (
int x = 0; x < sheet_width; x++) {
304 if (n < data.size()) {
306 buffer[n] = bitmap_data[x][y];
333 uint16_t
id = word & 0x3FF;
336 bool vertical_mirror = (word >> 15) & 0x01;
337 bool horizontal_mirror = (word >> 14) & 0x01;
338 bool over = (word >> 13) & 0x01;
341 uint8_t palette = (word >> 10) & 0x07;
343 return TileInfo(
id, palette, vertical_mirror, horizontal_mirror, over);
390 std::vector<uint8_t>& blockset) {
392 ((tile - ((tile / 0x08) * 0x08)) * 0x10) + ((tile / 0x08) * 2048);
393 int dest_pos = (x + (y * 0x200));
394 for (
int yy = 0; yy < 0x10; yy++) {
395 for (
int xx = 0; xx < 0x10; xx++) {
396 bitmap[dest_pos + xx + (yy * 0x200)] =
397 blockset[src_pos + xx + (yy * 0x80)];