1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
use image; use image::{ GenericImage, Rgba, Rgb, }; use texture::{ Pixel, Texture, }; impl<P: Pixel + image::Pixel, I: GenericImage<Pixel=P>> Texture for I { type Pixel = I::Pixel; fn width(&self) -> u32 { self.dimensions().0 } fn height(&self) -> u32 { self.dimensions().1 } fn get(&self, x: u32, y: u32) -> Option<I::Pixel> { if self.in_bounds(x, y) { Some(self.get_pixel(x, y)) } else { None } } fn set(&mut self, x: u32, y: u32, val: I::Pixel) { self.put_pixel(x, y, val); } } impl Pixel for Rgba<u8> { fn is_transparent(&self) -> bool { self[3] == 0 } fn transparency() -> Option<Rgba<u8>> { Some(Rgba([0; 4])) } fn outline() -> Rgba<u8> { Rgba([255, 0, 0, 255]) } } impl Pixel for Rgb<u8> { fn is_transparent(&self) -> bool { false } fn transparency() -> Option<Rgb<u8>> { None } fn outline() -> Rgb<u8> { Rgb([255, 0, 0]) } }