FileDocCategorySizeDatePackage
DQTMarkerSegment.javaAPI DocJava SE 5 API10209Fri Aug 26 14:54:42 BST 2005com.sun.imageio.plugins.jpeg

DQTMarkerSegment

public class DQTMarkerSegment extends MarkerSegment
A DQT (Define Quantization Table) marker segment.

Fields Summary
List
tables
Constructors Summary
DQTMarkerSegment(float quality, boolean needTwo)

  // Could be 1 to 4
        
        
        super(JPEG.DQT);
        tables.add(new Qtable(true, quality));
        if (needTwo) {
            tables.add(new Qtable(false, quality));
        }
    
DQTMarkerSegment(JPEGBuffer buffer)

        super(buffer);
        int count = length;
        while (count > 0) {
            Qtable newGuy = new Qtable(buffer);
            tables.add(newGuy);
            count -= newGuy.data.length+1;
        }
        buffer.bufAvail -= length;
    
DQTMarkerSegment(JPEGQTable[] qtables)

        super(JPEG.DQT);
        for (int i = 0; i < qtables.length; i++) {
            tables.add(new Qtable(qtables[i], i));
        }
    
DQTMarkerSegment(Node node)

        super(JPEG.DQT);
        NodeList children = node.getChildNodes();
        int size = children.getLength();
        if ((size < 1) || (size > 4)) {
            throw new IIOInvalidTreeException("Invalid DQT node", node);
        }
        for (int i = 0; i < size; i++) {
            tables.add(new Qtable(children.item(i)));
        }
    
Methods Summary
protected java.lang.Objectclone()

        DQTMarkerSegment newGuy = (DQTMarkerSegment) super.clone();
        newGuy.tables = new ArrayList(tables.size());
        Iterator iter = tables.iterator();
        while (iter.hasNext()) {
            Qtable table = (Qtable) iter.next();
            newGuy.tables.add(table.clone());
        }
        return newGuy;
    
com.sun.imageio.plugins.jpeg.DQTMarkerSegment$QtablegetChromaForLuma(com.sun.imageio.plugins.jpeg.DQTMarkerSegment$Qtable luma)
Assuming the given table was generated by scaling the "standard" visually lossless luminance table, extract the scale factor that was used.

        Qtable newGuy = null;
        // Determine if the table is all the same values
        // if so, use the same table
        boolean allSame = true;
        for (int i = 1; i < luma.QTABLE_SIZE; i++) {
            if (luma.data[i] != luma.data[i-1]) {
                allSame = false;
                break;
            }
        }
        if (allSame) {
            newGuy = (Qtable) luma.clone();
            newGuy.tableID = 1;
        } else {
            // Otherwise, find the largest coefficient less than 255.  This is
            // the largest value that we know did not clamp on scaling.
            int largestPos = 0;
            for (int i = 1; i < luma.QTABLE_SIZE; i++) {
                if (luma.data[i] > luma.data[largestPos]) {
                    largestPos = i;
                }
            }
            // Compute the scale factor by dividing it by the value in the
            // same position from the "standard" table.
            // If the given table was not generated by scaling the standard,
            // the resulting table will still be reasonable, as it will reflect
            // a comparable scaling of chrominance frequency response of the
            // eye.
            float scaleFactor = ((float)(luma.data[largestPos])) 
                / ((float)(JPEGQTable.K1Div2Luminance.getTable()[largestPos]));
            //    generate a new table
            JPEGQTable jpegTable = 
                JPEGQTable.K2Div2Chrominance.getScaledInstance(scaleFactor, 
                                                               true);
            newGuy = new Qtable(jpegTable, 1);
        }
        return newGuy;
    
javax.imageio.metadata.IIOMetadataNodegetNativeNode()

        IIOMetadataNode node = new IIOMetadataNode("dqt");
        for (int i= 0; i<tables.size(); i++) {
            Qtable table = (Qtable) tables.get(i);
            node.appendChild(table.getNativeNode());
        }
        return node;
    
com.sun.imageio.plugins.jpeg.DQTMarkerSegment$QtablegetQtableFromNode(org.w3c.dom.Node node)

        return new Qtable(node);
    
voidprint()

        printTag("DQT");
        System.out.println("Num tables: " 
                           + Integer.toString(tables.size()));
        for (int i= 0; i<tables.size(); i++) {
            Qtable table = (Qtable) tables.get(i);
            table.print();
        }
        System.out.println();
    
voidwrite(javax.imageio.stream.ImageOutputStream ios)
Writes the data for this segment to the stream in valid JPEG format.

        // We don't write DQT segments; the IJG library does.