devela/media/image/sixel/output/enums.rs
1// devela::media::image::sixel::output::enums
2//
3//! Defines: [`SixelPixelFormat`],
4//
5// TOC
6// - enum SixelSplit
7// - enum SixelMean
8// - enum SixelDither
9// - enum SixelQuality
10//
11// private:
12// - enum SixelEncodePolicy
13// - enum SixelPalette
14// - enum SixelLoop
15// - //
16// - enum ResampleMethod
17// - enum ImageFormat
18// - enum PixelFormatType
19
20crate::impl_cdef! { Self::Auto =>
21SixelSplit, SixelMean, SixelQuality, Loop, SixelEncodePolicy, SixelColorModel }
22
23/// Method for finding the largest dimension for splitting,
24/// and sorting by that component.
25//
26// # Adaptation
27// - Derived from `methodForLargest` enum in the `libsixel` C library.
28#[repr(u8)]
29#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
30pub enum SixelSplit {
31 /// Choose automatically the method for finding the largest dimension. (default)
32 #[default]
33 Auto,
34 /// Simply comparing the range in RGB space.
35 Norm,
36 /// Transforming into luminosities before the comparison.
37 Lum,
38}
39
40/// Method for selecting a representative color from a color space partition (box).
41//
42// # Adaptation
43// - Derived from `methodForRep` enum in the `libsixel` C library.
44#[repr(u8)]
45#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
46pub enum SixelMean {
47 /// Choose automatically the method for selecting representative color from each box.
48 /// (default)
49 #[default]
50 Auto,
51 /// Choose the geometric center of the box.
52 Center,
53 /// Choose the mean of all unique colors in the box (specified in Heckbert's paper).
54 Colors,
55 /// Computes the mean weighted by pixel count.
56 Pixels,
57}
58
59/// Quality modes.
60//
61// # Adaptation
62// Derived from `qualityMode` enum in the `libsixel` C library.
63#[repr(u8)]
64#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
65pub enum SixelQuality {
66 /// Choose quality mode automatically.
67 #[default]
68 Auto,
69 /// High quality palette construction.
70 High,
71 /// Low quality palette construction.
72 Low,
73 /// Full quality palette construction.
74 Full,
75 /// High color.
76 HighColor,
77}
78
79/* private items */
80
81/// Policies of SIXEL encoding.
82//
83// # Adaptation
84// Derived from `encodePolicy` enum in the `libsixel` C library.
85#[repr(u8)]
86#[allow(dead_code, reason = "Fast variant never constructed")]
87#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
88pub(crate) enum SixelEncodePolicy {
89 /// Choose encoding policy automatically (default).
90 #[default]
91 Auto = 0,
92 /// Encode as fast as possible.
93 Fast = 1,
94 /// Encode to as small sixel sequence as possible.
95 Size = 2,
96}
97
98/// Color model used for palette generation in Sixel output.
99///
100/// This defines **how colors are represented or generated** in a Sixel image,
101/// rather than the specific colors used.
102///
103//
104// # Adaptation
105// Derived from `paletteType` enum in the `libsixel` C library.
106#[repr(u8)]
107#[allow(dead_code, reason = "Some variants are never constructed")]
108#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
109pub(crate) enum SixelColorModel {
110 /// Automatically chooses a color model based on output settings.
111 #[default]
112 Auto,
113 /// Uses the **HLS (Hue, Lightness, Saturation)** colorspace.
114 Hls,
115 /// Uses the **RGB (Red, Green, Blue)** colorspace.
116 Rgb,
117}
118
119/// Loop mode.
120//
121// # Adaptation
122// Derived from `loopControl` enum in the `libsixel` C library.
123#[repr(u8)]
124#[expect(dead_code, reason = "Only using `Auto` for now")]
125#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
126enum Loop {
127 /// Honer the setting of GIF header.
128 #[default]
129 Auto,
130 /// Always enable loop.
131 Force,
132 /// Always disable loop.
133 Disable,
134}
135
136// /// Method of resampling.
137// //
138// // # Adaptation
139// // Derived from `methodForResampling` enum in the `libsixel` C library.
140// #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
141// pub enum ResampleMethod { // TODO:MAYBE
142// /// Use nearest neighbor method
143// Nearest,
144// /// Use guaussian filter
145// Gaussian,
146// /// Use hanning filter
147// Hanning,
148// /// Use hamming filter
149// Hamming,
150// /// Use bilinear filter
151// Bilinear,
152// /// Use welfilter
153// Welsh,
154// /// Use bicubic filter
155// Bicubic,
156// /// Use lanczos-2 filter
157// Lanczos2,
158// /// Use lanczos-3 filter
159// Lanczos3,
160// /// Use lanczos-4 filter
161// Lanczos4,
162// }
163
164// /// Image format
165// //
166// // # Adaptation
167// // Derived from `imageFormat` enum in the `libsixel` C library.
168// #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
169// enum ImageFormat { // TODO:MAYBE
170// GIF, // 0x0 /* read only */
171// PNG, // 0x1 /* read/write */
172// BMP, // 0x2 /* read only */
173// JPG, // 0x3 /* read only */
174// TGA, // 0x4 /* read only */
175// WBMP, // 0x5 /* read only with --with-gd configure option */
176// TIFF, // 0x6 /* read only */
177// SIXEL, // 0x7 /* read only */
178// PNM, // 0x8 /* read only */
179// GD2, // 0x9 /* read only with --with-gd configure option */
180// PSD, // 0xa /* read only */
181// HDR, // 0xb /* read only */
182// }
183
184// /// Offset value of `PixelFormat`.
185// //
186// // # Adaptation
187// // Derived from `formatType` enum in the `libsixel` C library.
188// #[repr(u8)]
189// #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
190// pub enum PixelFormatType { // TODO:MAYBE
191// Color, // 0
192// Grayscale, // (1 << 6)
193// Palette, // (1 << 7)
194// }