File: getSetRgb1Pixel.java

package info (click to toggle)
mauve 20120103-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 28,504 kB
  • sloc: java: 250,155; sh: 2,834; xml: 208; makefile: 66
file content (104 lines) | stat: -rw-r--r-- 3,284 bytes parent folder | download | duplicates (5)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* getSetRgb1Pixel.java -- Tests the work of the single pixel get/set Rgb
 Copyright (C) 2006 Audrius Meskauskas
 This file is part of Mauve.

 Mauve is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2, or (at your option)
 any later version.

 Mauve is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Mauve; see the file COPYING.  If not, write to the
 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 02110-1301 USA.

 */

// Tags: 1.4


package gnu.testlet.java.awt.image.BufferedImage;

import java.awt.Color;
import java.awt.image.BufferedImage;

import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;

/**
 * Tests the getRgb and setRgb.
 * 
 * @author Audrius Meskauskas
 */
public class getSetRgb1Pixel implements Testlet
{

  public void test(TestHarness h)
  {
    testType(h, BufferedImage.TYPE_3BYTE_BGR, "TYPE_3BYTE_BGR");
    testType(h, BufferedImage.TYPE_4BYTE_ABGR, "TYPE_4BYTE_ABGR");
    testType(h, BufferedImage.TYPE_4BYTE_ABGR_PRE, "TYPE_4BYTE_ABGR_PRE");
    testType(h, BufferedImage.TYPE_INT_ARGB, "TYPE_INT_ARGB");
    testType(h, BufferedImage.TYPE_INT_ARGB_PRE, "TYPE_INT_ARGB_PRE");
    testType(h, BufferedImage.TYPE_INT_BGR, "TYPE_INT_BGR");
    testType(h, BufferedImage.TYPE_INT_RGB, "TYPE_INT_RGB");
  }

  public void testType(TestHarness h, int type, String typeName)
  {
    int w = 10;

    BufferedImage b = new BufferedImage(w, w, type);

    Color[][] colors = new Color[w][];

    for (int i = 0; i < colors.length; i++)
      {
        colors[i] = new Color[w];
        for (int j = 0; j < colors[i].length; j++)
          {
            colors[i][j] = new Color((int) (Math.random() * 255),
                                     (int) (Math.random() * 255),
                                     (int) (Math.random() * 255));
            b.setRGB(i, j, colors[i][j].getRGB());
          }
      }

    BufferedImage cloned = new BufferedImage(w, w, type);
    b.copyData(cloned.getRaster());

    for (int i = 0; i < colors.length; i++)
      for (int j = 0; j < colors[i].length; j++)
        {
          if (!colors[i][j].equals(new Color(b.getRGB(i, j))))
            {
              h.fail("Failed " + typeName + ", " + colors[i][j] + " v "
                     + new Color(b.getRGB(i, j)));
              return;
            }
          int blue = Color.blue.getRGB();
          b.setRGB(i, j, blue);
          if (b.getRGB(i, j) != blue)
            {
              h.fail("Failed " + typeName + " when resetting into blue " + blue
                     + " v " + b.getRGB(i, j));
              return;
            }
        }

    for (int i = 0; i < colors.length; i++)
      for (int j = 0; j < colors[i].length; j++)
        {
          if (!colors[i][j].equals(new Color(cloned.getRGB(i, j))))
            {
              h.fail("Failed " + typeName + " on cloned image");
              return;
            }
        }
  }
}