}
impl Canvas {
- fn new(width: u32, height: u32) -> Canvas {
- Canvas { pen: 0, img: ImageBuffer::new(width, height) }
+ fn new(width: u32, height: u32) -> Result<Canvas, CanvasError> {
+ // Image must not be larger than 1 megapixel
+ if width * height > 1048576 {
+ Err(ImageError::dimension_error().into())
+ }
+ else {
+ Ok(Canvas { pen: 0, img: ImageBuffer::new(width, height) })
+ }
}
/*fn from_image(img: RgbImage) -> Canvas {
},
None => match dimensions {
Some((dim_x, dim_y)) =>
- Ok(Canvas::new(dim_x, dim_y)),
+ Ok(Canvas::new(dim_x, dim_y)?),
None =>
Err(CanvasError::NotExists)
}
let scale = 16;
let img: RgbImage = ({
let canvas_option = &mut *canvas0.lock().unwrap();
- Ok(apply_to_canvas( |c, d| rgb_encode_to_canvas(c, d), &mut canvas_option.0, None, data)?.img.clone())
+ Ok(apply_to_canvas( |c, d| rgb_encode_to_canvas(c, d), &mut canvas_option.0, Some((32, 32)), data)?.img.clone())
} as Result<RgbImage, CanvasError>)?;
let cursor = image_to_cursor(img, scale)?;
Ok(response_image!(cursor))
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)
+ 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())
.init();
let listenaddress = env::args().nth(1).unwrap_or_else(|| "127.0.0.1:8080".to_string());
- let canvas0 = Arc::new(Mutex::new(Canvas0(Some(Canvas::new(32, 32)))));
+ let canvas0 = Arc::new(Mutex::new(Canvas0(None)));
let canvas1 = Arc::new(Mutex::new(Canvas1(None)));
let canvas2 = Arc::new(Mutex::new(Canvas2(None)));