23
23
24
24
import java .awt .AlphaComposite ;
25
25
import java .awt .Graphics2D ;
26
+ import java .awt .Transparency ;
26
27
import java .awt .color .ColorSpace ;
27
28
import java .awt .color .ICC_ColorSpace ;
28
29
import java .awt .color .ICC_Profile ;
29
30
import java .awt .image .BufferedImage ;
30
31
import java .awt .image .ColorConvertOp ;
32
+ import java .awt .image .ColorModel ;
33
+ import java .awt .image .ComponentColorModel ;
34
+ import java .awt .image .DataBuffer ;
35
+ import java .awt .image .DirectColorModel ;
36
+ import java .awt .image .Raster ;
37
+ import java .awt .image .WritableRaster ;
31
38
32
39
import static java .awt .image .BufferedImage .TYPE_3BYTE_BGR ;
33
40
import static java .awt .image .BufferedImage .TYPE_4BYTE_ABGR ;
45
52
46
53
/*
47
54
* @test
48
- * @bug 8012229 8300725
55
+ * @bug 8012229 8300725 8279216
49
56
* @summary one more test to check the alpha channel
50
57
*/
51
58
public final class ColCvtAlphaDifferentSrcDst {
52
59
53
60
private static final int WIDTH = 256 ;
54
61
private static final int HEIGHT = 256 ;
55
62
63
+ private static final int TYPE_CUSTOM_4BYTE_ABGR_PRE = -1 ;
64
+ private static final int TYPE_CUSTOM_4BYTE_ARGB_PRE = -2 ;
65
+ private static final int TYPE_CUSTOM_4BYTE_RGBA_PRE = -3 ;
66
+ private static final int TYPE_CUSTOM_4BYTE_GABR_PRE = -4 ;
67
+ private static final int TYPE_CUSTOM_INT_ARGB_PRE = -5 ;
68
+ private static final int TYPE_CUSTOM_INT_GABR_PRE = -6 ;
69
+
56
70
public static void main (String [] args ) throws Exception {
57
71
differentToOpaqueDst ();
58
72
differentToTransparentDst (TYPE_INT_ARGB );
59
73
differentToTransparentDst (TYPE_4BYTE_ABGR );
60
74
differentToTransparentDst (TYPE_INT_ARGB_PRE );
75
+ differentToTransparentDst (TYPE_4BYTE_ABGR_PRE );
61
76
differentToNullDst ();
62
77
}
63
78
@@ -97,7 +112,16 @@ private static void differentToOpaqueDst() {
97
112
opaqueDst (TYPE_INT_ARGB , TYPE_INT_BGR );
98
113
opaqueDst (TYPE_4BYTE_ABGR , TYPE_INT_BGR );
99
114
100
- // It is unclear how to hangle pre colors in the opaque DST
115
+ // compare the "fast" and "slow" paths
116
+ opaqueDst (TYPE_4BYTE_ABGR_PRE , TYPE_CUSTOM_4BYTE_ABGR_PRE );
117
+ opaqueDst (TYPE_4BYTE_ABGR_PRE , TYPE_CUSTOM_4BYTE_ARGB_PRE );
118
+ opaqueDst (TYPE_4BYTE_ABGR_PRE , TYPE_CUSTOM_4BYTE_RGBA_PRE );
119
+ opaqueDst (TYPE_4BYTE_ABGR_PRE , TYPE_CUSTOM_4BYTE_GABR_PRE );
120
+
121
+ opaqueDst (TYPE_INT_ARGB_PRE , TYPE_CUSTOM_INT_ARGB_PRE );
122
+ opaqueDst (TYPE_INT_ARGB_PRE , TYPE_CUSTOM_INT_GABR_PRE );
123
+
124
+ // It is unclear how to handle pre colors in the opaque DST
101
125
//opaqueDst(TYPE_INT_ARGB_PRE, TYPE_4BYTE_ABGR_PRE);
102
126
//opaqueDst(TYPE_4BYTE_ABGR_PRE, TYPE_INT_BGR);
103
127
}
@@ -196,7 +220,15 @@ private static void validate(BufferedImage img1, BufferedImage img2,
196
220
}
197
221
198
222
private static BufferedImage createSrc (int type ) {
199
- BufferedImage img = new BufferedImage (WIDTH , HEIGHT , type );
223
+ BufferedImage img = switch (type ) {
224
+ case TYPE_CUSTOM_4BYTE_ABGR_PRE -> TYPE_4BYTE_ABGR_PRE ();
225
+ case TYPE_CUSTOM_4BYTE_ARGB_PRE -> TYPE_4BYTE_ARGB_PRE ();
226
+ case TYPE_CUSTOM_4BYTE_RGBA_PRE -> TYPE_4BYTE_RGBA_PRE ();
227
+ case TYPE_CUSTOM_4BYTE_GABR_PRE -> TYPE_4BYTE_GABR_PRE ();
228
+ case TYPE_CUSTOM_INT_ARGB_PRE -> TYPE_INT_ARGB_PRE ();
229
+ case TYPE_CUSTOM_INT_GABR_PRE -> TYPE_INT_GABR_PRE ();
230
+ default -> new BufferedImage (WIDTH , HEIGHT , type );
231
+ };
200
232
fill (img );
201
233
return img ;
202
234
}
@@ -220,4 +252,92 @@ private static void fill(BufferedImage image) {
220
252
}
221
253
}
222
254
}
255
+
256
+ private static BufferedImage TYPE_4BYTE_RGBA_PRE () {
257
+ ColorSpace cs = ColorSpace .getInstance (ColorSpace .CS_sRGB );
258
+ int [] nBits = {8 , 8 , 8 , 8 };
259
+ int [] bOffs = {0 , 1 , 2 , 3 };
260
+ ColorModel colorModel = new ComponentColorModel (cs , nBits , true , true ,
261
+ Transparency .TRANSLUCENT ,
262
+ DataBuffer .TYPE_BYTE );
263
+ WritableRaster raster = Raster .createInterleavedRaster (DataBuffer .TYPE_BYTE ,
264
+ WIDTH , HEIGHT ,
265
+ WIDTH * 4 , 4 ,
266
+ bOffs , null );
267
+ return new BufferedImage (colorModel , raster , true , null );
268
+ }
269
+
270
+ private static BufferedImage TYPE_4BYTE_ABGR_PRE () {
271
+ ColorSpace cs = ColorSpace .getInstance (ColorSpace .CS_sRGB );
272
+ int [] nBits = {8 , 8 , 8 , 8 };
273
+ int [] bOffs = {3 , 2 , 1 , 0 };
274
+ ColorModel colorModel = new ComponentColorModel (cs , nBits , true , true ,
275
+ Transparency .TRANSLUCENT ,
276
+ DataBuffer .TYPE_BYTE );
277
+ WritableRaster raster = Raster .createInterleavedRaster (DataBuffer .TYPE_BYTE ,
278
+ WIDTH , HEIGHT ,
279
+ WIDTH * 4 , 4 ,
280
+ bOffs , null );
281
+ return new BufferedImage (colorModel , raster , true , null );
282
+ }
283
+
284
+ private static BufferedImage TYPE_4BYTE_ARGB_PRE () {
285
+ ColorSpace cs = ColorSpace .getInstance (ColorSpace .CS_sRGB );
286
+ int [] nBits = {8 , 8 , 8 , 8 };
287
+ int [] bOffs = {1 , 2 , 3 , 0 };
288
+ ColorModel colorModel = new ComponentColorModel (cs , nBits , true , true ,
289
+ Transparency .TRANSLUCENT ,
290
+ DataBuffer .TYPE_BYTE );
291
+ WritableRaster raster = Raster .createInterleavedRaster (DataBuffer .TYPE_BYTE ,
292
+ WIDTH , HEIGHT ,
293
+ WIDTH * 4 , 4 ,
294
+ bOffs , null );
295
+ return new BufferedImage (colorModel , raster , true , null );
296
+ }
297
+
298
+ private static BufferedImage TYPE_4BYTE_GABR_PRE () {
299
+ ColorSpace cs = ColorSpace .getInstance (ColorSpace .CS_sRGB );
300
+ int [] nBits = {8 , 8 , 8 , 8 };
301
+ int [] bOffs = {3 , 0 , 2 , 1 };
302
+ ColorModel colorModel = new ComponentColorModel (cs , nBits , true , false ,
303
+ Transparency .TRANSLUCENT ,
304
+ DataBuffer .TYPE_BYTE );
305
+ WritableRaster raster = Raster .createInterleavedRaster (DataBuffer .TYPE_BYTE ,
306
+ WIDTH , HEIGHT ,
307
+ WIDTH * 4 , 4 ,
308
+ bOffs , null );
309
+ return new BufferedImage (colorModel , raster , true , null );
310
+ }
311
+
312
+ private static BufferedImage TYPE_INT_ARGB_PRE () {
313
+ ColorModel colorModel = new DirectColorModel (
314
+ ColorSpace .getInstance (ColorSpace .CS_sRGB ),
315
+ 32 ,
316
+ 0x00ff0000 , // Red
317
+ 0x0000ff00 , // Green
318
+ 0x000000ff , // Blue
319
+ 0xff000000 , // Alpha
320
+ true , // Alpha Premultiplied
321
+ DataBuffer .TYPE_INT
322
+ );
323
+ WritableRaster raster = colorModel .createCompatibleWritableRaster (WIDTH ,
324
+ HEIGHT );
325
+ return new BufferedImage (colorModel , raster , true , null );
326
+ }
327
+
328
+ private static BufferedImage TYPE_INT_GABR_PRE () {
329
+ ColorModel colorModel = new DirectColorModel (
330
+ ColorSpace .getInstance (ColorSpace .CS_sRGB ),
331
+ 32 ,
332
+ 0x000000ff , // Red
333
+ 0xff000000 , // Green
334
+ 0x0000ff00 , // Blue
335
+ 0x00ff0000 , // Alpha
336
+ true , // Alpha Premultiplied
337
+ DataBuffer .TYPE_INT
338
+ );
339
+ WritableRaster raster = colorModel .createCompatibleWritableRaster (WIDTH ,
340
+ HEIGHT );
341
+ return new BufferedImage (colorModel , raster , true , null );
342
+ }
223
343
}
0 commit comments