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;
163 buffer_size = 0x2000;
164 }
else if (bpp == 3) {
166 }
else if (bpp == 4) {
168 buffer_size = 0x4000;
169 }
else if (bpp == 8) {
172 std::vector<uint8_t> sheet_buffer_out(buffer_size);
174 for (
int i = 0; i < num_tiles; i++) {
175 for (
int y = 0; y < 8; y++) {
176 for (
int x = 0; x < 8; x++) {
187 if (b3 != 0 && bpp != 16) {
190 sheet_buffer_out[x + xx + (y * 128) + (yy * 1024)] = b;
202 return sheet_buffer_out;
218 auto buffer = std::vector<uint8_t>(data.size());
219 std::vector<std::vector<uint8_t>> bitmap_data;
220 bitmap_data.resize(0x80);
221 for (
auto& each : bitmap_data) {
228 const uint16_t sheet_width = 128;
234 for (
int i = 0; i < 4096; i++) {
236 for (
int y = 0; y < 8; y++) {
238 for (
int x = 0; x < 8; x++) {
239 const uint16_t bitmask[] = {0x80, 0x40, 0x20, 0x10,
240 0x08, 0x04, 0x02, 0x01};
241 auto b1 = (data[(y * 2) + ((bpp * 8) * pos)] & (bitmask[x]));
242 auto b2 = (data[((y * 2) + ((bpp * 8) * pos)) + 1] & (bitmask[x]));
243 auto b3 = (data[(y * 2) + ((bpp * 8) * pos) + 16] & (bitmask[x]));
244 auto b4 = (data[(y * 2) + ((bpp * 8) * pos) + 17] & (bitmask[x]));
245 auto b5 = (data[(y * 2) + ((bpp * 8) * pos) + 32] & (bitmask[x]));
246 auto b6 = (data[(y * 2) + ((bpp * 8) * pos) + 33] & (bitmask[x]));
247 auto b7 = (data[(y * 2) + ((bpp * 8) * pos) + 48] & (bitmask[x]));
248 auto b8 = (data[(y * 2) + ((bpp * 8) * pos) + 49] & (bitmask[x]));
280 bitmap_data[x + xx][y + (yy * 8)] = b;
295 for (
int y = 0; y < (data.size() / 64); y++) {
296 for (
int x = 0; x < sheet_width; x++) {
297 if (n < data.size()) {
299 buffer[n] = bitmap_data[x][y];
326 uint16_t
id = word & 0x3FF;
329 bool vertical_mirror = (word >> 15) & 0x01;
330 bool horizontal_mirror = (word >> 14) & 0x01;
331 bool over = (word >> 13) & 0x01;
334 uint8_t palette = (word >> 10) & 0x07;
336 return TileInfo(
id, palette, vertical_mirror, horizontal_mirror, over);