use crate::legacy::internal::pixel::{ComponentMap, ColorComponentMap}; #[allow(deprecated)] use crate::legacy::internal::pixel::ComponentSlice; use core::slice; pub use crate::formats::gray::Gray_v08 as Gray; pub use crate::formats::gray_alpha::GrayAlpha_v08 as GrayAlpha; /// Renamed to `Bgra` #[doc(hidden)] pub use crate::formats::bgra::Bgra as BGRA; /// Renamed to `Bgr` #[doc(hidden)] pub use crate::formats::bgr::Bgr as BGR; /// Renamed to `Abgr` #[doc(hidden)] pub use crate::formats::abgr::Abgr as ABGR; /// Renamed to `Argb` #[doc(hidden)] pub use crate::formats::argb::Argb as ARGB; /// Renamed to `Grb` #[doc(hidden)] pub use crate::formats::grb::Grb as GRB; /// 8-bit BGR pub type BGR8 = crate::formats::bgr::Bgr; /// 16-bit BGR in machine's native endian pub type BGR16 = crate::formats::bgr::Bgr; /// 8-bit BGRA pub type BGRA8 = crate::formats::bgra::Bgra; /// 8-bit ABGR, alpha is first. 0 = transparent, 255 = opaque. pub type ABGR8 = crate::formats::abgr::Abgr; /// 8-bit ARGB, alpha is first. 0 = transparent, 255 = opaque. pub type ARGB8 = crate::Argb; /// 16-bit BGR in machine's native endian pub type BGRA16 = crate::formats::bgra::Bgra; /// 16-bit ABGR in machine's native endian. 0 = transparent, 65535 = opaque. pub type ABGR16 = crate::formats::abgr::Abgr; /// 16-bit ARGB in machine's native endian. 0 = transparent, 65535 = opaque. pub type ARGB16 = crate::Argb; /// 8-bit GRB pub type GRB8 = crate::formats::grb::Grb; /// 8-bit gray #[deprecated(note = "Refer to ::rgb::alt::Gray directly (this type alias will change in the next major version)")] pub type GRAY8 = Gray; /// 16-bit gray in machine's native endian #[deprecated(note = "Refer to ::rgb::alt::Gray directly (this type alias will change in the next major version)")] pub type GRAY16 = Gray; /// 8-bit gray with alpha in machine's native endian #[deprecated(note = "Refer to ::rgb::alt::GrayAlpha directly (this type alias will change in the next major version)")] pub type GRAYA8 = GrayAlpha; /// 16-bit gray with alpha in machine's native endian #[deprecated(note = "Refer to ::rgb::alt::GrayAlpha directly (this type alias will change in the next major version)")] pub type GRAYA16 = GrayAlpha; #[cfg(not(feature = "unstable-experimental"))] impl core::ops::Deref for Gray { type Target = T; #[inline(always)] #[allow(deprecated)] fn deref(&self) -> &T { &self.0 } } impl From for Gray { #[inline(always)] fn from(component: T) -> Self { Self(component) } } impl GrayAlpha { /// Copy `Gray` component out of the `GrayAlpha` struct #[inline(always)] #[allow(deprecated)] pub fn gray(&self) -> Gray { Gray(self.0.clone()) } } impl GrayAlpha { /// Provide a mutable view of only `Gray` component (leaving out alpha). #[inline(always)] pub fn gray_mut(&mut self) -> &mut Gray { unsafe { &mut *(self as *mut Self).cast() } } } impl GrayAlpha { /// Create a new `GrayAlpha` with the new alpha value, but same gray value #[doc(hidden)] #[deprecated(note = "use .with_alpha(a) instead; this will become a getter in the future")] pub fn alpha(&self, a: A) -> Self { self.with_alpha(a) } /// Create a new `GrayAlpha` with the new alpha value, but same gray value #[inline(always)] #[allow(deprecated)] pub fn with_alpha(&self, a: A) -> Self { Self(self.0, a) } /// Create a new `GrayAlpha` with a new alpha value created by the callback. #[inline(always)] #[allow(deprecated)] pub fn map_alpha(&self, f: F) -> GrayAlpha where F: FnOnce(A) -> B { GrayAlpha(self.0, f(self.1.clone())) } /// Create new `GrayAlpha` with the same alpha value, but different `Gray` value #[inline(always)] #[allow(deprecated)] pub fn map_gray(&self, f: F) -> GrayAlpha where F: FnOnce(T) -> U, U: Clone, B: From + Clone { GrayAlpha(f(self.0), self.1.clone().into()) } } impl ComponentMap, T, B> for Gray { #[inline(always)] #[allow(deprecated)] fn map(&self, mut f: F) -> Gray where F: FnMut(T) -> B { Gray(f(self.0)) } } impl ColorComponentMap, T, B> for Gray { #[inline(always)] #[allow(deprecated)] fn map_colors(&self, mut f: F) -> Gray where F: FnMut(T) -> B { Gray(f(self.0)) } } impl ComponentMap, T, B> for GrayAlpha { #[inline(always)] #[allow(deprecated)] fn map(&self, mut f: F) -> GrayAlpha where F: FnMut(T) -> B { GrayAlpha(f(self.0), f(self.1)) } } impl ColorComponentMap, T, B> for GrayAlpha { #[inline(always)] #[allow(deprecated)] fn map_colors(&self, mut f: F) -> GrayAlpha where F: FnMut(T) -> B { GrayAlpha(f(self.0), self.1) } } #[allow(deprecated)] impl ComponentSlice for GrayAlpha { #[inline(always)] fn as_slice(&self) -> &[T] { unsafe { slice::from_raw_parts((self as *const Self).cast::(), 2) } } #[inline(always)] fn as_mut_slice(&mut self) -> &mut [T] { unsafe { slice::from_raw_parts_mut((self as *mut Self).cast::(), 2) } } } #[allow(deprecated)] impl ComponentSlice for [GrayAlpha] { #[inline] fn as_slice(&self) -> &[T] { unsafe { slice::from_raw_parts(self.as_ptr().cast(), self.len() * 2) } } #[inline] fn as_mut_slice(&mut self) -> &mut [T] { unsafe { slice::from_raw_parts_mut(self.as_mut_ptr().cast::(), self.len() * 2) } } } #[allow(deprecated)] impl ComponentSlice for Gray { #[inline(always)] #[allow(deprecated)] fn as_slice(&self) -> &[T] { slice::from_ref(&self.0) } #[inline(always)] #[allow(deprecated)] fn as_mut_slice(&mut self) -> &mut [T] { slice::from_mut(&mut self.0) } } #[allow(deprecated)] impl ComponentSlice for [Gray] { #[inline] fn as_slice(&self) -> &[T] { unsafe { slice::from_raw_parts(self.as_ptr().cast(), self.len()) } } #[inline] fn as_mut_slice(&mut self) -> &mut [T] { unsafe { slice::from_raw_parts_mut(self.as_mut_ptr().cast::(), self.len()) } } } /// Assumes 255 is opaque impl From> for GrayAlpha { #[inline(always)] #[allow(deprecated)] fn from(other: Gray) -> Self { Self(other.0, 0xFF) } } /// Assumes 65535 is opaque impl From> for GrayAlpha { #[inline(always)] #[allow(deprecated)] fn from(other: Gray) -> Self { Self(other.0, 0xFFFF) } }