Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spoutn1k committed Aug 3, 2024
1 parent 3ffc54a commit ef80908
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions tests/encode_images_with_compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tiff::{
encoder::{
colortype::{self, ColorType},
compression::*,
TiffEncoder, TiffValue,
Compression, TiffEncoder, TiffValue,
},
};

Expand All @@ -18,15 +18,12 @@ trait TestImage<const NUM_CHANNELS: usize>: From<Vec<<Self::Color as ColorType>:
fn reference_data(&self) -> &[<Self::Color as ColorType>::Inner];
fn generate_pixel(x: u32, y: u32) -> [<Self::Color as ColorType>::Inner; NUM_CHANNELS];

fn compress<C: Compression, W: Write + Seek>(
&self,
encoder: &mut TiffEncoder<W>,
compression: C,
) where
fn compress<W: Write + Seek>(&self, encoder: &mut TiffEncoder<W>)
where
[<Self::Color as ColorType>::Inner]: TiffValue,
{
let image = encoder
.new_image_with_compression::<Self::Color, C>(Self::WIDTH, Self::HEIGHT, compression)
.new_image::<Self::Color>(Self::WIDTH, Self::HEIGHT)
.unwrap();
image.write_data(self.reference_data()).unwrap();
}
Expand Down Expand Up @@ -94,7 +91,7 @@ impl TestImage<1> for TestImageGrayscale {
}
}

fn encode_decode_with_compression<C: Compression + Clone>(compression: C) {
fn encode_decode_with_compression(compression: Compression) {
let mut data = Cursor::new(Vec::new());

let image_rgb = TestImageColor::generate();
Expand All @@ -103,9 +100,11 @@ fn encode_decode_with_compression<C: Compression + Clone>(compression: C) {
// Encode tiff with compression
{
// Create a multipage image with 2 images
let mut encoder = TiffEncoder::new(&mut data).unwrap();
image_rgb.compress(&mut encoder, compression.clone());
image_grayscale.compress(&mut encoder, compression);
let mut encoder = TiffEncoder::new(&mut data)
.unwrap()
.with_compression(compression);
image_rgb.compress(&mut encoder);
image_grayscale.compress(&mut encoder);
}

// Decode tiff
Expand Down Expand Up @@ -136,22 +135,22 @@ fn encode_decode_with_compression<C: Compression + Clone>(compression: C) {

#[test]
fn encode_decode_without_compression() {
encode_decode_with_compression(Uncompressed::default());
encode_decode_with_compression(Compression::Uncompressed);
}

#[test]
fn encode_decode_with_lzw() {
encode_decode_with_compression(Lzw::default());
encode_decode_with_compression(Compression::Lzw);
}

#[test]
fn encode_decode_with_deflate() {
encode_decode_with_compression(Deflate::with_level(DeflateLevel::Fast));
encode_decode_with_compression(Deflate::with_level(DeflateLevel::Balanced));
encode_decode_with_compression(Deflate::with_level(DeflateLevel::Best));
encode_decode_with_compression(Compression::Deflate(DeflateLevel::Fast));
encode_decode_with_compression(Compression::Deflate(DeflateLevel::Balanced));
encode_decode_with_compression(Compression::Deflate(DeflateLevel::Best));
}

#[test]
fn encode_decode_with_packbits() {
encode_decode_with_compression(Packbits::default());
encode_decode_with_compression(Compression::Packbits);
}

0 comments on commit ef80908

Please sign in to comment.