|
From: <ls...@us...> - 2007-06-25 07:44:51
|
Revision: 3301
http://jnode.svn.sourceforge.net/jnode/?rev=3301&view=rev
Author: lsantha
Date: 2007-06-25 00:44:50 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Openjdk integration.
Added Paths:
-----------
trunk/core/src/openjdk/com/com/sun/imageio/
trunk/core/src/openjdk/com/com/sun/imageio/metadata/
trunk/core/src/openjdk/com/com/sun/imageio/metadata/XmlChars.java
trunk/core/src/openjdk/com/com/sun/imageio/metadata/XmlNames.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/
trunk/core/src/openjdk/com/com/sun/imageio/plugins/bmp/
trunk/core/src/openjdk/com/com/sun/imageio/plugins/bmp/BMPConstants.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/bmp/BMPImageReader.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/bmp/BMPImageReaderSpi.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/bmp/BMPImageWriter.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/bmp/BMPImageWriterSpi.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/bmp/BMPMetadata.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/bmp/BMPMetadataFormat.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/bmp/BMPMetadataFormatResources.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/common/
trunk/core/src/openjdk/com/com/sun/imageio/plugins/common/BitFile.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/common/BogusColorSpace.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/common/I18N.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/common/I18NImpl.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/common/ImageUtil.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/common/InputStreamAdapter.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/common/LZWCompressor.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/common/LZWStringTable.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/common/PaletteBuilder.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/common/ReaderUtil.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/common/StandardMetadataFormat.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/common/StandardMetadataFormatResources.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/common/SubImageInputStream.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/common/iio-plugin.properties
trunk/core/src/openjdk/com/com/sun/imageio/plugins/gif/
trunk/core/src/openjdk/com/com/sun/imageio/plugins/gif/GIFImageMetadata.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/gif/GIFImageMetadataFormat.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/gif/GIFImageMetadataFormatResources.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/gif/GIFImageReader.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/gif/GIFImageReaderSpi.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/gif/GIFImageWriter.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/gif/GIFImageWriterSpi.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/gif/GIFMetadata.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/gif/GIFStreamMetadata.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/gif/GIFStreamMetadataFormat.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/gif/GIFStreamMetadataFormatResources.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/gif/GIFWritableImageMetadata.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/gif/GIFWritableStreamMetadata.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/png/
trunk/core/src/openjdk/com/com/sun/imageio/plugins/png/PNGImageReader.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/png/PNGImageReaderSpi.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/png/PNGImageWriter.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/png/PNGImageWriterSpi.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/png/PNGMetadata.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/png/PNGMetadataFormat.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/png/PNGMetadataFormatResources.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/png/RowFilter.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/wbmp/
trunk/core/src/openjdk/com/com/sun/imageio/plugins/wbmp/WBMPImageReader.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/wbmp/WBMPImageReaderSpi.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/wbmp/WBMPImageWriter.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/wbmp/WBMPImageWriterSpi.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/wbmp/WBMPMetadata.java
trunk/core/src/openjdk/com/com/sun/imageio/plugins/wbmp/WBMPMetadataFormat.java
trunk/core/src/openjdk/com/com/sun/imageio/spi/
trunk/core/src/openjdk/com/com/sun/imageio/spi/FileImageInputStreamSpi.java
trunk/core/src/openjdk/com/com/sun/imageio/spi/FileImageOutputStreamSpi.java
trunk/core/src/openjdk/com/com/sun/imageio/spi/InputStreamImageInputStreamSpi.java
trunk/core/src/openjdk/com/com/sun/imageio/spi/OutputStreamImageOutputStreamSpi.java
trunk/core/src/openjdk/com/com/sun/imageio/spi/RAFImageInputStreamSpi.java
trunk/core/src/openjdk/com/com/sun/imageio/spi/RAFImageOutputStreamSpi.java
Added: trunk/core/src/openjdk/com/com/sun/imageio/metadata/XmlChars.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/imageio/metadata/XmlChars.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/imageio/metadata/XmlChars.java 2007-06-25 07:44:50 UTC (rev 3301)
@@ -0,0 +1,431 @@
+/*
+ * reserved comment block
+ * DO NOT REMOVE OR ALTER!
+ */
+/*
+ * $Id: XmlChars.java,v 1.1.1.1 2000/11/23 01:53:35 edwingo Exp $
+ *
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Crimson" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact ap...@ap....
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Sun Microsystems, Inc.,
+ * http://www.sun.com. For more information on the Apache Software
+ * Foundation, please see <http://www.apache.org/>.
+ */
+
+package com.sun.imageio.metadata;
+
+
+/**
+ * Methods in this class are used to determine whether characters may
+ * appear in certain roles in XML documents. Such methods are used
+ * both to parse and to create such documents.
+ *
+ * @version 1.8
+ * @author David Brownell
+ */
+public class XmlChars
+{
+ // can't construct instances
+ private XmlChars () { }
+
+ /**
+ * Returns true if the argument, a UCS-4 character code, is valid in
+ * XML documents. Unicode characters fit into the low sixteen
+ * bits of a UCS-4 character, and pairs of Unicode <em>surrogate
+ * characters</em> can be combined to encode UCS-4 characters in
+ * documents containing only Unicode. (The <code>char</code> datatype
+ * in the Java Programming Language represents Unicode characters,
+ * including unpaired surrogates.)
+ *
+ * <P> In XML, UCS-4 characters can also be encoded by the use of
+ * <em>character references</em> such as <b>&#x12345678;</b>, which
+ * happens to refer to a character that is disallowed in XML documents.
+ * UCS-4 characters allowed in XML documents can be expressed with
+ * one or two Unicode characters.
+ *
+ * @param ucs4char The 32-bit UCS-4 character being tested.
+ */
+ static public boolean isChar (int ucs4char)
+ {
+ // [2] Char ::= #x0009 | #x000A | #x000D
+ // | [#x0020-#xD7FF]
+ // ... surrogates excluded!
+ // | [#xE000-#xFFFD]
+ // | [#x10000-#x10ffff]
+ return ((ucs4char >= 0x0020 && ucs4char <= 0xD7FF)
+ || ucs4char == 0x000A || ucs4char == 0x0009
+ || ucs4char == 0x000D
+ || (ucs4char >= 0xE000 && ucs4char <= 0xFFFD)
+ || (ucs4char >= 0x10000 && ucs4char <= 0x10ffff));
+ }
+
+ /**
+ * Returns true if the character is allowed to be a non-initial
+ * character in names according to the XML recommendation.
+ * @see #isNCNameChar
+ * @see #isLetter
+ */
+ public static boolean isNameChar (char c)
+ {
+ // [4] NameChar ::= Letter | Digit | '.' | '_' | ':'
+ // | CombiningChar | Extender
+
+ if (isLetter2 (c))
+ return true;
+ else if (c == '>')
+ return false;
+ else if (c == '.' || c == '-' || c == '_' || c == ':'
+ || isExtender (c))
+ return true;
+ else
+ return false;
+ }
+
+ /**
+ * Returns true if the character is allowed to be a non-initial
+ * character in unscoped names according to the rules of the XML
+ * Namespaces proposed recommendation. Except for precluding
+ * the colon (used to separate names from their scopes) these
+ * characters are just as allowed by the XML recommendation.
+ * @see #isNameChar
+ * @see #isLetter
+ */
+ public static boolean isNCNameChar (char c)
+ {
+ // [NC 5] NCNameChar ::= Letter | Digit | '.' | '_'
+ // | CombiningChar | Extender
+ return c != ':' && isNameChar (c);
+ }
+
+ /**
+ * Returns true if the character is allowed where XML supports
+ * whitespace characters, false otherwise.
+ */
+ public static boolean isSpace (char c)
+ {
+ return c == ' ' || c == '\t' || c == '\n' || c == '\r';
+ }
+
+
+ /*
+ * NOTE: java.lang.Character.getType() values are:
+ *
+ * UNASSIGNED = 0,
+ *
+ * UPPERCASE_LETTER = 1, // Lu
+ * LOWERCASE_LETTER = 2, // Ll
+ * TITLECASE_LETTER = 3, // Lt
+ * MODIFIER_LETTER = 4, // Lm
+ * OTHER_LETTER = 5, // Lo
+ * NON_SPACING_MARK = 6, // Mn
+ * ENCLOSING_MARK = 7, // Me
+ * COMBINING_SPACING_MARK = 8, // Mc
+ * DECIMAL_DIGIT_NUMBER = 9, // Nd
+ * LETTER_NUMBER = 10, // Nl
+ * OTHER_NUMBER = 11, // No
+ * SPACE_SEPARATOR = 12, // Zs
+ * LINE_SEPARATOR = 13, // Zl
+ * PARAGRAPH_SEPARATOR = 14, // Zp
+ * CONTROL = 15, // Cc
+ * FORMAT = 16, // Cf
+ * // 17 reserved for proposed Ci category
+ * PRIVATE_USE = 18, // Co
+ * SURROGATE = 19, // Cs
+ * DASH_PUNCTUATION = 20, // Pd
+ * START_PUNCTUATION = 21, // Ps
+ * END_PUNCTUATION = 22, // Pe
+ * CONNECTOR_PUNCTUATION = 23, // Pc
+ * OTHER_PUNCTUATION = 24, // Po
+ * MATH_SYMBOL = 25, // Sm
+ * CURRENCY_SYMBOL = 26, // Sc
+ * MODIFIER_SYMBOL = 27, // Sk
+ * OTHER_SYMBOL = 28; // So
+ */
+
+ /**
+ * Returns true if the character is an XML "letter". XML Names must
+ * start with Letters or a few other characters, but other characters
+ * in names must only satisfy the <em>isNameChar</em> predicate.
+ *
+ * @see #isNameChar
+ * @see #isNCNameChar
+ */
+ public static boolean isLetter (char c)
+ {
+ // [84] Letter ::= BaseChar | Ideographic
+ // [85] BaseChar ::= ... too much to repeat
+ // [86] Ideographic ::= ... too much to repeat
+
+ //
+ // Optimize the typical case.
+ //
+ if (c >= 'a' && c <= 'z')
+ return true;
+ if (c == '/')
+ return false;
+ if (c >= 'A' && c <= 'Z')
+ return true;
+
+ //
+ // Since the tables are too ridiculous to use in code,
+ // we're using the footnotes here to drive this test.
+ //
+ switch (Character.getType (c)) {
+ // app. B footnote says these are 'name start'
+ // chars' ...
+ case Character.LOWERCASE_LETTER: // Ll
+ case Character.UPPERCASE_LETTER: // Lu
+ case Character.OTHER_LETTER: // Lo
+ case Character.TITLECASE_LETTER: // Lt
+ case Character.LETTER_NUMBER: // Nl
+
+ // OK, here we just have some exceptions to check...
+ return !isCompatibilityChar (c)
+ // per "5.14 of Unicode", rule out some combiners
+ && !(c >= 0x20dd && c <= 0x20e0);
+
+ default:
+ // check for some exceptions: these are "alphabetic"
+ return ((c >= 0x02bb && c <= 0x02c1)
+ || c == 0x0559 || c == 0x06e5 || c == 0x06e6);
+ }
+ }
+
+ //
+ // XML 1.0 discourages "compatibility" characters in names; these
+ // were defined to permit passing through some information stored in
+ // older non-Unicode character sets. These always have alternative
+ // representations in Unicode, e.g. using combining chars.
+ //
+ private static boolean isCompatibilityChar (char c)
+ {
+ // the numerous comparisions here seem unavoidable,
+ // but the switch can reduce the number which must
+ // actually be executed.
+
+ switch ((c >> 8) & 0x0ff) {
+ case 0x00:
+ // ISO Latin/1 has a few compatibility characters
+ return c == 0x00aa || c == 0x00b5 || c == 0x00ba;
+
+ case 0x01:
+ // as do Latin Extended A and (parts of) B
+ return (c >= 0x0132 && c <= 0x0133)
+ || (c >= 0x013f && c <= 0x0140)
+ || c == 0x0149
+ || c == 0x017f
+ || (c >= 0x01c4 && c <= 0x01cc)
+ || (c >= 0x01f1 && c <= 0x01f3) ;
+
+ case 0x02:
+ // some spacing modifiers
+ return (c >= 0x02b0 && c <= 0x02b8)
+ || (c >= 0x02e0 && c <= 0x02e4);
+
+ case 0x03:
+ return c == 0x037a; // Greek
+
+ case 0x05:
+ return c == 0x0587; // Armenian
+
+ case 0x0e:
+ return c >= 0x0edc && c <= 0x0edd; // Laotian
+
+ case 0x11:
+ // big chunks of Hangul Jamo are all "compatibility"
+ return c == 0x1101
+ || c == 0x1104
+ || c == 0x1108
+ || c == 0x110a
+ || c == 0x110d
+ || (c >= 0x1113 && c <= 0x113b)
+ || c == 0x113d
+ || c == 0x113f
+ || (c >= 0x1141 && c <= 0x114b)
+ || c == 0x114d
+ || c == 0x114f
+ || (c >= 0x1151 && c <= 0x1153)
+ || (c >= 0x1156 && c <= 0x1158)
+ || c == 0x1162
+ || c == 0x1164
+ || c == 0x1166
+ || c == 0x1168
+ || (c >= 0x116a && c <= 0x116c)
+ || (c >= 0x116f && c <= 0x1171)
+ || c == 0x1174
+ || (c >= 0x1176 && c <= 0x119d)
+ || (c >= 0x119f && c <= 0x11a2)
+ || (c >= 0x11a9 && c <= 0x11aa)
+ || (c >= 0x11ac && c <= 0x11ad)
+ || (c >= 0x11b0 && c <= 0x11b6)
+ || c == 0x11b9
+ || c == 0x11bb
+ || (c >= 0x11c3 && c <= 0x11ea)
+ || (c >= 0x11ec && c <= 0x11ef)
+ || (c >= 0x11f1 && c <= 0x11f8)
+ ;
+
+ case 0x20:
+ return c == 0x207f; // superscript
+
+ case 0x21:
+ return
+ // various letterlike symbols
+ c == 0x2102
+ || c == 0x2107
+ || (c >= 0x210a && c <= 0x2113)
+ || c == 0x2115
+ || (c >= 0x2118 && c <= 0x211d)
+ || c == 0x2124
+ || c == 0x2128
+ || (c >= 0x212c && c <= 0x212d)
+ || (c >= 0x212f && c <= 0x2138)
+
+ // most Roman numerals (less 1K, 5K, 10K)
+ || (c >= 0x2160 && c <= 0x217f)
+ ;
+
+ case 0x30:
+ // some Hiragana
+ return c >= 0x309b && c <= 0x309c;
+
+ case 0x31:
+ // all Hangul Compatibility Jamo
+ return c >= 0x3131 && c <= 0x318e;
+
+ case 0xf9:
+ case 0xfa:
+ case 0xfb:
+ case 0xfc:
+ case 0xfd:
+ case 0xfe:
+ case 0xff:
+ // the whole "compatibility" area is for that purpose!
+ return true;
+
+ default:
+ // most of Unicode isn't flagged as being for compatibility
+ return false;
+ }
+ }
+
+ // guts of isNameChar/isNCNameChar
+ private static boolean isLetter2 (char c)
+ {
+ // [84] Letter ::= BaseChar | Ideographic
+ // [85] BaseChar ::= ... too much to repeat
+ // [86] Ideographic ::= ... too much to repeat
+ // [87] CombiningChar ::= ... too much to repeat
+
+ //
+ // Optimize the typical case.
+ //
+ if (c >= 'a' && c <= 'z')
+ return true;
+ if (c == '>')
+ return false;
+ if (c >= 'A' && c <= 'Z')
+ return true;
+
+ //
+ // Since the tables are too ridiculous to use in code,
+ // we're using the footnotes here to drive this test.
+ //
+ switch (Character.getType (c)) {
+ // app. B footnote says these are 'name start'
+ // chars' ...
+ case Character.LOWERCASE_LETTER: // Ll
+ case Character.UPPERCASE_LETTER: // Lu
+ case Character.OTHER_LETTER: // Lo
+ case Character.TITLECASE_LETTER: // Lt
+ case Character.LETTER_NUMBER: // Nl
+ // ... and these are name characters 'other
+ // than name start characters'
+ case Character.COMBINING_SPACING_MARK: // Mc
+ case Character.ENCLOSING_MARK: // Me
+ case Character.NON_SPACING_MARK: // Mn
+ case Character.MODIFIER_LETTER: // Lm
+ case Character.DECIMAL_DIGIT_NUMBER: // Nd
+
+ // OK, here we just have some exceptions to check...
+ return !isCompatibilityChar (c)
+ // per "5.14 of Unicode", rule out some combiners
+ && !(c >= 0x20dd && c <= 0x20e0);
+
+ default:
+ // added a character ...
+ return c == 0x0387;
+ }
+ }
+
+ private static boolean isDigit (char c)
+ {
+ // [88] Digit ::= ...
+
+ //
+ // java.lang.Character.isDigit is correct from the XML point
+ // of view except that it allows "fullwidth" digits.
+ //
+ return Character.isDigit (c)
+ && ! ( (c >= 0xff10) && (c <= 0xff19));
+ }
+
+ private static boolean isExtender (char c)
+ {
+ // [89] Extender ::= ...
+ return c == 0x00b7 || c == 0x02d0 || c == 0x02d1 || c == 0x0387
+ || c == 0x0640 || c == 0x0e46 || c == 0x0ec6
+ || c == 0x3005 || (c >= 0x3031 && c <= 0x3035)
+ || (c >= 0x309d && c <= 0x309e)
+ || (c >= 0x30fc && c <= 0x30fe)
+ ;
+ }
+}
Added: trunk/core/src/openjdk/com/com/sun/imageio/metadata/XmlNames.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/imageio/metadata/XmlNames.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/imageio/metadata/XmlNames.java 2007-06-25 07:44:50 UTC (rev 3301)
@@ -0,0 +1,234 @@
+/*
+ * reserved comment block
+ * DO NOT REMOVE OR ALTER!
+ */
+/*
+ * $Id: XmlNames.java,v 1.3 2001/03/16 04:01:34 edwingo Exp $
+ *
+ * The Apache Software License, Version 1.1
+ *
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ * if any, must include the following acknowledgment:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself,
+ * if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Crimson" and "Apache Software Foundation" must
+ * not be used to endorse or promote products derived from this
+ * software without prior written permission. For written
+ * permission, please contact ap...@ap....
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ * nor may "Apache" appear in their name, without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation and was
+ * originally based on software copyright (c) 1999, Sun Microsystems, Inc.,
+ * http://www.sun.com. For more information on the Apache Software
+ * Foundation, please see <http://www.apache.org/>.
+ */
+
+package com.sun.imageio.metadata;
+
+/**
+ * This class contains static methods used to determine whether identifiers
+ * may appear in certain roles in XML documents. Such methods are used
+ * both to parse and to create such documents.
+ *
+ * @version 1.4
+ * @author David Brownell
+ */
+public class XmlNames
+{
+ /**
+ * Useful strings from the DOM Level 2 Spec
+ */
+ public static final String
+ SPEC_XML_URI = "http://www.w3.org/XML/1998/namespace";
+ public static final String
+ SPEC_XMLNS_URI = "http://www.w3.org/2000/xmlns/";
+
+ private XmlNames () { }
+
+
+ /**
+ * Returns true if the value is a legal XML name.
+ *
+ * @param value the string being tested
+ */
+ public static boolean isName (String value)
+ {
+ if (value == null || "".equals(value))
+ return false;
+
+ char c = value.charAt (0);
+ if (!XmlChars.isLetter (c) && c != '_' && c != ':')
+ return false;
+ for (int i = 1; i < value.length (); i++)
+ if (!XmlChars.isNameChar (value.charAt (i)))
+ return false;
+ return true;
+ }
+
+ /**
+ * Returns true if the value is a legal "unqualified" XML name, as
+ * defined in the XML Namespaces proposed recommendation.
+ * These are normal XML names, except that they may not contain
+ * a "colon" character.
+ *
+ * @param value the string being tested
+ */
+ public static boolean isUnqualifiedName (String value)
+ {
+ if (value == null || value.length() == 0)
+ return false;
+
+ char c = value.charAt (0);
+ if (!XmlChars.isLetter (c) && c != '_')
+ return false;
+ for (int i = 1; i < value.length (); i++)
+ if (!XmlChars.isNCNameChar (value.charAt (i)))
+ return false;
+ return true;
+ }
+
+ /**
+ * Returns true if the value is a legal "qualified" XML name, as defined
+ * in the XML Namespaces proposed recommendation. Qualified names are
+ * composed of an optional prefix (an unqualified name), followed by a
+ * colon, and a required "local part" (an unqualified name). Prefixes are
+ * declared, and correspond to particular URIs which scope the "local
+ * part" of the name. (This method cannot check whether the prefix of a
+ * name has been declared.)
+ *
+ * @param value the string being tested
+ */
+ public static boolean isQualifiedName (String value)
+ {
+ if (value == null)
+ return false;
+
+ // [6] QName ::= (Prefix ':')? LocalPart
+ // [7] Prefix ::= NCName
+ // [8] LocalPart ::= NCName
+
+ int first = value.indexOf (':');
+
+ // no Prefix, only check LocalPart
+ if (first <= 0)
+ return isUnqualifiedName (value);
+
+ // Prefix exists, check everything
+
+ int last = value.lastIndexOf (':');
+ if (last != first)
+ return false;
+
+ return isUnqualifiedName (value.substring (0, first))
+ && isUnqualifiedName (value.substring (first + 1));
+ }
+
+ /**
+ * This method returns true if the identifier is a "name token"
+ * as defined in the XML specification. Like names, these
+ * may only contain "name characters"; however, they do not need
+ * to have letters as their initial characters. Attribute values
+ * defined to be of type NMTOKEN(S) must satisfy this predicate.
+ *
+ * @param token the string being tested
+ */
+ public static boolean isNmtoken (String token)
+ {
+ int length = token.length ();
+
+ for (int i = 0; i < length; i++)
+ if (!XmlChars.isNameChar (token.charAt (i)))
+ return false;
+ return true;
+ }
+
+
+ /**
+ * This method returns true if the identifier is a "name token" as
+ * defined by the XML Namespaces proposed recommendation.
+ * These are like XML "name tokens" but they may not contain the
+ * "colon" character.
+ *
+ * @see #isNmtoken
+ *
+ * @param token the string being tested
+ */
+ public static boolean isNCNmtoken (String token)
+ {
+ return isNmtoken (token) && token.indexOf (':') < 0;
+ }
+
+ /**
+ * Return the Prefix of qualifiedName. Does not check that Prefix is a
+ * valid NCName.
+ *
+ * @param qualifiedName name to find the Prefix of
+ * @return prefix or null if it has none
+ */
+ public static String getPrefix(String qualifiedName) {
+ // [6] QName ::= (Prefix ':')? LocalPart
+ // [7] Prefix ::= NCName
+ int index = qualifiedName.indexOf(':');
+ return index <= 0 ? null : qualifiedName.substring(0, index);
+ }
+
+ /**
+ * Return the LocalPart of qualifiedName. Does not check that Prefix is a
+ * valid NCName.
+ *
+ * @param qualifiedName name to find the LocalPart of
+ * @return LocalPart or null if it has none
+ */
+ public static String getLocalPart(String qualifiedName) {
+ // [6] QName ::= (Prefix ':')? LocalPart
+ // [8] LocalPart ::= NCName
+ int index = qualifiedName.indexOf(':');
+ if (index < 0) {
+ return qualifiedName;
+ }
+
+ // ':' at end of qualifiedName
+ if (index == qualifiedName.length() - 1) {
+ return null;
+ }
+
+ return qualifiedName.substring(index + 1);
+ }
+}
Added: trunk/core/src/openjdk/com/com/sun/imageio/plugins/bmp/BMPConstants.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/imageio/plugins/bmp/BMPConstants.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/imageio/plugins/bmp/BMPConstants.java 2007-06-25 07:44:50 UTC (rev 3301)
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.imageio.plugins.bmp;
+
+public interface BMPConstants {
+ // bmp versions
+ static final String VERSION_2 = "BMP v. 2.x";
+ static final String VERSION_3 = "BMP v. 3.x";
+ static final String VERSION_3_NT = "BMP v. 3.x NT";
+ static final String VERSION_4 = "BMP v. 4.x";
+ static final String VERSION_5 = "BMP v. 5.x";
+
+ // Color space types
+ static final int LCS_CALIBRATED_RGB = 0;
+ static final int LCS_sRGB = 1;
+ static final int LCS_WINDOWS_COLOR_SPACE = 2;
+ static final int PROFILE_LINKED = 3;
+ static final int PROFILE_EMBEDDED = 4;
+
+ // Compression Types
+ static final int BI_RGB = 0;
+ static final int BI_RLE8 = 1;
+ static final int BI_RLE4 = 2;
+ static final int BI_BITFIELDS = 3;
+ static final int BI_JPEG = 4;
+ static final int BI_PNG = 5;
+
+ static final String[] compressionTypeNames =
+ {"BI_RGB", "BI_RLE8", "BI_RLE4", "BI_BITFIELDS", "BI_JPEG", "BI_PNG"};
+}
Added: trunk/core/src/openjdk/com/com/sun/imageio/plugins/bmp/BMPImageReader.java
===================================================================
--- trunk/core/src/openjdk/com/com/sun/imageio/plugins/bmp/BMPImageReader.java (rev 0)
+++ trunk/core/src/openjdk/com/com/sun/imageio/plugins/bmp/BMPImageReader.java 2007-06-25 07:44:50 UTC (rev 3301)
@@ -0,0 +1,1748 @@
+/*
+ * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package com.sun.imageio.plugins.bmp;
+
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Transparency;
+import java.awt.color.ColorSpace;
+import java.awt.color.ICC_ColorSpace;
+import java.awt.color.ICC_Profile;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.ComponentColorModel;
+import java.awt.image.ComponentSampleModel;
+import java.awt.image.DataBuffer;
+import java.awt.image.DataBufferByte;
+import java.awt.image.DataBufferInt;
+import java.awt.image.DataBufferUShort;
+import java.awt.image.DirectColorModel;
+import java.awt.image.IndexColorModel;
+import java.awt.image.MultiPixelPackedSampleModel;
+import java.awt.image.PixelInterleavedSampleModel;
+import java.awt.image.Raster;
+import java.awt.image.SampleModel;
+import java.awt.image.SinglePixelPackedSampleModel;
+import java.awt.image.WritableRaster;
+
+import javax.imageio.IIOException;
+import javax.imageio.ImageIO;
+import javax.imageio.ImageReader;
+import javax.imageio.ImageReadParam;
+import javax.imageio.ImageTypeSpecifier;
+import javax.imageio.metadata.IIOMetadata;
+import javax.imageio.spi.ImageReaderSpi;
+import javax.imageio.stream.ImageInputStream;
+import javax.imageio.event.IIOReadProgressListener;
+import javax.imageio.event.IIOReadUpdateListener;
+import javax.imageio.event.IIOReadWarningListener;
+
+import java.io.*;
+import java.nio.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+import com.sun.imageio.plugins.common.ImageUtil;
+import com.sun.imageio.plugins.common.I18N;
+
+/** This class is the Java Image IO plugin reader for BMP images.
+ * It may subsample the image, clip the image, select sub-bands,
+ * and shift the decoded image origin if the proper decoding parameter
+ * are set in the provided <code>ImageReadParam</code>.
+ *
+ * This class supports Microsoft Windows Bitmap Version 3-5,
+ * as well as OS/2 Bitmap Version 2.x (for single-image BMP file).
+ */
+public class BMPImageReader extends ImageReader implements BMPConstants {
+ // BMP Image types
+ private static final int VERSION_2_1_BIT = 0;
+ private static final int VERSION_2_4_BIT = 1;
+ private static final int VERSION_2_8_BIT = 2;
+ private static final int VERSION_2_24_BIT = 3;
+
+ private static final int VERSION_3_1_BIT = 4;
+ private static final int VERSION_3_4_BIT = 5;
+ private static final int VERSION_3_8_BIT = 6;
+ private static final int VERSION_3_24_BIT = 7;
+
+ private static final int VERSION_3_NT_16_BIT = 8;
+ private static final int VERSION_3_NT_32_BIT = 9;
+
+ private static final int VERSION_4_1_BIT = 10;
+ private static final int VERSION_4_4_BIT = 11;
+ private static final int VERSION_4_8_BIT = 12;
+ private static final int VERSION_4_16_BIT = 13;
+ private static final int VERSION_4_24_BIT = 14;
+ private static final int VERSION_4_32_BIT = 15;
+
+ private static final int VERSION_3_XP_EMBEDDED = 16;
+ private static final int VERSION_4_XP_EMBEDDED = 17;
+ private static final int VERSION_5_XP_EMBEDDED = 18;
+
+ // BMP variables
+ private long bitmapFileSize;
+ private long bitmapOffset;
+ private long compression;
+ private long imageSize;
+ private byte palette[];
+ private int imageType;
+ private int numBands;
+ private boolean isBottomUp;
+ private int bitsPerPixel;
+ private int redMask, greenMask, blueMask, alphaMask;
+
+ private SampleModel sampleModel, originalSampleModel;
+ private ColorModel colorModel, originalColorModel;
+
+ /** The input stream where reads from */
+ private ImageInputStream iis = null;
+
+ /** Indicates whether the header is read. */
+ private boolean gotHeader = false;
+
+ /** The original image width. */
+ private int width;
+
+ /** The original image height. */
+ private int height;
+
+ /** The destination region. */
+ private Rectangle destinationRegion;
+
+ /** The source region. */
+ private Rectangle sourceRegion;
+
+ /** The metadata from the stream. */
+ private BMPMetadata metadata;
+
+ /** The destination image. */
+ private BufferedImage bi;
+
+ /** Indicates whether subsampled, subregion is required, and offset is
+ * defined
+ */
+ private boolean noTransform = true;
+
+ /** Indicates whether subband is selected. */
+ private boolean seleBand = false;
+
+ /** The scaling factors. */
+ private int scaleX, scaleY;
+
+ /** source and destination bands. */
+ private int[] sourceBands, destBands;
+
+ /** Constructs <code>BMPImageReader</code> from the provided
+ * <code>ImageReaderSpi</code>.
+ */
+ public BMPImageReader(ImageReaderSpi originator) {
+ super(originator);
+ }
+
+ /** Overrides the method defined in the superclass. */
+ public void setInput(Object input,
+ boolean seekForwardOnly,
+ boolean ignoreMetadata) {
+ super.setInput(input, seekForwardOnly, ignoreMetadata);
+ iis = (ImageInputStream) input; // Always works
+ if(iis != null)
+ iis.setByteOrder(ByteOrder.LITTLE_ENDIAN);
+ resetHeaderInfo();
+ }
+
+ /** Overrides the method defined in the superclass. */
+ public int getNumImages(boolean allowSearch) throws IOException {
+ if (iis == null) {
+ throw new IllegalStateException(I18N.getString("GetNumImages0"));
+ }
+ if (seekForwardOnly && allowSearch) {
+ throw new IllegalStateException(I18N.getString("GetNumImages1"));
+ }
+ return 1;
+ }
+
+ public int getWidth(int imageIndex) throws IOException {
+ checkIndex(imageIndex);
+ readHeader();
+ return width;
+ }
+
+ public int getHeight(int imageIndex) throws IOException {
+ checkIndex(imageIndex);
+ readHeader();
+ return height;
+ }
+
+ private void checkIndex(int imageIndex) {
+ if (imageIndex != 0) {
+ throw new IndexOutOfBoundsException(I18N.getString("BMPImageReader0"));
+ }
+ }
+
+ public void readHeader() throws IOException {
+ if (gotHeader)
+ return;
+
+ if (iis == null) {
+ throw new IllegalStateException("Input source not set!");
+ }
+ int profileData = 0, profileSize = 0;
+
+ this.metadata = new BMPMetadata();
+ iis.mark();
+
+ // read and check the magic marker
+ byte[] marker = new byte[2];
+ iis.read(marker);
+ if (marker[0] != 0x42 || marker[1] != 0x4d)
+ throw new IllegalArgumentException(I18N.getString("BMPImageReader1"));
+
+ // Read file size
+ bitmapFileSize = iis.readUnsignedInt();
+ // skip the two reserved fields
+ iis.skipBytes(4);
+
+ // Offset to the bitmap from the beginning
+ bitmapOffset = iis.readUnsignedInt();
+ // End File Header
+
+ // Start BitmapCoreHeader
+ long size = iis.readUnsignedInt();
+
+ if (size == 12) {
+ width = iis.readShort();
+ height = iis.readShort();
+ } else {
+ width = iis.readInt();
+ height = iis.readInt();
+ }
+
+ metadata.width = width;
+ metadata.height = height;
+
+ int planes = iis.readUnsignedShort();
+ bitsPerPixel = iis.readUnsignedShort();
+
+ //metadata.colorPlane = planes;
+ metadata.bitsPerPixel = (short)bitsPerPixel;
+
+ // As BMP always has 3 rgb bands, except for Version 5,
+ // which is bgra
+ numBands = 3;
+
+ if (size == 12) {
+ // Windows 2.x and OS/2 1.x
+ metadata.bmpVersion = VERSION_2;
+
+ // Classify the image type
+ if (bitsPerPixel == 1) {
+ imageType = VERSION_2_1_BIT;
+ } else if (bitsPerPixel == 4) {
+ imageType = VERSION_2_4_BIT;
+ } else if (bitsPerPixel == 8) {
+ imageType = VERSION_2_8_BIT;
+ } else if (bitsPerPixel == 24) {
+ imageType = VERSION_2_24_BIT;
+ }
+
+ // Read in the palette
+ int numberOfEntries = (int)((bitmapOffset - 14 - size) / 3);
+ int sizeOfPalette = numberOfEntries*3;
+ palette = new byte[sizeOfPalette];
+ iis.readFully(palette, 0, sizeOfPalette);
+ metadata.palette = palette;
+ metadata.paletteSize = numberOfEntries;
+ } else {
+ compression = iis.readUnsignedInt();
+ imageSize = iis.readUnsignedInt();
+ long xPelsPerMeter = iis.readInt();
+ long yPelsPerMeter = iis.readInt();
+ long colorsUsed = iis.readUnsignedInt();
+ long colorsImportant = iis.readUnsignedInt();
+
+ metadata.compression = (int)compression;
+ metadata.xPixelsPerMeter = (int)xPelsPerMeter;
+ metadata.yPixelsPerMeter = (int)yPelsPerMeter;
+ metadata.colorsUsed = (int)colorsUsed;
+ metadata.colorsImportant = (int)colorsImportant;
+
+ if (size == 40) {
+ // Windows 3.x and Windows NT
+ switch((int)compression) {
+
+ case BI_JPEG:
+ case BI_PNG:
+ metadata.bmpVersion = VERSION_3;
+ imageType = VERSION_3_XP_EMBEDDED;
+ break;
+
+ case BI_RGB: // No compression
+ case BI_RLE8: // 8-bit RLE compression
+ case BI_RLE4: // 4-bit RLE compression
+
+ // Read in the palette
+ int numberOfEntries = (int)((bitmapOffset-14-size) / 4);
+ int sizeOfPalette = numberOfEntries * 4;
+ palette = new byte[sizeOfPalette];
+ iis.readFully(palette, 0, sizeOfPalette);
+
+ metadata.palette = palette;
+ metadata.paletteSize = numberOfEntries;
+
+ if (bitsPerPixel == 1) {
+ imageType = VERSION_3_1_BIT;
+ } else if (bitsPerPixel == 4) {
+ imageType = VERSION_3_4_BIT;
+ } else if (bitsPerPixel == 8) {
+ imageType = VERSION_3_8_BIT;
+ } else if (bitsPerPixel == 24) {
+ imageType = VERSION_3_24_BIT;
+ } else if (bitsPerPixel == 16) {
+ imageType = VERSION_3_NT_16_BIT;
+
+ redMask = 0x7C00;
+ greenMask = 0x3E0;
+ blueMask = (1 << 5) - 1;// 0x1F;
+ metadata.redMask = redMask;
+ metadata.greenMask = greenMask;
+ metadata.blueMask = blueMask;
+ } else if (bitsPerPixel == 32) {
+ imageType = VERSION_3_NT_32_BIT;
+ redMask = 0x00FF0000;
+ greenMask = 0x0000FF00;
+ blueMask = 0x000000FF;
+ metadata.redMask = redMask;
+ metadata.greenMask = greenMask;
+ metadata.blueMask = blueMask;
+ }
+
+ metadata.bmpVersion = VERSION_3;
+ break;
+
+ case BI_BITFIELDS:
+
+ if (bitsPerPixel == 16) {
+ imageType = VERSION_3_NT_16_BIT;
+ } else if (bitsPerPixel == 32) {
+ imageType = VERSION_3_NT_32_BIT;
+ }
+
+ // BitsField encoding
+ redMask = (int)iis.readUnsignedInt();
+ greenMask = (int)iis.readUnsignedInt();
+ blueMask = (int)iis.readUnsignedInt();
+ metadata.redMask = redMask;
+ metadata.greenMask = greenMask;
+ metadata.blueMask = blueMask;
+
+ if (colorsUsed != 0) {
+ // there is a palette
+ sizeOfPalette = (int)colorsUsed*4;
+ palette = new byte[sizeOfPalette];
+ iis.readFully(palette, 0, sizeOfPalette);
+
+ metadata.palette = palette;
+ metadata.paletteSize = (int)colorsUsed;
+ }
+ metadata.bmpVersion = VERSION_3_NT;
+
+ break;
+ default:
+ throw new
+ RuntimeException(I18N.getString("BMPImageReader2"));
+ }
+ } else if (size == 108 || size == 124) {
+ // Windows 4.x BMP
+ if (size == 108)
+ metadata.bmpVersion = VERSION_4;
+ else if (size == 124)
+ metadata.bmpVersion = VERSION_5;
+
+ // rgb masks, valid only if comp is BI_BITFIELDS
+ redMask = (int)iis.readUnsignedInt();
+ greenMask = (int)iis.readUnsignedInt();
+ blueMask = (int)iis.readUnsignedInt();
+ // Only supported for 32bpp BI_RGB argb
+ alphaMask = (int)iis.readUnsignedInt();
+ long csType = iis.readUnsignedInt();
+ int redX = iis.readInt();
+ int redY = iis.readInt();
+ int redZ = iis.readInt();
+ int greenX = iis.readInt();
+ int greenY = iis.readInt();
+ int greenZ = iis.readInt();
+ int blueX = iis.readInt();
+ int blueY = iis.readInt();
+ int blueZ = iis.readInt();
+ long gammaRed = iis.readUnsignedInt();
+ long gammaGreen = iis.readUnsignedInt();
+ long gammaBlue = iis.readUnsignedInt();
+
+ if (size == 124) {
+ metadata.intent = iis.readInt();
+ profileData = iis.readInt();
+ profileSize = iis.readInt();
+ iis.skipBytes(4);
+ }
+
+ metadata.colorSpace = (int)csType;
+
+ if (csType == LCS_CALIBRATED_RGB) {
+ // All the new fields are valid only for this case
+ metadata.redX = redX;
+ metadata.redY = redY;
+ metadata.redZ = redZ;
+ metadata.greenX = greenX;
+ metadata.greenY = greenY;
+ metadata.greenZ = greenZ;
+ metadata.blueX = blueX;
+ metadata.blueY = blueY;
+ metadata.blueZ = blueZ;
+ metadata.gammaRed = (int)gammaRed;
+ metadata.gammaGreen = (int)gammaGreen;
+ metadata.gammaBlue = (int)gammaBlue;
+ }
+
+ // Read in the palette
+ int numberOfEntries = (int)((bitmapOffset-14-size) / 4);
+ int sizeOfPalette = numberOfEntries*4;
+ palette = new byte[sizeOfPalette];
+ iis.readFully(palette, 0, sizeOfPalette);
+ metadata.palette = palette;
+ metadata.paletteSize = numberOfEntries;
+
+ switch ((int)compression) {
+ case BI_JPEG:
+ case BI_PNG:
+ if (size == 108) {
+ imageType = VERSION_4_XP_EMBEDDED;
+ } else if (size == 124) {
+ imageType = VERSION_5_XP_EMBEDDED;
+ }
+ break;
+ default:
+ if (bitsPerPixel == 1) {
+ imageType = VERSION_4_1_BIT;
+ } else if (bitsPerPixel == 4) {
+ imageType = VERSION_4_4_BIT;
+ } else if (bitsPerPixel == 8) {
+ imageType = VERSION_4_8_BIT;
+ } else if (bitsPerPixel == 16) {
+ imageType = VERSION_4_16_BIT;
+ if ((int)compression == BI_RGB) {
+ redMask = 0x7C00;
+ greenMask = 0x3E0;
+ blueMask = 0x1F;
+ }
+ } else if (bitsPerPixel == 24) {
+ imageType = VERSION_4_24_BIT;
+ } else if (bitsPerPixel == 32) {
+ imageType = VERSION_4_32_BIT;
+ if ((int)compression == BI_RGB) {
+ redMask = 0x00FF0000;
+ greenMask = 0x0000FF00;
+ blueMask = 0x000000FF;
+ }
+ }
+
+ metadata.redMask = redMask;
+ metadata.greenMask = greenMask;
+ metadata.blueMask = blueMask;
+ metadata.alphaMask = alphaMask;
+ }
+ } else {
+ throw new
+ RuntimeException(I18N.getString("BMPImageReader3"));
+ }
+ }
+
+ if (height > 0) {
+ // bottom up image
+ isBottomUp = true;
+ } else {
+ // top down image
+ isBottomUp = false;
+ height = Math.abs(height);
+ }
+
+ // Reset Image Layout so there's only one tile.
+ //Define the color space
+ ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+ if (metadata.colorSpace == PROFILE_LINKED ||
+ metadata.colorSpace == PROFILE_EMBEDDED) {
+
+ iis.mark();
+ iis.skipBytes(profileData - size);
+ byte[] profile = new byte[profileSize];
+ iis.readFully(profile, 0, profileSize);
+ iis.reset();
+
+ try {
+ if (metadata.colorSpace == PROFILE_LINKED)
+ colorSpace =
+ new ICC_ColorSpace(ICC_Profile.getInstance(new String(profile)));
+ else
+ colorSpace =
+ new ICC_ColorSpace(ICC_Profile.getInstance(profile));
+ } catch (Exception e) {
+ colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+ }
+ }
+
+ if (bitsPerPixel == 0 ||
+ compression == BI_JPEG || compression == BI_PNG )
+ {
+ // the colorModel and sampleModel will be initialzed
+ // by the reader of embedded image
+ colorModel = null;
+ sampleModel = null;
+ } else if (bitsPerPixel == 1 || bitsPerPixel == 4 || bitsPerPixel == 8) {
+ // When number of bitsPerPixel is <= 8, we use IndexColorModel.
+ numBands = 1;
+
+ if (bitsPerPixel == 8) {
+ int[] bandOffsets = new int[numBands];
+ for (int i = 0; i < numBands; i++) {
+ bandOffsets[i] = numBands -1 -i;
+ }
+ sampleModel =
+ new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
+ width, height,
+ numBands,
+ numBands * width,
+ bandOffsets);
+ } else {
+ // 1 and 4 bit pixels can be stored in a packed format.
+ sampleModel =
+ new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
+ width, height,
+ bitsPerPixel);
+ }
+
+ // Create IndexColorModel from the palette.
+ byte r[], g[], b[];
+ if (imageType == VERSION_2_1_BIT ||
+ imageType == VERSION_2_4_BIT ||
+ imageType == VERSION_2_8_BIT) {
+
+
+ size = palette.length/3;
+
+ if (size > 256) {
+ size = 256;
+ }
+
+ int off;
+ r = new byte[(int)size];
+ g = new byte[(int)size];
+ b = new byte[(int)size];
+ for (int i=0; i<(int)size; i++) {
+ off = 3 * i;
+ b[i] = palette[off];
+ g[i] = palette[off+1];
+ r[i] = palette[off+2];
+ }
+ } else {
+ size = palette.length/4;
+
+ if (size > 256) {
+ size = 256;
+ }
+
+ int off;
+ r = new byte[(int)size];
+ g = new byte[(int)size];
+ b = new byte[(int)size];
+ for (int i=0; i<size; i++) {
+ off = 4 * i;
+ b[i] = palette[off];
+ g[i] = palette[off+1];
+ r[i] = palette[off+2];
+ }
+ }
+
+ if (ImageUtil.isIndicesForGrayscale(r, g, b))
+ colorModel =
+ ImageUtil.createColorModel(null, sampleModel);
+ else
+ colorModel = new IndexColorModel(bitsPerPixel, (int)size, r, g, b);
+ } else if (bitsPerPixel == 16) {
+ numBands = 3;
+ sampleModel =
+ new SinglePixelPackedSampleModel(DataBuffer.TYPE_USHORT,
+ width, height,
+ new int[] {redMask, greenMask, blueMask});
+
+ colorModel =
+ new DirectColorModel(colorSpace,
+ 16, redMask, greenMask, blueMask, 0,
+ false, DataBuffer.TYPE_USHORT);
+
+ } else if (bitsPerPixel == 32) {
+ numBands = alphaMask == 0 ? 3 : 4;
+
+ // The number of bands in the SampleModel is determined by
+ // the length of the mask array passed in.
+ int[] bitMasks = numBands == 3 ?
+ new int[] {redMask, greenMask, blueMask} :
+ new int[] {redMask, greenMask, blueMask, alphaMask};
+
+ sampleModel =
+ new SinglePixelPackedSampleModel(DataBuffer.TYPE_INT,
+ width, height,
+ bitMasks);
+
+ colorModel =
+ new DirectColorModel(colorSpace,
+ 32, redMask, greenMask, blueMask, alphaMask,
+ false, DataBuffer.TYPE_INT);
+ } else {
+ numBands = 3;
+ // Create SampleModel
+ int[] bandOffsets = new int[numBands];
+ for (int i = 0; i < numBands; i++) {
+ bandOffsets[i] = numBands -1 -i;
+ }
+
+ sampleModel =
+ new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
+ width, height,
+ numBands,
+ numBands * width,
+ bandOffsets);
+
+ colorModel =
+ ImageUtil.createColorModel(colorSpace, sampleModel);
+ }
+
+ originalSampleModel = sampleModel;
+ originalColorModel = colorModel;
+
+ // Reset to the start of bitmap; then jump to the
+ //start of image data
+ iis.reset();
+ iis.skipBytes(bitmapOffset);
+ gotHeader = true;
+ }
+
+ public Iterator getImageTypes(int imageIndex)
+ throws IOException {
+ checkIndex(imageIndex);
+ readHeader();
+ ArrayList list = new ArrayList(1);
+ list.add(new ImageTypeSpecifier(originalColorModel,
+ originalSampleModel));
+ return list.iterator();
+ }
+
+ public ImageReadParam getDefaultReadParam() {
+ return new ImageReadParam();
+ }
+
+ public IIOMetadata getImageMetadata(int imageIndex)
+ throws IOException {
+ checkIndex(imageIndex);
+ if (metadata == null) {
+ readHeader();
+ }
+ return metadata;
+ }
+
+ public IIOMetadata getStreamMetadata() throws IOException {
+ return null;
+ }
+
+ public boolean isRandomAccessEasy(int imageIndex) throws IOException {
+ checkIndex(imageIndex);
+ readHeader();
+ return metadata.compression == BI_RGB;
+ }
+
+ public BufferedImage read(int imageIndex, ImageReadParam param)
+ throws IOException {
+
+ if (iis == null) {
+ throw new IllegalStateException(I18N.getString("BMPImageReader5"));
+ }
+
+ checkIndex(imageIndex);
+ clearAbortRequest();
+ processImageStarted(imageIndex);
+
+ if (param == null)
+ param = getDefaultReadParam();
+
+ //read header
+ readHeader();
+
+ sourceRegion = new Rectangle(0, 0, 0, 0);
+ destinationRegion = new Rectangle(0, 0, 0, 0);
+
+ computeRegions(param, this.width, this.height,
+ param.getDestination(),
+ sourceRegion,
+ destinationRegion);
+
+ scaleX = param.getSourceXSubsampling();
+ scaleY = param.getSourceYSubsampling();
+
+ // If the destination band is set used it
+ sourceBands = param.getSourceBands();
+ destBands = param.getDestinationBands();
+
+ seleBand = (sourceBands != null) && (destBands != null);
+ noTransform =
+ destinationRegion.equals(new Rectangle(0, 0, width, height)) ||
+ seleBand;
+
+ if (!seleBand) {
+ sourceBands = new int[numBands];
+ destBands = new int[numBands];
+ for (int i = 0; i < numBands; i++)
+ destBands[i] = sourceBands[i] = i;
+ }
+
+ // If the destination is provided, then use it. Otherwise, create new one
+ bi = param.getDestination();
+
+ // Get the image data.
+ WritableRaster raster = null;
+
+ if (bi == null) {
+ if (sampleModel != null && colorModel != null) {
+ sampleModel =
+ sampleModel.createCompatibleSampleModel(destinationRegion.x +
+ destinationRegion.width,
+ destinationRegion.y +
+ destinationRegion.height);
+ if (seleBand)
+ sampleModel = sampleModel.createSubsetSampleModel(sourceBands);
+ raster = Raster.createWritableRaster(sampleModel, new Point());
+ bi = new BufferedImage(colorModel, raster, false, null);
+ }
+ } else {
+ raster = bi.getWritableTile(0, 0);
+ sampleModel = bi.getSampleModel();
+ colorModel = bi.getColorModel();
+
+ noTransform &= destinationRegion.equals(raster.getBounds());
+ }
+
+ byte bdata[] = null; // buffer for byte data
+ short sdata[] = null; // buffer for short data
+ int idata[] = null; // buffer for int data
+
+ // the sampleModel can be null in case of embedded image
+ if (sampleModel != null) {
+ if (sampleModel.getDataType() == DataBuffer.TYPE_BYTE)
+ bdata = (byte[])
+ ((DataBufferByte)raster.getDataBuffer()).getData();
+ else if (sampleModel.getDataType() == DataBuffer.TYPE_USHOR...
[truncated message content] |