6631559: Registration of ImageIO plugins should not cause loading of jpeg.dlli and cmm.dll

Reviewed-by: igor, prr
This commit is contained in:
Andrew Brygin 2009-01-29 13:19:34 +03:00
parent 55076b2558
commit 2a2bbe2879
8 changed files with 167 additions and 186 deletions

View File

@ -1003,7 +1003,7 @@ class JFIFMarkerSegment extends MarkerSegment {
3, 3,
new int [] {0, 1, 2}, new int [] {0, 1, 2},
null); null);
ColorModel cm = new ComponentColorModel(JPEG.sRGB, ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB,
false, false,
false, false,
ColorModel.OPAQUE, ColorModel.OPAQUE,

View File

@ -208,15 +208,24 @@ public class JPEG {
public static final int [] bOffsRGB = { 2, 1, 0 }; public static final int [] bOffsRGB = { 2, 1, 0 };
protected static final ColorSpace sRGB = /* These are kept in the inner class to avoid static initialization
* of the CMM class until someone actually needs it.
* (e.g. do not init CMM on the request for jpeg mime types)
*/
public static class JCS {
public static final ColorSpace sRGB =
ColorSpace.getInstance(ColorSpace.CS_sRGB); ColorSpace.getInstance(ColorSpace.CS_sRGB);
protected static ColorSpace YCC = null; // Can't be final public static final ColorSpace YCC;
static { static {
ColorSpace cs = null;
try { try {
YCC = ColorSpace.getInstance(ColorSpace.CS_PYCC); cs = ColorSpace.getInstance(ColorSpace.CS_PYCC);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// PYCC.pf may not always be installed // PYCC.pf may not always be installed
} finally {
YCC = cs;
}
} }
} }

View File

@ -228,31 +228,31 @@ public class JPEGImageReader extends ImageReader {
(BufferedImage.TYPE_BYTE_GRAY); (BufferedImage.TYPE_BYTE_GRAY);
defaultTypes[JPEG.JCS_RGB] = defaultTypes[JPEG.JCS_RGB] =
ImageTypeSpecifier.createInterleaved ImageTypeSpecifier.createInterleaved
(JPEG.sRGB, (JPEG.JCS.sRGB,
JPEG.bOffsRGB, JPEG.bOffsRGB,
DataBuffer.TYPE_BYTE, DataBuffer.TYPE_BYTE,
false, false,
false); false);
defaultTypes[JPEG.JCS_RGBA] = defaultTypes[JPEG.JCS_RGBA] =
ImageTypeSpecifier.createPacked ImageTypeSpecifier.createPacked
(JPEG.sRGB, (JPEG.JCS.sRGB,
0xff000000, 0xff000000,
0x00ff0000, 0x00ff0000,
0x0000ff00, 0x0000ff00,
0x000000ff, 0x000000ff,
DataBuffer.TYPE_INT, DataBuffer.TYPE_INT,
false); false);
if (JPEG.YCC != null) { if (JPEG.JCS.YCC != null) {
defaultTypes[JPEG.JCS_YCC] = defaultTypes[JPEG.JCS_YCC] =
ImageTypeSpecifier.createInterleaved ImageTypeSpecifier.createInterleaved
(JPEG.YCC, (JPEG.JCS.YCC,
JPEG.bandOffsets[2], JPEG.bandOffsets[2],
DataBuffer.TYPE_BYTE, DataBuffer.TYPE_BYTE,
false, false,
false); false);
defaultTypes[JPEG.JCS_YCCA] = defaultTypes[JPEG.JCS_YCCA] =
ImageTypeSpecifier.createInterleaved ImageTypeSpecifier.createInterleaved
(JPEG.YCC, (JPEG.JCS.YCC,
JPEG.bandOffsets[3], JPEG.bandOffsets[3],
DataBuffer.TYPE_BYTE, DataBuffer.TYPE_BYTE,
true, true,
@ -774,7 +774,7 @@ public class JPEGImageReader extends ImageReader {
case JPEG.JCS_RGB: case JPEG.JCS_RGB:
list.add(raw); list.add(raw);
list.add(getImageType(JPEG.JCS_GRAYSCALE)); list.add(getImageType(JPEG.JCS_GRAYSCALE));
if (JPEG.YCC != null) { if (JPEG.JCS.YCC != null) {
list.add(getImageType(JPEG.JCS_YCC)); list.add(getImageType(JPEG.JCS_YCC));
} }
break; break;
@ -811,7 +811,7 @@ public class JPEGImageReader extends ImageReader {
} }
list.add(getImageType(JPEG.JCS_GRAYSCALE)); list.add(getImageType(JPEG.JCS_GRAYSCALE));
if (JPEG.YCC != null) { // Might be null if PYCC.pf not installed if (JPEG.JCS.YCC != null) { // Might be null if PYCC.pf not installed
list.add(getImageType(JPEG.JCS_YCC)); list.add(getImageType(JPEG.JCS_YCC));
} }
break; break;
@ -893,7 +893,7 @@ public class JPEGImageReader extends ImageReader {
(!cs.isCS_sRGB()) && (!cs.isCS_sRGB()) &&
(cm.getNumComponents() == numComponents)) { (cm.getNumComponents() == numComponents)) {
// Target isn't sRGB, so convert from sRGB to the target // Target isn't sRGB, so convert from sRGB to the target
convert = new ColorConvertOp(JPEG.sRGB, cs, null); convert = new ColorConvertOp(JPEG.JCS.sRGB, cs, null);
} else if (csType != ColorSpace.TYPE_RGB) { } else if (csType != ColorSpace.TYPE_RGB) {
throw new IIOException("Incompatible color conversion"); throw new IIOException("Incompatible color conversion");
} }
@ -906,18 +906,18 @@ public class JPEGImageReader extends ImageReader {
} }
break; break;
case JPEG.JCS_YCC: case JPEG.JCS_YCC:
if (JPEG.YCC == null) { // We can't do YCC at all if (JPEG.JCS.YCC == null) { // We can't do YCC at all
throw new IIOException("Incompatible color conversion"); throw new IIOException("Incompatible color conversion");
} }
if ((cs != JPEG.YCC) && if ((cs != JPEG.JCS.YCC) &&
(cm.getNumComponents() == numComponents)) { (cm.getNumComponents() == numComponents)) {
convert = new ColorConvertOp(JPEG.YCC, cs, null); convert = new ColorConvertOp(JPEG.JCS.YCC, cs, null);
} }
break; break;
case JPEG.JCS_YCCA: case JPEG.JCS_YCCA:
// No conversions available; image must be YCCA // No conversions available; image must be YCCA
if ((JPEG.YCC == null) || // We can't do YCC at all if ((JPEG.JCS.YCC == null) || // We can't do YCC at all
(cs != JPEG.YCC) || (cs != JPEG.JCS.YCC) ||
(cm.getNumComponents() != numComponents)) { (cm.getNumComponents() != numComponents)) {
throw new IIOException("Incompatible color conversion"); throw new IIOException("Incompatible color conversion");
} }

View File

@ -39,8 +39,6 @@ public class JPEGImageReaderSpi extends ImageReaderSpi {
private static String [] writerSpiNames = private static String [] writerSpiNames =
{"com.sun.imageio.plugins.jpeg.JPEGImageWriterSpi"}; {"com.sun.imageio.plugins.jpeg.JPEGImageWriterSpi"};
private boolean registered = false;
public JPEGImageReaderSpi() { public JPEGImageReaderSpi() {
super(JPEG.vendor, super(JPEG.vendor,
JPEG.version, JPEG.version,
@ -61,26 +59,6 @@ public class JPEGImageReaderSpi extends ImageReaderSpi {
); );
} }
public void onRegistration(ServiceRegistry registry,
Class<?> category) {
if (registered) {
return;
}
try {
java.security.AccessController.doPrivileged(
new sun.security.action.LoadLibraryAction("jpeg"));
// Stuff it all into one lib for first pass
//java.security.AccessController.doPrivileged(
//new sun.security.action.LoadLibraryAction("imageioIJG"));
} catch (Throwable e) { // Fail on any Throwable
// if it can't be loaded, deregister and return
registry.deregisterServiceProvider(this);
return;
}
registered = true;
}
public String getDescription(Locale locale) { public String getDescription(Locale locale) {
return "Standard JPEG Image Reader"; return "Standard JPEG Image Reader";
} }

View File

@ -812,13 +812,13 @@ public class JPEGImageWriter extends ImageWriter {
} }
break; break;
case ColorSpace.TYPE_3CLR: case ColorSpace.TYPE_3CLR:
if (cs == JPEG.YCC) { if (cs == JPEG.JCS.YCC) {
if (!alpha) { if (!alpha) {
if (jfif != null) { if (jfif != null) {
convertTosRGB = true; convertTosRGB = true;
convertOp = convertOp =
new ColorConvertOp(cs, new ColorConvertOp(cs,
JPEG.sRGB, JPEG.JCS.sRGB,
null); null);
outCsType = JPEG.JCS_YCbCr; outCsType = JPEG.JCS_YCbCr;
} else if (adobe != null) { } else if (adobe != null) {
@ -1494,7 +1494,7 @@ public class JPEGImageWriter extends ImageWriter {
} }
break; break;
case ColorSpace.TYPE_3CLR: case ColorSpace.TYPE_3CLR:
if (cs == JPEG.YCC) { if (cs == JPEG.JCS.YCC) {
if (alpha) { if (alpha) {
retval = JPEG.JCS_YCCA; retval = JPEG.JCS_YCCA;
} else { } else {
@ -1533,7 +1533,7 @@ public class JPEGImageWriter extends ImageWriter {
} }
break; break;
case ColorSpace.TYPE_3CLR: case ColorSpace.TYPE_3CLR:
if (cs == JPEG.YCC) { if (cs == JPEG.JCS.YCC) {
if (alpha) { if (alpha) {
retval = JPEG.JCS_YCCA; retval = JPEG.JCS_YCCA;
} else { } else {
@ -1579,7 +1579,7 @@ public class JPEGImageWriter extends ImageWriter {
} }
break; break;
case ColorSpace.TYPE_3CLR: case ColorSpace.TYPE_3CLR:
if (cs == JPEG.YCC) { if (cs == JPEG.JCS.YCC) {
if (alpha) { if (alpha) {
retval = JPEG.JCS_YCCA; retval = JPEG.JCS_YCCA;
} else { } else {

View File

@ -42,8 +42,6 @@ public class JPEGImageWriterSpi extends ImageWriterSpi {
private static String [] readerSpiNames = private static String [] readerSpiNames =
{"com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi"}; {"com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi"};
private boolean registered = false;
public JPEGImageWriterSpi() { public JPEGImageWriterSpi() {
super(JPEG.vendor, super(JPEG.vendor,
JPEG.version, JPEG.version,
@ -68,23 +66,6 @@ public class JPEGImageWriterSpi extends ImageWriterSpi {
return "Standard JPEG Image Writer"; return "Standard JPEG Image Writer";
} }
public void onRegistration(ServiceRegistry registry,
Class<?> category) {
if (registered) {
return;
}
try {
java.security.AccessController.doPrivileged(
new sun.security.action.LoadLibraryAction("jpeg"));
} catch (Throwable e) { // Fail on any Throwable
// if it can't be loaded, deregister and return
registry.deregisterServiceProvider(this);
return;
}
registered = true;
}
public boolean isFormatLossless() { public boolean isFormatLossless() {
return false; return false;
} }

View File

@ -490,7 +490,7 @@ public class JPEGMetadata extends IIOMetadata implements Cloneable {
} }
break; break;
case ColorSpace.TYPE_3CLR: case ColorSpace.TYPE_3CLR:
if (cs == JPEG.YCC) { if (cs == JPEG.JCS.YCC) {
wantJFIF = false; wantJFIF = false;
componentIDs[0] = (byte) 'Y'; componentIDs[0] = (byte) 'Y';
componentIDs[1] = (byte) 'C'; componentIDs[1] = (byte) 'C';

View File

@ -67,126 +67,13 @@ public class ImageTypeSpecifier {
* <code>BufferedImage</code> types. * <code>BufferedImage</code> types.
*/ */
private static ImageTypeSpecifier[] BISpecifier; private static ImageTypeSpecifier[] BISpecifier;
private static ColorSpace sRGB;
// Initialize the standard specifiers // Initialize the standard specifiers
static { static {
ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB); sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
BISpecifier = BISpecifier =
new ImageTypeSpecifier[BufferedImage.TYPE_BYTE_INDEXED + 1]; new ImageTypeSpecifier[BufferedImage.TYPE_BYTE_INDEXED + 1];
BISpecifier[BufferedImage.TYPE_CUSTOM] = null;
BISpecifier[BufferedImage.TYPE_INT_RGB] =
createPacked(sRGB,
0x00ff0000,
0x0000ff00,
0x000000ff,
0x0,
DataBuffer.TYPE_INT,
false);
BISpecifier[BufferedImage.TYPE_INT_ARGB] =
createPacked(sRGB,
0x00ff0000,
0x0000ff00,
0x000000ff,
0xff000000,
DataBuffer.TYPE_INT,
false);
BISpecifier[BufferedImage.TYPE_INT_ARGB_PRE] =
createPacked(sRGB,
0x00ff0000,
0x0000ff00,
0x000000ff,
0xff000000,
DataBuffer.TYPE_INT,
true);
BISpecifier[BufferedImage.TYPE_INT_BGR] =
createPacked(sRGB,
0x000000ff,
0x0000ff00,
0x00ff0000,
0x0,
DataBuffer.TYPE_INT,
false);
int[] bOffsRGB = { 2, 1, 0 };
BISpecifier[BufferedImage.TYPE_3BYTE_BGR] =
createInterleaved(sRGB,
bOffsRGB,
DataBuffer.TYPE_BYTE,
false,
false);
int[] bOffsABGR = { 3, 2, 1, 0 };
BISpecifier[BufferedImage.TYPE_4BYTE_ABGR] =
createInterleaved(sRGB,
bOffsABGR,
DataBuffer.TYPE_BYTE,
true,
false);
BISpecifier[BufferedImage.TYPE_4BYTE_ABGR_PRE] =
createInterleaved(sRGB,
bOffsABGR,
DataBuffer.TYPE_BYTE,
true,
true);
BISpecifier[BufferedImage.TYPE_USHORT_565_RGB] =
createPacked(sRGB,
0xF800,
0x07E0,
0x001F,
0x0,
DataBuffer.TYPE_USHORT,
false);
BISpecifier[BufferedImage.TYPE_USHORT_555_RGB] =
createPacked(sRGB,
0x7C00,
0x03E0,
0x001F,
0x0,
DataBuffer.TYPE_USHORT,
false);
BISpecifier[BufferedImage.TYPE_BYTE_GRAY] =
createGrayscale(8,
DataBuffer.TYPE_BYTE,
false);
BISpecifier[BufferedImage.TYPE_USHORT_GRAY] =
createGrayscale(16,
DataBuffer.TYPE_USHORT,
false);
BISpecifier[BufferedImage.TYPE_BYTE_BINARY] =
createGrayscale(1,
DataBuffer.TYPE_BYTE,
false);
BufferedImage bi =
new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_INDEXED);
IndexColorModel icm = (IndexColorModel)bi.getColorModel();
int mapSize = icm.getMapSize();
byte[] redLUT = new byte[mapSize];
byte[] greenLUT = new byte[mapSize];
byte[] blueLUT = new byte[mapSize];
byte[] alphaLUT = new byte[mapSize];
icm.getReds(redLUT);
icm.getGreens(greenLUT);
icm.getBlues(blueLUT);
icm.getAlphas(alphaLUT);
BISpecifier[BufferedImage.TYPE_BYTE_INDEXED] =
createIndexed(redLUT, greenLUT, blueLUT, alphaLUT,
8,
DataBuffer.TYPE_BYTE);
} }
/** /**
@ -1011,7 +898,7 @@ public class ImageTypeSpecifier {
ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) { ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) {
if (bufferedImageType >= BufferedImage.TYPE_INT_RGB && if (bufferedImageType >= BufferedImage.TYPE_INT_RGB &&
bufferedImageType <= BufferedImage.TYPE_BYTE_INDEXED) { bufferedImageType <= BufferedImage.TYPE_BYTE_INDEXED) {
return BISpecifier[bufferedImageType]; return getSpecifier(bufferedImageType);
} else if (bufferedImageType == BufferedImage.TYPE_CUSTOM) { } else if (bufferedImageType == BufferedImage.TYPE_CUSTOM) {
throw new IllegalArgumentException("Cannot create from TYPE_CUSTOM!"); throw new IllegalArgumentException("Cannot create from TYPE_CUSTOM!");
} else { } else {
@ -1041,7 +928,7 @@ public class ImageTypeSpecifier {
if (image instanceof BufferedImage) { if (image instanceof BufferedImage) {
int bufferedImageType = ((BufferedImage)image).getType(); int bufferedImageType = ((BufferedImage)image).getType();
if (bufferedImageType != BufferedImage.TYPE_CUSTOM) { if (bufferedImageType != BufferedImage.TYPE_CUSTOM) {
return BISpecifier[bufferedImageType]; return getSpecifier(bufferedImageType);
} }
} }
@ -1225,4 +1112,130 @@ public class ImageTypeSpecifier {
public int hashCode() { public int hashCode() {
return (9 * colorModel.hashCode()) + (14 * sampleModel.hashCode()); return (9 * colorModel.hashCode()) + (14 * sampleModel.hashCode());
} }
private static ImageTypeSpecifier getSpecifier(int type) {
if (BISpecifier[type] == null) {
BISpecifier[type] = createSpecifier(type);
}
return BISpecifier[type];
}
private static ImageTypeSpecifier createSpecifier(int type) {
switch(type) {
case BufferedImage.TYPE_INT_RGB:
return createPacked(sRGB,
0x00ff0000,
0x0000ff00,
0x000000ff,
0x0,
DataBuffer.TYPE_INT,
false);
case BufferedImage.TYPE_INT_ARGB:
return createPacked(sRGB,
0x00ff0000,
0x0000ff00,
0x000000ff,
0xff000000,
DataBuffer.TYPE_INT,
false);
case BufferedImage.TYPE_INT_ARGB_PRE:
return createPacked(sRGB,
0x00ff0000,
0x0000ff00,
0x000000ff,
0xff000000,
DataBuffer.TYPE_INT,
true);
case BufferedImage.TYPE_INT_BGR:
return createPacked(sRGB,
0x000000ff,
0x0000ff00,
0x00ff0000,
0x0,
DataBuffer.TYPE_INT,
false);
case BufferedImage.TYPE_3BYTE_BGR:
return createInterleaved(sRGB,
new int[] { 2, 1, 0 },
DataBuffer.TYPE_BYTE,
false,
false);
case BufferedImage.TYPE_4BYTE_ABGR:
return createInterleaved(sRGB,
new int[] { 3, 2, 1, 0 },
DataBuffer.TYPE_BYTE,
true,
false);
case BufferedImage.TYPE_4BYTE_ABGR_PRE:
return createInterleaved(sRGB,
new int[] { 3, 2, 1, 0 },
DataBuffer.TYPE_BYTE,
true,
true);
case BufferedImage.TYPE_USHORT_565_RGB:
return createPacked(sRGB,
0xF800,
0x07E0,
0x001F,
0x0,
DataBuffer.TYPE_USHORT,
false);
case BufferedImage.TYPE_USHORT_555_RGB:
return createPacked(sRGB,
0x7C00,
0x03E0,
0x001F,
0x0,
DataBuffer.TYPE_USHORT,
false);
case BufferedImage.TYPE_BYTE_GRAY:
return createGrayscale(8,
DataBuffer.TYPE_BYTE,
false);
case BufferedImage.TYPE_USHORT_GRAY:
return createGrayscale(16,
DataBuffer.TYPE_USHORT,
false);
case BufferedImage.TYPE_BYTE_BINARY:
return createGrayscale(1,
DataBuffer.TYPE_BYTE,
false);
case BufferedImage.TYPE_BYTE_INDEXED:
{
BufferedImage bi =
new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_INDEXED);
IndexColorModel icm = (IndexColorModel)bi.getColorModel();
int mapSize = icm.getMapSize();
byte[] redLUT = new byte[mapSize];
byte[] greenLUT = new byte[mapSize];
byte[] blueLUT = new byte[mapSize];
byte[] alphaLUT = new byte[mapSize];
icm.getReds(redLUT);
icm.getGreens(greenLUT);
icm.getBlues(blueLUT);
icm.getAlphas(alphaLUT);
return createIndexed(redLUT, greenLUT, blueLUT, alphaLUT,
8,
DataBuffer.TYPE_BYTE);
}
default:
throw new IllegalArgumentException("Invalid BufferedImage type!");
}
}
} }