Skip to main content

sixel/
optflags.rs

1// use sixel::*;
2use std::path::Path;
3
4#[doc(hidden)]
5pub type OptflagUnderlying = u8;
6
7// #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
8// pub enum Optflag {
9//     Input,
10//     Output,
11//     Outfile,
12//     SevenBitMode,
13//     EightBitMode,
14//     HasGriArgLimit,
15//     Colors,
16//     Mapfile,
17//     Monochrome,
18//     Insecure,
19//     Invert,
20//     HighColor,
21//     UseMacro,
22//     MacroNumber,
23//     ComplexionScore,
24//     IgnoreDelay,
25//     Static,
26//     Diffusion,
27//     FindLargest,
28//     SelectColor,
29//     Crop,
30//     Width,
31//     Height,
32//     Resampling,
33//     Quality,
34//     Loopmode,
35//     PaletteType,
36//     BuiltinPalette,
37//     EncodePolicy,
38//     Bgcolor,
39//     Penetrate,
40//     PipeMode,
41//     Verbose,
42//     Version,
43//     Help
44// }
45
46#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
47pub enum BitMode {
48    SevenBit,
49    EightBit,
50}
51
52#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
53pub enum BuiltinPalette {
54    XTerm16,
55    XTerm256,
56    VT340Mono,
57    VT340Color,
58    Gray1,
59    Gray2,
60    Gray4,
61    Gray8,
62}
63
64impl BuiltinPalette {
65    pub fn to_str(self) -> &'static str {
66        use self::BuiltinPalette::*;
67
68        match self {
69            XTerm16 => "xterm16",
70            XTerm256 => "xterm256",
71            VT340Mono => "vt340mono",
72            VT340Color => "vt340color",
73            Gray1 => "gray1",
74            Gray2 => "gray2",
75            Gray4 => "gray4",
76            Gray8 => "gray8",
77        }
78    }
79}
80
81#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
82pub enum ColorOption<'a> {
83    Monochrome,
84    Builtin(&'a str),
85    Mapfile(&'a Path),
86    Highcolor,
87}
88
89impl<'a> ColorOption<'a> {
90    // So that you can select a builtin color option using enums instead of strings
91    pub fn builtin_palette(palette: self::BuiltinPalette) -> ColorOption<'static> {
92        ColorOption::Builtin(palette.to_str())
93    }
94}
95
96#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
97pub enum DiffusionMethod {
98    Auto,
99    None,
100    FS,
101    Atkinson,
102    Jajuni,
103    Stucki,
104    Burkes,
105}
106
107impl DiffusionMethod {
108    pub fn to_str(self) -> &'static str {
109        use self::DiffusionMethod::*;
110
111        match self {
112            Auto => "auto",
113            None => "none",
114            FS => "fs",
115            Atkinson => "atkinson",
116            Jajuni => "jajuni",
117            Stucki => "stucki",
118            Burkes => "burkes",
119        }
120    }
121}
122
123#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
124pub enum FindLargestOpt {
125    Auto,
126    Norm,
127    Lum,
128}
129
130impl FindLargestOpt {
131    pub fn to_str(self) -> &'static str {
132        use self::FindLargestOpt::*;
133
134        match self {
135            Auto => "auto",
136            Norm => "norm",
137            Lum => "lum",
138        }
139    }
140}
141
142#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
143pub enum ColorSelectionMethod {
144    Auto,
145    Center,
146    Average,
147    Histogram,
148}
149
150impl ColorSelectionMethod {
151    pub fn to_str(self) -> &'static str {
152        use self::ColorSelectionMethod::*;
153
154        match self {
155            Auto => "auto",
156            Center => "center",
157            Average => "average",
158            Histogram => "histogram",
159        }
160    }
161}
162
163#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
164pub enum SizeSpecification {
165    Auto,
166    Pixel(u64),
167    Percent(u64),
168}
169
170impl ToString for SizeSpecification {
171    fn to_string(&self) -> String {
172        use self::SizeSpecification::*;
173
174        match *self {
175            Auto => "auto".to_owned(),
176            Pixel(size) => format!("{}px", size),
177            Percent(size) => format!("{}%", size),
178        }
179    }
180}
181
182#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
183pub enum ResampleMethod {
184    Nearest,
185    Gaussian,
186    Hanning,
187    Hamming,
188    Bilinear,
189    Welsh,
190    Bicubic,
191    Lanczos2,
192    Lanczos3,
193    Lanczos4,
194}
195
196impl ResampleMethod {
197    pub fn to_str(self) -> &'static str {
198        use self::ResampleMethod::*;
199
200        match self {
201            Nearest => "nearest",
202            Gaussian => "gaussian",
203            Hanning => "hanning",
204            Hamming => "hamming",
205            Bilinear => "bilinear",
206            Welsh => "welsh",
207            Bicubic => "bicubic",
208            Lanczos2 => "lanczos2",
209            Lanczos3 => "lanczos3",
210            Lanczos4 => "lanczos4",
211        }
212    }
213}
214
215#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
216pub enum Quality {
217    Auto,
218    High,
219    Low,
220    Full,
221}
222
223impl Quality {
224    pub fn to_str(self) -> &'static str {
225        use self::Quality::*;
226
227        match self {
228            Auto => "auto",
229            High => "high",
230            Low => "low",
231            Full => "full",
232        }
233    }
234}
235
236#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
237pub enum LoopMode {
238    Auto,
239    Force,
240    Disable,
241}
242
243impl LoopMode {
244    pub fn to_str(self) -> &'static str {
245        use self::LoopMode::*;
246
247        match self {
248            Auto => "auto",
249            Force => "force",
250            Disable => "disable",
251        }
252    }
253}
254
255#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
256pub enum PaletteType {
257    Auto,
258    HLS,
259    RGB,
260}
261
262impl PaletteType {
263    pub fn to_str(self) -> &'static str {
264        use self::PaletteType::*;
265
266        match self {
267            Auto => "auto",
268            HLS => "hls",
269            RGB => "rgb",
270        }
271    }
272}
273
274#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
275pub enum EncodePolicy {
276    Auto,
277    Fast,
278    Size,
279}
280
281impl EncodePolicy {
282    pub fn to_str(self) -> &'static str {
283        use self::EncodePolicy::*;
284
285        match self {
286            Auto => "auto",
287            Fast => "fast",
288            Size => "size",
289        }
290    }
291}