Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 27 additions & 0 deletions src/formats/gray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,30 @@ impl<T> core::ops::Deref for Gray_v08<T> {
&self.0
}
}

impl<T: Copy> Gray_v08<T> {
/// Reads the `.0` field
///
/// This is a compatibility shim. Migrate to `Gray_v09` and use `.v` directly.
#[deprecated(since = "0.8.91", note = "Use Gray_v09 with .v field instead")]
pub fn value(self) -> T {
self.0
}

/// Exposes the `.0` field for writing
///
/// This is a compatibility shim. Migrate to `Gray_v09` and use `.v` directly.
#[deprecated(since = "0.8.91", note = "Use Gray_v09 with .v field instead")]
pub fn value_mut(&mut self) -> &mut T {
&mut self.0
}

/// Add alpha component to this pixel
///
/// This is a compatibility shim. Migrate to `Gray_v09` and use `GrayA` instead.
#[deprecated(since = "0.8.91", note = "Use Gray_v09::with_alpha() or GrayA instead")]
#[allow(deprecated)]
pub fn with_alpha(self, add_alpha_value: T) -> crate::formats::gray_alpha::GrayAlpha_v08<T> {
crate::formats::gray_alpha::GrayAlpha_v08(self.0, add_alpha_value)
}
}
22 changes: 20 additions & 2 deletions src/formats/gray_alpha.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::formats::gray_a::GrayA;
use core::ops::Deref;
use core::ops::{Deref, DerefMut};

#[repr(C)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down Expand Up @@ -34,13 +34,31 @@ impl<T, A> Deref for GrayAlpha_v08<T, A> {
}
}

impl<T, A> DerefMut for GrayAlpha_v08<T, A> {
/// Compatibility shim - allows mutable access to `.v` and `.a` on the old `GrayAlpha` type.
///
/// **Deprecated:** Migrate to `GrayA` instead of `GrayAlpha_v08`.
fn deref_mut(&mut self) -> &mut GrayA<T, A> {
Comment thread
lilith marked this conversation as resolved.
unsafe { &mut *(self as *mut Self).cast::<GrayA<T, A>>() }
}
}

impl<T: Copy, A> GrayAlpha_v08<T, A> {
/// Value - the brightness component. May be luma or luminance.
///
/// Backwards-compatible getter for `self.v`
/// This is a compatibility shim. Migrate to `GrayA` and use `.v` directly.
#[deprecated(since = "0.8.91", note = "Use GrayA with .v field instead")]
pub fn value(&self) -> T {
self.0
}

/// Exposes the `.0` field for writing
///
/// This is a compatibility shim. Migrate to `GrayA` and use `.v` directly.
#[deprecated(since = "0.8.91", note = "Use GrayA with .v field instead")]
pub fn value_mut(&mut self) -> &mut T {
&mut self.0
}
}

#[test]
Expand Down