jdk/src/share/classes/com/sun/imageio/plugins/jpeg/DHTMarkerSegment.java
author henryjen
Fri, 21 Feb 2014 15:28:37 -0800
changeset 23312 4711f66e7d5c
parent 22584 eed64ee05369
permissions -rw-r--r--
8033716: Fix raw and unchecked lint warnings in com.sun.imageio Reviewed-by: darcy, prr, bae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 5506
diff changeset
     2
 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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.jpeg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.imageio.metadata.IIOInvalidTreeException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.imageio.metadata.IIOMetadataNode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.imageio.stream.ImageOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.imageio.plugins.jpeg.JPEGHuffmanTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import org.w3c.dom.NodeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import org.w3c.dom.NamedNodeMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * A DHT (Define Huffman Table) marker segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
class DHTMarkerSegment extends MarkerSegment {
23312
4711f66e7d5c 8033716: Fix raw and unchecked lint warnings in com.sun.imageio
henryjen
parents: 22584
diff changeset
    46
    List<Htable> tables = new ArrayList<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    DHTMarkerSegment(boolean needFour) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        super(JPEG.DHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        tables.add(new Htable(JPEGHuffmanTable.StdDCLuminance, true, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        if (needFour) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            tables.add(new Htable(JPEGHuffmanTable.StdDCChrominance, true, 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        tables.add(new Htable(JPEGHuffmanTable.StdACLuminance, false, 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (needFour) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            tables.add(new Htable(JPEGHuffmanTable.StdACChrominance, false, 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    DHTMarkerSegment(JPEGBuffer buffer) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        super(buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        int count = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        while (count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            Htable newGuy = new Htable(buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            tables.add(newGuy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            count -= 1 + 16 + newGuy.values.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        buffer.bufAvail -= length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    DHTMarkerSegment(JPEGHuffmanTable[] dcTables,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                     JPEGHuffmanTable[] acTables) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        super(JPEG.DHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        for (int i = 0; i < dcTables.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            tables.add(new Htable(dcTables[i], true, i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        for (int i = 0; i < acTables.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            tables.add(new Htable(acTables[i], false, i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    DHTMarkerSegment(Node node) throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        super(JPEG.DHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        NodeList children = node.getChildNodes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        int size = children.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if ((size < 1) || (size > 4)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            throw new IIOInvalidTreeException("Invalid DHT node", node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        for (int i = 0; i < size; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            tables.add(new Htable(children.item(i)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    protected Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        DHTMarkerSegment newGuy = (DHTMarkerSegment) super.clone();
23312
4711f66e7d5c 8033716: Fix raw and unchecked lint warnings in com.sun.imageio
henryjen
parents: 22584
diff changeset
    96
        newGuy.tables = new ArrayList<>(tables.size());
4711f66e7d5c 8033716: Fix raw and unchecked lint warnings in com.sun.imageio
henryjen
parents: 22584
diff changeset
    97
        Iterator<Htable> iter = tables.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        while (iter.hasNext()) {
23312
4711f66e7d5c 8033716: Fix raw and unchecked lint warnings in com.sun.imageio
henryjen
parents: 22584
diff changeset
    99
            Htable table = iter.next();
4711f66e7d5c 8033716: Fix raw and unchecked lint warnings in com.sun.imageio
henryjen
parents: 22584
diff changeset
   100
            newGuy.tables.add((Htable) table.clone());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return newGuy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    IIOMetadataNode getNativeNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        IIOMetadataNode node = new IIOMetadataNode("dht");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        for (int i= 0; i<tables.size(); i++) {
23312
4711f66e7d5c 8033716: Fix raw and unchecked lint warnings in com.sun.imageio
henryjen
parents: 22584
diff changeset
   108
            Htable table = tables.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            node.appendChild(table.getNativeNode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Writes the data for this segment to the stream in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * valid JPEG format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    void write(ImageOutputStream ios) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        // We don't write DHT segments; the IJG library does.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    void print() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        printTag("DHT");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        System.out.println("Num tables: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                           + Integer.toString(tables.size()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        for (int i= 0; i<tables.size(); i++) {
23312
4711f66e7d5c 8033716: Fix raw and unchecked lint warnings in com.sun.imageio
henryjen
parents: 22584
diff changeset
   127
            Htable table = tables.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            table.print();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    Htable getHtableFromNode(Node node) throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return new Htable(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    void addHtable(JPEGHuffmanTable table, boolean isDC, int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        tables.add(new Htable(table, isDC, id));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * A Huffman table within a DHT marker segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    class Htable implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        int tableClass;  // 0 == DC, 1 == AC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        int tableID; // 0 - 4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        private static final int NUM_LENGTHS = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        // # of codes of each length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        short [] numCodes = new short[NUM_LENGTHS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        short [] values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        Htable(JPEGBuffer buffer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            tableClass = buffer.buf[buffer.bufPtr] >>> 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            tableID = buffer.buf[buffer.bufPtr++] & 0xf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            for (int i = 0; i < NUM_LENGTHS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                numCodes[i] = (short) (buffer.buf[buffer.bufPtr++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            int numValues = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            for (int i = 0; i < NUM_LENGTHS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                numValues += numCodes[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            values = new short[numValues];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            for (int i = 0; i < numValues; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                values[i] = (short) (buffer.buf[buffer.bufPtr++] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        Htable(JPEGHuffmanTable table, boolean isDC, int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            tableClass = isDC ? 0 : 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            tableID = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            numCodes = table.getLengths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            values = table.getValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        Htable(Node node) throws IIOInvalidTreeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            if (node.getNodeName().equals("dhtable")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                int count = attrs.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                if (count != 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    throw new IIOInvalidTreeException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                        ("dhtable node must have 2 attributes", node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                tableClass = getAttributeValue(node, attrs, "class", 0, 1, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                tableID = getAttributeValue(node, attrs, "htableId", 0, 3, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                if (node instanceof IIOMetadataNode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    IIOMetadataNode ourNode = (IIOMetadataNode) node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    JPEGHuffmanTable table =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                        (JPEGHuffmanTable) ourNode.getUserObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                    if (table == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        throw new IIOInvalidTreeException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                            ("dhtable node must have user object", node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    numCodes = table.getLengths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    values = table.getValues();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    throw new IIOInvalidTreeException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                        ("dhtable node must have user object", node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                throw new IIOInvalidTreeException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    ("Invalid node, expected dqtable", node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        protected Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            Htable newGuy = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                newGuy = (Htable) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            } catch (CloneNotSupportedException e) {} // won't happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            if (numCodes != null) {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 5506
diff changeset
   214
                newGuy.numCodes = numCodes.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            if (values != null) {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 5506
diff changeset
   217
                newGuy.values = values.clone();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            return newGuy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        IIOMetadataNode getNativeNode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            IIOMetadataNode node = new IIOMetadataNode("dhtable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            node.setAttribute("class", Integer.toString(tableClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            node.setAttribute("htableId", Integer.toString(tableID));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            node.setUserObject(new JPEGHuffmanTable(numCodes, values));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            return node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        void print() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            System.out.println("Huffman Table");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            System.out.println("table class: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                               + ((tableClass == 0) ? "DC":"AC"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            System.out.println("table id: " + Integer.toString(tableID));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            (new JPEGHuffmanTable(numCodes, values)).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
              System.out.print("Lengths:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
              for (int i=0; i<16; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
              System.out.print(" " + Integer.toString(numCodes[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
              int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
              if (values.length > 16) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
              System.out.println("\nFirst 16 Values:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
              count = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
              System.out.println("\nValues:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
              count = values.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
              for (int i=0; i<count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
              System.out.println(Integer.toString(values[i]&0xff));
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
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
}