Skip to content

Commit 0c66d56

Browse files
author
Aurelia Molzer
authored
Merge pull request #62 from image-rs/release-0.4.0
Add changelog and some polish on documentation
2 parents 6d5cc5c + 9feda75 commit 0c66d56

File tree

7 files changed

+86
-10
lines changed

7 files changed

+86
-10
lines changed

canvas/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repository = "https://github.com/image-rs/canvas"
1212
categories = ["multimedia::images"]
1313

1414
[dependencies]
15-
image-texel = { path = "../texel", version = "0.3.0" }
15+
image-texel = { path = "../texel", version = "0.4.0" }
1616
bytemuck = "1.1"
1717

1818
[dev-dependencies]

texel/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "image-texel"
3-
version = "0.3.1"
3+
version = "0.4.0"
44
edition = "2021"
5-
rust-version = "1.77"
5+
rust-version = "1.84"
66

77
description = "A texel type and allocated buffers suitable for image data."
88
authors = ["Aurelia Molzer <[email protected]>"]

texel/Changes.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# v0.4.0
2+
3+
- Add `AtomicImage`, `CellImage` and several supporting types and interfaces.
4+
These replicate large parts of the `Image` and `ImageMut` types but allow for
5+
operations on a shared buffer, wrapping `Arc` and `Rc` respectively.
6+
- Added `PlaneOf` trait, a relationship between a layout, and index, and a
7+
subcomponent of the layout. All image reference types implement a form of
8+
`into_planes` that splits them apart by those components.
9+
- Added a `Relocate` trait for layouts that can be move to another location
10+
in a buffer.
11+
112
## v0.3.1
213

314
- Fix compilation on non-explicit targets, where the maximum alignment will

texel/src/buf.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ impl AtomicBuffer {
332332
}
333333
}
334334

