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