|
1 /* |
|
2 * Copyright (c) 2003, 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CJp2kReadCodec class implements the ICL read codec interface. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __JP2KCODEC_H__ |
|
20 #define __JP2KCODEC_H__ |
|
21 |
|
22 // INCLUDES |
|
23 #include <icl/imageprocessor.h> |
|
24 #include <icl/imagecodec.h> |
|
25 #include <icl/imagecodecdata.h> |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 // Delimiting marker segments |
|
30 const TUint16 KSOC = 0xFF4F; // Start of codestream |
|
31 const TUint16 KSOT = 0xFF90; // Start of tile-part |
|
32 const TUint16 KSOD = 0xFF93; // Start of data |
|
33 const TUint16 KEOC = 0xFFD9; // End of codestream |
|
34 |
|
35 // Fixed information marker segments |
|
36 const TUint16 KSIZ = 0xFF51; // Image and tile size |
|
37 |
|
38 // Functional marker segments |
|
39 const TUint16 KCOD = 0xFF52; // Coding style default |
|
40 const TUint16 KCOC = 0xFF53; // Coding style component |
|
41 const TUint16 KRGN = 0xFF5E; // Region of interest |
|
42 const TUint16 KQCD = 0xFF5C; // Quantization default |
|
43 const TUint16 KQCC = 0xFF5D; // Quantization component |
|
44 const TUint16 KPOC = 0xFF5F; // Progression order default |
|
45 |
|
46 // Pointer marker segments |
|
47 const TUint16 KTLM = 0xFF55; // Tile-part lengths, main header |
|
48 const TUint16 KPLM = 0xFF57; // Packet length, main header |
|
49 const TUint16 KPLT = 0xFF58; // Packet length, tile-part header |
|
50 const TUint16 KPPM = 0xFF60; // Packed packet headers, main header |
|
51 const TUint16 KPPT = 0xFF61; // Packed packet headers, tile-part header |
|
52 |
|
53 // Informational marker segments |
|
54 const TUint16 KCME = 0xFF64; // Comment and extension |
|
55 const TUint16 KCRG = 0xFF63; // Component registration |
|
56 |
|
57 // Packet information |
|
58 const TUint16 KSOP = 0xFF91; // Start of packet |
|
59 const TUint16 KEPH = 0xFF92; // End of packet header |
|
60 const TUint16 KSOP_LEN = 0x04; // Length of the SOP |
|
61 |
|
62 // Extensions marker segments |
|
63 const TUint16 KEXTS = 0xFF30; // Start of extensions |
|
64 const TUint16 KEXTE = 0xFF3F; // End Of extensions |
|
65 |
|
66 const TUint16 KMarkerSize = 2; // Size of a marker - 2 bytes |
|
67 const TUint16 KMarkerLength = 2; // Size of a length - 2 bytes |
|
68 const TUint16 KMarkerMinLength = KMarkerSize + KMarkerLength; |
|
69 |
|
70 // MACROS |
|
71 |
|
72 // DATA TYPES |
|
73 |
|
74 // FUNCTION PROTOTYPES |
|
75 |
|
76 // FORWARD DECLARATIONS |
|
77 class TJ2kInfo; |
|
78 class CJ2kImageInfo; |
|
79 class TJ2kStreamReader; |
|
80 class CJ2kEntropyDecoder; |
|
81 class CJ2kImageWriter; |
|
82 class CJ2kSynthesis; |
|
83 class CJ2kTileInfo; |
|
84 |
|
85 // CLASS DECLARATION |
|
86 |
|
87 /** |
|
88 * CJp2kReadCodec JPEG2000 image read codec class. |
|
89 * Implement the ICL read codec interface. |
|
90 * |
|
91 * JP2KCodec.dll |
|
92 * @since 2.6 |
|
93 */ |
|
94 class CJp2kReadCodec : public CImageProcessorReadCodec //lint !e768 Will be referenced by framework. |
|
95 { |
|
96 public: // Constructors and destructor |
|
97 |
|
98 /** |
|
99 * Two-phased constructor. |
|
100 */ |
|
101 static CJp2kReadCodec* NewL( const TJ2kInfo& aJ2kInfo ); |
|
102 |
|
103 /** |
|
104 * Destructor. |
|
105 */ |
|
106 virtual ~CJp2kReadCodec(); |
|
107 |
|
108 public: // New functions |
|
109 |
|
110 /** |
|
111 * Decoding the current tile-part. |
|
112 * @since 2.6 |
|
113 * @return TFrameState: frame state after decoding the current tile-part. |
|
114 */ |
|
115 TFrameState DecodeTileL(); |
|
116 |
|
117 /** |
|
118 * Is codec in the decoding state. |
|
119 * @since 2.6 |
|
120 * @return TBool: false if codec in the parsing state. |
|
121 */ |
|
122 TBool IsDecodeTile() const; |
|
123 |
|
124 public: // Functions from base classes |
|
125 |
|
126 /** |
|
127 * From CImageReadCodec |
|
128 * @since 2.6 |
|
129 * @param aFrameInfo: Frame information. |
|
130 * @param aFrameData: Frame data. |
|
131 */ |
|
132 void InitFrameHeader( TFrameInfo& aFrameInfo, CFrameImageData& aFrameData ); |
|
133 |
|
134 /** |
|
135 * From CImageReadCodec |
|
136 * @since 2.6 |
|
137 * @param aData: Data to be processed. |
|
138 */ |
|
139 TFrameState ProcessFrameHeaderL( TBufPtr8& aData ); |
|
140 |
|
141 /** |
|
142 * From CImageReadCodec |
|
143 * @since 2.6 |
|
144 * @param aFrameInfo: Frame information. |
|
145 * @param aFrameData: Frame data. |
|
146 * @param aDisableErrorDiffusion: Use error diffusion or not. |
|
147 * @param aDestination: Destination bitmap. |
|
148 * @param aDestinationMask: Destination bitmap mask. |
|
149 */ |
|
150 void InitFrameL( TFrameInfo& aFrameInfo, CFrameImageData& aFrameData, |
|
151 TBool aDisableErrorDiffusion, CFbsBitmap& aDestination, |
|
152 CFbsBitmap *aDestinationMask ); |
|
153 |
|
154 /** |
|
155 * From CImageReadCodec |
|
156 * @since 2.6 |
|
157 * @param aSrc: Source data. |
|
158 */ |
|
159 TFrameState ProcessFrameL( TBufPtr8& aSrc ); |
|
160 |
|
161 /** |
|
162 * From CImageReadCodec |
|
163 * @since 2.6 |
|
164 * @param aPosition: New position in data. |
|
165 * @param aLength: Number of bytes to read. |
|
166 */ |
|
167 void GetNewDataPosition(TInt& aPosition, TInt& aLength); |
|
168 |
|
169 protected: // New functions |
|
170 |
|
171 protected: // Functions from base classes |
|
172 |
|
173 private: |
|
174 |
|
175 /** |
|
176 * C++ default constructor. |
|
177 */ |
|
178 CJp2kReadCodec( const TJ2kInfo& aJ2kInfo ); |
|
179 |
|
180 /** |
|
181 * By default Symbian 2nd phase constructor is private. |
|
182 */ |
|
183 void ConstructL(); |
|
184 |
|
185 /** |
|
186 * Verify and process Start of Codestream (SOC marker) |
|
187 * @since 2.6 |
|
188 */ |
|
189 TFrameState ReadSOCL(); |
|
190 |
|
191 /** |
|
192 * Verify and process Image and Tile Size (SIZ marker) |
|
193 * @since 2.6 |
|
194 */ |
|
195 TFrameState ReadSIZL(); |
|
196 |
|
197 /** |
|
198 * Verify and process Coding Style Default (COD marker) |
|
199 * @since 2.6 |
|
200 * @param aMain: true for Main Header, false for Tile Part Header. |
|
201 */ |
|
202 TFrameState ReadCODL( TBool aMain = ETrue ); |
|
203 |
|
204 /** |
|
205 * Verify and process Coding Style Component (COC marker) |
|
206 * @since 2.6 |
|
207 * @param aMain: true for Main Header, false for Tile Part Header. |
|
208 */ |
|
209 TFrameState ReadCOCL( TBool aMain = ETrue ); |
|
210 |
|
211 /** |
|
212 * Verify and process Quantization Default (QCD marker) |
|
213 * @since 2.6 |
|
214 * @param aMain: true for Main Header, false for Tile Part Header. |
|
215 */ |
|
216 TFrameState ReadQCDL( TBool aMain = ETrue ); |
|
217 |
|
218 /** |
|
219 * Verify and process Quantization Component (QCC marker) |
|
220 * @since 2.6 |
|
221 * @param aMain: true for Main Header, false for Tile Part Header. |
|
222 */ |
|
223 TFrameState ReadQCCL( TBool aMain = ETrue ); |
|
224 |
|
225 /** |
|
226 * Verify and process Region of Interest (RGN marker) |
|
227 * @since 2.6 |
|
228 * @param aMain: true for Main Header, false for Tile Part Header. |
|
229 */ |
|
230 TFrameState ReadRGNL( TBool aMain = ETrue ); |
|
231 |
|
232 /** |
|
233 * Verify and process Progression Order Change (POC marker) |
|
234 * @since 2.6 |
|
235 * @param aMain: true for Main Header, false for Tile Part Header. |
|
236 */ |
|
237 TFrameState ReadPOCL( TBool aMain = ETrue ); |
|
238 |
|
239 /** |
|
240 * Verify and process Packed Packet Headers, Main Header (PPM marker) |
|
241 * @since 2.6 |
|
242 */ |
|
243 TFrameState ReadPPML(); |
|
244 |
|
245 /** |
|
246 * Verify and process Tile Part Lengths, Main Header (TLM marker) |
|
247 * @since 2.6 |
|
248 */ |
|
249 TFrameState ReadTLML(); |
|
250 |
|
251 /** |
|
252 * Verify and process Packet Length, Main Header (PLM marker) |
|
253 * @since 2.6 |
|
254 */ |
|
255 TFrameState ReadPLML(); |
|
256 |
|
257 /** |
|
258 * Verify and process Component Registration, Main Header (CRG marker) |
|
259 * @since 2.6 |
|
260 */ |
|
261 TFrameState ReadCRGL(); |
|
262 |
|
263 /** |
|
264 * Verify and process Comment (COM marker) |
|
265 * @since 2.6 |
|
266 * @param aMain: true for Main Header, false for Tile Part Header. |
|
267 */ |
|
268 TFrameState ReadCOML( TBool aMain = ETrue ); |
|
269 |
|
270 /** |
|
271 * Verify and process Start of Tile Part (SOT marker) |
|
272 * @since 2.6 |
|
273 */ |
|
274 TFrameState ReadSOTL(); |
|
275 |
|
276 /** |
|
277 * Verify and process Start of Data (SOD marker) |
|
278 * @since 2.6 |
|
279 */ |
|
280 TFrameState ReadSODL(); |
|
281 |
|
282 /** |
|
283 * Verify and process BitStream Data |
|
284 * @since 2.6 |
|
285 */ |
|
286 TFrameState ReadBitStreamL(); |
|
287 |
|
288 /** |
|
289 * Verify and process Packed Packet Headers, Tile Part Header (PPT marker) |
|
290 * @since 2.6 |
|
291 */ |
|
292 TFrameState ReadPPTL(); |
|
293 |
|
294 /** |
|
295 * Verify and process Packet Length, Tile Part Header (PLT marker) |
|
296 * @since 2.6 |
|
297 */ |
|
298 TFrameState ReadPLTL(); |
|
299 |
|
300 /** |
|
301 * Ignore the content and advance the iterator to the next marker |
|
302 * @since 2.6 |
|
303 */ |
|
304 TFrameState ReadSkipTileL(); |
|
305 |
|
306 /** |
|
307 * Update the current state according to the marker type |
|
308 * @since 2.6 |
|
309 */ |
|
310 TFrameState UpdateStateFromMarkerL(); |
|
311 |
|
312 /** |
|
313 * Decode the tile and delete it after decoding |
|
314 * @since 2.6 |
|
315 * @param aTile: a reference to the tile to decode. |
|
316 */ |
|
317 void DecodeAndDeleteTileL( CJ2kTileInfo& aTile ); |
|
318 |
|
319 /** |
|
320 * Convert metadata from file format to TImageDataBlock derived objects |
|
321 * @since 2.6 |
|
322 */ |
|
323 void ConvertImageDataL(); |
|
324 |
|
325 public: // Data |
|
326 |
|
327 // State machine represent the state when parsing of the JP2 codestream. |
|
328 enum TFrameHeaderState |
|
329 { |
|
330 EStateInSOC, |
|
331 EStateInSIZ, |
|
332 EStateInCOD, |
|
333 EStateInCOC, |
|
334 EStateInQCD, |
|
335 EStateInQCC, |
|
336 EStateInRGN, |
|
337 EStateInPOC, |
|
338 EStateInPPM, |
|
339 EStateInTLM, |
|
340 EStateInPLM, |
|
341 EStateInCRG, |
|
342 EStateInCOM, |
|
343 EStateInSOT, |
|
344 EStateInPPT, |
|
345 EStateInPLT, |
|
346 EStateInSOD, |
|
347 EStateInBITSTREAM, |
|
348 EStateInEOC, |
|
349 EStateInSkipTile, |
|
350 EStateInUnknown |
|
351 }; |
|
352 |
|
353 protected: // Data |
|
354 |
|
355 private: // Data |
|
356 |
|
357 // Decoding style. |
|
358 enum TDecoderStyle |
|
359 { |
|
360 ETileBasedDecoder, // Tile-based decoding |
|
361 EBlockBasedDecoder, // Block-based wavelet |
|
362 EUnknownDecoder // Use some logic to choose the style to use |
|
363 }; |
|
364 |
|
365 // JP2 file format information |
|
366 const TJ2kInfo& iJ2kInfo; |
|
367 |
|
368 // Frame information |
|
369 TFrameInfo *iFrame; |
|
370 |
|
371 // Frame data, owned by framework |
|
372 CFrameImageData *iFrameData; |
|
373 |
|
374 // Index of last tile processed |
|
375 TUint16 iLastTileIndex; |
|
376 |
|
377 // Current state |
|
378 TFrameHeaderState iFHState; |
|
379 |
|
380 // Indicate new tile to be processed |
|
381 TUint8 iUseNewTile; |
|
382 |
|
383 // Indicate next tile to be processed |
|
384 TUint8 iUseNextTile; |
|
385 |
|
386 // Tiles are in sequential order |
|
387 TUint8 iSequential; |
|
388 |
|
389 // Reference to stream reader |
|
390 TJ2kStreamReader iReader; |
|
391 |
|
392 // .jp2 image information |
|
393 CJ2kImageInfo *iImageInfo; |
|
394 |
|
395 // To handle the underflow PPM |
|
396 TPPMMarker *iPreviousPPM; |
|
397 |
|
398 // To handle the underflow COM |
|
399 TCOMMarker *iPreviousCOM; |
|
400 |
|
401 // The entropy decoder |
|
402 CJ2kEntropyDecoder *iEntropy; |
|
403 |
|
404 // The image write |
|
405 CJ2kImageWriter *iImageWriter; |
|
406 |
|
407 // The synthesis |
|
408 CJ2kSynthesis *iSynthesis; |
|
409 |
|
410 // The decoding mechanism used |
|
411 TDecoderStyle iStyleUsed; |
|
412 |
|
413 // Indicate a progression bar is needed for single tile image |
|
414 TBool iProgressBar; |
|
415 |
|
416 // Indicate the codec state |
|
417 TBool iDecodeTile; |
|
418 |
|
419 public: // Friend classes |
|
420 |
|
421 protected: // Friend classes |
|
422 |
|
423 private: // Friend classes |
|
424 }; |
|
425 |
|
426 #endif // __JP2KCODEC_H__ |
|
427 |