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] iloc_extents()23fn iloc_extents() { 24 let mut decoder = get_decoder("sacre_coeur_2extents.avif"); 25 assert!(decoder.parse().is_ok()); 26 if !HAS_DECODER { 27 return; 28 } 29 assert!(decoder.next_image().is_ok()); 30 let decoded = decoder.image().expect("image was none"); 31 let mut rgb = Image::create_from_yuv(decoded); 32 rgb.format = Format::Rgb; 33 assert!(rgb.allocate().is_ok()); 34 assert!(rgb.convert_from_yuv(decoded).is_ok()); 35 36 let source = ImageReader::open(get_test_file("sacre_coeur.png")); 37 let source = source.unwrap().decode().unwrap(); 38 39 // sacre_coeur_2extents.avif was generated with 40 // avifenc --lossless --ignore-exif --ignore-xmp --ignore-icc sacre_coeur.png 41 // so pixels can be compared byte by byte. 42 assert_eq!( 43 source.as_bytes(), 44 rgb.pixels 45 .as_ref() 46 .unwrap() 47 .slice(0, source.as_bytes().len() as u32) 48 .unwrap() 49 ); 50 } 51 52 #[test] nth_image_max_extent()53fn nth_image_max_extent() { 54 let mut decoder = get_decoder("sacre_coeur_2extents.avif"); 55 assert!(decoder.parse().is_ok()); 56 57 let max_extent = decoder.nth_image_max_extent(0).unwrap(); 58 assert_eq!(max_extent.offset, 290); 59 assert_eq!(max_extent.size, 1000 + 1 + 5778); // '\0' in the middle. 60 } 61