diff --git a/src/api/config/encoder.rs b/src/api/config/encoder.rs index ef8ba5725a..85992cf263 100644 --- a/src/api/config/encoder.rs +++ b/src/api/config/encoder.rs @@ -221,7 +221,7 @@ impl EncoderConfig { // has the property that the scaled distortion of a 2Nx2N block is always // equal to the sum of the scaled distortions of the NxN sub-blocks it's // made of, this is a necessary property to be able to do RDO between - // multiple partition sizes properly. Unfortunately, when tx domains + // multiple partition sizes properly. Unfortunately, when tx domain // distortion is used, distortion is only known at the tx block level which // might be bigger than 8x8. So temporal RDO is always disabled in that case. !self.speed_settings.tx_domain_distortion diff --git a/src/api/config/mod.rs b/src/api/config/mod.rs index b0527eed32..d4f0263411 100644 --- a/src/api/config/mod.rs +++ b/src/api/config/mod.rs @@ -32,11 +32,21 @@ pub use crate::tiling::TilingInfo; #[non_exhaustive] pub enum InvalidConfig { /// The width is invalid. - #[error("invalid width {0} (expected >= 16, <= 65535)")] - InvalidWidth(usize), + #[error("invalid width {actual} (expected >= 16, <= {max})")] + InvalidWidth { + /// The actual value. + actual: usize, + /// The maximal supported value. + max: usize, + }, /// The height is invalid. - #[error("invalid height {0} (expected >= 16, <= 65535)")] - InvalidHeight(usize), + #[error("invalid height {actual} (expected >= 16, <= {max})")] + InvalidHeight { + /// The actual value. + actual: usize, + /// The maximal supported value. + max: usize, + }, /// Aspect ratio numerator is invalid. #[error("invalid aspect ratio numerator {0} (expected > 0)")] InvalidAspectRatioNum(usize), @@ -285,14 +295,30 @@ impl Config { if (config.still_picture && config.width < 1) || (!config.still_picture && config.width < 16) || config.width > u16::max_value() as usize + || (config.max_width != 0 && config.width > config.max_width) { - return Err(InvalidWidth(config.width)); + return Err(InvalidWidth { + actual: config.width, + max: if config.max_width != 0 { + config.max_width + } else { + u16::max_value() as usize + }, + }); } if (config.still_picture && config.height < 1) || (!config.still_picture && config.height < 16) || config.height > u16::max_value() as usize + || (config.max_height != 0 && config.height > config.max_height) { - return Err(InvalidHeight(config.height)); + return Err(InvalidHeight { + actual: config.height, + max: if config.max_height != 0 { + config.max_height + } else { + u16::max_value() as usize + }, + }); } if config.sample_aspect_ratio.num == 0 { @@ -313,12 +339,6 @@ impl Config { if render_height == 0 || render_height > u16::max_value() as usize { return Err(InvalidRenderHeight(render_height)); } - if config.max_width != 0 && config.width > config.max_width { - return Err(InvalidWidth(config.width)); - } - if config.max_height != 0 && config.height > config.max_height { - return Err(InvalidHeight(config.height)); - } if config.rdo_lookahead_frames > MAX_RDO_LOOKAHEAD_FRAMES || config.rdo_lookahead_frames < 1 diff --git a/src/capi.rs b/src/capi.rs index 99cb874944..4edcf2b68c 100644 --- a/src/capi.rs +++ b/src/capi.rs @@ -609,12 +609,8 @@ unsafe fn option_match( match key { "width" => enc.width = value.parse().map_err(|_| ())?, "height" => enc.height = value.parse().map_err(|_| ())?, - "max_width" => { - enc.max_width = value.parse().map_err(|_| ())? - } - "max_height" => { - enc.max_height = value.parse().map_err(|_| ())? - } + "max_width" => enc.max_width = value.parse().map_err(|_| ())?, + "max_height" => enc.max_height = value.parse().map_err(|_| ())?, "speed" => { enc.speed_settings = rav1e::SpeedSettings::from_preset(value.parse().map_err(|_| ())?) diff --git a/src/encoder.rs b/src/encoder.rs index 7eeb0a63b1..9bf6853d21 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -191,8 +191,8 @@ impl Sequence { if config.max_width > 0 { config.max_width } else { config.width }; let max_height = if config.max_height > 0 { config.max_height } else { config.height }; - let width_bits = 32 - ((max_width as u32) - 1).leading_zeros(); - let height_bits = 32 - ((max_height as u32) - 1).leading_zeros(); + let width_bits = 32 - (max_width as u32).leading_zeros(); + let height_bits = 32 - (max_height as u32).leading_zeros(); assert!(width_bits <= 16); assert!(height_bits <= 16); diff --git a/src/fuzzing.rs b/src/fuzzing.rs index 8362783689..f8b403da1e 100644 --- a/src/fuzzing.rs +++ b/src/fuzzing.rs @@ -221,6 +221,8 @@ impl Arbitrary for ArbitraryEncoder { speed_settings: SpeedSettings::from_preset(u.int_in_range(0..=10)?), width: u.int_in_range(1..=256)?, height: u.int_in_range(1..=256)?, + max_width: 0, + max_height: 0, still_picture: Arbitrary::arbitrary(u)?, time_base: arbitrary_rational(u)?, min_key_frame_interval: u.int_in_range(0..=3)?,