25
25
26
26
package sun .java2d .cmm .lcms ;
27
27
28
+ import java .awt .color .CMMException ;
28
29
import java .awt .image .BufferedImage ;
29
30
import java .awt .image .ColorModel ;
30
31
import java .awt .image .ComponentColorModel ;
37
38
38
39
final class LCMSImageLayout {
39
40
40
- public static int BYTES_SH (int x ) {
41
+ static int BYTES_SH (int x ) {
41
42
return x ;
42
43
}
43
44
44
- public static int EXTRA_SH (int x ) {
45
+ private static int EXTRA_SH (int x ) {
45
46
return x << 7 ;
46
47
}
47
48
48
- public static int CHANNELS_SH (int x ) {
49
+ static int CHANNELS_SH (int x ) {
49
50
return x << 3 ;
50
51
}
51
- public static final int SWAPFIRST = 1 << 14 ;
52
- public static final int DOSWAP = 1 << 10 ;
53
- public static final int PT_RGB_8 =
54
- CHANNELS_SH (3 ) | BYTES_SH (1 );
55
- public static final int PT_GRAY_8 =
56
- CHANNELS_SH (1 ) | BYTES_SH (1 );
57
- public static final int PT_GRAY_16 =
58
- CHANNELS_SH (1 ) | BYTES_SH (2 );
59
- public static final int PT_RGBA_8 =
60
- EXTRA_SH (1 ) | CHANNELS_SH (3 ) | BYTES_SH (1 );
61
- public static final int PT_ARGB_8 =
62
- EXTRA_SH (1 ) | CHANNELS_SH (3 ) | BYTES_SH (1 ) | SWAPFIRST ;
63
- public static final int PT_BGR_8 =
64
- DOSWAP | CHANNELS_SH (3 ) | BYTES_SH (1 );
65
- public static final int PT_ABGR_8 =
66
- DOSWAP | EXTRA_SH (1 ) | CHANNELS_SH (3 ) | BYTES_SH (1 );
67
- public static final int PT_BGRA_8 = EXTRA_SH (1 ) | CHANNELS_SH (3 )
68
- | BYTES_SH (1 ) | DOSWAP | SWAPFIRST ;
69
- public static final int DT_BYTE = 0 ;
70
- public static final int DT_SHORT = 1 ;
71
- public static final int DT_INT = 2 ;
72
- public static final int DT_DOUBLE = 3 ;
52
+ private static final int SWAPFIRST = 1 << 14 ;
53
+ private static final int DOSWAP = 1 << 10 ;
54
+ private static final int PT_GRAY_8 = CHANNELS_SH (1 ) | BYTES_SH (1 );
55
+ private static final int PT_GRAY_16 = CHANNELS_SH (1 ) | BYTES_SH (2 );
56
+ private static final int PT_RGB_8 = CHANNELS_SH (3 ) | BYTES_SH (1 );
57
+ private static final int PT_RGBA_8 = PT_RGB_8 | EXTRA_SH (1 );
58
+ private static final int PT_ARGB_8 = PT_RGBA_8 | SWAPFIRST ;
59
+ private static final int PT_BGR_8 = PT_RGB_8 | DOSWAP ;
60
+ private static final int PT_ABGR_8 = PT_BGR_8 | EXTRA_SH (1 );
61
+ // private static final int PT_BGRA_8 = PT_ABGR_8 | SWAPFIRST;
62
+
63
+ private static final int DT_BYTE = 0 ;
64
+ private static final int DT_SHORT = 1 ;
65
+ private static final int DT_INT = 2 ;
66
+ private static final int DT_DOUBLE = 3 ;
73
67
boolean isIntPacked = false ;
74
68
int pixelType ;
75
69
int dataType ;
@@ -83,9 +77,7 @@ public static int CHANNELS_SH(int x) {
83
77
84
78
private int dataArrayLength ; /* in bytes */
85
79
86
- private LCMSImageLayout (int np , int pixelType , int pixelSize )
87
- throws ImageLayoutException
88
- {
80
+ private LCMSImageLayout (int np , int pixelType , int pixelSize ) {
89
81
this .pixelType = pixelType ;
90
82
width = np ;
91
83
height = 1 ;
@@ -94,9 +86,7 @@ private LCMSImageLayout(int np, int pixelType, int pixelSize)
94
86
offset = 0 ;
95
87
}
96
88
97
- private LCMSImageLayout (int width , int height , int pixelType ,
98
- int pixelSize )
99
- throws ImageLayoutException
89
+ private LCMSImageLayout (int width , int height , int pixelType , int pixelSize )
100
90
{
101
91
this .pixelType = pixelType ;
102
92
this .width = width ;
@@ -106,10 +96,7 @@ private LCMSImageLayout(int width, int height, int pixelType,
106
96
offset = 0 ;
107
97
}
108
98
109
-
110
- public LCMSImageLayout (byte [] data , int np , int pixelType , int pixelSize )
111
- throws ImageLayoutException
112
- {
99
+ LCMSImageLayout (byte [] data , int np , int pixelType , int pixelSize ) {
113
100
this (np , pixelType , pixelSize );
114
101
dataType = DT_BYTE ;
115
102
dataArray = data ;
@@ -118,9 +105,7 @@ public LCMSImageLayout(byte[] data, int np, int pixelType, int pixelSize)
118
105
verify ();
119
106
}
120
107
121
- public LCMSImageLayout (short [] data , int np , int pixelType , int pixelSize )
122
- throws ImageLayoutException
123
- {
108
+ LCMSImageLayout (short [] data , int np , int pixelType , int pixelSize ) {
124
109
this (np , pixelType , pixelSize );
125
110
dataType = DT_SHORT ;
126
111
dataArray = data ;
@@ -129,9 +114,7 @@ public LCMSImageLayout(short[] data, int np, int pixelType, int pixelSize)
129
114
verify ();
130
115
}
131
116
132
- public LCMSImageLayout (int [] data , int np , int pixelType , int pixelSize )
133
- throws ImageLayoutException
134
- {
117
+ LCMSImageLayout (int [] data , int np , int pixelType , int pixelSize ) {
135
118
this (np , pixelType , pixelSize );
136
119
dataType = DT_INT ;
137
120
dataArray = data ;
@@ -140,9 +123,7 @@ public LCMSImageLayout(int[] data, int np, int pixelType, int pixelSize)
140
123
verify ();
141
124
}
142
125
143
- public LCMSImageLayout (double [] data , int np , int pixelType , int pixelSize )
144
- throws ImageLayoutException
145
- {
126
+ LCMSImageLayout (double [] data , int np , int pixelType , int pixelSize ) {
146
127
this (np , pixelType , pixelSize );
147
128
dataType = DT_DOUBLE ;
148
129
dataArray = data ;
@@ -157,7 +138,7 @@ private LCMSImageLayout() {
157
138
/* This method creates a layout object for given image.
158
139
* Returns null if the image is not supported by current implementation.
159
140
*/
160
- public static LCMSImageLayout createImageLayout (BufferedImage image ) throws ImageLayoutException {
141
+ static LCMSImageLayout createImageLayout (BufferedImage image ) {
161
142
LCMSImageLayout l = new LCMSImageLayout ();
162
143
163
144
switch (image .getType ()) {
@@ -288,7 +269,7 @@ private static enum BandOrder {
288
269
ARBITRARY ,
289
270
UNKNOWN ;
290
271
291
- public static BandOrder getBandOrder (int [] bandOffsets ) {
272
+ static BandOrder getBandOrder (int [] bandOffsets ) {
292
273
BandOrder order = UNKNOWN ;
293
274
294
275
int numBands = bandOffsets .length ;
@@ -320,10 +301,10 @@ public static BandOrder getBandOrder(int[] bandOffsets) {
320
301
}
321
302
}
322
303
323
- private void verify () throws ImageLayoutException {
304
+ private void verify () {
324
305
checkIndex (offset , dataArrayLength );
325
306
if (nextPixelOffset != getBytesPerPixel (pixelType )) {
326
- throw new ImageLayoutException ("Invalid image layout" );
307
+ throw new CMMException ("Invalid image layout" );
327
308
}
328
309
329
310
int lastScanOffset = safeMult (nextRowOffset , (height - 1 ));
@@ -333,27 +314,19 @@ private void verify() throws ImageLayoutException {
333
314
checkIndex (off , dataArrayLength );
334
315
}
335
316
336
- private static int checkIndex (long index , int length )
337
- throws ImageLayoutException
338
- {
317
+ private static int checkIndex (long index , int length ) {
339
318
if (index < 0 || index >= length ) {
340
- throw new ImageLayoutException ("Invalid image layout" );
319
+ throw new CMMException ("Invalid image layout" );
341
320
}
342
321
return (int ) index ;
343
322
}
344
323
345
- private static int safeMult (int a , int b ) throws ImageLayoutException {
324
+ private static int safeMult (int a , int b ) {
346
325
long res = (long ) a * b ;
347
326
return checkIndex (res , Integer .MAX_VALUE );
348
327
}
349
328
350
- @ SuppressWarnings ("serial" ) // JDK-implementation class
351
- public static class ImageLayoutException extends Exception {
352
- public ImageLayoutException (String message ) {
353
- super (message );
354
- }
355
- }
356
- public static LCMSImageLayout createImageLayout (Raster r ) {
329
+ static LCMSImageLayout createImageLayout (Raster r ) {
357
330
LCMSImageLayout l = new LCMSImageLayout ();
358
331
if (r instanceof ByteComponentRaster &&
359
332
r .getSampleModel () instanceof ComponentSampleModel ) {
0 commit comments