1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
   | <?php
 
function hex2in_digit($num) {
	if (($num >= '0') && ($num <= '9'))
		return $num;
	return ord(strtolower($num)) - ord('a') + 10;
}
 
function hex2int($num) {
	if (strlen($num) == 1) $num = "0" . $num;
	return hex2in_digit($num[0])*16 + hex2in_digit($num[1]);
}
 
function normColor($c) {
	$c = floor($c);
	if ($c < 0) return 0;
	if ($c > 255) return 255;
	return $c;
}
 
$yv = explode(",",$_POST['yv']);
$cb = explode(",",$_POST['cb']);
$cr = explode(",",$_POST['cr']);
 
$sortie = imagecreatetruecolor(260,220);
 
$k=0;
for($i=0;$i<120;$i++) {
	for($j=0;$j<160;$j++){
		$y_value = hex2int($yv[$k]);
		//tab[i][j]=tab[i*n+j] with n the width
		$index = floor($i/4) * 40 + floor($j/4); //40=160/4
		$cb_value = hex2int($cb[$index]);
		$cr_value = hex2int($cr[$index]);
 
		$r = normColor(1 * $y_value + 0.0000 * $cb_value + 1.4022 * $cr_value + (1.4022 * -127.5));
		$g = normColor(1 * $y_value + -0.3456 * $cb_value + -0.7145 * $cr_value + (-0.3456 * -127.5) + (-0.7145 * -127.5));
		$b = normColor(1 * $y_value + 1.7710 * $cb_value + 0.0000 * $cr_value + (1.7710* -127.5));
 
		$pix = imagecolorallocate($sortie, $r, $g, $b);
 
		imagesetpixel($sortie,$j,$i,$pix);
		$k++;
	}
}
header("Content-type: image/jpeg");
imagejpeg($sortie,"",100);
imagedestroy($sortie);
 
?> | 
Partager