1 // Copyright 2024 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #[path = "./mod.rs"]
16 mod tests;
17
18 use crabby_avif::reformat::rgb::*;
19 use image::ImageReader;
20 use tests::*;
21
22 #[test_case::test_case("paris_identity.avif", "paris_icc_exif_xmp.png"; "lossless_identity")]
23 #[test_case::test_case("paris_ycgco_re.avif", "paris_icc_exif_xmp.png"; "lossless_ycgco_re")]
lossless(avif_file: &str, png_file: &str)24 fn lossless(avif_file: &str, png_file: &str) {
25 let mut decoder = get_decoder(avif_file);
26 assert!(decoder.parse().is_ok());
27 if !HAS_DECODER {
28 return;
29 }
30 assert!(decoder.next_image().is_ok());
31 let decoded = decoder.image().expect("image was none");
32 let mut rgb = Image::create_from_yuv(decoded);
33 rgb.depth = 8;
34 rgb.format = Format::Rgb;
35 assert!(rgb.allocate().is_ok());
36 assert!(rgb.convert_from_yuv(decoded).is_ok());
37
38 let source = ImageReader::open(get_test_file(png_file));
39 let source = source.unwrap().decode().unwrap();
40
41 assert_eq!(
42 source.as_bytes(),
43 rgb.pixels
44 .as_ref()
45 .unwrap()
46 .slice(0, source.as_bytes().len() as u32)
47 .unwrap()
48 );
49 }
50