Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 Doom9's Forum Scaling of YCoCg to 8-bit bytes
 User Name Remember Me? Password
 Register FAQ Calendar Search Today's Posts Mark Forums Read

 Thread Tools Search this Thread Display Modes
 28th September 2020, 03:45 #1  |  Link kornelski image optimizer     Join Date: Sep 2020 Location: UK Posts: 1 Scaling of YCoCg to 8-bit bytes I'd like to add support for YCoCg color space in my AVIF image compressor. I can easily find RGB to YCoCg formulas (including the original YCoCg paper) that are equivalent of a matrix rotation, but I'm missing a second formula that scales the result to actual bytes to be encoded. All the sources I can find assume it's lossless and/or Co/Cg can be negative, but that means a conversion of 8-bit RGB to YCoCg gives 9- or 10-bit values. How am I supposed to store that in 8-bit unsigned bytes of YUV channels when encoding?
28th September 2020, 17:30   #2  |  Link
benwaggoner
Moderator

Join Date: Jan 2006
Location: Portland, OR
Posts: 3,625
Quote:
 Originally Posted by kornelski I'd like to add support for YCoCg color space in my AVIF image compressor. I can easily find RGB to YCoCg formulas (including the original YCoCg paper) that are equivalent of a matrix rotation, but I'm missing a second formula that scales the result to actual bytes to be encoded. All the sources I can find assume it's lossless and/or Co/Cg can be negative, but that means a conversion of 8-bit RGB to YCoCg gives 9- or 10-bit values. How am I supposed to store that in 8-bit unsigned bytes of YUV channels when encoding?
U and V are also signed, with "0" meaning no chroma for that channel and saturation coming from absolute value. It's really only luma or native RGB that are purely unsigned. You should be able to treat other chroma formats identically, and the codec itself doesn't really care.
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book

 28th September 2020, 18:53 #3  |  Link nhw_pulsar Registered User   Join Date: Apr 2017 Posts: 28 Yes, just for the precision, I used in my codec (NHW) for test the YCoCg matrix from the english wikipedia article. With these matrixes if you input 8-Bit RGB, it will output 8-Bit YCoCg, just the ranges will be Y: [0-255], Co: [-128,127], Cg: [-128,127], so typically you need to add an offset of +128 for Co and Cg, (and then remove it before converting back to RGB)... This would give a classic YCoCg 8-Bit colorspace... Just as we are talking about YCoCg, how do you estimate it? Its big advantage is that it is very fast (no multiplies), but visually I find that it is not as good as YCbCR/YUV... When I tested it 3-4 years ago in my codec, I made quite extensive tests at -l9 and -l11 compression settings if I remember correctly, and the results were not visually as pleasant as YUV at the same compression ratio.Did you have same experience? By the way, I read that your AVIF image compressor: CAVIF is great! Cheers, Raphael
29th September 2020, 20:10   #4  |  Link
benwaggoner
Moderator

Join Date: Jan 2006
Location: Portland, OR
Posts: 3,625
Quote:
 Originally Posted by nhw_pulsar Just as we are talking about YCoCg, how do you estimate it? Its big advantage is that it is very fast (no multiplies), but visually I find that it is not as good as YCbCR/YUV... When I tested it 3-4 years ago in my codec, I made quite extensive tests at -l9 and -l11 compression settings if I remember correctly, and the results were not visually as pleasant as YUV at the same compression ratio.Did you have same experience?
Yeah, Y'CbCr was well researched and grounded in science. Math is a little more complex, but it was still worth using it even back in JPEG where available MIPS per pixel were many orders of magnitude less. Y'CtCp also has its psychovisual strengths.

YCoCg doesn't make a lot of practical sense for me to adopt, since the easier math is pretty immaterial in modern systems.
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book

 Tags avif, ycocg, yuv

 Thread Tools Search this Thread Search this Thread: Advanced Search Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements and Chat     General Discussion     News     Forum / Site Suggestions & Help General     Decrypting     Newbies     DVD2AVI / DGIndex     Audio encoding     Subtitles     Linux, Mac OS X, & Co Capturing and Editing Video     Avisynth Usage     Avisynth Development     VapourSynth     Capturing Video     DV     HDTV / DVB / TiVo     NLE - Non Linear Editing     VirtualDub, VDubMod & AviDemux     New and alternative a/v containers Video Encoding     (Auto) Gordian Knot     MPEG-4 ASP     MPEG-4 Encoder GUIs     MPEG-4 AVC / H.264     High Efficiency Video Coding (HEVC)     New and alternative video codecs     MPEG-2 Encoding     VP9 and AV1 (HD) DVD, Blu-ray & (S)VCD     One click suites for DVD backup and DVD creation     DVD & BD Rebuilder     (HD) DVD & Blu-ray authoring     Advanced authoring     IFO/VOB Editors     DVD burning Hardware & Software     Software players     Hardware players     PC Hard & Software Programming and Hacking     Development     Translations

All times are GMT +1. The time now is 00:42.

 Doom9.org - Archive - Top