Skip to content

Commit 02fde85

Browse files
committed
Support max_width/max_height options.
1 parent 150679f commit 02fde85

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/api/config/mod.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,21 @@ pub use crate::tiling::TilingInfo;
3232
#[non_exhaustive]
3333
pub enum InvalidConfig {
3434
/// The width is invalid.
35-
#[error("invalid width {0} (expected >= 16, <= 65535)")]
36-
InvalidWidth(usize),
35+
#[error("invalid width {0} (expected >= 16, <= {max})")]
36+
InvalidWidth {
37+
/// The actual value.
38+
actual: usize,
39+
/// The maximal supported value.
40+
max: usize,
41+
},
3742
/// The height is invalid.
38-
#[error("invalid height {0} (expected >= 16, <= 65535)")]
39-
InvalidHeight(usize),
43+
#[error("invalid height {0} (expected >= 16, <= {max})")]
44+
InvalidHeight {
45+
/// The actual value.
46+
actual: usize,
47+
/// The maximal supported value.
48+
max: usize,
49+
},
4050
/// Aspect ratio numerator is invalid.
4151
#[error("invalid aspect ratio numerator {0} (expected > 0)")]
4252
InvalidAspectRatioNum(usize),
@@ -285,14 +295,22 @@ impl Config {
285295
if (config.still_picture && config.width < 1)
286296
|| (!config.still_picture && config.width < 16)
287297
|| config.width > u16::max_value() as usize
298+
|| (config.max_width != 0 && config.width > config.max_width)
288299
{
289-
return Err(InvalidWidth(config.width));
300+
return Err(InvalidWidth {
301+
actual: config.width,
302+
max: if config.max_width != 0 { config.max_width } else { u16::max_value() as usize },
303+
});
290304
}
291305
if (config.still_picture && config.height < 1)
292306
|| (!config.still_picture && config.height < 16)
293307
|| config.height > u16::max_value() as usize
308+
|| (config.max_height != 0 && config.height > config.max_height)
294309
{
295-
return Err(InvalidHeight(config.height));
310+
return Err(InvalidHeight {
311+
actual: config.height,
312+
max: if config.max_height != 0 { config.max_height } else { u16::max_value() as usize },
313+
});
296314
}
297315

298316
if config.sample_aspect_ratio.num == 0 {

0 commit comments

Comments
 (0)