|
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: JP2KPacket class used to collect packet related |
|
15 * information such as tag tree and list of codeblocks. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef __JP2KPACKET_H__ |
|
21 #define __JP2KPACKET_H__ |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include "JP2KEntropyDecoder.h" |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 // MACROS |
|
30 |
|
31 // DATA TYPES |
|
32 |
|
33 // FUNCTION PROTOTYPES |
|
34 |
|
35 // FORWARD DECLARATIONS |
|
36 class CJ2kSubband; |
|
37 class CJ2kTileInfo; |
|
38 class CJ2kComponentInfo; |
|
39 class CJ2kCodeBlock; |
|
40 |
|
41 // CLASS DECLARATION |
|
42 |
|
43 /** |
|
44 * JP2KPacket class used to collect packet related |
|
45 * information such as tag tree, list of codeblocks, |
|
46 * and data used to control where to resume the parsing |
|
47 * of the bitstream. |
|
48 * |
|
49 * JP2KCodec.dll |
|
50 * @since 2.6 |
|
51 */ |
|
52 class CJ2kPacket : public CBase |
|
53 { |
|
54 public: // Constructors and destructor |
|
55 |
|
56 /** |
|
57 * C++ default constructor. |
|
58 */ |
|
59 CJ2kPacket( TUint16 aLayer ); |
|
60 |
|
61 /** |
|
62 * Destructor. |
|
63 */ |
|
64 virtual ~CJ2kPacket(); |
|
65 |
|
66 public: // New functions |
|
67 |
|
68 /** |
|
69 * Set the canvas of the packet |
|
70 * @since 2.6 |
|
71 * @param aX: the x position. |
|
72 * @param aY: the y position. |
|
73 * @param aWidth the width. |
|
74 * @param aHeight: the height. |
|
75 */ |
|
76 void SetPacketCanvas( TInt32 aX, TInt32 aY, TInt32 aWidth, TInt32 aHeight ); |
|
77 |
|
78 /** |
|
79 * Set the number of blocks |
|
80 * @since 2.6 |
|
81 * @param aCodeBlock: the size of the codeblock. |
|
82 */ |
|
83 void SetNumOfBlocks( TSize& aCodeBlock ); |
|
84 |
|
85 /** |
|
86 * Build the inclusive informaiton of the packet |
|
87 * @since 2.6 |
|
88 */ |
|
89 void BuildInclusiveInfoL(); |
|
90 |
|
91 /** |
|
92 * Build the codeblocks in the packet |
|
93 * @since 2.6 |
|
94 * @param aX: the x position. |
|
95 * @param aY: the y position. |
|
96 * @param aCodeBlock: the size of the codeblock. |
|
97 */ |
|
98 void BuildCodeBlocksL( TInt32 aX, TInt32 aY, TSize& aCodeBlock ); |
|
99 |
|
100 /** |
|
101 * Read the packet header |
|
102 * @since 2.6 |
|
103 * @param aTile: a reference to CJ2kTileInfo object. |
|
104 * @param aComponent: a reference to CJ2kComponentInfo object. |
|
105 * @param aSubband: a reference to CJ2kSubband object. |
|
106 * @return TUint8: true if incomplete. |
|
107 */ |
|
108 TUint8 ReadPacketHeaderL( CJ2kTileInfo& aTile, CJ2kComponentInfo& aComponent, CJ2kSubband& aSubband ); |
|
109 |
|
110 /** |
|
111 * Read the packet body |
|
112 * @since 2.6 |
|
113 * @param aTile: a reference to CJ2kTileInfo object. |
|
114 * @param aComponent: a reference to CJ2kComponentInfo object. |
|
115 * @param aSubband: a reference to CJ2kSubband object. |
|
116 * @return TUint8: true if incomplete. |
|
117 */ |
|
118 TUint8 ReadPacketBodyL( CJ2kTileInfo& aTile, CJ2kComponentInfo& aComponent, CJ2kSubband& aSubband ); |
|
119 |
|
120 /** |
|
121 * Reset the internal flags |
|
122 * @since 2.6 |
|
123 */ |
|
124 void ResetInternalFlags(); |
|
125 |
|
126 /** |
|
127 * Get the last codeblock processed |
|
128 * @since 2.6 |
|
129 * @return TUint16: the last codeblock processed. |
|
130 */ |
|
131 TUint16 LastCodeBlockProcessed() const; |
|
132 |
|
133 /** |
|
134 * Set the last codeblock processed |
|
135 * @since 2.6 |
|
136 * @param aLastCodeBlock: the last codeblock processed. |
|
137 */ |
|
138 void SetLastCodeBlockProcessed( TUint16 aLastCodeBlock ); |
|
139 |
|
140 /** |
|
141 * Get number of blocks |
|
142 * @since 2.6 |
|
143 * @return TUint16: number of codeblocks. |
|
144 */ |
|
145 TUint16 NumOfBlocks() const; |
|
146 |
|
147 /** |
|
148 * Get number of blocks in horizontal direction |
|
149 * @since 2.6 |
|
150 * @return TUint16: number of codeblock in X direction. |
|
151 */ |
|
152 TUint16 NumOfBlocksX() const; |
|
153 |
|
154 /** |
|
155 * Get number of blocks in vertical direction |
|
156 * @since 2.6 |
|
157 * @return TUint16: number of codeblock in Y direction. |
|
158 */ |
|
159 TUint16 NumOfBlocksY() const; |
|
160 |
|
161 /** |
|
162 * Get the canvas of the packet |
|
163 * @since 2.6 |
|
164 * @return TRect&: a reference to the packet's canvas. |
|
165 */ |
|
166 const CJ2kCodeBlock& CodeBlockAt( TUint16 aIndex ) const; |
|
167 |
|
168 /** |
|
169 * Is packet body read underflow |
|
170 * @since 2.6 |
|
171 * @return TUint8: true if packet body incomplete. |
|
172 */ |
|
173 TUint8 IsBodyIncomplete() const; |
|
174 |
|
175 public: // Functions from base classes |
|
176 |
|
177 protected: // New functions |
|
178 |
|
179 protected: // Functions from base classes |
|
180 |
|
181 private: |
|
182 |
|
183 /** |
|
184 * Build the tag trees |
|
185 * @since 2.6 |
|
186 */ |
|
187 void BuildTagtreeL(); |
|
188 |
|
189 /** |
|
190 * Decode the included tag tree |
|
191 * @since 2.6 |
|
192 * @param aTile: a reference to CJ2kTileInfo object. |
|
193 * @param aWidth: the width. |
|
194 * @param aHeight: the height. |
|
195 * @param aValue: a reference to the TUint16. |
|
196 * @return TUint8: true if incomplete. |
|
197 */ |
|
198 TUint8 DecodeIncTagtree( CJ2kTileInfo& aTile, TUint32 aWidth, TUint32 aHeight, TUint16& aValue ); |
|
199 |
|
200 /** |
|
201 * Decode the msb tag tree |
|
202 * @since 2.6 |
|
203 * @param aTile: a reference to CJ2kTileInfo object. |
|
204 * @param aWidth: the width. |
|
205 * @param aHeight: the height. |
|
206 * @param aValue: a reference to the TUint16. |
|
207 * @return TUint8: true if incomplete. |
|
208 */ |
|
209 TUint8 DecodeMsbTagtree( CJ2kTileInfo& aTile, TUint32 aWidth, TUint32 aHeight, TUint16& aValue ); |
|
210 |
|
211 /** |
|
212 * Backup the included tag tree |
|
213 * @since 2.6 |
|
214 * @param aTagValue: a reference to the value descriptor pointer. |
|
215 * @param aTagState: a reference to the state descriptor pointer. |
|
216 */ |
|
217 void BackupIncTagtreeL( HBufC16*& aTagValue, HBufC16*& aTagState ); |
|
218 |
|
219 /** |
|
220 * Backup the msb tag tree |
|
221 * @since 2.6 |
|
222 * @param aTagValue: a reference to the value descriptor pointer. |
|
223 * @param aTagState: a reference to the state descriptor pointer. |
|
224 */ |
|
225 void BackupMsbTagtreeL( HBufC16*& aTagValue, HBufC16*& aTagState ); |
|
226 |
|
227 /** |
|
228 * Restore the included tag tree |
|
229 * @since 2.6 |
|
230 * @param aTagValue: a pointer to the value descriptor. |
|
231 * @param aTagState: a pointer to the state descriptor. |
|
232 */ |
|
233 void RestoreIncTagtree( HBufC16 *aTagValue, HBufC16 *aTagState ); |
|
234 |
|
235 /** |
|
236 * Restore the msb tag tree |
|
237 * @since 2.6 |
|
238 * @param a |
|
239 * @param aTagValue: a pointer to the value descriptor. |
|
240 * @param aTagState: a pointer to the state descriptor. |
|
241 */ |
|
242 void RestoreMsbTagtree( HBufC16 *aTagValue, HBufC16 *aTagState ); |
|
243 |
|
244 /** |
|
245 * Release the temporary backup memory |
|
246 * @since 2.6 |
|
247 * @param aTagValue: a reference to the include value descriptor pointer. |
|
248 * @param aTagState: a reference to the include state descriptor pointer. |
|
249 * @param aTagValue: a reference to the msb value descriptor pointer. |
|
250 * @param aTagState: a reference to the msb state descriptor pointer. |
|
251 */ |
|
252 void FreeBackupTagtree( HBufC16*& aIncTagValue, HBufC16*& aIncTagState, |
|
253 HBufC16*& aMsbTagValue, HBufC16*& aMsbTagState ); |
|
254 |
|
255 /** |
|
256 * Is the layer has been included in the previous packet |
|
257 * @since 2.6 |
|
258 * @param aLayer: the layer |
|
259 * @return TUint8: true if layer has been included. |
|
260 */ |
|
261 TUint8 IsIncludedL( TUint16 aLayer ); |
|
262 |
|
263 /** |
|
264 * Get the inclusive information at specific layer |
|
265 * @since 2.6 |
|
266 * @param aLayer: the layer. |
|
267 * @return TUint8: inclusive information. |
|
268 */ |
|
269 TUint8 IncludedAt( TUint16 aLayer ) const; |
|
270 |
|
271 /** |
|
272 * Set the inclusive information at specific layer |
|
273 * @since 2.6 |
|
274 * @param aLayer: the layer. |
|
275 */ |
|
276 void SetIncluded( TUint16 aLayer ); |
|
277 |
|
278 /** |
|
279 * Is tag tree backup is required for underflow recovery |
|
280 * @since 2.6 |
|
281 * @param aTile: a reference to CJ2kTileInfo object. |
|
282 * @return TUint8: true if backup is needed. |
|
283 */ |
|
284 TUint8 IsBackupNeeded( CJ2kTileInfo& aTile ); |
|
285 |
|
286 /** |
|
287 * Start reading from packet header stream |
|
288 * @since 2.6 |
|
289 * @param aTile: a reference to CJ2kTileInfo object. |
|
290 * @return TUint8: true if end of buffer. |
|
291 */ |
|
292 TUint8 StartReadBit( CJ2kTileInfo& aTile ); |
|
293 |
|
294 /** |
|
295 * Read a bit from the packet header stream |
|
296 * @since 2.6 |
|
297 * @param aBit: get a bit from the packet header bitstream. |
|
298 * @param aTile: a reference to CJ2kTileInfo object. |
|
299 * @return TUint8: true if end of buffer. |
|
300 */ |
|
301 TUint8 ReadBit( TUint8& aBit, CJ2kTileInfo& aTile ); |
|
302 |
|
303 /** |
|
304 * Read some bits from the packet header stream |
|
305 * @since 2.6 |
|
306 * @param aBit: get some bits from the packet header bitstream. |
|
307 * @param aBitLen: how many bits to read. |
|
308 * @param aTile: a reference to CJ2kTileInfo object. |
|
309 * @return TUint8: true if end of buffer. |
|
310 */ |
|
311 TUint8 ReadBits( TUint8& aBit, TUint8 aBitLen, CJ2kTileInfo& aTile ); |
|
312 |
|
313 /** |
|
314 * Read some bits from the packet header stream |
|
315 * @since 2.6 |
|
316 * @param aBit: get some bits from the packet header bitstream. |
|
317 * @param aBitLen: how many bits to read. |
|
318 * @param aTile: a reference to CJ2kTileInfo object. |
|
319 * @return TUint8: true if end of buffer. |
|
320 */ |
|
321 TUint8 ReadBits( TUint32& aBit, TUint8 aBitLen, CJ2kTileInfo& aTile ); |
|
322 |
|
323 /** |
|
324 * Align the stream to the next byte boundary if necessary |
|
325 * @since 2.6 |
|
326 * @param aTile: a reference to CJ2kTileInfo object. |
|
327 */ |
|
328 void AlignReader( CJ2kTileInfo& aTile ); |
|
329 |
|
330 /** |
|
331 * Try to consume the SOP marker if there is one |
|
332 * @since 2.6 |
|
333 * @param aTile: a reference to CJ2kTileInfo object. |
|
334 * @return TUint8: true if end of buffer. |
|
335 */ |
|
336 TUint8 ReadSOPMarker( CJ2kTileInfo& aTile ); |
|
337 |
|
338 /** |
|
339 * Try to consume the EPH marker if there is one |
|
340 * @since 2.6 |
|
341 * @param aTile: a reference to CJ2kTileInfo object. |
|
342 * @return TUint8: true if end of buffer. |
|
343 */ |
|
344 TUint8 ReadEPHMarker( CJ2kTileInfo& aTile ); |
|
345 |
|
346 /** |
|
347 * Try to re-align stream to next byte boundary if necessary, |
|
348 * Try to consume the previous leftover EPH marker if there is one, |
|
349 * Try to consume the SOP marker if there is one |
|
350 * @since 2.6 |
|
351 * @param aComponent: a reference to CJ2kComponentInfo object. |
|
352 * @param aTile: a reference to CJ2kTileInfo object. |
|
353 * @param aSOP: true if to try SOP marker. |
|
354 * @return TUint8: true if end of buffer. |
|
355 */ |
|
356 TUint8 ReadSOP_EPHMarker( CJ2kComponentInfo& aComponent, CJ2kTileInfo& aTile, TBool aSOP = ETrue ); |
|
357 |
|
358 /** |
|
359 * Get the included tag tree value at specific level and width |
|
360 * @since 2.6 |
|
361 * @param aLevel: the layer. |
|
362 * @param aWidth: the width. |
|
363 * @return TUint16: the include tag value. |
|
364 */ |
|
365 TUint16 IncTagValue( TUint16 aLevel, TUint16 aWidth ) const; |
|
366 |
|
367 /** |
|
368 * Get the included tag tree state at specific level and width |
|
369 * @since 2.6 |
|
370 * @param aLevel: the layer. |
|
371 * @param aWidth: the width. |
|
372 * @return TUint16: the include tag state. |
|
373 */ |
|
374 TUint16 IncTagState( TUint16 aLevel, TUint16 aWidth ) const; |
|
375 |
|
376 /** |
|
377 * Get the msb tag tree value at specific level and width |
|
378 * @since 2.6 |
|
379 * @param aLevel: the layer. |
|
380 * @param aWidth: the width. |
|
381 * @return TUint16: the msb tag value. |
|
382 */ |
|
383 TUint16 MsbTagValue( TUint16 aLevel, TUint16 aWidth ) const; |
|
384 |
|
385 /** |
|
386 * Get the msb tag tree state at specific level and width |
|
387 * @since 2.6 |
|
388 * @param aLevel: the layer. |
|
389 * @param aWidth: the width. |
|
390 * @return TUint16: the msb tag state. |
|
391 */ |
|
392 TUint16 MsbTagState( TUint16 aLevel, TUint16 aWidth ) const; |
|
393 |
|
394 /** |
|
395 * Set the included tag tree value at specific level and width |
|
396 * @since 2.6 |
|
397 * @param aLevel: the layer. |
|
398 * @param aWidth: the width. |
|
399 * @param aValue: the value. |
|
400 */ |
|
401 void SetIncTagValue( TUint16 aLevel, TUint16 aWidth, TUint16 aValue ); |
|
402 |
|
403 /** |
|
404 * Set the included tag tree state at specific level and width |
|
405 * @since 2.6 |
|
406 * @param aLevel: the layer. |
|
407 * @param aWidth: the width. |
|
408 * @param aState: the state. |
|
409 */ |
|
410 void SetIncTagState( TUint16 aLevel, TUint16 aWidth, TUint16 aState ); |
|
411 |
|
412 /** |
|
413 * Increment the included tag tree state at specific level and width |
|
414 * @since 2.6 |
|
415 * @param aLevel: the layer. |
|
416 * @param aWidth: the width. |
|
417 */ |
|
418 void IncrementIncTagState( TUint16 aLevel, TUint16 aWidth ); |
|
419 |
|
420 /** |
|
421 * Set the msb tag tree value at specific level and width |
|
422 * @since 2.6 |
|
423 * @param aLevel: the layer. |
|
424 * @param aWidth: the width. |
|
425 * @param aValue: the value. |
|
426 */ |
|
427 void SetMsbTagValue( TUint16 aLevel, TUint16 aWidth, TUint16 aValue ); |
|
428 |
|
429 /** |
|
430 * Set the msb tag tree state at specific level and width |
|
431 * @since 2.6 |
|
432 * @param aLevel: the layer. |
|
433 * @param aWidth: the width. |
|
434 * @param aState: the state. |
|
435 */ |
|
436 void SetMsbTagState( TUint16 aLevel, TUint16 aWidth, TUint16 aState ); |
|
437 |
|
438 /** |
|
439 * Increment the msb tag tree state at specific level and width |
|
440 * @since 2.6 |
|
441 * @param aLevel: the layer. |
|
442 * @param aWidth: the width. |
|
443 */ |
|
444 void IncrementMsbTagState( TUint16 aLevel, TUint16 aWidth ); |
|
445 |
|
446 /** |
|
447 * Is packet header has been read |
|
448 * @since 2.6 |
|
449 * @return TUint8: true if packet header has been read. |
|
450 */ |
|
451 TUint8 IsHeader() const; |
|
452 |
|
453 /** |
|
454 * Set the flag to indicate that packet header has been read |
|
455 * @since 2.6 |
|
456 */ |
|
457 void SetHeader(); |
|
458 |
|
459 /** |
|
460 * Reset the flag to indicate that packet header has not been read |
|
461 * @since 2.6 |
|
462 */ |
|
463 void ResetHeader(); |
|
464 |
|
465 /** |
|
466 * Is packet body has been read |
|
467 * @since 2.6 |
|
468 * @return TUint8: true if packet body has been read. |
|
469 */ |
|
470 TUint8 IsBody() const; |
|
471 |
|
472 /** |
|
473 * Set the flag to indicate that packet body has been read |
|
474 * @since 2.6 |
|
475 */ |
|
476 void SetBody(); |
|
477 |
|
478 /** |
|
479 * Reset the flag to indicate that packet body has not been read |
|
480 * @since 2.6 |
|
481 */ |
|
482 void ResetBody(); |
|
483 |
|
484 /** |
|
485 * Set the flag to indicate that packet body read underflow |
|
486 * @since 2.6 |
|
487 */ |
|
488 void SetBodyIncomplete(); |
|
489 |
|
490 /** |
|
491 * Reset the flag to indicate that packet body read is not underflow |
|
492 * @since 2.6 |
|
493 */ |
|
494 void ResetBodyIncomplete(); |
|
495 |
|
496 /** |
|
497 * Is the read recover from previous underflow |
|
498 * @since 2.6 |
|
499 * @return TUint8: true if recover from previous underflow. |
|
500 */ |
|
501 TUint8 IsRecoverFromIncomplete() const; |
|
502 |
|
503 /** |
|
504 * Set the flag to indicate that the next read is recover from underflow |
|
505 * @since 2.6 |
|
506 */ |
|
507 void SetRecoverFromIncomplete(); |
|
508 |
|
509 /** |
|
510 * Reset the flag to indicate that the next read is not recover from underflow |
|
511 * @since 2.6 |
|
512 */ |
|
513 void ResetRecoverFromIncomplete(); |
|
514 |
|
515 /** |
|
516 * Is codeblock number should iLastCodeBlock |
|
517 * @since 2.6 |
|
518 * @return TUint8: true if codeblock number should match with iLastCodeBlock. |
|
519 */ |
|
520 TUint8 IsMatch() const; |
|
521 |
|
522 /** |
|
523 * Set the flag to indicate that the next codeblock should match iLastCodeBlock |
|
524 * @since 2.6 |
|
525 */ |
|
526 void ResetMatch(); |
|
527 |
|
528 /** |
|
529 * Reset the flag to indicate that the next codeblock should be greater than |
|
530 * iLastCodeBlock |
|
531 * @since 2.6 |
|
532 */ |
|
533 void SetMatch(); |
|
534 |
|
535 public: // Data |
|
536 |
|
537 protected: // Data |
|
538 |
|
539 private: // Data |
|
540 |
|
541 // Flags to control the parsing of bitstream |
|
542 enum TReadPacket |
|
543 { |
|
544 EReadHeader = 0x01, |
|
545 EReadBody = 0x02, |
|
546 EReadBodyIncomplete = 0x04, |
|
547 EReadRecoverFromIncomplete = 0x08, |
|
548 EReadMatchLastCodeBlock = 0x10 |
|
549 }; |
|
550 |
|
551 // Canvas of the packet |
|
552 TRect iPacketCanvas; |
|
553 |
|
554 // Codeblock size |
|
555 TSize iCodeBlockSize; |
|
556 |
|
557 // Tag tree level |
|
558 TUint8 iTagTreeLevel; |
|
559 |
|
560 // Control flags |
|
561 TUint8 iReadControl; |
|
562 |
|
563 // Inclusive layer number |
|
564 TUint16 iLayer; |
|
565 |
|
566 // Last codeblock processed |
|
567 TUint16 iLastCodeBlock; |
|
568 |
|
569 // Inclusive information |
|
570 HBufC8 *iIncluded; |
|
571 |
|
572 // Tagtree information |
|
573 HBufC16 *iTagTreeInfo; |
|
574 |
|
575 // Included tag tree value |
|
576 HBufC16 *iIncTagTreeValue; |
|
577 |
|
578 // Included tag tree state |
|
579 HBufC16 *iIncTagTreeState; |
|
580 |
|
581 // MSB tag tree value |
|
582 HBufC16 *iMsbTagTreeValue; |
|
583 |
|
584 // MSB tag tree state |
|
585 HBufC16 *iMsbTagTreeState; |
|
586 |
|
587 // List of codeblocks |
|
588 RPointerArray<CJ2kCodeBlock> iCodeBlockList; |
|
589 |
|
590 public: // Friend classes |
|
591 |
|
592 protected: // Friend classes |
|
593 |
|
594 private: // Friend classes |
|
595 |
|
596 }; |
|
597 |
|
598 // For inliners. |
|
599 #include "JP2KPacket.inl" |
|
600 |
|
601 #endif // __JP2KPACKET_H__ |
|
602 |