Crate rgb

Source
Expand description

Basic struct for RGB and RGBA pixels. Packed, with red first, alpha last.

This crate is intended to be the lowest common denominator for sharing RGB/RGBA bitmaps between other crates.

The crate includes convenience functions for converting between the struct and bytes, and overloaded operators that work on all channels at once.

This crate intentionally doesn’t implement color management (due to complexity of the problem), but the structs can be parametrized to implement this if necessary. Other colorspaces are out of scope.

let pixel = RGB8 {r:0, g:100, b:255};

let pixel_rgba = pixel.alpha(255);
let pixel = pixel_rgba.rgb();

let pixels = vec![pixel; 100];
use rgb::ComponentBytes; // Import byte conversion trait
let bytes = pixels.as_bytes();

use rgb::ComponentMap; // Import pixel map trait
let half_bright = pixel.map(|channel| channel / 2);
let doubled = half_bright * 2;

Re-exports§

pub use ::bytemuck;bytemuck

Modules§

alt
BGR/BGRA alernative layouts & grayscale
prelude
traits for forward compatibility with the next major version of the crate

Structs§

Abgr
An Alpha + Blue + Green + Red pixel.
Argb
An Alpha + Red + Green + Blue pixel.
Bgr
A Blue + Green + Red pixel.
Bgra
A Blue + Green + Red + Alpha pixel.
GrayNon-unstable-experimental
A Grayscale pixel (rgb crate v0.8)
GrayAlphaNon-unstable-experimental
A pixel for grayscale value + alpha components (rgb crate v0.8)
Grb
A Green + Red + Blue pixel.
Rgb
A Red + Green + Blue pixel.
Rgba
A Red + Green + Blue + Alpha pixel.

Traits§

AsPixels
Use ::bytemuck::cast_slice() instead.
ColorComponentMap
Same as ComponentMap, but doesn’t change the alpha channel (if there’s any alpha).
ComponentBytesas-bytes
Use ::bytemuck::cast_slice() instead.
ComponentMap
Applying operation to every component
ComponentSlice
Casting the struct to slices of its components
FromSlice
Use ::bytemuck::cast_slice() or ::bytemuck::from_bytes() to convert
Podas-bytes
Re-export from bytemuck crate Marker trait for “plain old data”.
Zeroableas-bytes
Re-export from bytemuck crate Trait for types that can be safely created with zeroed.

Type Aliases§

RGB8
8-bit RGB
RGB16
16-bit RGB in machine’s native endian
RGBA8
8-bit RGBA, alpha is last. 0 = transparent, 255 = opaque.
RGBA16
16-bit RGB in machine’s native endian. 0 = transparent, 65535 = opaque.