File: Markers.java

package info (click to toggle)
pixelmed-codec 20141206-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 268 kB
  • ctags: 329
  • sloc: java: 1,270; makefile: 164
file content (317 lines) | stat: -rw-r--r-- 12,580 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/* Copyright (c) 2014, David A. Clunie DBA Pixelmed Publishing. All rights reserved. */

package com.pixelmed.codec.jpeg;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>A class containing static definitions of JPEG marker segments and related methods.</p>
 *
 * @author	dclunie
 */
public class Markers {

	private static final String identString = "@(#) $Header: /userland/cvs/codec/com/pixelmed/codec/jpeg/Markers.java,v 1.1 2014/03/21 15:28:07 dclunie Exp $";
	
	// modified from dicom3tools appsrc/misc/jpegdump.cc ...

	public static final int APP0 = 0xffe0;
	public static final int APP1 = 0xffe1;
	public static final int APP2 = 0xffe2;
	public static final int APP3 = 0xffe3;
	public static final int APP4 = 0xffe4;
	public static final int APP5 = 0xffe5;
	public static final int APP6 = 0xffe6;
	public static final int APP7 = 0xffe7;
	public static final int APP8 = 0xffe8;
	public static final int APP9 = 0xffe9;
	public static final int APPA = 0xffea;
	public static final int APPB = 0xffeb;
	public static final int APPC = 0xffec;
	public static final int APPD = 0xffed;
	public static final int APPE = 0xffee;
	public static final int APPF = 0xffef;

	public static final int COM = 0xfffe;
	public static final int DAC = 0xffcc;
	public static final int DHP = 0xffde;
	public static final int DHT = 0xffc4;
	public static final int DNL = 0xffdc;
	public static final int DQT = 0xffdb;
	public static final int DRI = 0xffdd;
	public static final int EOI = 0xffd9;          // also JPEG 2000 "EOC"
	public static final int EXP = 0xffdf;

	public static final int JPG = 0xffc8;

	// left out reserved JPGn and RES
	// (especially those with first bit (not just byte) zero ... new LS 0 stuffing)

	public static final int RST0 = 0xffd0;
	public static final int RST1 = 0xffd1;
	public static final int RST2 = 0xffd2;
	public static final int RST3 = 0xffd3;
	public static final int RST4 = 0xffd4;
	public static final int RST5 = 0xffd5;
	public static final int RST6 = 0xffd6;
	public static final int RST7 = 0xffd7;

	public static final int SOF0 = 0xffc0;
	public static final int SOF1 = 0xffc1;
	public static final int SOF2 = 0xffc2;
	public static final int SOF3 = 0xffc3;

	public static final int SOF5 = 0xffc5;
	public static final int SOF6 = 0xffc6;
	public static final int SOF7 = 0xffc7;

	public static final int SOF9 = 0xffc9;
	public static final int SOFA = 0xffca;
	public static final int SOFB = 0xffcb;

	public static final int SOFD = 0xffcd;
	public static final int SOFE = 0xffce;
	public static final int SOFF = 0xffcf;

	public static final int SOI = 0xffd8;
	public static final int SOS = 0xffda;
	public static final int TEM = 0xff01;

	// New for JPEG-LS (14495-1:1997)

	public static final int SOF55 = 0xfff7;
	public static final int LSE   = 0xfff8;

	public static final int LSE_ID_L1 = 0x01;
	public static final int LSE_ID_L2 = 0x02;
	public static final int LSE_ID_L3 = 0x03;
	public static final int LSE_ID_L4 = 0x04;

	// New for JPEG 2000 (15444-1:2000)

