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 super::image::*; 16 use super::io::*; 17 use super::types::*; 18 19 use crate::decoder::gainmap::*; 20 use crate::image::YuvRange; 21 use crate::internal_utils::*; 22 use crate::parser::mp4box::*; 23 use crate::*; 24 25 pub type avifContentLightLevelInformationBox = ContentLightLevelInformation; 26 pub type avifSignedFraction = Fraction; 27 pub type avifUnsignedFraction = UFraction; 28 29 #[repr(C)] 30 #[derive(Debug)] 31 pub struct avifGainMap { 32 pub image: *mut avifImage, 33 pub gainMapMin: [avifSignedFraction; 3], 34 pub gainMapMax: [avifSignedFraction; 3], 35 pub gainMapGamma: [avifUnsignedFraction; 3], 36 pub baseOffset: [avifSignedFraction; 3], 37 pub alternateOffset: [avifSignedFraction; 3], 38 pub baseHdrHeadroom: avifUnsignedFraction, 39 pub alternateHdrHeadroom: avifUnsignedFraction, 40 pub useBaseColorSpace: avifBool, 41 pub altICC: avifRWData, 42 pub altColorPrimaries: ColorPrimaries, 43 pub altTransferCharacteristics: TransferCharacteristics, 44 pub altMatrixCoefficients: MatrixCoefficients, 45 pub altYUVRange: YuvRange, 46 pub altDepth: u32, 47 pub altPlaneCount: u32, 48 pub altCLLI: avifContentLightLevelInformationBox, 49 } 50 51 impl Default for avifGainMap { default() -> Self52 fn default() -> Self { 53 avifGainMap { 54 image: std::ptr::null_mut(), 55 gainMapMin: [Fraction(1, 1), Fraction(1, 1), Fraction(1, 1)], 56 gainMapMax: [Fraction(1, 1), Fraction(1, 1), Fraction(1, 1)], 57 gainMapGamma: [UFraction(1, 1), UFraction(1, 1), UFraction(1, 1)], 58 baseOffset: [Fraction(1, 64), Fraction(1, 64), Fraction(1, 64)], 59 alternateOffset: [Fraction(1, 64), Fraction(1, 64), Fraction(1, 64)], 60 baseHdrHeadroom: UFraction(0, 1), 61 alternateHdrHeadroom: UFraction(1, 1), 62 useBaseColorSpace: to_avifBool(false), 63 altICC: avifRWData::default(), 64 altColorPrimaries: ColorPrimaries::default(), 65 altTransferCharacteristics: TransferCharacteristics::default(), 66 altMatrixCoefficients: MatrixCoefficients::default(), 67 altYUVRange: YuvRange::Full, 68 altDepth: 0, 69 altPlaneCount: 0, 70 altCLLI: Default::default(), 71 } 72 } 73 } 74 75 impl From<&GainMap> for avifGainMap { from(gainmap: &GainMap) -> Self76 fn from(gainmap: &GainMap) -> Self { 77 avifGainMap { 78 gainMapMin: gainmap.metadata.min, 79 gainMapMax: gainmap.metadata.max, 80 gainMapGamma: gainmap.metadata.gamma, 81 baseOffset: gainmap.metadata.base_offset, 82 alternateOffset: gainmap.metadata.alternate_offset, 83 baseHdrHeadroom: gainmap.metadata.base_hdr_headroom, 84 alternateHdrHeadroom: gainmap.metadata.alternate_hdr_headroom, 85 useBaseColorSpace: gainmap.metadata.use_base_color_space as avifBool, 86 altICC: (&gainmap.alt_icc).into(), 87 altColorPrimaries: gainmap.alt_color_primaries, 88 altTransferCharacteristics: gainmap.alt_transfer_characteristics, 89 altMatrixCoefficients: gainmap.alt_matrix_coefficients, 90 altYUVRange: gainmap.alt_yuv_range, 91 altDepth: u32::from(gainmap.alt_plane_depth), 92 altPlaneCount: u32::from(gainmap.alt_plane_count), 93 altCLLI: gainmap.alt_clli, 94 ..Self::default() 95 } 96 } 97 } 98