⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jpegmetadata.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    protected IIOMetadataNode getStandardTextNode() {        IIOMetadataNode text = null;        // Add a text entry for each COM Marker Segment        if (findMarkerSegment(JPEG.COM) != null) {            text = new IIOMetadataNode("Text");            Iterator iter = markerSequence.iterator();            while (iter.hasNext()) {                MarkerSegment seg = (MarkerSegment) iter.next();                if (seg.tag == JPEG.COM) {                    COMMarkerSegment com = (COMMarkerSegment) seg;                    IIOMetadataNode entry = new IIOMetadataNode("TextEntry");                    entry.setAttribute("keyword", "comment");                    entry.setAttribute("value", com.getComment());                text.appendChild(entry);                }            }        }        return text;    }    protected IIOMetadataNode getStandardTransparencyNode() {        IIOMetadataNode trans = null;        if (hasAlpha == true) {            trans = new IIOMetadataNode("Transparency");            IIOMetadataNode alpha = new IIOMetadataNode("Alpha");            alpha.setAttribute("value", "nonpremultiplied"); // Always assume            trans.appendChild(alpha);        }        return trans;    }    // Editing    public boolean isReadOnly() {        return false;    }    public void mergeTree(String formatName, Node root)        throws IIOInvalidTreeException {        if (formatName == null) {            throw new IllegalArgumentException("null formatName!");        }         if (root == null) {            throw new IllegalArgumentException("null root!");        }        List copy = null;        if (resetSequence == null) {            resetSequence = cloneSequence();  // Deep copy            copy = resetSequence;  // Avoid cloning twice        } else {            copy = cloneSequence();        }        if (isStream &&            (formatName.equals(JPEG.nativeStreamMetadataFormatName))) {                mergeNativeTree(root);        } else if (!isStream &&                   (formatName.equals(JPEG.nativeImageMetadataFormatName))) {            mergeNativeTree(root);        } else if (!isStream &&                   (formatName.equals                    (IIOMetadataFormatImpl.standardMetadataFormatName))) {            mergeStandardTree(root);        } else {            throw  new IllegalArgumentException("Unsupported format name: "                                                 + formatName);        }        if (!isConsistent()) {            markerSequence = copy;            throw new IIOInvalidTreeException                ("Merged tree is invalid; original restored", root);        }    }    private void mergeNativeTree(Node root) throws IIOInvalidTreeException {        String name = root.getNodeName();        if (name != ((isStream) ? JPEG.nativeStreamMetadataFormatName                                : JPEG.nativeImageMetadataFormatName)) {            throw new IIOInvalidTreeException("Invalid root node name: " + name,                                               root);        }        if (root.getChildNodes().getLength() != 2) { // JPEGvariety and markerSequence            throw new IIOInvalidTreeException(                "JPEGvariety and markerSequence nodes must be present", root);        }        mergeJFIFsubtree(root.getFirstChild());        mergeSequenceSubtree(root.getLastChild());    }    /**     * Merge a JFIF subtree into the marker sequence, if the subtree     * is non-empty.     * If a JFIF marker exists, update it from the subtree.     * If none exists, create one from the subtree and insert it at the     * beginning of the marker sequence.     */    private void mergeJFIFsubtree(Node JPEGvariety)         throws IIOInvalidTreeException {        if (JPEGvariety.getChildNodes().getLength() != 0) {            Node jfifNode = JPEGvariety.getFirstChild();            // is there already a jfif marker segment?            JFIFMarkerSegment jfifSeg =                 (JFIFMarkerSegment) findMarkerSegment(JFIFMarkerSegment.class, true);            if (jfifSeg != null) {                jfifSeg.updateFromNativeNode(jfifNode, false);            } else {                // Add it as the first element in the list.                markerSequence.add(0, new JFIFMarkerSegment(jfifNode));            }        }    }    private void mergeSequenceSubtree(Node sequenceTree)         throws IIOInvalidTreeException {        NodeList children = sequenceTree.getChildNodes();        for (int i = 0; i < children.getLength(); i++) {            Node node = children.item(i);            String name = node.getNodeName();            if (name.equals("dqt")) {                mergeDQTNode(node);            } else if (name.equals("dht")) {                mergeDHTNode(node);            } else if (name.equals("dri")) {                mergeDRINode(node);            } else if (name.equals("com")) {                mergeCOMNode(node);            } else if (name.equals("app14Adobe")) {                mergeAdobeNode(node);            } else if (name.equals("unknown")) {                mergeUnknownNode(node);            } else if (name.equals("sof")) {                mergeSOFNode(node);            } else if (name.equals("sos")) {                mergeSOSNode(node);            } else {                throw new IIOInvalidTreeException("Invalid node: " + name, node);            }        }    }    /**     * Merge the given DQT node into the marker sequence.  If there already     * exist DQT marker segments in the sequence, then each table in the      * node replaces the first table, in any DQT segment, with the same     * table id.  If none of the existing DQT segments contain a table with     * the same id, then the table is added to the last existing DQT segment.     * If there are no DQT segments, then a new one is created and added     * as follows:     * If there are DHT segments, the new DQT segment is inserted before the     * first one.       * If there are no DHT segments, the new DQT segment is inserted before     * an SOF segment, if there is one.      * If there is no SOF segment, the new DQT segment is inserted before      * the first SOS segment, if there is one.     * If there is no SOS segment, the new DQT segment is added to the end     * of the sequence.     */    private void mergeDQTNode(Node node) throws IIOInvalidTreeException {        // First collect any existing DQT nodes into a local list        ArrayList oldDQTs = new ArrayList();        Iterator iter = markerSequence.iterator();        while (iter.hasNext()) {            MarkerSegment seg = (MarkerSegment) iter.next();            if (seg instanceof DQTMarkerSegment) {                oldDQTs.add(seg);            }        }        if (!oldDQTs.isEmpty()) {            NodeList children = node.getChildNodes();            for (int i = 0; i < children.getLength(); i++) {                Node child = children.item(i);                int childID = MarkerSegment.getAttributeValue(child,                                                               null,                                                               "qtableId",                                                               0, 3,                                                               true);                DQTMarkerSegment dqt = null;                int tableIndex = -1;                for (int j = 0; j < oldDQTs.size(); j++) {                    DQTMarkerSegment testDQT = (DQTMarkerSegment) oldDQTs.get(j);                    for (int k = 0; k < testDQT.tables.size(); k++) {                        DQTMarkerSegment.Qtable testTable =                             (DQTMarkerSegment.Qtable) testDQT.tables.get(k);                        if (childID == testTable.tableID) {                            dqt = testDQT;                            tableIndex = k;                            break;                        }                    }                    if (dqt != null) break;                }                if (dqt != null) {                    dqt.tables.set(tableIndex, dqt.getQtableFromNode(child));                } else {                    dqt = (DQTMarkerSegment) oldDQTs.get(oldDQTs.size()-1);                    dqt.tables.add(dqt.getQtableFromNode(child));                }            }        } else {            DQTMarkerSegment newGuy = new DQTMarkerSegment(node);            int firstDHT = findMarkerSegmentPosition(DHTMarkerSegment.class, true);            int firstSOF = findMarkerSegmentPosition(SOFMarkerSegment.class, true);            int firstSOS = findMarkerSegmentPosition(SOSMarkerSegment.class, true);            if (firstDHT != -1) {                markerSequence.add(firstDHT, newGuy);            } else if (firstSOF != -1) {                markerSequence.add(firstSOF, newGuy);            } else if (firstSOS != -1) {                markerSequence.add(firstSOS, newGuy);            } else {                markerSequence.add(newGuy);            }        }    }    /**     * Merge the given DHT node into the marker sequence.  If there already     * exist DHT marker segments in the sequence, then each table in the      * node replaces the first table, in any DHT segment, with the same     * table class and table id.  If none of the existing DHT segments contain     * a table with the same class and id, then the table is added to the last     * existing DHT segment.     * If there are no DHT segments, then a new one is created and added     * as follows:     * If there are DQT segments, the new DHT segment is inserted immediately     * following the last DQT segment.     * If there are no DQT segments, the new DHT segment is inserted before     * an SOF segment, if there is one.      * If there is no SOF segment, the new DHT segment is inserted before      * the first SOS segment, if there is one.     * If there is no SOS segment, the new DHT segment is added to the end     * of the sequence.     */    private void mergeDHTNode(Node node) throws IIOInvalidTreeException {        // First collect any existing DQT nodes into a local list        ArrayList oldDHTs = new ArrayList();        Iterator iter = markerSequence.iterator();        while (iter.hasNext()) {            MarkerSegment seg = (MarkerSegment) iter.next();            if (seg instanceof DHTMarkerSegment) {                oldDHTs.add(seg);            }        }        if (!oldDHTs.isEmpty()) {            NodeList children = node.getChildNodes();            for (int i = 0; i < children.getLength(); i++) {                Node child = children.item(i);                NamedNodeMap attrs = child.getAttributes();                int childID = MarkerSegment.getAttributeValue(child,                                                               attrs,                                                               "htableId",                                                               0, 3,                                                               true);                int childClass = MarkerSegment.getAttributeValue(child,                                                                  attrs,                                                                  "class",                                                                  0, 1,                                                                  true);                DHTMarkerSegment dht = null;                int tableIndex = -1;                for (int j = 0; j < oldDHTs.size(); j++) {                    DHTMarkerSegment testDHT = (DHTMarkerSegment) oldDHTs.get(j);                    for (int k = 0; k < testDHT.tables.size(); k++) {                        DHTMarkerSegment.Htable testTable =                             (DHTMarkerSegment.Htable) testDHT.tables.get(k);                        if ((childID == testTable.tableID) &&                             (childClass == testTable.tableClass)) {                            dht = testDHT;                            tableIndex = k;                            break;                        }                    }                    if (dht != null) break;                }                if (dht != null) {                    dht.tables.set(tableIndex, dht.getHtableFromNode(child));                } else {                    dht = (DHTMarkerSegment) oldDHTs.get(oldDHTs.size()-1);                    dht.tables.add(dht.getHtableFromNode(child));                }            }        } else {            DHTMarkerSegment newGuy = new DHTMarkerSegment(node);            int lastDQT = findMarkerSegmentPosition(DQTMarkerSegment.class, false);            int firstSOF = findMarkerSegmentPosition(SOFMarkerSegment.class, true);            int firstSOS = findMarkerSegmentPosition(SOSMarkerSegment.class, true);            if (lastDQT != -1) {                markerSequence.add(lastDQT+1, newGuy);            } else if (firstSOF != -1) {                markerSequence.add(firstSOF, newGuy);            } else if (firstSOS != -1) {                markerSequence.add(firstSOS, newGuy);            } else {                markerSequence.add(newGuy);            }        }    }    /**     * Merge the given DRI node into the marker sequence.     * If there already exists a DRI marker segment, the restart interval      * value is updated.     * If there is no DRI segment, then a new one is created and added as     * follows:     * If there is an SOF segment, the new DRI segment is inserted before     * it.     * If there is no SOF segment, the new DRI segment is inserted before      * the first SOS segment, if there is one.     * If there is no SOS segment, the new DRI segment is added to the end     * of the sequence.     */    private void mergeDRINode(Node node) throws IIOInvalidTreeException {        DRIMarkerSegment dri =            (DRIMarkerSegment) findMarkerSegment(DRIMarkerSegment.class, true);        if (dri != null) {            dri.updateFromNativeNode(node, false);        } else {            DRIMarkerSegment newGuy = new DRIMarkerSegment(node);            int firstSOF = findMarkerSegmentPosition(SOFMarkerSegment.class, true);            int firstSOS = findMarkerSegmentPosition(SOSMarkerSegment.class, true);            if (firstSOF != -1) {                markerSequence.add(firstSOF, newGuy);            } else if (firstSOS != -1) {                markerSequence.add(firstSOS, newGuy);            } else {                markerSequence.add(newGuy);            }        }    }    /**     * Merge the given COM node into the marker sequence.     * A new COM marker segment is created and added to the sequence      * using insertCOMMarkerSegment.     */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -