jdk/src/share/classes/com/sun/imageio/plugins/png/PNGMetadata.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 1734 861400729115
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2001 Sun Microsystems, Inc.  All Rights Reserved.
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.png;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.image.IndexColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.image.SampleModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.imageio.ImageTypeSpecifier;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.imageio.metadata.IIOInvalidTreeException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.imageio.metadata.IIOMetadata;
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 javax.imageio.metadata.IIOMetadataNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class PNGMetadata extends IIOMetadata implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    // package scope
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        nativeMetadataFormatName = "javax_imageio_png_1.0";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    protected static final String nativeMetadataFormatClassName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        = "com.sun.imageio.plugins.png.PNGMetadataFormat";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    // Color types for IHDR chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static final String[] IHDR_colorTypeNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        "Grayscale", null, "RGB", "Palette",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        "GrayAlpha", null, "RGBAlpha"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static final int[] IHDR_numChannels = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        1, 0, 3, 3, 2, 0, 4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // Bit depths for IHDR chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public static final String[] IHDR_bitDepths = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        "1", "2", "4", "8", "16"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // Compression methods for IHDR chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static final String[] IHDR_compressionMethodNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        "deflate"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // Filter methods for IHDR chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static final String[] IHDR_filterMethodNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        "adaptive"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // Interlace methods for IHDR chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static final String[] IHDR_interlaceMethodNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        "none", "adam7"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    // Compression methods for iCCP chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public static final String[] iCCP_compressionMethodNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        "deflate"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // Compression methods for zTXt chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static final String[] zTXt_compressionMethodNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        "deflate"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // "Unknown" unit for pHYs chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public static final int PHYS_UNIT_UNKNOWN = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // "Meter" unit for pHYs chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public static final int PHYS_UNIT_METER = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // Unit specifiers for pHYs chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static final String[] unitSpecifierNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        "unknown", "meter"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    // Rendering intents for sRGB chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public static final String[] renderingIntentNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        "Perceptual", // 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        "Relative colorimetric", // 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        "Saturation", // 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        "Absolute colorimetric" // 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    // Color space types for Chroma->ColorSpaceType node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public static final String[] colorSpaceTypeNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        "GRAY", null, "RGB", "RGB",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        "GRAY", null, "RGB"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    // IHDR chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public boolean IHDR_present;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public int IHDR_width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public int IHDR_height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public int IHDR_bitDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public int IHDR_colorType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public int IHDR_compressionMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public int IHDR_filterMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public int IHDR_interlaceMethod; // 0 == none, 1 == adam7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    // PLTE chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public boolean PLTE_present;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public byte[] PLTE_red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public byte[] PLTE_green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public byte[] PLTE_blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    // If non-null, used to reorder palette entries during encoding in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    // order to minimize the size of the tRNS chunk.  Thus an index of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    // 'i' in the source should be encoded as index 'PLTE_order[i]'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    // PLTE_order will be null unless 'initialize' is called with an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    // IndexColorModel image type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public int[] PLTE_order = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    // bKGD chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    // If external (non-PNG sourced) data has red = green = blue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    // always store it as gray and promote when writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public boolean bKGD_present;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public int bKGD_colorType; // PNG_COLOR_GRAY, _RGB, or _PALETTE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public int bKGD_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public int bKGD_gray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public int bKGD_red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public int bKGD_green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public int bKGD_blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    // cHRM chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public boolean cHRM_present;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public int cHRM_whitePointX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public int cHRM_whitePointY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public int cHRM_redX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public int cHRM_redY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public int cHRM_greenX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public int cHRM_greenY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public int cHRM_blueX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public int cHRM_blueY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    // gAMA chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public boolean gAMA_present;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public int gAMA_gamma;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    // hIST chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public boolean hIST_present;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public char[] hIST_histogram;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    // iCCP chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public boolean iCCP_present;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public String iCCP_profileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public int iCCP_compressionMethod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public byte[] iCCP_compressedProfile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    // iTXt chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public ArrayList iTXt_keyword = new ArrayList(); // Strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public ArrayList iTXt_compressionFlag = new ArrayList(); // Integers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public ArrayList iTXt_compressionMethod = new ArrayList(); // Integers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public ArrayList iTXt_languageTag = new ArrayList(); // Strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public ArrayList iTXt_translatedKeyword = new ArrayList(); // Strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public ArrayList iTXt_text = new ArrayList(); // Strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    // pHYs chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public boolean pHYs_present;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public int pHYs_pixelsPerUnitXAxis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public int pHYs_pixelsPerUnitYAxis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public int pHYs_unitSpecifier; // 0 == unknown, 1 == meter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    // sBIT chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public boolean sBIT_present;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public int sBIT_colorType; // PNG_COLOR_GRAY, _GRAY_ALPHA, _RGB, _RGB_ALPHA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public int sBIT_grayBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public int sBIT_redBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public int sBIT_greenBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public int sBIT_blueBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public int sBIT_alphaBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    // sPLT chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public boolean sPLT_present;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public String sPLT_paletteName; // 1-79 characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public int sPLT_sampleDepth; // 8 or 16
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public int[] sPLT_red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public int[] sPLT_green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public int[] sPLT_blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public int[] sPLT_alpha;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public int[] sPLT_frequency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    // sRGB chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public boolean sRGB_present;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public int sRGB_renderingIntent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    // tEXt chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public ArrayList tEXt_keyword = new ArrayList(); // 1-79 char Strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public ArrayList tEXt_text = new ArrayList(); // Strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    // tIME chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public boolean tIME_present;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public int tIME_year;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public int tIME_month;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public int tIME_day;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public int tIME_hour;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public int tIME_minute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public int tIME_second;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    // tRNS chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    // If external (non-PNG sourced) data has red = green = blue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    // always store it as gray and promote when writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public boolean tRNS_present;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public int tRNS_colorType; // PNG_COLOR_GRAY, _RGB, or _PALETTE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public byte[] tRNS_alpha; // May have fewer entries than PLTE_red, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public int tRNS_gray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public int tRNS_red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public int tRNS_green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public int tRNS_blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    // zTXt chunk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public ArrayList zTXt_keyword = new ArrayList(); // Strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public ArrayList zTXt_compressionMethod = new ArrayList(); // Integers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public ArrayList zTXt_text = new ArrayList(); // Strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    // Unknown chunks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public ArrayList unknownChunkType = new ArrayList(); // Strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public ArrayList unknownChunkData = new ArrayList(); // byte arrays
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public PNGMetadata() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        super(true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
              nativeMetadataFormatName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
              nativeMetadataFormatClassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
              null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public PNGMetadata(IIOMetadata metadata) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        // TODO -- implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Sets the IHDR_bitDepth and IHDR_colorType variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * The <code>numBands</code> parameter is necessary since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * we may only be writing a subset of the image bands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public void initialize(ImageTypeSpecifier imageType, int numBands) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        ColorModel colorModel = imageType.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        SampleModel sampleModel = imageType.getSampleModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        // Initialize IHDR_bitDepth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        int[] sampleSize = sampleModel.getSampleSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        int bitDepth = sampleSize[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        // Choose max bit depth over all channels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        // Fixes bug 4413109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        for (int i = 1; i < sampleSize.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            if (sampleSize[i] > bitDepth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                bitDepth = sampleSize[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        // Multi-channel images must have a bit depth of 8 or 16
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (sampleSize.length > 1 && bitDepth < 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            bitDepth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        // Round bit depth up to a power of 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (bitDepth > 2 && bitDepth < 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            bitDepth = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        } else if (bitDepth > 4 && bitDepth < 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            bitDepth = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        } else if (bitDepth > 8 && bitDepth < 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            bitDepth = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        } else if (bitDepth > 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            throw new RuntimeException("bitDepth > 16!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        IHDR_bitDepth = bitDepth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        // Initialize IHDR_colorType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (colorModel instanceof IndexColorModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            IndexColorModel icm = (IndexColorModel)colorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            int size = icm.getMapSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            byte[] reds = new byte[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            icm.getReds(reds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            byte[] greens = new byte[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            icm.getGreens(greens);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            byte[] blues = new byte[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            icm.getBlues(blues);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            // Determine whether the color tables are actually a gray ramp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            // if the color type has not been set previously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            boolean isGray = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            if (!IHDR_present ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                (IHDR_colorType != PNGImageReader.PNG_COLOR_PALETTE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                isGray = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                int scale = 255/((1 << IHDR_bitDepth) - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                for (int i = 0; i < size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    byte red = reds[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    if ((red != (byte)(i*scale)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                        (red != greens[i]) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                        (red != blues[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                        isGray = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            // Determine whether transparency exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            boolean hasAlpha = colorModel.hasAlpha();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            byte[] alpha = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            if (hasAlpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                alpha = new byte[size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                icm.getAlphas(alpha);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
             * NB: PNG_COLOR_GRAY_ALPHA color type may be not optimal for images
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
             * contained more than 1024 pixels (or even than 768 pixels in case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
             * single transparent pixel in palette).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
             * For such images alpha samples in raster will occupy more space than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
             * it is required to store palette so it could be reasonable to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
             * use PNG_COLOR_PALETTE color type for large images.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            if (isGray && hasAlpha && (bitDepth == 8 || bitDepth == 16)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                IHDR_colorType = PNGImageReader.PNG_COLOR_GRAY_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            } else if (isGray && !hasAlpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                IHDR_colorType = PNGImageReader.PNG_COLOR_GRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                IHDR_colorType = PNGImageReader.PNG_COLOR_PALETTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                PLTE_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                PLTE_order = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                PLTE_red = (byte[])reds.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                PLTE_green = (byte[])greens.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                PLTE_blue = (byte[])blues.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                if (hasAlpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    tRNS_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                    tRNS_colorType = PNGImageReader.PNG_COLOR_PALETTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                    PLTE_order = new int[alpha.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    // Reorder the palette so that non-opaque entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    // come first.  Since the tRNS chunk does not have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    // to store trailing 255's, this can save a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                    // considerable amount of space when encoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    // images with only one transparent pixel value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    // e.g., images from GIF sources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    byte[] newAlpha = new byte[alpha.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    // Scan for non-opaque entries and assign them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    // positions starting at 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    int newIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    for (int i = 0; i < alpha.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                        if (alpha[i] != (byte)255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                            PLTE_order[i] = newIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                            newAlpha[newIndex] = alpha[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                            ++newIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                    int numTransparent = newIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                    // Scan for opaque entries and assign them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    // positions following the non-opaque entries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                    for (int i = 0; i < alpha.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                        if (alpha[i] == (byte)255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                            PLTE_order[i] = newIndex++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    // Reorder the palettes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    byte[] oldRed = PLTE_red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                    byte[] oldGreen = PLTE_green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    byte[] oldBlue = PLTE_blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    int len = oldRed.length; // All have the same length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    PLTE_red = new byte[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    PLTE_green = new byte[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    PLTE_blue = new byte[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                        PLTE_red[PLTE_order[i]] = oldRed[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                        PLTE_green[PLTE_order[i]] = oldGreen[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                        PLTE_blue[PLTE_order[i]] = oldBlue[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                    // Copy only the transparent entries into tRNS_alpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    tRNS_alpha = new byte[numTransparent];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                    System.arraycopy(newAlpha, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                                     tRNS_alpha, 0, numTransparent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            if (numBands == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                IHDR_colorType = PNGImageReader.PNG_COLOR_GRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            } else if (numBands == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                IHDR_colorType = PNGImageReader.PNG_COLOR_GRAY_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            } else if (numBands == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                IHDR_colorType = PNGImageReader.PNG_COLOR_RGB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            } else if (numBands == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                IHDR_colorType = PNGImageReader.PNG_COLOR_RGB_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                throw new RuntimeException("Number of bands not 1-4!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        IHDR_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    public boolean isReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    private ArrayList cloneBytesArrayList(ArrayList in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        if (in == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            ArrayList list = new ArrayList(in.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            Iterator iter = in.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                Object o = iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                if (o == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    list.add(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    list.add(((byte[])o).clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            return list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    // Deep clone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        PNGMetadata metadata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            metadata = (PNGMetadata)super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        // unknownChunkData needs deep clone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        metadata.unknownChunkData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            cloneBytesArrayList(this.unknownChunkData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return metadata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public Node getAsTree(String formatName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        if (formatName.equals(nativeMetadataFormatName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            return getNativeTree();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        } else if (formatName.equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                   (IIOMetadataFormatImpl.standardMetadataFormatName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            return getStandardTree();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            throw new IllegalArgumentException("Not a recognized format!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    private Node getNativeTree() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        IIOMetadataNode node = null; // scratch node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        IIOMetadataNode root = new IIOMetadataNode(nativeMetadataFormatName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        // IHDR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if (IHDR_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            IIOMetadataNode IHDR_node = new IIOMetadataNode("IHDR");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            IHDR_node.setAttribute("width", Integer.toString(IHDR_width));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            IHDR_node.setAttribute("height", Integer.toString(IHDR_height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            IHDR_node.setAttribute("bitDepth",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                                   Integer.toString(IHDR_bitDepth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            IHDR_node.setAttribute("colorType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                                   IHDR_colorTypeNames[IHDR_colorType]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            // IHDR_compressionMethod must be 0 in PNG 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            IHDR_node.setAttribute("compressionMethod",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                          IHDR_compressionMethodNames[IHDR_compressionMethod]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            // IHDR_filterMethod must be 0 in PNG 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            IHDR_node.setAttribute("filterMethod",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                                    IHDR_filterMethodNames[IHDR_filterMethod]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            IHDR_node.setAttribute("interlaceMethod",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                              IHDR_interlaceMethodNames[IHDR_interlaceMethod]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            root.appendChild(IHDR_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        // PLTE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        if (PLTE_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            IIOMetadataNode PLTE_node = new IIOMetadataNode("PLTE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            int numEntries = PLTE_red.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            for (int i = 0; i < numEntries; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                IIOMetadataNode entry = new IIOMetadataNode("PLTEEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                entry.setAttribute("index", Integer.toString(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                entry.setAttribute("red",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                                   Integer.toString(PLTE_red[i] & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                entry.setAttribute("green",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                                   Integer.toString(PLTE_green[i] & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                entry.setAttribute("blue",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                                   Integer.toString(PLTE_blue[i] & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                PLTE_node.appendChild(entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            root.appendChild(PLTE_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        // bKGD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if (bKGD_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            IIOMetadataNode bKGD_node = new IIOMetadataNode("bKGD");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            if (bKGD_colorType == PNGImageReader.PNG_COLOR_PALETTE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                node = new IIOMetadataNode("bKGD_Palette");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                node.setAttribute("index", Integer.toString(bKGD_index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            } else if (bKGD_colorType == PNGImageReader.PNG_COLOR_GRAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                node = new IIOMetadataNode("bKGD_Grayscale");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                node.setAttribute("gray", Integer.toString(bKGD_gray));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            } else if (bKGD_colorType == PNGImageReader.PNG_COLOR_RGB) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                node = new IIOMetadataNode("bKGD_RGB");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                node.setAttribute("red", Integer.toString(bKGD_red));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                node.setAttribute("green", Integer.toString(bKGD_green));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                node.setAttribute("blue", Integer.toString(bKGD_blue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            bKGD_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            root.appendChild(bKGD_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        // cHRM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        if (cHRM_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            IIOMetadataNode cHRM_node = new IIOMetadataNode("cHRM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            cHRM_node.setAttribute("whitePointX",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                              Integer.toString(cHRM_whitePointX));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            cHRM_node.setAttribute("whitePointY",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                              Integer.toString(cHRM_whitePointY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            cHRM_node.setAttribute("redX", Integer.toString(cHRM_redX));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            cHRM_node.setAttribute("redY", Integer.toString(cHRM_redY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            cHRM_node.setAttribute("greenX", Integer.toString(cHRM_greenX));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            cHRM_node.setAttribute("greenY", Integer.toString(cHRM_greenY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            cHRM_node.setAttribute("blueX", Integer.toString(cHRM_blueX));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            cHRM_node.setAttribute("blueY", Integer.toString(cHRM_blueY));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            root.appendChild(cHRM_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        // gAMA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        if (gAMA_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            IIOMetadataNode gAMA_node = new IIOMetadataNode("gAMA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            gAMA_node.setAttribute("value", Integer.toString(gAMA_gamma));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            root.appendChild(gAMA_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        // hIST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        if (hIST_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            IIOMetadataNode hIST_node = new IIOMetadataNode("hIST");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            for (int i = 0; i < hIST_histogram.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                IIOMetadataNode hist =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    new IIOMetadataNode("hISTEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                hist.setAttribute("index", Integer.toString(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                hist.setAttribute("value",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                                  Integer.toString(hIST_histogram[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                hIST_node.appendChild(hist);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            root.appendChild(hIST_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        // iCCP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        if (iCCP_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            IIOMetadataNode iCCP_node = new IIOMetadataNode("iCCP");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            iCCP_node.setAttribute("profileName", iCCP_profileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            iCCP_node.setAttribute("compressionMethod",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                          iCCP_compressionMethodNames[iCCP_compressionMethod]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            Object profile = iCCP_compressedProfile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            if (profile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                profile = ((byte[])profile).clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            iCCP_node.setUserObject(profile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            root.appendChild(iCCP_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        // iTXt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        if (iTXt_keyword.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            IIOMetadataNode iTXt_parent = new IIOMetadataNode("iTXt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            for (int i = 0; i < iTXt_keyword.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                Integer val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                IIOMetadataNode iTXt_node = new IIOMetadataNode("iTXtEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                iTXt_node.setAttribute("keyword", (String)iTXt_keyword.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                val = (Integer)iTXt_compressionFlag.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                iTXt_node.setAttribute("compressionFlag", val.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                val = (Integer)iTXt_compressionMethod.get(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                iTXt_node.setAttribute("compressionMethod", val.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                iTXt_node.setAttribute("languageTag",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                                       (String)iTXt_languageTag.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                iTXt_node.setAttribute("translatedKeyword",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                                       (String)iTXt_translatedKeyword.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                iTXt_node.setAttribute("text", (String)iTXt_text.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                iTXt_parent.appendChild(iTXt_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            root.appendChild(iTXt_parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        // pHYs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        if (pHYs_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            IIOMetadataNode pHYs_node = new IIOMetadataNode("pHYs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            pHYs_node.setAttribute("pixelsPerUnitXAxis",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                              Integer.toString(pHYs_pixelsPerUnitXAxis));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            pHYs_node.setAttribute("pixelsPerUnitYAxis",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                                   Integer.toString(pHYs_pixelsPerUnitYAxis));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            pHYs_node.setAttribute("unitSpecifier",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                                   unitSpecifierNames[pHYs_unitSpecifier]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            root.appendChild(pHYs_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        // sBIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        if (sBIT_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            IIOMetadataNode sBIT_node = new IIOMetadataNode("sBIT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            if (sBIT_colorType == PNGImageReader.PNG_COLOR_GRAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                node = new IIOMetadataNode("sBIT_Grayscale");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                node.setAttribute("gray",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                                  Integer.toString(sBIT_grayBits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            } else if (sBIT_colorType == PNGImageReader.PNG_COLOR_GRAY_ALPHA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                node = new IIOMetadataNode("sBIT_GrayAlpha");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                node.setAttribute("gray",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                                  Integer.toString(sBIT_grayBits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                node.setAttribute("alpha",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                                  Integer.toString(sBIT_alphaBits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            } else if (sBIT_colorType == PNGImageReader.PNG_COLOR_RGB) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                node = new IIOMetadataNode("sBIT_RGB");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                node.setAttribute("red",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                                  Integer.toString(sBIT_redBits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                node.setAttribute("green",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                                  Integer.toString(sBIT_greenBits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                node.setAttribute("blue",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                                  Integer.toString(sBIT_blueBits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            } else if (sBIT_colorType == PNGImageReader.PNG_COLOR_RGB_ALPHA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                node = new IIOMetadataNode("sBIT_RGBAlpha");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                node.setAttribute("red",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                                  Integer.toString(sBIT_redBits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                node.setAttribute("green",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                                  Integer.toString(sBIT_greenBits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                node.setAttribute("blue",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                                  Integer.toString(sBIT_blueBits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                node.setAttribute("alpha",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                                  Integer.toString(sBIT_alphaBits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            } else if (sBIT_colorType == PNGImageReader.PNG_COLOR_PALETTE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                node = new IIOMetadataNode("sBIT_Palette");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                node.setAttribute("red",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                                  Integer.toString(sBIT_redBits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                node.setAttribute("green",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                                  Integer.toString(sBIT_greenBits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                node.setAttribute("blue",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                                  Integer.toString(sBIT_blueBits));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            sBIT_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            root.appendChild(sBIT_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        // sPLT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        if (sPLT_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            IIOMetadataNode sPLT_node = new IIOMetadataNode("sPLT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            sPLT_node.setAttribute("name", sPLT_paletteName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            sPLT_node.setAttribute("sampleDepth",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                                   Integer.toString(sPLT_sampleDepth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            int numEntries = sPLT_red.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            for (int i = 0; i < numEntries; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                IIOMetadataNode entry = new IIOMetadataNode("sPLTEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                entry.setAttribute("index", Integer.toString(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                entry.setAttribute("red", Integer.toString(sPLT_red[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                entry.setAttribute("green", Integer.toString(sPLT_green[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                entry.setAttribute("blue", Integer.toString(sPLT_blue[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                entry.setAttribute("alpha", Integer.toString(sPLT_alpha[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                entry.setAttribute("frequency",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                                  Integer.toString(sPLT_frequency[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                sPLT_node.appendChild(entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            root.appendChild(sPLT_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        // sRGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        if (sRGB_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            IIOMetadataNode sRGB_node = new IIOMetadataNode("sRGB");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            sRGB_node.setAttribute("renderingIntent",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                                   renderingIntentNames[sRGB_renderingIntent]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            root.appendChild(sRGB_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        // tEXt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        if (tEXt_keyword.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            IIOMetadataNode tEXt_parent = new IIOMetadataNode("tEXt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            for (int i = 0; i < tEXt_keyword.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                IIOMetadataNode tEXt_node = new IIOMetadataNode("tEXtEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                tEXt_node.setAttribute("keyword" , (String)tEXt_keyword.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                tEXt_node.setAttribute("value" , (String)tEXt_text.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                tEXt_parent.appendChild(tEXt_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            root.appendChild(tEXt_parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        // tIME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        if (tIME_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            IIOMetadataNode tIME_node = new IIOMetadataNode("tIME");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            tIME_node.setAttribute("year", Integer.toString(tIME_year));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            tIME_node.setAttribute("month", Integer.toString(tIME_month));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            tIME_node.setAttribute("day", Integer.toString(tIME_day));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            tIME_node.setAttribute("hour", Integer.toString(tIME_hour));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            tIME_node.setAttribute("minute", Integer.toString(tIME_minute));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            tIME_node.setAttribute("second", Integer.toString(tIME_second));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            root.appendChild(tIME_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        // tRNS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        if (tRNS_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            IIOMetadataNode tRNS_node = new IIOMetadataNode("tRNS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            if (tRNS_colorType == PNGImageReader.PNG_COLOR_PALETTE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                node = new IIOMetadataNode("tRNS_Palette");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                for (int i = 0; i < tRNS_alpha.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    IIOMetadataNode entry =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                        new IIOMetadataNode("tRNS_PaletteEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                    entry.setAttribute("index", Integer.toString(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                    entry.setAttribute("alpha",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                                       Integer.toString(tRNS_alpha[i] & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                    node.appendChild(entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            } else if (tRNS_colorType == PNGImageReader.PNG_COLOR_GRAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                node = new IIOMetadataNode("tRNS_Grayscale");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                node.setAttribute("gray", Integer.toString(tRNS_gray));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            } else if (tRNS_colorType == PNGImageReader.PNG_COLOR_RGB) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                node = new IIOMetadataNode("tRNS_RGB");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                node.setAttribute("red", Integer.toString(tRNS_red));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                node.setAttribute("green", Integer.toString(tRNS_green));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                node.setAttribute("blue", Integer.toString(tRNS_blue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            tRNS_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            root.appendChild(tRNS_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        // zTXt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        if (zTXt_keyword.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            IIOMetadataNode zTXt_parent = new IIOMetadataNode("zTXt");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            for (int i = 0; i < zTXt_keyword.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                IIOMetadataNode zTXt_node = new IIOMetadataNode("zTXtEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                zTXt_node.setAttribute("keyword", (String)zTXt_keyword.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                int cm = ((Integer)zTXt_compressionMethod.get(i)).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                zTXt_node.setAttribute("compressionMethod",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                                       zTXt_compressionMethodNames[cm]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                zTXt_node.setAttribute("text", (String)zTXt_text.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                zTXt_parent.appendChild(zTXt_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            root.appendChild(zTXt_parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        // Unknown chunks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        if (unknownChunkType.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            IIOMetadataNode unknown_parent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                new IIOMetadataNode("UnknownChunks");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            for (int i = 0; i < unknownChunkType.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                IIOMetadataNode unknown_node =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                    new IIOMetadataNode("UnknownChunk");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                unknown_node.setAttribute("type",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                                          (String)unknownChunkType.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                unknown_node.setUserObject((byte[])unknownChunkData.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                unknown_parent.appendChild(unknown_node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            root.appendChild(unknown_parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        return root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    private int getNumChannels() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        // Determine number of channels
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        // Be careful about palette color with transparency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        int numChannels = IHDR_numChannels[IHDR_colorType];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        if (IHDR_colorType == PNGImageReader.PNG_COLOR_PALETTE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            tRNS_present && tRNS_colorType == IHDR_colorType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            numChannels = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        return numChannels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    public IIOMetadataNode getStandardChromaNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        IIOMetadataNode chroma_node = new IIOMetadataNode("Chroma");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        IIOMetadataNode node = null; // scratch node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        node = new IIOMetadataNode("ColorSpaceType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        node.setAttribute("name", colorSpaceTypeNames[IHDR_colorType]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        chroma_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        node = new IIOMetadataNode("NumChannels");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        node.setAttribute("value", Integer.toString(getNumChannels()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        chroma_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
        if (gAMA_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            node = new IIOMetadataNode("Gamma");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            node.setAttribute("value", Float.toString(gAMA_gamma*1.0e-5F));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
            chroma_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        node = new IIOMetadataNode("BlackIsZero");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        node.setAttribute("value", "true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        chroma_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        if (PLTE_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            boolean hasAlpha = tRNS_present &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                (tRNS_colorType == PNGImageReader.PNG_COLOR_PALETTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            node = new IIOMetadataNode("Palette");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            for (int i = 0; i < PLTE_red.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                IIOMetadataNode entry =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                    new IIOMetadataNode("PaletteEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                entry.setAttribute("index", Integer.toString(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                entry.setAttribute("red",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                                   Integer.toString(PLTE_red[i] & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                entry.setAttribute("green",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                                   Integer.toString(PLTE_green[i] & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                entry.setAttribute("blue",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                                   Integer.toString(PLTE_blue[i] & 0xff));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                if (hasAlpha) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                    int alpha = (i < tRNS_alpha.length) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                        (tRNS_alpha[i] & 0xff) : 255;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                    entry.setAttribute("alpha", Integer.toString(alpha));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                node.appendChild(entry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            chroma_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        if (bKGD_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            if (bKGD_colorType == PNGImageReader.PNG_COLOR_PALETTE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                node = new IIOMetadataNode("BackgroundIndex");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                node.setAttribute("value", Integer.toString(bKGD_index));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                node = new IIOMetadataNode("BackgroundColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                int r, g, b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                if (bKGD_colorType == PNGImageReader.PNG_COLOR_GRAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                    r = g = b = bKGD_gray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                    r = bKGD_red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                    g = bKGD_green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                    b = bKGD_blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
                node.setAttribute("red", Integer.toString(r));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                node.setAttribute("green", Integer.toString(g));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
                node.setAttribute("blue", Integer.toString(b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            chroma_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        return chroma_node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    public IIOMetadataNode getStandardCompressionNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        IIOMetadataNode compression_node = new IIOMetadataNode("Compression");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        IIOMetadataNode node = null; // scratch node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        node = new IIOMetadataNode("CompressionTypeName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        node.setAttribute("value", "deflate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        compression_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        node = new IIOMetadataNode("Lossless");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        node.setAttribute("value", "true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        compression_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        node = new IIOMetadataNode("NumProgressiveScans");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        node.setAttribute("value",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                          (IHDR_interlaceMethod == 0) ? "1" : "7");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        compression_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        return compression_node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    private String repeat(String s, int times) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        if (times == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        StringBuffer sb = new StringBuffer((s.length() + 1)*times - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        sb.append(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        for (int i = 1; i < times; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            sb.append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            sb.append(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    public IIOMetadataNode getStandardDataNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        IIOMetadataNode data_node = new IIOMetadataNode("Data");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        IIOMetadataNode node = null; // scratch node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        node = new IIOMetadataNode("PlanarConfiguration");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        node.setAttribute("value", "PixelInterleaved");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        data_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        node = new IIOMetadataNode("SampleFormat");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        node.setAttribute("value",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                          IHDR_colorType == PNGImageReader.PNG_COLOR_PALETTE ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                          "Index" : "UnsignedIntegral");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        data_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        String bitDepth = Integer.toString(IHDR_bitDepth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        node = new IIOMetadataNode("BitsPerSample");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        node.setAttribute("value", repeat(bitDepth, getNumChannels()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        data_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        if (sBIT_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            node = new IIOMetadataNode("SignificantBitsPerSample");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            String sbits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            if (sBIT_colorType == PNGImageReader.PNG_COLOR_GRAY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                sBIT_colorType == PNGImageReader.PNG_COLOR_GRAY_ALPHA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                sbits = Integer.toString(sBIT_grayBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            } else { // sBIT_colorType == PNGImageReader.PNG_COLOR_RGB ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                     // sBIT_colorType == PNGImageReader.PNG_COLOR_RGB_ALPHA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                sbits = Integer.toString(sBIT_redBits) + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                    Integer.toString(sBIT_greenBits) + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                    Integer.toString(sBIT_blueBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            if (sBIT_colorType == PNGImageReader.PNG_COLOR_GRAY_ALPHA ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                sBIT_colorType == PNGImageReader.PNG_COLOR_RGB_ALPHA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                sbits += " " + Integer.toString(sBIT_alphaBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            node.setAttribute("value", sbits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            data_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        // SampleMSB
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        return data_node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    public IIOMetadataNode getStandardDimensionNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        IIOMetadataNode dimension_node = new IIOMetadataNode("Dimension");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        IIOMetadataNode node = null; // scratch node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        node = new IIOMetadataNode("PixelAspectRatio");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        float ratio = pHYs_present ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            (float)pHYs_pixelsPerUnitXAxis/pHYs_pixelsPerUnitYAxis : 1.0F;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        node.setAttribute("value", Float.toString(ratio));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        dimension_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        node = new IIOMetadataNode("ImageOrientation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        node.setAttribute("value", "Normal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        dimension_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        if (pHYs_present && pHYs_unitSpecifier == PHYS_UNIT_METER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            node = new IIOMetadataNode("HorizontalPixelSize");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            node.setAttribute("value",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                              Float.toString(1000.0F/pHYs_pixelsPerUnitXAxis));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            dimension_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            node = new IIOMetadataNode("VerticalPixelSize");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            node.setAttribute("value",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                              Float.toString(1000.0F/pHYs_pixelsPerUnitYAxis));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            dimension_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        return dimension_node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    public IIOMetadataNode getStandardDocumentNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        if (!tIME_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        IIOMetadataNode document_node = new IIOMetadataNode("Document");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        IIOMetadataNode node = null; // scratch node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        node = new IIOMetadataNode("ImageModificationTime");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        node.setAttribute("year", Integer.toString(tIME_year));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        node.setAttribute("month", Integer.toString(tIME_month));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        node.setAttribute("day", Integer.toString(tIME_day));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        node.setAttribute("hour", Integer.toString(tIME_hour));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        node.setAttribute("minute", Integer.toString(tIME_minute));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        node.setAttribute("second", Integer.toString(tIME_second));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        document_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        return document_node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    public IIOMetadataNode getStandardTextNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        int numEntries = tEXt_keyword.size() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            iTXt_keyword.size() + zTXt_keyword.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        if (numEntries == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        IIOMetadataNode text_node = new IIOMetadataNode("Text");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        IIOMetadataNode node = null; // scratch node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        for (int i = 0; i < tEXt_keyword.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            node = new IIOMetadataNode("TextEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            node.setAttribute("keyword", (String)tEXt_keyword.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            node.setAttribute("value", (String)tEXt_text.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            node.setAttribute("encoding", "ISO-8859-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            node.setAttribute("compression", "none");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            text_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        for (int i = 0; i < iTXt_keyword.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            node = new IIOMetadataNode("TextEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            node.setAttribute("keyword", (String)iTXt_keyword.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            node.setAttribute("value", (String)iTXt_text.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            node.setAttribute("language",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                              (String)iTXt_languageTag.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            if (((Integer)iTXt_compressionFlag.get(i)).intValue() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                node.setAttribute("compression", "deflate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                node.setAttribute("compression", "none");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            text_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        for (int i = 0; i < zTXt_keyword.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            node = new IIOMetadataNode("TextEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            node.setAttribute("keyword", (String)zTXt_keyword.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            node.setAttribute("value", (String)zTXt_text.get(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            node.setAttribute("compression", "deflate");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            text_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        return text_node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    public IIOMetadataNode getStandardTransparencyNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        IIOMetadataNode transparency_node =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            new IIOMetadataNode("Transparency");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        IIOMetadataNode node = null; // scratch node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        node = new IIOMetadataNode("Alpha");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        boolean hasAlpha =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            (IHDR_colorType == PNGImageReader.PNG_COLOR_RGB_ALPHA) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
            (IHDR_colorType == PNGImageReader.PNG_COLOR_GRAY_ALPHA) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            (IHDR_colorType == PNGImageReader.PNG_COLOR_PALETTE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
             tRNS_present &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
             (tRNS_colorType == IHDR_colorType) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
             (tRNS_alpha != null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        node.setAttribute("value", hasAlpha ? "nonpremultipled" : "none");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        transparency_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        if (tRNS_present) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            node = new IIOMetadataNode("TransparentColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            if (tRNS_colorType == PNGImageReader.PNG_COLOR_RGB) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                node.setAttribute("value",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                                  Integer.toString(tRNS_red) + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                                  Integer.toString(tRNS_green) + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                                  Integer.toString(tRNS_blue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            } else if (tRNS_colorType == PNGImageReader.PNG_COLOR_GRAY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                node.setAttribute("value", Integer.toString(tRNS_gray));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            transparency_node.appendChild(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        return transparency_node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    // Shorthand for throwing an IIOInvalidTreeException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    private void fatal(Node node, String reason)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        throw new IIOInvalidTreeException(reason, node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    // Get an integer-valued attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    private String getStringAttribute(Node node, String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                                      String defaultValue, boolean required)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        Node attr = node.getAttributes().getNamedItem(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        if (attr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            if (!required) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                fatal(node, "Required attribute " + name + " not present!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        return attr.getNodeValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    // Get an integer-valued attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    private int getIntAttribute(Node node, String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                                int defaultValue, boolean required)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        String value = getStringAttribute(node, name, null, required);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        return Integer.parseInt(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    // Get a float-valued attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    private float getFloatAttribute(Node node, String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                                    float defaultValue, boolean required)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        String value = getStringAttribute(node, name, null, required);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        return Float.parseFloat(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    // Get a required integer-valued attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    private int getIntAttribute(Node node, String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        return getIntAttribute(node, name, -1, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    // Get a required float-valued attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    private float getFloatAttribute(Node node, String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        return getFloatAttribute(node, name, -1.0F, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    // Get a boolean-valued attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    private boolean getBooleanAttribute(Node node, String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                                        boolean defaultValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                                        boolean required)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        Node attr = node.getAttributes().getNamedItem(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        if (attr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            if (!required) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                fatal(node, "Required attribute " + name + " not present!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        String value = attr.getNodeValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        if (value.equals("true")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        } else if (value.equals("false")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            fatal(node, "Attribute " + name + " must be 'true' or 'false'!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    // Get a required boolean-valued attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    private boolean getBooleanAttribute(Node node, String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        return getBooleanAttribute(node, name, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
    // Get an enumerated attribute as an index into a String array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    private int getEnumeratedAttribute(Node node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                                       String name, String[] legalNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                                       int defaultValue, boolean required)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        Node attr = node.getAttributes().getNamedItem(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        if (attr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            if (!required) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                fatal(node, "Required attribute " + name + " not present!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        String value = attr.getNodeValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        for (int i = 0; i < legalNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            if (value.equals(legalNames[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        fatal(node, "Illegal value for attribute " + name + "!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
    // Get a required enumerated attribute as an index into a String array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
    private int getEnumeratedAttribute(Node node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                                       String name, String[] legalNames)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        return getEnumeratedAttribute(node, name, legalNames, -1, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
    // Get a String-valued attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    private String getAttribute(Node node, String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                                String defaultValue, boolean required)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        Node attr = node.getAttributes().getNamedItem(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        if (attr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            if (!required) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                fatal(node, "Required attribute " + name + " not present!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        return attr.getNodeValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    // Get a required String-valued attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    private String getAttribute(Node node, String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            return getAttribute(node, name, null, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    public void mergeTree(String formatName, Node root)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        if (formatName.equals(nativeMetadataFormatName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
            if (root == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                throw new IllegalArgumentException("root == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            mergeNativeTree(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        } else if (formatName.equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                   (IIOMetadataFormatImpl.standardMetadataFormatName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            if (root == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                throw new IllegalArgumentException("root == null!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            mergeStandardTree(root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            throw new IllegalArgumentException("Not a recognized format!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    private void mergeNativeTree(Node root)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        Node node = root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        if (!node.getNodeName().equals(nativeMetadataFormatName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            fatal(node, "Root must be " + nativeMetadataFormatName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        node = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        while (node != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            String name = node.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            if (name.equals("IHDR")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                IHDR_width = getIntAttribute(node, "width");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                IHDR_height = getIntAttribute(node, "height");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                IHDR_bitDepth = getEnumeratedAttribute(node, "bitDepth",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                                                       IHDR_bitDepths);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                IHDR_colorType = getEnumeratedAttribute(node, "colorType",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                                                        IHDR_colorTypeNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                IHDR_compressionMethod =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                    getEnumeratedAttribute(node, "compressionMethod",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                                           IHDR_compressionMethodNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                IHDR_filterMethod =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                    getEnumeratedAttribute(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                                           "filterMethod",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                                           IHDR_filterMethodNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                IHDR_interlaceMethod =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                    getEnumeratedAttribute(node, "interlaceMethod",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                                           IHDR_interlaceMethodNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                IHDR_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            } else if (name.equals("PLTE")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                byte[] red = new byte[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                byte[] green  = new byte[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                byte[] blue = new byte[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                int maxindex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                Node PLTE_entry = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                if (PLTE_entry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                    fatal(node, "Palette has no entries!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                while (PLTE_entry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                    if (!PLTE_entry.getNodeName().equals("PLTEEntry")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                        fatal(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                              "Only a PLTEEntry may be a child of a PLTE!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                    int index = getIntAttribute(PLTE_entry, "index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                    if (index < 0 || index > 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                        fatal(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                              "Bad value for PLTEEntry attribute index!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                    if (index > maxindex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                        maxindex = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                    red[index] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                        (byte)getIntAttribute(PLTE_entry, "red");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                    green[index] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                        (byte)getIntAttribute(PLTE_entry, "green");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                    blue[index] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                        (byte)getIntAttribute(PLTE_entry, "blue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                    PLTE_entry = PLTE_entry.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                int numEntries = maxindex + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                PLTE_red = new byte[numEntries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                PLTE_green = new byte[numEntries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                PLTE_blue = new byte[numEntries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                System.arraycopy(red, 0, PLTE_red, 0, numEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                System.arraycopy(green, 0, PLTE_green, 0, numEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                System.arraycopy(blue, 0, PLTE_blue, 0, numEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                PLTE_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
            } else if (name.equals("bKGD")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                bKGD_present = false; // Guard against partial overwrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                Node bKGD_node = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                if (bKGD_node == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                    fatal(node, "bKGD node has no children!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                String bKGD_name = bKGD_node.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                if (bKGD_name.equals("bKGD_Palette")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                    bKGD_index = getIntAttribute(bKGD_node, "index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                    bKGD_colorType = PNGImageReader.PNG_COLOR_PALETTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                } else if (bKGD_name.equals("bKGD_Grayscale")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                    bKGD_gray = getIntAttribute(bKGD_node, "gray");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                    bKGD_colorType = PNGImageReader.PNG_COLOR_GRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                } else if (bKGD_name.equals("bKGD_RGB")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                    bKGD_red = getIntAttribute(bKGD_node, "red");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                    bKGD_green = getIntAttribute(bKGD_node, "green");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                    bKGD_blue = getIntAttribute(bKGD_node, "blue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                    bKGD_colorType = PNGImageReader.PNG_COLOR_RGB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                    fatal(node, "Bad child of a bKGD node!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
                if (bKGD_node.getNextSibling() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
                    fatal(node, "bKGD node has more than one child!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
                bKGD_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
            } else if (name.equals("cHRM")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
                cHRM_whitePointX = getIntAttribute(node, "whitePointX");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                cHRM_whitePointY = getIntAttribute(node, "whitePointY");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                cHRM_redX = getIntAttribute(node, "redX");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                cHRM_redY = getIntAttribute(node, "redY");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                cHRM_greenX = getIntAttribute(node, "greenX");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                cHRM_greenY = getIntAttribute(node, "greenY");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
                cHRM_blueX = getIntAttribute(node, "blueX");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
                cHRM_blueY = getIntAttribute(node, "blueY");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                cHRM_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            } else if (name.equals("gAMA")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                gAMA_gamma = getIntAttribute(node, "value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                gAMA_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
            } else if (name.equals("hIST")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                char[] hist = new char[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                int maxindex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                Node hIST_entry = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                if (hIST_entry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                    fatal(node, "hIST node has no children!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                while (hIST_entry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                    if (!hIST_entry.getNodeName().equals("hISTEntry")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                        fatal(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                              "Only a hISTEntry may be a child of a hIST!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                    int index = getIntAttribute(hIST_entry, "index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                    if (index < 0 || index > 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                        fatal(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                              "Bad value for histEntry attribute index!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                    if (index > maxindex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                        maxindex = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                    hist[index] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                        (char)getIntAttribute(hIST_entry, "value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                    hIST_entry = hIST_entry.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                int numEntries = maxindex + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                hIST_histogram = new char[numEntries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                System.arraycopy(hist, 0, hIST_histogram, 0, numEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                hIST_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
            } else if (name.equals("iCCP")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                iCCP_profileName = getAttribute(node, "profileName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                iCCP_compressionMethod =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                    getEnumeratedAttribute(node, "compressionMethod",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                                           iCCP_compressionMethodNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                Object compressedProfile =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                    ((IIOMetadataNode)node).getUserObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                if (compressedProfile == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                    fatal(node, "No ICCP profile present in user object!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                if (!(compressedProfile instanceof byte[])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                    fatal(node, "User object not a byte array!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                iCCP_compressedProfile =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                    (byte[])((byte[])compressedProfile).clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                iCCP_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
            } else if (name.equals("iTXt")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                Node iTXt_node = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                while (iTXt_node != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                    if (!iTXt_node.getNodeName().equals("iTXtEntry")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                        fatal(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                              "Only an iTXtEntry may be a child of an iTXt!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                    String keyword = getAttribute(iTXt_node, "keyword");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                    iTXt_keyword.add(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                    boolean compressionFlag =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
                        getBooleanAttribute(iTXt_node, "compressionFlag");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                    iTXt_compressionFlag.add(new Boolean(compressionFlag));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                    String compressionMethod =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                        getAttribute(iTXt_node, "compressionMethod");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                    iTXt_compressionMethod.add(compressionMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
                    String languageTag =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                        getAttribute(iTXt_node, "languageTag");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                    iTXt_languageTag.add(languageTag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                    String translatedKeyword =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                        getAttribute(iTXt_node, "translatedKeyword");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                    iTXt_translatedKeyword.add(translatedKeyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                    String text = getAttribute(iTXt_node, "text");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                    iTXt_text.add(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                    iTXt_node = iTXt_node.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
            } else if (name.equals("pHYs")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                pHYs_pixelsPerUnitXAxis =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
                    getIntAttribute(node, "pixelsPerUnitXAxis");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                pHYs_pixelsPerUnitYAxis =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
                    getIntAttribute(node, "pixelsPerUnitYAxis");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
                pHYs_unitSpecifier =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
                    getEnumeratedAttribute(node, "unitSpecifier",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
                                           unitSpecifierNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
                pHYs_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
            } else if (name.equals("sBIT")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
                sBIT_present = false; // Guard against partial overwrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                Node sBIT_node = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                if (sBIT_node == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                    fatal(node, "sBIT node has no children!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
                String sBIT_name = sBIT_node.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                if (sBIT_name.equals("sBIT_Grayscale")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
                    sBIT_grayBits = getIntAttribute(sBIT_node, "gray");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                    sBIT_colorType = PNGImageReader.PNG_COLOR_GRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
                } else if (sBIT_name.equals("sBIT_GrayAlpha")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                    sBIT_grayBits = getIntAttribute(sBIT_node, "gray");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                    sBIT_alphaBits = getIntAttribute(sBIT_node, "alpha");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                    sBIT_colorType = PNGImageReader.PNG_COLOR_GRAY_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
                } else if (sBIT_name.equals("sBIT_RGB")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                    sBIT_redBits = getIntAttribute(sBIT_node, "red");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                    sBIT_greenBits = getIntAttribute(sBIT_node, "green");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                    sBIT_blueBits = getIntAttribute(sBIT_node, "blue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                    sBIT_colorType = PNGImageReader.PNG_COLOR_RGB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                } else if (sBIT_name.equals("sBIT_RGBAlpha")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                    sBIT_redBits = getIntAttribute(sBIT_node, "red");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                    sBIT_greenBits = getIntAttribute(sBIT_node, "green");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                    sBIT_blueBits = getIntAttribute(sBIT_node, "blue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                    sBIT_alphaBits = getIntAttribute(sBIT_node, "alpha");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                    sBIT_colorType = PNGImageReader.PNG_COLOR_RGB_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                } else if (sBIT_name.equals("sBIT_Palette")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                    sBIT_redBits = getIntAttribute(sBIT_node, "red");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                    sBIT_greenBits = getIntAttribute(sBIT_node, "green");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                    sBIT_blueBits = getIntAttribute(sBIT_node, "blue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                    sBIT_colorType = PNGImageReader.PNG_COLOR_PALETTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                    fatal(node, "Bad child of an sBIT node!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
                if (sBIT_node.getNextSibling() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                    fatal(node, "sBIT node has more than one child!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                sBIT_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            } else if (name.equals("sPLT")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                sPLT_paletteName = getAttribute(node, "name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                sPLT_sampleDepth = getIntAttribute(node, "sampleDepth");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                int[] red = new int[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                int[] green  = new int[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                int[] blue = new int[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
                int[] alpha = new int[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
                int[] frequency = new int[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
                int maxindex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
                Node sPLT_entry = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                if (sPLT_entry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
                    fatal(node, "sPLT node has no children!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                while (sPLT_entry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
                    if (!sPLT_entry.getNodeName().equals("sPLTEntry")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                        fatal(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
                              "Only an sPLTEntry may be a child of an sPLT!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                    int index = getIntAttribute(sPLT_entry, "index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
                    if (index < 0 || index > 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                        fatal(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                              "Bad value for PLTEEntry attribute index!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                    if (index > maxindex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                        maxindex = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                    red[index] = getIntAttribute(sPLT_entry, "red");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                    green[index] = getIntAttribute(sPLT_entry, "green");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                    blue[index] = getIntAttribute(sPLT_entry, "blue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                    alpha[index] = getIntAttribute(sPLT_entry, "alpha");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                    frequency[index] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                        getIntAttribute(sPLT_entry, "frequency");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                    sPLT_entry = sPLT_entry.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                int numEntries = maxindex + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                sPLT_red = new int[numEntries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                sPLT_green = new int[numEntries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                sPLT_blue = new int[numEntries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                sPLT_alpha = new int[numEntries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                sPLT_frequency = new int[numEntries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
                System.arraycopy(red, 0, sPLT_red, 0, numEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                System.arraycopy(green, 0, sPLT_green, 0, numEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                System.arraycopy(blue, 0, sPLT_blue, 0, numEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                System.arraycopy(alpha, 0, sPLT_alpha, 0, numEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                System.arraycopy(frequency, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                                 sPLT_frequency, 0, numEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                sPLT_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
            } else if (name.equals("sRGB")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                sRGB_renderingIntent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                    getEnumeratedAttribute(node, "renderingIntent",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                                           renderingIntentNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                sRGB_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
            } else if (name.equals("tEXt")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                Node tEXt_node = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                while (tEXt_node != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                    if (!tEXt_node.getNodeName().equals("tEXtEntry")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                        fatal(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                              "Only an tEXtEntry may be a child of an tEXt!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                    String keyword = getAttribute(tEXt_node, "keyword");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                    tEXt_keyword.add(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                    String text = getAttribute(tEXt_node, "value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                    tEXt_text.add(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                    tEXt_node = tEXt_node.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
            } else if (name.equals("tIME")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                tIME_year = getIntAttribute(node, "year");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                tIME_month = getIntAttribute(node, "month");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                tIME_day = getIntAttribute(node, "day");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                tIME_hour = getIntAttribute(node, "hour");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                tIME_minute = getIntAttribute(node, "minute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                tIME_second = getIntAttribute(node, "second");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                tIME_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
            } else if (name.equals("tRNS")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                tRNS_present = false; // Guard against partial overwrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                Node tRNS_node = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                if (tRNS_node == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                    fatal(node, "tRNS node has no children!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                String tRNS_name = tRNS_node.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                if (tRNS_name.equals("tRNS_Palette")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                    byte[] alpha = new byte[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                    int maxindex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                    Node tRNS_paletteEntry = tRNS_node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                    if (tRNS_paletteEntry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                        fatal(node, "tRNS_Palette node has no children!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                    while (tRNS_paletteEntry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                        if (!tRNS_paletteEntry.getNodeName().equals(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                                                        "tRNS_PaletteEntry")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                            fatal(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                 "Only a tRNS_PaletteEntry may be a child of a tRNS_Palette!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                        int index =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                            getIntAttribute(tRNS_paletteEntry, "index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                        if (index < 0 || index > 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                            fatal(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
                           "Bad value for tRNS_PaletteEntry attribute index!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
                        if (index > maxindex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
                            maxindex = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                        alpha[index] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                            (byte)getIntAttribute(tRNS_paletteEntry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                                                  "alpha");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                        tRNS_paletteEntry =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                            tRNS_paletteEntry.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                    int numEntries = maxindex + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                    tRNS_alpha = new byte[numEntries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                    tRNS_colorType = PNGImageReader.PNG_COLOR_PALETTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                    System.arraycopy(alpha, 0, tRNS_alpha, 0, numEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                } else if (tRNS_name.equals("tRNS_Grayscale")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                    tRNS_gray = getIntAttribute(tRNS_node, "gray");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                    tRNS_colorType = PNGImageReader.PNG_COLOR_GRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                } else if (tRNS_name.equals("tRNS_RGB")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                    tRNS_red = getIntAttribute(tRNS_node, "red");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
                    tRNS_green = getIntAttribute(tRNS_node, "green");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                    tRNS_blue = getIntAttribute(tRNS_node, "blue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                    tRNS_colorType = PNGImageReader.PNG_COLOR_RGB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                    fatal(node, "Bad child of a tRNS node!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                if (tRNS_node.getNextSibling() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                    fatal(node, "tRNS node has more than one child!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                tRNS_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
            } else if (name.equals("zTXt")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                Node zTXt_node = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                while (zTXt_node != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                    if (!zTXt_node.getNodeName().equals("zTXtEntry")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                        fatal(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
                              "Only an zTXtEntry may be a child of an zTXt!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                    String keyword = getAttribute(zTXt_node, "keyword");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                    zTXt_keyword.add(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                    int compressionMethod =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                        getEnumeratedAttribute(zTXt_node, "compressionMethod",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                                               zTXt_compressionMethodNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                    zTXt_compressionMethod.add(new Integer(compressionMethod));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                    String text = getAttribute(zTXt_node, "text");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                    zTXt_text.add(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                    zTXt_node = zTXt_node.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
            } else if (name.equals("UnknownChunks")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                Node unknown_node = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
                while (unknown_node != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                    if (!unknown_node.getNodeName().equals("UnknownChunk")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
                        fatal(node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                   "Only an UnknownChunk may be a child of an UnknownChunks!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                    String chunkType = getAttribute(unknown_node, "type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                    Object chunkData =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
                        ((IIOMetadataNode)unknown_node).getUserObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                    if (chunkType.length() != 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
                        fatal(unknown_node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                              "Chunk type must be 4 characters!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                    if (chunkData == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                        fatal(unknown_node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                              "No chunk data present in user object!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                    if (!(chunkData instanceof byte[])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                        fatal(unknown_node,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                              "User object not a byte array!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                    unknownChunkType.add(chunkType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                    unknownChunkData.add(((byte[])chunkData).clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                    unknown_node = unknown_node.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
                fatal(node, "Unknown child of root node!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
            node = node.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
    private boolean isISOLatin(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
        int len = s.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
            if (s.charAt(i) > 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
    private void mergeStandardTree(Node root)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        Node node = root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        if (!node.getNodeName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
            .equals(IIOMetadataFormatImpl.standardMetadataFormatName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
            fatal(node, "Root must be " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
                  IIOMetadataFormatImpl.standardMetadataFormatName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
        node = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
        while (node != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
            String name = node.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
            if (name.equals("Chroma")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
                Node child = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
                while (child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
                    String childName = child.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
                    if (childName.equals("Gamma")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
                        float gamma = getFloatAttribute(child, "value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
                        gAMA_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                        gAMA_gamma = (int)(gamma*100000 + 0.5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
                    } else if (childName.equals("Palette")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
                        byte[] red = new byte[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                        byte[] green = new byte[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
                        byte[] blue = new byte[256];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                        int maxindex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
                        Node entry = child.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
                        while (entry != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
                            int index = getIntAttribute(entry, "index");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
                            if (index >= 0 && index <= 255) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
                                red[index] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
                                    (byte)getIntAttribute(entry, "red");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
                                green[index] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
                                    (byte)getIntAttribute(entry, "green");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                                blue[index] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
                                    (byte)getIntAttribute(entry, "blue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
                                if (index > maxindex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
                                    maxindex = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
                            entry = entry.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
                        int numEntries = maxindex + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
                        PLTE_red = new byte[numEntries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
                        PLTE_green = new byte[numEntries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
                        PLTE_blue = new byte[numEntries];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
                        System.arraycopy(red, 0, PLTE_red, 0, numEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
                        System.arraycopy(green, 0, PLTE_green, 0, numEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
                        System.arraycopy(blue, 0, PLTE_blue, 0, numEntries);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
                        PLTE_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
                    } else if (childName.equals("BackgroundIndex")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
                        bKGD_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                        bKGD_colorType = PNGImageReader.PNG_COLOR_PALETTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
                        bKGD_index = getIntAttribute(child, "value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
                    } else if (childName.equals("BackgroundColor")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                        int red = getIntAttribute(child, "red");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
                        int green = getIntAttribute(child, "green");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
                        int blue = getIntAttribute(child, "blue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
                        if (red == green && red == blue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
                            bKGD_colorType = PNGImageReader.PNG_COLOR_GRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                            bKGD_gray = red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
                            bKGD_red = red;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
                            bKGD_green = green;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
                            bKGD_blue = blue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
                        bKGD_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
//                  } else if (childName.equals("ColorSpaceType")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
//                  } else if (childName.equals("NumChannels")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                    child = child.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
            } else if (name.equals("Compression")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                Node child = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                while (child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                    String childName = child.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                    if (childName.equals("NumProgressiveScans")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
                        // Use Adam7 if NumProgressiveScans > 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                        int scans = getIntAttribute(child, "value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                        IHDR_interlaceMethod = (scans > 1) ? 1 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
//                  } else if (childName.equals("CompressionTypeName")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
//                  } else if (childName.equals("Lossless")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
//                  } else if (childName.equals("BitRate")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
                    child = child.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
            } else if (name.equals("Data")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
                Node child = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
                while (child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
                    String childName = child.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
                    if (childName.equals("BitsPerSample")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
                        String s = getAttribute(child, "value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
                        StringTokenizer t = new StringTokenizer(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
                        int maxBits = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
                        while (t.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
                            int bits = Integer.parseInt(t.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
                            if (bits > maxBits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
                                maxBits = bits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
                        if (maxBits < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
                            maxBits = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
                        if (maxBits == 3) maxBits = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
                        if (maxBits > 4 || maxBits < 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
                            maxBits = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                        if (maxBits > 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
                            maxBits = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                        IHDR_bitDepth = maxBits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                    } else if (childName.equals("SignificantBitsPerSample")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
                        String s = getAttribute(child, "value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
                        StringTokenizer t = new StringTokenizer(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                        int numTokens = t.countTokens();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                        if (numTokens == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                            sBIT_colorType = PNGImageReader.PNG_COLOR_GRAY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                            sBIT_grayBits = Integer.parseInt(t.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                        } else if (numTokens == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                            sBIT_colorType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
                              PNGImageReader.PNG_COLOR_GRAY_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                            sBIT_grayBits = Integer.parseInt(t.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                            sBIT_alphaBits = Integer.parseInt(t.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                        } else if (numTokens == 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                            sBIT_colorType = PNGImageReader.PNG_COLOR_RGB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
                            sBIT_redBits = Integer.parseInt(t.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                            sBIT_greenBits = Integer.parseInt(t.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                            sBIT_blueBits = Integer.parseInt(t.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                        } else if (numTokens == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                            sBIT_colorType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                              PNGImageReader.PNG_COLOR_RGB_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
                            sBIT_redBits = Integer.parseInt(t.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
                            sBIT_greenBits = Integer.parseInt(t.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                            sBIT_blueBits = Integer.parseInt(t.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
                            sBIT_alphaBits = Integer.parseInt(t.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
                        if (numTokens >= 1 && numTokens <= 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
                            sBIT_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
//                      } else if (childName.equals("PlanarConfiguration")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
//                      } else if (childName.equals("SampleFormat")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
//                      } else if (childName.equals("SampleMSB")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
                    child = child.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
            } else if (name.equals("Dimension")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
                boolean gotWidth = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
                boolean gotHeight = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
                boolean gotAspectRatio = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
                float width = -1.0F;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
                float height = -1.0F;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
                float aspectRatio = -1.0F;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
                Node child = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
                while (child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
                    String childName = child.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
                    if (childName.equals("PixelAspectRatio")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
                        aspectRatio = getFloatAttribute(child, "value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
                        gotAspectRatio = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
                    } else if (childName.equals("HorizontalPixelSize")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
                        width = getFloatAttribute(child, "value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
                        gotWidth = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
                    } else if (childName.equals("VerticalPixelSize")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                        height = getFloatAttribute(child, "value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
                        gotHeight = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
//                  } else if (childName.equals("ImageOrientation")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
//                  } else if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
//                      (childName.equals("HorizontalPhysicalPixelSpacing")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
//                  } else if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
//                      (childName.equals("VerticalPhysicalPixelSpacing")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
//                  } else if (childName.equals("HorizontalPosition")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
//                  } else if (childName.equals("VerticalPosition")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
//                  } else if (childName.equals("HorizontalPixelOffset")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
//                  } else if (childName.equals("VerticalPixelOffset")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                    child = child.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                if (gotWidth && gotHeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
                    pHYs_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
                    pHYs_unitSpecifier = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
                    pHYs_pixelsPerUnitXAxis = (int)(width*1000 + 0.5F);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
                    pHYs_pixelsPerUnitYAxis = (int)(height*1000 + 0.5F);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
                } else if (gotAspectRatio) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
                    pHYs_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
                    pHYs_unitSpecifier = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                    // Find a reasonable rational approximation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
                    int denom = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
                    for (; denom < 100; denom++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
                        int num = (int)(aspectRatio*denom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                        if (Math.abs(num/denom - aspectRatio) < 0.001) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                    pHYs_pixelsPerUnitXAxis = (int)(aspectRatio*denom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
                    pHYs_pixelsPerUnitYAxis = denom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
            } else if (name.equals("Document")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
                Node child = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
                while (child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
                    String childName = child.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
                    if (childName.equals("ImageModificationTime")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
                        tIME_present = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
                        tIME_year = getIntAttribute(child, "year");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
                        tIME_month = getIntAttribute(child, "month");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
                        tIME_day = getIntAttribute(child, "day");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
                        tIME_hour =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
                            getIntAttribute(child, "hour", 0, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
                        tIME_minute =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
                            getIntAttribute(child, "minute", 0, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
                        tIME_second =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
                            getIntAttribute(child, "second", 0, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
//                  } else if (childName.equals("SubimageInterpretation")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
//                  } else if (childName.equals("ImageCreationTime")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
                    child = child.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
            } else if (name.equals("Text")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
                Node child = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
                while (child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
                    String childName = child.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
                    if (childName.equals("TextEntry")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
                        String keyword = getAttribute(child, "keyword");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
                        String value = getAttribute(child, "value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
                        String encoding = getAttribute(child, "encoding");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
                        String language = getAttribute(child, "language");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
                        String compression =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
                            getAttribute(child, "compression");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
                        if (isISOLatin(value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
                            if (compression.equals("zip")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
                                // Use a zTXt node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
                                zTXt_keyword.add(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
                                zTXt_text.add(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
                                zTXt_compressionMethod.add(new Integer(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
                                // Use a tEXt node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
                                tEXt_keyword.add(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                                tEXt_text.add(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                            int flag = compression.equals("zip") ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
                                1 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
                            // Use an iTXt node
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
                            iTXt_keyword.add(keyword);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
                            iTXt_compressionFlag.add(new Integer(flag));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
                            iTXt_compressionMethod.add(new Integer(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
                            iTXt_languageTag.add(language);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
                            iTXt_translatedKeyword.add(keyword); // fake it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
                            iTXt_text.add(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
                    child = child.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
//          } else if (name.equals("Transparency")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
//              Node child = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
//              while (child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
//                  String childName = child.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
//                  if (childName.equals("Alpha")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
//                  } else if (childName.equals("TransparentIndex")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
//                  } else if (childName.equals("TransparentColor")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
//                  } else if (childName.equals("TileTransparencies")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
//                  } else if (childName.equals("TileOpacities")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
//                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
//                  child = child.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
//              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
//          } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
//              // fatal(node, "Unknown child of root node!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
            node = node.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
    // Reset all instance variables to their initial state
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
    public void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
        IHDR_present = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
        PLTE_present = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
        bKGD_present = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
        cHRM_present = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
        gAMA_present = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
        hIST_present = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
        iCCP_present = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
        iTXt_keyword = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
        iTXt_compressionFlag = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
        iTXt_compressionMethod = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
        iTXt_languageTag = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
        iTXt_translatedKeyword = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
        iTXt_text = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
        pHYs_present = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
        sBIT_present = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
        sPLT_present = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
        sRGB_present = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
        tEXt_keyword = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
        tEXt_text = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
        tIME_present = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
        tRNS_present = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
        zTXt_keyword = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
        zTXt_compressionMethod = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
        zTXt_text = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
        unknownChunkType = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
        unknownChunkData = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
}