const TIMEAVATAR_SIZE_U32: u32 = 6;
const TIMEAVATAR_SIZE_I64: i64 = TIMEAVATAR_SIZE_U32 as i64;
+macro_rules! response_image {
+ ($cursor:expr) => {
+ HttpResponse::build(StatusCode::OK)
+ .content_type("image/png")
+ .body($cursor.into_inner())
+ }
+}
+
#[derive(Debug)]
struct ImageError(image::ImageError);
async fn img_gen0(req: HttpRequest) -> Result<impl Responder> {
let data = req.uri().path().split('/').nth(3).unwrap();
let cursor = make_png(32, 32, 16, percent_decode_str(data).into_iter().borrow_mut())?;
- Ok(HttpResponse::build(StatusCode::OK)
- .content_type("image/png")
- .body(cursor.into_inner()))
+ Ok(response_image!(cursor))
}
#[get("/gen/1/{dim_x}/{dim_y}/{scale}/{data}")]
let (dim_x, dim_y, scale) = path.into_inner();
let data = req.uri().path().split('/').nth(6).unwrap();
let cursor = make_png(dim_x, dim_y, scale, percent_decode_str(data).into_iter().borrow_mut())?;
- Ok(HttpResponse::build(StatusCode::OK)
- .content_type("image/png")
- .body(cursor.into_inner()))
+ Ok(response_image!(cursor))
}
#[get("/gen/2/{dim_x}/{dim_y}/{scale}")]
_ => ""
};
let cursor = make_png(dim_x, dim_y, scale, &mut data.bytes())?;
- Ok(HttpResponse::build(StatusCode::OK)
- .content_type("image/png")
- .body(cursor.into_inner()))
+ Ok(response_image!(cursor))
}
#[get("/gen/3/{scale}")]
let (hour, minute): (i64, i64) = (time.hour().into(), time.minute().into());
overlay(&mut resimg, &rgbimg, minute * TIMEAVATAR_SIZE_I64, hour * TIMEAVATAR_SIZE_I64);
let cursor = image_to_cursor(resimg, scale)?;
- Ok(HttpResponse::build(StatusCode::OK)
- .content_type("image/png")
- .body(cursor.into_inner()))
+ Ok(response_image!(cursor))
}
#[get("/pgen/0/{data}")]
Ok(apply_to_canvas( |c, d| to_canvasresult(rgb_encode_to_canvas(c, d)), &mut canvas_option.0, None, data)?.img.clone())
} as Result<RgbImage, CanvasError>)?;
let cursor = image_to_cursor(img, scale)?;
- Ok(HttpResponse::build(StatusCode::OK)
- .content_type("image/png")
- .body(cursor.into_inner()))
+ Ok(response_image!(cursor))
}
#[get("/pgen/1/{dim_x}/{dim_y}/{scale}/{data}")]
Ok(apply_to_canvas( |c, d| to_canvasresult(rgb_encode_to_canvas(c, d)), &mut canvas_option.0, Some((dim_x, dim_y)), data)?.img.clone())
} as Result<RgbImage, CanvasError>)?;
let cursor = image_to_cursor(img, scale)?;
- Ok(HttpResponse::build(StatusCode::OK)
- .content_type("image/png")
- .body(cursor.into_inner()))
+ Ok(response_image!(cursor))
}
#[get("/pgen/2/{dim_x}/{dim_y}/{scale}")]
Ok(apply_to_canvas( |c, d| to_canvasresult(rgb_encode_to_canvas(c, d)), &mut canvas_option.0, Some((dim_x, dim_y)), data)?.img.clone())
} as Result<RgbImage, CanvasError>)?;
let cursor = image_to_cursor(img, scale)?;
- Ok(HttpResponse::build(StatusCode::OK)
- .content_type("image/png")
- .body(cursor.into_inner()))
+ Ok(response_image!(cursor))
}
#[get("/pgen/3/{scale}")]
Ok(canvas_option.0.insert(canvas).img.clone())
} as Result<RgbImage, CanvasError>)?;
let cursor = image_to_cursor(resimg, scale)?;
- Ok(HttpResponse::build(StatusCode::OK)
- .content_type("image/png")
- .body(cursor.into_inner()))
+ Ok(response_image!(cursor))
}
#[get("/pdrop/{canvas_id}")]