combostew/operations/wrapper/
filter_type.rs1use std::error::Error;
2use std::fmt::{Debug, Formatter};
3
4pub enum FilterTypeWrap {
7 Inner(image::FilterType),
8}
9
10impl PartialEq<FilterTypeWrap> for FilterTypeWrap {
11 fn eq(&self, other: &FilterTypeWrap) -> bool {
12 match (self, other) {
13 (
14 FilterTypeWrap::Inner(image::FilterType::CatmullRom),
15 FilterTypeWrap::Inner(image::FilterType::CatmullRom),
16 ) => true,
17 (
18 FilterTypeWrap::Inner(image::FilterType::Gaussian),
19 FilterTypeWrap::Inner(image::FilterType::Gaussian),
20 ) => true,
21 (
22 FilterTypeWrap::Inner(image::FilterType::Lanczos3),
23 FilterTypeWrap::Inner(image::FilterType::Lanczos3),
24 ) => true,
25 (
26 FilterTypeWrap::Inner(image::FilterType::Nearest),
27 FilterTypeWrap::Inner(image::FilterType::Nearest),
28 ) => true,
29 (
30 FilterTypeWrap::Inner(image::FilterType::Triangle),
31 FilterTypeWrap::Inner(image::FilterType::Triangle),
32 ) => true,
33 _ => false,
34 }
35 }
36}
37
38impl Clone for FilterTypeWrap {
39 fn clone(&self) -> Self {
40 match self {
41 FilterTypeWrap::Inner(a) => FilterTypeWrap::Inner(*a),
42 }
43 }
44}
45
46impl Eq for FilterTypeWrap {}
47
48impl Debug for FilterTypeWrap {
49 fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
50 let msg = match self {
51 FilterTypeWrap::Inner(image::FilterType::CatmullRom) => {
52 "image::FilterType::CatmullRom (Wrapper)"
53 }
54 FilterTypeWrap::Inner(image::FilterType::Gaussian) => {
55 "image::FilterType::Gaussian (Wrapper)"
56 }
57 FilterTypeWrap::Inner(image::FilterType::Lanczos3) => {
58 "image::FilterType::Lanczos3 (Wrapper)"
59 }
60 FilterTypeWrap::Inner(image::FilterType::Nearest) => {
61 "image::FilterType::Nearest (Wrapper)"
62 }
63 FilterTypeWrap::Inner(image::FilterType::Triangle) => {
64 "image::FilterType::Triangle (Wrapper)"
65 }
66 };
67
68 f.write_str(msg)
69 }
70}
71
72impl From<FilterTypeWrap> for image::FilterType {
73 fn from(wrap: FilterTypeWrap) -> Self {
74 match wrap {
75 FilterTypeWrap::Inner(w) => w,
76 }
77 }
78}
79
80impl FilterTypeWrap {
81 pub fn try_from_str(val: &str) -> Result<FilterTypeWrap, Box<dyn Error>> {
82 match val.to_lowercase().as_str() {
83 "catmullrom" | "cubic" => Ok(FilterTypeWrap::Inner(image::FilterType::CatmullRom)),
84 "gaussian" => Ok(FilterTypeWrap::Inner(image::FilterType::Gaussian)),
85 "lanczos3" => Ok(FilterTypeWrap::Inner(image::FilterType::Lanczos3)),
86 "nearest" => Ok(FilterTypeWrap::Inner(image::FilterType::Nearest)),
87 "triangle" => Ok(FilterTypeWrap::Inner(image::FilterType::Triangle)),
88 fail => Err(format!("No such sampling filter: {}", fail).into()),
89 }
90 }
91}