libsixel_rs/quant/
tuple.rs

1use alloc::vec::Vec;
2
3/// Convenience alias for a palette sample.
4pub type Sample = u32;
5
6/// Convenience alias for a [Sample] list.
7pub type Tuple = Vec<Sample>;
8
9/// Variable-length container of [ColorMap](super::ColorMap) [Sample]s.
10#[derive(Clone, Debug, PartialEq)]
11#[repr(C)]
12pub struct TupleInt {
13    pub value: u32,
14    pub tuple: Tuple,
15}
16
17impl TupleInt {
18    /// Creates a new [TupleInt].
19    pub const fn new() -> Self {
20        Self {
21            value: 0,
22            tuple: Tuple::new(),
23        }
24    }
25
26    /// Creates a new [TupleInt] with `depth` entries.
27    pub fn with_depth(depth: usize) -> Self {
28        Self {
29            value: 0,
30            tuple: vec![0; depth],
31        }
32    }
33
34    /// Gets the value.
35    pub const fn value(&self) -> u32 {
36        self.value
37    }
38
39    /// Sets the value.
40    pub fn set_value(&mut self, value: u32) {
41        self.value = value;
42    }
43
44    /// Gets a reference to the [Tuple].
45    pub fn tuple(&self) -> &[Sample] {
46        self.tuple.as_ref()
47    }
48
49    /// Sets the [Tuple].
50    pub fn set_tuple<V: Into<Tuple>>(&mut self, tuple: V) {
51        self.tuple = tuple.into();
52    }
53}