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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use crate::draw::*;
pub use crate::prelude::*;
use fltk_sys::image::*;
use std::{ffi::CString, mem, os::raw};
#[derive(Debug, Clone)]
pub struct Image {
_inner: *mut Fl_Image,
}
impl<I: ImageExt> From<I> for Image {
fn from(s: I) -> Self {
let img: *mut Fl_Image = s.as_image_ptr();
Image { _inner: img }
}
}
impl Image {
pub fn as_ptr(&mut self) -> *mut Fl_Image {
self._inner
}
pub fn from_raw(ptr: *mut fltk_sys::image::Fl_Image) -> Self {
Image { _inner: ptr }
}
pub fn downcast_into<I: ImageExt>(&mut self) -> I {
I::from_image_ptr(self._inner)
}
}
#[derive(ImageExt, Debug, Clone)]
pub struct JpegImage {
_inner: *mut Fl_JPEG_Image,
}
#[derive(ImageExt, Debug, Clone)]
pub struct PngImage {
_inner: *mut Fl_PNG_Image,
}
#[derive(ImageExt, Debug, Clone)]
pub struct SvgImage {
_inner: *mut Fl_SVG_Image,
}
#[derive(ImageExt, Debug, Clone)]
pub struct BmpImage {
_inner: *mut Fl_BMP_Image,
}
#[derive(ImageExt, Debug, Clone)]
pub struct GifImage {
_inner: *mut Fl_GIF_Image,
}
#[derive(Debug, Clone)]
pub struct RgbImage {
_inner: Vec<u8>,
_w: i32,
_h: i32,
}
impl RgbImage {
pub fn new(data: Vec<u8>, w: i32, h: i32) -> RgbImage {
RgbImage {
_inner: data,
_w: w,
_h: h,
}
}
pub fn into_parts(self) -> (Vec<u8>, i32, i32) {
(self._inner, self._w, self._h)
}
pub fn into_png_image(self) -> Result<PngImage, FltkError> {
let path = std::path::PathBuf::from("_internal_temp_fltk_file.png");
let _ = write_to_png_file(self, &path)?;
let ret = PngImage::new(&path).copy();
std::fs::remove_file(&path)?;
Ok(ret)
}
pub fn into_jpg_image(self) -> Result<JpegImage, FltkError> {
let path = std::path::PathBuf::from("_internal_temp_fltk_file.jpg");
let _ = write_to_jpg_file(self, &path)?;
let ret = JpegImage::new(&path).copy();
std::fs::remove_file(&path)?;
Ok(ret)
}
pub fn into_bmp_image(&self) -> Result<BmpImage, FltkError> {
let path = std::path::PathBuf::from("_internal_temp_fltk_file.bmp");
let _ = write_to_bmp_file(self.clone(), &path)?;
let ret = BmpImage::new(&path).copy();
std::fs::remove_file(&path)?;
Ok(ret)
}
}