	public static final int SOC = 0xff4f;
	public static final int SOT = 0xff90;
	public static final int SOD = 0xff93;
//	public static final int EOC = 0xffd9;        // same as JPEG EOI
	public static final int SIZ = 0xff51;
	public static final int COD = 0xff52;
	public static final int COC = 0xff53;
	public static final int RGN = 0xff5e;
	public static final int QCD = 0xff5c;
	public static final int QCC = 0xff5d;
	public static final int POC = 0xff5f;
	public static final int TLM = 0xff55;
	public static final int PLM = 0xff57;
	public static final int PLT = 0xff58;
	public static final int PPM = 0xff60;
	public static final int PPT = 0xff61;
	public static final int SOP = 0xff91;
	public static final int EPH = 0xff92;
	public static final int CRG = 0xff63;
	public static final int COM2K = 0xff64;

	public static final int FF30 = 0xff30;
	public static final int FF31 = 0xff31;
	public static final int FF32 = 0xff32;
	public static final int FF33 = 0xff33;
	public static final int FF34 = 0xff34;
	public static final int FF35 = 0xff35;
	public static final int FF36 = 0xff36;
	public static final int FF37 = 0xff37;
	public static final int FF38 = 0xff38;
	public static final int FF39 = 0xff39;
	public static final int FF3A = 0xff3a;
	public static final int FF3B = 0xff3b;
	public static final int FF3C = 0xff3c;
	public static final int FF3D = 0xff3d;
	public static final int FF3E = 0xff3e;
	public static final int FF3F = 0xff3f;

	public static final int isFixedLengthJPEGSegment(int marker) {
		int length;
		switch (marker) {
			case EXP:
				length=3; break;
			default:
				length=0; break;
		}
		return length;
	}
	
	public static final boolean isNoLengthJPEGSegment(int marker) {
		boolean nolength;
		switch (marker) {
			case SOI:
			case EOI:
			case TEM:
			case RST0:
			case RST1:
			case RST2:
			case RST3:
			case RST4:
			case RST5:
			case RST6:
			case RST7:
			case FF30:
			case FF31:
			case FF32:
			case FF33:
			case FF34:
			case FF35:
			case FF36:
			case FF37:
			case FF38:
			case FF39:
			case FF3A:
			case FF3B:
			case FF3C:
			case FF3D:
			case FF3E:
			case FF3F:
			case SOC:
			case SOD:
			//case EOC:         // same as JPEG EOI
			case EPH:
				nolength=true; break;
			default:
				nolength=false; break;
		}
		return nolength;
	}
	
	public static final boolean isVariableLengthJPEGSegment(int marker) {
		return !isNoLengthJPEGSegment(marker) && isFixedLengthJPEGSegment(marker) == 0;
	}
	
	private static class MarkerDictionaryEntry {
		int markercode;
		String abbreviation;
		String description;
		
		MarkerDictionaryEntry(int markercode,String abbreviation,String description) {
			this.markercode = markercode;
			this.abbreviation = abbreviation;
			this.description = description;
		}
	};
	
