File: createCompatibleDestImage.java

package info (click to toggle)
mauve 20161030-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 44,628 kB
  • ctags: 35,425
  • sloc: java: 336,555; sh: 2,834; xml: 208; makefile: 72
file content (135 lines) | stat: -rw-r--r-- 5,274 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* createCompatibleDestImage.java -- some checks for the
       createCompatibleDestImage() method of the LookupOp class.
   Copyright (C) 2006 Francis Kung <fkung@redhat.com>
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: JDK1.2

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

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

import java.awt.image.BufferedImage;
import java.awt.image.ByteLookupTable;
import java.awt.image.DataBuffer;
import java.awt.image.DirectColorModel;
import java.awt.image.LookupOp;

/**
 * Checks for the createCompatibleDestImage method in the
 * {@link LookupOp} class.
 */
public class createCompatibleDestImage implements Testlet 
{

  /**
   * Runs the test using the specified harness.
   * 
   * @param harness  the test harness (<code>null</code> not permitted). 
   */
  public void test(TestHarness harness)      
  {
    simpleTest(harness);
    colorModelTest(harness);
  }
  
  private void simpleTest(TestHarness harness)
  {
    harness.checkPoint("createCompatibleDestImage");

    // Simple test
    byte[] bytes = new byte[] {(byte) 0xAA, (byte) 0xBB};
    ByteLookupTable t = new ByteLookupTable(0, bytes);
    LookupOp op = new LookupOp(t, null);
    
    BufferedImage img = new BufferedImage(25, 40, BufferedImage.TYPE_INT_RGB);
    
    BufferedImage dest = op.createCompatibleDestImage(img, img.getColorModel());
    
    harness.check(dest.getHeight(), 40);
    harness.check(dest.getWidth(), 25);
    harness.check(dest.getColorModel(), img.getColorModel());
    
    // Try a different colour model
    img = new BufferedImage(25, 40, BufferedImage.TYPE_INT_RGB);
    DirectColorModel cm = new DirectColorModel(16, 0x0f00, 0x00f0, 0x000f);
    dest = op.createCompatibleDestImage(img, cm);
    
    harness.check(dest.getHeight(), 40);
    harness.check(dest.getWidth(), 25);
    harness.check(dest.getColorModel(), cm);
  }
  
  // Test all the default color models
  private void colorModelTest(TestHarness harness)
  {
    byte[] bytes = new byte[] {(byte) 0xAA, (byte) 0xBB};
    ByteLookupTable t = new ByteLookupTable(0, bytes);
    LookupOp op = new LookupOp(t, null);

    int[] types = {BufferedImage.TYPE_INT_RGB,
                   BufferedImage.TYPE_INT_ARGB,
                   BufferedImage.TYPE_INT_ARGB_PRE,
                   BufferedImage.TYPE_3BYTE_BGR,
                   BufferedImage.TYPE_4BYTE_ABGR,
                   BufferedImage.TYPE_4BYTE_ABGR_PRE,
                   BufferedImage.TYPE_USHORT_565_RGB,
                   BufferedImage.TYPE_USHORT_555_RGB,
                   BufferedImage.TYPE_BYTE_GRAY,
                   BufferedImage.TYPE_USHORT_GRAY};
    // Skipped types that are not implemented yet:
    // TYPE_CUSTOM, TYPE_INT_BGR, TYPE_BYTE_BINARY, TYPE_BYTE_INDEXED

    for (int i = 0; i < types.length; i++)
      {
        int type = types[i];
        harness.checkPoint("type: " + type);
        
        BufferedImage img = new BufferedImage(25, 40, type);
        BufferedImage dest = op.createCompatibleDestImage(img, null);
        
        // Unlike most Ops, this one creates a clone of the original image
        
        // Except there's a strange exception for TYPE_USHORT_GRAY ???
        if (type == BufferedImage.TYPE_USHORT_GRAY)
          {
            harness.check(dest.getColorModel().getPixelSize(), 8);
            harness.check(dest.getColorModel().getTransferType(), DataBuffer.TYPE_BYTE);
          }
        else
          {
            harness.check(dest.getColorModel().getPixelSize(),
                          img.getColorModel().getPixelSize());
            harness.check(dest.getColorModel().getTransferType(), img.getColorModel().getTransferType());
          }

        harness.check(dest.getColorModel().getClass() == img.getColorModel().getClass());
        harness.check(dest.getSampleModel().getClass() == img.getSampleModel().getClass());
        harness.check(dest.getColorModel().getNumComponents(), img.getColorModel().getNumComponents());
        harness.check(dest.getColorModel().getTransparency(), img.getColorModel().getTransparency());
        harness.check(dest.getColorModel().hasAlpha(), img.getColorModel().hasAlpha());
        harness.check(dest.getColorModel().isAlphaPremultiplied(), img.getColorModel().isAlphaPremultiplied());
        harness.check(dest.getColorModel().getColorSpace().getType(), img.getColorModel().getColorSpace().getType());
        harness.check(dest.getRaster().getNumBands(), img.getRaster().getNumBands());
        harness.check(dest.getRaster().getNumDataElements(), img.getRaster().getNumDataElements());
      }
  }
}