Here is the original post by David Cary:
http://stackoverflow.com/questions/10566668/lossless-rgb-to-ycbcr-transformation
8-bit RGB to YCoCg and back with no errors. Here is the code I adapted from David's pseudo code:
Code:#include <stdio.h> signed char x,yy,diff,average, temp; signed char Y,Co,Cg; unsigned char R1, G1, B1, Rd, Gd, Bd; unsigned long count; unsigned short maxrederror, maxgreenerror, maxblueerror, Rct, Gct, Bct; void RGB_to_YCoCg24(void){ //forward_lift(red, blue); diff = (B1 - R1); average = (R1 + (diff >> 1)); temp = average; Co = diff; diff = (temp - G1); average = (G1 + (diff >> 1)); Y = average; Cg = diff; } void YCoCg24_to_RGB(void) { x = (Y - (Cg >> 1)); yy = (x + Cg); Gd = x; temp = yy; x = (temp - (Co >> 1)); Bd = (x + Co); Rd = x; } int main(void){ for (Rct = 0; Rct <= 255; Rct ++) for (Gct = 0; Gct <= 255; Gct ++) for (Bct = 0; Bct <= 255; Bct ++) { { { R1 = Rct; G1 = Gct; B1 = Bct; RGB_to_YCoCg24(); YCoCg24_to_RGB(); count ++; if (Rd-R1 > maxrederror) {maxrederror = Rd-R1;} else if (R1-Rd > maxrederror) {maxrederror = R1-Rd;} if (Gd-G1 > maxgreenerror) {maxgreenerror = Gd-G1;} else if (G1-Gd > maxgreenerror) {maxgreenerror = G1-Gd;} if (Bd-B1 > maxblueerror) {maxblueerror = Bd-B1;} else if (B1-Bd > maxblueerror) {maxblueerror = B1-Bd;} } } } printf("Colors tested: %d\n", count); printf("Max red error %d\n",maxrederror); printf("Max green error %d\n",maxgreenerror); printf("Max blue error %d\n",maxblueerror); }
+ Reply to Thread
Results 1 to 1 of 1
Similar Threads
-
Looking for free tools to cut part of mp4 without re encoding it ?
By method in forum EditingReplies: 5Last Post: 9th May 2016, 13:11 -
Good (preferably free, GUI) tool to split H.265 MP4s (w/o re-encoding)?
By Razz in forum Newbie / General discussionsReplies: 2Last Post: 9th Jun 2015, 05:34 -
Tool for m2ts edit without encoding? Simple & possibly free?
By Golem in forum EditingReplies: 2Last Post: 31st Jan 2013, 16:08 -
What's a Free MP4 Editor that Preserves Source Settings while Encoding
By imdaman in forum EditingReplies: 1Last Post: 8th Jan 2013, 03:05 -
Free wmv joiner/merger without re encoding
By taebog in forum EditingReplies: 15Last Post: 6th Oct 2012, 16:36