#include "readloop-cvt.h" double cvt_Kr; double cvt_Kb; int cvt_clip_Y; int cvt_clip_CbCr; //static unsigned short int to_rgb[3][3]; /* * In analog terms, * * Y' = Kr R' + (1 - Kr - Kb) G' + Kb B' * Pr = .5 (R' - Y') / (1 - Kr) * Pb = .5 (B' - Y') / (1 - Kb) * * Expanding this to create the matrix form, we get, successively, * * Y' = Kr R' + (1-Kr-Kb) G' + Kb B' * Pr = .5 (R' - (Kr R' + (1-Kr-Kb) G' + Kb B')) / (1-Kr) * Pb = .5 (B' - (Kr R' + (1-Kr-Kb) G' + Kb B')) / (1-Kb) * * Y' = Kr R' + (1-Kr-Kb) G' + Kb B' * Pr = .5 (R' - Kr R' - (1-Kr-Kb) G' - Kb B') / (1-Kr) * Pb = .5 (B' - Kr R' - (1-Kr-Kb) G' - Kb B') / (1-Kb) * * Y' = Kr R' + (1-Kr-Kb) G' + Kb B' * Pr = ˝ R' - ˝(1-Kr-Kb)/(1-Kr) G' - ˝Kb/(1-Kr) B' * Pb = - ˝Kr/(1-Kb) R' - ˝(1-Kr-Kb)/(1-Kb) G' + ˝ B' * * [ Y' ] [ Kr 1-Kr-Kb Kb ] [ R' ] * [ Pr ] = [ ˝ -˝(1-Kr-Kb)/(1-Kr) -˝Kb/(1-Kr) ] [ G' ] * [ Pb ] [ -˝Kr/(1-Kb) -˝(1-Kr-Kb)/(1-Kb) ˝ ] [ B' ] * * Because R'/G'/B' and Y'/Pr/Pb use the same scale (a range of 1, * [0,1] for Y'/R'/G'/B' and [-˝,˝] for Pr/Pb) exactly the same matrix * works for [0..255] Y'/R'/G'/B' and [-128..127] Cr/Cb. When * limited-range clipping is turned on, we have to adjust for it. * * In any case, the above is the wrong matrix, because it's to go * _from_ RGB triples, not _to_ RGB triples. We have to invert it. */ static void reset_cvt(void) { double Kg; Kg = 1 - cvt_Kr - cvt_Kb; } void init_cvt(void) { cvt_Kr = .299; cvt_Kb = .114; cvt_clip_Y = 0; cvt_clip_CbCr = 0; reset_cvt(); }