• Lossless rgb<->yuv discuss

    From Yang Luo@21:1/5 to All on Sun Jul 17 16:25:16 2016
    Is there a lossless rgb<->yuv formula, no clip?
    something like this: (not all OK)
    C = 256 or 32 or 16
    tmp = ((r-b)/2+b)
    v = g - tmp + C
    u = r - b + C
    y = (g+tmp)/2;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Yang Luo@21:1/5 to All on Sun Jul 17 16:27:27 2016
    Is there a lossless rgb<->yuv formula, no clip?
    something like this: (not all OK)
    C = 256 or 32 or 16
    tmp = ((r-b)/2+b)
    v = g - tmp + C
    u = r - b + C
    y = (g+tmp)/2;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Richter@21:1/5 to Yang Luo on Mon Jul 18 15:08:27 2016
    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)
  • From Sand Glass@21:1/5 to All on Mon Jul 18 08:20:24 2016
    在 2016年7月18日星期一 UTC+8下午9:08:29,Thomas Richter写道:
    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

    Thanks, Thomas. The wiki gets the detailed response https://en.wikipedia.org/wiki/YCgCo

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)