335+
/// Query if two buffers share the same memory region.
336+
pub fn ptr_eq(&self, other: &Self) -> bool {
337+
Arc::ptr_eq(&self.inner, &other.inner)
338+
}
339+
335340
/// Retrieve the byte capacity of the allocated storage.
336341
pub fn capacity(&self) -> usize {
337342
core::mem::size_of_val(&*self.inner)
@@ -1014,6 +1019,14 @@ impl cmp::PartialEq<[u8]> for cell_buf {
10141019

10151020
impl cmp::Eq for cell_buf {}
10161021

1022+
impl cmp::PartialEq for CellBuffer {
1023+
fn eq(&self, other: &Self) -> bool {
1024+
**self == **other
1025+
}
1026+
}
1027+
1028+
impl cmp::Eq for CellBuffer {}
1029+
10171030
impl TexelMappingBuffer for &'_ cell_buf {
10181031
/// Internally mapping function when the mapping can be done forwards.
10191032
fn map_forward<P, Q>(
@@ -1197,6 +1210,14 @@ impl cmp::PartialEq<[u8]> for atomic_buf {
11971210

11981211
impl cmp::Eq for atomic_buf {}
11991212

1213+
impl cmp::PartialEq for AtomicBuffer {
1214+
fn eq(&self, other: &Self) -> bool {
1215+
**self == **other
1216+
}
1217+
}
1218+
1219+
impl cmp::Eq for AtomicBuffer {}
1220+
12001221
impl TexelMappingBuffer for &'_ atomic_buf {
12011222
/// Internally mapping function when the mapping can be done forwards.
12021223
fn map_forward<P, Q>(

texel/src/image/atomic.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,20 @@ use crate::{Texel, TexelBuffer};
99

1010
/// A container of allocated bytes, parameterized over the layout.
1111
///
12+
/// This is a synchronized, shared equivalent to [`Image`][`crate::image::Image`]. That is the
13+
/// buffer of bytes of this container is shared between clones of this value and potentially
14+
/// between threads. In particular the same buffer may be owned and viewed with different layouts
15+
/// and modified concurrently. The guarantee, however, is merely that concurrent modification is
16+
/// free of undefined data races. There is no locking, implied synchronization, or ordering
17+
/// guarantees between edits except when you can modify disjoint parts of the buffer.
18+
///
1219
/// ## Differences to owned Image
20+
///
21+
/// Comparing values of this type is possible, but requires calling the method [`Self::compare`] to
22+
/// create a comparator. This is because comparing is inherently racing against modifications made
23+
/// on other threads. While the implementation prevents any unsound *data races* there is no
24+
/// specific meaning to any of its outcomes unless the caller ensure synchronization in some other
25+
/// manner.
1326
#[derive(Clone)]
1427
pub struct AtomicImage<Layout = Bytes> {
1528
inner: RawImage<AtomicBuffer, Layout>,
@@ -18,7 +31,8 @@ pub struct AtomicImage<Layout = Bytes> {
1831
/// A partial view of an atomic image.
1932
///
2033
/// Note that this requires its underlying buffer to be highly aligned! For that reason it is not
21-
/// possible to take a reference at an arbitrary number of bytes.
34+
/// possible to take a reference at an arbitrary number of bytes. Values of this type are created
35+
/// by calling [`AtomicImage::as_ref`] or [`AtomicImage::checked_to_ref`].
2236
#[derive(Clone, PartialEq, Eq)]
2337
pub struct AtomicImageRef<'buf, Layout = &'buf Bytes> {
2438
inner: RawImage<&'buf atomic_buf, Layout>,
@@ -156,6 +170,26 @@ impl<L> AtomicImage<L> {
156170
self.inner.fits(layout)
157171
}
158172

173+
/// Check if two images refer to the same buffer.
174+
pub fn ptr_eq(&self, other: &Self) -> bool {
175+
AtomicBuffer::ptr_eq(self.inner.get(), other.inner.get())
176+
}
177+
178+
/// Create a comparator to another image.
179+
///
180+
/// Note that comparing is inherently racing against modifications made on other threads. While
181+
/// the implementation prevents any unsound *data races* there is no specific meaning to any of
182+
/// its outcomes unless the caller ensure synchronization in some other manner.
183+
///
184+
/// You can also compare the allocation with [`Self::ptr_eq`] or ignore the layout and compare
185+
/// buffer contents with [`Self::as_capacity_atomic_buf`].
186+
pub fn compare(&self) -> impl core::cmp::Eq + core::cmp::PartialEq + '_
187+
where
188+
L: core::cmp::Eq,
189+
{
190+
(self.inner.layout(), self.inner.get())
191+
}
192+
159193
/// Get a reference to the aligned unstructured bytes of the image.
160194
///
161195
/// Note that this may return more bytes than required for the specific layout for various

texel/src/image/cell.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ use core::cell::Cell;
1010

1111
/// A container of allocated bytes, parameterized over the layout.
1212
///
13-
/// ## Differences to owned Image
14-
///
15-
/// The implementations for [`PartialEq`] and [`Eq`] are not provided. In many containers and
16-
/// contexts these two traits are required to rule out absence of interior mutability.
17-
#[derive(Clone)]
13+
/// This is a unsynchronized, shared equivalent to [`Image`][`crate::image::Image`]. That is the
14+
/// buffer of bytes of this container is shared between clones of this value but can not be sent
15+
/// between threads. In particular the same buffer may be owned and viewed with different layouts.
16+
#[derive(Clone, PartialEq, Eq)]
1817
pub struct CellImage<Layout = Bytes> {
1918
inner: RawImage<CellBuffer, Layout>,
2019
}
2120

2221
/// A partial view of an atomic image.
2322
///
2423
/// Note that this requires its underlying buffer to be highly aligned! For that reason it is not
25-
/// possible to take a reference at an arbitrary number of bytes.
24+
/// possible to take a reference at an arbitrary number of bytes. Values of this type are created
25+
/// by calling [`CellImage::as_ref`] or [`CellImage::checked_to_ref`].
2626
#[derive(Clone, PartialEq, Eq)]
2727
pub struct CellImageRef<'buf, Layout = &'buf Bytes> {
2828
inner: RawImage<&'buf cell_buf, Layout>,
@@ -160,6 +160,11 @@ impl<L> CellImage<L> {
160160
self.inner.fits(layout)
161161
}
162162

163+
/// Check if two images refer to the same buffer.
164+
pub fn ptr_eq(&self, other: &Self) -> bool {
165+
CellBuffer::ptr_eq(self.inner.get(), other.inner.get())
166+
}
167+
163168
/// Get a reference to the aligned unstructured bytes of the image.
164169
///
165170
/// Note that this may return more bytes than required for the specific layout for various

texel/src/image/raw.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ impl<B, L> RawImage<B, L> {
320320
texel.cast_buf(self.as_buf())
321321
}
322322

323+
/// Get mutable reference to the buffer.
324+
pub(crate) fn get(&self) -> &B {
325+
&self.buffer
326+
}
327+
323328
/// Get a mutable reference to the buffer. It is inadvisible to modify the buffer in a way that
324329
/// it can no longer hold the layout.
325330
pub(crate) fn get_mut(&mut self) -> &mut B {

0 commit comments

Comments
 (0)