tauri_plugin_android_fs/models/
image.rs1use serde::{Deserialize, Serialize};
2
3
4#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, Deserialize, Serialize)]
5pub struct Size {
6 pub width: u32,
7 pub height: u32
8}
9
10#[derive(Debug, Clone, Copy, PartialEq, Deserialize, Serialize)]
11#[non_exhaustive]
12pub enum ImageFormat {
13
14 Png,
17
18 Jpeg,
21
22 Webp,
25
26 JpegWith {
29
30 quality: f32
34 },
35
36 WebpWith {
39
40 quality: f32
44 }
45}
46
47#[allow(unused)]
48impl ImageFormat {
49
50 pub(crate) fn mime_type(&self) -> &'static str {
51 match self {
52 ImageFormat::Jpeg | ImageFormat::JpegWith { .. } => "image/jpeg",
53 ImageFormat::Webp | ImageFormat::WebpWith { .. } => "image/webp",
54 ImageFormat::Png => "image/png",
55 }
56 }
57
58 pub(crate) fn from_mime_type(mime_type: &str) -> Option<Self> {
59 match mime_type {
60 "image/jpeg" | "image/jpg" => Some(Self::Jpeg),
61 "image/webp" => Some(Self::Webp),
62 "image/png" => Some(Self::Png),
63 _ => None,
64 }
65 }
66
67 pub(crate) fn from_name(name: &str) -> Option<Self> {
68 if name.eq_ignore_ascii_case("jpeg") || name.eq_ignore_ascii_case("jpg") {
69 Some(Self::Jpeg)
70 }
71 else if name.eq_ignore_ascii_case("webp") {
72 Some(Self::Webp)
73 }
74 else if name.eq_ignore_ascii_case("png") {
75 Some(Self::Png)
76 }
77 else {
78 None
79 }
80 }
81}