From: MegaBrutal Date: Sat, 24 Dec 2022 22:30:00 +0000 (+0100) Subject: Implement /gen/5 X-Git-Url: http://git.megabrutal.com/?p=litoprism.git;a=commitdiff_plain;h=e21bfd707bf838591e55eb1dba9222d1b70c8b28 Implement /gen/5 --- diff --git a/src/main.rs b/src/main.rs index 460364b..25a4e4a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -372,6 +372,31 @@ async fn img_gen4(req: HttpRequest, path: web::Path<(u32, u32, u32, u32, u32, f3 Ok(response_image!(cursor)) } +#[get("/gen/5/{dim_x}/{dim_y}/{scale}/{offset_x}/{offset_y}/{run}/{color}/{data}")] +async fn img_gen5(req: HttpRequest, path: web::Path<(u32, u32, u32, u32, u32, u32)>) -> Result { + let (dim_x, dim_y, scale, offset_x, offset_y, run) = path.into_inner(); + let color = extract_color!(req, 9)?; + let data = &mut percent_decode_str(extract_data!(req, 10)); + let cursor = make_png(dim_x, dim_y, scale, data, + |mut img, data| { + let mut x = offset_x; + let mut data = data.peekable(); + while (x < img.width()) && (data.peek().is_some()) { + let v = data.next().unwrap_or(0); + let y = offset_y + v as u32; + let max_x = if (x + run) < img.width() { x + run } else { img.width() }; + while x < max_x { + if y < img.height() { + img.put_pixel(x, offset_y + v as u32, color); + } + x += 1; + } + } + Ok(img) + })?; + Ok(response_image!(cursor)) +} + #[get("/pgen/0/{data}")] async fn img_pgen0(req: HttpRequest, canvas0: web::Data>>) -> Result { let data = extract_data!(req, 3); @@ -489,6 +514,7 @@ async fn main() -> std::io::Result<()> { .service(img_gen2) .service(img_gen3) .service(img_gen4) + .service(img_gen5) .service(img_pgen0) .service(img_pgen1) .service(img_pgen2)