If a pictorial color image is stored as red, green and blue (RGB) channels, it must use lossless compression to avoid smearing of primary colors.
If the three color channels of a pictorial color image use lossy compression, storage as RGB channels is not suitable, because lossy compression spatially affects different channels differently, causing primary colors to smear relative to each other.
To use lossy compression, the three color channels must be decorrelated. For built-in color decorrelation, this XRH version uses these formulas to convert RGB colors to YCbCr:
Y = αr · R + αg · G + αb · B
Cb = 0.5 (B − Y) ⁄ (1 − αb)
Cr = 0.5 (R − Y) ⁄ (1 − αr)
Y is the image intensity (luminance).
It is the weighted average of the RGB channels.
add up to 1, and
depend on which
If Zero (0) is stored in the Color Transformation Type integer of the XRH file header, then no color transformation is performed.
If the Color Transformation Type is One (1),
αr = 0.2126 αg = 0.7152 αb = 0.0722
This is the default color transformation for decorrelation.
If the Color Transformation Type is Two (2),
αr = 0.2627 αg = 0.6780 αb = 0.0593
Some of the chroma difference channel values (generated by the equations above) may be negative. That is OK. Those values need to be recovered later. When compressing chroma channels, the compressor must support negative values in input, or the input will need to be filtered to temporarily make the values non-negative until recovered later.
To perform a custom color transformation, for your application only, set the high order bit of the Color Transformation Type integer. In that case, no built-in color transformation is performed. Built-in color transformations will not have the high order bit set in the Color Transformation Type integer.