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