# Color spaces

A project log for Recursive Range Reduction (3R) HW&SW CODEC

A high speed circuit design in JS and VHDL for decoding 3R bitstreams, a "quasi-entropy" code that compacts series of correlated numbers.

Note for later : Test a variety of lossless colorspace conversions and see which performs best :-)

• G, R-G, B-G

This one is the simplest !

```; encoding
Y = G
Cb = B - G
Cr = R-G

; decoding
G = Y
B = Cb - Y
R = Cr - Y```
Latency is 1 addition (1 cycle). 8-bits components wrap around on overflow.
• Reversible Color Transform (RCT)

https://en.wikipedia.org/wiki/JPEG_2000#Color_components_transformation

```; encoding
Y = ( R + 2G + B) >> 2
Cb = B - G
Cr = R - G
; decoding
G = Y - ((Cb + Cr)>>4)
R = Cr + G
B = Cb + G```
That one is very nice, encoding takes 1 cycle and decoding 2 cycles. Is it more efficient than the previous one ?
• YCoCg

It's a bit different https://software.intel.com/en-us/node/503873

```; coding
Y = R/4 + G/2 + B/4
Co = R/2 - B/2
Cg = -R/4 + G/2 - B/4
; or better :
t = (R + B) >> 1
Co = (R - B) >> 1    ; I have to find an "add-sub" circuit, but A+B and A-B have the same LSB
Y = (G + t ) >> 1
Cg = (G - t) >> 1

; decoding
R = Y + Co - Cg
G = Y + Cg
B = Y - Co - Cg

```
Coding and decoding use 4 add or sub each but more bits are needed to preserve perfect reversibility.
• YCoCG24

I love this one. I'm not sure who designed it first, it uses a different lifting scheme that preserves reversibility

http://stackoverflowproxy.eu/questions/10566668/lossless-rgb-to-ycbcr-transformation/12146329#12146329

```; encoding
Co = B - R
R = R + Co>>1
Cg = R - G
Y = G + Cg>>1

; decoding
G = Y - Cg>>1
Cg = Cg + Y
R = Cg - Co>>1
Cg = Co + R
```

It is perfectly reversible at the price of a longer critical datapath.

Which of those transforms is the best in practice ?

20170529:

See the solution at colorspace decomposition

## Discussions 