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 | // Safety lints |
11 | #![deny (bare_trait_objects)] |
12 | #![deny (clippy::as_ptr_cast_mut)] |
13 | #![deny (clippy::cast_ptr_alignment)] |
14 | #![deny (clippy::large_stack_arrays)] |
15 | #![deny (clippy::ptr_as_ptr)] |
16 | #![deny (clippy::transmute_ptr_to_ptr)] |
17 | #![deny (clippy::unwrap_used)] |
18 | // Performance lints |
19 | #![warn (clippy::cloned_instead_of_copied)] |
20 | #![warn (clippy::inefficient_to_string)] |
21 | #![warn (clippy::invalid_upcast_comparisons)] |
22 | #![warn (clippy::iter_with_drain)] |
23 | #![warn (clippy::large_types_passed_by_value)] |
24 | #![warn (clippy::linkedlist)] |
25 | #![warn (clippy::mutex_integer)] |
26 | #![warn (clippy::naive_bytecount)] |
27 | #![warn (clippy::needless_bitwise_bool)] |
28 | #![warn (clippy::needless_collect)] |
29 | #![warn (clippy::needless_pass_by_value)] |
30 | #![warn (clippy::no_effect_underscore_binding)] |
31 | #![warn (clippy::or_fun_call)] |
32 | #![warn (clippy::stable_sort_primitive)] |
33 | #![warn (clippy::suboptimal_flops)] |
34 | #![warn (clippy::trivial_regex)] |
35 | #![warn (clippy::trivially_copy_pass_by_ref)] |
36 | #![warn (clippy::unnecessary_join)] |
37 | #![warn (clippy::unused_async)] |
38 | #![warn (clippy::zero_sized_map_values)] |
39 | // Correctness lints |
40 | #![deny (clippy::case_sensitive_file_extension_comparisons)] |
41 | #![deny (clippy::copy_iterator)] |
42 | #![deny (clippy::expl_impl_clone_on_copy)] |
43 | #![deny (clippy::float_cmp)] |
44 | #![warn (clippy::imprecise_flops)] |
45 | #![deny (clippy::manual_instant_elapsed)] |
46 | #![deny (clippy::match_same_arms)] |
47 | #![deny (clippy::mem_forget)] |
48 | #![warn (clippy::must_use_candidate)] |
49 | #![deny (clippy::path_buf_push_overwrite)] |
50 | #![deny (clippy::same_functions_in_if_condition)] |
51 | #![warn (clippy::suspicious_operation_groupings)] |
52 | #![deny (clippy::unchecked_duration_subtraction)] |
53 | #![deny (clippy::unicode_not_nfc)] |
54 | // Clarity/formatting lints |
55 | #![warn (clippy::borrow_as_ptr)] |
56 | #![warn (clippy::checked_conversions)] |
57 | #![warn (clippy::default_trait_access)] |
58 | #![warn (clippy::derive_partial_eq_without_eq)] |
59 | #![warn (clippy::explicit_deref_methods)] |
60 | #![warn (clippy::filter_map_next)] |
61 | #![warn (clippy::flat_map_option)] |
62 | #![warn (clippy::fn_params_excessive_bools)] |
63 | #![warn (clippy::from_iter_instead_of_collect)] |
64 | #![warn (clippy::if_not_else)] |
65 | #![warn (clippy::implicit_clone)] |
66 | #![warn (clippy::iter_not_returning_iterator)] |
67 | #![warn (clippy::iter_on_empty_collections)] |
68 | #![warn (clippy::macro_use_imports)] |
69 | #![warn (clippy::manual_clamp)] |
70 | #![warn (clippy::manual_let_else)] |
71 | #![warn (clippy::manual_ok_or)] |
72 | #![warn (clippy::manual_string_new)] |
73 | #![warn (clippy::map_flatten)] |
74 | #![warn (clippy::map_unwrap_or)] |
75 | #![warn (clippy::match_bool)] |
76 | #![warn (clippy::mut_mut)] |
77 | #![warn (clippy::needless_borrow)] |
78 | #![warn (clippy::needless_continue)] |
79 | #![warn (clippy::option_if_let_else)] |
80 | #![warn (clippy::range_minus_one)] |
81 | #![warn (clippy::range_plus_one)] |
82 | #![warn (clippy::redundant_else)] |
83 | #![warn (clippy::ref_binding_to_reference)] |
84 | #![warn (clippy::ref_option_ref)] |
85 | #![warn (clippy::semicolon_if_nothing_returned)] |
86 | #![warn (clippy::trait_duplication_in_bounds)] |
87 | #![warn (clippy::type_repetition_in_bounds)] |
88 | #![warn (clippy::unnested_or_patterns)] |
89 | #![warn (clippy::unused_peekable)] |
90 | #![warn (clippy::unused_rounding)] |
91 | #![warn (clippy::unused_self)] |
92 | #![warn (clippy::used_underscore_binding)] |
93 | #![warn (clippy::verbose_bit_mask)] |
94 | #![warn (clippy::verbose_file_reads)] |
95 | // Documentation lints |
96 | #![warn (clippy::doc_link_with_quotes)] |
97 | #![warn (clippy::doc_markdown)] |
98 | |
99 | #[cfg (feature = "create" )] |
100 | mod create; |
101 | #[cfg (feature = "diff" )] |
102 | mod diff; |
103 | #[cfg (all(feature = "estimate" , feature = "unstable" ))] |
104 | mod estimate; |
105 | #[cfg (feature = "parse" )] |
106 | mod parse; |
107 | mod util; |
108 | |
109 | use arrayvec::ArrayVec; |
110 | #[cfg (feature = "create" )] |
111 | pub use create::*; |
112 | #[cfg (feature = "diff" )] |
113 | pub use diff::*; |
114 | #[cfg (all(feature = "estimate" , feature = "unstable" ))] |
115 | pub use estimate::*; |
116 | #[cfg (feature = "parse" )] |
117 | pub use parse::*; |
118 | pub use v_frame; |
119 | |
120 | /// The max number of luma scaling points for grain synthesis |
121 | pub const NUM_Y_POINTS: usize = 14; |
122 | /// The max number of scaling points per chroma plane for grain synthesis |
123 | pub const NUM_UV_POINTS: usize = 10; |
124 | /// The max number of luma coefficients for grain synthesis |
125 | pub const NUM_Y_COEFFS: usize = 24; |
126 | /// The max number of coefficients per chroma plane for grain synthesis |
127 | pub const NUM_UV_COEFFS: usize = 25; |
128 | |
129 | /// A randomly generated u16 to be used as a starting random seed |
130 | /// for grain synthesis. The idea behind using a constant random seed |
131 | /// is so that encodes are deterministic and reproducible. |
132 | pub const DEFAULT_GRAIN_SEED: u16 = 10956; |
133 | |
134 | pub type ScalingPoints = ArrayVec<[u8; 2], NUM_Y_POINTS>; |
135 | |
136 | /// Specifies parameters for enabling decoder-side grain synthesis for |
137 | /// a segment of video from `start_time` to `end_time`. |
138 | #[derive (Debug, Clone, PartialEq, Eq)] |
139 | #[cfg_attr (feature = "serialize" , derive(serde::Deserialize, serde::Serialize))] |
140 | pub struct GrainTableSegment { |
141 | /// The beginning timestamp of this segment, in 10,000,000ths of a second. |
142 | pub start_time: u64, |
143 | /// The ending timestamp of this segment, not inclusive, in 10,000,000ths of |
144 | /// a second. |
145 | pub end_time: u64, |
146 | |
147 | /// Values for the cutoffs and scale factors for luma scaling points |
148 | pub scaling_points_y: ArrayVec<[u8; 2], NUM_Y_POINTS>, |
149 | /// Values for the cutoffs and scale factors for Cb scaling points |
150 | pub scaling_points_cb: ArrayVec<[u8; 2], NUM_UV_POINTS>, |
151 | /// Values for the cutoffs and scale factors for Cr scaling points |
152 | pub scaling_points_cr: ArrayVec<[u8; 2], NUM_UV_POINTS>, |
153 | |
154 | /// Determines the range and quantization step of the standard deviation |
155 | /// of film grain. |
156 | /// |
157 | /// Accepts values between `8..=11`. |
158 | pub scaling_shift: u8, |
159 | |
160 | /// A factor specifying how many AR coefficients are provided, |
161 | /// based on the forumla `coeffs_len = (2 * ar_coeff_lag * (ar_coeff_lag + |
162 | /// 1))`. |
163 | /// |
164 | /// Accepts values between `0..=3`. |
165 | pub ar_coeff_lag: u8, |
166 | /// Values for the AR coefficients for luma scaling points |
167 | pub ar_coeffs_y: ArrayVec<i8, NUM_Y_COEFFS>, |
168 | /// Values for the AR coefficients for Cb scaling points |
169 | pub ar_coeffs_cb: ArrayVec<i8, NUM_UV_COEFFS>, |
170 | /// Values for the AR coefficients for Cr scaling points |
171 | pub ar_coeffs_cr: ArrayVec<i8, NUM_UV_COEFFS>, |
172 | /// Shift value: Specifies the range of acceptable AR coefficients |
173 | /// 6: [-2, 2) |
174 | /// 7: [-1, 1) |
175 | /// 8: [-0.5, 0.5) |
176 | /// 9: [-0.25, 0.25) |
177 | pub ar_coeff_shift: u8, |
178 | /// Multiplier to the grain strength of the Cb plane |
179 | pub cb_mult: u8, |
180 | /// Multiplier to the grain strength of the Cb plane inherited from the luma |
181 | /// plane |
182 | pub cb_luma_mult: u8, |
183 | /// A base value for the Cb plane grain |
184 | pub cb_offset: u16, |
185 | /// Multiplier to the grain strength of the Cr plane |
186 | pub cr_mult: u8, |
187 | /// Multiplier to the grain strength of the Cr plane inherited from the luma |
188 | /// plane |
189 | pub cr_luma_mult: u8, |
190 | /// A base value for the Cr plane grain |
191 | pub cr_offset: u16, |
192 | |
193 | /// Whether film grain blocks should overlap or not |
194 | pub overlap_flag: bool, |
195 | /// Scale chroma grain from luma instead of providing chroma scaling points |
196 | pub chroma_scaling_from_luma: bool, |
197 | /// Specifies how much the Gaussian random numbers should be scaled down |
198 | /// during the grain synthesis process. |
199 | pub grain_scale_shift: u8, |
200 | /// Random seed used for generating grain |
201 | pub random_seed: u16, |
202 | } |
203 | |