tauri_plugin_android_fs/models/
image.rs

1use 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    /// - Loss less
15    /// - Support transparency
16    Png,
17
18    /// - Lossy
19    /// - Unsupport transparency
20    Jpeg,
21
22    /// - Lossy (**Not loss less**)
23    /// - Support transparency
24    Webp,
25
26    /// - Lossy
27    /// - Unsupport transparency
28    JpegWith {
29
30        /// Range is `0.0 ~ 1.0`  
31        /// 0.0 means compress for the smallest size.  
32        /// 1.0 means compress for max visual quality.  
33        quality: f32
34    },
35
36    /// - Lossy
37    /// - Support transparency
38    WebpWith {
39        
40        /// Range is `0.0 ~ 1.0`  
41        /// 0.0 means compress for the smallest size.  
42        /// 1.0 means compress for max visual quality.  
43        quality: f32
44    }
45}
46
47impl ImageFormat {
48
49    pub(crate) fn mime_type(&self) -> &'static str {
50        match self {
51            ImageFormat::Jpeg | ImageFormat::JpegWith { .. } => "image/jpeg",
52            ImageFormat::Webp | ImageFormat::WebpWith { .. } => "image/webp",
53            ImageFormat::Png => "image/png",
54        }
55    }
56}