imagingmodules/jp2kcodec/Src/JP2KTileInfo.cpp
changeset 0 469c91dae73b
child 4 3993b8f65362
equal deleted inserted replaced
-1:000000000000 0:469c91dae73b
       
     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:  CJ2kTileInfo class used to collect tile related information 
       
    15 *                such as Tile Part Header, SOT marker and list of components.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <icl/imagecodec.h>
       
    22 #include "JP2KImageUtils.h"
       
    23 #include "JP2KFormat.h"
       
    24 #include "JP2KStreamReader.h"
       
    25 #include "JP2KTileInfo.h"
       
    26 #include "JP2KImageInfo.h"
       
    27 #include "JP2KCodec.h"
       
    28 #include "JP2KComponentInfo.h"
       
    29 
       
    30 // EXTERNAL DATA STRUCTURES
       
    31 
       
    32 // EXTERNAL FUNCTION PROTOTYPES  
       
    33 
       
    34 // CONSTANTS
       
    35 
       
    36 // MACROS
       
    37 
       
    38 // LOCAL CONSTANTS AND MACROS
       
    39 
       
    40 // MODULE DATA STRUCTURES
       
    41 
       
    42 // LOCAL FUNCTION PROTOTYPES
       
    43 
       
    44 // FORWARD DECLARATIONS
       
    45 
       
    46 // ============================ MEMBER FUNCTIONS ===============================
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CJ2kTileInfo::NewLC
       
    50 // Two-phased constructor.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CJ2kTileInfo* CJ2kTileInfo::NewLC( CJ2kImageInfo& aImageInfo, TJ2kStreamReader& aReader )
       
    54     {
       
    55     CJ2kTileInfo* self = new ( ELeave ) CJ2kTileInfo( aImageInfo, aReader );
       
    56 
       
    57     CleanupStack::PushL( self );
       
    58 
       
    59     return self;
       
    60     }
       
    61 
       
    62 // Destructor
       
    63 CJ2kTileInfo::~CJ2kTileInfo()
       
    64     {
       
    65     DoReleaseUnusedMarkers();
       
    66 
       
    67     iComponentList.ResetAndDestroy();
       
    68 
       
    69     delete iPpt;
       
    70     iPpt = 0;
       
    71 
       
    72     delete iPptBuffer;
       
    73     iPptBuffer = 0;
       
    74 
       
    75     // iPOC not owned - not deleted. 
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CJ2kTileInfo::InitializeL
       
    80 // Initialize the components in the tile.
       
    81 // (other items were commented in a header).
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CJ2kTileInfo::InitializeL()
       
    85     {
       
    86     const TSizMarker &sizMarker = iImageInfo.SizMarker();
       
    87     TUint16 numOfHorizTiles = iImageInfo.NumOfHorizTiles();
       
    88 
       
    89     // Calculate the tile canvas
       
    90     TDiv    tDiv = TJ2kUtils::Div( iSot.iIsot, numOfHorizTiles );
       
    91     iTileCanvas.iTl = TPoint( Max( sizMarker.iXTOsiz + tDiv.rem * sizMarker.iXTsiz, sizMarker.iXOsiz ),
       
    92                               Max( sizMarker.iYTOsiz + tDiv.quot * sizMarker.iYTsiz, sizMarker.iYOsiz ) );
       
    93     iTileCanvas.iBr = TPoint( Min( sizMarker.iXTOsiz + ( tDiv.rem + 1 ) * sizMarker.iXTsiz, sizMarker.iXsiz ),
       
    94                               Min( sizMarker.iYTOsiz + ( tDiv.quot + 1 ) * sizMarker.iYTsiz, sizMarker.iYsiz ) );
       
    95 
       
    96     CJ2kComponentInfo *component = 0;
       
    97     for ( TUint16 index = 0; index < sizMarker.iCsiz; ++index )
       
    98         {
       
    99         // Instantiate the components in the tile
       
   100         component = CJ2kComponentInfo::NewLC( *this, index );
       
   101         User::LeaveIfError( iComponentList.Append( component ) );
       
   102         CleanupStack::Pop();
       
   103         }
       
   104 
       
   105     iLastN1 = iTileCanvas.iTl.iY;
       
   106     iLastN2 = iTileCanvas.iTl.iX;
       
   107 
       
   108     // Initialize the end of layer, resolution level, component to process
       
   109     iNumOfLayersPOC = NumOfLayers();
       
   110     iNumOfLevelsPOC = NumOfLevels();
       
   111     iNumOfComponentsPOC = sizMarker.iCsiz;
       
   112 
       
   113     if ( IsSpeedup() )
       
   114         {
       
   115         iNumOfLevelsPOC = (TUint8)( iNumOfLevelsPOC - iImageInfo.LevelDrop() );
       
   116         }
       
   117 
       
   118     // Let iPOC points to the POC marker in Tile Part Header
       
   119     iPOC = iTileMarker.iPoc;
       
   120     if ( !iPOC )
       
   121         {
       
   122         // Let iPOC points to the POC marker in the Main Header
       
   123         iPOC = iImageInfo.MainMarker().iPoc;
       
   124         }
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CJ2kTileInfo::AppendCOD
       
   129 // Verify and append COD to the tile part header.
       
   130 // (other items were commented in a header).
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CJ2kTileInfo::AppendCOD( TCODMarker *aMarker, TUint32 aLength )
       
   134     {
       
   135     if ( iSot.iTPsot == 0 )
       
   136         {
       
   137         // Use only for the first tile part of a tile
       
   138         if ( iTileMarker.iCod == 0 )
       
   139             {
       
   140             iTileMarker.iCod = aMarker;
       
   141             }
       
   142         else
       
   143             {
       
   144             // No more than one COD per tile
       
   145             delete aMarker;
       
   146             aMarker = 0;
       
   147             }
       
   148         }
       
   149     else
       
   150         {
       
   151         // Read but ignore it
       
   152         delete aMarker;
       
   153         aMarker = 0;
       
   154         }
       
   155 
       
   156     if ( iTileLength )
       
   157         {
       
   158         iTileLength -= aLength;
       
   159         }
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CJ2kTileInfo::AppendCOCL
       
   164 // Verify and append COC to the tile part header.
       
   165 // (other items were commented in a header).
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CJ2kTileInfo::AppendCOCL( TCOCMarker *aMarker, TUint32 aLength )
       
   169     {
       
   170     if ( iSot.iTPsot == 0 )
       
   171         {
       
   172         // Use only for the first tile part of a tile
       
   173         TUint8 found = EFalse;
       
   174         for ( TUint16 index = 0; index < iTileMarker.iCoc.Count(); ++index )
       
   175             {
       
   176             if ( iTileMarker.iCoc[index]->iCcoc == aMarker->iCcoc )
       
   177                 {
       
   178                 found = ETrue; 
       
   179                 index = (TUint16)iTileMarker.iCoc.Count();   
       
   180                 }
       
   181             }
       
   182         if ( !found )
       
   183             {
       
   184             User::LeaveIfError( iTileMarker.iCoc.Append( aMarker ) );
       
   185             }
       
   186         else
       
   187             {
       
   188             // No more than one COC per component
       
   189             delete aMarker;
       
   190             aMarker = 0;
       
   191             }
       
   192         }
       
   193     else
       
   194         {
       
   195         // Read but ignore it
       
   196         delete aMarker;
       
   197         aMarker = 0;
       
   198         }
       
   199 
       
   200     if ( iTileLength )
       
   201         {
       
   202         iTileLength -= aLength;
       
   203         }
       
   204     }
       
   205 
       
   206 // -----------------------------------------------------------------------------
       
   207 // CJ2kTileInfo::AppendQCD
       
   208 // Verify and append QCD to the tile part header.
       
   209 // (other items were commented in a header).
       
   210 // -----------------------------------------------------------------------------
       
   211 //
       
   212 void CJ2kTileInfo::AppendQCD( TQCDMarker *aMarker, TUint32 aLength )
       
   213     {
       
   214     if ( iSot.iTPsot == 0 )
       
   215         {
       
   216         // Use only for the first tile part of a tile
       
   217         if ( iTileMarker.iQcd == 0 )
       
   218             {
       
   219             iTileMarker.iQcd = aMarker;
       
   220             }
       
   221         else
       
   222             {
       
   223             // No more than one QCD per tile
       
   224             delete aMarker;
       
   225             aMarker = 0;
       
   226             }
       
   227         }
       
   228     else
       
   229         {
       
   230         // Read but ignore it
       
   231         delete aMarker;
       
   232         aMarker = 0;
       
   233         }
       
   234 
       
   235     if ( iTileLength )
       
   236         {
       
   237         iTileLength -= aLength;
       
   238         }
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CJ2kTileInfo::AppendQCCL
       
   243 // Verify and append QCC to the tile part header.
       
   244 // (other items were commented in a header).
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 void CJ2kTileInfo::AppendQCCL( TQCCMarker *aMarker, TUint32 aLength )
       
   248     {
       
   249     if ( iSot.iTPsot == 0 )
       
   250         {
       
   251         // Use only for the first tile part of a tile
       
   252         TUint8 found = EFalse;
       
   253         for ( TUint16 index = 0; index < iTileMarker.iQcc.Count(); ++index )
       
   254             {
       
   255             if ( iTileMarker.iQcc[index]->iCqcc == aMarker->iCqcc )
       
   256                 {
       
   257                 found = ETrue;
       
   258                 index = (TUint16)iTileMarker.iQcc.Count();  
       
   259                 }
       
   260             }
       
   261         if ( !found )
       
   262             {
       
   263             User::LeaveIfError( iTileMarker.iQcc.Append( aMarker ) );
       
   264             }
       
   265         else
       
   266             {
       
   267             // No more than one QCC per component
       
   268             delete aMarker;
       
   269             aMarker = 0;
       
   270             }
       
   271         }
       
   272     else
       
   273         {
       
   274         // read but ignore it
       
   275         delete aMarker;
       
   276         aMarker = 0;
       
   277         }
       
   278 
       
   279     if ( iTileLength )
       
   280         {
       
   281         iTileLength -= aLength;
       
   282         }
       
   283     }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // CJ2kTileInfo::AppendRGNL
       
   287 // Verify and append RGN to the tile part header.
       
   288 // (other items were commented in a header).
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 void CJ2kTileInfo::AppendRGNL( TRGNMarker *aMarker, TUint32 aLength )
       
   292     {
       
   293     if ( iSot.iTPsot == 0 )
       
   294         {
       
   295         // Use only for the first tile part of a tile
       
   296         TUint8 found = EFalse;
       
   297         for ( TUint16 index = 0; index < iTileMarker.iRgn.Count(); ++index )
       
   298             {
       
   299             if ( iTileMarker.iRgn[index]->iCrgn == aMarker->iCrgn )
       
   300                 {
       
   301                 found = ETrue;
       
   302                 index = (TUint16)iTileMarker.iRgn.Count();   
       
   303                 }
       
   304             }
       
   305         if ( !found )
       
   306             {
       
   307             User::LeaveIfError( iTileMarker.iRgn.Append( aMarker ) );
       
   308             }
       
   309         else
       
   310             {
       
   311             // No more than one RGN per component
       
   312             delete aMarker;
       
   313             aMarker = 0;
       
   314             }
       
   315         }
       
   316     else
       
   317         {
       
   318         // Read but ignore it
       
   319         delete aMarker;
       
   320         aMarker = 0;
       
   321         }
       
   322 
       
   323     if ( iTileLength )
       
   324         {
       
   325         iTileLength -= aLength;
       
   326         }
       
   327     }
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // CJ2kTileInfo::AppendPOCL
       
   331 // Verify and append POC to the tile part header.
       
   332 // (other items were commented in a header).
       
   333 // -----------------------------------------------------------------------------
       
   334 //
       
   335 void CJ2kTileInfo::AppendPOCL( TPOCMarker *aMarker, TUint32 aLength )
       
   336     {
       
   337     if ( iTileMarker.iPoc == 0 )
       
   338         {
       
   339         iTileMarker.iPoc = aMarker;
       
   340         }
       
   341     else
       
   342         {
       
   343         // Appending the content of the POC to the
       
   344         // existing tile part header POC
       
   345         for ( TInt index = 0; index < aMarker->iPpoc.Count(); ++index )
       
   346             {
       
   347             User::LeaveIfError( iTileMarker.iPoc->iRSpoc.Append( aMarker->iRSpoc[index] ) );
       
   348             User::LeaveIfError( iTileMarker.iPoc->iCSpoc.Append( aMarker->iCSpoc[index] ) );
       
   349             User::LeaveIfError( iTileMarker.iPoc->iLYEpoc.Append( aMarker->iLYEpoc[index] ) );
       
   350             User::LeaveIfError( iTileMarker.iPoc->iREpoc.Append( aMarker->iREpoc[index] ) );
       
   351             User::LeaveIfError( iTileMarker.iPoc->iCEpoc.Append( aMarker->iCEpoc[index] ) );
       
   352             User::LeaveIfError( iTileMarker.iPoc->iPpoc.Append( aMarker->iPpoc[index] ) );
       
   353             }
       
   354         // At most one POC may exist in tile part header
       
   355         delete aMarker;
       
   356         aMarker = 0;
       
   357         }
       
   358 
       
   359     if ( iTileLength )
       
   360         {
       
   361         iTileLength -= aLength;
       
   362         }
       
   363     }
       
   364 
       
   365 // -----------------------------------------------------------------------------
       
   366 // CJ2kTileInfo::AppendCOML
       
   367 // Verify and append COM to the tile part header.
       
   368 // (other items were commented in a header).
       
   369 // -----------------------------------------------------------------------------
       
   370 //
       
   371 void CJ2kTileInfo::AppendCOML( TCOMMarker *aMarker, TUint32 aLength )
       
   372     {
       
   373     User::LeaveIfError( iTileMarker.iCom.Append( aMarker ) );
       
   374 
       
   375     if ( iTileLength )
       
   376         {
       
   377         iTileLength -= aLength;
       
   378         }
       
   379     }
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // CJ2kTileInfo::AppendPPTL
       
   383 // Verify and append PPT to the tile part header.
       
   384 // (other items were commented in a header).
       
   385 // -----------------------------------------------------------------------------
       
   386 //
       
   387 void CJ2kTileInfo::AppendPPTL( TPPTMarker *aMarker, TUint32 aLength )
       
   388     {
       
   389     TUint8 inserted = EFalse;
       
   390 
       
   391     // Insert the new PPT marker into the right order
       
   392     for ( TUint16 index = 0; index < iTileMarker.iPpt.Count(); ++index )
       
   393         {
       
   394         // Order by iZppt of the PPT marker
       
   395         if ( iTileMarker.iPpt[index]->iZppt > aMarker->iZppt )
       
   396             {
       
   397             User::LeaveIfError( iTileMarker.iPpt.Insert( aMarker, index ) );
       
   398             inserted = ETrue;
       
   399             index = (TUint16)( iTileMarker.iPpt.Count() );   
       
   400             }
       
   401         }
       
   402 
       
   403     if ( !inserted )
       
   404         {
       
   405         User::LeaveIfError( iTileMarker.iPpt.Append( aMarker ) );
       
   406         }
       
   407     if ( iTileLength )
       
   408         {
       
   409         iTileLength -= aLength;
       
   410         }
       
   411     }
       
   412 
       
   413 // -----------------------------------------------------------------------------
       
   414 // CJ2kTileInfo::AppendPLTL
       
   415 // Verify and append PLT to the tile part header.
       
   416 // (other items were commented in a header).
       
   417 // -----------------------------------------------------------------------------
       
   418 //
       
   419 void CJ2kTileInfo::AppendPLTL( TPLTMarker *aMarker, TUint32 aLength )
       
   420     {
       
   421     TUint8 inserted = EFalse;
       
   422 
       
   423     // Insert the new PLT marker into the right order
       
   424     for ( TUint16 index = 0; index < iTileMarker.iPlt.Count(); ++index )
       
   425         {
       
   426         // Order by iZplt of the PLT marker
       
   427         if ( iTileMarker.iPlt[index]->iZplt > aMarker->iZplt )
       
   428             {
       
   429             User::LeaveIfError( iTileMarker.iPlt.Insert( aMarker, index ) );
       
   430             inserted = ETrue;
       
   431             index = (TUint16)( iTileMarker.iPlt.Count() );   
       
   432             }
       
   433         }
       
   434 
       
   435     if ( !inserted )
       
   436         {
       
   437         User::LeaveIfError( iTileMarker.iPlt.Append( aMarker ) );
       
   438         }
       
   439 
       
   440     if ( iTileLength )
       
   441         {
       
   442         iTileLength -= aLength;
       
   443         }
       
   444     }
       
   445 
       
   446 // -----------------------------------------------------------------------------
       
   447 // CJ2kTileInfo::ReadBitStreamL
       
   448 // Parsing the bitstream data based on progression order.
       
   449 // (other items were commented in a header).
       
   450 // -----------------------------------------------------------------------------
       
   451 //
       
   452 void CJ2kTileInfo::ReadBitStreamL( TUint8 aBool )
       
   453     {
       
   454     SetCheckMarker( aBool );
       
   455     if ( iPOC )
       
   456         {
       
   457         TUint8 incomplete = EFalse;
       
   458         while ( iLastPOC < iPOC->iPpoc.Count() )
       
   459             {
       
   460             if ( !iDoLoadPOC )
       
   461                 {
       
   462                 // Reload progression order change from POC marker
       
   463                 iDoLoadPOC = ETrue;
       
   464                 iLastLayer = 0;
       
   465                 iLastLevelOrig = iLastLevel = (TUint8)iPOC->iRSpoc[iLastPOC];
       
   466                 iLastComponentOrig = iLastComponent = (TUint16)iPOC->iCSpoc[iLastPOC];
       
   467 
       
   468                 iNumOfLayersPOC = (TUint16)iPOC->iLYEpoc[iLastPOC];
       
   469                 if ( iNumOfLayersPOC > NumOfLayers() )
       
   470                     {
       
   471                     iNumOfLayersPOC = NumOfLayers();
       
   472                     }
       
   473 
       
   474                 iNumOfLevelsPOC = (TUint8)( iPOC->iREpoc[iLastPOC] - 1 );
       
   475                 if ( iNumOfLevelsPOC > (TUint8)NumOfLevels() )
       
   476                     {
       
   477                     iNumOfLevelsPOC = (TUint8)NumOfLevels();
       
   478                     }
       
   479 
       
   480                 iNumOfComponentsPOC = (TUint16)iPOC->iCEpoc[iLastPOC];
       
   481                 if ( iNumOfComponentsPOC > NumOfComponents() )
       
   482                     {
       
   483                     iNumOfComponentsPOC = NumOfComponents();
       
   484                     }
       
   485 
       
   486                 for ( TUint16 index = 0; index < iNumOfComponentsPOC; ++index )
       
   487                     {
       
   488                     iComponentList[index]->ResetLastPacketProcessed();
       
   489                     }
       
   490 
       
   491                 iLastN2 = iTileCanvas.iTl.iX;
       
   492                 iLastN1 = iTileCanvas.iTl.iY;
       
   493                 }
       
   494 
       
   495             switch ( iPOC->iPpoc[iLastPOC] )
       
   496                 {
       
   497                 case EProgression_L_R_C_P:
       
   498                     {
       
   499                     incomplete = LRCPProgressionL();
       
   500                     break;
       
   501                     }
       
   502                 case EProgression_R_L_C_P:
       
   503                     {
       
   504                     incomplete = RLCPProgressionL();
       
   505                     break;
       
   506                     }
       
   507                 case EProgression_R_P_C_L:
       
   508                     {
       
   509                     incomplete = RPCLProgressionL();
       
   510                     break;
       
   511                     }
       
   512                 case EProgression_P_C_R_L:
       
   513                     {
       
   514                     incomplete = PCRLProgressionL();
       
   515                     break;
       
   516                     }
       
   517                 case EProgression_C_P_R_L:
       
   518                     {
       
   519                     incomplete = CPRLProgressionL();
       
   520                     break;
       
   521                     }
       
   522                 default:
       
   523                     {
       
   524                     // Unrecognized progressin order
       
   525                     User::Leave( KErrCorrupt );
       
   526                     break;
       
   527                     }
       
   528                 }
       
   529 
       
   530             if ( incomplete )
       
   531                 {
       
   532                 break;   //lint !e960    It is Ok to break here.
       
   533                 }
       
   534 
       
   535             if ( iLastPOC == iPOC->iPpoc.Count() && !iDoLoadPOC )
       
   536                 {
       
   537                 // Try to use Main POC if it is currently using Tile POC
       
   538                 if ( iTileMarker.iPoc && iPOC == iTileMarker.iPoc )
       
   539                     {
       
   540                     if ( iImageInfo.MainMarker().iPoc )
       
   541                         {
       
   542                         iPOC = iImageInfo.MainMarker().iPoc;
       
   543                         iLastPOC = 0;
       
   544                         }
       
   545                     }
       
   546                 }
       
   547             }
       
   548         }
       
   549     else
       
   550         {
       
   551         // Without POC changes
       
   552         switch ( ProgressionOrder() )
       
   553             {
       
   554             case EProgression_L_R_C_P:
       
   555                 {
       
   556                 LRCPProgressionL();
       
   557                 break;
       
   558                 }
       
   559             case EProgression_R_L_C_P:
       
   560                 {
       
   561                 RLCPProgressionL();
       
   562                 break;
       
   563                 }
       
   564             case EProgression_R_P_C_L:
       
   565                 {
       
   566                 RPCLProgressionL();
       
   567                 break;
       
   568                 }
       
   569             case EProgression_P_C_R_L:
       
   570                 {
       
   571                 PCRLProgressionL();
       
   572                 break;
       
   573                 }
       
   574             case EProgression_C_P_R_L:
       
   575                 {
       
   576                 CPRLProgressionL();
       
   577                 break;
       
   578                 }
       
   579             default:
       
   580                 {
       
   581                 // Unrecognized progression order
       
   582                 User::Leave( KErrCorrupt );
       
   583                 break;
       
   584                 }
       
   585             }
       
   586         }
       
   587     }
       
   588 
       
   589 // -----------------------------------------------------------------------------
       
   590 // CJ2kTileInfo::ColorTransformation
       
   591 // Get the color transformation.
       
   592 // (other items were commented in a header).
       
   593 // -----------------------------------------------------------------------------
       
   594 //
       
   595 TUint8 CJ2kTileInfo::ColorTransformation() const
       
   596     {
       
   597     return ( iTileMarker.iCod ) ?
       
   598              iTileMarker.iCod->iColorTransformation :
       
   599              iImageInfo.MainMarker().iCod.iColorTransformation;
       
   600     }
       
   601 
       
   602 // -----------------------------------------------------------------------------
       
   603 // CJ2kTileInfo::ProgressionOrder
       
   604 // Get the progression order.
       
   605 // (other items were commented in a header).
       
   606 // -----------------------------------------------------------------------------
       
   607 //
       
   608 TUint8 CJ2kTileInfo::ProgressionOrder() const
       
   609     {
       
   610     return ( iTileMarker.iCod ) ?
       
   611              iTileMarker.iCod->iProgressionOrder :
       
   612              iImageInfo.MainMarker().iCod.iProgressionOrder;
       
   613     }
       
   614 
       
   615 // -----------------------------------------------------------------------------
       
   616 // CJ2kTileInfo::NumOfLayers
       
   617 // Get the number of layers.
       
   618 // (other items were commented in a header).
       
   619 // -----------------------------------------------------------------------------
       
   620 //
       
   621 TUint16 CJ2kTileInfo::NumOfLayers() const
       
   622     {
       
   623     return ( iTileMarker.iCod ) ?
       
   624              iTileMarker.iCod->iNumOfLayers :
       
   625              iImageInfo.MainMarker().iCod.iNumOfLayers;
       
   626     }
       
   627 
       
   628 // -----------------------------------------------------------------------------
       
   629 // CJ2kTileInfo::NumOfLevels
       
   630 // Get the number of resolution level.
       
   631 // (other items were commented in a header).
       
   632 // -----------------------------------------------------------------------------
       
   633 //
       
   634 TUint8 CJ2kTileInfo::NumOfLevels() const
       
   635     {
       
   636     TUint8 maxLevel = 0;
       
   637     for ( TUint16 index = 0; index < iImageInfo.NumOfComponents(); ++index )
       
   638         {
       
   639         maxLevel = Max( maxLevel, iComponentList[index]->Levels() );
       
   640         }
       
   641 
       
   642     return maxLevel;
       
   643     }
       
   644 
       
   645 // -----------------------------------------------------------------------------
       
   646 // CJ2kTileInfo::GetMinGrid
       
   647 // Get the minimum grid among the components in the tile.
       
   648 // (other items were commented in a header).
       
   649 // -----------------------------------------------------------------------------
       
   650 //
       
   651 void CJ2kTileInfo::GetMinGrid( TSize &aGrid ) const
       
   652     {
       
   653     TSize tmpGrid;
       
   654     aGrid = iComponentList[0]->MinGrid();
       
   655     for ( TUint16 index = 1; index < iImageInfo.NumOfComponents(); ++index )
       
   656         {
       
   657         tmpGrid = iComponentList[index]->MinGrid();
       
   658         aGrid.iWidth = Min( aGrid.iWidth, tmpGrid.iWidth );
       
   659         aGrid.iHeight = Min( aGrid.iHeight, tmpGrid.iHeight );
       
   660         }
       
   661     }
       
   662 
       
   663 // -----------------------------------------------------------------------------
       
   664 // CJ2kTileInfo::UsePPTL
       
   665 // Set up to read the packet header from the PPT marker.
       
   666 // (other items were commented in a header).
       
   667 // -----------------------------------------------------------------------------
       
   668 //
       
   669 void CJ2kTileInfo::UsePPTL()
       
   670     {
       
   671     if ( !iPpt )
       
   672         {
       
   673         iPpt = new ( ELeave ) TPPTStream;
       
   674         }
       
   675     Mem::FillZ( iPpt, sizeof( TPPTStream ) );
       
   676 
       
   677     // Remove the previous ppt buffer
       
   678     delete iPptBuffer;
       
   679     iPptBuffer = 0;
       
   680 
       
   681     if ( iTileMarker.iPpt.Count() > 1  )
       
   682         {
       
   683         // Concatenate all PPT markers into one
       
   684         TInt bytes = 0;
       
   685         TInt index = 0;
       
   686         for ( index = 0; index < iTileMarker.iPpt.Count(); ++index )
       
   687             {
       
   688             bytes += iTileMarker.iPpt[index]->iIppt->Length();
       
   689             }
       
   690 
       
   691         iPptBuffer = HBufC8::NewL( bytes );
       
   692         iPpt->iPtrEnd = (TUint32)bytes;
       
   693         TPtr8 ptr = iPptBuffer->Des();
       
   694         for ( index = 0; index < iTileMarker.iPpt.Count(); ++index )
       
   695             {
       
   696             ptr.Append( iTileMarker.iPpt[index]->iIppt->Ptr(), iTileMarker.iPpt[index]->iIppt->Length() );
       
   697             }
       
   698         }
       
   699     else
       
   700         {
       
   701         // Use the only PPT marker
       
   702         // transfer the ownership of the buffer from PPT to iPptBuffer
       
   703         iPptBuffer = iTileMarker.iPpt[0]->iIppt;
       
   704         iPpt->iPtrEnd = iPptBuffer->Length();
       
   705         iTileMarker.iPpt[0]->iIppt = 0;
       
   706         }
       
   707 
       
   708     // PPT markers can be released
       
   709     iTileMarker.iPpt.ResetAndDestroy();
       
   710     iPacketHeaderReader = STATIC_CAST( MJ2kPacketHeaderReader*, this );
       
   711     }
       
   712 
       
   713 // -----------------------------------------------------------------------------
       
   714 // From MJ2kPacketHeaderReader
       
   715 // CJ2kTileInfo::ReadEPHMarker
       
   716 // Try to consume the EPH marker if there is one.
       
   717 // (other items were commented in a header).
       
   718 // -----------------------------------------------------------------------------
       
   719 //
       
   720 TUint8  CJ2kTileInfo::ReadEPHMarker()
       
   721     {
       
   722     if ( iPpt && ( iPpt->iPtrEnd - iPpt->iPtr ) >= 2 )
       
   723         {
       
   724         const TUint8 *ptr = iPptBuffer->Ptr();
       
   725         ptr += iPpt->iPtr;
       
   726         if ( PtrReadUtil::ReadBigEndianUint16( ptr ) == KEPH )
       
   727             {
       
   728             iPpt->iPtr += 2;
       
   729             }
       
   730         }
       
   731 
       
   732     return EFalse;
       
   733     }
       
   734 
       
   735 // -----------------------------------------------------------------------------
       
   736 // From MJ2kPacketHeaderReader
       
   737 // CJ2kTileInfo::ReadBit
       
   738 // Read a bit from the packet header stream.
       
   739 // (other items were commented in a header).
       
   740 // -----------------------------------------------------------------------------
       
   741 //
       
   742 TUint8 CJ2kTileInfo::ReadBit( TUint8& aBit )
       
   743     {
       
   744     if ( iPpt->iPos == 0 )
       
   745         {
       
   746         if ( iPpt->iPtr < iPpt->iPtrEnd )
       
   747             {
       
   748             // Stream contains some packet header data
       
   749             iPpt->iData = ( *iPptBuffer )[iPpt->iPtr++];
       
   750             iPpt->iPos = iPpt->iNextPos;
       
   751             if ( iPpt->iNextPos == 0x08 && iPpt->iData == 0xff )
       
   752                 {
       
   753                 iPpt->iNextPos = 0x07;
       
   754                 }
       
   755             else
       
   756                 {
       
   757                 iPpt->iNextPos = 0x08;
       
   758                 }
       
   759             }
       
   760         else
       
   761             {
       
   762             // No more data
       
   763             return ETrue;
       
   764             }
       
   765         }
       
   766     aBit = (TUint8)( ( iPpt->iData >> ( --iPpt->iPos ) ) & 0x01 );
       
   767 
       
   768     return EFalse;
       
   769     }
       
   770 
       
   771 // -----------------------------------------------------------------------------
       
   772 // From MJ2kPacketHeaderReader
       
   773 // CJ2kTileInfo::ReadBits
       
   774 // Read some bits from the packet header stream.
       
   775 // (other items were commented in a header).
       
   776 // -----------------------------------------------------------------------------
       
   777 //
       
   778 TUint8 CJ2kTileInfo::ReadBits( TUint8& aBit, TUint8 aBitLen )
       
   779     {
       
   780     aBit = (TUint8)0;
       
   781     TUint8 bit = 0;
       
   782     for ( TInt8 index = (TInt8)( aBitLen - 1 ); index >= 0; --index )
       
   783         {
       
   784         if ( !ReadBit( bit ) )
       
   785             {
       
   786             aBit |= ( bit << index );
       
   787             }
       
   788         else
       
   789             {
       
   790             return ETrue;
       
   791             }
       
   792         }
       
   793 
       
   794     return EFalse;
       
   795     }
       
   796 
       
   797 // -----------------------------------------------------------------------------
       
   798 // From MJ2kPacketHeaderReader
       
   799 // CJ2kTileInfo::ReadBits
       
   800 // Read some bits from the packet header stream.
       
   801 // (other items were commented in a header).
       
   802 // -----------------------------------------------------------------------------
       
   803 //
       
   804 TUint8 CJ2kTileInfo::ReadBits( TUint32& aBit, TUint8 aBitLen )
       
   805     {
       
   806     aBit = ( TUint32 )0;
       
   807     TUint8 bit = 0;
       
   808     for ( TInt8 index = ( TInt8 )( aBitLen - 1 ); index >= 0; --index )
       
   809         {
       
   810         if ( !ReadBit( bit ) )
       
   811             {
       
   812             aBit |= ( bit << index );
       
   813             }
       
   814         else
       
   815             {
       
   816             return ETrue;
       
   817             }
       
   818         }
       
   819 
       
   820     return EFalse;
       
   821     }
       
   822 
       
   823 // -----------------------------------------------------------------------------
       
   824 // From MJ2kPacketHeaderReader
       
   825 // CJ2kTileInfo::StartReadBit
       
   826 // Start reading from packet header stream.
       
   827 // (other items were commented in a header).
       
   828 // -----------------------------------------------------------------------------
       
   829 //
       
   830 TUint8 CJ2kTileInfo::StartReadBit()
       
   831     {
       
   832     if ( iPpt && iPpt->iPtr < iPpt->iPtrEnd )
       
   833         {
       
   834          // Stream contains some packet header data
       
   835         iPpt->iData = ( *iPptBuffer )[iPpt->iPtr++];
       
   836         iPpt->iPos = iPpt->iNextPos = 0x08;
       
   837         if ( iPpt->iData == 0xff )
       
   838             {
       
   839             iPpt->iNextPos = 0x07;
       
   840             }
       
   841 
       
   842         return EFalse;
       
   843         }
       
   844     return ETrue;
       
   845     }
       
   846 
       
   847 // -----------------------------------------------------------------------------
       
   848 // From MJ2kPacketHeaderReader
       
   849 // CJ2kTileInfo::AlignReader
       
   850 // Align the stream to the next byte boundary if necessary.
       
   851 // (other items were commented in a header).
       
   852 // -----------------------------------------------------------------------------
       
   853 //
       
   854 void CJ2kTileInfo::AlignReader()
       
   855     {
       
   856     if ( iPpt->iNextPos == 0x07 )
       
   857         {
       
   858         if ( iPpt->iPtr < iPpt->iPtrEnd )
       
   859             {
       
   860             ++iPpt->iPtr;
       
   861             }
       
   862         }
       
   863     iPpt->iData = iPpt->iPos = iPpt->iNextPos = 0;
       
   864     }
       
   865 
       
   866 // -----------------------------------------------------------------------------
       
   867 // CJ2kTileInfo::DoReleaseUnusedMarkers
       
   868 // Release unused markers in tile part header.
       
   869 // (other items were commented in a header).
       
   870 // -----------------------------------------------------------------------------
       
   871 //
       
   872 void CJ2kTileInfo::DoReleaseUnusedMarkers()
       
   873     {
       
   874     delete iPptBuffer;
       
   875     iPptBuffer = 0;
       
   876 
       
   877     iTileMarker.iPlt.ResetAndDestroy();
       
   878     iTileMarker.iCom.ResetAndDestroy();
       
   879 
       
   880     delete iTileMarker.iPoc;
       
   881     iTileMarker.iPoc = 0;
       
   882 
       
   883     delete iTileMarker.iCod;
       
   884     iTileMarker.iCod = 0;
       
   885 
       
   886     iTileMarker.iCoc.ResetAndDestroy();
       
   887     iTileMarker.iRgn.ResetAndDestroy();
       
   888     }
       
   889 
       
   890 // -----------------------------------------------------------------------------
       
   891 // CJ2kTileInfo::CJ2kTileInfo
       
   892 // C++ default constructor can NOT contain any code, that
       
   893 // might leave.
       
   894 // -----------------------------------------------------------------------------
       
   895 //
       
   896 CJ2kTileInfo::CJ2kTileInfo( CJ2kImageInfo& aImageInfo, TJ2kStreamReader& aReader ) : 
       
   897     iComponentList( 3 ), 
       
   898     iImageInfo( aImageInfo ), 
       
   899     iReader( aReader )
       
   900     {
       
   901     }
       
   902 
       
   903 // -----------------------------------------------------------------------------
       
   904 // CJ2kTileInfo::LRCPProgressionL
       
   905 // Parse the bitstream with LRCP progression order.
       
   906 // (other items were commented in a header).
       
   907 // -----------------------------------------------------------------------------
       
   908 //
       
   909 TUint8 CJ2kTileInfo::LRCPProgressionL()
       
   910     {
       
   911     TUint16 marker = 0;
       
   912     TUint8  compIncomplete = EFalse;
       
   913 
       
   914     // For each layer
       
   915     while ( iLastLayer < iNumOfLayersPOC )
       
   916         {
       
   917         // For each resolution level
       
   918         while ( iLastLevel <= iNumOfLevelsPOC )
       
   919             {
       
   920             // For each component
       
   921             while ( iLastComponent < iNumOfComponentsPOC )
       
   922                 {
       
   923                 compIncomplete = iComponentList[iLastComponent]->LRCPProgressionL( *this );
       
   924                 if ( compIncomplete )
       
   925                     {
       
   926                     // Underflow
       
   927                     return compIncomplete;
       
   928                     }
       
   929 
       
   930                 if ( IsPOC() )
       
   931                     {
       
   932                     // Check if we found next SOT or EOC
       
   933                     marker = PtrReadUtil::ReadBigEndianUint16( iReader.iPtr );
       
   934                     if ( marker == KSOT || marker == KEOC )
       
   935                         {
       
   936                         compIncomplete = ETrue;
       
   937                         return compIncomplete;
       
   938                         }
       
   939                     }
       
   940 
       
   941                 ++iLastComponent;
       
   942                 }
       
   943 
       
   944             iLastComponent = iLastComponentOrig;
       
   945             ++iLastLevel;
       
   946 
       
   947             if ( IsCheckMarker() )
       
   948                 {
       
   949                 // Check if we found next SOT or EOC
       
   950                 // it signals the end of one LEVEL
       
   951                 marker = PtrReadUtil::ReadBigEndianUint16( iReader.iPtr );
       
   952                 if ( marker == KSOT || marker == KEOC )
       
   953                     {
       
   954                     compIncomplete = ETrue;
       
   955                     return compIncomplete;
       
   956                     }
       
   957                 }
       
   958             }
       
   959 
       
   960         iLastLevel = iLastLevelOrig;
       
   961         ++iLastLayer;
       
   962         }
       
   963 
       
   964     // Continue using the next POC
       
   965     ++iLastPOC;
       
   966     iDoLoadPOC = EFalse;
       
   967 
       
   968     return compIncomplete;
       
   969     }
       
   970 
       
   971 // -----------------------------------------------------------------------------
       
   972 // CJ2kTileInfo::RLCPProgressionL
       
   973 // Parse the bitstream with RLCP progression order.
       
   974 // (other items were commented in a header).
       
   975 // -----------------------------------------------------------------------------
       
   976 //
       
   977 TUint8 CJ2kTileInfo::RLCPProgressionL()
       
   978     {
       
   979     TUint16 marker = 0;
       
   980     TUint8  compIncomplete = EFalse;
       
   981 
       
   982     // For each resolution level
       
   983     while ( iLastLevel <= iNumOfLevelsPOC )
       
   984         {
       
   985         // For each layer
       
   986         while ( iLastLayer < iNumOfLayersPOC )
       
   987             {
       
   988             // For each component
       
   989             while ( iLastComponent < iNumOfComponentsPOC )
       
   990                 {
       
   991                 compIncomplete = iComponentList[iLastComponent]->LRCPProgressionL( *this );
       
   992                 if ( compIncomplete )
       
   993                     {
       
   994                     // Underflow
       
   995                     return compIncomplete;
       
   996                     }
       
   997 
       
   998                 if ( IsPOC() )
       
   999                     {
       
  1000                     // Check if we found next SOT or EOC
       
  1001                     marker = PtrReadUtil::ReadBigEndianUint16( iReader.iPtr );
       
  1002                     if ( marker == KSOT || marker == KEOC )
       
  1003                         {
       
  1004                         compIncomplete = ETrue;
       
  1005                         return compIncomplete;
       
  1006                         }
       
  1007                     }
       
  1008 
       
  1009                 ++iLastComponent;
       
  1010                 }
       
  1011 
       
  1012             iLastComponent = iLastComponentOrig;
       
  1013             ++iLastLayer;
       
  1014 
       
  1015             if ( IsCheckMarker() )
       
  1016                 {
       
  1017                 // Check if we found next SOT or EOC
       
  1018                 // it signals the end of one LAYER
       
  1019                 marker = PtrReadUtil::ReadBigEndianUint16( iReader.iPtr );
       
  1020                 if ( marker == KSOT || marker == KEOC )
       
  1021                     {
       
  1022                     
       
  1023                     // If we are at the end of layers, we have to reset 
       
  1024                     // layers and move to next resolution level
       
  1025                     if(iLastLayer==iNumOfLayersPOC)
       
  1026                     {
       
  1027                         iLastLayer = 0;
       
  1028                         ++iLastLevel;
       
  1029                     }
       
  1030                     
       
  1031                     compIncomplete = ETrue;
       
  1032                     return compIncomplete;
       
  1033                     }
       
  1034                 }
       
  1035             }
       
  1036 
       
  1037         iLastLayer = 0;
       
  1038         ++iLastLevel;
       
  1039         }
       
  1040 
       
  1041     // Continue using the next POC
       
  1042     ++iLastPOC;
       
  1043     iDoLoadPOC = EFalse;
       
  1044 
       
  1045     return compIncomplete;
       
  1046     }
       
  1047 
       
  1048 // -----------------------------------------------------------------------------
       
  1049 // CJ2kTileInfo::RPCLProgressionL
       
  1050 // Parse the bitstream with RPCL progression order.
       
  1051 // (other items were commented in a header).
       
  1052 // -----------------------------------------------------------------------------
       
  1053 //
       
  1054 TUint8 CJ2kTileInfo::RPCLProgressionL()
       
  1055     {
       
  1056     TUint16 marker = 0;
       
  1057     TUint8  compIncomplete = EFalse;
       
  1058 
       
  1059     TSize   minGrid( 0, 0 );
       
  1060     GetMinGrid( minGrid );
       
  1061 	
       
  1062 	// Check that no divided by zero calculation are done.
       
  1063 	if ( minGrid.iWidth == 0 || minGrid.iHeight == 0 )
       
  1064 		{
       
  1065 		User::Leave( KErrCorrupt );	
       
  1066 		}
       
  1067 
       
  1068     // For each resolution level
       
  1069     while ( iLastLevel <= iNumOfLevelsPOC )
       
  1070         {
       
  1071         // For each position in vertical direction
       
  1072         while ( iLastN1 < iTileCanvas.iBr.iY )
       
  1073             {
       
  1074             // For each position in horizontal direction
       
  1075             while ( iLastN2 < iTileCanvas.iBr.iX )
       
  1076                 {
       
  1077                 // For each component
       
  1078                 while ( iLastComponent < iNumOfComponentsPOC )
       
  1079                     {
       
  1080                     compIncomplete = iComponentList[iLastComponent]->RPCLProgressionL( *this );
       
  1081                     if ( compIncomplete )
       
  1082                         {
       
  1083                         // Underflow
       
  1084                         return compIncomplete;
       
  1085                         }
       
  1086 
       
  1087                     if ( IsPOC() )
       
  1088                         {
       
  1089                         // Check if we found next SOT or EOC
       
  1090                         // it signals the end of one Precinct
       
  1091                         marker = PtrReadUtil::ReadBigEndianUint16( iReader.iPtr );
       
  1092                         if ( marker == KSOT || marker == KEOC )
       
  1093                             {
       
  1094                             compIncomplete = ETrue;
       
  1095                             return compIncomplete;
       
  1096                             }
       
  1097                         }
       
  1098 
       
  1099                     ++iLastComponent;
       
  1100                     }
       
  1101 
       
  1102                 iLastComponent = iLastComponentOrig;
       
  1103                 iLastN2 += ( minGrid.iWidth - ( iLastN2 % minGrid.iWidth ) );
       
  1104 
       
  1105                 if ( IsCheckMarker() )
       
  1106                     {
       
  1107                     // Check if we found next SOT or EOC
       
  1108                     // it signals the end of one Precinct
       
  1109                     marker = PtrReadUtil::ReadBigEndianUint16( iReader.iPtr );
       
  1110                     if ( marker == KSOT || marker == KEOC )
       
  1111                         {
       
  1112                         
       
  1113                         // If we are at the end of horizontal precincts, move to 
       
  1114                         // next row of vertical precincts
       
  1115                         if(iLastN2 >= iTileCanvas.iBr.iX)
       
  1116                         {
       
  1117                             iLastN2 = iTileCanvas.iTl.iX;
       
  1118                             iLastN1 += ( minGrid.iHeight - ( iLastN1 % minGrid.iHeight ) );
       
  1119                             // If we are at the end of vertical precincts, move to next 
       
  1120                             // resolution level
       
  1121                             if(iLastN1 >= iTileCanvas.iBr.iY)
       
  1122                             {
       
  1123                                 iLastN1 = iTileCanvas.iTl.iY;
       
  1124                                 // Advance to next level to avoid a situation where we would 
       
  1125                                 // return without reading any bytes from the frame the next 
       
  1126                                 // time we enter this function
       
  1127                                 ++iLastLevel;
       
  1128                             }
       
  1129                         }
       
  1130                         
       
  1131                         compIncomplete = ETrue;
       
  1132                         return compIncomplete;
       
  1133                         }
       
  1134                     }
       
  1135                 }
       
  1136 
       
  1137             iLastN2 = iTileCanvas.iTl.iX;
       
  1138             iLastN1 += ( minGrid.iHeight - ( iLastN1 % minGrid.iHeight ) );
       
  1139             }
       
  1140 
       
  1141         iLastN2 = iTileCanvas.iTl.iX;
       
  1142         iLastN1 = iTileCanvas.iTl.iY;
       
  1143         ++iLastLevel;
       
  1144         }
       
  1145 
       
  1146     // Continue using the next POC
       
  1147     ++iLastPOC;
       
  1148     iDoLoadPOC = EFalse;
       
  1149 
       
  1150     return compIncomplete;
       
  1151     }
       
  1152 
       
  1153 // -----------------------------------------------------------------------------
       
  1154 // CJ2kTileInfo::PCRLProgressionL
       
  1155 // Parse the bitstream with PCRL progression order.
       
  1156 // (other items were commented in a header).
       
  1157 // -----------------------------------------------------------------------------
       
  1158 //
       
  1159 TUint8 CJ2kTileInfo::PCRLProgressionL()
       
  1160     {
       
  1161     TUint16 marker = 0;
       
  1162     TUint8  compIncomplete = EFalse;
       
  1163 
       
  1164     TSize   minGrid;
       
  1165     GetMinGrid( minGrid );
       
  1166 
       
  1167 	// Check that no divided by zero calculation are done.
       
  1168 	if ( minGrid.iWidth == 0 || minGrid.iHeight == 0 )
       
  1169 		{
       
  1170 		User::Leave( KErrCorrupt );	
       
  1171 		}
       
  1172 
       
  1173     // For each position in vertical direction
       
  1174     while ( iLastN1 < iTileCanvas.iBr.iY )
       
  1175         {
       
  1176         // For each position in horizontal direction
       
  1177         while ( iLastN2 < iTileCanvas.iBr.iX )
       
  1178             {
       
  1179             // For each component
       
  1180             while ( iLastComponent < iNumOfComponentsPOC )
       
  1181                 {
       
  1182                 // For each resolution level
       
  1183                 while ( iLastLevel <= iNumOfLevelsPOC )
       
  1184                     {
       
  1185                     compIncomplete = iComponentList[iLastComponent]->CPRLProgressionL( *this );
       
  1186                     if ( compIncomplete )
       
  1187                         {
       
  1188                         // Underflow
       
  1189                         return compIncomplete;
       
  1190                         }
       
  1191 
       
  1192                     if ( IsPOC() )
       
  1193                         {
       
  1194                         // Check if we found next SOT or EOC
       
  1195                         // it signals the end of one Precinct
       
  1196                         marker = PtrReadUtil::ReadBigEndianUint16( iReader.iPtr );
       
  1197                         if ( marker == KSOT || marker == KEOC )
       
  1198                             {
       
  1199                             compIncomplete = ETrue;
       
  1200                             return compIncomplete;
       
  1201                             }
       
  1202                         }
       
  1203 
       
  1204                     ++iLastLevel;
       
  1205                     }
       
  1206 
       
  1207                 iLastLevel = iLastLevelOrig;
       
  1208                 ++iLastComponent;
       
  1209 
       
  1210                 if ( IsCheckMarker() )
       
  1211                     {
       
  1212                     // Check if we found next SOT or EOC
       
  1213                     // it signals the end of one Precinct
       
  1214                     marker = PtrReadUtil::ReadBigEndianUint16( iReader.iPtr );
       
  1215                     if ( marker == KSOT || marker == KEOC )
       
  1216                         {
       
  1217                         compIncomplete = ETrue;
       
  1218                         return compIncomplete;
       
  1219                         }
       
  1220                     }
       
  1221                 }
       
  1222 
       
  1223             iLastComponent = iLastComponentOrig;
       
  1224             iLastN2 += ( minGrid.iWidth - ( iLastN2 % minGrid.iWidth ) );
       
  1225             }
       
  1226 
       
  1227         iLastN2 = iTileCanvas.iTl.iX;
       
  1228         iLastN1 += ( minGrid.iHeight - ( iLastN1 % minGrid.iHeight ) );
       
  1229         }
       
  1230 
       
  1231     // Continue using the next POC
       
  1232     ++iLastPOC;
       
  1233     iDoLoadPOC = EFalse;
       
  1234 
       
  1235     return compIncomplete;
       
  1236     }
       
  1237 
       
  1238 // -----------------------------------------------------------------------------
       
  1239 // CJ2kTileInfo::CPRLProgressionL
       
  1240 // Parse the bitstream with CPRL progression order.
       
  1241 // (other items were commented in a header).
       
  1242 // -----------------------------------------------------------------------------
       
  1243 //
       
  1244 TUint8 CJ2kTileInfo::CPRLProgressionL()
       
  1245     {
       
  1246     TUint16 marker = 0;
       
  1247     TUint8  compIncomplete = EFalse;
       
  1248 
       
  1249     TSize   minGrid;
       
  1250     GetMinGrid( minGrid );
       
  1251 
       
  1252 	// Check that no divided by zero calculation are done.
       
  1253 	if ( minGrid.iWidth == 0 || minGrid.iHeight == 0 )
       
  1254 		{
       
  1255 		User::Leave( KErrCorrupt );	
       
  1256 		}
       
  1257 
       
  1258     // For each component
       
  1259     while ( iLastComponent < iNumOfComponentsPOC )
       
  1260         {
       
  1261         // For each position in vertical direction
       
  1262         while ( iLastN1 < iTileCanvas.iBr.iY )
       
  1263             {
       
  1264             // For each position in horizontal direction
       
  1265             while ( iLastN2 < iTileCanvas.iBr.iX )
       
  1266                 {
       
  1267                 // For each resolution level
       
  1268                 while ( iLastLevel <= iNumOfLevelsPOC )
       
  1269                     {
       
  1270                     compIncomplete = iComponentList[iLastComponent]->CPRLProgressionL( *this );
       
  1271                     if ( compIncomplete )
       
  1272                         {
       
  1273                         // Underflow
       
  1274                         return compIncomplete;
       
  1275                         }
       
  1276 
       
  1277                     if ( IsPOC() )
       
  1278                         {
       
  1279                         // Check if we found next SOT or EOC
       
  1280                         // it signals the end of one Precinct
       
  1281                         marker = PtrReadUtil::ReadBigEndianUint16( iReader.iPtr );
       
  1282                         if ( marker == KSOT || marker == KEOC )
       
  1283                             {
       
  1284                             compIncomplete = ETrue;
       
  1285                             return compIncomplete;
       
  1286                             }
       
  1287                         }
       
  1288 
       
  1289                     ++iLastLevel;
       
  1290                     }
       
  1291 
       
  1292                 iLastLevel = iLastLevelOrig;
       
  1293                 iLastN2 += ( minGrid.iWidth - ( iLastN2 % minGrid.iWidth ) );
       
  1294 
       
  1295                 if ( IsCheckMarker() )
       
  1296                     {
       
  1297                     // Check if we found next SOT or EOC
       
  1298                     // it signals the end of one Precinct
       
  1299                     marker = PtrReadUtil::ReadBigEndianUint16( iReader.iPtr );
       
  1300                     if ( marker == KSOT || marker == KEOC )
       
  1301                         {
       
  1302                         compIncomplete = ETrue;
       
  1303                         return compIncomplete;
       
  1304                         }
       
  1305                     }
       
  1306                 }
       
  1307 
       
  1308             iLastN2 = iTileCanvas.iTl.iX;
       
  1309             iLastN1 += ( minGrid.iHeight - ( iLastN1 % minGrid.iHeight ) );
       
  1310             }
       
  1311 
       
  1312         iLastN2 = iTileCanvas.iTl.iX;
       
  1313         iLastN1 = iTileCanvas.iTl.iY;
       
  1314         ++iLastComponent;
       
  1315         }
       
  1316 
       
  1317     // Continue using the next POC
       
  1318     ++iLastPOC;
       
  1319     iDoLoadPOC = EFalse;
       
  1320 
       
  1321     return compIncomplete;
       
  1322     }
       
  1323