/hg/icedtea6: Added basic support for using JPEGCodec to encode ...

asu at icedtea.classpath.org asu at icedtea.classpath.org
Tue May 10 06:39:08 PDT 2011


changeset 8720a7df46e3 in /hg/icedtea6
details: http://icedtea.classpath.org/hg/icedtea6?cmd=changeset;node=8720a7df46e3
author: Andrew Su <asu at redhat.com>
date: Tue May 10 09:41:12 2011 -0400

	Added basic support for using JPEGCodec to encode and decode jpeg
	files.


diffstat:

 ChangeLog                                                                                        |   19 +
 Makefile.am                                                                                      |    2 +-
 overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/ImageFormatException.java   |   49 +
 overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGCodec.java              |  191 ++
 overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGDecodeParam.java        |  390 +++++
 overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGEncodeParam.java        |  307 ++++
 overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGHuffmanTable.java       |   97 +
 overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGImageDecoder.java       |  102 +
 overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGImageEncoder.java       |  208 ++
 overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGQTable.java             |  118 +
 overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/TruncatedFileException.java |   54 +
 overlays/jpeg/openjdk/jdk/src/share/classes/sun/awt/image/codec/JPEGImageDecoderImpl.java        |  103 +
 overlays/jpeg/openjdk/jdk/src/share/classes/sun/awt/image/codec/JPEGImageEncoderImpl.java        |  183 ++
 overlays/jpeg/openjdk/jdk/src/share/classes/sun/awt/image/codec/JPEGParam.java                   |  750 ++++++++++
 patches/jpegclasses.patch                                                                        |  643 --------
 15 files changed, 2572 insertions(+), 644 deletions(-)

diffs (truncated from 3300 to 500 lines):

diff -r 9f374bb0cb94 -r 8720a7df46e3 ChangeLog
--- a/ChangeLog	Fri May 06 10:59:07 2011 -0400
+++ b/ChangeLog	Tue May 10 09:41:12 2011 -0400
@@ -1,3 +1,22 @@
+2011-05-10  Andrew Su  <asu at redhat.com>
+
+	* Makefile.am:
+	(ICEDTEA_PATCHES): Removed patch jpegclasses.patch.
+	(stamps/overlay.stamp): Added jpeg class overlay path.
+	* patches/jpegclasses.patch: Removed
+	* overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/ImageFormatException.java,
+	* overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGCodec.java,
+	* overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGDecodeParam.java,
+	* overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGEncodeParam.java,
+	* overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGHuffmanTable.java,
+	* overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGImageDecoder.java,
+	* overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGImageEncoder.java,
+	* overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGQTable.java,
+	* overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/TruncatedFileException.java,
+	* overlays/jpeg/openjdk/jdk/src/share/classes/sun/awt/image/codec/JPEGImageDecoderImpl.java,
+	* overlays/jpeg/openjdk/jdk/src/share/classes/sun/awt/image/codec/JPEGImageEncoderImpl.java,
+	* overlays/jpeg/openjdk/jdk/src/share/classes/sun/awt/image/codec/JPEGParam.java: New classes.
+
 2011-05-06  Omair Majid  <omajid at redhat.com>
 
 	* Makefile.am (ICEDTEA_PATCHES): Replace
diff -r 9f374bb0cb94 -r 8720a7df46e3 Makefile.am
--- a/Makefile.am	Fri May 06 10:59:07 2011 -0400
+++ b/Makefile.am	Tue May 10 09:41:12 2011 -0400
@@ -230,7 +230,6 @@
 	patches/jvmtiEnv.patch \
 	patches/lcms.patch \
 	patches/print_lsb_release.patch \
-	patches/jpegclasses.patch \
 	patches/uname.patch \
 	patches/freetypeversion.patch \
 	patches/nomotif-6706121.patch \
