The pixel_map Rust Crate
A PixelMap stores pixel data for an image in a quadtree 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
;
Drawing on the PixelMap
Navigating the PixelMap
Features
- Set individual pixel values, or draw primitive shapes:
- Lines
- Rectangles
- Circles
- Perform boolean operations against two pixel maps (i.e. union, intersection, difference, xor).
- Detect changes to tree nodes via a "dirty" flag.
- Calculate contiguous contouring lines around shapes.
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 quadtree structure are provided. So, this is achievable in encompassing or accompanying code, according to the needs of your use case.
Testing
Run cargo test to unit test.
Mind blown, hey?
Benchmarking
Run cargo bench to run all Criterion benchmarks.
Or, cargo bench --bench <name> to run a particular benchmark.
Benchmarks are integrated with pprof to produce flamegraphs, upon activation.
Run cargo benchmark --bench <name> -- --profile-time=5 to sample the benchmark run,
and generate a flamegraph, which can be found in
./target/criterion/<name>/<group>/profile/flamegraph.svg.
License
pixel_map is free and open source. All code in this repository is dual-licensed under
either of the following, at your option:
- MIT License (
LICENSE-MITor http://opensource.org/licenses/MIT) - Apache License, Version 2.0 (
LICENSE-APACHEor http://www.apache.org/licenses/LICENSE-2.0)