YCbCr To RGB

This algorithm converts YCbCr color space to RGB color model.



									class RGB
{
	public $R;
	public $G;
	public $B;
}

class YCbCr
{
	public $Y;
	public $Cb;
	public $Cr;
}

function YCbCrToRGB($ycbcr) {
	$r = max(0.0, min(1.0, (float)($ycbcr->Y + 0.0000 * $ycbcr->Cb + 1.4022 * $ycbcr->Cr)));
	$g = max(0.0, min(1.0, (float)($ycbcr->Y - 0.3456 * $ycbcr->Cb - 0.7145 * $ycbcr->Cr)));
	$b = max(0.0, min(1.0, (float)($ycbcr->Y + 1.7710 * $ycbcr->Cb + 0.0000 * $ycbcr->Cr)));

	$rgb = new RGB();
	$rgb->R = floor($r * 255);
	$rgb->G = floor($g * 255);
	$rgb->B = floor($b * 255);

	return $rgb;
}
								


Example

									$data = new YCbCr();
$data->Y = 0.28;
$data->Cb = 0.21;
$data->Cr = 0.34;

$value = YCbCrToRGB($data);
								


Output

									R: 192
G: 0
B: 166