Generate a bytestring for the image converter rather than the array

This commit is contained in:
Gwilym Kuiper 2022-03-21 22:41:11 +00:00
parent 3c09a86f88
commit d4a12277eb

View file

@ -1,6 +1,6 @@
use crate::image_loader::Image;
use crate::palette16::Palette16OptimisationResults;
use crate::TileSize;
use crate::{image_loader::Image, ByteString};
use proc_macro2::TokenStream;
use quote::{format_ident, quote};
@ -45,11 +45,11 @@ pub(crate) fn generate_code(
for x in 0..tiles_x {
let palette_index = results.assignments[y * tiles_x + x];
let palette = &results.optimised_palettes[palette_index];
for inner_y in 0..tile_size / 8 {
for inner_x in 0..tile_size / 8 {
for j in inner_y * 8..inner_y * 8 + 8 {
for i in (inner_x * 8..inner_x * 8 + 8).rev() {
for j in inner_y * 8..inner_y * 8 + 8 {
for i in inner_x * 8..inner_x * 8 + 8 {
let colour = image.colour(x * tile_size + i, y * tile_size + j);
tile_data.push(palette.colour_index(colour));
}
@ -59,8 +59,12 @@ pub(crate) fn generate_code(
}
}
let tile_data = tile_data.chunks(8)
.map(|chunk| chunk.iter().fold(0u32, |acc, &x| (acc << 4) | (x as u32)));
let tile_data: Vec<_> = tile_data
.chunks(2)
.map(|chunk| (chunk[1] << 4) | chunk[0])
.collect();
let data = ByteString(&tile_data);
let assignments = results.assignments.iter().map(|&x| x as u8);
@ -73,9 +77,7 @@ pub(crate) fn generate_code(
#(#palette_data),*
];
const TILE_DATA: &[u32] = &[
#(#tile_data),*
];
const TILE_DATA: &[u8] = #data;
const PALETTE_ASSIGNMENT: &[u8] = &[
#(#assignments),*