1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::prelude::Handle;
use crate::{Data, EncodedImageFormat};
use skia_bindings::{SkBitmap, SkPixmap};
impl Handle<SkPixmap> {
pub fn encode(&self, format: EncodedImageFormat, quality: usize) -> Option<Data> {
crate::encode::pixmap(self, format, quality)
}
}
impl Handle<SkBitmap> {
pub fn encode(&self, format: EncodedImageFormat, quality: usize) -> Option<Data> {
crate::encode::bitmap(self, format, quality)
}
}
pub mod encode {
use crate::prelude::*;
use crate::{Bitmap, Data, EncodedImageFormat, Pixmap};
use skia_bindings as sb;
pub fn pixmap(src: &Pixmap, format: EncodedImageFormat, quality: usize) -> Option<Data> {
Data::from_ptr(unsafe {
sb::C_SkEncodePixmap(
src.native(),
format.into_native(),
quality.try_into().unwrap(),
)
})
}
pub fn bitmap(src: &Bitmap, format: EncodedImageFormat, quality: usize) -> Option<Data> {
Data::from_ptr(unsafe {
sb::C_SkEncodeBitmap(
src.native(),
format.into_native(),
quality.try_into().unwrap(),
)
})
}
}