Revision: 3973
http://openutils.svn.sourceforge.net/openutils/?rev=3973&view=rev
Author: fgiust
Date: 2012-05-06 14:35:22 +0000 (Sun, 06 May 2012)
Log Message:
-----------
MEDIA-285 remove usage of com.sun.image.codec.jpeg.JPEGCodec
Modified Paths:
--------------
magnoliamodules/branches/magnolia44/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/JpegUtils.java
Modified: magnoliamodules/branches/magnolia44/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/JpegUtils.java
===================================================================
--- magnoliamodules/branches/magnolia44/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/JpegUtils.java 2012-05-06 14:21:17 UTC (rev 3972)
+++ magnoliamodules/branches/magnolia44/openutils-mgnlmedia/src/main/java/net/sourceforge/openutils/mgnlmedia/media/utils/JpegUtils.java 2012-05-06 14:35:22 UTC (rev 3973)
@@ -32,6 +32,8 @@
import java.awt.image.WritableRaster;
import java.io.IOException;
import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.Iterator;
import javax.imageio.ImageIO;
@@ -220,13 +222,40 @@
try
{
// see MEDIA-72, we need the sun codec to make this work properly
- return com.sun.image.codec.jpeg.JPEGCodec.createJPEGDecoder(is4).decodeAsBufferedImage();
+
+ Class< ? > sunjpegcodec = Class.forName("com.sun.image.codec.jpeg.JPEGCodec");
+ Method createJPEGDecoderMethod = sunjpegcodec.getMethod("createJPEGDecoder", InputStream.class);
+ Object jpegDecoder = createJPEGDecoderMethod.invoke(null, is4);
+ Method decodeAsBufferedImageMethod = jpegDecoder.getClass().getMethod(
+ "decodeAsBufferedImage",
+ new Class[0]);
+ BufferedImage result = (BufferedImage) decodeAsBufferedImageMethod.invoke(jpegDecoder, null);
+
+ return result;
}
- catch (RuntimeException ife)
+ catch (ClassNotFoundException e)
{
- // Icom.sun.image.codec,jpeg.ImageFormatException: Can't construct a BufferedImage for given COLOR_ID try also with CMYK?
+ log.info("com.sun.image.codec.jpeg.JPEGCodec not available, can't process non-standard jpeg");
return createJPEG4(raster, ycckProfile);
}
+ catch (NoSuchMethodException e)
+ {
+ log.info("com.sun.image.codec.jpeg.JPEGCodec not available, can't process non-standard jpeg");
+ return createJPEG4(raster, ycckProfile);
+ }
+ catch (IllegalAccessException e)
+ {
+ // should never happen
+ log.error(e.getMessage(), e);
+ return createJPEG4(raster, ycckProfile);
+ }
+ catch (InvocationTargetException e)
+ {
+ log.debug(e.getTargetException().getMessage(), e.getTargetException());
+ // Icom.sun.image.codec,jpeg.ImageFormatException: Can't construct a BufferedImage for given
+ // COLOR_ID try also with CMYK?
+ return createJPEG4(raster, ycckProfile);
+ }
finally
{
IOUtils.closeQuietly(is4);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|