rename imageproc to dither.rs
This commit is contained in:
parent
cee237cb32
commit
a033a55098
14
src/api.rs
14
src/api.rs
|
@ -1,5 +1,5 @@
|
||||||
use crate::display::EInkPanel;
|
use crate::display::EInkPanel;
|
||||||
use crate::imageproc::{DitherMethod, DitherPalette, DitheredImage};
|
use crate::dither::{DitherMethod, DitherPalette, DitheredImage};
|
||||||
use axum::async_trait;
|
use axum::async_trait;
|
||||||
use axum::extract::{FromRequest, Multipart, State};
|
use axum::extract::{FromRequest, Multipart, State};
|
||||||
use axum::http::{header, StatusCode};
|
use axum::http::{header, StatusCode};
|
||||||
|
@ -153,7 +153,11 @@ async fn set_image(
|
||||||
img_req: ImageRequest,
|
img_req: ImageRequest,
|
||||||
) -> Result<impl IntoResponse, AppError> {
|
) -> Result<impl IntoResponse, AppError> {
|
||||||
// FIXME: resize image to 800x480 to match the eink panel.
|
// 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();
|
let mut dither = img_req.dither_method.get_ditherer();
|
||||||
dither.dither(&img_req.image, &mut buf);
|
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.
|
/// 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.
|
/// 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> {
|
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();
|
let mut dither = img_req.dither_method.get_ditherer();
|
||||||
dither.dither(&img_req.image, &mut buf);
|
dither.dither(&img_req.image, &mut buf);
|
||||||
|
|
|
@ -8,7 +8,7 @@ use tracing::{debug, warn};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use linux_embedded_hal::gpio_cdev::{Chip, LineRequestFlags};
|
use linux_embedded_hal::gpio_cdev::{Chip, LineRequestFlags};
|
||||||
|
|
||||||
use crate::imageproc::DitheredImage;
|
use crate::dither::DitheredImage;
|
||||||
|
|
||||||
pub trait EInkPanel {
|
pub trait EInkPanel {
|
||||||
fn display(&mut self, buf: &DitheredImage) -> Result<()>;
|
fn display(&mut self, buf: &DitheredImage) -> Result<()>;
|
||||||
|
@ -83,7 +83,7 @@ pub struct FakeEInk();
|
||||||
impl EInkPanel for FakeEInk {
|
impl EInkPanel for FakeEInk {
|
||||||
fn display(&mut self, img: &DitheredImage) -> Result<()> {
|
fn display(&mut self, img: &DitheredImage) -> Result<()> {
|
||||||
warn!("Fake display was called: saving to display.bmp");
|
warn!("Fake display was called: saving to display.bmp");
|
||||||
img.into_rgbimage().save("display.bmp");
|
img.into_rgbimage().save("display.bmp")?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,10 @@ impl DitheredImage {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert the index-based image back into an RGB image using the color palette.
|
/// 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]
|
#[must_use]
|
||||||
pub fn into_rgbimage(&self) -> RgbImage {
|
pub fn into_rgbimage(&self) -> RgbImage {
|
||||||
RgbImage::from_fn(self.buf.width(), self.buf.height(), |x, y| {
|
RgbImage::from_fn(self.buf.width(), self.buf.height(), |x, y| {
|
|
@ -1,10 +1,10 @@
|
||||||
pub mod api;
|
pub mod api;
|
||||||
pub mod display;
|
pub mod display;
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
pub mod imageproc;
|
pub mod dither;
|
||||||
|
|
||||||
use crate::display::{EInkPanel, FakeEInk, Wrapper};
|
use crate::display::{EInkPanel, FakeEInk, Wrapper};
|
||||||
use crate::imageproc::{DitherMethod, DitheredImage};
|
use crate::dither::{DitherMethod, DitheredImage};
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use image::RgbImage;
|
use image::RgbImage;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
|
|
Loading…
Reference in a new issue