|
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: CJ2kComponentInfo class used to collect component related |
|
15 * information such as precincts size at each resolution level and |
|
16 * list of subbands. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include "JP2KTileInfo.h" |
|
24 #include "JP2KImageInfo.h" |
|
25 #include "JP2KSubband.h" |
|
26 #include "JP2KComponentInfo.h" |
|
27 |
|
28 // EXTERNAL DATA STRUCTURES |
|
29 |
|
30 // EXTERNAL FUNCTION PROTOTYPES |
|
31 |
|
32 // CONSTANTS |
|
33 |
|
34 // MACROS |
|
35 |
|
36 // LOCAL CONSTANTS AND MACROS |
|
37 |
|
38 // MODULE DATA STRUCTURES |
|
39 |
|
40 // LOCAL FUNCTION PROTOTYPES |
|
41 |
|
42 // FORWARD DECLARATIONS |
|
43 |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CJ2kComponentInfo::NewLC |
|
48 // Two-phased constructor. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CJ2kComponentInfo* CJ2kComponentInfo::NewLC( CJ2kTileInfo& aTile, TUint16 aIndex ) |
|
52 { |
|
53 CJ2kComponentInfo* self = new ( ELeave ) CJ2kComponentInfo; |
|
54 |
|
55 CleanupStack::PushL(self); |
|
56 self->ConstructL( aTile, aIndex ); |
|
57 |
|
58 return self; |
|
59 } |
|
60 |
|
61 // Destructor |
|
62 CJ2kComponentInfo::~CJ2kComponentInfo() |
|
63 { |
|
64 delete iRootSubband; |
|
65 iRootSubband = 0; |
|
66 |
|
67 iPrecinctSizeList.Close(); |
|
68 iGridList.Close(); |
|
69 |
|
70 // iExponentList and iMantissaList are not owned by this object |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CJ2kComponentInfo::LRCPProgressionL |
|
75 // At each component, parse the bitstream with LRCP progression order |
|
76 // (other items were commented in a header). |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 TUint8 CJ2kComponentInfo::LRCPProgressionL( CJ2kTileInfo& aTile ) |
|
80 { |
|
81 TUint8 incomplete = 0; |
|
82 if ( aTile.LastLevelProcessed() <= iNumOfLevels ) |
|
83 { |
|
84 incomplete = iRootSubband->SubbandAt( aTile.LastLevelProcessed() )->LRCPProgressionL( aTile, *this ); |
|
85 } |
|
86 return incomplete; |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CJ2kComponentInfo::RPCLProgressionL |
|
91 // At each component, parse the bitstream with RPCL progression order |
|
92 // (other items were commented in a header). |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 TUint8 CJ2kComponentInfo::RPCLProgressionL( CJ2kTileInfo& aTile ) |
|
96 { |
|
97 TUint8 incomplete = 0; |
|
98 TUint8 level = aTile.LastLevelProcessed(); |
|
99 TUint8 diff = (TUint8)( iNumOfLevels - level ); |
|
100 if ( level <= iNumOfLevels ) |
|
101 { |
|
102 TInt trx0 = TJ2kUtils::Ceil( iComponentCanvas.iTl.iX, 1 << diff ); |
|
103 TInt try0 = TJ2kUtils::Ceil( iComponentCanvas.iTl.iY, 1 << diff ); |
|
104 const TSizMarker& sizMarker = aTile.ImageInfo().SizMarker(); |
|
105 |
|
106 if ( ( ( aTile.LastN1Processed() % (TInt)( sizMarker.iYRsiz[aTile.LastComponentProcessed()] * iGridList[level].iHeight ) == 0) || |
|
107 ( ( aTile.LastN1Processed() == aTile.TileCanvas().iTl.iY ) && |
|
108 ( ( try0 << diff) % iGridList[level].iHeight ) ) ) && |
|
109 ( ( aTile.LastN2Processed() % (TInt)( sizMarker.iXRsiz[aTile.LastComponentProcessed()] * iGridList[level].iWidth ) == 0) || |
|
110 ( ( aTile.LastN2Processed() == aTile.TileCanvas().iTl.iX ) && |
|
111 ( ( trx0 << diff ) % iGridList[level].iWidth ) ) ) ) |
|
112 { |
|
113 incomplete = iRootSubband->SubbandAt( level )->RPCLProgressionL( aTile, *this ); |
|
114 } |
|
115 } |
|
116 return incomplete; |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CJ2kComponentInfo::CPRLProgressionL |
|
121 // At each component, parse the bitstream with CPRL progression order |
|
122 // (other items were commented in a header). |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 TUint8 CJ2kComponentInfo::CPRLProgressionL( CJ2kTileInfo& aTile ) |
|
126 { |
|
127 TUint8 incomplete = 0; |
|
128 TUint8 level = aTile.LastLevelProcessed(); |
|
129 TUint8 diff = (TUint8)( iNumOfLevels - level ); |
|
130 |
|
131 if (level <= iNumOfLevels) |
|
132 { |
|
133 TInt trx0 = TJ2kUtils::Ceil( iComponentCanvas.iTl.iX, 1 << diff ); |
|
134 TInt try0 = TJ2kUtils::Ceil( iComponentCanvas.iTl.iY, 1 << diff ); |
|
135 const TSizMarker& sizMarker = aTile.ImageInfo().SizMarker(); |
|
136 |
|
137 if ( ( ( aTile.LastN1Processed() % (TInt)( sizMarker.iYRsiz[aTile.LastComponentProcessed()] * iGridList[level].iHeight ) == 0 ) || |
|
138 ( ( aTile.LastN1Processed() == aTile.TileCanvas().iTl.iY ) && |
|
139 ( ( try0 << diff) % iGridList[level].iHeight ) ) ) && |
|
140 ( ( aTile.LastN2Processed() % (TInt)( sizMarker.iXRsiz[aTile.LastComponentProcessed()] * iGridList[level].iWidth ) == 0 ) || |
|
141 ( ( aTile.LastN2Processed() == aTile.TileCanvas().iTl.iX ) && |
|
142 ( ( trx0 << diff) % iGridList[level].iWidth ) ) ) ) |
|
143 { |
|
144 incomplete = iRootSubband->SubbandAt( level )->CPRLProgressionL( aTile, *this ); |
|
145 } |
|
146 } |
|
147 return incomplete; |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CJ2kComponentInfo::SubbandAt |
|
152 // Get the subband at specific resolution level |
|
153 // (other items were commented in a header). |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 const CJ2kSubband* CJ2kComponentInfo::SubbandAt( TUint8 aResLevel ) const |
|
157 { |
|
158 return ( iRootSubband ) ? iRootSubband->SubbandAt( aResLevel ) : 0; |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CJ2kComponentInfo::NumOfPackets |
|
163 // Get the number of packets at specific resolution level |
|
164 // (other items were commented in a header). |
|
165 // ----------------------------------------------------------------------------- |
|
166 // |
|
167 TUint32 CJ2kComponentInfo::NumOfPackets( TUint8 aResLevel ) const |
|
168 { |
|
169 return (TUint32)( iPrecinctSizeList[aResLevel].iWidth * |
|
170 iPrecinctSizeList[aResLevel].iHeight ); |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CJ2kComponentInfo::Exponent |
|
175 // Get the quantization exponnet value for transformation |
|
176 // (other items were commented in a header). |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 TUint8 CJ2kComponentInfo::Exponent( TUint16 aIndex ) const |
|
180 { |
|
181 if ( iQc & 0x01 ) |
|
182 { |
|
183 if ( aIndex > 0 ) |
|
184 { |
|
185 return (TUint8)( ( *iExponentList)[0] - ( ( aIndex - 1 ) / 3 ) ); |
|
186 } |
|
187 } |
|
188 return ( *iExponentList )[aIndex]; |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CJ2kComponentInfo::Mantissa |
|
193 // Get the quantization mantissa value for transformation |
|
194 // (other items were commented in a header). |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 TUint16 CJ2kComponentInfo::Mantissa( TUint16 aIndex ) const |
|
198 { |
|
199 if ( iQc & 0x01 ) |
|
200 { |
|
201 if ( aIndex > 0 ) |
|
202 { |
|
203 return ( *iMantissaList )[0]; |
|
204 } |
|
205 } |
|
206 return ( *iMantissaList )[aIndex]; |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CJ2kComponentInfo::MagnitudeBits |
|
211 // Get the magnitude bits |
|
212 // (other items were commented in a header). |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 TUint8 CJ2kComponentInfo::MagnitudeBits( TUint16 aIndex ) const |
|
216 { |
|
217 return (TUint8)( NumGuard() + Exponent( aIndex ) - 1 ); |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CJ2kComponentInfo::ResetLastPacketProcessed |
|
222 // Reset the last packet processed |
|
223 // (other items were commented in a header). |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 void CJ2kComponentInfo::ResetLastPacketProcessed() |
|
227 { |
|
228 for ( TUint8 index = 0; index <= iNumOfLevels; ++index ) |
|
229 { |
|
230 iRootSubband->SubbandAt( index )->ResetLastPacketProcessed(); |
|
231 } |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // CJ2kComponentInfo::CJ2kComponentInfo |
|
236 // C++ default constructor can NOT contain any code, that |
|
237 // might leave. |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 CJ2kComponentInfo::CJ2kComponentInfo() : |
|
241 iPrecinctSizeList(4), |
|
242 iGridList(4) |
|
243 { |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // CJ2kComponentInfo::ConstructL |
|
248 // Symbian 2nd phase constructor can leave. |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 void CJ2kComponentInfo::ConstructL( CJ2kTileInfo& aTile, TUint16 aIndex ) |
|
252 { |
|
253 CJ2kImageInfo& imageInfo = CONST_CAST( CJ2kImageInfo&, aTile.ImageInfo() ); |
|
254 const TSizMarker& sizMarker = imageInfo.SizMarker(); |
|
255 const TRect& tileCanvas = aTile.TileCanvas(); |
|
256 |
|
257 iComponentCanvas.iTl = TPoint( TJ2kUtils::Ceil( tileCanvas.iTl.iX, sizMarker.iXRsiz[aIndex] ), |
|
258 TJ2kUtils::Ceil( tileCanvas.iTl.iY, sizMarker.iYRsiz[aIndex] ) ); |
|
259 iComponentCanvas.iBr = TPoint( TJ2kUtils::Ceil( tileCanvas.iBr.iX, sizMarker.iXRsiz[aIndex] ), |
|
260 TJ2kUtils::Ceil( tileCanvas.iBr.iY, sizMarker.iYRsiz[aIndex] ) ); |
|
261 |
|
262 if ( iComponentCanvas.Width( ) <= 0 || iComponentCanvas.Height( ) <= 0 ) |
|
263 { |
|
264 // Empty may be caused by subsampled |
|
265 return; |
|
266 } |
|
267 |
|
268 // Tile part COD > main header COD |
|
269 TCODMarker *codMarker = aTile.TileMarker().iCod; |
|
270 if ( !codMarker ) |
|
271 { |
|
272 codMarker = CONST_CAST( TCODMarker*, &imageInfo.MainMarker().iCod ); |
|
273 } |
|
274 |
|
275 TCODMarker *cod = 0; |
|
276 TCOCMarker *coc = 0; |
|
277 |
|
278 // Tile part COC > tile part COD > main header COC > main header COD |
|
279 imageInfo.GetCodingStyle( cod, coc, aTile, aIndex ); |
|
280 |
|
281 iNumOfLevels = ( coc ) ? coc->iNumOfLevels : cod->iNumOfLevels; |
|
282 iCodeBlockSiz = ( coc ) ? coc->iCodeBlockSiz : cod->iCodeBlockSiz; |
|
283 iCodeBlockStyle = ( coc ) ? coc->iCodeBlockStyle : cod->iCodeBlockStyle; |
|
284 iWaveletTransformation = ( coc ) ? coc->iWaveletTransformation : cod->iWaveletTransformation; |
|
285 |
|
286 HBufC8 *precinctSiz = ( coc ) ? coc->iPrecinctSiz : cod->iPrecinctSiz; |
|
287 iCod = ( coc ) ? (TUint8)( ( codMarker->iScod & 0xfe ) | ( coc->iScoc & 0x01 ) ): cod->iScod; |
|
288 |
|
289 TQCDMarker *qcd = 0; |
|
290 TQCCMarker *qcc = 0; |
|
291 |
|
292 // Tile part QCC > tile part QCD > main header QCC > main header QCD |
|
293 imageInfo.GetQuantization( qcd, qcc, aTile, aIndex ); |
|
294 |
|
295 iQc = ( qcc ) ? qcc->iSqcc : qcd->iSqcd; |
|
296 iExponentList = ( qcc ) ? qcc->iExponent : qcd->iExponent; |
|
297 iMantissaList = ( qcc ) ? qcc->iMantissa : qcd->iMantissa; |
|
298 |
|
299 TRGNMarker *rgn = 0; |
|
300 |
|
301 // Tile part RGN > main header RGN |
|
302 imageInfo.GetRegion( rgn, aTile, aIndex ); |
|
303 iRoiShift = ( rgn ) ? rgn->iSPrgn : (TUint8)0; |
|
304 |
|
305 TSize& maxBlock = CONST_CAST( TSize&, imageInfo.MaxBlockSize() ); |
|
306 maxBlock.iWidth = Max( maxBlock.iWidth, iCodeBlockSiz.iWidth ); |
|
307 maxBlock.iHeight = Max( maxBlock.iHeight, iCodeBlockSiz.iHeight ); |
|
308 |
|
309 TSize precinct( 0,0 ); |
|
310 TInt trx0 = 0; |
|
311 TInt trx1 = 0; |
|
312 TInt try0 = 0; |
|
313 TInt try1 = 0; |
|
314 TInt denom = 0; |
|
315 TInt ppx = 15; |
|
316 TInt ppy = 15; |
|
317 |
|
318 for ( TUint8 index = 0; index <= iNumOfLevels; ++index ) |
|
319 { |
|
320 // Resolution level at r = index |
|
321 if ( precinctSiz ) |
|
322 { |
|
323 ppx = ( *precinctSiz )[index] & 0x0f; |
|
324 ppy = ( ( *precinctSiz )[index] & 0xf0 ) >> 4; |
|
325 } |
|
326 denom = 1 << ( iNumOfLevels - index ); |
|
327 |
|
328 trx0 = TJ2kUtils::Ceil( iComponentCanvas.iTl.iX, denom ); |
|
329 try0 = TJ2kUtils::Ceil( iComponentCanvas.iTl.iY, denom ); |
|
330 trx1 = TJ2kUtils::Ceil( iComponentCanvas.iBr.iX, denom ); |
|
331 try1 = TJ2kUtils::Ceil( iComponentCanvas.iBr.iY, denom ); |
|
332 |
|
333 if ( trx1 > trx0 ) |
|
334 { |
|
335 precinct.iWidth = TJ2kUtils::Ceil( trx1, 1 << ppx ) - TJ2kUtils::Floor( trx0, 1 << ppx ); |
|
336 } |
|
337 else |
|
338 { |
|
339 precinct.iWidth = 0; |
|
340 } |
|
341 |
|
342 if ( try1 > try0 ) |
|
343 { |
|
344 precinct.iHeight = TJ2kUtils::Ceil( try1, 1 << ppy ) - TJ2kUtils::Floor( try0, 1 << ppy ); |
|
345 } |
|
346 else |
|
347 { |
|
348 precinct.iHeight = 0; |
|
349 } |
|
350 |
|
351 User::LeaveIfError( iPrecinctSizeList.Append( precinct ) ); |
|
352 |
|
353 precinct.iWidth = 1 << ( ppx + iNumOfLevels - index ); |
|
354 precinct.iHeight = 1 << ( ppy + iNumOfLevels - index ); |
|
355 User::LeaveIfError( iGridList.Append( precinct ) ); |
|
356 |
|
357 // Calculate the minimum grid |
|
358 if ( iMinGrid.iWidth == 0 || iMinGrid.iWidth > precinct.iWidth ) |
|
359 { |
|
360 iMinGrid.iWidth = precinct.iWidth; |
|
361 } |
|
362 if ( iMinGrid.iHeight == 0 || iMinGrid.iHeight > precinct.iHeight ) |
|
363 { |
|
364 iMinGrid.iHeight = precinct.iHeight; |
|
365 } |
|
366 } |
|
367 |
|
368 if ( imageInfo.Crop() ) |
|
369 { |
|
370 const TRect& crop = imageInfo.CropArea(); |
|
371 |
|
372 if ( !( crop.iTl.iX >= ( tileCanvas.iBr.iX - ( TInt )sizMarker.iXOsiz ) || |
|
373 crop.iBr.iX < ( tileCanvas.iTl.iX - ( TInt )sizMarker.iXOsiz ) || |
|
374 crop.iTl.iY >= ( tileCanvas.iBr.iY - ( TInt )sizMarker.iYOsiz ) || |
|
375 crop.iBr.iY < ( tileCanvas.iTl.iY - ( TInt )sizMarker.iYOsiz ) ) ) |
|
376 { |
|
377 imageInfo.SetTileMask( aTile.SotMarker().iIsot, ETrue ); |
|
378 } |
|
379 else |
|
380 { |
|
381 // Current tile is not in the cropping area, |
|
382 // just skip setting up the subbands and packets |
|
383 return; |
|
384 } |
|
385 } |
|
386 |
|
387 // Build the associated Subband root |
|
388 iRootSubband = CJ2kSubband::BuildSubbandTreeL( iNumOfLevels, *this ); |
|
389 |
|
390 // Build the associated Packet classes |
|
391 iRootSubband->BuildPacketsL( *this, precinctSiz, codMarker->iNumOfLayers ); |
|
392 } |
|
393 |