pixelmed
Markers.java
Go to the documentation of this file.
1 /* Copyright (c) 2014-2015, David A. Clunie DBA Pixelmed Publishing. All rights reserved. */
2 
3 package com.pixelmed.codec.jpeg;
4 
5 import java.util.HashMap;
6 import java.util.Map;
7 
13 public class Markers {
14 
15  private static final String identString = "@(#) $Header: /userland/cvs/codec/com/pixelmed/codec/jpeg/Markers.java,v 1.4 2016/01/16 15:07:52 dclunie Exp $";
16 
17  // modified from dicom3tools appsrc/misc/jpegdump.cc ...
18 
19  public static final int APP0 = 0xffe0;
20  public static final int APP1 = 0xffe1;
21  public static final int APP2 = 0xffe2;
22  public static final int APP3 = 0xffe3;
23  public static final int APP4 = 0xffe4;
24  public static final int APP5 = 0xffe5;
25  public static final int APP6 = 0xffe6;
26  public static final int APP7 = 0xffe7;
27  public static final int APP8 = 0xffe8;
28  public static final int APP9 = 0xffe9;
29  public static final int APPA = 0xffea;
30  public static final int APPB = 0xffeb;
31  public static final int APPC = 0xffec;
32  public static final int APPD = 0xffed;
33  public static final int APPE = 0xffee;
34  public static final int APPF = 0xffef;
35 
36  public static final int COM = 0xfffe;
37  public static final int DAC = 0xffcc;
38  public static final int DHP = 0xffde;
39  public static final int DHT = 0xffc4;
40  public static final int DNL = 0xffdc;
41  public static final int DQT = 0xffdb;
42  public static final int DRI = 0xffdd;
43  public static final int EOI = 0xffd9; // also JPEG 2000 "EOC"
44  public static final int EXP = 0xffdf;
45 
46  public static final int JPG = 0xffc8;
47 
48  // left out reserved JPGn and RES
49  // (especially those with first bit (not just byte) zero ... new LS 0 stuffing)
50 
51  public static final int RST0 = 0xffd0;
52  public static final int RST1 = 0xffd1;
53  public static final int RST2 = 0xffd2;
54  public static final int RST3 = 0xffd3;
55  public static final int RST4 = 0xffd4;
56  public static final int RST5 = 0xffd5;
57  public static final int RST6 = 0xffd6;
58  public static final int RST7 = 0xffd7;
59 
60  public static final int SOF0 = 0xffc0;
61  public static final int SOF1 = 0xffc1;
62  public static final int SOF2 = 0xffc2;
63  public static final int SOF3 = 0xffc3;
64 
65  public static final int SOF5 = 0xffc5;
66  public static final int SOF6 = 0xffc6;
67  public static final int SOF7 = 0xffc7;
68 
69  public static final int SOF9 = 0xffc9;
70  public static final int SOFA = 0xffca;
71  public static final int SOFB = 0xffcb;
72 
73  public static final int SOFD = 0xffcd;
74  public static final int SOFE = 0xffce;
75  public static final int SOFF = 0xffcf;
76 
77  public static final int SOI = 0xffd8;
78  public static final int SOS = 0xffda;
79  public static final int TEM = 0xff01;
80 
81  // New for JPEG-LS (14495-1:1997)
82 
83  public static final int SOF55 = 0xfff7;
84  public static final int LSE = 0xfff8;
85 
86  public static final int LSE_ID_L1 = 0x01;
87  public static final int LSE_ID_L2 = 0x02;
88  public static final int LSE_ID_L3 = 0x03;
89  public static final int LSE_ID_L4 = 0x04;
90 
91  // New for JPEG 2000 (15444-1:2000)
92 
93  public static final int SOC = 0xff4f;
94  public static final int SOT = 0xff90;
95  public static final int SOD = 0xff93;
96 // public static final int EOC = 0xffd9; // same as JPEG EOI
97  public static final int SIZ = 0xff51;
98  public static final int COD = 0xff52;
99  public static final int COC = 0xff53;
100  public static final int RGN = 0xff5e;
101  public static final int QCD = 0xff5c;
102  public static final int QCC = 0xff5d;
103  public static final int POC = 0xff5f;
104  public static final int TLM = 0xff55;
105  public static final int PLM = 0xff57;
106  public static final int PLT = 0xff58;
107  public static final int PPM = 0xff60;
108  public static final int PPT = 0xff61;
109  public static final int SOP = 0xff91;
110  public static final int EPH = 0xff92;
111  public static final int CRG = 0xff63;
112  public static final int COM2K = 0xff64;
113 
114  public static final int FF30 = 0xff30;
115  public static final int FF31 = 0xff31;
116  public static final int FF32 = 0xff32;
117  public static final int FF33 = 0xff33;
118  public static final int FF34 = 0xff34;
119  public static final int FF35 = 0xff35;
120  public static final int FF36 = 0xff36;
121  public static final int FF37 = 0xff37;
122  public static final int FF38 = 0xff38;
123  public static final int FF39 = 0xff39;
124  public static final int FF3A = 0xff3a;
125  public static final int FF3B = 0xff3b;
126  public static final int FF3C = 0xff3c;
127  public static final int FF3D = 0xff3d;
128  public static final int FF3E = 0xff3e;
129  public static final int FF3F = 0xff3f;
130 
131  public static final int isFixedLengthJPEGSegment(int marker) {
132  int length;
133  switch (marker) {
134  case EXP:
135  length=3; break;
136  default:
137  length=0; break;
138  }
139  return length;
140  }
141 
142  public static final boolean isNoLengthJPEGSegment(int marker) {
143  boolean nolength;
144  switch (marker) {
145  case SOI:
146  case EOI:
147  case TEM:
148  case RST0:
149  case RST1:
150  case RST2:
151  case RST3:
152  case RST4:
153  case RST5:
154  case RST6:
155  case RST7:
156  case FF30:
157  case FF31:
158  case FF32:
159  case FF33:
160  case FF34:
161  case FF35:
162  case FF36:
163  case FF37:
164  case FF38:
165  case FF39:
166  case FF3A:
167  case FF3B:
168  case FF3C:
169  case FF3D:
170  case FF3E:
171  case FF3F:
172  case SOC:
173  case SOD:
174  //case EOC: // same as JPEG EOI
175  case EPH:
176  nolength=true; break;
177  default:
178  nolength=false; break;
179  }
180  return nolength;
181  }
182 
183  public static final boolean isVariableLengthJPEGSegment(int marker) {
184  return !isNoLengthJPEGSegment(marker) && isFixedLengthJPEGSegment(marker) == 0;
185  }
186 
187  public static final boolean isSOF(int marker) {
188  boolean isSOF;
189  switch (marker) {
190  case SOF0:
191  case SOF1:
192  case SOF2:
193  case SOF3:
194  case SOF5:
195  case SOF6:
196  case SOF7:
197  case SOF9:
198  case SOFA:
199  case SOFB:
200  case SOFD:
201  case SOFE:
202  case SOFF:
203  case SOF55:
204  isSOF=true; break;
205  default:
206  isSOF=false; break;
207  }
208  return isSOF;
209  }
210 
211  public static final boolean isHuffman(int marker) {
212  boolean isHuffman;
213  switch (marker) {
214  case SOF0:
215  case SOF1:
216  case SOF2:
217  case SOF3:
218  case SOF5:
219  case SOF6:
220  case SOF7:
221  isHuffman=true; break;
222  default:
223  isHuffman=false; break;
224  }
225  return isHuffman;
226  }
227 
228  public static final boolean isDCT(int marker) {
229  boolean isDCT;
230  switch (marker) {
231  case SOF0:
232  case SOF1:
233  case SOF2:
234  case SOF5:
235  case SOF6:
236  case SOF9:
237  case SOFA:
238  case SOFD:
239  case SOFE:
240  isDCT=true; break;
241  default:
242  isDCT=false; break;
243  }
244  return isDCT;
245  }
246 
247  public static final boolean isLossless(int marker) {
248  boolean isLossless;
249  switch (marker) {
250  case SOF3:
251  case SOF7:
252  case SOFB:
253  case SOFF:
254  isLossless=true; break;
255  default:
256  isLossless=false; break;
257  }
258  return isLossless;
259  }
260 
261  private static class MarkerDictionaryEntry {
262  int markercode;
263  String abbreviation;
264  String description;
265 
266  MarkerDictionaryEntry(int markercode,String abbreviation,String description) {
267  this.markercode = markercode;
268  this.abbreviation = abbreviation;
269  this.description = description;
270  }
271  };
272 
273  private static final MarkerDictionaryEntry[] markerDictionaryTable = {
274  new MarkerDictionaryEntry(APP0, "APP0", "Reserved for Application Use"),
275  new MarkerDictionaryEntry(APP1, "APP1", "Reserved for Application Use"),
276  new MarkerDictionaryEntry(APP2, "APP2", "Reserved for Application Use"),
277  new MarkerDictionaryEntry(APP3, "APP3", "Reserved for Application Use"),
278  new MarkerDictionaryEntry(APP4, "APP4", "Reserved for Application Use"),
279  new MarkerDictionaryEntry(APP5, "APP5", "Reserved for Application Use"),
280  new MarkerDictionaryEntry(APP6, "APP6", "Reserved for Application Use"),
281  new MarkerDictionaryEntry(APP7, "APP7", "Reserved for Application Use"),
282  new MarkerDictionaryEntry(APP8, "APP8", "Reserved for Application Use"),
283  new MarkerDictionaryEntry(APP9, "APP9", "Reserved for Application Use"),
284  new MarkerDictionaryEntry(APPA, "APPA", "Reserved for Application Use"),
285  new MarkerDictionaryEntry(APPB, "APPB", "Reserved for Application Use"),
286  new MarkerDictionaryEntry(APPC, "APPC", "Reserved for Application Use"),
287  new MarkerDictionaryEntry(APPD, "APPD", "Reserved for Application Use"),
288  new MarkerDictionaryEntry(APPE, "APPE", "Reserved for Application Use"),
289  new MarkerDictionaryEntry(APPF, "APPF", "Reserved for Application Use"),
290 
291  new MarkerDictionaryEntry(COM, "COM", "Comment"),
292  new MarkerDictionaryEntry(DAC, "DAC", "Define Arithmetic Conditioning Table(s)"),
293  new MarkerDictionaryEntry(DHP, "DHP", "Define Hierarchical Progression"),
294  new MarkerDictionaryEntry(DHT, "DHT", "Define Huffman Table(s)"),
295  new MarkerDictionaryEntry(DNL, "DNL", "Define Number of Lines"),
296  new MarkerDictionaryEntry(DQT, "DQT", "Define Quantization Table(s)"),
297  new MarkerDictionaryEntry(DRI, "DRI", "Define Restart Interval"),
298  new MarkerDictionaryEntry(EOI, "EOI", "End of Image (JPEG 2000 EOC End of codestream)"),
299  new MarkerDictionaryEntry(EXP, "EXP", "Expand Reference Image(s)"),
300 
301  new MarkerDictionaryEntry(JPG, "JPG", "Reserved for JPEG extensions"),
302 
303  new MarkerDictionaryEntry(RST0, "RST0", "Restart with modulo 8 counter 0"),
304  new MarkerDictionaryEntry(RST1, "RST1", "Restart with modulo 8 counter 1"),
305  new MarkerDictionaryEntry(RST2, "RST2", "Restart with modulo 8 counter 2"),
306  new MarkerDictionaryEntry(RST3, "RST3", "Restart with modulo 8 counter 3"),
307  new MarkerDictionaryEntry(RST4, "RST4", "Restart with modulo 8 counter 4"),
308  new MarkerDictionaryEntry(RST5, "RST5", "Restart with modulo 8 counter 5"),
309  new MarkerDictionaryEntry(RST6, "RST6", "Restart with modulo 8 counter 6"),
310  new MarkerDictionaryEntry(RST7, "RST7", "Restart with modulo 8 counter 7"),
311 
312  new MarkerDictionaryEntry(SOF0, "SOF0", "Huffman Baseline DCT"),
313  new MarkerDictionaryEntry(SOF1, "SOF1", "Huffman Extended Sequential DCT"),
314  new MarkerDictionaryEntry(SOF2, "SOF2", "Huffman Progressive DCT"),
315  new MarkerDictionaryEntry(SOF3, "SOF3", "Huffman Lossless Sequential"),
316  new MarkerDictionaryEntry(SOF5, "SOF5", "Huffman Differential Sequential DCT"),
317  new MarkerDictionaryEntry(SOF6, "SOF6", "Huffman Differential Progressive DCT"),
318  new MarkerDictionaryEntry(SOF7, "SOF7", "Huffman Differential Lossless"),
319  new MarkerDictionaryEntry(SOF9, "SOF9", "Arithmetic Extended Sequential DCT"),
320  new MarkerDictionaryEntry(SOFA, "SOFA", "Arithmetic Progressive DCT"),
321  new MarkerDictionaryEntry(SOFB, "SOFB", "Arithmetic Lossless Sequential"),
322  new MarkerDictionaryEntry(SOFD, "SOFD", "Arithmetic Differential Sequential DCT"),
323  new MarkerDictionaryEntry(SOFE, "SOFE", "Arithmetic Differential Progressive DCT"),
324  new MarkerDictionaryEntry(SOFF, "SOFF", "Arithmetic Differential Lossless"),
325 
326  new MarkerDictionaryEntry(SOF55, "SOF55", "LS"),
327 
328  new MarkerDictionaryEntry(SOI, "SOI", "Start of Image"),
329  new MarkerDictionaryEntry(SOS, "SOS", "Start of Scan"),
330  new MarkerDictionaryEntry(TEM, "TEM", "Temporary use with Arithmetic Encoding"),
331 
332  new MarkerDictionaryEntry(SOC, "SOC", "Start of codestream"),
333  new MarkerDictionaryEntry(SOT, "SOT", "Start of tile-part"),
334  new MarkerDictionaryEntry(SOD, "SOD", "Start of data"),
335  //new MarkerDictionaryEntry(EOC, "EOC", "End of codestream"), // same as JPEG EOI
336  new MarkerDictionaryEntry(SIZ, "SIZ", "Image and tile size"),
337  new MarkerDictionaryEntry(COD, "COD", "Coding style default"),
338  new MarkerDictionaryEntry(COC, "COC", "Coding style component"),
339  new MarkerDictionaryEntry(RGN, "RGN", "Rgeion-of-interest"),
340  new MarkerDictionaryEntry(QCD, "QCD", "Quantization default"),
341  new MarkerDictionaryEntry(QCC, "QCC", "Quantization component"),
342  new MarkerDictionaryEntry(POC, "POC", "Progression order change"),
343  new MarkerDictionaryEntry(TLM, "TLM", "Tile-part lengths"),
344  new MarkerDictionaryEntry(PLM, "PLM", "Packet length, main header"),
345  new MarkerDictionaryEntry(PLT, "PLT", "Packet length, tile-part header"),
346  new MarkerDictionaryEntry(PPM, "PPM", "Packet packer headers, main header"),
347  new MarkerDictionaryEntry(PPT, "PPT", "Packet packer headers, tile-part header"),
348  new MarkerDictionaryEntry(SOP, "SOP", "Start of packet"),
349  new MarkerDictionaryEntry(EPH, "EPH", "End of packet header"),
350  new MarkerDictionaryEntry(CRG, "CRG", "Component registration"),
351  new MarkerDictionaryEntry(COM2K, "COM", "Comment (JPEG 2000)"),
352 
353  new MarkerDictionaryEntry(FF30, "FF30", "Reserved"),
354  new MarkerDictionaryEntry(FF31, "FF31", "Reserved"),
355  new MarkerDictionaryEntry(FF32, "FF32", "Reserved"),
356  new MarkerDictionaryEntry(FF33, "FF33", "Reserved"),
357  new MarkerDictionaryEntry(FF34, "FF34", "Reserved"),
358  new MarkerDictionaryEntry(FF35, "FF35", "Reserved"),
359  new MarkerDictionaryEntry(FF36, "FF36", "Reserved"),
360  new MarkerDictionaryEntry(FF37, "FF37", "Reserved"),
361  new MarkerDictionaryEntry(FF38, "FF38", "Reserved"),
362  new MarkerDictionaryEntry(FF39, "FF39", "Reserved"),
363  new MarkerDictionaryEntry(FF3A, "FF3A", "Reserved"),
364  new MarkerDictionaryEntry(FF3B, "FF3B", "Reserved"),
365  new MarkerDictionaryEntry(FF3C, "FF3C", "Reserved"),
366  new MarkerDictionaryEntry(FF3D, "FF3D", "Reserved"),
367  new MarkerDictionaryEntry(FF3E, "FF3E", "Reserved"),
368  new MarkerDictionaryEntry(FF3F, "FF3F", "Reserved")
369  };
370 
371  private static final Map<Integer,MarkerDictionaryEntry> mapOfMarkerToDictionaryEntry = new HashMap<Integer,MarkerDictionaryEntry>();
372 
373  static {
374  for (MarkerDictionaryEntry e : markerDictionaryTable) {
375  mapOfMarkerToDictionaryEntry.put(new Integer(e.markercode),e);
376  }
377  }
378 
379  public static final String getAbbreviation(int marker) {
380  MarkerDictionaryEntry e = mapOfMarkerToDictionaryEntry.get(new Integer(marker));
381  return e == null ? "" : e.abbreviation;
382  }
383 
384  public static final String getDescription(int marker) {
385  MarkerDictionaryEntry e = mapOfMarkerToDictionaryEntry.get(new Integer(marker));
386  return e == null ? "" : e.description;
387  }
388 
389 }
390 
static final boolean isDCT(int marker)
Definition: Markers.java:228
static final int isFixedLengthJPEGSegment(int marker)
Definition: Markers.java:131
static final int LSE_ID_L4
Definition: Markers.java:89
static final boolean isVariableLengthJPEGSegment(int marker)
Definition: Markers.java:183
static final String getDescription(int marker)
Definition: Markers.java:384
static final int LSE_ID_L2
Definition: Markers.java:87
static final int LSE_ID_L1
Definition: Markers.java:86
static final int LSE_ID_L3
Definition: Markers.java:88
static final boolean isHuffman(int marker)
Definition: Markers.java:211
static final boolean isNoLengthJPEGSegment(int marker)
Definition: Markers.java:142
static final boolean isLossless(int marker)
Definition: Markers.java:247
static final boolean isSOF(int marker)
Definition: Markers.java:187
static final String getAbbreviation(int marker)
Definition: Markers.java:379