On 18.07.2016 01:25, Yang Luo wrote:
Is there a lossless rgb<->yuv formula, no clip?
Not "yuv" directly, but "ycgco", which is "close enough" to yuv for many purposes. It doesn't clip, but it (necessarily) extends the range of the
chroma signal by one bit. Alternatively, you can also use RCT from JPEG
2000.
If you look for a continuous (i.e. no wrap-arounds, no jumps) lossless conversion from RGB to some other color space *without* range extension,
then I afraid the identity transformation and trivial variations thereof
(i.e. reflections, and permutations of the axes) are the only option.
This is the forwards transform:
LONG rp = *r;
LONG gp = *g;
LONG bp = *b;
LONG v = bp - rp;
LONG t = rp - gp + (v >> 1);
LONG y = gp + (t >> 1);
LONG u = -t;
And this is the backwards transform:
u = -u; // this was called t above
y -= u >> 1; // restore g. yp is now == g
u += y - (v >> 1); // this restores r. up is now == r
v += u; // this restores b
r = u
g = y
b = v
HTHH,
Thomas
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)