[][src]Crate rgb

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;

Modules

alt

BGR/BGRA alernative layouts & grayscale

Structs

RGB

The RGB pixel

RGBA

The RGBA pixel

Traits

AsPixels

Casts a slice of bytes into a slice of pixels, e.g. [u8] to [RGB8].

ComponentBytes

Casting a slice of RGB/A values to a slice of u8

ComponentMap

Applying operation to every component

ComponentSlice

Casting the struct to slices of its components

FromSlice

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

Type Definitions

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.