imagingmodules/jp2kcodec/Src/JP2KCodec.cpp
changeset 10 ac33adcbae0f
parent 0 469c91dae73b
child 8 9ebf3284bc56
equal deleted inserted replaced
0:469c91dae73b 10:ac33adcbae0f
   293         const TSizMarker &sizMarker = iImageInfo->SizMarker();
   293         const TSizMarker &sizMarker = iImageInfo->SizMarker();
   294 
   294 
   295         // To get the right output image size, we must compute the size tile by tile.
   295         // To get the right output image size, we must compute the size tile by tile.
   296         // Compute the width of the output image
   296         // Compute the width of the output image
   297         TInt32 tileCompCanvasWidth = 0;
   297         TInt32 tileCompCanvasWidth = 0;
   298         TInt32 numHorTiles = iImageInfo->NumOfHorizTiles(); 
   298         TInt32 numHorTiles = iImageInfo->NumOfHorizTilesL(); 
   299         TInt32 tileStartCanvas;
   299         TInt32 tileStartCanvas;
   300         TInt32 tileEndCanvas;
   300         TInt32 tileEndCanvas;
   301         TInt32 tileCompStartCanvas;
   301         TInt32 tileCompStartCanvas;
   302         for(TUint16 indexX = 0; indexX < numHorTiles; ++indexX )  
   302         for(TUint16 indexX = 0; indexX < numHorTiles; ++indexX )  
   303             {
   303             {
   304             tileStartCanvas = Max( ( sizMarker.iXTOsiz + indexX * sizMarker.iXTsiz ), sizMarker.iXOsiz );
   304             tileStartCanvas = Max( ( sizMarker.iXTOsiz + indexX * sizMarker.iXTsiz ), sizMarker.iXOsiz );
   305             tileEndCanvas = Min( ( sizMarker.iXTOsiz + ( indexX + 1 ) * sizMarker.iXTsiz ), sizMarker.iXsiz );
   305             tileEndCanvas = Min( ( sizMarker.iXTOsiz + ( indexX + 1 ) * sizMarker.iXTsiz ), sizMarker.iXsiz );
   306 
   306 
   307             // Add this tile's contribution to the total size
   307             // Add this tile's contribution to the total size
   308             tileCompStartCanvas = TJ2kUtils::Ceil( tileStartCanvas, sizMarker.iXRsiz[0] );
   308             tileCompStartCanvas = TJ2kUtils::CeilL( tileStartCanvas, sizMarker.iXRsiz[0] );
   309             tileCompCanvasWidth += TJ2kUtils::Ceil( tileEndCanvas, sizMarker.iXRsiz[0] ) - tileCompStartCanvas;
   309             tileCompCanvasWidth += TJ2kUtils::CeilL( tileEndCanvas, sizMarker.iXRsiz[0] ) - tileCompStartCanvas;
   310             }
   310             }
   311         
   311         
   312         // Compute the height of the output image
   312         // Compute the height of the output image
   313         TInt32 tileCompCanvasHeight = 0;
   313         TInt32 tileCompCanvasHeight = 0;
   314         TInt32 numVerTiles = iImageInfo->NumOfVertTiles(); 
   314         TInt32 numVerTiles = iImageInfo->NumOfVertTilesL(); 
   315         for(TUint16 indexY = 0; indexY < numVerTiles; ++indexY )  
   315         for(TUint16 indexY = 0; indexY < numVerTiles; ++indexY )  
   316             {
   316             {
   317             tileStartCanvas = Max( ( sizMarker.iYTOsiz + indexY * sizMarker.iYTsiz ), sizMarker.iYOsiz );
   317             tileStartCanvas = Max( ( sizMarker.iYTOsiz + indexY * sizMarker.iYTsiz ), sizMarker.iYOsiz );
   318             tileEndCanvas = Min( ( sizMarker.iYTOsiz + ( indexY + 1 ) * sizMarker.iYTsiz ), sizMarker.iYsiz );
   318             tileEndCanvas = Min( ( sizMarker.iYTOsiz + ( indexY + 1 ) * sizMarker.iYTsiz ), sizMarker.iYsiz );
   319 
   319 
   320             // Add this tile's contribution to the total size
   320             // Add this tile's contribution to the total size
   321             tileCompStartCanvas = TJ2kUtils::Ceil( tileStartCanvas, sizMarker.iYRsiz[0] );
   321             tileCompStartCanvas = TJ2kUtils::CeilL( tileStartCanvas, sizMarker.iYRsiz[0] );
   322             tileCompCanvasHeight += TJ2kUtils::Ceil( tileEndCanvas, sizMarker.iYRsiz[0] ) - tileCompStartCanvas;
   322             tileCompCanvasHeight += TJ2kUtils::CeilL( tileEndCanvas, sizMarker.iYRsiz[0] ) - tileCompStartCanvas;
   323             }
   323             }
   324         
   324         
   325         iFrame->iOverallSizeInPixels = TSize( tileCompCanvasWidth, tileCompCanvasHeight );
   325         iFrame->iOverallSizeInPixels = TSize( tileCompCanvasWidth, tileCompCanvasHeight );
   326 
   326 
   327         iFrame->iFrameCoordsInPixels.SetRect( TPoint( 0, 0 ), iFrame->iOverallSizeInPixels );
   327         iFrame->iFrameCoordsInPixels.SetRect( TPoint( 0, 0 ), iFrame->iOverallSizeInPixels );
   454     iUseNewTile = ETrue;
   454     iUseNewTile = ETrue;
   455     iReader.iNewDataStart = iFrame->FrameDataOffset();
   455     iReader.iNewDataStart = iFrame->FrameDataOffset();
   456     iStyleUsed = EUnknownDecoder;
   456     iStyleUsed = EUnknownDecoder;
   457 
   457 
   458     iProgressBar = EFalse;
   458     iProgressBar = EFalse;
   459     if ( ( iImageInfo->NumOfHorizTiles() == 1 ) &&
   459     if ( ( iImageInfo->NumOfHorizTilesL() == 1 ) &&
   460          ( iImageInfo->NumOfVertTiles() == 1 ) )
   460          ( iImageInfo->NumOfVertTilesL() == 1 ) )
   461         {
   461         {
   462         // To force a return immediately from ProcessFrameL()
   462         // To force a return immediately from ProcessFrameL()
   463         // on first entry to stimulate the occurrance of
   463         // on first entry to stimulate the occurrance of
   464         // the progress bar
   464         // the progress bar
   465         iProgressBar = ETrue;
   465         iProgressBar = ETrue;
   839         }
   839         }
   840     else
   840     else
   841         {
   841         {
   842         // COD in Tile Part Header
   842         // COD in Tile Part Header
   843         codMarker = new ( ELeave ) TCODMarker;        
   843         codMarker = new ( ELeave ) TCODMarker;        
   844         CleanupDeletePushL( codMarker );
   844         //CleanupDeletePushL( codMarker );
       
   845         CleanupStack::PushL(codMarker);
   845         }
   846         }
   846 
   847 
   847     codMarker->iScod = *iReader.iPtr++;
   848     codMarker->iScod = *iReader.iPtr++;
   848     codMarker->iProgressionOrder = *iReader.iPtr++;
   849     codMarker->iProgressionOrder = *iReader.iPtr++;
   849     codMarker->iNumOfLayers = PtrReadUtil::ReadBigEndianUint16Inc( iReader.iPtr );
   850     codMarker->iNumOfLayers = PtrReadUtil::ReadBigEndianUint16Inc( iReader.iPtr );
   861 
   862 
   862     if ( codMarker->iScod & 0x01 )
   863     if ( codMarker->iScod & 0x01 )
   863         {
   864         {
   864         // Entropy coder with precincts defined below
   865         // Entropy coder with precincts defined below
   865         codMarker->iPrecinctSiz = HBufC8::NewL( codMarker->iNumOfLevels + 1 );
   866         codMarker->iPrecinctSiz = HBufC8::NewL( codMarker->iNumOfLevels + 1 );
       
   867         CleanupStack::PushL(codMarker->iPrecinctSiz);
   866         for ( TUint8 index = 0; index < codMarker->iNumOfLevels + 1; ++index )
   868         for ( TUint8 index = 0; index < codMarker->iNumOfLevels + 1; ++index )
   867             {
   869             {
   868             codMarker->iPrecinctSiz->Des().Append( *iReader.iPtr++ );
   870             codMarker->iPrecinctSiz->Des().Append( *iReader.iPtr++ );
   869             }
   871             }
   870         }
   872         }
   873     if ( ( iReader.iPtr - iReader.iPtrStartMarker ) != ( markerLength + KMarkerSize ) )
   875     if ( ( iReader.iPtr - iReader.iPtrStartMarker ) != ( markerLength + KMarkerSize ) )
   874         {
   876         {
   875         // We must be missing some data in the marker
   877         // We must be missing some data in the marker
   876         User::Leave( KErrCorrupt );
   878         User::Leave( KErrCorrupt );
   877         }
   879         }
   878 
   880     if ( codMarker->iScod & 0x01 )
       
   881         {
       
   882             CleanupStack::Pop(codMarker->iPrecinctSiz);
       
   883         }
   879     if ( !aMain )
   884     if ( !aMain )
   880         {
   885         {
   881         CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
   886         CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
   882 
   887 
   883         // Append COD to the current tile and decrement the tile length
   888         // Append COD to the current tile and decrement the tile length
   884         tile.AppendCOD( codMarker, markerLength + KMarkerSize );
   889         tile.AppendCOD( codMarker, markerLength + KMarkerSize );
   885         CleanupStack::Pop();
   890         CleanupStack::PopAndDestroy(codMarker);
   886         }
   891         }
   887 
   892 
   888     // Any valid marker may come after COD marker
   893     // Any valid marker may come after COD marker
   889     iFHState = EStateInUnknown;
   894     iFHState = EStateInUnknown;
   890     return EFrameComplete;
   895     return EFrameComplete;
   920         }
   925         }
   921 
   926 
   922     const TSizMarker& sizMarker = iImageInfo->SizMarker();
   927     const TSizMarker& sizMarker = iImageInfo->SizMarker();
   923 
   928 
   924     TCOCMarker *cocMarker = new ( ELeave ) TCOCMarker;    
   929     TCOCMarker *cocMarker = new ( ELeave ) TCOCMarker;    
   925     CleanupDeletePushL(cocMarker);
   930     //CleanupDeletePushL(cocMarker);
       
   931     CleanupStack::PushL(cocMarker);
   926 
   932 
   927     if ( sizMarker.iCsiz < 257 )
   933     if ( sizMarker.iCsiz < 257 )
   928         {
   934         {
   929         // 8 bits component
   935         // 8 bits component
   930         cocMarker->iCcoc = *iReader.iPtr++;
   936         cocMarker->iCcoc = *iReader.iPtr++;
   949 
   955 
   950     if ( cocMarker->iScoc & 0x01 )
   956     if ( cocMarker->iScoc & 0x01 )
   951         {
   957         {
   952         // Entropy coder with precincts defined below
   958         // Entropy coder with precincts defined below
   953         cocMarker->iPrecinctSiz = HBufC8::NewL( cocMarker->iNumOfLevels + 1 );
   959         cocMarker->iPrecinctSiz = HBufC8::NewL( cocMarker->iNumOfLevels + 1 );
       
   960         CleanupStack::PushL(cocMarker->iPrecinctSiz);
   954         for ( TUint8 index = 0; index < cocMarker->iNumOfLevels + 1; ++index )
   961         for ( TUint8 index = 0; index < cocMarker->iNumOfLevels + 1; ++index )
   955             {
   962             {
   956             cocMarker->iPrecinctSiz->Des().Append( *iReader.iPtr++ );
   963             cocMarker->iPrecinctSiz->Des().Append( *iReader.iPtr++ );
   957             }
   964             }
   958         }
   965         }
   973         CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
   980         CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
   974 
   981 
   975         // Append COC to the current tile and decrement the tile length
   982         // Append COC to the current tile and decrement the tile length
   976         tile.AppendCOCL( cocMarker, markerLength + KMarkerSize );
   983         tile.AppendCOCL( cocMarker, markerLength + KMarkerSize );
   977         }
   984         }
   978     CleanupStack::Pop();
   985     
       
   986     if ( cocMarker->iScoc & 0x01 )
       
   987         {    
       
   988             CleanupStack::Pop(cocMarker->iPrecinctSiz);
       
   989         }
       
   990     CleanupStack::PopAndDestroy(cocMarker);
   979 
   991 
   980     // Any valid marker may come after COC marker
   992     // Any valid marker may come after COC marker
   981     iFHState = EStateInUnknown;
   993     iFHState = EStateInUnknown;
   982 
   994 
   983     return EFrameComplete;
   995     return EFrameComplete;
  1021     else
  1033     else
  1022         {
  1034         {
  1023         // QCD in Tile Part Header
  1035         // QCD in Tile Part Header
  1024         qcdMarker = new ( ELeave ) TQCDMarker;
  1036         qcdMarker = new ( ELeave ) TQCDMarker;
  1025         
  1037         
  1026         CleanupDeletePushL( qcdMarker );
  1038         //CleanupDeletePushL( qcdMarker );
       
  1039         CleanupStack::PushL( qcdMarker );
  1027         }
  1040         }
  1028 
  1041 
  1029     qcdMarker->iSqcd = *iReader.iPtr++;
  1042     qcdMarker->iSqcd = *iReader.iPtr++;
  1030 
  1043 
  1031     if ( qcdMarker->iSqcd & 0x01 )
  1044     if ( qcdMarker->iSqcd & 0x01 )
  1064                 qcdMarker->iExponent->Des().Append( (TUint8)( ( *iReader.iPtr++ >> 3 ) & 0x1f ) );
  1077                 qcdMarker->iExponent->Des().Append( (TUint8)( ( *iReader.iPtr++ >> 3 ) & 0x1f ) );
  1065                 --entries;
  1078                 --entries;
  1066                 }
  1079                 }
  1067             }
  1080             }
  1068         }
  1081         }
       
  1082     
       
  1083     CleanupStack::PushL( qcdMarker->iExponent );
       
  1084     if ((qcdMarker->iSqcd & 0x1f) || (qcdMarker->iSqcd & 0x01))
       
  1085     {
       
  1086         CleanupStack::PushL( qcdMarker->iMantissa );       
       
  1087     }
  1069 
  1088 
  1070     // Make sure we read all the data
  1089     // Make sure we read all the data
  1071     if ( ( iReader.iPtr - iReader.iPtrStartMarker ) != ( markerLength + KMarkerSize ) )
  1090     if ( ( iReader.iPtr - iReader.iPtrStartMarker ) != ( markerLength + KMarkerSize ) )
  1072         {
  1091         {
  1073         // We must be missing some data in the marker
  1092         // We must be missing some data in the marker
  1074         User::Leave( KErrCorrupt );
  1093         User::Leave( KErrCorrupt );
  1075         }
  1094         }
  1076 
  1095 
       
  1096     
       
  1097     if ((qcdMarker->iSqcd & 0x1f) || (qcdMarker->iSqcd & 0x01))
       
  1098     {
       
  1099         CleanupStack::Pop( qcdMarker->iMantissa );       
       
  1100     }   
       
  1101     
       
  1102     CleanupStack::Pop( qcdMarker->iExponent );
       
  1103     
  1077     if ( !aMain )
  1104     if ( !aMain )
  1078         {
  1105         {
  1079         CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
  1106         CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
  1080 
  1107 
  1081         // Append QCD to the current tile and decrement the tile length
  1108         // Append QCD to the current tile and decrement the tile length
  1082         tile.AppendQCD( qcdMarker, markerLength + KMarkerSize );
  1109         tile.AppendQCD( qcdMarker, markerLength + KMarkerSize );
  1083         CleanupStack::Pop();
  1110         //CleanupStack::PopAndDestroy(qcdMarker);
       
  1111         CleanupStack::PopAndDestroy(qcdMarker);
  1084         }
  1112         }
  1085 
  1113 
  1086     // Any valid marker may come after QCD marker
  1114     // Any valid marker may come after QCD marker
  1087     iFHState = EStateInUnknown;
  1115     iFHState = EStateInUnknown;
  1088 
  1116 
  1119 
  1147 
  1120     const TSizMarker& sizMarker = iImageInfo->SizMarker();
  1148     const TSizMarker& sizMarker = iImageInfo->SizMarker();
  1121 
  1149 
  1122     TQCCMarker *qccMarker = new (ELeave) TQCCMarker;
  1150     TQCCMarker *qccMarker = new (ELeave) TQCCMarker;
  1123 
  1151 
  1124     CleanupDeletePushL( qccMarker );
  1152     //CleanupDeletePushL( qccMarker );
       
  1153     CleanupStack::PushL( qccMarker );
  1125 
  1154 
  1126     if ( sizMarker.iCsiz < 257 )
  1155     if ( sizMarker.iCsiz < 257 )
  1127         {
  1156         {
  1128         // 8 bits component
  1157         // 8 bits component
  1129         qccMarker->iCqcc = *iReader.iPtr++;
  1158         qccMarker->iCqcc = *iReader.iPtr++;
  1172                 qccMarker->iExponent->Des().Append( (TUint8)( ( *iReader.iPtr++ >> 3 ) & 0x1f ) );
  1201                 qccMarker->iExponent->Des().Append( (TUint8)( ( *iReader.iPtr++ >> 3 ) & 0x1f ) );
  1173                 --entries;
  1202                 --entries;
  1174                 }
  1203                 }
  1175             }
  1204             }
  1176         }
  1205         }
       
  1206     
       
  1207     CleanupStack::PushL( qccMarker->iExponent );
       
  1208     if( (qccMarker->iSqcc & 0x1f) || (qccMarker->iSqcc & 0x01) )
       
  1209     {
       
  1210         CleanupStack::PushL( qccMarker->iMantissa );
       
  1211     }
  1177 
  1212 
  1178     // Make sure we read all the data
  1213     // Make sure we read all the data
  1179     if ( ( iReader.iPtr - iReader.iPtrStartMarker ) != ( markerLength + KMarkerSize ) )
  1214     if ( ( iReader.iPtr - iReader.iPtrStartMarker ) != ( markerLength + KMarkerSize ) )
  1180         {
  1215         {
  1181         // We must be missing some data in the marker
  1216         // We must be missing some data in the marker
  1191         CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
  1226         CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
  1192 
  1227 
  1193         // Append QCC to the current tile and decrement the tile length
  1228         // Append QCC to the current tile and decrement the tile length
  1194         tile.AppendQCCL( qccMarker, markerLength + KMarkerSize );
  1229         tile.AppendQCCL( qccMarker, markerLength + KMarkerSize );
  1195         }
  1230         }
  1196     CleanupStack::Pop();
  1231     
       
  1232     if( (qccMarker->iSqcc & 0x1f) || (qccMarker->iSqcc & 0x01) )
       
  1233     {
       
  1234         CleanupStack::Pop( qccMarker->iMantissa );
       
  1235     }    
       
  1236     
       
  1237     CleanupStack::Pop( qccMarker->iExponent );
       
  1238     CleanupStack::PopAndDestroy(qccMarker);
  1197 
  1239 
  1198     // Any valid marker may come after QCC marker
  1240     // Any valid marker may come after QCC marker
  1199     iFHState = EStateInUnknown;
  1241     iFHState = EStateInUnknown;
  1200 
  1242 
  1201     return EFrameComplete;
  1243     return EFrameComplete;
  1231         }
  1273         }
  1232 
  1274 
  1233     const TSizMarker& sizMarker = iImageInfo->SizMarker();
  1275     const TSizMarker& sizMarker = iImageInfo->SizMarker();
  1234 
  1276 
  1235     TRGNMarker *rgnMarker = new ( ELeave ) TRGNMarker;
  1277     TRGNMarker *rgnMarker = new ( ELeave ) TRGNMarker;
  1236     CleanupDeletePushL( rgnMarker );
  1278     CleanupStack::PushL( rgnMarker );
  1237 
  1279 
  1238     if ( sizMarker.iCsiz < 257 )
  1280     if ( sizMarker.iCsiz < 257 )
  1239         {
  1281         {
  1240         // 8 bits component
  1282         // 8 bits component
  1241         rgnMarker->iCrgn = *iReader.iPtr++;
  1283         rgnMarker->iCrgn = *iReader.iPtr++;
  1265         CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
  1307         CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
  1266 
  1308 
  1267         // Append RGN to the current tile and decrement the tile length
  1309         // Append RGN to the current tile and decrement the tile length
  1268         tile.AppendRGNL( rgnMarker, markerLength + KMarkerSize );
  1310         tile.AppendRGNL( rgnMarker, markerLength + KMarkerSize );
  1269         }
  1311         }
  1270     CleanupStack::Pop();
  1312     CleanupStack::PopAndDestroy(rgnMarker);
  1271 
  1313 
  1272     // Any valid marker may come after RGN marker
  1314     // Any valid marker may come after RGN marker
  1273     iFHState = EStateInUnknown;
  1315     iFHState = EStateInUnknown;
  1274 
  1316 
  1275     return EFrameComplete;
  1317     return EFrameComplete;
  1405             // Underflow, will keep reading
  1447             // Underflow, will keep reading
  1406             isUnderflow = ETrue;
  1448             isUnderflow = ETrue;
  1407             }
  1449             }
  1408 
  1450 
  1409         TPPMMarker *ppmMarker = new ( ELeave ) TPPMMarker;        
  1451         TPPMMarker *ppmMarker = new ( ELeave ) TPPMMarker;        
  1410         CleanupDeletePushL( ppmMarker );
  1452         CleanupStack::PushL( ppmMarker );
  1411 
  1453 
  1412         ppmMarker->iZppm = *iReader.iPtr++;
  1454         ppmMarker->iZppm = *iReader.iPtr++;
  1413         TUint32 entries = (TUint32)( markerLength - KMarkerSize - 1 );
  1455         TUint32 entries = (TUint32)( markerLength - KMarkerSize - 1 );
  1414 
  1456 
  1415         ppmMarker->iNppm = entries;
  1457         ppmMarker->iNppm = entries;
  1416         ppmMarker->iIppm = HBufC8::NewL( entries );
  1458         ppmMarker->iIppm = HBufC8::NewL( entries );
       
  1459         CleanupStack::PushL( ppmMarker->iIppm );
  1417 
  1460 
  1418         if ( !isUnderflow )
  1461         if ( !isUnderflow )
  1419             {
  1462             {
  1420             ppmMarker->iIppm->Des(  ).Append( iReader.iPtr, entries );
  1463             ppmMarker->iIppm->Des(  ).Append( iReader.iPtr, entries );
  1421             iReader.iPtr += entries;
  1464             iReader.iPtr += entries;
  1457 
  1500 
  1458         if ( tmp )
  1501         if ( tmp )
  1459             {
  1502             {
  1460             User::LeaveIfError( mainMarker.iPpm.Append( ppmMarker ) );
  1503             User::LeaveIfError( mainMarker.iPpm.Append( ppmMarker ) );
  1461             }
  1504             }
  1462         CleanupStack::Pop();
  1505         CleanupStack::Pop(ppmMarker->iIppm);
       
  1506         CleanupStack::Pop(ppmMarker);
  1463         }
  1507         }
  1464     else
  1508     else
  1465         {
  1509         {
  1466         if ( (TUint32)( iReader.iPtrEnd - iReader.iPtr ) < iPreviousPPM->iRemainder )
  1510         if ( (TUint32)( iReader.iPtrEnd - iReader.iPtr ) < iPreviousPPM->iRemainder )
  1467             {
  1511             {
  1620         iReader.iPtr -= KMarkerMinLength;
  1664         iReader.iPtr -= KMarkerMinLength;
  1621         return EFrameIncomplete;
  1665         return EFrameIncomplete;
  1622         }
  1666         }
  1623 
  1667 
  1624     TPLMMarker *plmMarker =  new ( ELeave ) TPLMMarker;    
  1668     TPLMMarker *plmMarker =  new ( ELeave ) TPLMMarker;    
  1625     CleanupDeletePushL( plmMarker );
  1669     CleanupStack::PushL( plmMarker );
  1626 
  1670 
  1627     plmMarker->iZplm = *iReader.iPtr++;
  1671     plmMarker->iZplm = *iReader.iPtr++;
  1628     TUint32 entries = (TUint32)( markerLength - KMarkerSize - 1 );
  1672     TUint32 entries = (TUint32)( markerLength - KMarkerSize - 1 );
  1629 
  1673 
  1630     plmMarker->iNplm = (TUint8)entries;
  1674     plmMarker->iNplm = (TUint8)entries;
  1631     plmMarker->iIplm = HBufC8::NewL( entries );
  1675     plmMarker->iIplm = HBufC8::NewL( entries );
       
  1676     CleanupStack::PushL( plmMarker->iIplm );
  1632     plmMarker->iIplm->Des().Append( iReader.iPtr, entries );
  1677     plmMarker->iIplm->Des().Append( iReader.iPtr, entries );
  1633     iReader.iPtr += entries;
  1678     iReader.iPtr += entries;
  1634 
  1679 
  1635     // Make sure we read all the data
  1680     // Make sure we read all the data
  1636     if ( ( iReader.iPtr - iReader.iPtrStartMarker ) != ( markerLength + KMarkerSize ) )
  1681     if ( ( iReader.iPtr - iReader.iPtrStartMarker ) != ( markerLength + KMarkerSize ) )
  1660 
  1705 
  1661     if ( tmp )
  1706     if ( tmp )
  1662         {
  1707         {
  1663         User::LeaveIfError( mainMarker.iPlm.Append( plmMarker ) );
  1708         User::LeaveIfError( mainMarker.iPlm.Append( plmMarker ) );
  1664         }
  1709         }
  1665     CleanupStack::Pop();
  1710     CleanupStack::Pop(plmMarker->iIplm);
       
  1711     CleanupStack::PopAndDestroy(plmMarker);
  1666 
  1712 
  1667     // Any valid marker may come after PLM marker
  1713     // Any valid marker may come after PLM marker
  1668     iFHState = EStateInUnknown;
  1714     iFHState = EStateInUnknown;
  1669 
  1715 
  1670     return EFrameComplete;
  1716     return EFrameComplete;
  1765             {
  1811             {
  1766             // Underflow, will keep reading
  1812             // Underflow, will keep reading
  1767             isUnderflow = ETrue;
  1813             isUnderflow = ETrue;
  1768             }
  1814             }
  1769 
  1815 
  1770         TCOMMarker* comMarker = new ( ELeave ) TCOMMarker;        
  1816         TCOMMarker* comMarker = new ( ELeave ) TCOMMarker;   
  1771         CleanupDeletePushL( comMarker );
  1817         //CleanupDeletePushL(comMarker);
       
  1818         CleanupStack::PushL( comMarker );
  1772 
  1819 
  1773         comMarker->iRcom = PtrReadUtil::ReadBigEndianUint16Inc( iReader.iPtr );
  1820         comMarker->iRcom = PtrReadUtil::ReadBigEndianUint16Inc( iReader.iPtr );
  1774         TInt entries = markerLength - ( 2 * KMarkerSize );
  1821         TInt entries = markerLength - ( 2 * KMarkerSize );
  1775 
  1822 
  1776         comMarker->iCcom = HBufC8::NewL( entries );
  1823         comMarker->iCcom = HBufC8::NewL( entries );
       
  1824         //CleanupDeletePushL( comMarker->iCcom );
       
  1825         CleanupStack::PushL(comMarker->iCcom);
  1777         if ( !isUnderflow )
  1826         if ( !isUnderflow )
  1778             {
  1827             {
  1779             comMarker->iCcom->Des().Append( iReader.iPtr, entries );
  1828             comMarker->iCcom->Des().Append( iReader.iPtr, entries );
  1780             iReader.iPtr += entries;
  1829             iReader.iPtr += entries;
  1781             iPreviousCOM = 0;
  1830             iPreviousCOM = 0;
  1804             CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
  1853             CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
  1805             
  1854             
  1806             // Append COM to the current tile and decrement the tile length
  1855             // Append COM to the current tile and decrement the tile length
  1807             tile.AppendCOML( comMarker, markerLength + KMarkerSize );
  1856             tile.AppendCOML( comMarker, markerLength + KMarkerSize );
  1808             }
  1857             }
  1809         CleanupStack::Pop();
  1858         CleanupStack::Pop(comMarker->iCcom);
       
  1859         CleanupStack::Pop(comMarker);
  1810         }
  1860         }
  1811     else
  1861     else
  1812         {
  1862         {
  1813         if ( ( iReader.iPtrEnd - iReader.iPtr ) < iPreviousCOM->iRemainder )
  1863         if ( ( iReader.iPtrEnd - iReader.iPtr ) < iPreviousCOM->iRemainder )
  1814             {
  1864             {
  1877     sotMarker.iIsot = PtrReadUtil::ReadBigEndianUint16Inc( iReader.iPtr );
  1927     sotMarker.iIsot = PtrReadUtil::ReadBigEndianUint16Inc( iReader.iPtr );
  1878     sotMarker.iPsot = PtrReadUtil::ReadBigEndianUint32Inc( iReader.iPtr );
  1928     sotMarker.iPsot = PtrReadUtil::ReadBigEndianUint32Inc( iReader.iPtr );
  1879     sotMarker.iTPsot = *iReader.iPtr++;
  1929     sotMarker.iTPsot = *iReader.iPtr++;
  1880     sotMarker.iTNsot = *iReader.iPtr++;
  1930     sotMarker.iTNsot = *iReader.iPtr++;
  1881     
  1931     
  1882     if(sotMarker.iIsot >= ( iImageInfo->NumOfHorizTiles() * iImageInfo->NumOfVertTiles() ))
  1932     if(sotMarker.iIsot >= ( iImageInfo->NumOfHorizTilesL() * iImageInfo->NumOfVertTilesL() ))
  1883         {
  1933         {
  1884         // Invalid tile index, exceeds the number of tiles, exit
  1934         // Invalid tile index, exceeds the number of tiles, exit
  1885         User::Leave( KErrCorrupt );
  1935         User::Leave( KErrCorrupt );
  1886         }
  1936         }
  1887 
  1937 
  2033     else
  2083     else
  2034         {
  2084         {
  2035         tile.SetPacketHeaderReader( &iReader );
  2085         tile.SetPacketHeaderReader( &iReader );
  2036         }
  2086         }
  2037 
  2087 
  2038     if ( ( iImageInfo->NumOfHorizTiles() == 1 ) &&
  2088     if ( ( iImageInfo->NumOfHorizTilesL() == 1 ) &&
  2039          ( iImageInfo->NumOfVertTiles() == 1 ) )
  2089          ( iImageInfo->NumOfVertTilesL() == 1 ) )
  2040         {
  2090         {
  2041         // To force a return immediately from ProcessFrameL()
  2091         // To force a return immediately from ProcessFrameL()
  2042         // on first entry to stimulate the occurrance of
  2092         // on first entry to stimulate the occurrance of
  2043         // the progress bar
  2093         // the progress bar
  2044         iProgressBar = ETrue;
  2094         iProgressBar = ETrue;
  2258                 return EFrameIncomplete;
  2308                 return EFrameIncomplete;
  2259                 }
  2309                 }
  2260             }
  2310             }
  2261         }
  2311         }
  2262 
  2312 
  2263     if ( ( iImageInfo->NumOfHorizTiles() == 1 ) &&
  2313     if ( ( iImageInfo->NumOfHorizTilesL() == 1 ) &&
  2264          ( iImageInfo->NumOfVertTiles() == 1 ) )
  2314          ( iImageInfo->NumOfVertTilesL() == 1 ) )
  2265         {
  2315         {
  2266         // To force a return immediately from ProcessFrameL()
  2316         // To force a return immediately from ProcessFrameL()
  2267         // on first entry to stimulate the occurrance of
  2317         // on first entry to stimulate the occurrance of
  2268         // the progress bar
  2318         // the progress bar
  2269         iProgressBar = ETrue;
  2319         iProgressBar = ETrue;
  2300         iReader.iPtr -= KMarkerMinLength;
  2350         iReader.iPtr -= KMarkerMinLength;
  2301         return EFrameIncomplete;
  2351         return EFrameIncomplete;
  2302         }
  2352         }
  2303 
  2353 
  2304     TPPTMarker *pptMarker = new ( ELeave ) TPPTMarker;    
  2354     TPPTMarker *pptMarker = new ( ELeave ) TPPTMarker;    
  2305     CleanupDeletePushL( pptMarker );
  2355     CleanupStack::PushL( pptMarker );
  2306 
  2356 
  2307     TInt entries = markerLength - KMarkerSize - 1;
  2357     TInt entries = markerLength - KMarkerSize - 1;
  2308     pptMarker->iZppt = *iReader.iPtr++;
  2358     pptMarker->iZppt = *iReader.iPtr++;
  2309     pptMarker->iIppt = HBufC8::NewL( entries );
  2359     pptMarker->iIppt = HBufC8::NewL( entries );
       
  2360     CleanupStack::PushL( pptMarker->iIppt );
  2310     pptMarker->iIppt->Des(  ).Append( iReader.iPtr, entries );
  2361     pptMarker->iIppt->Des(  ).Append( iReader.iPtr, entries );
  2311     iReader.iPtr += entries;
  2362     iReader.iPtr += entries;
  2312 
  2363 
  2313     // Make sure we read all the data
  2364     // Make sure we read all the data
  2314     if ( ( iReader.iPtr - iReader.iPtrStartMarker ) != ( markerLength + KMarkerSize ) )
  2365     if ( ( iReader.iPtr - iReader.iPtrStartMarker ) != ( markerLength + KMarkerSize ) )
  2319 
  2370 
  2320     CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
  2371     CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
  2321     
  2372     
  2322     // Append PPT to the current tile and decrement the tile length
  2373     // Append PPT to the current tile and decrement the tile length
  2323     tile.AppendPPTL( pptMarker, markerLength + KMarkerSize );
  2374     tile.AppendPPTL( pptMarker, markerLength + KMarkerSize );
  2324     CleanupStack::Pop();
  2375     CleanupStack::Pop(pptMarker->iIppt);
       
  2376     CleanupStack::PopAndDestroy(pptMarker);
  2325 
  2377 
  2326     // Any valid marker may come after PPT marker
  2378     // Any valid marker may come after PPT marker
  2327     iFHState = EStateInUnknown;
  2379     iFHState = EStateInUnknown;
  2328 
  2380 
  2329     return EFrameComplete;
  2381     return EFrameComplete;
  2357         iReader.iPtr -= KMarkerMinLength;
  2409         iReader.iPtr -= KMarkerMinLength;
  2358         return EFrameIncomplete;
  2410         return EFrameIncomplete;
  2359         }
  2411         }
  2360 
  2412 
  2361     TPLTMarker *pltMarker = new ( ELeave ) TPLTMarker;
  2413     TPLTMarker *pltMarker = new ( ELeave ) TPLTMarker;
  2362     //CleanupStack::PushL( pltMarker );
  2414     CleanupStack::PushL( pltMarker );
  2363     CleanupDeletePushL( pltMarker );
  2415     //CleanupDeletePushL( pltMarker );
  2364 
  2416 
  2365     pltMarker->iZplt = *iReader.iPtr++;
  2417     pltMarker->iZplt = *iReader.iPtr++;
  2366 
  2418 
  2367     TInt entries = markerLength - KMarkerSize - 1;
  2419     TInt entries = markerLength - KMarkerSize - 1;
  2368     while ( entries )
  2420     while ( entries )
  2380 
  2432 
  2381     CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
  2433     CJ2kTileInfo& tile = CONST_CAST( CJ2kTileInfo&, iImageInfo->TileAt( iLastTileIndex ) );
  2382 
  2434 
  2383     // Append PLT to the current tile and decrement the tile length
  2435     // Append PLT to the current tile and decrement the tile length
  2384     tile.AppendPLTL( pltMarker, markerLength + KMarkerSize );
  2436     tile.AppendPLTL( pltMarker, markerLength + KMarkerSize );
  2385     CleanupStack::Pop();
  2437     //CleanupStack::Pop();
       
  2438     CleanupStack::PopAndDestroy(pltMarker);
  2386 
  2439 
  2387     // Any valid marker may come after PLT marker
  2440     // Any valid marker may come after PLT marker
  2388     iFHState = EStateInUnknown;
  2441     iFHState = EStateInUnknown;
  2389 
  2442 
  2390     return EFrameComplete;
  2443     return EFrameComplete;