|
| 1 | +// Copyright (c) 2022-2022, The rav1e contributors. All rights reserved |
| 2 | +// |
| 3 | +// This source code is subject to the terms of the BSD 2 Clause License and |
| 4 | +// the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 5 | +// was not distributed with this source code in the LICENSE file, you can |
| 6 | +// obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 7 | +// Media Patent License 1.0 was not distributed with this source code in the |
| 8 | +// PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
| 9 | + |
| 10 | +use crate::serialize::{Deserialize, Serialize}; |
| 11 | +use arrayvec::ArrayVec; |
| 12 | + |
| 13 | +/// The max number of luma scaling points for grain synthesis |
| 14 | +pub const GS_NUM_Y_POINTS: usize = 14; |
| 15 | +/// The max number of scaling points per chroma plane for grain synthesis |
| 16 | +pub const GS_NUM_UV_POINTS: usize = 10; |
| 17 | +/// The max number of luma coefficients for grain synthesis |
| 18 | +pub const GS_NUM_Y_COEFFS: usize = 24; |
| 19 | +/// The max number of coefficients per chroma plane for grain synthesis |
| 20 | +pub const GS_NUM_UV_COEFFS: usize = 25; |
| 21 | + |
| 22 | +/// A randomly generated u16 to be used as a starting random seed |
| 23 | +/// for grain synthesis. |
| 24 | +pub const DEFAULT_GS_SEED: u16 = 10956; |
| 25 | + |
| 26 | +/// Specifies parameters for enabling decoder-side grain synthesis for |
| 27 | +/// a segment of video from `start_time` to `end_time`. |
| 28 | +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] |
| 29 | +pub struct GrainTableParams { |
| 30 | + /// The beginning timestamp of this segment, in 10,000,000ths of a second. |
| 31 | + pub start_time: u64, |
| 32 | + /// The ending timestamp of this segment, not inclusive, in 10,000,000ths of a second. |
| 33 | + pub end_time: u64, |
| 34 | + |
| 35 | + /// Values for the cutoffs and scale factors for luma scaling points |
| 36 | + pub scaling_points_y: ArrayVec<[u8; 2], GS_NUM_Y_POINTS>, |
| 37 | + /// Values for the cutoffs and scale factors for Cb scaling points |
| 38 | + pub scaling_points_cb: ArrayVec<[u8; 2], GS_NUM_UV_POINTS>, |
| 39 | + /// Values for the cutoffs and scale factors for Cr scaling points |
| 40 | + pub scaling_points_cr: ArrayVec<[u8; 2], GS_NUM_UV_POINTS>, |
| 41 | + |
| 42 | + /// Determines the range and quantization step of the standard deviation |
| 43 | + /// of film grain. |
| 44 | + /// |
| 45 | + /// Accepts values between `8..=11`. |
| 46 | + pub scaling_shift: u8, |
| 47 | + |
| 48 | + /// A factor specifying how many AR coefficients are provided, |
| 49 | + /// based on the forumla `coeffs_len = (2 * ar_coeff_lag * (ar_coeff_lag + 1))`. |
| 50 | + /// |
| 51 | + /// Accepts values between `0..=3`. |
| 52 | + pub ar_coeff_lag: u8, |
| 53 | + /// Values for the AR coefficients for luma scaling points |
| 54 | + pub ar_coeffs_y: ArrayVec<i8, GS_NUM_Y_COEFFS>, |
| 55 | + /// Values for the AR coefficients for Cb scaling points |
| 56 | + pub ar_coeffs_cb: ArrayVec<i8, GS_NUM_UV_COEFFS>, |
| 57 | + /// Values for the AR coefficients for Cr scaling points |
| 58 | + pub ar_coeffs_cr: ArrayVec<i8, GS_NUM_UV_COEFFS>, |
| 59 | + /// Shift value: Specifies the range of acceptable AR coefficients |
| 60 | + /// 6: [-2, 2) |
| 61 | + /// 7: [-1, 1) |
| 62 | + /// 8: [-0.5, 0.5) |
| 63 | + /// 9: [-0.25, 0.25) |
| 64 | + pub ar_coeff_shift: u8, |
| 65 | + /// Multiplier to the grain strength of the Cb plane |
| 66 | + pub cb_mult: u8, |
| 67 | + /// Multiplier to the grain strength of the Cb plane inherited from the luma plane |
| 68 | + pub cb_luma_mult: u8, |
| 69 | + /// A base value for the Cb plane grain |
| 70 | + pub cb_offset: u16, |
| 71 | + /// Multiplier to the grain strength of the Cr plane |
| 72 | + pub cr_mult: u8, |
| 73 | + /// Multiplier to the grain strength of the Cr plane inherited from the luma plane |
| 74 | + pub cr_luma_mult: u8, |
| 75 | + /// A base value for the Cr plane grain |
| 76 | + pub cr_offset: u16, |
| 77 | + |
| 78 | + /// Whether film grain blocks should overlap or not |
| 79 | + pub overlap_flag: bool, |
| 80 | + /// Scale chroma grain from luma instead of providing chroma scaling points |
| 81 | + pub chroma_scaling_from_luma: bool, |
| 82 | + /// Specifies how much the Gaussian random numbers should be scaled down during the grain synthesis |
| 83 | + /// process. |
| 84 | + pub grain_scale_shift: u8, |
| 85 | + /// Random seed used for generating grain |
| 86 | + pub random_seed: u16, |
| 87 | +} |
0 commit comments