Skip to main content

j2k_core/
sample.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3/// Integer sample width used by a pixel format or row sink.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[non_exhaustive]
6pub enum SampleType {
7    /// Unsigned 8-bit samples.
8    U8,
9    /// Unsigned 16-bit samples.
10    U16,
11    /// Signed 16-bit samples.
12    I16,
13}
14
15/// Supported integer sample type for row-oriented APIs.
16pub trait Sample: Copy + Default + Send + Sync + 'static {
17    /// Runtime sample type tag.
18    const TYPE: SampleType;
19    /// Number of significant bits in the sample type.
20    const BITS: u8;
21}
22
23impl Sample for u8 {
24    const TYPE: SampleType = SampleType::U8;
25    const BITS: u8 = 8;
26}
27
28impl Sample for u16 {
29    const TYPE: SampleType = SampleType::U16;
30    const BITS: u8 = 16;
31}
32
33impl Sample for i16 {
34    const TYPE: SampleType = SampleType::I16;
35    const BITS: u8 = 16;
36}