public void Init(float[] luma, float[] refBlackWhite)
{
Array.Clear(clamptab, 0, 256); /* v < 0 => 0 */
for (int i = 0; i < 256; i++)
clamptab[clamptabOffset + i] = (byte)i;
int start = clamptabOffset + 256;
int stop = start + 2 * 256;
for (int i = start; i < stop; i++)
clamptab[i] = 255; /* v > 255 => 255 */
float LumaRed = luma[0];
float LumaGreen = luma[1];
float LumaBlue = luma[2];
float f1 = 2 - 2 * LumaRed;
int D1 = fix(f1);
float f2 = LumaRed * f1 / LumaGreen;
int D2 = -fix(f2);
float f3 = 2 - 2 * LumaBlue;
int D3 = fix(f3);
float f4 = LumaBlue * f3 / LumaGreen;
int D4 = -fix(f4);
/*
* i is the actual input pixel value in the range 0..255
* Cb and Cr values are in the range -128..127 (actually
* they are in a range defined by the ReferenceBlackWhite
* tag) so there is some range shifting to do here when
* constructing tables indexed by the raw pixel data.
*/
for (int i = 0, x = -128; i < 256; i++, x++)
{
int Cr = code2V(x, refBlackWhite[4] - 128.0F, refBlackWhite[5] - 128.0F, 127);
int Cb = code2V(x, refBlackWhite[2] - 128.0F, refBlackWhite[3] - 128.0F, 127);
Cr_r_tab[i] = (D1 * Cr + ONE_HALF) >> SHIFT;
Cb_b_tab[i] = (D3 * Cb + ONE_HALF) >> SHIFT;
Cr_g_tab[i] = D2 * Cr;
Cb_g_tab[i] = D4 * Cb + ONE_HALF;
Y_tab[i] = code2V(x + 128, refBlackWhite[0], refBlackWhite[1], 255);
}
}