rename imageproc to dither.rs

This commit is contained in:
saji 2024-07-30 10:45:29 -05:00
parent cee237cb32
commit a033a55098
4 changed files with 19 additions and 7 deletions

View file

@ -1,5 +1,5 @@
use crate::display::EInkPanel;
use crate::imageproc::{DitherMethod, DitherPalette, DitheredImage};
use crate::dither::{DitherMethod, DitherPalette, DitheredImage};
use axum::async_trait;
use axum::extract::{FromRequest, Multipart, State};
use axum::http::{header, StatusCode};
@ -153,7 +153,11 @@ async fn set_image(
img_req: ImageRequest,
) -> Result<impl IntoResponse, AppError> {
// FIXME: resize image to 800x480 to match the eink panel.
let mut buf = DitheredImage::new(img_req.image.width(), img_req.image.height(), img_req.palette.value().to_vec());
let mut buf = DitheredImage::new(
img_req.image.width(),
img_req.image.height(),
img_req.palette.value().to_vec(),
);
{
let mut dither = img_req.dither_method.get_ditherer();
dither.dither(&img_req.image, &mut buf);
@ -168,7 +172,11 @@ async fn set_image(
/// generates a dithered image based on the given image and the dithering parameters.
/// Can be used to see how the dithering and palette choices affect the result.
async fn preview_image(img_req: ImageRequest) -> Result<impl IntoResponse, AppError> {
let mut buf = DitheredImage::new(img_req.image.width(), img_req.image.height(), img_req.palette.value().to_vec());
let mut buf = DitheredImage::new(
img_req.image.width(),
img_req.image.height(),
img_req.palette.value().to_vec(),
);
{
let mut dither = img_req.dither_method.get_ditherer();
dither.dither(&img_req.image, &mut buf);

View file

@ -8,7 +8,7 @@ use tracing::{debug, warn};
use anyhow::Result;
use linux_embedded_hal::gpio_cdev::{Chip, LineRequestFlags};
use crate::imageproc::DitheredImage;
use crate::dither::DitheredImage;
pub trait EInkPanel {
fn display(&mut self, buf: &DitheredImage) -> Result<()>;
@ -83,7 +83,7 @@ pub struct FakeEInk();
impl EInkPanel for FakeEInk {
fn display(&mut self, img: &DitheredImage) -> Result<()> {
warn!("Fake display was called: saving to display.bmp");
img.into_rgbimage().save("display.bmp");
img.into_rgbimage().save("display.bmp")?;
Ok(())
}

View file

@ -91,6 +91,10 @@ impl DitheredImage {
}
/// Convert the index-based image back into an RGB image using the color palette.
///
/// # Panics
/// May panic if the given palette is somehow not the one used to actually dither, and the
/// image has color indexes that are out of bounds of the palette.
#[must_use]
pub fn into_rgbimage(&self) -> RgbImage {
RgbImage::from_fn(self.buf.width(), self.buf.height(), |x, y| {

View file

@ -1,10 +1,10 @@
pub mod api;
pub mod display;
pub mod errors;
pub mod imageproc;
pub mod dither;
use crate::display::{EInkPanel, FakeEInk, Wrapper};
use crate::imageproc::{DitherMethod, DitheredImage};
use crate::dither::{DitherMethod, DitheredImage};
use clap::{Parser, Subcommand};
use image::RgbImage;
use tracing::{error, info};