Skip to content

Commit

Permalink
now spitting out byte data in asm format
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume committed Sep 24, 2021
1 parent cf80f06 commit ae104aa
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 9 deletions.
9 changes: 4 additions & 5 deletions samples_cbm/petscii_tile/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ NAME = p128

project.av: p128-ref-template.png
$(ALOEVERA) create project project.av
$(ALOEVERA) -p project.av palette import cbm_palette p128-ref-template.png
$(ALOEVERA) -p project.av imageset import test_set_1 4 8 p128-ref-template.png
$(ALOEVERA) -p project.av imageset format -v test_set_1 cbm_palette 8
# $(ALOEVERA) -p project.av asm ./output/ all
# $(ALOEVERA) -p project.av asm -f ca65 ./output/ all
$(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

generate_resources: project.av

Expand Down
Binary file not shown.
Binary file added 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.
5 changes: 5 additions & 0 deletions src/bin/aloevera.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ subcommands:
- input_file:
help: Input Imageset PNG file name
index: 4
- keep_duplicates:
help: Don't cull duplicate frames
long: keep_duplicates
short: k
takes_value: false
- format:
about: Formats an imageset to a target depth with a given palette
args:
Expand Down
7 changes: 6 additions & 1 deletion src/cmd/imageset/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ pub struct ImageSetImportArgs {
pub input_file: String,
pub frame_width: u32,
pub frame_height: u32,
pub keep_duplicates: bool,
}

/// Imageset import command
pub fn imageset_import(g_args: &GlobalArgs, args: &ImageSetImportArgs) -> Result<(), Error> {
let png_bytes = common::read_file_bin(&args.input_file)?;
let config = VeraImageSetLoadConfig::default();
let mut config = VeraImageSetLoadConfig::default();
if args.keep_duplicates {
config.cull_duplicates = false;
}
let mut imageset = VeraImageSet::new(&args.id, args.frame_width, args.frame_height);
imageset.load_from_png(png_bytes, &config)?;
insert_imageset(g_args.project_file.clone(), &args.id, &imageset)?;
Expand Down Expand Up @@ -86,6 +90,7 @@ pub fn imageset_format(g_args: &GlobalArgs, args: &ImageSetFormatArgs) -> Result
}
if palette.entries.len() != 16 {
let msg = format!("Palettes used to format Vic2 Multicolour Tiled mode Imagesets MUST have only 16 colours");
return Err(ErrorKind::ArgumentError(msg).into());
}
}
imageset.format_indices(&palette, pixel_depth)?;
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/imageset/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ pub fn parse_imageset_import_args(
let v = common::parse_required(args, "frame_height")?;
let frame_height = common::parse_u64(&v, "frame_height")?;
let id = common::parse_required(args, "id")?;
let keep_duplicates = args.is_present("keep_duplicates");
Ok(ImageSetImportArgs {
id: id.into(),
frame_height: frame_height as u32,
frame_width: frame_width as u32,
input_file: input_file.into(),
keep_duplicates,
})
}

Expand Down
108 changes: 105 additions & 3 deletions vera/src/imageset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,114 @@ impl VeraImageSet {
Ok(())
}

/// Assemble vic2 bpm information using the given number of chunks
pub fn assemble_vic2_bmp(
&self,
tiles_per_copy_x: u8,
tiles_per_copy_y: u8,
tiles_per_copy_x: usize,
tiles_per_copy_y: usize,
) -> Result<AssembledPrimitive, Error> {
let retval = AssembledPrimitive::new(self.id());
let mut retval = AssembledPrimitive::new(self.id());
retval.add_meta(format!(
"copy size is {} x {} 4x8 tiles",
tiles_per_copy_x, tiles_per_copy_y
));
let mut out_count = 0;
let mut cur_out_byte = 0u8;
let mut cur_val_count = 0;
let depth = match self.depth {
Some(d) => d,
None => {
return Err(ErrorKind::ImageSetNotFormatted(format!("{}", self.id)).into());
}
};
// build a list representing the order in which we'll traverse the individual tiles
let mut traversal_list = vec![];
let mut cur_x = 0;
let mut cur_y = 0;
let mut cur_block_start_x = 0;
let mut cur_block_start_y = 0;
while cur_x < self.frames_per_row && cur_y < self.frames_per_col {
traversal_list.push((cur_x, cur_y));
cur_x += 1;
if cur_x as usize % tiles_per_copy_x == 0 {
cur_x = cur_block_start_x;
cur_y += 1;
if cur_y as usize % tiles_per_copy_y == 0 {
cur_block_start_x += tiles_per_copy_x as u32;
cur_x = cur_block_start_x;
cur_y = cur_block_start_y;
}
if cur_x >= self.frames_per_row {
cur_block_start_y += tiles_per_copy_y as u32;
cur_y = cur_block_start_y;
cur_block_start_x = 0;
cur_x = 0;
}
}
}
trace!(
"Tiles will be traversed in this order: {:?}",
traversal_list
);
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
let mut used_palette_entries = vec![0];
for p in frame.data.iter() {
let index = match p.pal_index {
Some(i) => i,
None => return Err(ErrorKind::PaletteIndexMissing(0, 0, 0).into()),
};
if !used_palette_entries.contains(&index) {
used_palette_entries.push(index);
}
}

for pixel in frame.data.iter() {
let pal_index = match pixel.pal_index {
Some(p) => p,
None => {
return Err(ErrorKind::ImageSetNotFormatted(format!("{}", self.id)).into())
}
};
if self.depth == Some(VeraPixelDepth::BPP4) {
if pal_index > 15 {
let msg = format!(
"Unexpected value in {}, {} in BPP4 mode",
self.id, pal_index
);
return Err(ErrorKind::UnexpectedDepthError(msg).into());
}
// transform colour entries into bit pairs
cur_out_byte <<= 2;
let actual_out = used_palette_entries
.iter()
.position(|&r| r == pal_index)
.unwrap() as u8;
cur_out_byte |= actual_out;
cur_val_count += 1;
}
if cur_val_count == 4 {
retval.add_data(&[cur_out_byte]);
cur_out_byte = 0u8;
cur_val_count = 0;
out_count += 1;
}
}
}
if out_count != self.size() / 2 {
return Err(ErrorKind::ImageSizeMismatch(out_count, self.size()).into());
}
retval.add_meta(format!(
"each {} color cell x {} color cell 'tile' is {} bytes",
tiles_per_copy_x,
tiles_per_copy_y,
self.frame_height
* self.frame_width
* tiles_per_copy_x as u32
* tiles_per_copy_y as u32
/ depth as u32
));
Ok(retval)
}
}
Expand Down

0 comments on commit ae104aa

Please sign in to comment.