j2k_core/scale.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3/// Power-of-two downscale requested during decode.
4#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
5#[non_exhaustive]
6pub enum Downscale {
7 /// Full-resolution output.
8 #[default]
9 None,
10 /// Half-resolution output.
11 Half,
12 /// Quarter-resolution output.
13 Quarter,
14 /// Eighth-resolution output.
15 Eighth,
16}
17
18impl Downscale {
19 /// Return the integer scale denominator.
20 #[must_use]
21 pub const fn denominator(self) -> u32 {
22 match self {
23 Self::None => 1,
24 Self::Half => 2,
25 Self::Quarter => 4,
26 Self::Eighth => 8,
27 }
28 }
29
30 /// Return the decoded DCT block dimension after scaling.
31 #[must_use]
32 pub const fn output_block_size(self) -> u32 {
33 match self {
34 Self::None => 8,
35 Self::Half => 4,
36 Self::Quarter => 2,
37 Self::Eighth => 1,
38 }
39 }
40}