Compare commits

..

No commits in common. "59886a80fd337bd2d8c3815b6f3e586a6a02d032" and "37f67323e13e86ee1fefa639440f391eeb157c33" have entirely different histories.

3 changed files with 6 additions and 9 deletions

View file

@ -3,17 +3,14 @@ use image::{ImageReader, RgbImage};
use pi_frame_server::dither::{DitherMethod, DitheredImage, Palette};
fn criterion_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("dithering_benchmark");
let sample_file = "sample_0.tiff";
let image: RgbImage = ImageReader::open(format!("samples/{sample_file}"))
.expect("file exists")
.decode()
.expect("file is valid")
.into_rgb8();
group.sample_size(20);
group.bench_with_input(BenchmarkId::new("dither", "sample_0"), &image, |b, i| {
c.bench_with_input(BenchmarkId::new("dither", "sample_0"), &image, |b, i| {
b.iter(|| {
let mut method = DitherMethod::Atkinson.get_ditherer();
let mut result = DitheredImage::new(

View file

@ -22,12 +22,12 @@ pub enum ApiError {
}
#[derive(Clone)]
pub struct AppState {
pub struct Context {
display_channel: Sender<DisplaySetCommand>,
display_task: Arc<JoinHandle<()>>,
}
impl AppState {
impl Context {
#[must_use]
pub fn new(disp: Box<dyn EInkPanel + Send>) -> Self {
let (tx, rx) = mpsc::channel(2);
@ -86,7 +86,7 @@ pub async fn display_task(
/// API routes for axum
/// Start with the basics: Send an image, crop it, dither, and upload.
/// we defer the upload to a separate task.
pub fn router() -> Router<AppState> {
pub fn router() -> Router<Context> {
Router::new()
.route("/setimage", post(set_image))
.route("/preview", post(preview_image))
@ -149,7 +149,7 @@ where
#[instrument(skip(ctx))]
async fn set_image(
State(ctx): State<AppState>,
State(ctx): State<Context>,
img_req: ImageRequest,
) -> Result<impl IntoResponse, AppError> {
// FIXME: resize image to 800x480 to match the eink panel.

View file

@ -80,7 +80,7 @@ async fn main() -> anyhow::Result<()> {
Command::Serve => {
let display = FakeEInk {};
let ctx = api::AppState::new(Box::new(display));
let ctx = api::Context::new(Box::new(display));
let app = api::router().with_state(ctx);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;