diff --git a/src/dynimage.rs b/src/dynimage.rs index 5ea4f1f364..375e65f006 100644 --- a/src/dynimage.rs +++ b/src/dynimage.rs @@ -22,6 +22,7 @@ use buffer::{ RgbaImage, Rgba16Image, }; use color::{self, IntoColor}; +use flat::FlatSamples; use image; use image::{ GenericImage, GenericImageView, ImageDecoder, ImageError, ImageFormat, ImageOutputFormat, ImageResult, @@ -392,6 +393,30 @@ impl DynamicImage { } } + /// Return a view on the raw sample buffer for 8 bit per channel images. + pub fn as_flat_samples_u8(&self) -> Option> { + match *self { + DynamicImage::ImageLuma8(ref p) => Some(p.as_flat_samples()), + DynamicImage::ImageLumaA8(ref p) => Some(p.as_flat_samples()), + DynamicImage::ImageRgb8(ref p) => Some(p.as_flat_samples()), + DynamicImage::ImageRgba8(ref p) => Some(p.as_flat_samples()), + DynamicImage::ImageBgr8(ref p) => Some(p.as_flat_samples()), + DynamicImage::ImageBgra8(ref p) => Some(p.as_flat_samples()), + _ => None, + } + } + + /// Return a view on the raw sample buffer for 16 bit per channel images. + pub fn as_flat_samples_u16(&self) -> Option> { + match *self { + DynamicImage::ImageLuma16(ref p) => Some(p.as_flat_samples()), + DynamicImage::ImageLumaA16(ref p) => Some(p.as_flat_samples()), + DynamicImage::ImageRgb16(ref p) => Some(p.as_flat_samples()), + DynamicImage::ImageRgba16(ref p) => Some(p.as_flat_samples()), + _ => None, + } + } + /// Return this image's pixels as a byte vector. pub fn to_bytes(&self) -> Vec { image_to_bytes(self)