diff --git a/src/buffer.rs b/src/buffer.rs index 046bdebe76..bfb6e66c14 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -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> @@ -1427,6 +1428,60 @@ pub type Rgb32FImage = ImageBuffer, Vec>; /// where the backing container is a flattened vector of floats. pub type Rgba32FImage = ImageBuffer, Vec>; +impl From for RgbImage { + fn from(value: DynamicImage) -> Self { + value.into_rgb8() + } +} + +impl From for RgbaImage { + fn from(value: DynamicImage) -> Self { + value.into_rgba8() + } +} + +impl From for GrayImage { + fn from(value: DynamicImage) -> Self { + value.into_luma8() + } +} + +impl From for GrayAlphaImage { + fn from(value: DynamicImage) -> Self { + value.into_luma_alpha8() + } +} + +impl From for Rgb16Image { + fn from(value: DynamicImage) -> Self { + value.into_rgb16() + } +} + +impl From for Rgba16Image { + fn from(value: DynamicImage) -> Self { + value.into_rgba16() + } +} + +impl From for Gray16Image { + fn from(value: DynamicImage) -> Self { + value.into_luma16() + } +} + +impl From for GrayAlpha16Image { + fn from(value: DynamicImage) -> Self { + value.into_luma_alpha16() + } +} + +impl From for Rgba32FImage { + fn from(value: DynamicImage) -> Self { + value.into_rgba32f() + } +} + #[cfg(test)] mod test { use super::{GrayImage, ImageBuffer, ImageOutputFormat, RgbImage};