blob: 61c031ba2388c9d9000d1929ffefee0f12d473f8 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 @test
26 @bug 5068850
27 @summary Tests that no exceptions are thrown when BufferedImageOp or RasterOps
28 are used.
29 @run main ImagingOpsNoExceptionsTest
30*/
31
32import java.awt.image.*;
33import java.awt.color.*;
34import java.awt.geom.AffineTransform;
35
36public class ImagingOpsNoExceptionsTest {
37 private static final String opsName[] = {
38 "Threshold", "RescaleOp" ,"Invert", "Yellow Invert", "3x3 Blur",
39 "3x3 Sharpen", "3x3 Edge", "5x5 Edge", "Color Convert", "Rotate"};
40 private static BufferedImageOp biop[] = new BufferedImageOp[opsName.length];
41 private static RasterOp rop[] = new RasterOp[opsName.length];
42 private static int low = 100, high = 200;
43
44 private static final int SIZE = 100;
45
46 public static void runTest() {
47 int exceptions = 0;
48 for (int i = 0; i < opsName.length; i++) {
49 // BUG: can't iterate through all image types because
50 // of crashes on solaris with VIS as of tiger-rc
51 for (int j = BufferedImage.TYPE_INT_RGB;
52 j <= BufferedImage.TYPE_INT_RGB; j++)
53 {
54 BufferedImage srcImage =
55 new BufferedImage(SIZE, SIZE, j);
56 BufferedImage dstImage =
57 new BufferedImage(SIZE, SIZE, j);
58 System.err.println("bi type="+j);
59 System.err.println(" biop ="+opsName[i]);
60 try {
61 biop[i].filter(srcImage, dstImage);
62 } catch (Exception e) {
63 e.printStackTrace();
64 exceptions++;
65 }
66 try {
67 biop[i].filter(srcImage, null);
68 } catch (Exception e) {
69 e.printStackTrace();
70 exceptions++;
71 }
72
73 // BUG: LookupOp raster op crashes on solaris with VIS
74 // as of tiger-rc
75 if (! (rop[i] instanceof LookupOp)) {
76 System.err.println(" rop ="+opsName[i]);
77 try {
78 rop[i].filter(srcImage.getRaster(),
79 (WritableRaster)dstImage.getRaster());
80 } catch (Exception e) {
81 e.printStackTrace();
82 exceptions++;
83 }
84 }
85 }
86 }
87
88 if (exceptions > 0) {
89 throw new RuntimeException("Test Failed, " + exceptions +
90 " exceptions were thrown");
91 }
92 System.err.println("Test Passed, no exceptions were thrown.");
93 }
94
95 public static void thresholdOp(int low, int high) {
96 byte threshold[] = new byte[256];
97 for (int j = 0; j < 256 ; j++) {
98 if (j > high) {
99 threshold[j] = (byte) 255;
100 } else if (j < low) {
101 threshold[j] = (byte) 0;
102 } else {
103 threshold[j] = (byte) j;
104 }
105 }
106 LookupOp lop = new LookupOp(new ByteLookupTable(0,threshold), null);
107 biop[0] = lop;
108 rop[0] = lop;
109 }
110
111 public static void main (String[] args) {
112 thresholdOp(low, high);
113 int i = 1;
114 RescaleOp resop = new RescaleOp(1.0f, 0, null);
115 biop[i] = resop;
116 rop[i] = resop;
117 i++;
118
119 byte invert[] = new byte[256];
120 byte ordered[] = new byte[256];
121 for (int j = 0; j < 256 ; j++) {
122 invert[j] = (byte) (256-j);
123 ordered[j] = (byte) j;
124 }
125 LookupOp lop = new LookupOp(new ByteLookupTable(0,invert), null);
126 biop[i] = lop;
127 rop[i] = lop;
128 i++;
129
130 byte[][] yellowInvert = new byte[][] { invert, invert, ordered };
131 lop = new LookupOp(new ByteLookupTable(0,yellowInvert), null);
132 biop[i] = lop;
133 rop[i] = lop;
134 i++;
135 int dim[][] = {{3,3}, {3,3}, {3,3}, {5,5}};
136 float data[][] = { {0.1f, 0.1f, 0.1f, // 3x3 blur
137 0.1f, 0.2f, 0.1f,
138 0.1f, 0.1f, 0.1f},
139 {-1.0f, -1.0f, -1.0f, // 3x3 sharpen
140 -1.0f, 9.0f, -1.0f,
141 -1.0f, -1.0f, -1.0f},
142 { 0.f, -1.f, 0.f, // 3x3 edge
143 -1.f, 5.f, -1.f,
144 0.f, -1.f, 0.f},
145 {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f, // 5x5 edge
146 -1.0f, -1.0f, -1.0f, -1.0f, -1.0f,
147 -1.0f, -1.0f, 24.0f, -1.0f, -1.0f,
148 -1.0f, -1.0f, -1.0f, -1.0f, -1.0f,
149 -1.0f, -1.0f, -1.0f, -1.0f, -1.0f}};
150 for (int j = 0; j < data.length; j++, i++) {
151 ConvolveOp cop = new ConvolveOp(new Kernel(dim[j][0],dim[j][1],data[j]));
152 biop[i] = cop;
153 rop[i] = cop;
154 }
155
156 ColorSpace cs1 = ColorSpace.getInstance(ColorSpace.CS_sRGB);
157 ColorSpace cs2 = ColorSpace.getInstance(ColorSpace.CS_PYCC);
158 ColorConvertOp ccop = new ColorConvertOp(cs1, cs2, null);
159 biop[i] = ccop;
160 rop[i] = ccop;
161 i++;
162
163 AffineTransform at =
164 AffineTransform.getRotateInstance(0.5*Math.PI, SIZE/2, SIZE/2);
165 AffineTransformOp atOp =
166 new AffineTransformOp(at, null);
167 biop[i] = atOp;
168 rop[i] = atOp;
169
170 runTest();
171 }
172}