Debian Codegraph @

src/container/heif.rs

raw symbols SCIP
1 use craterust-analyzer cargo imagesize 0.13.0 crate/::utilrust-analyzer cargo imagesize 0.13.0 util/::*;
2 use craterust-analyzer cargo imagesize 0.13.0 crate/::{ImageErrorrust-analyzer cargo imagesize 0.13.0 ImageError#, ImageResultrust-analyzer cargo imagesize 0.13.0 ImageResult#, ImageSizerust-analyzer cargo imagesize 0.13.0 ImageSize#};
3
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryIntorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#;
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#, Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#, SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#};
6
7 // REFS: https://github.com/strukturag/libheif/blob/f0c1a863cabbccb2d280515b7ecc73e6717702dc/libheif/heif.h#L600
8 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)]
9 pub enum Compressionrust-analyzer cargo imagesize 0.13.0 container/heif/Compression# {
10 Av1rust-analyzer cargo imagesize 0.13.0 container/heif/Compression#Av1#,
11 Hevcrust-analyzer cargo imagesize 0.13.0 container/heif/Compression#Hevc#,
12 Jpegrust-analyzer cargo imagesize 0.13.0 container/heif/Compression#Jpeg#,
13 Unknownrust-analyzer cargo imagesize 0.13.0 container/heif/Compression#Unknown#,
14 // unused(reuse in the future?)
15 // Avc,
16 // Vvc,
17 // Evc,
18 }
19
20 pub fn sizerust-analyzer cargo imagesize 0.13.0 container/heif/size().<R: BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#>(reader: &mut R) -> ImageResultrust-analyzer cargo imagesize 0.13.0 ImageResult#<ImageSizerust-analyzer cargo imagesize 0.13.0 ImageSize#> {
21 reader.seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#seek().(SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Startrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Start#(0))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
22 // Read the ftyp header size
23 let ftyp_size = read_u32rust-analyzer cargo imagesize 0.13.0 util/read_u32().(reader, &Endianrust-analyzer cargo imagesize 0.13.0 util/Endian#::Bigrust-analyzer cargo imagesize 0.13.0 util/Endian#Big#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
24
25 // Jump to the first actual box offset
26 reader.seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#seek().(SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Startrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Start#(ftyp_size.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
27
28 // Skip to meta tag which contains all the metadata
29 skip_to_tagrust-analyzer cargo imagesize 0.13.0 container/heif/skip_to_tag().(reader, b"meta")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
30 read_u32rust-analyzer cargo imagesize 0.13.0 util/read_u32().(reader, &Endianrust-analyzer cargo imagesize 0.13.0 util/Endian#::Bigrust-analyzer cargo imagesize 0.13.0 util/Endian#Big#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; // Meta has a junk value after it
31 skip_to_tagrust-analyzer cargo imagesize 0.13.0 container/heif/skip_to_tag().(reader, b"iprp")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; // Find iprp tag
32
33 let mut ipco_size = skip_to_tagrust-analyzer cargo imagesize 0.13.0 container/heif/skip_to_tag().(reader, b"ipco")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). as usize; // Find ipco tag
34
35 // Keep track of the max size of ipco tag
36 let mut max_width = 0usize;
37 let mut max_height = 0usize;
38 let mut found_ispe = false;
39 let mut rotation = 0u8;
40
41 while let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((tag, size)) = read_tagrust-analyzer cargo imagesize 0.13.0 util/read_tag().(reader) {
42 // Size of tag length + tag cannot be under 8 (4 bytes each)
43 if size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().8 {
44 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ImageErrorrust-analyzer cargo imagesize 0.13.0 ImageError#::CorruptedImagerust-analyzer cargo imagesize 0.13.0 ImageError#CorruptedImage#);
45 }
46
47 // ispe tag has a junk value followed by width and height as u32
48 if tag rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."ispe" {
49 found_ispe = true;
50 read_u32rust-analyzer cargo imagesize 0.13.0 util/read_u32().(reader, &Endianrust-analyzer cargo imagesize 0.13.0 util/Endian#::Bigrust-analyzer cargo imagesize 0.13.0 util/Endian#Big#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; // Discard junk value
51 let width = read_u32rust-analyzer cargo imagesize 0.13.0 util/read_u32().(reader, &Endianrust-analyzer cargo imagesize 0.13.0 util/Endian#::Bigrust-analyzer cargo imagesize 0.13.0 util/Endian#Big#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). as usize;
52 let height = read_u32rust-analyzer cargo imagesize 0.13.0 util/read_u32().(reader, &Endianrust-analyzer cargo imagesize 0.13.0 util/Endian#::Bigrust-analyzer cargo imagesize 0.13.0 util/Endian#Big#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). as usize;
53
54 // Assign new largest size by area
55 if width rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().height rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().max_width rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul().max_height {
56 max_width = width;
57 max_height = height;
58 }
59 } else if tag rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."irot" {
60 // irot is 9 bytes total: size, tag, 1 byte for rotation (0-3)
61 rotation = read_u8rust-analyzer cargo imagesize 0.13.0 util/read_u8().(reader)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
62 } else if size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().ipco_size {
63 // If we've gone past the ipco boundary, then break
64 break;
65 } else {
66 // If we're still inside ipco, consume all bytes for
67 // the current tag, minus the bytes already read in `read_tag`
68 ipco_size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().size;
69 reader.seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#seek().(SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Currentrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Current#(size as i64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().8))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
70 }
71 }
72
73 // If no ispe found, then we have no actual dimension data to use
74 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().found_ispe {
75 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(
76 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::UnexpectedEofrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#UnexpectedEof#, "Not enough data").intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
77 );
78 }
79
80 // Rotation can only be 0-3. 1 and 3 are 90 and 270 degrees respectively (anti-clockwise)
81 // If we have 90 or 270 rotation, flip width and height
82 if rotation rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().1 || rotation rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().3 {
83 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::swaprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/swap().(&mut max_width, &mut max_height);
84 }
85
86 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ImageSizerust-analyzer cargo imagesize 0.13.0 ImageSize# {
87 widthrust-analyzer cargo imagesize 0.13.0 ImageSize#width.: max_width,
88 heightrust-analyzer cargo imagesize 0.13.0 ImageSize#height.: max_height,
89 })
90 }
91
92 pub fn matchesrust-analyzer cargo imagesize 0.13.0 container/heif/matches().<R: BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#>(header: &[u8], reader: &mut R) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Compressionrust-analyzer cargo imagesize 0.13.0 container/heif/Compression#> {
93 if header.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().12 || &header[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().4..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#8]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().b"ftyp" {
94 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
95 }
96
97 let brand: [u8; 4] = header[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().8..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#12]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
98
99 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(compression) = inner_matchesrust-analyzer cargo imagesize 0.13.0 container/heif/inner_matches().(&brand) {
100 // case 1: { heic, ... }
101 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(compression);
102 }
103
104 // REFS: https://github.com/nokiatech/heif/blob/be43efdf273ae9cf90e552b99f16ac43983f3d19/srcs/reader/heifreaderimpl.cpp#L738
105 let brands = [b"mif1", b"msf1", b"mif2", b"miaf"];
106
107 if brands.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&&brand) {
108 let mut buf = [0; 12];
109
110 if reader.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut buf).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() {
111 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Compressionrust-analyzer cargo imagesize 0.13.0 container/heif/Compression#::Unknownrust-analyzer cargo imagesize 0.13.0 container/heif/Compression#Unknown#);
112 }
113
114 let brand2: [u8; 4] = buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().4..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#8]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
115
116 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(compression) = inner_matchesrust-analyzer cargo imagesize 0.13.0 container/heif/inner_matches().(&brand2) {
117 // case 2: { msf1, version, heic, msf1, ... }
118 // brand brand2 brand3
119 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(compression);
120 }
121
122 if brands.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&&brand2) {
123 // case 3: { msf1, version, msf1, heic, ... }
124 // brand brand2 brand3
125 let brand3: [u8; 4] = buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().8..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#12]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()..try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
126
127 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(compression) = inner_matchesrust-analyzer cargo imagesize 0.13.0 container/heif/inner_matches().(&brand3) {
128 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(compression);
129 }
130 }
131 }
132
133 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Compressionrust-analyzer cargo imagesize 0.13.0 container/heif/Compression#::Unknownrust-analyzer cargo imagesize 0.13.0 container/heif/Compression#Unknown#)
134 }
135
136 fn inner_matchesrust-analyzer cargo imagesize 0.13.0 container/heif/inner_matches().(brand: &[u8; 4]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Compressionrust-analyzer cargo imagesize 0.13.0 container/heif/Compression#> {
137 // Since other non-heif files may contain ftype in the header
138 // we try to use brands to distinguish image files specifically.
139 // List of brands from here: https://mp4ra.org/#/brands
140 let hevc_brands = [
141 b"heic", b"heix", b"heis", b"hevs", b"heim", b"hevm", b"hevc", b"hevx",
142 ];
143 let av1_brands = [
144 b"avif", b"avio", b"avis",
145 // AVIF only
146 // REFS: https://rawcdn.githack.com/AOMediaCodec/av1-avif/67a92add6cd642a8863e386fa4db87954a6735d1/index.html#advanced-profile
147 b"MA1A", b"MA1B",
148 ];
149 let jpeg_brands = [b"jpeg", b"jpgs"];
150
151 // unused
152 // REFS: https://github.com/MPEGGroup/FileFormatConformance/blob/6eef4e4c8bc70e2af9aeb1d62e764a6235f9d6a6/data/standard_features/23008-12/brands.json
153 // let avc_brands = [b"avci", b"avcs"];
154 // let vvc_brands = [b"vvic", b"vvis"];
155 // let evc_brands = [b"evbi", b"evbs", b"evmi", b"evms"];
156
157 // Maybe unnecessary
158 // REFS: https://github.com/nokiatech/heif/blob/be43efdf273ae9cf90e552b99f16ac43983f3d19/srcs/reader/heifreaderimpl.cpp#L1415
159 // REFS: https://github.com/nokiatech/heif/blob/be43efdf273ae9cf90e552b99f16ac43983f3d19/srcs/api-cpp/ImageItem.h#L37
160 // let feature_brands = [b"pred", b"auxl", b"thmb", b"base", b"dimg"];
161 if hevc_brands.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&brand) {
162 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Compressionrust-analyzer cargo imagesize 0.13.0 container/heif/Compression#::Hevcrust-analyzer cargo imagesize 0.13.0 container/heif/Compression#Hevc#);
163 }
164
165 if av1_brands.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&brand) {
166 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Compressionrust-analyzer cargo imagesize 0.13.0 container/heif/Compression#::Av1rust-analyzer cargo imagesize 0.13.0 container/heif/Compression#Av1#);
167 }
168
169 if jpeg_brands.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&brand) {
170 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Compressionrust-analyzer cargo imagesize 0.13.0 container/heif/Compression#::Jpegrust-analyzer cargo imagesize 0.13.0 container/heif/Compression#Jpeg#);
171 }
172
173 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
174 }
175
176 fn skip_to_tagrust-analyzer cargo imagesize 0.13.0 container/heif/skip_to_tag().<R: BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead# + Seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#>(reader: &mut R, tag: &[u8]) -> ImageResultrust-analyzer cargo imagesize 0.13.0 ImageResult#<u32> {
177 let mut tag_buf = [0; 4];
178
179 loop {
180 let size = read_u32rust-analyzer cargo imagesize 0.13.0 util/read_u32().(reader, &Endianrust-analyzer cargo imagesize 0.13.0 util/Endian#::Bigrust-analyzer cargo imagesize 0.13.0 util/Endian#Big#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
181 reader.read_exactrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read_exact().(&mut tag_buf)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
182
183 if tag_buf rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/equality/impl#[`[T; N]`][`PartialEq<&[U]>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/equality/impl#[`[T; N]`][`PartialEq<&[U]>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/equality/impl#[`[T; N]`][`PartialEq<&[U]>`]eq().tag {
184 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(size);
185 }
186
187 if size rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]ge().8 {
188 reader.seekrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Seek#seek().(SeekFromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#::Currentrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/SeekFrom#Current#(size as i64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().8))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
189 } else {
190 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(
191 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::InvalidDatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#InvalidData#,
192 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("Invalid heif box size: {}", size),
193 )
194 .intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
195 }
196 }
197 }