	private static final MarkerDictionaryEntry[] markerDictionaryTable = {
		new MarkerDictionaryEntry(APP0, "APP0", "Reserved for Application Use"),
		new MarkerDictionaryEntry(APP1, "APP1", "Reserved for Application Use"),
		new MarkerDictionaryEntry(APP2, "APP2", "Reserved for Application Use"),
		new MarkerDictionaryEntry(APP3, "APP3", "Reserved for Application Use"),
		new MarkerDictionaryEntry(APP4, "APP4", "Reserved for Application Use"),
		new MarkerDictionaryEntry(APP5, "APP5", "Reserved for Application Use"),
		new MarkerDictionaryEntry(APP6, "APP6", "Reserved for Application Use"),
		new MarkerDictionaryEntry(APP7, "APP7", "Reserved for Application Use"),
		new MarkerDictionaryEntry(APP8, "APP8", "Reserved for Application Use"),
		new MarkerDictionaryEntry(APP9, "APP9", "Reserved for Application Use"),
		new MarkerDictionaryEntry(APPA, "APPA", "Reserved for Application Use"),
		new MarkerDictionaryEntry(APPB, "APPB", "Reserved for Application Use"),
		new MarkerDictionaryEntry(APPC, "APPC", "Reserved for Application Use"),
		new MarkerDictionaryEntry(APPD, "APPD", "Reserved for Application Use"),
		new MarkerDictionaryEntry(APPE, "APPE", "Reserved for Application Use"),
		new MarkerDictionaryEntry(APPF, "APPF", "Reserved for Application Use"),

		new MarkerDictionaryEntry(COM, "COM", "Comment"),
		new MarkerDictionaryEntry(DAC, "DAC", "Define Arithmetic Conditioning Table(s)"),
		new MarkerDictionaryEntry(DHP, "DHP", "Define Hierarchical Progression"),
		new MarkerDictionaryEntry(DHT, "DHT", "Define Huffman Table(s)"),
		new MarkerDictionaryEntry(DNL, "DNL", "Define Number of Lines"),
		new MarkerDictionaryEntry(DQT, "DQT", "Define Quantization Table(s)"),
		new MarkerDictionaryEntry(DRI, "DRI", "Define Restart Interval"),
		new MarkerDictionaryEntry(EOI, "EOI", "End of Image (JPEG 2000 EOC End of codestream)"),
		new MarkerDictionaryEntry(EXP, "EXP", "Expand Reference Image(s)"),

		new MarkerDictionaryEntry(JPG, "JPG", "Reserved for JPEG extensions"),

		new MarkerDictionaryEntry(RST0, "RST0", "Restart with modulo 8 counter 0"),
		new MarkerDictionaryEntry(RST1, "RST1", "Restart with modulo 8 counter 1"),
		new MarkerDictionaryEntry(RST2, "RST2", "Restart with modulo 8 counter 2"),
		new MarkerDictionaryEntry(RST3, "RST3", "Restart with modulo 8 counter 3"),
		new MarkerDictionaryEntry(RST4, "RST4", "Restart with modulo 8 counter 4"),
		new MarkerDictionaryEntry(RST5, "RST5", "Restart with modulo 8 counter 5"),
		new MarkerDictionaryEntry(RST6, "RST6", "Restart with modulo 8 counter 6"),
		new MarkerDictionaryEntry(RST7, "RST7", "Restart with modulo 8 counter 7"),

		new MarkerDictionaryEntry(SOF0, "SOF0", "Huffman Baseline DCT"),
		new MarkerDictionaryEntry(SOF1, "SOF1", "Huffman Extended Sequential DCT"),
		new MarkerDictionaryEntry(SOF2, "SOF2", "Huffman Progressive DCT"),
		new MarkerDictionaryEntry(SOF3, "SOF3", "Huffman Lossless Sequential"),
		new MarkerDictionaryEntry(SOF5, "SOF5", "Huffman Differential Sequential DCT"),
		new MarkerDictionaryEntry(SOF6, "SOF6", "Huffman Differential Progressive DCT"),
		new MarkerDictionaryEntry(SOF7, "SOF7", "Huffman Differential Lossless"),
		new MarkerDictionaryEntry(SOF9, "SOF9", "Arithmetic Extended Sequential DCT"),
		new MarkerDictionaryEntry(SOFA, "SOFA", "Arithmetic Progressive DCT"),
		new MarkerDictionaryEntry(SOFB, "SOFB", "Arithmetic Lossless Sequential"),
		new MarkerDictionaryEntry(SOFD, "SOFD", "Arithmetic Differential Sequential DCT"),
		new MarkerDictionaryEntry(SOFE, "SOFE", "Arithmetic Differential Progressive DCT"),
		new MarkerDictionaryEntry(SOFF, "SOFF", "Arithmetic Differential Lossless"),

		new MarkerDictionaryEntry(SOF55, "SOF55", "LS"),

		new MarkerDictionaryEntry(SOI, "SOI", "Start of Image"),
		new MarkerDictionaryEntry(SOS, "SOS", "Start of Scan"),
		new MarkerDictionaryEntry(TEM, "TEM", "Temporary use with Arithmetic Encoding"),

		new MarkerDictionaryEntry(SOC, "SOC", "Start of codestream"),
		new MarkerDictionaryEntry(SOT, "SOT", "Start of tile-part"),
		new MarkerDictionaryEntry(SOD, "SOD", "Start of data"),
        //new MarkerDictionaryEntry(EOC, "EOC", "End of codestream"),          // same as JPEG EOI
		new MarkerDictionaryEntry(SIZ, "SIZ", "Image and tile size"),
		new MarkerDictionaryEntry(COD, "COD", "Coding style default"),
		new MarkerDictionaryEntry(COC, "COC", "Coding style component"),
		new MarkerDictionaryEntry(RGN, "RGN", "Rgeion-of-interest"),
		new MarkerDictionaryEntry(QCD, "QCD", "Quantization default"),
		new MarkerDictionaryEntry(QCC, "QCC", "Quantization component"),
		new MarkerDictionaryEntry(POC, "POC", "Progression order change"),
		new MarkerDictionaryEntry(TLM, "TLM", "Tile-part lengths"),
		new MarkerDictionaryEntry(PLM, "PLM", "Packet length, main header"),
		new MarkerDictionaryEntry(PLT, "PLT", "Packet length, tile-part header"),
		new MarkerDictionaryEntry(PPM, "PPM", "Packet packer headers, main header"),
		new MarkerDictionaryEntry(PPT, "PPT", "Packet packer headers, tile-part header"),
		new MarkerDictionaryEntry(SOP, "SOP", "Start of packet"),
		new MarkerDictionaryEntry(EPH, "EPH", "End of packet header"),
		new MarkerDictionaryEntry(CRG, "CRG", "Component registration"),
		new MarkerDictionaryEntry(COM2K, "COM", "Comment (JPEG 2000)"),

		new MarkerDictionaryEntry(FF30, "FF30", "Reserved"),
		new MarkerDictionaryEntry(FF31, "FF31", "Reserved"),
		new MarkerDictionaryEntry(FF32, "FF32", "Reserved"),
		new MarkerDictionaryEntry(FF33, "FF33", "Reserved"),
		new MarkerDictionaryEntry(FF34, "FF34", "Reserved"),
		new MarkerDictionaryEntry(FF35, "FF35", "Reserved"),
		new MarkerDictionaryEntry(FF36, "FF36", "Reserved"),
		new MarkerDictionaryEntry(FF37, "FF37", "Reserved"),
		new MarkerDictionaryEntry(FF38, "FF38", "Reserved"),
		new MarkerDictionaryEntry(FF39, "FF39", "Reserved"),
		new MarkerDictionaryEntry(FF3A, "FF3A", "Reserved"),
		new MarkerDictionaryEntry(FF3B, "FF3B", "Reserved"),
		new MarkerDictionaryEntry(FF3C, "FF3C", "Reserved"),
		new MarkerDictionaryEntry(FF3D, "FF3D", "Reserved"),
		new MarkerDictionaryEntry(FF3E, "FF3E", "Reserved"),
		new MarkerDictionaryEntry(FF3F, "FF3F", "Reserved")
	};

	private static final Map<Integer,MarkerDictionaryEntry> mapOfMarkerToDictionaryEntry = new HashMap<Integer,MarkerDictionaryEntry>();
	
	static {
		for (MarkerDictionaryEntry e : markerDictionaryTable) {
			mapOfMarkerToDictionaryEntry.put(new Integer(e.markercode),e);
		}
	}
	
	public static final String getAbbreviation(int marker) {
		MarkerDictionaryEntry e = mapOfMarkerToDictionaryEntry.get(new Integer(marker));
		return e == null ? "" : e.abbreviation;
	}

	
	public static final String getDescription(int marker) {
		MarkerDictionaryEntry e = mapOfMarkerToDictionaryEntry.get(new Integer(marker));
		return e == null ? "" : e.description;
	}

}