Skip to main content

j2k_types/dispatch/
report.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! Encode-stage dispatch accounting.
4
5/// Encode-stage dispatch counters reported by an accelerator.
6#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
7pub struct J2kEncodeDispatchReport {
8    /// Pixel deinterleave/level-shift dispatch count.
9    pub deinterleave: usize,
10    /// Forward RCT kernel dispatch count.
11    pub forward_rct: usize,
12    /// Forward ICT kernel dispatch count.
13    pub forward_ict: usize,
14    /// Forward reversible 5/3 DWT kernel dispatch count.
15    pub forward_dwt53: usize,
16    /// Forward irreversible 9/7 DWT kernel dispatch count.
17    pub forward_dwt97: usize,
18    /// Subband quantization dispatch count.
19    pub quantize_subband: usize,
20    /// Tier-1 code-block encode dispatch count.
21    pub tier1_code_block: usize,
22    /// HTJ2K code-block encode dispatch count.
23    pub ht_code_block: usize,
24    /// Packetization dispatch count.
25    pub packetization: usize,
26}
27
28impl J2kEncodeDispatchReport {
29    /// Return the saturating per-stage delta from `before` to `self`.
30    #[must_use]
31    pub fn saturating_delta(self, before: Self) -> Self {
32        Self {
33            deinterleave: self.deinterleave.saturating_sub(before.deinterleave),
34            forward_rct: self.forward_rct.saturating_sub(before.forward_rct),
35            forward_ict: self.forward_ict.saturating_sub(before.forward_ict),
36            forward_dwt53: self.forward_dwt53.saturating_sub(before.forward_dwt53),
37            forward_dwt97: self.forward_dwt97.saturating_sub(before.forward_dwt97),
38            quantize_subband: self
39                .quantize_subband
40                .saturating_sub(before.quantize_subband),
41            tier1_code_block: self
42                .tier1_code_block
43                .saturating_sub(before.tier1_code_block),
44            ht_code_block: self.ht_code_block.saturating_sub(before.ht_code_block),
45            packetization: self.packetization.saturating_sub(before.packetization),
46        }
47    }
48
49    /// Return total dispatches across all encode stages.
50    #[must_use]
51    pub fn total(self) -> usize {
52        self.forward_rct
53            .saturating_add(self.deinterleave)
54            .saturating_add(self.forward_ict)
55            .saturating_add(self.forward_dwt53)
56            .saturating_add(self.forward_dwt97)
57            .saturating_add(self.quantize_subband)
58            .saturating_add(self.tier1_code_block)
59            .saturating_add(self.ht_code_block)
60            .saturating_add(self.packetization)
61    }
62
63    /// Return whether at least one encode stage dispatched.
64    #[must_use]
65    pub fn any(self) -> bool {
66        self.total() > 0
67    }
68}