# [FFmpeg-devel] colorspace.h

Chris c319chris at aol.com
Sat Jun 6 06:42:28 CEST 2015

```Here is a somewhat improved routine to calculate colors in colorspace.h, using the round() function. It is for calculating BT.601 and BT.709 colors. The rounding is very important for accurate colors.

Is anyone else concerned about accurate colors in ffpeg?

==================================================================================
#include "..\include\stdio.h"
#include "..\include\math.h"

//coefficients
#define R601 0.299
#define G601 0.587
#define B601 0.114

#define R709 0.2126
#define G709 0.7152
#define B709 0.0722

float Cr,Cb,y;
int r, g, b;

void encode(int r, int g, int b, int colorspace) {

if(colorspace == 601){ //use BT.601 color space
y = (r*R601) + (g*G601) + (b*B601);
Cr = (r * R601) - y;
Cb = (b * B601) - y;

r = round((Cr + y) / R601);
g = round(-((Cr + y + Cb) / G601));
b = round((y + Cb) / B601);
}
else { //use BT.709 color space
y = (r*R709) + (g*G709) + (b*B709);
Cr = (r * R709) - y;
Cb = (b * B709) - y;

r = round((Cr + y) / R709);
g = round(-((Cr + y + Cb) / G709));
b = round((y + Cb) / B709);
}

printf("%i\n", r);
printf("%i\n", g);
printf("%i\n", b);
}

int main(void){
// encode rgb colors
encode(255,128,0,601); //use 601 or 709 as last argument
}

-----Original Message-----
From: Michael Niedermayer <michaelni at gmx.at>
To: FFmpeg development discussions and patches <ffmpeg-devel at ffmpeg.org>
Sent: Wed, Jun 3, 2015 11:52 am
Subject: Re: [FFmpeg-devel] colorspace.h

On Tue, Jun 02, 2015 at 02:28:59AM -0400, Chris wrote:
> Hello -
>
> I have
found what I believe to be some questionable code in colorspace.h. I have
modified the code to what I believe is correct but am unable to compile ffmpeg
myself on Windows to test my modifications, despite spending many hours trying
to do so and reading several how-to's.
>
> We can discuss the code changes
here if people would like, but someone who is better equipped to compile ffmpeg
would have to compile it.

can you post a patch that shows the modifications
and explain what is
wrong before and how its improved

Thanks

[...]
--

Michael     GnuPG fingerprint:

During times of universal deceit,
telling the truth becomes a
revolutionary act. -- George Orwell

_______________________________________________
ffmpeg-devel mailing
list
ffmpeg-devel at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

```