From: MegaBrutal Date: Thu, 14 Jul 2022 21:30:45 +0000 (+0200) Subject: /pgen/0 now resizes image as /gen/0 does X-Git-Url: http://git.megabrutal.com/?a=commitdiff_plain;h=59d0212130f0a8501a206422b1cc40b6ccb30ed1;hp=f31d6495cc627afbfd9ffa04e65359275ccb0cd7;p=litoprism.git /pgen/0 now resizes image as /gen/0 does --- diff --git a/src/main.rs b/src/main.rs index 7340b0b..32202b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -142,7 +142,6 @@ fn make_png(dim_x: u32, dim_y: u32, scale: u32, data: &mut dyn Iterator Result { let data = req.uri().path().split("/").skip(3).next().unwrap(); let cursor = make_png(32, 32, 16, percent_decode_str(&data).into_iter().borrow_mut())?; - println!("{:?}", &cursor); Ok(HttpResponse::build(StatusCode::OK) .content_type("image/png") .body(cursor.into_inner())) @@ -162,15 +161,17 @@ async fn img_gen1(req: HttpRequest, path: web::Path<(u32, u32, u32)>) -> Result< async fn img_pgen0(req: HttpRequest, canvas0: web::Data>>>) -> Result { let data = req.uri().path().split("/").skip(3).next().unwrap(); let mut cursor = Cursor::new(Vec::new()); - let tdim_x = 32; - let tdim_y = 32; - { + let scale = 16; + let tdim_x = 32 * scale; + let tdim_y = 32 * scale; + let img: RgbImage = { let mut canvas_option = &mut *canvas0.lock().unwrap(); let canvas = canvas_option.take(); let canvas = rgb_encode_to_canvas(canvas.expect("Canvas doesn't exist!"), percent_decode_str(&data).into_iter().borrow_mut())?; - to_imageresult(write_buffer_with_format(&mut cursor, &canvas.img, tdim_x, tdim_y, ColorType::Rgb8, Png))?; - canvas_option.insert(canvas); - } + canvas_option.insert(canvas).img.clone() + }; + let img = resize(&img, tdim_x, tdim_y, FilterType::Nearest); + to_imageresult(write_buffer_with_format(&mut cursor, &img, tdim_x, tdim_y, ColorType::Rgb8, Png))?; Ok(HttpResponse::build(StatusCode::OK) .content_type("image/png") .body(cursor.into_inner()))