diff --git a/flif-cli/src/main.rs b/flif-cli/src/main.rs index 27c4f33..6fccdcb 100644 --- a/flif-cli/src/main.rs +++ b/flif-cli/src/main.rs @@ -28,7 +28,9 @@ enum Command { #[structopt(name = "decode")] Decode { #[structopt( - short = "i", long = "identify", help = "don't decode, just identify the input FLIF" + short = "i", + long = "identify", + help = "don't decode, just identify the input FLIF" )] identify: bool, #[structopt(name = "INPUT", help = "Input file")] diff --git a/flif/src/colors.rs b/flif/src/colors.rs index bc750bd..f94d101 100644 --- a/flif/src/colors.rs +++ b/flif/src/colors.rs @@ -12,9 +12,9 @@ pub enum Channel { #[derive(PartialEq, Eq, Debug, Clone, Copy)] pub enum ColorSpace { - Monochrome, - RGB, - RGBA, + Monochrome = 1, + RGB = 3, + RGBA = 4, } pub type Pixel = ChannelSet; diff --git a/flif/src/components/transformations/channel_compact.rs b/flif/src/components/transformations/channel_compact.rs index ae8e58a..fd48617 100644 --- a/flif/src/components/transformations/channel_compact.rs +++ b/flif/src/components/transformations/channel_compact.rs @@ -28,7 +28,7 @@ impl ChannelCompact { let t_range = transformation.range(c); t.ranges[c].max = rac.read_near_zero(0, t_range.max - t_range.min, &mut context)?; let mut min = t_range.min; - for i in 0..t.ranges[c].max { + for i in 0..t.ranges[c].max + 1 { t.decompacted[c].push( min + rac.read_near_zero( 0, @@ -36,7 +36,7 @@ impl ChannelCompact { &mut context, )?, ); - min = t.decompacted[c][i as usize]; + min = t.decompacted[c][i as usize] + 1; } } diff --git a/flif/tests/channel_compact.rs b/flif/tests/channel_compact.rs new file mode 100644 index 0000000..90535f0 --- /dev/null +++ b/flif/tests/channel_compact.rs @@ -0,0 +1,27 @@ +extern crate flif; + +use std::fs::File; +use std::io::BufReader; + +use flif::components::Transformation; +use flif::Decoder; + +#[test] +fn invalid_tree() { + let file = BufReader::new(File::open("../resources/invalid_tree.flif").unwrap()); + let image = Decoder::new(file).unwrap(); + let info = image.info(); + + let expected = vec![Transformation::ChannelCompact]; + assert_eq!(expected, info.second_header.transformations); +} + +#[test] +fn invalid_transform() { + let file = BufReader::new(File::open("../resources/invalid_tid.flif").unwrap()); + let image = Decoder::new(file).unwrap(); + let info = image.info(); + + let expected = vec![Transformation::ChannelCompact]; + assert_eq!(expected, info.second_header.transformations); +} diff --git a/resources/invalid_tid.flif b/resources/invalid_tid.flif new file mode 100644 index 0000000..b9f2d4d Binary files /dev/null and b/resources/invalid_tid.flif differ diff --git a/resources/invalid_tree.flif b/resources/invalid_tree.flif new file mode 100644 index 0000000..2a50615 Binary files /dev/null and b/resources/invalid_tree.flif differ