Crate cint[][src]

Expand description

cint - color interop

This library provides a lean, minimal, and stable set of types for color interoperation between crates in Rust. Its goal is to serve the same function that mint provides for (linear algebra) math types. It does not actually provide any conversion, math, etc. for these types, but rather serves as a stable interface that multiple libraries can rely on and then convert to their own internal representations to actually use. It is also #![no_std]. bytemuck impls are provided with the bytemuck feature.

How to Use

If you have no idea about color management or encoding principles but you want to use this crate in your own, here’s a very basic rundown.

If you have a color that you loaded from an 8-bit format like a PNG, JPG, etc., or if you have a color that you picked from some sort of online color picker or in Photoshop or Aseprite, then what you have is almost certainly an EncodedSrgb<u8> color. If you have a color that you loaded from a similar format but has floating point values instead of u8 ints, then you almost certainly instead have a EncodedSrgb<f32> color.

If you “linearized” or performed “inverse gamma correction” on such a color, then you instead might have a LinearSrgb<f32>.

If you are more familiar with color encoding, then you’ll find a collection of other color spaces represented, as well as the generic GenericColor<ComponentTy> type which can be used if the color space you wish to use is not represented.

Colors with alpha channels

cint provides the ColorAlpha<ComponentTy, ColorTy> and PremultipliedColorAlpha<ComponentTy, ColorTy> structs, which are generic over both ComponentTy and ColorTy. To represent an EncodedSrgb<u8> color with a premultiplied alpha component, you’d use PremultipliedColorAlpha<u8, EncodedSrgb<u8>>. If, on the other hand, you want to represent an Oklab<f32> color with an independent alpha component, you’d use ColorAlpha<f32, Oklab<f32>>

Structs

Aces2065

A color in the ACES 2065-1 color space.

AcesCc

A color in the ACEScc color space.

AcesCct

A color in the ACEScct color space.

AcesCg

A color in the ACEScg color space.

Bt2020

A color in the BT.2020 color space.

Bt2100

A color in the BT.2100 color space.

CieLCh

A color in the CIE L*C*h color space.

CieLab

A color in the CIE L*a*b color space.

CieXYZ

A color in the CIE XYZ color space.

ColorAlpha

A color with an alpha component.

DciP3

A color in the DCI-P3 (aka P3 DCI and P3 D60) color space.

DciXYZPrime

A color in the X’Y’Z’ color space, a DCI specification used for digital cinema mastering.

DisplayP3

A color in the Display P3 (aka P3 D65) color space.

EncodedBt2020

A color in the encoded BT.2020 color space.

EncodedBt2100HLG

A color in the encoded BT.2100 color space with HLG (Hybrid Log-Gamma) transfer function.

EncodedBt2100PQ

A color in the encoded BT.2100 color space with PQ (Perceptual Quantizer) transfer function.

EncodedDisplayP3

A color in the Display P3 (aka P3 D65) color space.

EncodedRec709

A color in the encoded Rec.709/BT.709 color space.

EncodedSrgb

A color in the encoded sRGB color space.

GenericColor

A color in a generic color space that can be represented by 3 components. The user is responsible for ensuring that the correct color space is respected.

ICtCpHLG

A color in the ICtCp color space with HLG (Hybrid Log-Gamma) nonlinearity.

ICtCpPQ

A color in the ICtCp color space with PQ (Perceptual Quantizer) nonlinearity.

LinearSrgb

A color in the linear (decoded) sRGB color space.

Oklab

A color in the Oklab color space.

Oklch

A color in the Oklch color space (a transformation from Oklab to L*c*h coordinates).

PremultipliedColorAlpha

A premultiplied color with an alpha component.

Rec709

A color in the Rec.709/BT.709 color space.