1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Shared helper functions for decoders.
//!
//! This module provides common validation logic extracted from individual decoder
//! files to eliminate repetitive boilerplate (positive-dimension checks, sign-loss
//! casts, and buffer-too-short guards).
use crateDecodeError;
use crateProfile;
/// Validates that profile dimensions are positive and converts them to `usize`.
///
/// When `bpp > 0` the function also checks that `src` is at least
/// `width × height × bpp` bytes long.
///
/// # Arguments
///
/// * `src` — Raw input byte slice.
/// * `profile` — The profile whose `width` and `height` are validated.
/// * `name` — Label used in the [`DecodeError::InvalidFormat`] message.
/// * `bpp` — Bytes per pixel. Pass `0` to skip the buffer-length check for
/// formats that need a more complex expected-size calculation (e.g., `YCbCr420`).
///
/// # Returns
///
/// `(width, height)` as `usize`.
///
/// # Errors
///
/// | Variant | Condition |
/// |---|---|
/// | `InvalidFormat` | Width or height ≤ 0 |
/// | `BufferTooShort` | `bpp > 0` and `src.len() < w × h × bpp` |
pub