jdk/src/share/classes/com/sun/imageio/plugins/gif/GIFWritableImageMetadata.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 438 2ae294e4518c
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 438
diff changeset
     2
 * Copyright 2005-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.imageio.plugins.gif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.UnsupportedEncodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.nio.charset.Charset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.imageio.ImageTypeSpecifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.imageio.metadata.IIOInvalidTreeException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.imageio.metadata.IIOMetadata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.imageio.metadata.IIOMetadataNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.imageio.metadata.IIOMetadataFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.imageio.metadata.IIOMetadataFormatImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
class GIFWritableImageMetadata extends GIFImageMetadata {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    // package scope
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    NATIVE_FORMAT_NAME = "javax_imageio_gif_image_1.0";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    GIFWritableImageMetadata() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        super(true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
              NATIVE_FORMAT_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
              "com.sun.imageio.plugins.gif.GIFImageMetadataFormat",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public boolean isReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        // Fields from Image Descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        imageLeftPosition = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        imageTopPosition = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        imageWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        imageHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        interlaceFlag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        sortFlag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        localColorTable = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        // Fields from Graphic Control Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        disposalMethod = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        userInputFlag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        transparentColorFlag = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        delayTime = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        transparentColorIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        // Fields from Plain Text Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        hasPlainTextExtension = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        textGridLeft = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        textGridTop = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        textGridWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        textGridHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        characterCellWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        characterCellHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        textForegroundColor = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        textBackgroundColor = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        text = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // Fields from ApplicationExtension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        applicationIDs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        authenticationCodes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        applicationData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        // Fields from CommentExtension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        // List of byte[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        comments = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private byte[] fromISO8859(String data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            return data.getBytes("ISO-8859-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        } catch (UnsupportedEncodingException e) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   101
            return "".getBytes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    protected void mergeNativeTree(Node root) throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        Node node = root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (!node.getNodeName().equals(nativeMetadataFormatName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            fatal(node, "Root must be " + nativeMetadataFormatName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        node = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        while (node != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            String name = node.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            if (name.equals("ImageDescriptor")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                imageLeftPosition = getIntAttribute(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                                    "imageLeftPosition",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                                    -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                                    true, 0, 65535);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                imageTopPosition = getIntAttribute(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                                                   "imageTopPosition",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                                   -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                                                   true, 0, 65535);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                imageWidth = getIntAttribute(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                             "imageWidth",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                             -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                             true, 1, 65535);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                imageHeight = getIntAttribute(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                              "imageHeight",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                              -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                              true, 1, 65535);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                interlaceFlag = getBooleanAttribute(node, "interlaceFlag",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                                    false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            } else if (name.equals("LocalColorTable")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                int sizeOfLocalColorTable =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    getIntAttribute(node, "sizeOfLocalColorTable",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                                    true, 2, 256);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                if (sizeOfLocalColorTable != 2 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                    sizeOfLocalColorTable != 4 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    sizeOfLocalColorTable != 8 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                    sizeOfLocalColorTable != 16 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    sizeOfLocalColorTable != 32 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    sizeOfLocalColorTable != 64 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    sizeOfLocalColorTable != 128 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    sizeOfLocalColorTable != 256) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    fatal(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                          "Bad value for LocalColorTable attribute sizeOfLocalColorTable!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                sortFlag = getBooleanAttribute(node, "sortFlag", false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                localColorTable = getColorTable(node, "ColorTableEntry",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                                true, sizeOfLocalColorTable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            } else if (name.equals("GraphicControlExtension")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                String disposalMethodName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    getStringAttribute(node, "disposalMethod", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                       true, disposalMethodNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                disposalMethod = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                while(!disposalMethodName.equals(disposalMethodNames[disposalMethod])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    disposalMethod++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                userInputFlag = getBooleanAttribute(node, "userInputFlag",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                                    false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                transparentColorFlag =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    getBooleanAttribute(node, "transparentColorFlag",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                        false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                delayTime = getIntAttribute(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                            "delayTime",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                            -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                            true, 0, 65535);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                transparentColorIndex =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    getIntAttribute(node, "transparentColorIndex",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                    -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                    true, 0, 65535);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            } else if (name.equals("PlainTextExtension")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                hasPlainTextExtension = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                textGridLeft = getIntAttribute(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                                               "textGridLeft",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                                               -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                               true, 0, 65535);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                textGridTop = getIntAttribute(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                                              "textGridTop",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                              -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                                              true, 0, 65535);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                textGridWidth = getIntAttribute(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                                                "textGridWidth",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                                                -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                                                true, 1, 65535);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                textGridHeight = getIntAttribute(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                                                 "textGridHeight",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                                                 -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                                                 true, 1, 65535);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                characterCellWidth = getIntAttribute(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                                                     "characterCellWidth",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                                                     -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                                     true, 1, 65535);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                characterCellHeight = getIntAttribute(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                                      "characterCellHeight",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                                                      -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                                                      true, 1, 65535);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                textForegroundColor = getIntAttribute(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                                                      "textForegroundColor",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                                                      -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                                                      true, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                textBackgroundColor = getIntAttribute(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                                      "textBackgroundColor",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                                      -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                                                      true, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                // XXX The "text" attribute of the PlainTextExtension element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                // is not defined in the GIF image metadata format but it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                // present in the GIFImageMetadata class. Consequently it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                // used here but not required and with a default of "". See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                // bug 5082763.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                String textString =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                    getStringAttribute(node, "text", "", false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                text = fromISO8859(textString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            } else if (name.equals("ApplicationExtensions")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                IIOMetadataNode applicationExtension =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    (IIOMetadataNode)node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                if (!applicationExtension.getNodeName().equals("ApplicationExtension")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    fatal(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                          "Only a ApplicationExtension may be a child of a ApplicationExtensions!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                String applicationIDString =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    getStringAttribute(applicationExtension, "applicationID",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                       null, true, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                String authenticationCodeString =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    getStringAttribute(applicationExtension, "authenticationCode",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                                       null, true, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                Object applicationExtensionData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    applicationExtension.getUserObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                if (applicationExtensionData == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    !(applicationExtensionData instanceof byte[])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                    fatal(applicationExtension,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                          "Bad user object in ApplicationExtension!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                if (applicationIDs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    applicationIDs = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    authenticationCodes = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    applicationData = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                applicationIDs.add(fromISO8859(applicationIDString));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                authenticationCodes.add(fromISO8859(authenticationCodeString));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                applicationData.add(applicationExtensionData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            } else if (name.equals("CommentExtensions")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                Node commentExtension = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                if (commentExtension != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    while(commentExtension != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                        if (!commentExtension.getNodeName().equals("CommentExtension")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                            fatal(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                  "Only a CommentExtension may be a child of a CommentExtensions!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                        if (comments == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                            comments = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                        String comment =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                            getStringAttribute(commentExtension, "value", null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                               true, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                        comments.add(fromISO8859(comment));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                        commentExtension = commentExtension.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                fatal(node, "Unknown child of root node!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            node = node.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    protected void mergeStandardTree(Node root)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
      throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        Node node = root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if (!node.getNodeName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            .equals(IIOMetadataFormatImpl.standardMetadataFormatName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            fatal(node, "Root must be " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                  IIOMetadataFormatImpl.standardMetadataFormatName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        node = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        while (node != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            String name = node.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            if (name.equals("Chroma")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                Node childNode = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                while(childNode != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    String childName = childNode.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    if (childName.equals("Palette")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                        localColorTable = getColorTable(childNode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                                                        "PaletteEntry",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                                                        false, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    childNode = childNode.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            } else if (name.equals("Compression")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                Node childNode = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                while(childNode != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                    String childName = childNode.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                    if (childName.equals("NumProgressiveScans")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                        int numProgressiveScans =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                            getIntAttribute(childNode, "value", 4, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                                            true, 1, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                        if (numProgressiveScans > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                            interlaceFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    childNode = childNode.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            } else if (name.equals("Dimension")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                Node childNode = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                while(childNode != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    String childName = childNode.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    if (childName.equals("HorizontalPixelOffset")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                        imageLeftPosition = getIntAttribute(childNode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                                                            "value",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                                                            -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                                                            true, 0, 65535);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    } else if (childName.equals("VerticalPixelOffset")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                        imageTopPosition = getIntAttribute(childNode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                                                           "value",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                                                           -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                                                           true, 0, 65535);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    childNode = childNode.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            } else if (name.equals("Text")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                Node childNode = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                while(childNode != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    String childName = childNode.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    if (childName.equals("TextEntry") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                        getAttribute(childNode, "compression",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                                     "none", false).equals("none") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                        Charset.isSupported(getAttribute(childNode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                                                         "encoding",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                                         "ISO-8859-1",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                                                         false))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                        String value = getAttribute(childNode, "value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                        byte[] comment = fromISO8859(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                        if (comments == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                            comments = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                        comments.add(comment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    childNode = childNode.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            } else if (name.equals("Transparency")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                Node childNode = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                while(childNode != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    String childName = childNode.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                    if (childName.equals("TransparentIndex")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                        transparentColorIndex = getIntAttribute(childNode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                                                                "value",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                                                                -1, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                                                                true, 0, 255);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                        transparentColorFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    childNode = childNode.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            node = node.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public void setFromTree(String formatName, Node root)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        throws IIOInvalidTreeException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        mergeTree(formatName, root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
}