• 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 use crate::decoder::Image;
16 use crate::image::YuvRange;
17 use crate::utils::*;
18 use crate::*;
19 
20 #[derive(Debug, Default)]
21 pub struct GainMapMetadata {
22     pub min: [Fraction; 3],
23     pub max: [Fraction; 3],
24     pub gamma: [UFraction; 3],
25     pub base_offset: [Fraction; 3],
26     pub alternate_offset: [Fraction; 3],
27     pub base_hdr_headroom: UFraction,
28     pub alternate_hdr_headroom: UFraction,
29     pub use_base_color_space: bool,
30 }
31 
32 impl GainMapMetadata {
is_valid(&self) -> AvifResult<()>33     pub(crate) fn is_valid(&self) -> AvifResult<()> {
34         for i in 0..3 {
35             self.min[i].is_valid()?;
36             self.max[i].is_valid()?;
37             self.gamma[i].is_valid()?;
38             self.base_offset[i].is_valid()?;
39             self.alternate_offset[i].is_valid()?;
40             if self.max[i].as_f64()? < self.min[i].as_f64()? || self.gamma[i].0 == 0 {
41                 return Err(AvifError::InvalidArgument);
42             }
43         }
44         self.base_hdr_headroom.is_valid()?;
45         self.alternate_hdr_headroom.is_valid()?;
46         Ok(())
47     }
48 }
49 
50 #[derive(Default)]
51 pub struct GainMap {
52     pub image: Image,
53     pub metadata: GainMapMetadata,
54 
55     pub alt_icc: Vec<u8>,
56     pub alt_color_primaries: ColorPrimaries,
57     pub alt_transfer_characteristics: TransferCharacteristics,
58     pub alt_matrix_coefficients: MatrixCoefficients,
59     pub alt_yuv_range: YuvRange,
60 
61     pub alt_plane_count: u8,
62     pub alt_plane_depth: u8,
63 
64     pub alt_clli: ContentLightLevelInformation,
65 }
66