use pyo3::{prelude::*, types::PyBytes};
use tauri::image;
#[pyclass(frozen, subclass)] #[non_exhaustive]
pub struct Image {
rgba: Py<PyBytes>,
width: u32,
height: u32,
}
impl Image {
pub(crate) fn to_tauri<'a>(&'a self, py: Python<'_>) -> image::Image<'a> {
image::Image::new(self.rgba.as_bytes(py), self.width, self.height)
}
pub(crate) fn from_tauri(py: Python<'_>, image: &image::Image) -> Self {
Self {
rgba: PyBytes::new(py, image.rgba()).unbind(),
width: image.width(),
height: image.height(),
}
}
}
#[pymethods]
impl Image {
#[new]
const fn __new__(rgba: Py<PyBytes>, width: u32, height: u32) -> Self {
Self {
rgba,
width,
height,
}
}
const fn rgba(&self) -> &Py<PyBytes> {
&self.rgba
}
const fn width(&self) -> u32 {
self.width
}
const fn height(&self) -> u32 {
self.height
}
}