Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement From<DynamicImage> for all image types #2076

Merged
merged 1 commit into from
Dec 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::image::{GenericImage, GenericImageView, ImageEncoder, ImageFormat, Im
use crate::math::Rect;
use crate::traits::{EncodableLayout, Pixel, PixelWithColorType};
use crate::utils::expand_packed;
use crate::DynamicImage;

/// Iterate over pixel refs.
pub struct Pixels<'a, P: Pixel + 'a>
Expand Down Expand Up @@ -1427,6 +1428,60 @@ pub type Rgb32FImage = ImageBuffer<Rgb<f32>, Vec<f32>>;
/// where the backing container is a flattened vector of floats.
pub type Rgba32FImage = ImageBuffer<Rgba<f32>, Vec<f32>>;

impl From<DynamicImage> for RgbImage {
fn from(value: DynamicImage) -> Self {
value.into_rgb8()
}
}

impl From<DynamicImage> for RgbaImage {
fn from(value: DynamicImage) -> Self {
value.into_rgba8()
}
}

impl From<DynamicImage> for GrayImage {
fn from(value: DynamicImage) -> Self {
value.into_luma8()
}
}

impl From<DynamicImage> for GrayAlphaImage {
fn from(value: DynamicImage) -> Self {
value.into_luma_alpha8()
}
}

impl From<DynamicImage> for Rgb16Image {
fn from(value: DynamicImage) -> Self {
value.into_rgb16()
}
}

impl From<DynamicImage> for Rgba16Image {
fn from(value: DynamicImage) -> Self {
value.into_rgba16()
}
}

impl From<DynamicImage> for Gray16Image {
fn from(value: DynamicImage) -> Self {
value.into_luma16()
}
}

impl From<DynamicImage> for GrayAlpha16Image {
fn from(value: DynamicImage) -> Self {
value.into_luma_alpha16()
}
}

impl From<DynamicImage> for Rgba32FImage {
fn from(value: DynamicImage) -> Self {
value.into_rgba32f()
}
}

#[cfg(test)]
mod test {
use super::{GrayImage, ImageBuffer, ImageOutputFormat, RgbImage};
Expand Down
Loading