1--TEST-- 2Apply imagegammacorrect() to a step wedge 3--SKIPIF-- 4<?php 5if (!extension_loaded('gd')) die('skip gd extension not available'); 6?> 7--FILE-- 8<?php 9require __DIR__ . DIRECTORY_SEPARATOR . 'func.inc'; 10 11test_gamma_both(1, 2); 12test_gamma_both(1, 1); 13test_gamma_both(2, 1); 14 15function test_gamma_both($in, $out) 16{ 17 test_gamma($in, $out, 'imagecreate'); 18 test_gamma($in, $out, 'imagecreatetruecolor'); 19} 20 21function test_gamma($in, $out, $constructor) 22{ 23 $im = $constructor(640, 480); 24 for ($j = 0; $j < 4; $j++) { 25 for ($i = 0; $i < 32; $i++) { 26 draw_cell($im, $i, $j); 27 } 28 } 29 30 imagegammacorrect($im, $in, $out); 31 32 $filename = __DIR__ . DIRECTORY_SEPARATOR 33 . "imagegammacorrect_variation2_{$in}_{$out}.png"; 34 $kind = $constructor === 'imagecreate' ? 'palette' : 'truecolor'; 35 echo "$kind gamma ($in, $out): "; 36 test_image_equals_file($filename, $im); 37} 38 39function draw_cell($im, $x, $y) 40{ 41 $x1 = 20 * $x; 42 $y1 = 120 * $y; 43 $x2 = $x1 + 19; 44 $y2 = $y1 + 119; 45 $color = cell_color($im, $x, $y); 46 imagefilledrectangle($im, $x1,$y1, $x2,$y2, $color); 47} 48 49function cell_color($im, $x, $y) 50{ 51 $channel = 8 * $x + 4; 52 switch ($y) { 53 case 0: 54 return imagecolorallocate($im, $channel, $channel, $channel); 55 case 1: 56 return imagecolorallocate($im, $channel, 0, 0); 57 case 2: 58 return imagecolorallocate($im, 0, $channel, 0); 59 case 3: 60 return imagecolorallocate($im, 0, 0, $channel); 61 } 62} 63?> 64--EXPECT-- 65palette gamma (1, 2): The images are equal. 66truecolor gamma (1, 2): The images are equal. 67palette gamma (1, 1): The images are equal. 68truecolor gamma (1, 1): The images are equal. 69palette gamma (2, 1): The images are equal. 70truecolor gamma (2, 1): The images are equal. 71