Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/sixlegs/image/png/Chunk.java


1   // Copyright (C) 1998, 1999, 2001 Chris Nokleberg
2   // Please see included LICENSE.TXT
3   
4   package com.sixlegs.image.png;
5   
6   import java.io.IOException;
7   
8   class Chunk
9   implements Cloneable
10  {
11      /* package */ int length;
12      /* package */ int type;
13  
14      protected PngImage img;
15      protected ExDataInputStream in_data;
16  
17      Chunk(int type)
18      {
19          this.type = type;
20      }
21  
22      Chunk copy()
23      {
24          try {
25              return (Chunk)clone();
26          } catch (CloneNotSupportedException e) { 
27              return null;
28          }
29      }
30  
31      boolean isAncillary()
32      {
33          return ((type & 0x20000000) != 0);
34      }
35  
36      final boolean isPrivate ()
37      {
38          return ((type & 0x00200000) != 0);
39      }
40  
41      final boolean isReservedSet ()
42      {
43          return ((type & 0x00002000) != 0);
44      }
45  
46      final boolean isSafeToCopy ()
47      {
48          return ((type & 0x00000020) != 0);
49      }
50  
51      final boolean isUnknown ()
52      {
53          return getClass() == Chunk.class;
54      }
55  
56      int bytesRemaining()
57      {
58          return Math.max(0, length + 4 - img.data.in_idat.count());
59      }
60  
61      protected boolean multipleOK() { return true; }
62      protected boolean beforeIDAT() { return false; }
63    
64      static String typeToString(int x)
65      {
66          return ("" + 
67                  (char)((x >>> 24) & 0xFF) + 
68                  (char)((x >>> 16) & 0xFF) + 
69                  (char)((x >>>  8) & 0xFF) + 
70                  (char)((x       ) & 0xFF));
71      }
72  
73      static int stringToType(String id)
74      {
75          return ((((int)id.charAt(0) & 0xFF) << 24) | 
76                  (((int)id.charAt(1) & 0xFF) << 16) | 
77                  (((int)id.charAt(2) & 0xFF) <<  8) | 
78                  (((int)id.charAt(3) & 0xFF)      ));
79      }
80  
81      final void badLength(int correct)
82      throws PngException
83      {
84          throw new PngException("Bad " + typeToString(type) +
85                                 " chunk length: " + in_data.unsign(length) +
86                                 " (expected " + correct + ")");
87      }
88  
89      final void badLength()
90      throws PngException
91      {
92          throw new PngException("Bad " + typeToString(type) +
93                                 " chunk length: " + in_data.unsign(length));
94      }
95  
96      protected void readData()
97      throws IOException
98      {
99          in_data.skipBytes(length);
100     }
101 
102     static final int IHDR = 0x49484452;
103     static final int PLTE = 0x504c5445;
104     static final int IDAT = 0x49444154;
105     static final int IEND = 0x49454e44;
106     static final int bKGD = 0x624b4744;
107     static final int cHRM = 0x6348524d;
108     static final int gAMA = 0x67414d41;
109     static final int hIST = 0x68495354;
110     static final int pHYs = 0x70485973;
111     static final int sBIT = 0x73424954;
112     static final int tEXt = 0x74455874;
113     static final int tIME = 0x74494d45;
114     static final int tRNS = 0x74524e53;
115     static final int zTXt = 0x7a545874;
116     static final int sRGB = 0x73524742;
117     static final int sPLT = 0x73504c54;
118     static final int oFFs = 0x6f464673;
119     static final int sCAL = 0x7343414c;
120     static final int iCCP = 0x69434350;
121     static final int pCAL = 0x7043414c;
122     static final int iTXt = 0x69545874;
123     static final int gIFg = 0x67494667;
124     static final int gIFx = 0x67494678;
125 }