KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > imageio > plugins > jpeg > DRIMarkerSegment


1 /*
2  * @(#)DRIMarkerSegment.java 1.5 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.imageio.plugins.jpeg;
9
10 import javax.imageio.metadata.IIOInvalidTreeException JavaDoc;
11 import javax.imageio.metadata.IIOMetadataNode JavaDoc;
12 import javax.imageio.stream.ImageOutputStream JavaDoc;
13
14 import java.io.IOException JavaDoc;
15
16 import org.w3c.dom.Node JavaDoc;
17
18 /**
19      * A DRI (Define Restart Interval) marker segment.
20      */

21 class DRIMarkerSegment extends MarkerSegment {
22     /**
23      * Restart interval, or 0 if none is specified.
24      */

25     int restartInterval = 0;
26
27     DRIMarkerSegment(JPEGBuffer buffer)
28         throws IOException JavaDoc {
29         super(buffer);
30         restartInterval = (buffer.buf[buffer.bufPtr++] & 0xff) << 8;
31         restartInterval |= buffer.buf[buffer.bufPtr++] & 0xff;
32         buffer.bufAvail -= length;
33     }
34
35     DRIMarkerSegment(Node JavaDoc node) throws IIOInvalidTreeException JavaDoc {
36         super(JPEG.DRI);
37         updateFromNativeNode(node, true);
38     }
39
40     IIOMetadataNode JavaDoc getNativeNode() {
41         IIOMetadataNode JavaDoc node = new IIOMetadataNode JavaDoc("dri");
42         node.setAttribute("interval", Integer.toString(restartInterval));
43         return node;
44     }
45
46     void updateFromNativeNode(Node JavaDoc node, boolean fromScratch)
47         throws IIOInvalidTreeException JavaDoc {
48         restartInterval = getAttributeValue(node, null, "interval",
49                                             0, 65535, true);
50     }
51
52     /**
53      * Writes the data for this segment to the stream in
54      * valid JPEG format.
55      */

56     void write(ImageOutputStream JavaDoc ios) throws IOException JavaDoc {
57         // We don't write DRI segments; the IJG library does.
58
}
59
60     void print() {
61         printTag("DRI");
62         System.out.println("Interval: "
63                            + Integer.toString(restartInterval));
64     }
65 }
66
67
Popular Tags