#[repr(align(4))]pub struct Pixmap { /* private fields */ }
Expand description
A struct representing a pixelmap for pixelflut.
This struct holds the data for each pixel, and can be concidered a bitmap. For each pixel, a u32 (DWORD) value is used containing 4 bytes that define the value for each of the 4 color channels.
This data structure is focussed on performance and multithreaded use with multiple readers and writers. This structure does not use any kind of locks. Instead, it is assumed that the operations done on the internal map are atomic (on a pixel basis). This is perfectly fine for what this pixelmap is used for.
Because this structure is aligned to 4 bytes in memory, each raw color value (u32) is also aligned to 4 bytes. This makes direct reads and writes on these values on most CPUs (but not all!). The fact that this may not be atomic in some cases is accepted for this structure. The speed of not using locks is preferred over the minor side effect of seldom rendering artifact on some systems.
More info: https://stackoverflow.com/a/5002256/1000145
Important: this data structure is considered unsafe, but is perfectly usable for pixelflut applications.
Implementations§
Source§impl Pixmap
impl Pixmap
Sourcepub fn dimensions(&self) -> (usize, usize)
pub fn dimensions(&self) -> (usize, usize)
Get the dimensions of the pixel map.
Sourcepub fn pixel(&self, x: usize, y: usize) -> Result<Color, PixmapErr<'_>>
pub fn pixel(&self, x: usize, y: usize) -> Result<Color, PixmapErr<'_>>
Get the pixel at the given coordinate, as color.
Sourcepub fn pixel_raw(&self, x: usize, y: usize) -> Result<u32, PixmapErr<'_>>
pub fn pixel_raw(&self, x: usize, y: usize) -> Result<u32, PixmapErr<'_>>
Get the pixel at the given coordinate, as raw color value.
Sourcepub fn set_pixel(
&self,
x: usize,
y: usize,
color: Color,
) -> Result<(), PixmapErr<'_>>
pub fn set_pixel( &self, x: usize, y: usize, color: Color, ) -> Result<(), PixmapErr<'_>>
Set the pixel at the given coordinate, to the given color.
Sourcepub fn set_pixel_raw(
&self,
x: usize,
y: usize,
raw: u32,
) -> Result<(), PixmapErr<'_>>
pub fn set_pixel_raw( &self, x: usize, y: usize, raw: u32, ) -> Result<(), PixmapErr<'_>>
Set the pixel at the given coordinate, to the given raw color value.