Skip to content

Commit

Permalink
catch color cell errors consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume committed Sep 26, 2021
1 parent 6f36ee2 commit 92d72ec
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
4 changes: 2 additions & 2 deletions samples_cbm/petscii_tile/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ NAME = p128

project.av: p128-ref-template.png
$(ALOEVERA) create project project.av
$(ALOEVERA) -p project.av palette import cbm_palette p128-temp-tileset.png
$(ALOEVERA) -p project.av imageset import -k test_set_1 4 8 p128-temp-tileset.png
$(ALOEVERA) -p project.av palette import cbm_palette p128-ref-template-short.png
$(ALOEVERA) -p project.av imageset import -k test_set_1 4 8 p128-ref-template-short.png
$(ALOEVERA) -p project.av imageset format -v test_set_1 cbm_palette 4
$(ALOEVERA) -p project.av asm -f ca65 ./output/ all
$(ALOEVERA) -p project.av asm -f bin ./output/ all
Expand Down
Binary file modified samples_cbm/petscii_tile/p128-ref-template-short.aseprite
Binary file not shown.
Binary file modified samples_cbm/petscii_tile/p128-ref-template-short.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions vera/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ pub enum ErrorKind {
BitmapNoImageSet(String),
/// VIC Color Bitmap more error constraint
#[fail(
display = "VIC Multicolor BMP formatting, each cell must only contain palette index 0 + 3 distinct colors at index {}",
_0
display = "VIC Multicolor BMP formatting - each color cell must only contain palette index 0 (black), 1 (white) + 2 distinct colors max at color cell coordinate ({},{})",
_0, _1
)]
VICColorBMP(usize),
VICColorBMP(usize, usize),
/// Other
#[fail(display = "Generic error: {}", _0)]
GenericError(String),
Expand Down
27 changes: 23 additions & 4 deletions vera/src/imageset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,16 @@ impl VeraImageSet {
Some(i) => i,
None => return Err(ErrorKind::PaletteIndexMissing(0, 0, 0).into()),
};
if !used_palette_entries.contains(&index) {
// White doesn't count towards color count, output here will assume that
// color ram is just being blanked to white
if !used_palette_entries.contains(&index) && index != 1 {
used_palette_entries.push(index);
}
}
if used_palette_entries.len() > 4 {
return Err(ErrorKind::VICColorBMP(frame_index).into());
if used_palette_entries.len() > 3 {
let x_coord = frame_index % self.frames_per_row as usize;
let y_coord = (frame_index as f32 / self.frames_per_row as f32).floor();
return Err(ErrorKind::VICColorBMP(x_coord, y_coord as usize).into());
}
}
}
Expand Down Expand Up @@ -597,6 +601,10 @@ impl VeraImageSet {
"Tiles will be traversed in this order: {:?}",
traversal_list
);
let mut color_buffer = vec![0u8; (self.frames_per_row * self.frames_per_col) as usize];
let cells_per_tile = tiles_per_copy_x * tiles_per_copy_y;
let mut start_tile_color_index = 0;
let mut tiles_copied = 0;
for list_entry in traversal_list {
let frame = self.frame_at_coord(list_entry.0 as usize, list_entry.1 as usize)?;
// organize palette entries for the frame in the order they appear
Expand Down Expand Up @@ -635,7 +643,17 @@ impl VeraImageSet {
color_byte |= *c.0;
}

retval.add_alt_data(&[color_byte]);
let cell_position = tiles_copied % cells_per_tile;
let output_position = start_tile_color_index
+ cell_position * self.frames_per_col as usize / tiles_per_copy_x
* self.frames_per_row as usize
/ tiles_per_copy_y;
color_buffer[output_position] = color_byte;

tiles_copied += 1;
if tiles_copied % cells_per_tile == 0 {
start_tile_color_index += 1;
}

for pixel in frame.data.iter() {
let pal_index = match pixel.pal_index {
Expand Down Expand Up @@ -674,6 +692,7 @@ impl VeraImageSet {
if out_count != self.size() / 2 {
return Err(ErrorKind::ImageSizeMismatch(out_count, self.size()).into());
}
retval.add_alt_data(&color_buffer);
retval.add_meta(format!(
"each {} color cell x {} color cell 'tile' is {} bytes",
tiles_per_copy_x,
Expand Down

0 comments on commit 92d72ec

Please sign in to comment.