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