kindle_screensaver/
structs.rs1use thiserror::Error;
2use image::imageops;
3
4#[derive(Debug, Clone, Copy, PartialEq)]
5pub enum KindleModel {
6 Basic,
7 Paperwhite,
8 Colorsoft,
9}
10
11#[derive(Debug, Clone, Copy, PartialEq)]
12pub enum DitheringAlgorithm {
13 None,
14 FloydSteinberg,
15 Ordered,
16}
17
18#[derive(Debug, Clone, Copy, PartialEq)]
19pub enum ResizingMethod {
20 Nearest,
21 Triangle,
22 Lanczos3,
23}
24
25
26impl ResizingMethod {
27 pub fn to_filter_type(&self) -> imageops::FilterType {
28 match self {
29 ResizingMethod::Nearest => imageops::FilterType::Nearest,
30 ResizingMethod::Triangle => imageops::FilterType::Triangle,
31 ResizingMethod::Lanczos3 => imageops::FilterType::Lanczos3,
32 }
33 }
34}
35
36impl ConversionOptions {
37 pub fn filter_type(&self) -> imageops::FilterType {
38 self.resizing_method.to_filter_type()
39 }
40}
41
42#[derive(Clone, Copy, PartialEq)]
43pub struct ConversionOptions {
44 pub model: KindleModel,
45 pub dithering: DitheringAlgorithm,
46 pub optimize_contrast: bool,
47 pub resizing_method: ResizingMethod,
48}
49
50impl Default for ConversionOptions {
51 fn default() -> Self {
52 Self {
53 model: KindleModel::Paperwhite,
54 dithering: DitheringAlgorithm::None,
55 optimize_contrast: true,
56 resizing_method: ResizingMethod::Nearest,
57 }
58 }
59}
60
61impl KindleModel {
62 pub fn dimensions(&self) -> (u32, u32) {
63 match self {
64 KindleModel::Basic => (1072, 1448),
65 KindleModel::Paperwhite => (1072, 1448),
66 KindleModel::Colorsoft => (1272, 1696),
67 }
68 }
69
70 pub fn bit_depth(&self) -> u8 {
71 match self {
72 KindleModel::Basic => 8,
73 KindleModel::Paperwhite => 8,
74 KindleModel::Colorsoft => 32,
75 }
76 }
77
78 pub fn is_color(&self) -> bool {
79 match self {
81 KindleModel::Colorsoft => true,
82 _ => false,
83 }
84 }
85}
86
87#[derive(Error, Debug)]
88pub enum KindleError {
89 #[error("Image processing error: {0}")]
90 ImageError(#[from] image::ImageError),
91
92 #[error("IO error: {0}")]
93 IoError(#[from] std::io::Error),
94
95 #[error("Unsupported image format")]
96 UnsupportedFormat,
97
98 #[error("Invalid input data")]
99 InvalidData,
100}