let rgbimg: RgbImage = rgb_encode(ImageBuffer::new(TIMEAVATAR_SIZE_U32, TIMEAVATAR_SIZE_U32), &mut data.bytes())?;
let resimg: RgbImage = ({
let canvas_option = &mut *canvas2.lock().unwrap();
- let mut canvas = match canvas_option.0.take() {
- Some(canvas) => canvas,
- None => Canvas::new(60 * TIMEAVATAR_SIZE_U32, 24 * TIMEAVATAR_SIZE_U32)?
- };
- overlay(&mut canvas.img, &rgbimg, minute * TIMEAVATAR_SIZE_I64, hour * TIMEAVATAR_SIZE_I64);
- Ok(canvas_option.0.insert(canvas).img.clone())
+ Ok(apply_to_canvas(|mut canvas, _| {
+ overlay(&mut canvas.img, &rgbimg, minute * TIMEAVATAR_SIZE_I64, hour * TIMEAVATAR_SIZE_I64);
+ Ok(canvas)
+ }, &mut canvas_option.0, Some((60 * TIMEAVATAR_SIZE_U32, 24 * TIMEAVATAR_SIZE_U32)), "")?.img.clone())
} as Result<RgbImage, CanvasError>)?;
let cursor = image_to_cursor(resimg, scale)?;
Ok(response_image!(cursor))