Crate rgb [] [src]

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];
let bytes = pixels.as_bytes();

let half_bright = pixel.map(|channel| channel / 2);
let doubled = half_bright * 2;

Structs

RGB

This is it. The component type can be u8 (aliased as RGB8), u16 (aliased as RGB16), or any other type (but simple copyable types are recommended.)

RGBA

This is it. The component type can be u8 (aliased as RGBA8), u16 (aliased as RGBA16), or any other type (but simple copyable types are recommended.)

Traits

ComponentBytes

Casting the struct to slices/bytes of its components

ComponentMap

Applying operation to every component

FromSlice

Cast a slice of component values (bytes) as a slice of RGB/RGBA pixels

Type Definitions

RGB8

8-bit RGB. The colorspace is techincally undefined, but generally sRGB is assumed.

RGB16

16-bit RGB in machine's native endian. Be careful to perform byte-swapping when reading from files.

RGBA8

Alpha is last. The crate doesn't impose which value represents transparency, but usually it's 0 = transparent, 255 = opaque.

RGBA16

16-bit RGB in machine's native endian. Alpha is last.