The pixel_map Rust Crate
A PixelMap stores pixel data for an image in a quad tree structure.
Overview
A PixelMap is an MX quadtree implementation, occupies a region of two-dimensional space at the
root node, and subdivides down to the pixel level. A type-generic pixel data value can be stored
for each pixel in the map, but the tree structure optimizes storage for regions of common values.
A pixel value must be Copy + PartialEq.
Project status: alpha. Releases may contain breaking changes.
Usage
Installation
Add the crate to your Cargo.toml:
Creating a Pixel Map
use PixelMap;
// Example pixel data
;
let mut pixel_map = new;
Drawing on the PixelMap
// Set a pixel
pixel_map.set_pixel;
// Draw a line
pixel_map.draw_line;
// Draw a rectangle
pixel_map.draw_rect;
// Draw a circle
pixel_map.draw_circle;
Navigating the PixelMap
// Visit all leaf nodes
pixel_map.visit;
// Visit all leaf nodes that have been modified
pixel_map.visit_dirty;
pixel_map.clear_dirty;
Features
- Set individual pixel values, or draw primitive shapes:
- Lines
- Rectangles
- Circles
- Split a pixel map into owned quadrants for parallel processing, and merge quadrants back into a unified pixel map.
- Perform boolean operations against two pixel maps (i.e. union, intersection, difference, xor).
- Tree nodes maintain a dirty state for efficiently traversing recently modified regions of the tree.
Limitations
- Loading and saving pixel data into various image formats is outside the scope of this crate. But, the basic operations necessary to both populate pixel data, and traverse the quad tree structure are provided. So, this is achievable in encompassing or accompanying code, according to the needs of your use case.
- In order to simplify and optimise pixel map operations, the pixel map is always square, and the number of pixels in each dimension must be a power of two.
License
Licensed under MIT license (LICENSE or https://opensource.org/licenses/MIT)