Skip to content

Commit b5b7948

Browse files
committed
8298240: Replace the usage of ImageLayoutException by the CMMException
Reviewed-by: prr
1 parent 99be740 commit b5b7948

File tree

2 files changed

+96
-162
lines changed

2 files changed

+96
-162
lines changed

src/java.desktop/share/classes/sun/java2d/cmm/lcms/LCMSImageLayout.java

+33-60
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
package sun.java2d.cmm.lcms;
2727

28+
import java.awt.color.CMMException;
2829
import java.awt.image.BufferedImage;
2930
import java.awt.image.ColorModel;
3031
import java.awt.image.ComponentColorModel;
@@ -37,39 +38,32 @@
3738

3839
final class LCMSImageLayout {
3940

40-
public static int BYTES_SH(int x) {
41+
static int BYTES_SH(int x) {
4142
return x;
4243
}
4344

44-
public static int EXTRA_SH(int x) {
45+
private static int EXTRA_SH(int x) {
4546
return x << 7;
4647
}
4748

48-
public static int CHANNELS_SH(int x) {
49+
static int CHANNELS_SH(int x) {
4950
return x << 3;
5051
}
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;
7367
boolean isIntPacked = false;
7468
int pixelType;
7569
int dataType;
@@ -83,9 +77,7 @@ public static int CHANNELS_SH(int x) {
8377

8478
private int dataArrayLength; /* in bytes */
8579

86-
private LCMSImageLayout(int np, int pixelType, int pixelSize)
87-
throws ImageLayoutException
88-
{
80+
private LCMSImageLayout(int np, int pixelType, int pixelSize) {
8981
this.pixelType = pixelType;
9082
width = np;
9183
height = 1;
@@ -94,9 +86,7 @@ private LCMSImageLayout(int np, int pixelType, int pixelSize)
9486
offset = 0;
9587
}
9688

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)
10090
{
10191
this.pixelType = pixelType;
10292
this.width = width;
@@ -106,10 +96,7 @@ private LCMSImageLayout(int width, int height, int pixelType,
10696
offset = 0;
10797
}
10898

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) {
113100
this(np, pixelType, pixelSize);
114101
dataType = DT_BYTE;
115102
dataArray = data;
@@ -118,9 +105,7 @@ public LCMSImageLayout(byte[] data, int np, int pixelType, int pixelSize)
118105
verify();
119106
}
120107

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) {
124109
this(np, pixelType, pixelSize);
125110
dataType = DT_SHORT;
126111
dataArray = data;
@@ -129,9 +114,7 @@ public LCMSImageLayout(short[] data, int np, int pixelType, int pixelSize)
129114
verify();
130115
}
131116

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) {
135118
this(np, pixelType, pixelSize);
136119
dataType = DT_INT;
137120
dataArray = data;
@@ -140,9 +123,7 @@ public LCMSImageLayout(int[] data, int np, int pixelType, int pixelSize)
140123
verify();
141124
}
142125

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) {
146127
this(np, pixelType, pixelSize);
147128
dataType = DT_DOUBLE;
148129
dataArray = data;
@@ -157,7 +138,7 @@ private LCMSImageLayout() {
157138
/* This method creates a layout object for given image.
158139
* Returns null if the image is not supported by current implementation.
159140
*/
160-
public static LCMSImageLayout createImageLayout(BufferedImage image) throws ImageLayoutException {
141+
static LCMSImageLayout createImageLayout(BufferedImage image) {
161142
LCMSImageLayout l = new LCMSImageLayout();
162143

163144
switch (image.getType()) {
@@ -288,7 +269,7 @@ private static enum BandOrder {
288269
ARBITRARY,
289270
UNKNOWN;
290271

291-
public static BandOrder getBandOrder(int[] bandOffsets) {
272+
static BandOrder getBandOrder(int[] bandOffsets) {
292273
BandOrder order = UNKNOWN;
293274

294275
int numBands = bandOffsets.length;
@@ -320,10 +301,10 @@ public static BandOrder getBandOrder(int[] bandOffsets) {
320301
}
321302
}
322303

323-
private void verify() throws ImageLayoutException {
304+
private void verify() {
324305
checkIndex(offset, dataArrayLength);
325306
if (nextPixelOffset != getBytesPerPixel(pixelType)) {
326-
throw new ImageLayoutException("Invalid image layout");
307+
throw new CMMException("Invalid image layout");
327308
}
328309

329310
int lastScanOffset = safeMult(nextRowOffset, (height - 1));
@@ -333,27 +314,19 @@ private void verify() throws ImageLayoutException {
333314
checkIndex(off, dataArrayLength);
334315
}
335316

336-
private static int checkIndex(long index, int length)
337-
throws ImageLayoutException
338-
{
317+
private static int checkIndex(long index, int length) {
339318
if (index < 0 || index >= length) {
340-
throw new ImageLayoutException("Invalid image layout");
319+
throw new CMMException("Invalid image layout");
341320
}
342321
return (int) index;
343322
}
344323

345-
private static int safeMult(int a, int b) throws ImageLayoutException {
324+
private static int safeMult(int a, int b) {
346325
long res = (long) a * b;
347326
return checkIndex(res, Integer.MAX_VALUE);
348327
}
349328

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) {
357330
LCMSImageLayout l = new LCMSImageLayout();
358331
if (r instanceof ByteComponentRaster &&
359332
r.getSampleModel() instanceof ComponentSampleModel) {

0 commit comments

Comments
 (0)