|
|
|
@ -21,13 +21,7 @@ use heapless::Vec;
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "jpeg")]
|
|
|
|
|
use crate::ui::display::tjpgd::{jpeg_info, jpeg_test};
|
|
|
|
|
use crate::{
|
|
|
|
|
micropython::{
|
|
|
|
|
buffer::get_buffer,
|
|
|
|
|
ffi::{mp_obj_new_int, mp_obj_new_tuple},
|
|
|
|
|
},
|
|
|
|
|
ui::display::toif::Toif,
|
|
|
|
|
};
|
|
|
|
|
use crate::{micropython::buffer::get_buffer, ui::display::toif::Toif};
|
|
|
|
|
|
|
|
|
|
pub fn iter_into_objs<const N: usize>(iterable: Obj) -> Result<[Obj; N], Error> {
|
|
|
|
|
let err = Error::ValueError(cstr!("Invalid iterable length"));
|
|
|
|
@ -224,28 +218,16 @@ pub extern "C" fn upy_disable_animation(disable: Obj) -> Obj {
|
|
|
|
|
#[cfg(feature = "jpeg")]
|
|
|
|
|
pub extern "C" fn upy_jpeg_info(data: Obj) -> Obj {
|
|
|
|
|
let block = || {
|
|
|
|
|
let buffer = unsafe { get_buffer(data) };
|
|
|
|
|
|
|
|
|
|
if let Ok(buffer) = buffer {
|
|
|
|
|
let info = jpeg_info(buffer);
|
|
|
|
|
|
|
|
|
|
if let Some(info) = info {
|
|
|
|
|
let obj = unsafe {
|
|
|
|
|
let values = [
|
|
|
|
|
mp_obj_new_int(info.0.x as _),
|
|
|
|
|
mp_obj_new_int(info.0.y as _),
|
|
|
|
|
mp_obj_new_int(info.1 as _),
|
|
|
|
|
];
|
|
|
|
|
mp_obj_new_tuple(3, values.as_ptr())
|
|
|
|
|
};
|
|
|
|
|
let buffer = unsafe { get_buffer(data) }?;
|
|
|
|
|
|
|
|
|
|
Ok(obj)
|
|
|
|
|
if let Some(info) = jpeg_info(buffer) {
|
|
|
|
|
let w = info.0.x as u16;
|
|
|
|
|
let h = info.0.y as u16;
|
|
|
|
|
let mcu_h = info.1 as u16;
|
|
|
|
|
(w.into(), h.into(), mcu_h.into()).try_into()
|
|
|
|
|
} else {
|
|
|
|
|
Err(Error::ValueError(cstr!("Invalid image format.")))
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Err(Error::ValueError(cstr!("Buffer error.")))
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
unsafe { try_or_raise(block) }
|
|
|
|
@ -253,27 +235,16 @@ pub extern "C" fn upy_jpeg_info(data: Obj) -> Obj {
|
|
|
|
|
|
|
|
|
|
pub extern "C" fn upy_toif_info(data: Obj) -> Obj {
|
|
|
|
|
let block = || {
|
|
|
|
|
let buffer = unsafe { get_buffer(data) };
|
|
|
|
|
|
|
|
|
|
if let Ok(buffer) = buffer {
|
|
|
|
|
let toif = Toif::new(buffer);
|
|
|
|
|
|
|
|
|
|
if let Some(toif) = toif {
|
|
|
|
|
let obj = unsafe {
|
|
|
|
|
let values = [
|
|
|
|
|
mp_obj_new_int(toif.width() as _),
|
|
|
|
|
mp_obj_new_int(toif.height() as _),
|
|
|
|
|
];
|
|
|
|
|
mp_obj_new_tuple(2, values.as_ptr())
|
|
|
|
|
};
|
|
|
|
|
let buffer = unsafe { get_buffer(data) }?;
|
|
|
|
|
|
|
|
|
|
Ok(obj)
|
|
|
|
|
if let Some(toif) = Toif::new(buffer) {
|
|
|
|
|
let w = toif.width() as u16;
|
|
|
|
|
let h = toif.height() as u16;
|
|
|
|
|
let is_grayscale = toif.is_grayscale();
|
|
|
|
|
(w.into(), h.into(), is_grayscale.into()).try_into()
|
|
|
|
|
} else {
|
|
|
|
|
Err(Error::ValueError(cstr!("Invalid image format.")))
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Err(Error::ValueError(cstr!("Buffer error.")))
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
unsafe { try_or_raise(block) }
|
|
|
|
|