1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.jpeg.segments;
18
19 import java.io.PrintWriter;
20
21 import org.apache.commons.imaging.common.BinaryFileParser;
22
23
24
25
26 public abstract class AbstractSegment extends BinaryFileParser {
27
28
29 public final int marker;
30
31
32 public final int length;
33
34
35
36
37
38
39
40 public AbstractSegment(final int marker, final int length) {
41 this.marker = marker;
42 this.length = length;
43 }
44
45 public void dump(final PrintWriter pw) {
46
47 }
48
49
50
51
52
53
54 public abstract String getDescription();
55
56
57
58
59
60
61 public String getSegmentType() {
62 switch (marker) {
63 case 0xffc0:
64 return "Start Of Frame, Baseline Dct, Huffman coding";
65 case 0xffc1:
66 return "Start Of Frame, Extended sequential Dct, Huffman coding";
67 case 0xffc2:
68 return "Start Of Frame, Progressive Dct, Huffman coding";
69 case 0xffc3:
70 return "Start Of Frame, Lossless (sequential), Huffman coding";
71 case 0xffc5:
72 return "Start Of Frame, Differential sequential Dct, Huffman coding";
73 case 0xffc6:
74 return "Start Of Frame, Differential progressive Dct, Huffman coding";
75 case 0xffc7:
76 return "Start Of Frame, Differential lossless (sequential), Huffman coding";
77 case 0xffc8:
78 return "Start Of Frame, Reserved for JPEG extensions, arithmetic coding";
79 case 0xffc9:
80 return "Start Of Frame, Extended sequential Dct, arithmetic coding";
81 case 0xffca:
82 return "Start Of Frame, Progressive Dct, arithmetic coding";
83 case 0xffcb:
84 return "Start Of Frame, Lossless (sequential), arithmetic coding";
85 case 0xffcd:
86 return "Start Of Frame, Differential sequential Dct, arithmetic coding";
87 case 0xffce:
88 return "Start Of Frame, Differential progressive Dct, arithmetic coding";
89 case 0xffcf:
90 return "Start Of Frame, Differential lossless (sequential), arithmetic coding";
91 case 0xffc4:
92 return "Define Huffman table(s)";
93 case 0xffcc:
94 return "Define arithmetic coding conditioning(s)";
95 case 0xffd0:
96 return "Restart with modulo 8 count 0";
97 case 0xffd1:
98 return "Restart with modulo 8 count 1";
99 case 0xffd2:
100 return "Restart with modulo 8 count 2";
101 case 0xffd3:
102 return "Restart with modulo 8 count 3";
103 case 0xffd4:
104 return "Restart with modulo 8 count 4";
105 case 0xffd5:
106 return "Restart with modulo 8 count 5";
107 case 0xffd6:
108 return "Restart with modulo 8 count 6";
109 case 0xffd7:
110 return "Restart with modulo 8 count 7";
111 case 0xffd8:
112 return "Start of image";
113 case 0xffd9:
114 return "End of image";
115 case 0xffda:
116 return "Start of scan";
117 case 0xffdb:
118 return "Define quantization table(s)";
119 case 0xffdc:
120 return "Define number of lines";
121 case 0xffdd:
122 return "Define restart interval";
123 case 0xffde:
124 return "Define hierarchical progression";
125 case 0xffdf:
126 return "Expand reference component(s)";
127
128
129
130
131 case 0xfffe:
132 return "Comment";
133 case 0xff01:
134 return "For temporary private use in arithmetic coding";
135
136
137 default:
138 }
139 if (marker >= 0xff02 && marker <= 0xffbf) {
140 return "Reserved";
141 }
142 if (marker >= 0xffe0 && marker <= 0xffef) {
143 return "APP" + (marker - 0xffe0);
144 }
145 if (marker >= 0xfff0 && marker <= 0xfffd) {
146 return "JPG" + (marker - 0xffe0);
147 }
148 return "Unknown";
149 }
150
151 @Override
152 public String toString() {
153 return "[Segment: " + getDescription() + "]";
154 }
155
156 }