@@ -1163,6 +1162,7 @@
 if ENABLE_NIO2
 	cp -r $(abs_top_srcdir)/overlays/nio2/openjdk/* openjdk/
 endif
+	cp -r $(abs_top_srcdir)/overlays/jpeg/openjdk/* openjdk/
 	touch stamps/overlay.stamp
 
 clean-overlay:
diff -r 9f374bb0cb94 -r 8720a7df46e3 overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/ImageFormatException.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/ImageFormatException.java	Tue May 10 09:41:12 2011 -0400
@@ -0,0 +1,49 @@
+/* ImageFormatException.java
+ * Copyright (C) 2007 Matthew Flaschen
+ * 
+ * This file is part of IcedTea
+ * 
+ * IcedTea is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * IcedTea is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Classpath; see the file COPYING. If not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ * 
+ * Linking this library statically or dynamically with other modules is
+ * making a combined work based on this library. Thus, the terms and
+ * conditions of the GNU General Public License cover the whole
+ * combination.
+ * 
+ * As a special exception, the copyright holders of this library give you
+ * permission to link this library with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under
+ * terms of your choice, provided that you also meet, for each linked
+ * independent module, the terms and conditions of the license of that
+ * module. An independent module is a module which is not derived from
+ * or based on this library. If you modify this library, you may extend
+ * this exception to your version of the library, but you are not
+ * obligated to do so. If you do not wish to do so, delete this
+ * exception statement from your version.
+ */
+
+package com.sun.image.codec.jpeg;
+
+public class ImageFormatException extends Exception {
+    public ImageFormatException() {
+	this("");
+    }
+
+    public ImageFormatException(String s) {
+	super(s);
+    }
+}
diff -r 9f374bb0cb94 -r 8720a7df46e3 overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGCodec.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGCodec.java	Tue May 10 09:41:12 2011 -0400
@@ -0,0 +1,191 @@
+/* JPEGCodec.java --
+ * Copyright (C) 2007 Free Software Foundation, Inc.
+ * Copyright (C) 2007 Matthew Flaschen
+ * 
+ * This file is part of GNU Classpath.
+ * 
+ * GNU Classpath is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Classpath is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Classpath; see the file COPYING. If not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ * 
+ * Linking this library statically or dynamically with other modules is
+ * making a combined work based on this library. Thus, the terms and
+ * conditions of the GNU General Public License cover the whole
+ * combination.
+ * 
+ * As a special exception, the copyright holders of this library give you
+ * permission to link this library with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under
+ * terms of your choice, provided that you also meet, for each linked
+ * independent module, the terms and conditions of the license of that
+ * module. An independent module is a module which is not derived from
+ * or based on this library. If you modify this library, you may extend
+ * this exception to your version of the library, but you are not
+ * obligated to do so. If you do not wish to do so, delete this
+ * exception statement from your version.
+ */
+
+package com.sun.image.codec.jpeg;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.awt.color.ColorSpace;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.Raster;
+
+import sun.awt.image.codec.JPEGImageDecoderImpl;
+import sun.awt.image.codec.JPEGImageEncoderImpl;
+import sun.awt.image.codec.JPEGParam;
+
+/**
+ * This class is a factory for implementations of the JPEG Image
+ * Decoder/Encoder.
+ */
+public class JPEGCodec {
+
+    /**
+     * This creates an instance of a JPEGImageDecoder that can be used to decode
+     * JPEG Data streams.
+     * 
+     * @param src
+     * @return
+     */
+    public static JPEGImageDecoder createJPEGDecoder(InputStream src) {
+	return new JPEGImageDecoderImpl(src);
+    }
+
+    /**
+     * This creates an instance of a JPEGImageDecoder that can be used to decode
+     * JPEG Data streams.
+     * 
+     * @param src
+     * @param jdp
+     * @return
+     */
+    public static JPEGImageDecoder createJPEGDecoder(InputStream src,
+	    JPEGDecodeParam jdp) {
+	return new JPEGImageDecoderImpl(src, jdp);
+    }
+
+    /**
+     * This creates an instance of a JPEGImageEncoder that can be used to encode
+     * image data as JPEG Data streams.
+     * 
+     * @param os
+     * @return
+     */
+    public static JPEGImageEncoder createJPEGEncoder(OutputStream os) {
+	return new JPEGImageEncoderImpl(os);
+    }
+
+    /**
+     * This creates an instance of a JPEGImageEncoder that can be used to encode
+     * image data as JPEG Data streams.
+     * 
+     * @param dest
+     * @param jep
+     * @return
+     */
+    public static JPEGImageEncoder createJPEGEncoder(OutputStream dest,
+	    JPEGEncodeParam jep) {
+	return new JPEGImageEncoderImpl(dest, jep);
+    }
+
+    /**
+     * This is a factory method for creating JPEGEncodeParam objects.
+     * 
+     * @param bi
+     * @return
+     */
+    public static JPEGEncodeParam getDefaultJPEGEncodeParam(BufferedImage bi) {
+	return getDefaultJPEGEncodeParam(bi.getRaster(),
+		getDefaultColorID(bi.getColorModel()));
+    }
+
+    /**
+     * This is a factory method for creating JPEGEncodeParam objects.
+     * 
+     * @param numBands
+     * @param colorID
+     * @return
+     */
+    public static JPEGEncodeParam getDefaultJPEGEncodeParam(int numBands,
+	    int colorID) {
+	return new JPEGParam(colorID, numBands);
+    }
+
+    /**
+     * This is a factory method for creating a JPEGEncodeParam from a
+     * JPEGDecodeParam.
+     * 
+     * @param jdp
+     * @return
+     */
+    public static JPEGEncodeParam getDefaultJPEGEncodeParam(JPEGDecodeParam jdp) {
+	return new JPEGParam(jdp);
+    }
+
+    /**
+     * This is a factory method for creating JPEGEncodeParam objects.
+     * 
+     * @param ras
+     * @param colorID
+     * @return
+     */
+    public static JPEGEncodeParam getDefaultJPEGEncodeParam(Raster ras,
+	    int colorID) {
+	return getDefaultJPEGEncodeParam(ras.getNumBands(), colorID);
+    }
+
+    private static int getDefaultColorID(ColorModel cm) {
+	ColorSpace cs = cm.getColorSpace();
+	int type = cs.getType();
+	int id = -1;
+	switch (type) {
+	    case ColorSpace.TYPE_GRAY:
+		id = JPEGEncodeParam.COLOR_ID_GRAY;
+		break;
+
+	    case ColorSpace.TYPE_RGB:
+		id = cm.hasAlpha() ? JPEGEncodeParam.COLOR_ID_RGBA
+			: JPEGEncodeParam.COLOR_ID_RGB;
+
+	    case ColorSpace.TYPE_YCbCr:
+		try {
+		    if (cs == ColorSpace.getInstance(ColorSpace.CS_PYCC)) {
+			id = cm.hasAlpha() ? JPEGEncodeParam.COLOR_ID_PYCCA
+				: JPEGEncodeParam.COLOR_ID_PYCC;
+		    }
+		} catch (IllegalArgumentException e) {
+		    /* We know it isn't PYCC type, nothing to handle */
+		}
+		if (id == -1) {
+		    id = cm.hasAlpha() ? JPEGEncodeParam.COLOR_ID_YCbCrA
+			    : JPEGEncodeParam.COLOR_ID_YCbCr;
+		}
+		break;
+
+	    case ColorSpace.TYPE_CMYK:
+		id = JPEGEncodeParam.COLOR_ID_CMYK;
+		break;
+
+	    default:
+		id = JPEGEncodeParam.COLOR_ID_UNKNOWN;
+	}
+
+	return id;
+    }
+}
diff -r 9f374bb0cb94 -r 8720a7df46e3 overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGDecodeParam.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGDecodeParam.java	Tue May 10 09:41:12 2011 -0400
@@ -0,0 +1,390 @@
+/* JPEGImageDecoder.java --
+ * Copyright (C) 2007 Free Software Foundation, Inc.
+ * Copyright (C) 2007 Matthew Flaschen
+ * 
+ * This file is part of GNU Classpath.
+ * 
+ * GNU Classpath is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Classpath is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Classpath; see the file COPYING. If not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ * 
+ * Linking this library statically or dynamically with other modules is
+ * making a combined work based on this library. Thus, the terms and
+ * conditions of the GNU General Public License cover the whole
+ * combination.
+ * 
+ * As a special exception, the copyright holders of this library give you
+ * permission to link this library with independent modules to produce an
+ * executable, regardless of the license terms of these independent
+ * modules, and to copy and distribute the resulting executable under
+ * terms of your choice, provided that you also meet, for each linked
+ * independent module, the terms and conditions of the license of that
+ * module. An independent module is a module which is not derived from
+ * or based on this library. If you modify this library, you may extend
+ * this exception to your version of the library, but you are not
+ * obligated to do so. If you do not wish to do so, delete this
+ * exception statement from your version.
+ */
+
+package com.sun.image.codec.jpeg;
+
+/**
+ * <p>
+ * JPEGDecodeParam encapsulates tables and options necessary to control decoding
+ * JPEG data streams. Parameters are either set explicitly by the application
+ * for encoding, or read from the JPEG header for decoding. In the case of
+ * decoding abbreviated data streams the application may need to set some/all of
+ * the values it's self.
+ * </p>
+ * <p>
+ * When working with BufferedImages (@see JPEGImageDecoder.decodeBufferedImage),
+ * the codec will attempt to generate an appropriate ColorModel for the JPEG
+ * COLOR_ID. This is not always possible (example mappings are listed below) .
+ * In cases where unsupported conversions are required, or unknown encoded
+ * COLOR_ID's are in use, the user must request the data as a Raster and perform
+ * the transformations themselves. When decoding into a raster (@see
+ * JPEGImageDecoder.decodeRaster) no ColorSpace adjustments are made. Note: The
+ * color ids described herein are simply enumerated values that influence data
+ * processing by the JPEG codec. JPEG compression is by definition color blind.
+ * These values are used as hints when decompressing JPEG data. Of particular
+ * interest is the default conversion from YCbCr to sRGB when decoding buffered
+ * Images.
+ * </p>
+ * <p>
+ * Note: because JPEG is mostly color-blind color fidelity can not be
+ * guaranteed. This will hopefully be rectified in the near future by the wide
+ * spread inclusion of ICC-profiles in the JPEG data stream (as a special
+ * marker). The following is an example of the conversions that take place. This
+ * is only a guide to the types of conversions that are allowed. This list is
+ * likely to change in the future so it is strongly recommended that you check
+ * for thrown ImageFormatExceptions and check the actual ColorModel associated
+ * with the BufferedImage returned rather than make assumptions.
+ * </p>
+ * DECODING:
+ * 
+ * <pre>
+ * JPEG (Encoded) Color ID   BufferedImage ColorSpace 
+ * =======================   ======================== 
+ * COLOR_ID_UNKNOWN          ** Invalid ** 
+ * COLOR_ID_GRAY             CS_GRAY
+ * COLOR_ID_RGB              CS_sRGB 
+ * COLOR_ID_YCbCr            CS_sRGB 
+ * COLOR_ID_CMYK             ** Invalid **
+ * COLOR_ID_PYCC             CS_PYCC 
+ * COLOR_ID_RGBA             CS_sRGB (w/ alpha) 
+ * COLOR_ID_YCbCrA           CS_sRGB (w/ alpha) 
+ * COLOR_ID_RGBA_INVERTED    ** Invalid **
+ * COLOR_ID_YCbCrA_INVERTED  ** Invalid ** 
+ * COLOR_ID_PYCCA            CS_PYCC (w/ alpha)
+ * COLOR_ID_YCCK             ** Invalid **
+ * </pre>
+ * <p>
+ * If the user needs better control over conversion, the user must request the
+ * data as a Raster and handle the conversion of the image data themselves. When
+ * decoding JFIF files the encoded COLOR_ID will always be one of:
+ * COLOR_ID_UNKNOWN, COLOR_ID_GRAY, COLOR_ID_RGB, COLOR_ID_YCbCr, COLOR_ID_CMYK,
+ * or COLOR_ID_YCCK
+ * </p>
+ * <p>
+ * Note that the classes in the com.sun.image.codec.jpeg package are not part of
+ * the core Java APIs. They are a part of Sun's JDK and JRE distributions.
+ * Although other licensees may choose to distribute these classes, developers
+ * cannot depend on their availability in non-Sun implementations. We expect
+ * that equivalent functionality will eventually be available in a core API or
+ * standard extension.
+ * </p>
+ */
+public interface JPEGDecodeParam extends Cloneable {
+
+    /** APP0 marker - JFIF info */
+    public static final int APP0_MARKER = 0xE0;
+    /** APP1 marker */
+    public static final int APP1_MARKER = 0xE1;
+    /** APP2 marker */
+    public static final int APP2_MARKER = 0xE2;
+    /** APP3 marker */
+    public static final int APP3_MARKER = 0xE3;
+    /** APP4 marker */
+    public static final int APP4_MARKER = 0xE4;
+    /** APP5 marker */
+    public static final int APP5_MARKER = 0xE5;
+    /** APP6 marker */
+    public static final int APP6_MARKER = 0xE6;
+    /** APP7 marker */
+    public static final int APP7_MARKER = 0xE7;
+    /** APP8 marker */
+    public static final int APP8_MARKER = 0xE8;
+    /** APP9 marker */
+    public static final int APP9_MARKER = 0xE9;
+    /** APPA marker */
+    public static final int APPA_MARKER = 0xEA;
+    /** APPB marker */
+    public static final int APPB_MARKER = 0xEB;
+    /** APPC marker */
+    public static final int APPC_MARKER = 0xEC;
+    /** APPD marker */
+    public static final int APPD_MARKER = 0xED;
+    /** APPE marker - Adobe info */
+    public static final int APPE_MARKER = 0xEE;
+    /** APPF marker */
+    public static final int APPF_MARKER = 0xEF;
+    /** Adobe marker indicates presence/need for Adobe marker. */
+    public static final int COMMENT_MARKER = 0XFE;
+
+    /* Color ID values */
+    public static final int COLOR_ID_UNKNOWN = 0;
+    public static final int COLOR_ID_GRAY = 1;
+    public static final int COLOR_ID_RGB = 2;
+    public static final int COLOR_ID_YCbCr = 3;
+    public static final int COLOR_ID_CMYK = 4;
+    public static final int COLOR_ID_PYCC = 5;
+    public static final int COLOR_ID_RGBA = 6;
+    public static final int COLOR_ID_YCbCrA = 7;
+    public static final int COLOR_ID_RGBA_INVERTED = 8;
+    public static final int COLOR_ID_YCbCrA_INVERTED = 9;
+    public static final int COLOR_ID_PYCCA = 10;
+    public static final int COLOR_ID_YCCK = 11;
+    public static final int NUM_COLOR_ID = 12;
+
+    /** Number of allowed Huffman and Quantization Tables */
+    public static final int NUM_TABLES = 4;
+
+    /** The X and Y units simply indicate the aspect ratio of the pixels. */
+    public static final int DENSITY_UNIT_ASPECT_RATIO = 0;
+    /** Pixel density is in pixels per inch. */
+    public static final int DENSITY_UNIT_DOTS_INCH = 1;
+    /** Pixel density is in pixels per centimeter. */
+    public static final int DENSITY_UNIT_DOTS_CM = 2;
+    /** The max known value for DENSITY_UNIT */
+    public static final int NUM_DENSITY_UNIT = 3;
+
+    public Object clone();
+
+    /**
+     * Get the image width.
+     * 
+     * @return int the width of the image data in pixels.
+     */
+    public int getWidth();
+
+    /**
+     * Get the image height.
+     * 
+     * @return The height of the image data in pixels.
+     */
+    public int getHeight();
+
+    /**
+     * Return the Horizontal subsampling factor for requested Component. The
+     * Subsample factor is the number of input pixels that contribute to each
+     * output pixel. This is distinct from the way the JPEG to each output
+     * pixel. This is distinct from the way the JPEG standard defines this
+     * quantity, because fractional subsampling factors are not allowed.
+     * 
+     * @param component
+     *            The component of the encoded image to return the subsampling
+     *            factor for.
+     * @return The subsample factor.
+     */
+    public int getHorizontalSubsampling(int component);
+
+    /**
+     * Return the Vertical subsampling factor for requested Component. The



More information about the distro-pkg-dev mailing list