| Crates.io | pixel_map |
| lib.rs | pixel_map |
| version | 0.4.0 |
| created_at | 2023-06-24 03:51:06.129929+00 |
| updated_at | 2025-05-12 23:12:18.045353+00 |
| description | A map of pixels implemented by an MX quadtree. |
| homepage | https://github.com/DonkulosisLabs/pixel_map_rs |
| repository | https://github.com/DonkulosisLabs/pixel_map_rs |
| max_upload_size | |
| id | 898766 |
| size | 411,632 |
pixel_map Rust CrateA PixelMap stores pixel data for an image in a quadtree structure.
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.
Add the crate to your Cargo.toml:
cargo add pixel_map
use pixel_map::PixelMap;
// Example pixel data
struct Color(u8, u8, u8);
fn main() {
let mut pixel_map = PixelMap::<Color>::new(
&uvec2(1920, 1080), // size of the pixel map
Color(0, 0, 0), // initial value
1, // pixel size
);
}
fn main() {
let pixel_map = ...;
// Set a pixel
pixel_map.set_pixel((11, 12), Color(255, 0, 0));
// Draw a line
pixel_map.draw_line(&ULine::new((500, 500), (600, 400)), Color(0, 255, 0));
// Draw a rectangle
pixel_map.draw_rect(&URect::from_corners(uvec2(200, 200), uvec2(300, 300)), Color(0, 0, 255));
// Draw a circle
pixel_map.draw_circle(&ICircle::new((500, 500), 100), Color(0, 0, 255));
}
fn main() {
let pixel_map = ...;
// Visit all leaf nodes
pixel_map.visit(|node| {
println!("region: {:?}, value: {:?}", node.region(), node.value());
});
// Visit all leaf nodes that have been modified
pixel_map.visit_dirty(|node| {
println!("region: {:?}, value: {:?}", node.region(), node.value());
});
pixel_map.clear_dirty(true /*recurse*/);
}
Run cargo test to unit test.
Mind blown, hey?
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.
pixel_map is free and open source. All code in this repository is dual-licensed under
either of the following, at your option:
LICENSE-MIT or http://opensource.org/licenses/MIT)LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)