Trait for images.
| 189 | |
| 190 | /// Trait for images. |
| 191 | pub trait Image { |
| 192 | /// Creates a new image with the given width and height. |
| 193 | fn new(width: usize, height: usize) -> Self; |
| 194 | |
| 195 | /// Returns the internal representation of the image. |
| 196 | fn buffer(&self) -> *const IplImage; |
| 197 | |
| 198 | /// Returns the RGB value of the pixel at location `(x, y)`. |
| 199 | /// |
| 200 | /// If the image is a grayscale image all color components have the same value. |
| 201 | fn pixel_as_rgb(&self, x: usize, y: usize) -> Option<Rgb>; |
| 202 | |
| 203 | /// Sets the pixel at the location `(x, y)` to the value specified by `p`. |
| 204 | /// |
| 205 | /// If the image is a frayscale image the following grayscale value is |
| 206 | /// set: val = 0.299 * red + 0.587 * green + 0.114 * blue |
| 207 | fn set_pixel_from_rgb(&self, x: usize, y: usize, p: &Rgb); |
| 208 | |
| 209 | // implemenations ---------------------------------------------------- |
| 210 | |
| 211 | /// Returns the width of the image. |
| 212 | fn width(&self) -> usize { unsafe { (*self.buffer()).width as usize } } |
| 213 | |
| 214 | /// Returns the height of the image. |
| 215 | fn height(&self) -> usize { unsafe { (*self.buffer()).height as usize } } |
| 216 | |
| 217 | /// Returns the color depth of the image. |
| 218 | fn depth(&self) -> usize { unsafe { (*self.buffer()).depth as usize } } |
| 219 | |
| 220 | /// Internal method which returns the length of one row in bytes. |
| 221 | /// |
| 222 | /// Due to the fact that rows might by aligned the number of bytes might |
| 223 | /// be greater than the width of the image. |
| 224 | fn widthstep(&self) -> usize { unsafe { (*self.buffer()).widthstep as usize } } |
| 225 | |
| 226 | /// Returns the number of color components used for this image. |
| 227 | fn channels(&self) -> usize { unsafe { (*self.buffer()).nchannels as usize } } |
| 228 | |
| 229 | /// Writes the image into a file. |
| 230 | /// |
| 231 | /// The file format that is written depends on the extension of the filename. |
| 232 | /// Supported formats are JPEG, PNG, PPM, PGM, PBM. Returns `false` if file |
| 233 | /// could not be written and `true` on success. |
| 234 | fn to_file(&self, fname: &str) -> bool { |
| 235 | |
| 236 | let mut s = fname.to_string(); |
| 237 | s.push('\0'); |
| 238 | unsafe { |
| 239 | let r = cvSaveImage( |
| 240 | s.as_ptr() as *const c_char, |
| 241 | self.buffer() as *const CvArr, |
| 242 | 0 as *const c_int |
| 243 | ); |
| 244 | r != 0 |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /// Copies an area from the given image at location `(x,y )` with width `width` |
no outgoing calls
no test coverage detected