Skip to content

Commit

Permalink
Restore as_flat_samples methods for DynamicImage
Browse files Browse the repository at this point in the history
Because the return type depends on the buffer's bits per channel, make
the return optional and provide separate methods for 8 and 16 bit
images.
  • Loading branch information
aschampion committed Dec 4, 2019
1 parent 7697e2b commit 8433f75
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/dynimage.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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<FlatSamples<&[u8]>> {
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<FlatSamples<&[u16]>> {
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<u8> {
image_to_bytes(self)
Expand Down

0 comments on commit 8433f75

Please sign in to comment.