Crates.io | pixel_map |
lib.rs | pixel_map |
version | 0.3.0 |
source | src |
created_at | 2023-06-24 03:51:06.129929 |
updated_at | 2023-10-07 04:06:48.043201 |
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 | 192,328 |
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);
let mut pixel_map = PixelMap::<Color>::new(
&uvec2(1920, 1080), // size of the pixel map
Color(0, 0, 0), // initial value
1, // pixel size
);
// 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));
// 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*/);
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)