All Projects → kornelski → imgref

kornelski / imgref

Licence: CC0-1.0 license
A trivial Rust struct for interchange of pixel buffers with width, height & stride

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to imgref

rust-rgb
struct RGB for sharing pixels between crates
Stars: ✭ 70 (+55.56%)
Mutual labels:  pixel-layout, rust-library
rustgraphblas
rust-library to wrap GraphBLAS.h
Stars: ✭ 23 (-48.89%)
Mutual labels:  rust-library
Awesome-Rust-MachineLearning
This repository is a list of machine learning libraries written in Rust. It's a compilation of GitHub repositories, blogs, books, movies, discussions, papers, etc. 🦀
Stars: ✭ 1,110 (+2366.67%)
Mutual labels:  rust-library
rust-phonenumber
Library for parsing, formatting and validating international phone numbers.
Stars: ✭ 99 (+120%)
Mutual labels:  rust-library
crc32c
Fast CRC-32-Castagnoli implementation in Rust
Stars: ✭ 26 (-42.22%)
Mutual labels:  rust-library
ghakuf
A Rust library for parsing/building SMF (Standard MIDI File).
Stars: ✭ 30 (-33.33%)
Mutual labels:  rust-library
hidapi-rs
Rust bindings for the hidapi C library
Stars: ✭ 103 (+128.89%)
Mutual labels:  rust-library
type-metadata
Rust type metadata reflection library
Stars: ✭ 27 (-40%)
Mutual labels:  rust-library
the-modular-grid
A Chrome extension that superimposes a grid over your web dev mockups.
Stars: ✭ 20 (-55.56%)
Mutual labels:  pixel-layout
tentacle
A multiplexed p2p network framework that supports custom protocols
Stars: ✭ 41 (-8.89%)
Mutual labels:  rust-library
twitter-stream-rs
A Rust library for listening on Twitter Streaming API.
Stars: ✭ 66 (+46.67%)
Mutual labels:  rust-library
Nebuchadnezzar
High Performance Key-Value Store
Stars: ✭ 49 (+8.89%)
Mutual labels:  rust-library
codebreaker-rs
A Rust library to decrypt & encrypt any cheat code for CodeBreaker PS2
Stars: ✭ 18 (-60%)
Mutual labels:  rust-library
arangors
Easy to use rust driver for arangoDB
Stars: ✭ 120 (+166.67%)
Mutual labels:  rust-library
har-rs
A HTTP Archive format (HAR) serialization & deserialization library, written in Rust.
Stars: ✭ 25 (-44.44%)
Mutual labels:  rust-library
i2p-rs
Rust client library for interacting with I2P
Stars: ✭ 62 (+37.78%)
Mutual labels:  rust-library
contour-rs
Contour polygon creation in Rust (using marching squares algorithm)
Stars: ✭ 33 (-26.67%)
Mutual labels:  rust-library
colorful
Make your terminal output colorful.
Stars: ✭ 43 (-4.44%)
Mutual labels:  rust-library
rust-lcms2
ICC color profiles in Rust
Stars: ✭ 25 (-44.44%)
Mutual labels:  rust-library
rsmorphy
Morphological analyzer / inflection engine for Russian and Ukrainian languages rewritten in Rust
Stars: ✭ 27 (-40%)
Mutual labels:  rust-library

2D slice of a Vec

This is a lowest common denominator struct for working with image fragments in Rust code. It represents a 2-dimensional vector and rectangular slices of it.

In graphics code it's very common to pass width and height along with a Vec of pixels — all as separate arguments. This gets very repetitive, and can lead to errors.

This crate is a simple struct that adds dimensions to the underlying buffer. This makes it easier to correctly keep track of the image size and allows passing images with just one function argument instead three or four.

Additionally, it has a concept of a stride, which allows defining sub-regions of images without copying, as well as padding (e.g. buffers for video frames may require to be a multiple of 8, regardless of logical image size).

For convenience, it implements iterators for pixels/rows and indexing with img[(x,y)].

use imgref::*;

fn main() {
    let img = Img::new(vec![0; 1000], 50, 20); // 1000 pixels of a 50×20 image

    let new_image = some_image_processing_function(img.as_ref()); // Use imgvec.as_ref() instead of &imgvec for better efficiency

    println!("New size is {}×{}", new_image.width(), new_image.height());
    println!("And the top left pixel is {:?}", new_image[(0u32,0u32)]);

    let first_row_slice = &new_image[0];

    for row in new_image.rows() {}
    for px in new_image.pixels() {}

    // slice (x, y, width, height) by reference - no copy!
    let fragment = img.sub_image(5, 5, 15, 15);

    // create a vec of pixels without stride, for compatibility with software
    // that expects pixels without any "gaps"
    let (vec, width, height) = fragment.to_contiguous_buf();
}

Type aliases

Illustration: stride is width of the whole buffer.

These are described in more detail in the reference.

ImgVec

It owns its pixels (held in a Vec). It's analogous to a 2-dimensional Vec. Use this type to create and return new images from functions.

Don't use &ImgVec. Instead call ImgVec.as_ref() to get a reference (ImgRef) from it (explicit .as_ref() call is required, because Rust doesn't support custom conversions yet.)

ImgRef

ImgRef is a reference to pixels owned by some other ImgVec or a slice. It's analogous to a 2-dimensional &[].

Use this type to accept read-only images as arguments in functions. Note that ImgRef is a Copy type. Pass ImgRef, and not &ImgRef.

Requirements

  • Latest stable Rust (1.42+)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].