|
2 | 2 | //!
|
3 | 3 | //! Re-exported at its super `image` module.
|
4 | 4 | use crate::buf::{atomic_buf, AtomicBuffer, AtomicSliceRef};
|
5 |
| -use crate::image::{raw::RawImage, Coord, IntoPlanesError}; |
6 |
| -use crate::layout::{ |
7 |
| - Bytes, Decay, Layout, Mend, PlaneOf, Raster, RasterMut, Relocate, SliceLayout, Take, TryMend, |
8 |
| -}; |
| 5 | +use crate::image::{raw::RawImage, IntoPlanesError}; |
| 6 | +use crate::layout::{Bytes, Decay, Layout, Mend, PlaneOf, Relocate, SliceLayout, Take, TryMend}; |
9 | 7 | use crate::texel::{constants::U8, MAX_ALIGN};
|
10 | 8 | use crate::{Texel, TexelBuffer};
|
11 | 9 |
|
@@ -84,7 +82,8 @@ impl<L: Layout> AtomicImage<L> {
|
84 | 82 | /// assert_eq!(as_bytes.layout().height(), 400);
|
85 | 83 | /// ```
|
86 | 84 | ///
|
87 |
| - /// See also [`Image::mend`] and [`Image::try_mend`] for operations that reverse the effects. |
| 85 | + /// See also [`AtomicImage::mend`] and [`AtomicImage::try_mend`] for operations that reverse |
| 86 | + /// the effects. |
88 | 87 | ///
|
89 | 88 | /// Can also be used to forget specifics of the layout, turning the image into a more general
|
90 | 89 | /// container type. For example, to use a uniform type as an allocated buffer waiting on reuse.
|
@@ -160,21 +159,51 @@ impl<L> AtomicImage<L> {
|
160 | 159 | /// Get a reference to the aligned unstructured bytes of the image.
|
161 | 160 | ///
|
162 | 161 | /// Note that this may return more bytes than required for the specific layout for various
|
163 |
| - /// reasons. See also [`Self::as_capacity_bytes`]. |
| 162 | + /// reasons. See also [`Self::make_mut`]. |
164 | 163 | pub fn as_capacity_atomic_buf(&self) -> &atomic_buf {
|
165 | 164 | self.inner.as_capacity_atomic_buf()
|
166 | 165 | }
|
167 | 166 |
|
| 167 | + /// Get a mutable reference to all allocated bytes if this image does not alias any other. |
| 168 | + /// |
| 169 | + /// # Example |
| 170 | + /// |
| 171 | + /// ``` |
| 172 | + /// use image_texel::{image::AtomicImage, layout::Matrix}; |
| 173 | + /// |
| 174 | + /// let layout = Matrix::<[u8; 4]>::width_and_height(10, 10).unwrap(); |
| 175 | + /// let mut image = AtomicImage::new(layout); |
| 176 | + /// assert!(image.get_mut().is_some()); |
| 177 | + /// |
| 178 | + /// let mut clone_of = image.clone(); |
| 179 | + /// assert!(image.get_mut().is_none()); |
| 180 | + /// ``` |
| 181 | + pub fn get_mut(&mut self) -> Option<&mut atomic_buf> { |
| 182 | + self.inner.get_mut().get_mut() |
| 183 | + } |
| 184 | + |
168 | 185 | /// Ensure this image does not alias any other.
|
169 | 186 | ///
|
| 187 | + /// Then returns a mutable reference to all the bytes allocated in the buffer. |
| 188 | + /// |
| 189 | + /// # Example |
| 190 | + /// |
170 | 191 | /// ```
|
171 |
| - /// use image_texel::{image::AtomicImage, layout::Matrix, layout::Bytes}; |
| 192 | + /// use image_texel::{image::AtomicImage, layout::Matrix, texels::U8}; |
| 193 | + /// let texel = U8.array::<4>(); |
172 | 194 | ///
|
173 | 195 | /// let layout = Matrix::<[u8; 4]>::width_and_height(10, 10).unwrap();
|
174 | 196 | /// let image = AtomicImage::new(layout);
|
| 197 | + /// |
175 | 198 | /// let mut clone_of = image.clone();
|
| 199 | + /// let atomic_mut_buf = clone_of.make_mut(); |
| 200 | + /// |
| 201 | + /// // Now these are independent buffers. |
| 202 | + /// atomic_mut_buf.as_buf_mut().as_mut_texels(texel)[0] = [0xff; 4]; |
| 203 | + /// assert_ne!(texel.load_atomic(image.as_slice().index_one(0)), [0xff; 4]); |
176 | 204 | ///
|
177 |
| - /// let buf = clone_of.make_mut(); |
| 205 | + /// // With mutable reference we initialized the new buffer. |
| 206 | + /// assert_eq!(texel.load_atomic(clone_of.as_slice().index_one(0)), [0xff; 4]); |
178 | 207 | /// ```
|
179 | 208 | pub fn make_mut(&mut self) -> &mut atomic_buf {
|
180 | 209 | self.inner.get_mut().make_mut()
|
@@ -308,7 +337,7 @@ impl<'data, L> AtomicImageRef<'data, L> {
|
308 | 337 |
|
309 | 338 | /// Decay into a image with less specific layout.
|
310 | 339 | ///
|
311 |
| - /// See [`Image::decay`]. |
| 340 | + /// See [`AtomicImage::checked_decay`]. |
312 | 341 | pub fn checked_decay<M>(self) -> Option<AtomicImageRef<'data, M>>
|
313 | 342 | where
|
314 | 343 | M: Decay<L>,
|
|
0 commit comments