Mercurial > hg > release > icedtea6-1.11
changeset 2632:bfbd7ccaa20c
Normalise whitespace in JPEG code.
2011-07-06 Andrew John Hughes <ahughes@redhat.com>
* 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:
Normalise whitespace using Oracle normaliser.
line wrap: on
line diff
--- a/ChangeLog Fri Jul 01 14:41:45 2011 +0200 +++ b/ChangeLog Wed Jul 06 20:55:06 2011 +0100 @@ -1,3 +1,19 @@ +2011-07-06 Andrew John Hughes <ahughes@redhat.com> + + * 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: + Normalise whitespace using Oracle normaliser. + 2011-07-01 Pavel Tisnovsky <ptisnovs@redhat.com> * Makefile.am: added new patches
--- a/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/ImageFormatException.java Fri Jul 01 14:41:45 2011 +0200 +++ b/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/ImageFormatException.java Wed Jul 06 20:55:06 2011 +0100 @@ -1,28 +1,28 @@ /* 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 @@ -40,10 +40,10 @@ public class ImageFormatException extends Exception { public ImageFormatException() { - this(""); + this(""); } public ImageFormatException(String s) { - super(s); + super(s); } }
--- a/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGCodec.java Fri Jul 01 14:41:45 2011 +0200 +++ b/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGCodec.java Wed Jul 06 20:55:06 2011 +0100 @@ -1,29 +1,29 @@ /* 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 @@ -59,133 +59,133 @@ /** * 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); + 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); + 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); + 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); + 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())); + 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); + 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); + 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); + 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; + 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_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_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; + case ColorSpace.TYPE_CMYK: + id = JPEGEncodeParam.COLOR_ID_CMYK; + break; - default: - id = JPEGEncodeParam.COLOR_ID_UNKNOWN; - } + default: + id = JPEGEncodeParam.COLOR_ID_UNKNOWN; + } - return id; + return id; } }
--- a/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGDecodeParam.java Fri Jul 01 14:41:45 2011 +0200 +++ b/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGDecodeParam.java Wed Jul 06 20:55:06 2011 +0100 @@ -1,29 +1,29 @@ /* 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 @@ -72,20 +72,20 @@ * with the BufferedImage returned rather than make assumptions. * </p> * DECODING: - * + * * <pre> - * JPEG (Encoded) Color ID BufferedImage ColorSpace - * ======================= ======================== - * COLOR_ID_UNKNOWN ** Invalid ** + * 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_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_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_YCbCrA_INVERTED ** Invalid ** * COLOR_ID_PYCCA CS_PYCC (w/ alpha) * COLOR_ID_YCCK ** Invalid ** * </pre> @@ -173,14 +173,14 @@ /** * 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(); @@ -191,7 +191,7 @@ * 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. @@ -205,7 +205,7 @@ * 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. @@ -216,7 +216,7 @@ /** * Returns the coefficient quantization tables or NULL if not defined. * tableNum must range in value from 0 - 3. - * + * * @param tableNum * the index of the table to be returned. * @return Quantization table stored at index tableNum. @@ -225,7 +225,7 @@ /** * Returns the Quantization table for the requested component. - * + * * @param component * the image component of interest. * @return Quantization table associated with component @@ -234,7 +234,7 @@ /** * Returns the DC Huffman coding table requested or null if not defined - * + * * @param tableNum * the index of the table to be returned. * @return Huffman table stored at index tableNum. @@ -243,7 +243,7 @@ /** * Returns the DC Huffman coding table for the requested component. - * + * * @param component * the image component of interest. * @return Huffman table associated with component @@ -252,7 +252,7 @@ /** * Returns the AC Huffman coding table requested or null if not defined - * + * * @param tableNum * the index of the table to be returned. * @return Huffman table stored at index tableNum. @@ -261,7 +261,7 @@ /** * Returns the AC Huffman coding table for the requested component. - * + * * @param component * the image component of interest. * @return Huffman table associated with component @@ -271,7 +271,7 @@ /** * Get the number of the DC Huffman table that will be used for a particular * component. - * + * * @param component * The Component of interest. * @return The table number of the DC Huffman table for component. @@ -281,7 +281,7 @@ /** * Get the number of the AC Huffman table that will be used for a particular * component. - * + * * @param component * The Component of interest. * @return The table number of the AC Huffman table for component. @@ -291,7 +291,7 @@ /** * Get the number of the quantization table that will be used for a * particular component. - * + * * @param component * The Component of interest. * @return The table number of the Quantization table for component. @@ -316,7 +316,7 @@ * Returns true if at least one instance of the marker is present in the * Parameter object. For encoding returns true if there is at least one * instance of the marker to be written. - * + * * @param marker * The marker of interest. */ @@ -327,7 +327,7 @@ * parameter object. Each entry in the 'byte[][]' is the data associated * with one instance of the marker (each marker can theoretically appear any * number of times in a stream). - * + * * @param marker * The marker of interest. * @return The 'byte[][]' for this marker or null if none available. @@ -338,21 +338,21 @@ * Returns the JPEG Encoded color id. This is generally speaking only used * if you are decoding into Rasters. Note that when decoding into a Raster * no color conversion is performed. - * + * * @return The value of the JPEG encoded data's color id. */ public int getEncodedColorID(); /** * Returns the number of components for the current encoding COLOR_ID. - * + * * @return the number of Components */ public int getNumComponents(); /** * Get the MCUs per restart marker. - * + * * @return The number of MCUs between restart markers. */ public int getRestartInterval(); @@ -361,7 +361,7 @@ * Get the code for pixel size units This value is copied from the APP0 * marker. It isn't used by the JPEG codec. If the APP0 marker wasn't * present then you can not rely on this value. - * + * * @return Value indicating the density unit one of the DENSITY_UNIT_* * constants. */ @@ -371,7 +371,7 @@ * Get the horizontal pixel density This value is copied from the APP0 * marker. It isn't used by the JPEG code. If the APP0 marker wasn't present * then you can not rely on this value. - * + * * @return The horizontal pixel density, in units described by * @see #getDensityUnit() */ @@ -381,7 +381,7 @@ * Get the vertical pixel density This value is copied into the APP0 marker. * It isn't used by the JPEG code. If the APP0 marker wasn't present then * you can not rely on this value. - * + * * @return The vertical pixel density, in units described by * @see #getDensityUnit() */
--- a/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGEncodeParam.java Fri Jul 01 14:41:45 2011 +0200 +++ b/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGEncodeParam.java Wed Jul 06 20:55:06 2011 +0100 @@ -1,4 +1,4 @@ -/* JPEGEncodeParam.java -- +/* JPEGEncodeParam.java -- Copyright (C) 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -72,20 +72,20 @@ * Raster. In this case the API programmer must specify the colorID of the data * in the Raster and no color conversion will take place. * </p> - * + * * ENCODING: - * + * * <pre> * BufferedImage Type/Instance JPEG (Encoded) Color ID - * =========================== ======================= - * TYPE_GRAY COLOR_ID_GRAYSCALE - * TYPE_RGB COLOR_ID_YCbCr + * =========================== ======================= + * TYPE_GRAY COLOR_ID_GRAYSCALE + * TYPE_RGB COLOR_ID_YCbCr * TYPE_YCbCr COLOR_ID_YCbCr - * TYPE_YCbCr/CS_PYCC COLOR_ID_PYCC - * TYPE_CMYK COLOR_ID_CMYK - * TYPE_RGB (w/ alpha) COLOR_ID_YCbCrA - * TYPE_YCbCr (w/ alpha) COLOR_ID_YCbCrA - * TYPE_YCbCr/CS_PYCC (w/ alpha) COLOR_ID_PYCCA + * TYPE_YCbCr/CS_PYCC COLOR_ID_PYCC + * TYPE_CMYK COLOR_ID_CMYK + * TYPE_RGB (w/ alpha) COLOR_ID_YCbCrA + * TYPE_YCbCr (w/ alpha) COLOR_ID_YCbCrA + * TYPE_YCbCr/CS_PYCC (w/ alpha) COLOR_ID_PYCCA * ** Any Other ** COLOR_ID_UNKNOWN * </pre> * <p> @@ -118,7 +118,7 @@ * Set the horizontal subsample factor for the given component. Note that * the subsample factor is the number of input pixels that contribute to * each output pixel (usually 2 for YCC). - * + * * @param component * The component being specified. * @param subsample @@ -130,7 +130,7 @@ * Set the vertical subsample factor for the given component. Note that the * subsample factor is the number of input pixels that contribute to each * output pixel (usually 2 for YCC). - * + * * @param component * The component being specified. * @param subsample @@ -141,7 +141,7 @@ /** * Sets the coefficient quantization tables at index passed. tableNum must * range in value from 0 - 3. - * + * * @param qtable * that will be used. * @param tableNum @@ -151,7 +151,7 @@ /** * Sets the DC Huffman coding table at index to the table provided. - * + * * @param huffTable * JPEGHuffmanTable that will be assigned to index tableNum. * @param tableNum @@ -164,7 +164,7 @@ /** * Sets the AC Huffman coding table at index to the table provided. - * + * * @param huffTable * JPEGHuffmanTable that will be assigned to index tableNum. * @param tableNum @@ -177,7 +177,7 @@ /** * Sets the mapping between a component and it's DC Huffman Table. - * + * * @param component * The component to set the mapping for * @param table @@ -187,7 +187,7 @@ /** * Sets the mapping between a component and it's AC Huffman Table. - * + * * @param component * The component to set the mapping for * @param table @@ -197,7 +197,7 @@ /** * Sets the mapping between a component and it's Quantization Table. - * + * * @param component * The component to set the mapping for * @param table @@ -223,7 +223,7 @@ * Sets the marker data to be written to the output data stream. This * removes any existing marker data in the JPEParm object. This can be used * to remove the default APP0 marker by calling it with data set to null. - * + * * @param marker * The marker to set the data for. * @param data @@ -235,7 +235,7 @@ * Appends 'data' to the array of byte[] associated with marker. This will * result in additional instance of the marker being written (one for each * byte[] in the array.). - * + * * @param marker * The marker to add and instance of. * @param data @@ -245,7 +245,7 @@ /** * Set the MCUs per restart, or 0 for no restart markers. - * + * * @param restartInterval * number MCUs per restart marker. */ @@ -254,7 +254,7 @@ /** * Set the pixel size units This value is copied into the APP0 marker (if * that marker is written). This value isn't used by the JPEG code. - * + * * @param unit * One of the DENSITY_UNIT_* values. */ @@ -263,7 +263,7 @@ /** * Set the horizontal pixel density. This value is written into the APP0 * marker. It isn't used by the JPEG code. - * + * * @param density * the horizontal pixel density, in units described by @see * JPEGParam.getDensityUnit. @@ -273,7 +273,7 @@ /** * Set the vertical pixel density. This value is copied into the JFIF APP0 * marker. It isn't used by the JPEG code. - * + * * @param density * The vertical pixel density, in units described by @see * JPEGParam.getDensityUnit. @@ -284,20 +284,20 @@ * This creates new Quantization tables that replace the currently installed * Quantization tables. It also updates the Component QTable mapping to the * default for the current encoded COLOR_ID. - * + * * The Created Quantization table varies from very high compression, very * low quality, (0.0) to low compression, very high quality (1.0) based on * the quality parameter. - * + * * At a quality level of 1.0 the table will be all 1's which will lead to no * loss of data due to quantization (however chrominance subsampling, if * used, and roundoff error in the DCT will still degrade the image some * what). - * + * * This is a linear manipulation of the standard chrominance Q-Table. - * + * * Some guidelines: 0.75 high quality 0.5 medium quality 0.25 low quality - * + * * @param quality * 0.0-1.0 setting of desired quality level. * @param forceBaseline
--- a/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGHuffmanTable.java Fri Jul 01 14:41:45 2011 +0200 +++ b/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGHuffmanTable.java Wed Jul 06 20:55:06 2011 +0100 @@ -22,7 +22,7 @@ * A class to encapsulate a JPEG Huffman table. */ public class JPEGHuffmanTable extends - javax.imageio.plugins.jpeg.JPEGHuffmanTable { + javax.imageio.plugins.jpeg.JPEGHuffmanTable { /** * The standard DC luminance Huffman table. @@ -45,28 +45,28 @@ public static final JPEGHuffmanTable StdACChrominance; static { - javax.imageio.plugins.jpeg.JPEGHuffmanTable temp = javax.imageio.plugins.jpeg.JPEGHuffmanTable.StdDCLuminance; - StdDCLuminance = new JPEGHuffmanTable(temp.getLengths(), - temp.getValues()); + javax.imageio.plugins.jpeg.JPEGHuffmanTable temp = javax.imageio.plugins.jpeg.JPEGHuffmanTable.StdDCLuminance; + StdDCLuminance = new JPEGHuffmanTable(temp.getLengths(), + temp.getValues()); - temp = javax.imageio.plugins.jpeg.JPEGHuffmanTable.StdDCChrominance; - StdDCChrominance = new JPEGHuffmanTable(temp.getLengths(), - temp.getValues()); + temp = javax.imageio.plugins.jpeg.JPEGHuffmanTable.StdDCChrominance; + StdDCChrominance = new JPEGHuffmanTable(temp.getLengths(), + temp.getValues()); - temp = javax.imageio.plugins.jpeg.JPEGHuffmanTable.StdACLuminance; - StdACLuminance = new JPEGHuffmanTable(temp.getLengths(), - temp.getValues()); + temp = javax.imageio.plugins.jpeg.JPEGHuffmanTable.StdACLuminance; + StdACLuminance = new JPEGHuffmanTable(temp.getLengths(), + temp.getValues()); - temp = javax.imageio.plugins.jpeg.JPEGHuffmanTable.StdACChrominance; - StdACChrominance = new JPEGHuffmanTable(temp.getLengths(), - temp.getValues()); + temp = javax.imageio.plugins.jpeg.JPEGHuffmanTable.StdACChrominance; + StdACChrominance = new JPEGHuffmanTable(temp.getLengths(), + temp.getValues()); } /** * Creates a Huffman table and initializes it. The input arrays are copied. * The arrays must describe a possible Huffman table. For example, 3 codes * cannot be expressed with a single bit. - * + * * @param lengths * an array of {@code short}s where <code>lengths[k]</code> is * equal to the number of values with corresponding codes of @@ -82,16 +82,16 @@ * zero, or if the arrays do not describe a valid Huffman table. */ public JPEGHuffmanTable(short lengths[], short symbols[]) { - super(lengths, symbols); + super(lengths, symbols); } /** * Return an array containing the Huffman symbols arranged by increasing * length. To make use of this array you must refer the the lengths array. - * + * * @return A short array of Huffman symbols */ public short[] getSymbols() { - return getValues(); + return getValues(); } }
--- a/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGImageDecoder.java Fri Jul 01 14:41:45 2011 +0200 +++ b/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGImageDecoder.java Wed Jul 06 20:55:06 2011 +0100 @@ -1,4 +1,4 @@ -/* JPEGImageDecoder.java -- +/* JPEGImageDecoder.java -- Copyright (C) 2007 Free Software Foundation, Inc. Copyright (C) 2007 Matthew Flaschen @@ -51,7 +51,7 @@ * InputStream is a BufferedImage the ColorModel associated with this * BufferedImage is determined based on the encoded COLOR_ID of the * JPEGDecodeParam object. For a tables only stream this will return null. - * + * * @return BufferedImage containing the image data. * @throws ImageFormatException * If irregularities in the JPEG stream or an unknown condition @@ -59,13 +59,13 @@ * @throws IOException */ public BufferedImage decodeAsBufferedImage() throws IOException, - ImageFormatException; + ImageFormatException; /** * Decode the JPEG stream that was passed as part of construction. The JPEG * decompression will be performed according to the current settings of the * JPEGDecodeParam object. For a tables only stream this will return null. - * + * * @return Raster containg the image data. Colorspace and other pertinent * information can be obtained from the JPEGDecodeParam object. * @throws ImageFormatException @@ -77,7 +77,7 @@ /** * Get the input stream that decoding will occur from. - * + * * @return The stream that the decoder is currently associated with. */ public InputStream getInputStream(); @@ -85,7 +85,7 @@ /** * Returns the JPEGDecodeParam object that resulted from the most recent * decoding event. - * + * * @return */ public JPEGDecodeParam getJPEGDecodeParam(); @@ -94,7 +94,7 @@ * Sets the JPEGDecodeParam object used to determine the features of the * decompression performed on the JPEG encoded data. This is usually only * needed for decoding abbreviated JPEG data streams. - * + * * @param jdp * JPEGDecodeParam object */
--- a/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGImageEncoder.java Fri Jul 01 14:41:45 2011 +0200 +++ b/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGImageEncoder.java Wed Jul 06 20:55:06 2011 +0100 @@ -1,4 +1,4 @@ -/* JPEGImageEncoder.java -- +/* JPEGImageEncoder.java -- Copyright (C) 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -49,13 +49,13 @@ * This is a factory method for creating JPEGEncodeParam objects. The * returned object will do a credible job of encoding the given * BufferedImage. - * + * * @param bi * @return * @throws ImageFormatException */ public JPEGEncodeParam getDefaultJPEGEncodeParam(BufferedImage bi) - throws ImageFormatException; + throws ImageFormatException; /** * This is a factory method for creating JPEGEncodeParam objects. It is the @@ -64,7 +64,7 @@ * poor compression and/or poor image quality. If you don't understand much * about JPEG it is strongly recommended that you stick to the BufferedImage * interface. - * + * * @param numBands * the number of bands that will be encoded (max of four). * @param colorID @@ -75,7 +75,7 @@ * @throws ImageFormatException */ public JPEGEncodeParam getDefaultJPEGEncodeParam(int numBands, int colorID) - throws ImageFormatException; + throws ImageFormatException; /** * This is a factory method for creating a JPEGEncodeParam from a @@ -83,14 +83,14 @@ * initialized from the JPEGDecodeParam object. All major pieces of * information will be initialized from the DecodeParam (Markers, Tables, * mappings). - * + * * @param d * The JPEGDecodeParam object to copy. * @return * @throws ImageFormatException */ public JPEGEncodeParam getDefaultJPEGEncodeParam(JPEGDecodeParam d) - throws ImageFormatException; + throws ImageFormatException; /** * This is a factory method for creating JPEGEncodeParam objects. It is the @@ -98,14 +98,14 @@ * Raster. Failure to do so may lead to either poor compression or poor * image quality. If you don't understand much about JPEG it is strongly * reccomended that you stick to the BufferedImage interfaces. - * + * * @param ras * @param colorID * @return * @throws ImageFormatException */ public JPEGEncodeParam getDefaultJPEGEncodeParam(Raster ras, int colorID) - throws ImageFormatException; + throws ImageFormatException; public JPEGEncodeParam getJPEGEncodeParam() throws ImageFormatException; @@ -113,7 +113,7 @@ * Set the JPEGEncodeParam object that is to be used for future encoding * operations. 'p' is copied so changes will not be tracked, unless you call * this method again. - * + * * @param p * The JPEGEncodeParam object to use for future encodings. */ @@ -121,7 +121,7 @@ /** * Return the stream the Encoder is current associated with. - * + * * @return */ public OutputStream getOutputStream(); @@ -134,7 +134,7 @@ * given JPEGEncodeParam object will be used for this and future encodings. * If p is null then a new JPEGEncodeParam object will be created by calling * getDefaultJPEGEncodeParam with bi. - * + * * @param bi * The BufferedImage to encode. * @param p @@ -143,7 +143,7 @@ * @throws ImageFormatException */ public void encode(BufferedImage bi, JPEGEncodeParam p) throws IOException, - ImageFormatException; + ImageFormatException; /** * Encode a Raster as a JPEG data stream. Note that no color conversion @@ -152,7 +152,7 @@ * JPEGEncodeParam object has been provided yet a new JPEGEncodeParam object * will be created by calling getDefaultJPEGEncodeParam with ras and * COLOR_ID_UNKNOWN. - * + * * @param ras * The Raster to encode. * @throws IOException @@ -167,14 +167,14 @@ * the BufferedImage's ColorModel. If no JPEGEncodeParam object has been * provided yet a default one will be created by calling * getDefaultJPEGEncodeParam with bi. - * + * * @param bi * The BufferedImage to encode. * @throws IOException * @throws ImageFormatException */ public void encode(BufferedImage bi) throws IOException, - ImageFormatException; + ImageFormatException; /** * Encode a Raster as a JPEG data stream. Note that no color conversion @@ -182,7 +182,7 @@ * COLOR_ID contained in the JPEGEncodeParam object. If p is null a new * JPEGEncodeParam object will be created by calling * getDefaultJPEGEncodeParam with ras and COLOR_ID_UNKNOWN. - * + * * @param ras * The Raster to encode. * @param p @@ -191,7 +191,7 @@ * @throws ImageFormatException */ public void encode(Raster ras, JPEGEncodeParam p) throws IOException, - ImageFormatException; + ImageFormatException; /** * Returns the 'default' encoded COLOR_ID for a given ColorModel. This @@ -199,7 +199,7 @@ * library will figure things out for you). It can be useful for encoding * Rasters. To determine what needs to be done to the image prior to * encoding. - * + * * @param cm * The ColorModel to map to an jpeg encoded COLOR_ID. * @return
--- a/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGQTable.java Fri Jul 01 14:41:45 2011 +0200 +++ b/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/JPEGQTable.java Wed Jul 06 20:55:06 2011 +0100 @@ -1,4 +1,4 @@ -/* JPEGQTable.java -- +/* JPEGQTable.java -- Copyright (C) 2011 Red Hat Copyright (C) 2007 Free Software Foundation, Inc. Copyright (C) 2007 Matthew Flaschen @@ -43,12 +43,12 @@ /** * Class to encapsulate the JPEG quantization tables. - * + * * Note: The tables K1Luminance, K1Div2Luminance, K2Chrominance, * K2Div2Chrominance is an instance of the superclass. - * + * * @author Andrew Su (asu@redhat.com) - * + * */ public class JPEGQTable { @@ -63,22 +63,22 @@ public static final JPEGQTable StdChrominance; static { - /* table for luminance values in zig-zag order */ - int[] table1 = { 16, 11, 12, 14, 12, 10, 16, 14, 13, 14, 18, 17, 16, - 19, 24, 40, 26, 24, 22, 22, 24, 49, 35, 37, 29, 40, 58, 51, 61, - 60, 57, 51, 56, 55, 64, 72, 92, 78, 64, 68, 87, 69, 55, 56, 80, - 109, 81, 87, 95, 98, 103, 104, 103, 62, 77, 113, 121, 112, 100, - 120, 92, 101, 103, 99 }; + /* table for luminance values in zig-zag order */ + int[] table1 = { 16, 11, 12, 14, 12, 10, 16, 14, 13, 14, 18, 17, 16, + 19, 24, 40, 26, 24, 22, 22, 24, 49, 35, 37, 29, 40, 58, 51, 61, + 60, 57, 51, 56, 55, 64, 72, 92, 78, 64, 68, 87, 69, 55, 56, 80, + 109, 81, 87, 95, 98, 103, 104, 103, 62, 77, 113, 121, 112, 100, + 120, 92, 101, 103, 99 }; - StdLuminance = new JPEGQTable(table1); + StdLuminance = new JPEGQTable(table1); - /* table for chrominance values in zig-zag order */ - int[] table2 = { 17, 18, 18, 24, 21, 24, 47, 26, 26, 47, 99, 66, 56, - 66, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, - 99, 99, 99 }; - StdChrominance = new JPEGQTable(table2); + /* table for chrominance values in zig-zag order */ + int[] table2 = { 17, 18, 18, 24, 21, 24, 47, 26, 26, 47, 99, 66, 56, + 66, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99 }; + StdChrominance = new JPEGQTable(table2); } private int[] table; @@ -87,32 +87,32 @@ * Constructs an quantization table from the array that was passed. The * coefficients must be in zig-zag order. The array must be of length 64. * The table will be copied. - * + * * @param table * the quantization table, as an int array. * @throws IllegalArgumentException * if table is null or table.length is not equal to 64. */ public JPEGQTable(int[] table) { - /* Table must be 8x8 thus 64 entries */ - if (table == null || table.length != 64) { - throw new IllegalArgumentException("Not a valid table."); - } - this.table = Arrays.copyOf(table, table.length); + /* Table must be 8x8 thus 64 entries */ + if (table == null || table.length != 64) { + throw new IllegalArgumentException("Not a valid table."); + } + this.table = Arrays.copyOf(table, table.length); } public int[] getTable() { - return Arrays.copyOf(table, table.length); + return Arrays.copyOf(table, table.length); } public JPEGQTable getScaledInstance(float scaleFactor, boolean forceBaseline) { - int limit = (forceBaseline) ? 255 : 32767; - int[] newTable = new int[table.length]; - for (int i = 0; i < table.length; i++) { - int newValue = Math.round(table[i] * scaleFactor); - newTable[i] = (newValue < 1) ? 1 : (newValue > limit) ? limit : newValue; - } - return new JPEGQTable(newTable); + int limit = (forceBaseline) ? 255 : 32767; + int[] newTable = new int[table.length]; + for (int i = 0; i < table.length; i++) { + int newValue = Math.round(table[i] * scaleFactor); + newTable[i] = (newValue < 1) ? 1 : (newValue > limit) ? limit : newValue; + } + return new JPEGQTable(newTable); } }
--- a/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/TruncatedFileException.java Fri Jul 01 14:41:45 2011 +0200 +++ b/overlays/jpeg/openjdk/jdk/src/share/classes/com/sun/image/codec/jpeg/TruncatedFileException.java Wed Jul 06 20:55:06 2011 +0100 @@ -41,14 +41,14 @@ public class TruncatedFileException extends RuntimeException { public TruncatedFileException() { - this(""); + this(""); } public TruncatedFileException(String s) { - super(s); + super(s); } public BufferedImage getBufferedImage() { - return null; + return null; } }
--- a/overlays/jpeg/openjdk/jdk/src/share/classes/sun/awt/image/codec/JPEGImageDecoderImpl.java Fri Jul 01 14:41:45 2011 +0200 +++ b/overlays/jpeg/openjdk/jdk/src/share/classes/sun/awt/image/codec/JPEGImageDecoderImpl.java Wed Jul 06 20:55:06 2011 +0100 @@ -45,59 +45,59 @@ private JPEGDecodeParam param; public JPEGImageDecoderImpl(InputStream in) { - this(in, null); + this(in, null); } public JPEGImageDecoderImpl(InputStream in, JPEGDecodeParam param) { - this.in = in; - setJPEGDecodeParam(param); + this.in = in; + setJPEGDecodeParam(param); - Iterator<ImageReader> JPGReaderIter = ImageIO - .getImageReadersByMIMEType(JPGMime); - if (JPGReaderIter.hasNext()) { - JPGReader = (JPEGImageReader) JPGReaderIter.next(); - } + Iterator<ImageReader> JPGReaderIter = ImageIO + .getImageReadersByMIMEType(JPGMime); + if (JPGReaderIter.hasNext()) { + JPGReader = (JPEGImageReader) JPGReaderIter.next(); + } - JPGReader.setInput(new MemoryCacheImageInputStream(in)); + JPGReader.setInput(new MemoryCacheImageInputStream(in)); } public BufferedImage decodeAsBufferedImage() throws IOException, - ImageFormatException { - JPEGImageReadParam irp = null; + ImageFormatException { + JPEGImageReadParam irp = null; - if (param != null) { - // We should do more than this, but it's a start. - javax.imageio.plugins.jpeg.JPEGQTable[] qTables = new javax.imageio.plugins.jpeg.JPEGQTable[4]; - javax.imageio.plugins.jpeg.JPEGHuffmanTable[] DCHuffmanTables = new JPEGHuffmanTable[4]; - javax.imageio.plugins.jpeg.JPEGHuffmanTable[] ACHuffmanTables = new JPEGHuffmanTable[4]; + if (param != null) { + // We should do more than this, but it's a start. + javax.imageio.plugins.jpeg.JPEGQTable[] qTables = new javax.imageio.plugins.jpeg.JPEGQTable[4]; + javax.imageio.plugins.jpeg.JPEGHuffmanTable[] DCHuffmanTables = new JPEGHuffmanTable[4]; + javax.imageio.plugins.jpeg.JPEGHuffmanTable[] ACHuffmanTables = new JPEGHuffmanTable[4]; - for (int i = 0; i < 4; i++) { - qTables[i] = new javax.imageio.plugins.jpeg.JPEGQTable(param.getQTable(i).getTable()); - DCHuffmanTables[i] = param.getDCHuffmanTable(i); - ACHuffmanTables[i] = param.getACHuffmanTable(i); - } + for (int i = 0; i < 4; i++) { + qTables[i] = new javax.imageio.plugins.jpeg.JPEGQTable(param.getQTable(i).getTable()); + DCHuffmanTables[i] = param.getDCHuffmanTable(i); + ACHuffmanTables[i] = param.getACHuffmanTable(i); + } - irp = new JPEGImageReadParam(); - irp.setDecodeTables(qTables, DCHuffmanTables, ACHuffmanTables); - } + irp = new JPEGImageReadParam(); + irp.setDecodeTables(qTables, DCHuffmanTables, ACHuffmanTables); + } - return JPGReader.read(0, irp); + return JPGReader.read(0, irp); } public Raster decodeAsRaster() throws IOException, ImageFormatException { - return JPGReader.readRaster(0, null); + return JPGReader.readRaster(0, null); } public InputStream getInputStream() { - return in; + return in; } public JPEGDecodeParam getJPEGDecodeParam() { - if (param == null) return null; - return (JPEGDecodeParam) param.clone(); + if (param == null) return null; + return (JPEGDecodeParam) param.clone(); } public void setJPEGDecodeParam(JPEGDecodeParam jdp) { - param = jdp; + param = jdp; } }
--- a/overlays/jpeg/openjdk/jdk/src/share/classes/sun/awt/image/codec/JPEGImageEncoderImpl.java Fri Jul 01 14:41:45 2011 +0200 +++ b/overlays/jpeg/openjdk/jdk/src/share/classes/sun/awt/image/codec/JPEGImageEncoderImpl.java Wed Jul 06 20:55:06 2011 +0100 @@ -42,7 +42,7 @@ /** * This class provides the implementation for encoding JPEG images. - * + * */ public class JPEGImageEncoderImpl implements JPEGImageEncoder { private static final String JPGMime = "image/jpeg"; @@ -52,132 +52,132 @@ private OutputStream out; public JPEGImageEncoderImpl(OutputStream os) { - this(os, null); + this(os, null); } public JPEGImageEncoderImpl(OutputStream out, JPEGEncodeParam newParam) { - this.out = out; - setJPEGEncodeParam(newParam); + this.out = out; + setJPEGEncodeParam(newParam); - Iterator<ImageWriter> JPGWriterIter = ImageIO - .getImageWritersByMIMEType(JPGMime); - if (JPGWriterIter.hasNext()) { - JPGWriter = JPGWriterIter.next(); - } + Iterator<ImageWriter> JPGWriterIter = ImageIO + .getImageWritersByMIMEType(JPGMime); + if (JPGWriterIter.hasNext()) { + JPGWriter = JPGWriterIter.next(); + } - JPGWriter.setOutput(new MemoryCacheImageOutputStream(out)); + JPGWriter.setOutput(new MemoryCacheImageOutputStream(out)); } public JPEGEncodeParam getDefaultJPEGEncodeParam(BufferedImage bi) - throws ImageFormatException { - return JPEGCodec.getDefaultJPEGEncodeParam(bi); + throws ImageFormatException { + return JPEGCodec.getDefaultJPEGEncodeParam(bi); } public JPEGEncodeParam getDefaultJPEGEncodeParam(int numBands, int colorID) - throws ImageFormatException { - return JPEGCodec.getDefaultJPEGEncodeParam(numBands, colorID); + throws ImageFormatException { + return JPEGCodec.getDefaultJPEGEncodeParam(numBands, colorID); } public JPEGEncodeParam getDefaultJPEGEncodeParam(JPEGDecodeParam d) - throws ImageFormatException { - return JPEGCodec.getDefaultJPEGEncodeParam(d); + throws ImageFormatException { + return JPEGCodec.getDefaultJPEGEncodeParam(d); } public JPEGEncodeParam getDefaultJPEGEncodeParam(Raster ras, int colorID) - throws ImageFormatException { - return JPEGCodec.getDefaultJPEGEncodeParam(ras, colorID); + throws ImageFormatException { + return JPEGCodec.getDefaultJPEGEncodeParam(ras, colorID); } public JPEGEncodeParam getJPEGEncodeParam() throws ImageFormatException { - if (param == null) - return null; - return (JPEGEncodeParam) param.clone(); + if (param == null) + return null; + return (JPEGEncodeParam) param.clone(); } public void setJPEGEncodeParam(JPEGEncodeParam p) { - param = p; + param = p; } public OutputStream getOutputStream() { - return out; + return out; } private void encode(IIOImage img) throws IOException, ImageFormatException { - if (JPGWriter == null) - throw new ImageFormatException( - "JPEG writer code not implemented in ImageIO"); + if (JPGWriter == null) + throw new ImageFormatException( + "JPEG writer code not implemented in ImageIO"); - JPEGImageWriteParam jiwp = new JPEGImageWriteParam(null); - ; - jiwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); - if (param != null && param instanceof JPEGParam) { - JPEGParam jp = (JPEGParam) param; - jiwp.setCompressionQuality(jp.getQuality()); - } else { - jiwp.setCompressionQuality(JPEG.DEFAULT_QUALITY); - } + JPEGImageWriteParam jiwp = new JPEGImageWriteParam(null); + ; + jiwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); + if (param != null && param instanceof JPEGParam) { + JPEGParam jp = (JPEGParam) param; + jiwp.setCompressionQuality(jp.getQuality()); + } else { + jiwp.setCompressionQuality(JPEG.DEFAULT_QUALITY); + } - JPGWriter.write(null, img, jiwp); + JPGWriter.write(null, img, jiwp); } public void encode(BufferedImage bi, JPEGEncodeParam writeParam) - throws IOException, ImageFormatException { - setJPEGEncodeParam(writeParam); - encode(new IIOImage(bi, new ArrayList<BufferedImage>(), null)); + throws IOException, ImageFormatException { + setJPEGEncodeParam(writeParam); + encode(new IIOImage(bi, new ArrayList<BufferedImage>(), null)); } public void encode(Raster rs, JPEGEncodeParam writeParam) - throws IOException, ImageFormatException { - setJPEGEncodeParam(writeParam); - encode(new IIOImage(rs, new ArrayList<BufferedImage>(), null)); + throws IOException, ImageFormatException { + setJPEGEncodeParam(writeParam); + encode(new IIOImage(rs, new ArrayList<BufferedImage>(), null)); } public void encode(BufferedImage bi) throws IOException, - ImageFormatException { - encode(bi, null); + ImageFormatException { + encode(bi, null); } public void encode(Raster rs) throws IOException, ImageFormatException { - encode(rs, null); + encode(rs, null); } @Override public 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; + 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_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_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; + case ColorSpace.TYPE_CMYK: + id = JPEGEncodeParam.COLOR_ID_CMYK; + break; - default: - id = JPEGEncodeParam.COLOR_ID_UNKNOWN; - } + default: + id = JPEGEncodeParam.COLOR_ID_UNKNOWN; + } - return id; + return id; } }
--- a/overlays/jpeg/openjdk/jdk/src/share/classes/sun/awt/image/codec/JPEGParam.java Fri Jul 01 14:41:45 2011 +0200 +++ b/overlays/jpeg/openjdk/jdk/src/share/classes/sun/awt/image/codec/JPEGParam.java Wed Jul 06 20:55:06 2011 +0100 @@ -1,16 +1,16 @@ /* JPEGParam.java -- keeps track of encode and decode parameters for JPEG. * Copyright (C) 2011 Red Hat - * + * * This program 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 of the License, or * (at your option) any later version. - * + * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA @@ -28,15 +28,15 @@ /** * This class encapsulates the information about encoding and decoding the JPEG * image. - * + * * @author Andrew Su (asu@redhat.com) - * + * */ public class JPEGParam implements JPEGEncodeParam { /* * NOTE: bands mean the same thing as components, trying to keep it * Consistent with the documentation - * + * * NOTE: subsampling is not done implementing. */ @@ -66,7 +66,7 @@ private int[] dcHuffmanComponentMapping; /* - * Breakdown for marker bytes + * Breakdown for marker bytes * 5 for name. * 2 for version. * 1 for density type. @@ -77,674 +77,674 @@ private byte APP0_MARKER_NUM_BYTES = 14; public JPEGParam(JPEGEncodeParam param) { - this((JPEGDecodeParam) param); + this((JPEGDecodeParam) param); } public JPEGParam(JPEGDecodeParam param) { - this(param.getEncodedColorID(), param.getNumComponents()); + this(param.getEncodedColorID(), param.getNumComponents()); - setTableInfoValid(param.isTableInfoValid()); - setImageInfoValid(param.isImageInfoValid()); - setRestartInterval(param.getRestartInterval()); + setTableInfoValid(param.isTableInfoValid()); + setImageInfoValid(param.isImageInfoValid()); + setRestartInterval(param.getRestartInterval()); - // Copy the Q tables and Huffman tables. - for (int i = 0; i < NUM_TABLES; i++) { - qTable[i] = param.getQTable(i); - acHuffmanTable[i] = param.getACHuffmanTable(i); - dcHuffmanTable[i] = param.getDCHuffmanTable(i); - } + // Copy the Q tables and Huffman tables. + for (int i = 0; i < NUM_TABLES; i++) { + qTable[i] = param.getQTable(i); + acHuffmanTable[i] = param.getACHuffmanTable(i); + dcHuffmanTable[i] = param.getDCHuffmanTable(i); + } - // Next we want to copy the component mappings. - for (int i = 0; i < getNumComponents(); i++) { - setQTableComponentMapping(i, param.getQTableComponentMapping(i)); - setACHuffmanComponentMapping(i, - param.getACHuffmanComponentMapping(i)); - setDCHuffmanComponentMapping(i, - param.getDCHuffmanComponentMapping(i)); - } + // Next we want to copy the component mappings. + for (int i = 0; i < getNumComponents(); i++) { + setQTableComponentMapping(i, param.getQTableComponentMapping(i)); + setACHuffmanComponentMapping(i, + param.getACHuffmanComponentMapping(i)); + setDCHuffmanComponentMapping(i, + param.getDCHuffmanComponentMapping(i)); + } - // Copy all the marker data. - for (int i = APP0_MARKER; i < APPF_MARKER; i++) { - byte[][] markerData = param.getMarkerData(i); - byte[][] copyMarkerData = null; - if (markerData != null) { - copyMarkerData = new byte[markerData.length][]; - for (int j = 0; j < markerData.length; j++) { - copyMarkerData[j] = Arrays.copyOf(markerData[j], - markerData[j].length); - } - } - setMarkerData(i, copyMarkerData); - } + // Copy all the marker data. + for (int i = APP0_MARKER; i < APPF_MARKER; i++) { + byte[][] markerData = param.getMarkerData(i); + byte[][] copyMarkerData = null; + if (markerData != null) { + copyMarkerData = new byte[markerData.length][]; + for (int j = 0; j < markerData.length; j++) { + copyMarkerData[j] = Arrays.copyOf(markerData[j], + markerData[j].length); + } + } + setMarkerData(i, copyMarkerData); + } - byte[][] commentData = param.getMarkerData(COMMENT_MARKER); - byte[][] copyCommentData = null; - if (commentData != null) { - copyCommentData = new byte[commentData.length][]; - for (int i = 0; i < commentData.length; i++) { - copyCommentData[i] = Arrays.copyOf(commentData[i], - commentData[i].length); - } - setMarkerData(COMMENT_MARKER, copyCommentData); - } + byte[][] commentData = param.getMarkerData(COMMENT_MARKER); + byte[][] copyCommentData = null; + if (commentData != null) { + copyCommentData = new byte[commentData.length][]; + for (int i = 0; i < commentData.length; i++) { + copyCommentData[i] = Arrays.copyOf(commentData[i], + commentData[i].length); + } + setMarkerData(COMMENT_MARKER, copyCommentData); + } } public JPEGParam(int colorID) { - this(colorID, components[colorID]); + this(colorID, components[colorID]); } public JPEGParam(int colorID, int numBands) { - // We were given an invalid color id, or the number of bands given to us - // did not match requirements. - if (colorID < 0 - || colorID >= JPEGDecodeParam.NUM_COLOR_ID - || (colorID != COLOR_ID_UNKNOWN && numBands != components[colorID])) { - throw new IllegalArgumentException(); - } - this.colorID = colorID; - this.numBands = numBands; + // We were given an invalid color id, or the number of bands given to us + // did not match requirements. + if (colorID < 0 + || colorID >= JPEGDecodeParam.NUM_COLOR_ID + || (colorID != COLOR_ID_UNKNOWN && numBands != components[colorID])) { + throw new IllegalArgumentException(); + } + this.colorID = colorID; + this.numBands = numBands; - initialize(); + initialize(); } private void initialize() { - qTable[0] = JPEGQTable.StdLuminance; - qTable[1] = JPEGQTable.StdChrominance; + qTable[0] = JPEGQTable.StdLuminance; + qTable[1] = JPEGQTable.StdChrominance; - acHuffmanTable[0] = JPEGHuffmanTable.StdACLuminance; - acHuffmanTable[1] = JPEGHuffmanTable.StdACChrominance; + acHuffmanTable[0] = JPEGHuffmanTable.StdACLuminance; + acHuffmanTable[1] = JPEGHuffmanTable.StdACChrominance; - dcHuffmanTable[0] = JPEGHuffmanTable.StdDCLuminance; - dcHuffmanTable[1] = JPEGHuffmanTable.StdDCChrominance; + dcHuffmanTable[0] = JPEGHuffmanTable.StdDCLuminance; + dcHuffmanTable[1] = JPEGHuffmanTable.StdDCChrominance; - qTableComponentMapping = new int[getNumComponents()]; - acHuffmanComponentMapping = new int[getNumComponents()]; - dcHuffmanComponentMapping = new int[getNumComponents()]; + qTableComponentMapping = new int[getNumComponents()]; + acHuffmanComponentMapping = new int[getNumComponents()]; + dcHuffmanComponentMapping = new int[getNumComponents()]; - horizontalSubsampleComponents = new int[getNumComponents()]; - verticalSubsampleComponents = new int[getNumComponents()]; + horizontalSubsampleComponents = new int[getNumComponents()]; + verticalSubsampleComponents = new int[getNumComponents()]; - /* - * we can just set these to true since they are using default values - * right now - */ - setTableInfoValid(true); - setImageInfoValid(true); + /* + * we can just set these to true since they are using default values + * right now + */ + setTableInfoValid(true); + setImageInfoValid(true); - setMarkerData(APP0_MARKER, - arrayAdd(getMarkerData(APP0_MARKER), createAPP0MarkerData())); + setMarkerData(APP0_MARKER, + arrayAdd(getMarkerData(APP0_MARKER), createAPP0MarkerData())); } private byte[] createAPP0MarkerData() { - byte[] data = null; - // Create JFIF APP0 Marker if compatible. - // By compatible, it must be one of the following cases. - // Reference: - // http://www.jpeg.org/public/jfif.pdf - // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JFIF.html - switch (colorID) { - case COLOR_ID_UNKNOWN: - case COLOR_ID_GRAY: - case COLOR_ID_RGB: - case COLOR_ID_YCbCr: - case COLOR_ID_CMYK: - data = new byte[APP0_MARKER_NUM_BYTES]; + byte[] data = null; + // Create JFIF APP0 Marker if compatible. + // By compatible, it must be one of the following cases. + // Reference: + // http://www.jpeg.org/public/jfif.pdf + // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/JFIF.html + switch (colorID) { + case COLOR_ID_UNKNOWN: + case COLOR_ID_GRAY: + case COLOR_ID_RGB: + case COLOR_ID_YCbCr: + case COLOR_ID_CMYK: + data = new byte[APP0_MARKER_NUM_BYTES]; - // Null terminated JFIF string. [5 bytes] - data[0] = 'J'; - data[1] = 'F'; - data[2] = 'I'; - data[3] = 'F'; - data[4] = 0x0; + // Null terminated JFIF string. [5 bytes] + data[0] = 'J'; + data[1] = 'F'; + data[2] = 'I'; + data[3] = 'F'; + data[4] = 0x0; - // Version number [2 bytes] - data[5] = 1; - data[6] = 2; + // Version number [2 bytes] + data[5] = 1; + data[6] = 2; - // Density unit [1 byte] - data[7] = DENSITY_UNIT_ASPECT_RATIO; + // Density unit [1 byte] + data[7] = DENSITY_UNIT_ASPECT_RATIO; - // X density [2 bytes] - data[8] = 0; - data[9] = 1; + // X density [2 bytes] + data[8] = 0; + data[9] = 1; - // Y density [2 bytes] - data[10] = 0; - data[11] = 1; + // Y density [2 bytes] + data[10] = 0; + data[11] = 1; - // Thumbnail [2 bytes] - data[12] = 0; - data[13] = 0; - break; - } + // Thumbnail [2 bytes] + data[12] = 0; + data[13] = 0; + break; + } - return data; + return data; } public void setQuality(float quality, boolean forceBaseline) { - if (quality < 0.0) { - quality = 0.00f; - } else if (quality > 1.0) { - quality = 1.0f; - } + if (quality < 0.0) { + quality = 0.00f; + } else if (quality > 1.0) { + quality = 1.0f; + } - this.quality = quality; // preserve original. + this.quality = quality; // preserve original. - /* - * Since quality value of 1 is the lowest compression, we want our - * QTable to contain as much 1s as possible. Since scaling is by a - * factor, we want to invert the selection such that highest quality is - * 0 and lowest is 1. - */ - quality = 1 - quality; + /* + * Since quality value of 1 is the lowest compression, we want our + * QTable to contain as much 1s as possible. Since scaling is by a + * factor, we want to invert the selection such that highest quality is + * 0 and lowest is 1. + */ + quality = 1 - quality; - // We will scale our QTables to match the quality value given to us. - for (int i = 0; i < NUM_TABLES; i++) { - if (qTable[i] != null) { - qTable[i] = qTable[i].getScaledInstance(quality, forceBaseline); - } - } + // We will scale our QTables to match the quality value given to us. + for (int i = 0; i < NUM_TABLES; i++) { + if (qTable[i] != null) { + qTable[i] = qTable[i].getScaledInstance(quality, forceBaseline); + } + } } public Object clone() { - JPEGParam c = new JPEGParam(this); - return c; + JPEGParam c = new JPEGParam(this); + return c; } @Override public int getWidth() { - return width; + return width; } @Override public int getHeight() { - return height; + return height; } @Override public int getHorizontalSubsampling(int component) { - if (component < 0 || component > getNumComponents()) { - throw new IllegalArgumentException("Invalid component"); - } + if (component < 0 || component > getNumComponents()) { + throw new IllegalArgumentException("Invalid component"); + } - return horizontalSubsampleComponents[component]; + return horizontalSubsampleComponents[component]; } @Override public int getVerticalSubsampling(int component) { - if (component < 0 || component > getNumComponents()) { - throw new IllegalArgumentException("Invalid component"); - } + if (component < 0 || component > getNumComponents()) { + throw new IllegalArgumentException("Invalid component"); + } - return verticalSubsampleComponents[component]; + return verticalSubsampleComponents[component]; } @Override public JPEGQTable getQTable(int tableNum) { - if (tableNum < 0 || tableNum > NUM_TABLES) - throw new IllegalArgumentException("tableNum must be [0-" - + (NUM_TABLES - 1) + "]"); - return qTable[tableNum]; + if (tableNum < 0 || tableNum > NUM_TABLES) + throw new IllegalArgumentException("tableNum must be [0-" + + (NUM_TABLES - 1) + "]"); + return qTable[tableNum]; } @Override public JPEGQTable getQTableForComponent(int component) { - if (component < 0 || component > getNumComponents()) { - throw new IllegalArgumentException("Invalid component"); - } + if (component < 0 || component > getNumComponents()) { + throw new IllegalArgumentException("Invalid component"); + } - return qTable[qTableComponentMapping[component]]; + return qTable[qTableComponentMapping[component]]; } @Override public JPEGHuffmanTable getDCHuffmanTable(int tableNum) { - if (tableNum < 0 || tableNum > NUM_TABLES) - throw new IllegalArgumentException("tableNum must be [0-" - + (NUM_TABLES - 1) + "]"); - return dcHuffmanTable[tableNum]; + if (tableNum < 0 || tableNum > NUM_TABLES) + throw new IllegalArgumentException("tableNum must be [0-" + + (NUM_TABLES - 1) + "]"); + return dcHuffmanTable[tableNum]; } @Override public JPEGHuffmanTable getDCHuffmanTableForComponent(int component) { - if (component < 0 || component > getNumComponents()) { - throw new IllegalArgumentException("Invalid component"); - } + if (component < 0 || component > getNumComponents()) { + throw new IllegalArgumentException("Invalid component"); + } - return dcHuffmanTable[dcHuffmanComponentMapping[component]]; + return dcHuffmanTable[dcHuffmanComponentMapping[component]]; } @Override public JPEGHuffmanTable getACHuffmanTable(int tableNum) { - if (tableNum < 0 || tableNum > NUM_TABLES) - throw new IllegalArgumentException("tableNum must be [0-" - + (NUM_TABLES - 1) + "]"); - return acHuffmanTable[tableNum]; + if (tableNum < 0 || tableNum > NUM_TABLES) + throw new IllegalArgumentException("tableNum must be [0-" + + (NUM_TABLES - 1) + "]"); + return acHuffmanTable[tableNum]; } @Override public JPEGHuffmanTable getACHuffmanTableForComponent(int component) { - if (component < 0 || component > getNumComponents()) { - throw new IllegalArgumentException("Invalid component"); - } + if (component < 0 || component > getNumComponents()) { + throw new IllegalArgumentException("Invalid component"); + } - return acHuffmanTable[acHuffmanComponentMapping[component]]; + return acHuffmanTable[acHuffmanComponentMapping[component]]; } @Override public int getDCHuffmanComponentMapping(int component) { - if (component < 0 || component > getNumComponents()) { - throw new IllegalArgumentException("Invalid component"); - } - return dcHuffmanComponentMapping[component]; + if (component < 0 || component > getNumComponents()) { + throw new IllegalArgumentException("Invalid component"); + } + return dcHuffmanComponentMapping[component]; } @Override public int getACHuffmanComponentMapping(int component) { - if (component < 0 || component > getNumComponents()) { - throw new IllegalArgumentException("Invalid component"); - } - return acHuffmanComponentMapping[component]; + if (component < 0 || component > getNumComponents()) { + throw new IllegalArgumentException("Invalid component"); + } + return acHuffmanComponentMapping[component]; } @Override public int getQTableComponentMapping(int component) { - if (component < 0 || component > getNumComponents()) { - throw new IllegalArgumentException("Invalid component"); - } - return qTableComponentMapping[component]; + if (component < 0 || component > getNumComponents()) { + throw new IllegalArgumentException("Invalid component"); + } + return qTableComponentMapping[component]; } @Override public boolean isImageInfoValid() { - return imageInfoValid; + return imageInfoValid; } @Override public boolean isTableInfoValid() { - return tableInfoValid; + return tableInfoValid; } @Override public boolean getMarker(int marker) { - byte[][] data = null; - switch (marker) { - case APP0_MARKER: - case APP1_MARKER: - case APP2_MARKER: - case APP3_MARKER: - case APP4_MARKER: - case APP5_MARKER: - case APP6_MARKER: - case APP7_MARKER: - case APP8_MARKER: - case APP9_MARKER: - case APPA_MARKER: - case APPB_MARKER: - case APPC_MARKER: - case APPD_MARKER: - case APPE_MARKER: - case APPF_MARKER: - data = markers[marker - APP0_MARKER]; - break; - case COMMENT_MARKER: - data = commentMarker; - break; - default: - throw new IllegalArgumentException("Marker provided is invalid"); - } + byte[][] data = null; + switch (marker) { + case APP0_MARKER: + case APP1_MARKER: + case APP2_MARKER: + case APP3_MARKER: + case APP4_MARKER: + case APP5_MARKER: + case APP6_MARKER: + case APP7_MARKER: + case APP8_MARKER: + case APP9_MARKER: + case APPA_MARKER: + case APPB_MARKER: + case APPC_MARKER: + case APPD_MARKER: + case APPE_MARKER: + case APPF_MARKER: + data = markers[marker - APP0_MARKER]; + break; + case COMMENT_MARKER: + data = commentMarker; + break; + default: + throw new IllegalArgumentException("Marker provided is invalid"); + } - return data != null && data.length > 0; + return data != null && data.length > 0; } @Override public byte[][] getMarkerData(int marker) { - byte[][] data = null; + byte[][] data = null; - switch (marker) { - case APP0_MARKER: - case APP1_MARKER: - case APP2_MARKER: - case APP3_MARKER: - case APP4_MARKER: - case APP5_MARKER: - case APP6_MARKER: - case APP7_MARKER: - case APP8_MARKER: - case APP9_MARKER: - case APPA_MARKER: - case APPB_MARKER: - case APPC_MARKER: - case APPD_MARKER: - case APPE_MARKER: - case APPF_MARKER: - data = markers[marker - APP0_MARKER]; - break; - case COMMENT_MARKER: - // TODO: Add stuff for comment marker - break; - default: - throw new IllegalArgumentException("Marker provided is invalid"); - } - return data; + switch (marker) { + case APP0_MARKER: + case APP1_MARKER: + case APP2_MARKER: + case APP3_MARKER: + case APP4_MARKER: + case APP5_MARKER: + case APP6_MARKER: + case APP7_MARKER: + case APP8_MARKER: + case APP9_MARKER: + case APPA_MARKER: + case APPB_MARKER: + case APPC_MARKER: + case APPD_MARKER: + case APPE_MARKER: + case APPF_MARKER: + data = markers[marker - APP0_MARKER]; + break; + case COMMENT_MARKER: + // TODO: Add stuff for comment marker + break; + default: + throw new IllegalArgumentException("Marker provided is invalid"); + } + return data; } @Override public int getEncodedColorID() { - return colorID; + return colorID; } @Override public int getNumComponents() { - return numBands; + return numBands; } @Override public int getRestartInterval() { - return restartInterval; + return restartInterval; } @Override public int getDensityUnit() { - if (!getMarker(APP0_MARKER)) - throw new IllegalArgumentException("APP0 Marker not found."); - byte[] data = getValidAPP0Marker(); + if (!getMarker(APP0_MARKER)) + throw new IllegalArgumentException("APP0 Marker not found."); + byte[] data = getValidAPP0Marker(); - if (data == null) - throw new IllegalArgumentException("No valid APP0 Marker found"); + if (data == null) + throw new IllegalArgumentException("No valid APP0 Marker found"); - return data[7]; + return data[7]; } @Override public int getXDensity() { - if (!getMarker(APP0_MARKER)) - throw new IllegalArgumentException("APP0 Marker not found."); - byte[] data = getValidAPP0Marker(); + if (!getMarker(APP0_MARKER)) + throw new IllegalArgumentException("APP0 Marker not found."); + byte[] data = getValidAPP0Marker(); - if (data == null) - throw new IllegalArgumentException("No valid APP0 Marker found"); + if (data == null) + throw new IllegalArgumentException("No valid APP0 Marker found"); - // data[8] is the upper portion of the density value - // data[9] is the lower portion of the density value - int upper = data[8] << 8; // Shift it so we can merge with lower value. - int lower = data[9] & 0xFF; // Keep it in bounds 0 - 256 - return upper | lower; // Merge + // data[8] is the upper portion of the density value + // data[9] is the lower portion of the density value + int upper = data[8] << 8; // Shift it so we can merge with lower value. + int lower = data[9] & 0xFF; // Keep it in bounds 0 - 256 + return upper | lower; // Merge } @Override public int getYDensity() { - if (!getMarker(APP0_MARKER)) - throw new IllegalArgumentException("APP0 Marker not found."); - byte[] data = getValidAPP0Marker(); + if (!getMarker(APP0_MARKER)) + throw new IllegalArgumentException("APP0 Marker not found."); + byte[] data = getValidAPP0Marker(); - if (data == null) - throw new IllegalArgumentException("No valid APP0 Marker found"); + if (data == null) + throw new IllegalArgumentException("No valid APP0 Marker found"); - // data[10] is the upper portion of the density value - // data[11] is the lower portion of the density value - int upper = data[10] << 8; // Shift it so we can merge with lower value. - int lower = data[11] & 0xFF;// Keep it in bounds 0 - 256 - return upper | lower; // merge + // data[10] is the upper portion of the density value + // data[11] is the lower portion of the density value + int upper = data[10] << 8; // Shift it so we can merge with lower value. + int lower = data[11] & 0xFF;// Keep it in bounds 0 - 256 + return upper | lower; // merge } @Override public void setHorizontalSubsampling(int component, int subsample) { - if (component < 0 || component > getNumComponents()) { - throw new IllegalArgumentException("Invalid component"); - } + if (component < 0 || component > getNumComponents()) { + throw new IllegalArgumentException("Invalid component"); + } - horizontalSubsampleComponents[component] = subsample; + horizontalSubsampleComponents[component] = subsample; } @Override public void setVerticalSubsampling(int component, int subsample) { - if (component < 0 || component > getNumComponents()) { - throw new IllegalArgumentException("Invalid component"); - } + if (component < 0 || component > getNumComponents()) { + throw new IllegalArgumentException("Invalid component"); + } - verticalSubsampleComponents[component] = subsample; + verticalSubsampleComponents[component] = subsample; } @Override public void setQTable(int tableNum, JPEGQTable qTable) { - if (tableNum < 0 || tableNum > NUM_TABLES) - throw new IllegalArgumentException("tableNum must be [0-" - + (NUM_TABLES - 1) + "]"); + if (tableNum < 0 || tableNum > NUM_TABLES) + throw new IllegalArgumentException("tableNum must be [0-" + + (NUM_TABLES - 1) + "]"); - this.qTable[tableNum] = qTable; + this.qTable[tableNum] = qTable; } @Override public void setDCHuffmanTable(int tableNum, JPEGHuffmanTable huffTable) { - if (tableNum < 0 || tableNum > NUM_TABLES) - throw new IllegalArgumentException("tableNum must be [0-" - + (NUM_TABLES - 1) + "]"); + if (tableNum < 0 || tableNum > NUM_TABLES) + throw new IllegalArgumentException("tableNum must be [0-" + + (NUM_TABLES - 1) + "]"); - dcHuffmanTable[tableNum] = huffTable; + dcHuffmanTable[tableNum] = huffTable; } @Override public void setACHuffmanTable(int tableNum, JPEGHuffmanTable huffTable) { - if (tableNum < 0 || tableNum > NUM_TABLES) - throw new IllegalArgumentException("tableNum must be [0-" - + (NUM_TABLES - 1) + "]"); - acHuffmanTable[tableNum] = huffTable; + if (tableNum < 0 || tableNum > NUM_TABLES) + throw new IllegalArgumentException("tableNum must be [0-" + + (NUM_TABLES - 1) + "]"); + acHuffmanTable[tableNum] = huffTable; } @Override public void setACHuffmanComponentMapping(int component, int table) { - if (component < 0 || component > getNumComponents()) { - throw new IllegalArgumentException("Invalid component specified."); - } else if (table < 0 || table > NUM_TABLES) { - throw new IllegalArgumentException("Invalid table specified"); - } + if (component < 0 || component > getNumComponents()) { + throw new IllegalArgumentException("Invalid component specified."); + } else if (table < 0 || table > NUM_TABLES) { + throw new IllegalArgumentException("Invalid table specified"); + } - acHuffmanComponentMapping[component] = table; + acHuffmanComponentMapping[component] = table; } @Override public void setDCHuffmanComponentMapping(int component, int table) { - if (component < 0 || component > getNumComponents()) { - throw new IllegalArgumentException("Invalid component specified."); - } else if (table < 0 || table > NUM_TABLES) { - throw new IllegalArgumentException("Invalid table specified"); - } + if (component < 0 || component > getNumComponents()) { + throw new IllegalArgumentException("Invalid component specified."); + } else if (table < 0 || table > NUM_TABLES) { + throw new IllegalArgumentException("Invalid table specified"); + } - dcHuffmanComponentMapping[component] = table; + dcHuffmanComponentMapping[component] = table; } @Override public void setQTableComponentMapping(int component, int table) { - if (component < 0 || component > getNumComponents()) { - throw new IllegalArgumentException("Invalid component specified."); - } else if (table < 0 || table > NUM_TABLES) { - throw new IllegalArgumentException("Invalid table specified"); - } + if (component < 0 || component > getNumComponents()) { + throw new IllegalArgumentException("Invalid component specified."); + } else if (table < 0 || table > NUM_TABLES) { + throw new IllegalArgumentException("Invalid table specified"); + } - qTableComponentMapping[component] = table; + qTableComponentMapping[component] = table; } @Override public void setImageInfoValid(boolean flag) { - imageInfoValid = flag; + imageInfoValid = flag; } @Override public void setTableInfoValid(boolean flag) { - tableInfoValid = flag; + tableInfoValid = flag; } @Override public void setMarkerData(int marker, byte[][] data) { - if (data == null) { - return; - } + if (data == null) { + return; + } - switch (marker) { - case APP0_MARKER: - case APP1_MARKER: - case APP2_MARKER: - case APP3_MARKER: - case APP4_MARKER: - case APP5_MARKER: - case APP6_MARKER: - case APP7_MARKER: - case APP8_MARKER: - case APP9_MARKER: - case APPA_MARKER: - case APPB_MARKER: - case APPC_MARKER: - case APPD_MARKER: - case APPE_MARKER: - case APPF_MARKER: - markers[marker - APP0_MARKER] = data; - break; - case COMMENT_MARKER: - commentMarker = data; - break; - default: - throw new IllegalArgumentException("Marker provided is invalid"); - } + switch (marker) { + case APP0_MARKER: + case APP1_MARKER: + case APP2_MARKER: + case APP3_MARKER: + case APP4_MARKER: + case APP5_MARKER: + case APP6_MARKER: + case APP7_MARKER: + case APP8_MARKER: + case APP9_MARKER: + case APPA_MARKER: + case APPB_MARKER: + case APPC_MARKER: + case APPD_MARKER: + case APPE_MARKER: + case APPF_MARKER: + markers[marker - APP0_MARKER] = data; + break; + case COMMENT_MARKER: + commentMarker = data; + break; + default: + throw new IllegalArgumentException("Marker provided is invalid"); + } } @Override public void addMarkerData(int marker, byte[] data) { - if (data == null) { - return; - } - switch (marker) { - case APP0_MARKER: - case APP1_MARKER: - case APP2_MARKER: - case APP3_MARKER: - case APP4_MARKER: - case APP5_MARKER: - case APP6_MARKER: - case APP7_MARKER: - case APP8_MARKER: - case APP9_MARKER: - case APPA_MARKER: - case APPB_MARKER: - case APPC_MARKER: - case APPD_MARKER: - case APPE_MARKER: - case APPF_MARKER: - markers[marker - APP0_MARKER] = arrayAdd(markers[marker - - APP0_MARKER], data); - break; - case COMMENT_MARKER: - commentMarker = arrayAdd(commentMarker, data); - break; - default: - throw new IllegalArgumentException("Marker provided is invalid"); - } + if (data == null) { + return; + } + switch (marker) { + case APP0_MARKER: + case APP1_MARKER: + case APP2_MARKER: + case APP3_MARKER: + case APP4_MARKER: + case APP5_MARKER: + case APP6_MARKER: + case APP7_MARKER: + case APP8_MARKER: + case APP9_MARKER: + case APPA_MARKER: + case APPB_MARKER: + case APPC_MARKER: + case APPD_MARKER: + case APPE_MARKER: + case APPF_MARKER: + markers[marker - APP0_MARKER] = arrayAdd(markers[marker + - APP0_MARKER], data); + break; + case COMMENT_MARKER: + commentMarker = arrayAdd(commentMarker, data); + break; + default: + throw new IllegalArgumentException("Marker provided is invalid"); + } } @Override public void setRestartInterval(int restartInterval) { - this.restartInterval = restartInterval; + this.restartInterval = restartInterval; } @Override public void setDensityUnit(int unit) { - if (unit < 0 || unit > NUM_DENSITY_UNIT) { - throw new IllegalArgumentException("Invalid density unit."); - } + if (unit < 0 || unit > NUM_DENSITY_UNIT) { + throw new IllegalArgumentException("Invalid density unit."); + } - byte[] data = getValidAPP0Marker(); - if (data == null) { // We will create one now. - data = createAPP0MarkerData(); - // markers[0] = array of APP0_MARKER - markers[0] = arrayAdd(markers[0], data); - } + byte[] data = getValidAPP0Marker(); + if (data == null) { // We will create one now. + data = createAPP0MarkerData(); + // markers[0] = array of APP0_MARKER + markers[0] = arrayAdd(markers[0], data); + } - data[7] = (byte) unit; + data[7] = (byte) unit; } @Override public void setXDensity(int density) { - byte[] data = getValidAPP0Marker(); - if (data == null) { // We will create one now. - data = createAPP0MarkerData(); - // markers[0] = array of APP0_MARKER - markers[0] = arrayAdd(markers[0], data); - } + byte[] data = getValidAPP0Marker(); + if (data == null) { // We will create one now. + data = createAPP0MarkerData(); + // markers[0] = array of APP0_MARKER + markers[0] = arrayAdd(markers[0], data); + } - byte upper = (byte) (density >>> 8 & 0xFF); // unsigned shift to keep it - // positive - byte lower = (byte) (density & 0xFF); - data[8] = upper; - data[9] = lower; + byte upper = (byte) (density >>> 8 & 0xFF); // unsigned shift to keep it + // positive + byte lower = (byte) (density & 0xFF); + data[8] = upper; + data[9] = lower; } @Override public void setYDensity(int density) { - byte[] data = getValidAPP0Marker(); - if (data == null) { // We will create one now. - data = createAPP0MarkerData(); - // markers[0] = array of APP0_MARKER - markers[0] = arrayAdd(markers[0], data); - } + byte[] data = getValidAPP0Marker(); + if (data == null) { // We will create one now. + data = createAPP0MarkerData(); + // markers[0] = array of APP0_MARKER + markers[0] = arrayAdd(markers[0], data); + } - byte upper = (byte) (density >>> 8 & 0xFF); // unsigned shift to keep it - // positive - byte lower = (byte) (density & 0xFF); - data[10] = upper; - data[11] = lower; + byte upper = (byte) (density >>> 8 & 0xFF); // unsigned shift to keep it + // positive + byte lower = (byte) (density & 0xFF); + data[10] = upper; + data[11] = lower; } public void setWidth(int width) { - this.width = width; + this.width = width; } public void setHeight(int height) { - this.height = height; + this.height = height; } /** * get the quality value. - * + * * @return currently set quality value. */ public float getQuality() { - return quality; + return quality; } /** * Appends new data to original array - * + * * @param origArr * @param newArr * @return */ private byte[][] arrayAdd(byte[][] origArr, byte[] newArr) { - byte[][] newData; - if (origArr != null) { - newData = Arrays.copyOf(origArr, origArr.length + 1); - newData[origArr.length] = Arrays.copyOf(newArr, newArr.length); - } else { - newData = new byte[1][]; - newData[0] = Arrays.copyOf(newArr, newArr.length); - } + byte[][] newData; + if (origArr != null) { + newData = Arrays.copyOf(origArr, origArr.length + 1); + newData[origArr.length] = Arrays.copyOf(newArr, newArr.length); + } else { + newData = new byte[1][]; + newData[0] = Arrays.copyOf(newArr, newArr.length); + } - return newData; + return newData; } private byte[] getValidAPP0Marker() { - byte[][] app0Markers = getMarkerData(APP0_MARKER); - for (int i = 0; i < app0Markers.length; i++) { - byte[] data = app0Markers[i]; - if (data[0] == 'J' && data[1] == 'F' && data[2] == 'I' - && data[3] == 'F' && data[4] == 0x0) { - if (data[5] <= 1) { // version is 1 or below. - // We have a valid JFIF header. - return data; - } - } - } - return null; + byte[][] app0Markers = getMarkerData(APP0_MARKER); + for (int i = 0; i < app0Markers.length; i++) { + byte[] data = app0Markers[i]; + if (data[0] == 'J' && data[1] == 'F' && data[2] == 'I' + && data[3] == 'F' && data[4] == 0x0) { + if (data[5] <= 1) { // version is 1 or below. + // We have a valid JFIF header. + return data; + } + } + } + return null; } }