From 7fb81697756bcb19781b36737c389224fc1e56a0 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Fri, 22 Aug 2025 12:23:40 -0400 Subject: [PATCH 1/3] Add {Mask, Pixmap}::into_data --- src/mask.rs | 5 +++++ src/pixmap.rs | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/mask.rs b/src/mask.rs index 94610c4..b750f47 100644 --- a/src/mask.rs +++ b/src/mask.rs @@ -132,6 +132,11 @@ impl Mask { self.data.as_mut_slice() } + /// Consumes the mask and returns its owned internal data. + pub fn into_data(self) -> Vec { + self.data + } + pub(crate) fn as_submask(&self) -> SubMaskRef<'_> { SubMaskRef { size: self.size, diff --git a/src/pixmap.rs b/src/pixmap.rs index b49f5a0..a480687 100644 --- a/src/pixmap.rs +++ b/src/pixmap.rs @@ -235,6 +235,13 @@ impl Pixmap { self.data.as_mut_slice() } + /// Consumes the pixmap and returns its owned internal data. + /// + /// Byteorder: RGBA + pub fn into_data(self) -> Vec { + self.data + } + /// Returns a pixel color. /// /// Returns `None` when position is out of bounds. From 60cf54a7b61f575c78f31e68971c86351453c08e Mon Sep 17 00:00:00 2001 From: valadaptive Date: Fri, 22 Aug 2025 12:47:28 -0400 Subject: [PATCH 2/3] Use the `take` method for consistency --- src/mask.rs | 2 +- src/pixmap.rs | 43 ++++++++++++++++++------------------------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/mask.rs b/src/mask.rs index b750f47..2cdc05c 100644 --- a/src/mask.rs +++ b/src/mask.rs @@ -133,7 +133,7 @@ impl Mask { } /// Consumes the mask and returns its owned internal data. - pub fn into_data(self) -> Vec { + pub fn take(self) -> Vec { self.data } diff --git a/src/pixmap.rs b/src/pixmap.rs index a480687..819553f 100644 --- a/src/pixmap.rs +++ b/src/pixmap.rs @@ -235,31 +235,6 @@ impl Pixmap { self.data.as_mut_slice() } - /// Consumes the pixmap and returns its owned internal data. - /// - /// Byteorder: RGBA - pub fn into_data(self) -> Vec { - self.data - } - - /// Returns a pixel color. - /// - /// Returns `None` when position is out of bounds. - pub fn pixel(&self, x: u32, y: u32) -> Option { - let idx = self.width().checked_mul(y)?.checked_add(x)?; - self.pixels().get(idx as usize).cloned() - } - - /// Returns a mutable slice of pixels. - pub fn pixels_mut(&mut self) -> &mut [PremultipliedColorU8] { - bytemuck::cast_slice_mut(self.data_mut()) - } - - /// Returns a slice of pixels. - pub fn pixels(&self) -> &[PremultipliedColorU8] { - bytemuck::cast_slice(self.data()) - } - /// Consumes the internal data. /// /// Byteorder: RGBA @@ -283,6 +258,24 @@ impl Pixmap { self.data } + /// Returns a pixel color. + /// + /// Returns `None` when position is out of bounds. + pub fn pixel(&self, x: u32, y: u32) -> Option { + let idx = self.width().checked_mul(y)?.checked_add(x)?; + self.pixels().get(idx as usize).cloned() + } + + /// Returns a mutable slice of pixels. + pub fn pixels_mut(&mut self) -> &mut [PremultipliedColorU8] { + bytemuck::cast_slice_mut(self.data_mut()) + } + + /// Returns a slice of pixels. + pub fn pixels(&self) -> &[PremultipliedColorU8] { + bytemuck::cast_slice(self.data()) + } + /// Returns a copy of the pixmap that intersects the `rect`. /// /// Returns `None` when `Pixmap`'s rect doesn't contain `rect`. From 39b3a14058aedeabbc5a1e99e0d4579ce7f4aeb5 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Fri, 22 Aug 2025 13:31:00 -0400 Subject: [PATCH 3/3] Revert pixmap changes entirely --- src/pixmap.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/pixmap.rs b/src/pixmap.rs index 819553f..b49f5a0 100644 --- a/src/pixmap.rs +++ b/src/pixmap.rs @@ -235,6 +235,24 @@ impl Pixmap { self.data.as_mut_slice() } + /// Returns a pixel color. + /// + /// Returns `None` when position is out of bounds. + pub fn pixel(&self, x: u32, y: u32) -> Option { + let idx = self.width().checked_mul(y)?.checked_add(x)?; + self.pixels().get(idx as usize).cloned() + } + + /// Returns a mutable slice of pixels. + pub fn pixels_mut(&mut self) -> &mut [PremultipliedColorU8] { + bytemuck::cast_slice_mut(self.data_mut()) + } + + /// Returns a slice of pixels. + pub fn pixels(&self) -> &[PremultipliedColorU8] { + bytemuck::cast_slice(self.data()) + } + /// Consumes the internal data. /// /// Byteorder: RGBA @@ -258,24 +276,6 @@ impl Pixmap { self.data } - /// Returns a pixel color. - /// - /// Returns `None` when position is out of bounds. - pub fn pixel(&self, x: u32, y: u32) -> Option { - let idx = self.width().checked_mul(y)?.checked_add(x)?; - self.pixels().get(idx as usize).cloned() - } - - /// Returns a mutable slice of pixels. - pub fn pixels_mut(&mut self) -> &mut [PremultipliedColorU8] { - bytemuck::cast_slice_mut(self.data_mut()) - } - - /// Returns a slice of pixels. - pub fn pixels(&self) -> &[PremultipliedColorU8] { - bytemuck::cast_slice(self.data()) - } - /// Returns a copy of the pixmap that intersects the `rect`. /// /// Returns `None` when `Pixmap`'s rect doesn't contain `rect`.