The pixel_map Rust Crate

crates.io docs MIT/Apache 2.0 build status

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:

bash cargo add pixel_map

Creating a Pixel Map

```rust use pixel_map::PixelMap;

// Example pixel data struct MyColor(u8, u8, u8);

let mut pixel_map = PixelMap::new( Region::new( 0, // position x 0, // position y 1024 // size ), MyColor(0, 0, 0), // initial value 1, // pixel size );

```

Drawing on the PixelMap

```rust // Set a pixel pixelmap.setpixel((11, 12), MyColor(255, 0, 0));

// Draw a line pixelmap.drawline(&ILine::new((500, 500), (600, 400)), MyColor(0, 255, 0));

// Draw a rectangle pixelmap.drawrect(&IRect::from_corners((200, 200), (300, 300)), MyColor(0, 0, 255));

// Draw a circle pixelmap.drawcircle(&ICircle::new((500, 500), 100), MyColor(0, 0, 255)); ```

Navigating the PixelMap

```rust // Visit all leaf nodes pixel_map.visit(|node| { println!("region: {:?}, value: {:?}", node.region(), node.value()); });

// Visit all leaf nodes that have been modified pixelmap.visitdirty(|node| { println!("region: {:?}, value: {:?}", node.region(), node.value()); }); pixelmap.cleardirty(true /recurse/); ```

Features

Limitations

License

pixel_map is free and open source. All code in this repository is dual-licensed under either of the following, at your option: