mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
remove dither crate dependency from modal tests
This commit is contained in:
parent
6f2e2ed9bc
commit
6dfed76b66
1 changed files with 14 additions and 33 deletions
|
|
@ -1,12 +1,6 @@
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
use super::*;
|
use super::*;
|
||||||
#[cfg(feature = "ditherpunk")]
|
|
||||||
use dither::prelude::{Img, RGB};
|
|
||||||
use gam::*;
|
use gam::*;
|
||||||
#[cfg(feature = "ditherpunk")]
|
|
||||||
use jpeg_decoder as jpeg;
|
|
||||||
#[cfg(feature = "ditherpunk")]
|
|
||||||
use std::fs::File;
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use xous_names::XousNames;
|
use xous_names::XousNames;
|
||||||
|
|
||||||
|
|
@ -149,7 +143,10 @@ pub fn spawn_test() {
|
||||||
{
|
{
|
||||||
log::info!("testing image");
|
log::info!("testing image");
|
||||||
match get_test_png("../services/modals/src/tests/bunny.png") {
|
match get_test_png("../services/modals/src/tests/bunny.png") {
|
||||||
Some(img) => modals.show_image(&img).expect("show image modal failed"),
|
Some((pixels, width)) => {
|
||||||
|
let img = Img::new(pixels, width);
|
||||||
|
modals.show_image(&img).expect("show image modal failed");
|
||||||
|
}
|
||||||
None => log::warn!("failed to load test image"),
|
None => log::warn!("failed to load test image"),
|
||||||
}
|
}
|
||||||
log::info!("image modal test done");
|
log::info!("image modal test done");
|
||||||
|
|
@ -162,8 +159,8 @@ pub fn spawn_test() {
|
||||||
feature = "ditherpunk",
|
feature = "ditherpunk",
|
||||||
not(any(target_os = "none", target_os = "xous"))
|
not(any(target_os = "none", target_os = "xous"))
|
||||||
))]
|
))]
|
||||||
fn get_test_png(path: &str) -> Option<Img<RGB<u8>>> {
|
fn get_test_png(path: &str) -> Option<(Vec<u8>, usize)> {
|
||||||
let file = match File::open(path) {
|
let file = match std::fs::File::open(path) {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("cannot load png image, {}", err);
|
log::error!("cannot load png image, {}", err);
|
||||||
return None;
|
return None;
|
||||||
|
|
@ -174,48 +171,32 @@ fn get_test_png(path: &str) -> Option<Img<RGB<u8>>> {
|
||||||
let mut reader = decoder.read_info().expect("failed to read png info");
|
let mut reader = decoder.read_info().expect("failed to read png info");
|
||||||
let mut buf = vec![0; reader.output_buffer_size()];
|
let mut buf = vec![0; reader.output_buffer_size()];
|
||||||
let info = reader.next_frame(&mut buf).expect("failed to decode png");
|
let info = reader.next_frame(&mut buf).expect("failed to decode png");
|
||||||
|
log::info!("png width {:?}", info.width);
|
||||||
let (width, height) = (info.width, info.height);
|
let width: usize = info.width.try_into().unwrap();
|
||||||
Some(vec_u8_to_img_rgb(buf, width, height))
|
Some((buf, width))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
feature = "ditherpunk",
|
feature = "ditherpunk",
|
||||||
not(any(target_os = "none", target_os = "xous"))
|
not(any(target_os = "none", target_os = "xous"))
|
||||||
))]
|
))]
|
||||||
fn get_test_jpeg(path: &str) -> Option<Img<RGB<u8>>> {
|
fn get_test_jpeg(path: &str) -> Option<(Vec<u8>, usize)> {
|
||||||
let file = match File::open(path) {
|
let file = match std::fs::File::open(path) {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("cannot load jpeg image, {}", err);
|
log::error!("cannot load jpeg image, {}", err);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
};
|
};
|
||||||
let mut decoder = jpeg::Decoder::new(file);
|
let mut decoder = jpeg_decoder::Decoder::new(file);
|
||||||
decoder
|
decoder
|
||||||
.scale(Modals::MODAL_WIDTH as u16, Modals::MODAL_HEIGHT as u16)
|
.scale(Modals::MODAL_WIDTH as u16, Modals::MODAL_HEIGHT as u16)
|
||||||
.expect("failed to scale jpeg");
|
.expect("failed to scale jpeg");
|
||||||
let _reader = decoder.read_info().expect("failed to read png info");
|
let _reader = decoder.read_info().expect("failed to read png info");
|
||||||
let pixels = decoder.decode().expect("failed to decode jpeg image");
|
let pixels = decoder.decode().expect("failed to decode jpeg image");
|
||||||
let info = decoder.info().unwrap();
|
let info = decoder.info().unwrap();
|
||||||
|
let width: usize = info.width.try_into().unwrap();
|
||||||
let (width, height) = (info.width, info.height);
|
Some((pixels, width))
|
||||||
Some(vec_u8_to_img_rgb(pixels, width.into(), height.into()))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(all(
|
|
||||||
feature = "ditherpunk",
|
|
||||||
not(any(target_os = "none", target_os = "xous"))
|
|
||||||
))]
|
|
||||||
fn vec_u8_to_img_rgb(buf: Vec<u8>, width: u32, height: u32) -> Img<RGB<u8>> {
|
|
||||||
let px = width * height;
|
|
||||||
let mut pixels: Vec<RGB<u8>> = Vec::with_capacity(px.try_into().unwrap());
|
|
||||||
let mut i = 0;
|
|
||||||
while i < buf.len() {
|
|
||||||
pixels.push(RGB::from([buf[i], buf[i + 1], buf[i + 2]]));
|
|
||||||
i += 3;
|
|
||||||
}
|
|
||||||
Img::new(pixels, width).expect("failed to create Image")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_validator(input: TextEntryPayload) -> Option<xous_ipc::String<256>> {
|
fn test_validator(input: TextEntryPayload) -> Option<xous_ipc::String<256>> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue