imagingmodules/exiflib/src/ExifRead.cpp
changeset 0 469c91dae73b
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:  Exif v2.2 file format reader/parser API implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "ExifReadImpl.h"
       
    21 #include "ExifCore.h"
       
    22 #include "ExifEndian.h"
       
    23 #include "ExifCommon.h"
       
    24 #include "ExifTagImpl.h"
       
    25 
       
    26 // ============================ CLASS CExifRead ================================
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CExifRead::NewL
       
    31 // Two-phased constructor.
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 EXPORT_C CExifRead* CExifRead::NewL( const TDesC8& aExifData )
       
    35     {
       
    36     return CExifReadImpl::NewL( aExifData, EFalse, CExifRead::ENoOptions );
       
    37     }
       
    38 
       
    39 EXPORT_C CExifRead* CExifRead::NewL( const TDesC8& aExifData, TUint aExifReadOption )
       
    40     {
       
    41     return CExifReadImpl::NewL( aExifData, EFalse, aExifReadOption );
       
    42     }
       
    43 
       
    44 // Destructor
       
    45 CExifRead::~CExifRead()
       
    46     {
       
    47     }
       
    48 
       
    49 
       
    50 // ============================ CLASS CExifReadImpl ============================
       
    51 // ============================ MEMBER FUNCTIONS ===============================
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CExifReadImpl::CExifReadImpl
       
    55 // C++ default constructor can NOT contain any code, that
       
    56 // might leave.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CExifReadImpl::CExifReadImpl()
       
    60     {
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CExifReadImpl::ConstructL
       
    65 // Symbian 2nd phase constructor can leave.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void CExifReadImpl::ConstructL( const TDesC8& aExifData, TBool aCreate, TUint aExifReadOption )
       
    69     {
       
    70     LOGTEXT3( _L( "ExifLib: CExifReadImpl::ConstructL() entering: aCreate=%x, aExifReadOption=0x%x" ), aCreate, aExifReadOption );
       
    71     iExifReadOption = aExifReadOption;
       
    72     iExifCore = CExifCore::NewL();
       
    73     iReader = CExifEndianBase::NewBaseL( aExifData.Ptr(), aExifData.Length(), 
       
    74             !aCreate );
       
    75 
       
    76     if ( aCreate )
       
    77         {
       
    78         ParseJpegDataL();
       
    79         }
       
    80     else
       
    81         {
       
    82         ParseExifFormatL();
       
    83         if ( !(iExifReadOption & CExifRead::ENoTagChecking ) &&
       
    84             !iExifCore->IsValid() )
       
    85             {
       
    86             LOGTEXT( _L( "ExifLib: CExifReadImpl::ConstructL() Leaving KErrNotSupported" ));
       
    87             User::Leave( KErrNotSupported );
       
    88             }
       
    89         }
       
    90     LOGTEXT( _L( "ExifLib: CExifReadImpl::ConstructL() returning" ));
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CExifReadImpl::ConstructL
       
    95 // Symbian 2nd phase constructor can leave.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CExifReadImpl::ConstructL()
       
    99     {
       
   100     iExifReadOption = CExifRead::ENoOptions;
       
   101     iExifCore = CExifCore::NewL();
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CExifReadImpl::NewL
       
   106 // Two-phased constructor.
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 CExifReadImpl* CExifReadImpl::NewL( const TDesC8& aExifData, TBool aCreate, TUint aExifReadOption )
       
   110     {
       
   111     CExifReadImpl* self = new( ELeave ) CExifReadImpl();
       
   112     CleanupStack::PushL( self ); 
       
   113     self->ConstructL( aExifData, aCreate, aExifReadOption );
       
   114     CleanupStack::Pop();
       
   115     return self;
       
   116     }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // CExifReadImpl::NewL
       
   120 // Two-phased constructor.
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 CExifReadImpl* CExifReadImpl::NewL()
       
   124     {
       
   125     CExifReadImpl* self = new( ELeave ) CExifReadImpl();
       
   126     CleanupStack::PushL( self ); 
       
   127     self->ConstructL();
       
   128     CleanupStack::Pop();
       
   129     return self;
       
   130     }
       
   131 
       
   132 // Destructor
       
   133 CExifReadImpl::~CExifReadImpl()
       
   134     {
       
   135     LOGTEXT( _L( "ExifLib: CExifReadImpl::~CExifReadImpl() entering" ) );
       
   136     if ( iExifCore )
       
   137         {
       
   138         delete iExifCore;
       
   139         }
       
   140     if ( iReader )
       
   141         {
       
   142         delete iReader;
       
   143         }
       
   144     LOGTEXT( _L( "ExifLib: CExifReadImpl::~CExifReadImpl() returning" ) );
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CExifReadImpl::GetTagL
       
   149 // Returns the Tag instance that has the specified tag ID from the requested IFD
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 const CExifTag* CExifReadImpl::GetTagL( 
       
   153     const TExifIfdType aIfdType, 
       
   154     const TUint16 aTagId ) const
       
   155     {
       
   156     if ( !iExifCore )
       
   157         {
       
   158         User::Leave( KErrGeneral );
       
   159         }
       
   160 
       
   161     if ( !TExifCommon::IsValidTagId( aTagId ) )
       
   162         {
       
   163         LOGTEXT( _L( "ExifLib: CExifReadImpl::GetTagL Leave( KErrNotSupported )" ) );
       
   164         User::Leave( KErrNotSupported );
       
   165         }
       
   166     return iExifCore->GetTagL( aIfdType, aTagId );
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CExifReadImpl::GetTagIdsL
       
   171 // Returns the IDs of all the tags that are stored in the Exif data.
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 TUint16* CExifReadImpl::GetTagIdsL( 
       
   175     const TExifIfdType aIfdType, 
       
   176     TInt& aNoTags ) const
       
   177     {
       
   178     if ( !iExifCore )
       
   179         {
       
   180         LOGTEXT( _L( "ExifLib: CExifReadImpl::GetTagIdsL Leave( KErrGeneral )" ) );
       
   181         User::Leave( KErrGeneral );
       
   182         }
       
   183 
       
   184     return iExifCore->GetTagIdsL( aIfdType, aNoTags );
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CExifReadImpl::GetIfdTypesL
       
   189 // Returns the types of the IFDs stored in the Exif data.
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 TExifIfdType* CExifReadImpl::GetIfdTypesL( TInt& aNoIfd ) const
       
   193     {
       
   194     if ( !iExifCore )
       
   195         {
       
   196         LOGTEXT( _L( "ExifLib: CExifReadImpl::GetIfdTypesL Leave( KErrGeneral )" ) );
       
   197         User::Leave( KErrGeneral );
       
   198         }
       
   199     
       
   200     return iExifCore->GetIfdTypesL( aNoIfd );
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CExifReadImpl::GetThumbnailL
       
   205 // Returns pointer to a copy of the thumbnail image data.
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 HBufC8* CExifReadImpl::GetThumbnailL() const
       
   209     {
       
   210     if ( !iExifCore )
       
   211         {
       
   212         LOGTEXT( _L( "ExifLib: CExifReadImpl::GetThumbnailL Leave( KErrGeneral )" ) );
       
   213         User::Leave( KErrGeneral );
       
   214         }
       
   215     
       
   216     return iExifCore->GetThumbnailL();
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CExifReadImpl::IfdExists
       
   221 // Returns a boolean stating if the queried IFD structure exists in Exif data
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 TBool CExifReadImpl::IfdExists( const TExifIfdType aIfdType ) const
       
   225     {
       
   226     if ( !iExifCore )
       
   227         {
       
   228         LOGTEXT( _L( "ExifLib: CExifReadImpl::IfdExists return EFalse" ) );
       
   229         return EFalse;
       
   230         }
       
   231 
       
   232     return iExifCore->IfdExists( aIfdType );
       
   233     }
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // CExifReadImpl::TagExists
       
   237 // Returns a boolean stating if the queried tag exists in the specified IFD 
       
   238 // structure
       
   239 // -----------------------------------------------------------------------------
       
   240 //
       
   241 TBool CExifReadImpl::TagExists( 
       
   242     const TUint16 aTagId, 
       
   243     const TExifIfdType aIfdType ) const
       
   244     {
       
   245     if ( !iExifCore )
       
   246         {
       
   247         LOGTEXT( _L( "ExifLib: CExifReadImpl::TagExists return EFalse" ) );
       
   248         return EFalse;
       
   249         }
       
   250 
       
   251     return iExifCore->TagExists( aTagId, aIfdType );
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CExifReadImpl::ParseExifFormatL
       
   256 // Parses the IFD data according to the specified IFD type. 
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 void CExifReadImpl::ParseExifFormatL()
       
   260     {
       
   261     LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseExifFormatL() entering" ) );
       
   262     if ( ( !iExifCore ) || ( !iReader ) )
       
   263         {
       
   264         LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseExifFormatL() Leaving KErrGeneral" ) );
       
   265         User::Leave( KErrGeneral );
       
   266         }
       
   267 
       
   268     TUint32 ifd1Offset = 0;
       
   269     ParseIfdL( EIfd0, ifd1Offset );
       
   270     
       
   271     TUint32 ifdExifOffset = 0;
       
   272     User::LeaveIfError( iExifCore->GetTagData( KIdExifIfdPointer, 
       
   273         ifdExifOffset ) ); 
       
   274 
       
   275     User::LeaveIfError( iReader->MoveTo( ifdExifOffset ) );
       
   276 
       
   277     TUint32 nextIfdOffset = 0;
       
   278     ParseIfdL( EIfdExif, nextIfdOffset );
       
   279 
       
   280     TUint32 ifdGpsOffset = 0 ;
       
   281     if ( !iExifCore->GetTagData( KIdGpsIfdPointer, ifdGpsOffset ) )
       
   282         {
       
   283         User::LeaveIfError( iReader->MoveTo( ifdGpsOffset ) );
       
   284         iExifCore->CreateIfdL( EIfdGps );
       
   285         nextIfdOffset = 0;
       
   286         ParseIfdL( EIfdGps, nextIfdOffset );
       
   287         }
       
   288 
       
   289     TUint32 ifdIntOpOffset = 0;
       
   290     if ( !iExifCore->GetTagData( KIdIntOpIfdPointer, ifdIntOpOffset ) )
       
   291         {
       
   292         User::LeaveIfError( iReader->MoveTo( ifdIntOpOffset ) );
       
   293         iExifCore->CreateIfdL( EIfdIntOp );
       
   294         nextIfdOffset = 0;
       
   295         ParseIfdL( EIfdIntOp, nextIfdOffset );
       
   296         }
       
   297 
       
   298     if ( ifd1Offset )
       
   299         {
       
   300         User::LeaveIfError( iReader->MoveTo( ifd1Offset ) );
       
   301         TRAPD( error, ParseIfdL( EIfd1, nextIfdOffset ) );
       
   302         if ( error == KErrNotSupported )
       
   303             {
       
   304             iExifCore->DeleteIfd( EIfd1 );
       
   305             }
       
   306         else if ( error == KErrCorrupt && ( iExifReadOption & CExifRead::ENoTagChecking ) )
       
   307             {
       
   308             iExifCore->DeleteIfd( EIfd1 );
       
   309             }
       
   310         else
       
   311             {
       
   312             LOGTEXT2( _L( "ExifLib: CExifReadImpl::ParseExifFormatL() ParseIfdL error=%d" ), error );
       
   313             User::LeaveIfError( error );
       
   314             }
       
   315         }
       
   316 
       
   317     // Parse jpeg data only if it is read to buffer    
       
   318     if ( !(iExifReadOption & (CExifRead::ENoJpeg)) )
       
   319         {
       
   320         ParseJpegDataL();
       
   321         }
       
   322     LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseExifFormatL() returning" ) );
       
   323     }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // CExifReadImpl::ParseIfdL
       
   327 // Parses the Jpeg primary image data and initializes the Jpeg primary image 
       
   328 // structures.
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 void CExifReadImpl::ParseIfdL( 
       
   332     const TExifIfdType aIfdType, 
       
   333     TUint32& aNextIfdOffset )
       
   334     {
       
   335     LOGTEXT3( _L( "ExifLib: CExifReadImpl::ParseIfdL() entering: aIfdType=0x%x, aNextIfdOffset=0x%x" ), aIfdType, aNextIfdOffset );
       
   336     if ( ( !iExifCore ) || ( !iReader ) )
       
   337         {
       
   338         LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseIfdL() Leaving KErrGeneral" ) );
       
   339         User::Leave( KErrGeneral );
       
   340         }
       
   341 
       
   342     TUint16 noTagsInIfd = 0;
       
   343     User::LeaveIfError( iReader->ReadUInt16( noTagsInIfd ) );
       
   344     if ( !noTagsInIfd )
       
   345         {
       
   346         LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseIfdL() Leaving KErrNotSupported" ) );
       
   347         User::Leave( KErrNotSupported );
       
   348         }
       
   349     // Read and create each tag one by one
       
   350     TUint32 tagsEndOffset = 0;
       
   351     for ( TUint16 i = 0; i < noTagsInIfd; ++i )
       
   352         {
       
   353         TUint16 tagId = 0;
       
   354         TUint16 tagType = 0;
       
   355         TUint32 tagCount = 0;
       
   356         User::LeaveIfError( ReadTagHeader( tagId, tagType, tagCount ) );
       
   357         TUint noBytes = 0;
       
   358         if ( ( tagType == CExifTag::ETagByte ) || 
       
   359             ( tagType == CExifTag::ETagAscii ) || 
       
   360             ( tagType == CExifTag::ETagUndefined ) )
       
   361             {
       
   362             noBytes = sizeof( TUint8 );
       
   363             }
       
   364         else if ( ( tagType == CExifTag::ETagLong ) || 
       
   365             ( tagType == CExifTag::ETagSlong ) )
       
   366             {
       
   367             noBytes = sizeof( TUint32 );
       
   368             }
       
   369         else if ( ( tagType == CExifTag::ETagRational ) || 
       
   370             ( tagType == CExifTag::ETagSrational ) )
       
   371             {
       
   372             noBytes = 2 * sizeof( TUint32 );
       
   373             }
       
   374         else if ( tagType == CExifTag::ETagShort )
       
   375             {
       
   376             noBytes = sizeof( TUint16 );
       
   377             }
       
   378         else
       
   379             {
       
   380             LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseIfdL() Leaving KErrCorrupt" ) );
       
   381             User::Leave( KErrCorrupt );
       
   382             }
       
   383         LOGTEXT2( _L( "ExifLib: CExifReadImpl::ParseIfdL() noBytes=%d" ), noBytes );
       
   384 
       
   385         if ( tagCount > KMaxApp1Size )
       
   386             {
       
   387             LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseIfdL() Leaving KErrCorrupt (>KMaxApp1Size)" ) );
       
   388             User::Leave( KErrCorrupt );
       
   389             }
       
   390         LOGTEXT2( _L( "ExifLib: CExifReadImpl::ParseIfdL() tagCount=%d" ), tagCount );
       
   391 
       
   392         if ( !tagCount )
       
   393             {
       
   394                 if ( noBytes > 4)
       
   395                     {
       
   396                     LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseIfdL() Leaving KErrCorrupt (noBytes > 4)" ) );
       
   397                     User::Leave( KErrCorrupt );
       
   398                     }
       
   399                 tagCount = 4 / noBytes;
       
   400             }
       
   401         noBytes *= tagCount;
       
   402         HBufC8* valueBuffer = HBufC8::NewL( noBytes );
       
   403         CleanupStack::PushL( valueBuffer );
       
   404 
       
   405         // If real tag data size is smaller than 4 bytes, the data is at the 
       
   406         // current position. Otherwise 4-byte pointer to the real data location
       
   407         // is kept. The pointer is at current location.
       
   408         LOGTEXT2( _L( "ExifLib: CExifReadImpl::ParseIfdL() noBytes=%d" ), noBytes );
       
   409         if ( noBytes < 5 )
       
   410             {
       
   411             iReader->CopyBuffer( tagCount, 
       
   412                 STATIC_CAST( TUint8, ( noBytes / tagCount ) ), valueBuffer );
       
   413             // Skip remaining bytes.
       
   414             if ( 4 - noBytes )
       
   415                 {
       
   416                 LOGTEXT2( _L( "ExifLib: CExifReadImpl::ParseIfdL() skipping=%d" ), 4 - noBytes );
       
   417                 iReader->Skip( 4 - noBytes );
       
   418                 }
       
   419             }
       
   420         else
       
   421             {
       
   422             TUint32 valueOffset = 0;
       
   423             User::LeaveIfError( iReader->ReadUInt32( valueOffset ) );
       
   424             LOGTEXT2( _L( "ExifLib: CExifReadImpl::ParseIfdL() valueOffset=%d" ), valueOffset );
       
   425             User::LeaveIfError( iReader->CopyBuffer( valueOffset, tagCount, 
       
   426                 STATIC_CAST( TUint8, ( noBytes / tagCount ) ), valueBuffer ) );
       
   427             LOGTEXT2( _L( "ExifLib: CExifReadImpl::ParseIfdL() tagCount=%d" ), tagsEndOffset );
       
   428             if ( tagsEndOffset < ( valueOffset + noBytes ) ) 
       
   429                 {
       
   430                 tagsEndOffset = valueOffset + noBytes;
       
   431                 }
       
   432             }
       
   433             
       
   434         //
       
   435         // Test if unknown tags should just be skipped and delete
       
   436         // 
       
   437         LOGTEXT2( _L( "ExifLib: CExifReadImpl::ParseIfdL() iExifReadOption=%x" ), iExifReadOption );
       
   438         if ( !(iExifReadOption & CExifRead::ENoTagChecking ) && !TExifCommon::IsValidTagId( tagId ) )
       
   439             {
       
   440             LOGTEXT2( _L( "ExifLib: CExifReadImpl::ParseIfdL() skipping tagId=%x" ), tagId );
       
   441             CleanupStack::PopAndDestroy( valueBuffer );
       
   442             }
       
   443         else // Tag was known
       
   444             {
       
   445             LOGTEXT2( _L( "ExifLib: CExifReadImpl::ParseIfdL() create new tagId=%x" ), tagId );
       
   446             CExifTagImpl* tag = NULL;
       
   447             if ( iExifReadOption & CExifRead::ENoTagChecking )
       
   448                 {
       
   449                 tag = CExifTagImpl::NewL( tagId, 
       
   450                     STATIC_CAST( CExifTag::TExifTagDataType, tagType ), 
       
   451                     tagCount, valueBuffer, EFalse );
       
   452                 }
       
   453             else
       
   454                 {
       
   455                 tag = CExifTagImpl::NewL( tagId, 
       
   456                     STATIC_CAST( CExifTag::TExifTagDataType, tagType ), 
       
   457                     tagCount, valueBuffer, ETrue );
       
   458                 }
       
   459             CleanupStack::Pop( valueBuffer );
       
   460             CleanupStack::PushL( tag );
       
   461             
       
   462             // Ignore case when valid tag is in wrong IFD and ENoTagChecking is set
       
   463             if ( !iExifCore->TagIsValid( tag->TagInfo(), aIfdType ) )
       
   464                 {
       
   465                 if ( iExifReadOption & CExifRead::ENoTagChecking )
       
   466                     {
       
   467                     LOGTEXT3( _L( "ExifLib: CExifReadImpl::ParseIfdL() keep tagId=0x%x in wrong aIfdType=0x%x" ), tagId, aIfdType );
       
   468                     iExifCore->InsertTagL( aIfdType, tag, EFalse );
       
   469                     CleanupStack::Pop( tag );
       
   470                     }
       
   471                 else
       
   472                     {
       
   473                     LOGTEXT3( _L( "ExifLib: CExifReadImpl::ParseIfdL() skipping tagId=0x%x in wrong aIfdType=0x%x" ), tagId, aIfdType );
       
   474                     CleanupStack::PopAndDestroy( tag );
       
   475                     }
       
   476                 }
       
   477             else // Tag is in correct IFD
       
   478                 {
       
   479                 if ( iExifReadOption & CExifRead::ENoTagChecking )
       
   480                     {
       
   481                     iExifCore->InsertTagL( aIfdType, tag, EFalse );
       
   482                     }
       
   483                 else
       
   484                     {
       
   485                     iExifCore->InsertTagL( aIfdType, tag, ETrue );
       
   486                     }
       
   487                 CleanupStack::Pop( tag );
       
   488                 }
       
   489             }
       
   490             
       
   491         }
       
   492     User::LeaveIfError( iReader->ReadUInt32( aNextIfdOffset ) );
       
   493     if ( tagsEndOffset )
       
   494         {
       
   495         User::LeaveIfError( iReader->MoveTo( tagsEndOffset ) );
       
   496         }
       
   497     if ( aIfdType == EIfd1 )
       
   498         {
       
   499         ParseThumbnailL();
       
   500         }
       
   501     LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseIfdL() returning" ) );
       
   502     }
       
   503 
       
   504 // -----------------------------------------------------------------------------
       
   505 // CExifReadImpl::ParseJpegDataL
       
   506 // Parses the Jpeg primary image data and initializes the Jpeg primary image 
       
   507 // structures.
       
   508 // -----------------------------------------------------------------------------
       
   509 //
       
   510 void CExifReadImpl::ParseJpegDataL()
       
   511     {
       
   512     LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseIfdL() entering" ) );
       
   513     if ( ( !iExifCore ) || ( !iReader ) )
       
   514         {
       
   515         LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseIfdL() Leave( KErrGeneral )" ) );
       
   516         User::Leave( KErrGeneral );
       
   517         }
       
   518 
       
   519     TUint32 jpgStartOffset = 0;
       
   520     TUint32 jpgStartOffset2 = 0;
       
   521     TUint32 jpgEndOffset = 0;
       
   522     TUint32 jpgEndOffset2 = 0;
       
   523     TUint32 jpgSofOffset = 0;
       
   524 
       
   525     // 1. Find the last 2 EOI markers.
       
   526     if ( iReader->LocateJpegMarkerFromEnd( KEoi, jpgEndOffset ) )
       
   527         {
       
   528         LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseIfdL() Leave( KErrCorrupt )LocateJpegMarkerFromEnd" ) );
       
   529         User::Leave( KErrCorrupt );
       
   530         }
       
   531 
       
   532     if ( iExifReadOption & CExifRead::EFastJpegParsing )
       
   533         {
       
   534         // Read current position after exif header parsing
       
   535     	iReader->CurrentPosOffset(jpgStartOffset);
       
   536     	
       
   537         // add start offset by 2 if exif header was not in image
       
   538         // SOI is in 0 position
       
   539         if ( !jpgStartOffset && jpgEndOffset )
       
   540             {
       
   541             jpgStartOffset += 2;
       
   542             }
       
   543         }
       
   544     else
       
   545         { // Scan the whole jpeg image data
       
   546         
       
   547         iReader->LocateJpegMarkerFromEnd( KEoi, jpgEndOffset2, 0, jpgEndOffset );
       
   548 
       
   549         // Assumption: There might be additional redundant EOI markers after the 
       
   550         // real EOI. Difference between two EOI marker is assumed to be 150 bytes.
       
   551         while( jpgEndOffset - jpgEndOffset2 < 150 ) 
       
   552             {
       
   553             jpgEndOffset = jpgEndOffset2;
       
   554             jpgEndOffset2 = 0;
       
   555             iReader->LocateJpegMarkerFromEnd( 
       
   556                 KEoi, jpgEndOffset2, 0, jpgEndOffset );
       
   557             }
       
   558 
       
   559         // 2. Find the SOF0 marker between the EOI markers.
       
   560         if ( iReader->LocateJpegMarker( 
       
   561             KSof0, jpgSofOffset, jpgEndOffset2, jpgEndOffset ) )
       
   562             {
       
   563             LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseIfdL() Leave( KErrNotSupported )LocateJpegMarker" ) );
       
   564             User::Leave( KErrNotSupported );
       
   565             }
       
   566 
       
   567         jpgStartOffset = jpgSofOffset;
       
   568 
       
   569         if ( (jpgStartOffset >= jpgEndOffset ) || 
       
   570             ( jpgStartOffset < jpgEndOffset2 ) )
       
   571             {
       
   572             LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseIfdL() Leave( KErrNotSupported )jpgStartOffset" ) );
       
   573             User::Leave( KErrNotSupported );
       
   574             }
       
   575 
       
   576         // 3. Find other Jpeg markers between the 2nd last EOI and the last 
       
   577         // SOF0 marker.
       
   578         if ( iReader->LocateJpegMarker( 
       
   579             KDqt, jpgStartOffset2, jpgEndOffset2, jpgStartOffset ) == KErrNone)
       
   580             {
       
   581             if ( jpgStartOffset2 < jpgStartOffset )
       
   582                 {
       
   583                 jpgStartOffset = jpgStartOffset2;
       
   584                 }
       
   585             }
       
   586 
       
   587         if ( iReader->LocateJpegMarker( 
       
   588             KDht, jpgStartOffset2, jpgEndOffset2, jpgStartOffset ) == KErrNone)
       
   589             {
       
   590             if ( jpgStartOffset2 < jpgStartOffset )
       
   591                 {
       
   592                 jpgStartOffset = jpgStartOffset2;
       
   593                 }
       
   594             }
       
   595 
       
   596         if ( iReader->LocateJpegMarker( 
       
   597             KDri, jpgStartOffset2, jpgEndOffset2, jpgStartOffset ) == KErrNone)
       
   598             {
       
   599             if ( jpgStartOffset2 < jpgStartOffset )
       
   600                 {
       
   601                 jpgStartOffset = jpgStartOffset2;
       
   602                 }
       
   603             }
       
   604         }
       
   605     // Should include the EOI marker.
       
   606     jpgEndOffset += 2;
       
   607 
       
   608     iExifCore->SetJpgOffsets( jpgStartOffset, jpgEndOffset );
       
   609     LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseIfdL() returning" ) );
       
   610     }
       
   611 
       
   612 // -----------------------------------------------------------------------------
       
   613 // CExifReadImpl::ParseThumbnailL
       
   614 // Parses the Jpeg thumbnail image data and initializes the Jpeg thumbnail 
       
   615 // structures.
       
   616 // -----------------------------------------------------------------------------
       
   617 //
       
   618 void CExifReadImpl::ParseThumbnailL()
       
   619     {
       
   620     LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseThumbnailL() entering" ) );
       
   621     if ( ( !iExifCore ) || ( !iReader ) )
       
   622         {
       
   623         LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseThumbnailL() Leave( KErrGeneral )" ) );
       
   624         User::Leave( KErrGeneral );
       
   625         }
       
   626 
       
   627     TUint32 thumbnailStart = 0;
       
   628     if ( iExifCore->GetThumbnailTagData( KIdJpegInterchangeFormat, 
       
   629         thumbnailStart ) )
       
   630         {
       
   631         LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseThumbnailL() Leave( KErrCorrupt )GetThumbnailTagData1" ) );
       
   632         User::Leave( KErrCorrupt );
       
   633         }
       
   634     TUint32 thumbnailSize = 0;
       
   635     if ( iExifCore->GetThumbnailTagData( KIdJpegInterchangeFormatLength, 
       
   636         thumbnailSize ) )
       
   637         {
       
   638         LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseThumbnailL() Leave( KErrCorrupt )GetThumbnailTagData2" ) );
       
   639         User::Leave( KErrCorrupt );
       
   640         }
       
   641     
       
   642     LOGTEXT3( _L( "ExifLib: CExifReadImpl::ParseThumbnailL() thumbnailStart=%d, thumbnailSize=%d" ), thumbnailStart, thumbnailSize );
       
   643     if ( thumbnailSize > KMaxApp1Size )
       
   644         {
       
   645         LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseThumbnailL() Leave( KErrCorrupt ) thumbnailSize > KMaxApp1Size" ) );
       
   646         User::Leave( KErrCorrupt );
       
   647         }
       
   648 
       
   649     iReader->MoveTo( thumbnailStart );
       
   650     HBufC8* buffer = HBufC8::NewLC( thumbnailSize );
       
   651     iReader->CopyBuffer( thumbnailSize, 1, buffer );
       
   652     iExifCore->InsertThumbnailL( buffer );
       
   653     CleanupStack::Pop();
       
   654     LOGTEXT( _L( "ExifLib: CExifReadImpl::ParseThumbnailL() returning" ) );
       
   655     }
       
   656 
       
   657 // -----------------------------------------------------------------------------
       
   658 // CExifReadImpl::ReadTagHeader
       
   659 // Reads the tag header, and returns the header information in the parameters.
       
   660 // -----------------------------------------------------------------------------
       
   661 //
       
   662 TInt CExifReadImpl::ReadTagHeader( 
       
   663     TUint16& aTagId, 
       
   664     TUint16& aTagType, 
       
   665     TUint32& aTagCount ) const
       
   666     {
       
   667     LOGTEXT4( _L( "ExifLib: CExifReadImpl::ReadTagHeader() entering: aTagId=0x%x, aTagType=0x%x, aTagCount=0x%x" ), aTagId, aTagType, aTagCount );
       
   668     if ( !iReader )
       
   669         {
       
   670         LOGTEXT( _L( "ExifLib: CExifReadImpl::ReadTagHeader() returning KErrGeneral" ) );
       
   671         return KErrGeneral;
       
   672         }
       
   673 
       
   674     TInt error = iReader->ReadUInt16( aTagId );
       
   675     if ( error )
       
   676         {
       
   677         LOGTEXT2( _L( "ExifLib: CExifReadImpl::ReadTagHeader() returning aTagId error=%d" ),error );
       
   678         return error;
       
   679         }
       
   680     error = iReader->ReadUInt16( aTagType );
       
   681     if ( error )
       
   682         {
       
   683         LOGTEXT2( _L( "ExifLib: CExifReadImpl::ReadTagHeader() returning aTagType error=%d" ),error );
       
   684         return error;
       
   685         }
       
   686     error = iReader->ReadUInt32( aTagCount );
       
   687     if ( error )
       
   688         {
       
   689         LOGTEXT2( _L( "ExifLib: CExifReadImpl::ReadTagHeader() returning aTagCount error=%d" ),error );
       
   690         return error;
       
   691         }
       
   692     LOGTEXT( _L( "ExifLib: CExifReadImpl::ReadTagHeader() returning" ) );
       
   693     return KErrNone;
       
   694     }
       
   695 
       
   696 // -----------------------------------------------------------------------------
       
   697 // CExifReadImpl::GetImageDescriptionL
       
   698 // Gets the Image Description tag data.
       
   699 // -----------------------------------------------------------------------------
       
   700 //
       
   701 HBufC8* CExifReadImpl::GetImageDescriptionL() const
       
   702     {
       
   703     if ( !iExifCore )
       
   704         {
       
   705         User::Leave( KErrGeneral );
       
   706         }
       
   707 
       
   708     return iExifCore->GetTagDataL( KIdImageDescription );
       
   709     }
       
   710 
       
   711 // -----------------------------------------------------------------------------
       
   712 // CExifReadImpl::GetMakeL
       
   713 // Gets the Make tag data.
       
   714 // -----------------------------------------------------------------------------
       
   715 //
       
   716 HBufC8* CExifReadImpl::GetMakeL() const
       
   717     {
       
   718     if ( !iExifCore )
       
   719         {
       
   720         User::Leave( KErrGeneral );
       
   721         }
       
   722 
       
   723     return iExifCore->GetTagDataL( KIdMake );
       
   724     }
       
   725 
       
   726 // -----------------------------------------------------------------------------
       
   727 // CExifReadImpl::GetModelL
       
   728 // Gets the Model tag data.
       
   729 // -----------------------------------------------------------------------------
       
   730 //
       
   731 HBufC8* CExifReadImpl::GetModelL() const
       
   732     {
       
   733     if ( !iExifCore )
       
   734         {
       
   735         User::Leave( KErrGeneral );
       
   736         }
       
   737 
       
   738     return iExifCore->GetTagDataL( KIdModel );
       
   739     }
       
   740 
       
   741 // -----------------------------------------------------------------------------
       
   742 // CExifReadImpl::GetOrientation
       
   743 // Gets the Orientation tag data.
       
   744 // -----------------------------------------------------------------------------
       
   745 //
       
   746 TInt CExifReadImpl::GetOrientation( TUint16& aOrientation ) const
       
   747     {
       
   748     if ( !iExifCore )
       
   749         {
       
   750         return KErrGeneral;
       
   751         }
       
   752 
       
   753     return iExifCore->GetTagData( KIdOrientation, aOrientation );
       
   754     }
       
   755 
       
   756 // -----------------------------------------------------------------------------
       
   757 // CExifReadImpl::GetXResolution
       
   758 // Gets the X Resolution tag data.
       
   759 // -----------------------------------------------------------------------------
       
   760 //
       
   761 TInt CExifReadImpl::GetXResolution( 
       
   762     TUint32& aXResolutionNumerator, 
       
   763     TUint32& aXResolutionDenumerator ) const
       
   764     {
       
   765     if ( !iExifCore )
       
   766         {
       
   767         return KErrGeneral;
       
   768         }
       
   769 
       
   770     return iExifCore->GetTagData( KIdXResolution, 
       
   771         aXResolutionNumerator, aXResolutionDenumerator );
       
   772     }
       
   773 
       
   774 // -----------------------------------------------------------------------------
       
   775 // CExifReadImpl::GetYResolution
       
   776 // Gets the Y Resolution tag data.
       
   777 // -----------------------------------------------------------------------------
       
   778 //
       
   779 TInt CExifReadImpl::GetYResolution( 
       
   780     TUint32& aYResolutionNumerator, 
       
   781     TUint32& aYResolutionDenumerator ) const        
       
   782     {
       
   783     if ( !iExifCore )
       
   784         {
       
   785         return KErrGeneral;
       
   786         }
       
   787 
       
   788     return iExifCore->GetTagData( KIdYResolution, 
       
   789         aYResolutionNumerator, aYResolutionDenumerator );
       
   790     }
       
   791 
       
   792 // -----------------------------------------------------------------------------
       
   793 // CExifReadImpl::GetResolutionUnit
       
   794 // Gets the Resolution Unit tag data.
       
   795 // -----------------------------------------------------------------------------
       
   796 //
       
   797 TInt CExifReadImpl::GetResolutionUnit( TUint16& aResolutionUnit ) const
       
   798     {
       
   799     if ( !iExifCore )
       
   800         {
       
   801         return KErrGeneral;
       
   802         }
       
   803 
       
   804     return iExifCore->GetTagData( KIdResolutionUnit, aResolutionUnit );
       
   805     }
       
   806 
       
   807 // -----------------------------------------------------------------------------
       
   808 // CExifReadImpl::GetTransferFunctionL
       
   809 // Gets the Transfer Function tag data.
       
   810 // -----------------------------------------------------------------------------
       
   811 //
       
   812 HBufC8* CExifReadImpl::GetTransferFunctionL() const
       
   813     {
       
   814     if ( !iExifCore )
       
   815         {
       
   816         User::Leave( KErrGeneral );
       
   817         }
       
   818 
       
   819     return iExifCore->GetTagDataL( KIdTransferFunction );
       
   820     }
       
   821 
       
   822 // -----------------------------------------------------------------------------
       
   823 // CExifReadImpl::GetDateTimeL
       
   824 // Gets the Date Time tag data.
       
   825 // -----------------------------------------------------------------------------
       
   826 //
       
   827 HBufC8* CExifReadImpl::GetDateTimeL() const
       
   828     {
       
   829     if ( !iExifCore )
       
   830         {
       
   831         User::Leave( KErrGeneral );
       
   832         }
       
   833 
       
   834     return iExifCore->GetTagDataL( KIdDateTime );
       
   835     }
       
   836 
       
   837 // -----------------------------------------------------------------------------
       
   838 // CExifReadImpl::GetYCbCrPositioning
       
   839 // Gets the YCbCr Positioning tag data.
       
   840 // -----------------------------------------------------------------------------
       
   841 //
       
   842 TInt CExifReadImpl::GetYCbCrPositioning( TUint16& aYCbCrPositioning ) const
       
   843     {
       
   844     if ( !iExifCore )
       
   845         {
       
   846         return KErrGeneral;
       
   847         }
       
   848 
       
   849     return iExifCore->GetTagData( KIdYCbCrPositioning, aYCbCrPositioning );
       
   850     }
       
   851 
       
   852 // -----------------------------------------------------------------------------
       
   853 // CExifReadImpl::GetSoftwareL
       
   854 // Gets the Software tag data.
       
   855 // -----------------------------------------------------------------------------
       
   856 //
       
   857 HBufC8* CExifReadImpl::GetSoftwareL() const
       
   858     {
       
   859     if ( !iExifCore )
       
   860         {
       
   861         User::Leave( KErrGeneral );
       
   862         }
       
   863 
       
   864     return iExifCore->GetTagDataL( KIdSoftware );
       
   865     }
       
   866 
       
   867 // -----------------------------------------------------------------------------
       
   868 // CExifReadImpl::GetCopyrightL
       
   869 // Gets the Copyright tag data.
       
   870 // -----------------------------------------------------------------------------
       
   871 //
       
   872 HBufC8* CExifReadImpl::GetCopyrightL() const
       
   873     {
       
   874     if ( !iExifCore )
       
   875         {
       
   876         User::Leave( KErrGeneral );
       
   877         }
       
   878 
       
   879     return iExifCore->GetTagDataL( KIdCopyright );
       
   880     }
       
   881 
       
   882 // -----------------------------------------------------------------------------
       
   883 // CExifReadImpl::GetExifIfdPointer
       
   884 // Gets the Exif Ifd Pointer tag data.
       
   885 // -----------------------------------------------------------------------------
       
   886 //
       
   887 TInt CExifReadImpl::GetExifIfdPointer( TUint32& aExifIfdPointer ) const
       
   888     {
       
   889     if ( !iExifCore )
       
   890         {
       
   891         return KErrGeneral;
       
   892         }
       
   893 
       
   894     return iExifCore->GetTagData( KIdExifIfdPointer, aExifIfdPointer );
       
   895     }
       
   896 
       
   897 // -----------------------------------------------------------------------------
       
   898 // CExifReadImpl::GetGpsInfoIfdPointer
       
   899 // Gets the Gps Ifd Pointer tag data.
       
   900 // -----------------------------------------------------------------------------
       
   901 //
       
   902 TInt CExifReadImpl::GetGpsInfoIfdPointer( TUint32& aGpsInfoIfdPointer ) const
       
   903     {
       
   904     if ( !iExifCore )
       
   905         {
       
   906         return KErrGeneral;
       
   907         }
       
   908 
       
   909     return iExifCore->GetTagData( KIdGpsIfdPointer, aGpsInfoIfdPointer );
       
   910     }
       
   911 
       
   912 // -----------------------------------------------------------------------------
       
   913 // CExifReadImpl::GetExposureTime
       
   914 // Gets the Exposure Time tag data.
       
   915 // -----------------------------------------------------------------------------
       
   916 //
       
   917 TInt CExifReadImpl::GetExposureTime( 
       
   918     TUint32& aExposureTime1, 
       
   919     TUint32& aExposureTime2 ) const
       
   920     {
       
   921     if ( !iExifCore )
       
   922         {
       
   923         return KErrGeneral;
       
   924         }
       
   925 
       
   926     return iExifCore->GetTagData( KIdExposureTime, 
       
   927         aExposureTime1, aExposureTime2 );
       
   928     }
       
   929 
       
   930 // -----------------------------------------------------------------------------
       
   931 // CExifReadImpl::GetComponentsConfiguration
       
   932 // Gets the Components Configuration tag data.
       
   933 // -----------------------------------------------------------------------------
       
   934 //
       
   935 TInt CExifReadImpl::GetComponentsConfiguration( 
       
   936     TUint8& aFirstComponent, TUint8& aSecondComponent,
       
   937     TUint8& aThirdComponent, TUint8& aFourthComponent) const 
       
   938     {
       
   939     if ( !iExifCore )
       
   940         {
       
   941         return KErrGeneral;
       
   942         }
       
   943 
       
   944     TUint32 componentsConfiguration = 0;
       
   945 
       
   946     TInt error = iExifCore->GetTagData( KIdComponentsConfiguration, 
       
   947         componentsConfiguration );
       
   948     if ( error )
       
   949         {
       
   950         return error;
       
   951         }
       
   952     aFirstComponent = STATIC_CAST ( TUint8, 
       
   953         ( KOneByteMask & componentsConfiguration ) );
       
   954     aSecondComponent = STATIC_CAST ( TUint8, 
       
   955         ( KOneByteMask & ( componentsConfiguration >> 8 ) ) );
       
   956     aThirdComponent = STATIC_CAST ( TUint8, 
       
   957         ( KOneByteMask & ( componentsConfiguration >> 16 ) ) );
       
   958     aFourthComponent = STATIC_CAST ( TUint8, 
       
   959         ( KOneByteMask & ( componentsConfiguration >> 24 ) ) );
       
   960     return KErrNone;
       
   961     }
       
   962 
       
   963 // -----------------------------------------------------------------------------
       
   964 // CExifReadImpl::GetFlash
       
   965 // Gets the Flash tag data.
       
   966 // -----------------------------------------------------------------------------
       
   967 //
       
   968 TInt CExifReadImpl::GetFlash( TUint16& aFlash ) const
       
   969     {
       
   970     if ( !iExifCore )
       
   971         {
       
   972         return KErrGeneral;
       
   973         }
       
   974 
       
   975     return iExifCore->GetTagData( KIdFlash, aFlash );
       
   976     }
       
   977 
       
   978 // -----------------------------------------------------------------------------
       
   979 // CExifReadImpl::GetColorSpace
       
   980 // Gets the Color Space tag data.
       
   981 // -----------------------------------------------------------------------------
       
   982 //
       
   983 TInt CExifReadImpl::GetColorSpace( TUint16& aColorSpace ) const
       
   984     {
       
   985     if ( !iExifCore )
       
   986         {
       
   987         return KErrGeneral;
       
   988         }
       
   989 
       
   990     return iExifCore->GetTagData( KIdColorSpace, aColorSpace );
       
   991     }
       
   992 
       
   993 // -----------------------------------------------------------------------------
       
   994 // CExifReadImpl::GetPixelXDimension
       
   995 // Gets the Pixel X Dimension tag data.
       
   996 // -----------------------------------------------------------------------------
       
   997 //
       
   998 TInt CExifReadImpl::GetPixelXDimension( TUint32& aPixelXDimension ) const
       
   999     {
       
  1000     if ( !iExifCore )
       
  1001         {
       
  1002         return KErrGeneral;
       
  1003         }
       
  1004 
       
  1005     return iExifCore->GetTagData( KIdPixelXDimension, aPixelXDimension );
       
  1006     }
       
  1007 
       
  1008 // -----------------------------------------------------------------------------
       
  1009 // CExifReadImpl::GetPixelYDimension
       
  1010 // Gets the Pixel Y Dimension tag data.
       
  1011 // -----------------------------------------------------------------------------
       
  1012 //
       
  1013 TInt CExifReadImpl::GetPixelYDimension( TUint32& aPixelYDimension ) const
       
  1014     {
       
  1015     if ( !iExifCore )
       
  1016         {
       
  1017         return KErrGeneral;
       
  1018         }
       
  1019 
       
  1020     return iExifCore->GetTagData( KIdPixelYDimension, aPixelYDimension );
       
  1021     }
       
  1022 
       
  1023 // -----------------------------------------------------------------------------
       
  1024 // CExifReadImpl::GetExposureMode
       
  1025 // Gets the Exposure Mode tag data.
       
  1026 // -----------------------------------------------------------------------------
       
  1027 //
       
  1028 TInt CExifReadImpl::GetExposureMode( TUint16& aExposureMode ) const
       
  1029     {
       
  1030     if ( !iExifCore )
       
  1031         {
       
  1032         return KErrGeneral;
       
  1033         }
       
  1034 
       
  1035     return iExifCore->GetTagData( KIdExposureMode, aExposureMode );
       
  1036     }
       
  1037 
       
  1038 // -----------------------------------------------------------------------------
       
  1039 // CExifReadImpl::GetWhiteBalance
       
  1040 // Gets the White Balance tag data.
       
  1041 // -----------------------------------------------------------------------------
       
  1042 //
       
  1043 TInt CExifReadImpl::GetWhiteBalance( TUint16& aWhiteBalance ) const
       
  1044     {
       
  1045     if ( !iExifCore )
       
  1046         {
       
  1047         return KErrGeneral;
       
  1048         }
       
  1049 
       
  1050     return iExifCore->GetTagData( KIdWhiteBalance, aWhiteBalance );
       
  1051     }
       
  1052 
       
  1053 // -----------------------------------------------------------------------------
       
  1054 // CExifReadImpl::GetSceneCaptureType
       
  1055 // Gets the Scene Capture Type tag data.
       
  1056 // -----------------------------------------------------------------------------
       
  1057 //
       
  1058 TInt CExifReadImpl::GetSceneCaptureType( TUint16& aSceneCaptureType ) const
       
  1059     {
       
  1060     if ( !iExifCore )
       
  1061         {
       
  1062         return KErrGeneral;
       
  1063         }
       
  1064 
       
  1065     return iExifCore->GetTagData( KIdSceneCaptureType, aSceneCaptureType );
       
  1066     }
       
  1067 
       
  1068 // -----------------------------------------------------------------------------
       
  1069 // CExifReadImpl::GetExposureProgram
       
  1070 // Gets the Exposure Program tag data.
       
  1071 // -----------------------------------------------------------------------------
       
  1072 //
       
  1073 TInt CExifReadImpl::GetExposureProgram( TUint16& aExposureProgram ) const
       
  1074     {
       
  1075     if ( !iExifCore )
       
  1076         {
       
  1077         return KErrGeneral;
       
  1078         }
       
  1079 
       
  1080     return iExifCore->GetTagData( KIdExposureProgram, aExposureProgram );
       
  1081     }
       
  1082 
       
  1083 // -----------------------------------------------------------------------------
       
  1084 // CExifReadImpl::GetIsoSpeedRatingsL
       
  1085 // Gets the Iso Speed Ratings tag data.
       
  1086 // -----------------------------------------------------------------------------
       
  1087 //
       
  1088 HBufC8* CExifReadImpl::GetIsoSpeedRatingsL() const
       
  1089     {
       
  1090     if ( !iExifCore )
       
  1091         {
       
  1092         User::Leave( KErrGeneral );
       
  1093         }
       
  1094 
       
  1095     return iExifCore->GetTagDataL( KIdIsoSpeedRatings );
       
  1096     }
       
  1097 
       
  1098 // -----------------------------------------------------------------------------
       
  1099 // CExifReadImpl::GetDateTimeOriginalL
       
  1100 // Gets the Date Time Original tag data.
       
  1101 // -----------------------------------------------------------------------------
       
  1102 //
       
  1103 HBufC8* CExifReadImpl::GetDateTimeOriginalL() const
       
  1104     {
       
  1105     if ( !iExifCore )
       
  1106         {
       
  1107         User::Leave( KErrGeneral );
       
  1108         }
       
  1109 
       
  1110     return iExifCore->GetTagDataL( KIdDateTimeOriginal );
       
  1111     }
       
  1112 
       
  1113 // -----------------------------------------------------------------------------
       
  1114 // CExifReadImpl::GetDateTimeDigitizedL
       
  1115 // Gets the Date Time Digitized tag data.
       
  1116 // -----------------------------------------------------------------------------
       
  1117 //
       
  1118 HBufC8* CExifReadImpl::GetDateTimeDigitizedL() const
       
  1119     {
       
  1120     if ( !iExifCore )
       
  1121         {
       
  1122         User::Leave( KErrGeneral );
       
  1123         }
       
  1124 
       
  1125     return iExifCore->GetTagDataL( KIdDateTimeDigitized );
       
  1126     }
       
  1127 
       
  1128 // -----------------------------------------------------------------------------
       
  1129 // CExifReadImpl::GetApertureValue
       
  1130 // Gets the Aperture Value tag data.
       
  1131 // -----------------------------------------------------------------------------
       
  1132 //
       
  1133 TInt CExifReadImpl::GetApertureValue( 
       
  1134     TUint32& aApertureValue1, 
       
  1135     TUint32& aApertureValue2 ) const
       
  1136     {
       
  1137     if ( !iExifCore )
       
  1138         {
       
  1139         return KErrGeneral;
       
  1140         }
       
  1141 
       
  1142     return iExifCore->GetTagData( KIdApertureValue, 
       
  1143         aApertureValue1, aApertureValue2 );
       
  1144     }
       
  1145 
       
  1146 // -----------------------------------------------------------------------------
       
  1147 // CExifReadImpl::GetExposureBiasValue
       
  1148 // Gets the Exposure Bias Value tag data.
       
  1149 // -----------------------------------------------------------------------------
       
  1150 //
       
  1151 TInt CExifReadImpl::GetExposureBiasValue( 
       
  1152     TInt32& aExposureBiasValue1, 
       
  1153     TInt32& aExposureBiasValue2 ) const
       
  1154     {
       
  1155     if ( !iExifCore )
       
  1156         {
       
  1157         return KErrGeneral;
       
  1158         }
       
  1159 
       
  1160     return iExifCore->GetTagData( KIdExposureBiasValue, 
       
  1161         aExposureBiasValue1, aExposureBiasValue2 );
       
  1162     }
       
  1163 
       
  1164 // -----------------------------------------------------------------------------
       
  1165 // CExifReadImpl::GetMeteringMode
       
  1166 // Gets the Metering Mode tag data.
       
  1167 // -----------------------------------------------------------------------------
       
  1168 //
       
  1169 TInt CExifReadImpl::GetMeteringMode( TUint16& aMeteringMode ) const
       
  1170     {
       
  1171     if ( !iExifCore )
       
  1172         {
       
  1173         return KErrGeneral;
       
  1174         }
       
  1175 
       
  1176     return iExifCore->GetTagData( KIdMeteringMode, aMeteringMode );
       
  1177     }
       
  1178 
       
  1179 // -----------------------------------------------------------------------------
       
  1180 // CExifReadImpl::GetLightSource
       
  1181 // Gets the Light Source tag data.
       
  1182 // -----------------------------------------------------------------------------
       
  1183 //
       
  1184 TInt CExifReadImpl::GetLightSource( TUint16& aLightSource ) const
       
  1185     {
       
  1186     if ( !iExifCore )
       
  1187         {
       
  1188         return KErrGeneral;
       
  1189         }
       
  1190 
       
  1191     return iExifCore->GetTagData( KIdLightSource, aLightSource );
       
  1192     }
       
  1193 
       
  1194 // -----------------------------------------------------------------------------
       
  1195 // CExifReadImpl::GetMakerNoteL
       
  1196 // Gets the Maker Note tag data.
       
  1197 // -----------------------------------------------------------------------------
       
  1198 //
       
  1199 HBufC8* CExifReadImpl::GetMakerNoteL() const
       
  1200     {
       
  1201     if ( !iExifCore )
       
  1202         {
       
  1203         User::Leave( KErrGeneral );
       
  1204         }
       
  1205 
       
  1206     return iExifCore->GetTagDataL( KIdMakerNote );
       
  1207     }
       
  1208 
       
  1209 // -----------------------------------------------------------------------------
       
  1210 // CExifReadImpl::GetUserCommentL
       
  1211 // Gets the User Comment tag data.
       
  1212 // -----------------------------------------------------------------------------
       
  1213 //
       
  1214 HBufC8* CExifReadImpl::GetUserCommentL() const
       
  1215     {
       
  1216     if ( !iExifCore )
       
  1217         {
       
  1218         User::Leave( KErrGeneral );
       
  1219         }
       
  1220 
       
  1221     return iExifCore->GetTagDataL( KIdUserComment );
       
  1222     }
       
  1223 
       
  1224 // -----------------------------------------------------------------------------
       
  1225 // CExifReadImpl::GetRelatedSoundFileL
       
  1226 // Gets the Related Sound File tag data.
       
  1227 // -----------------------------------------------------------------------------
       
  1228 //
       
  1229 HBufC8* CExifReadImpl::GetRelatedSoundFileL() const
       
  1230 
       
  1231     {
       
  1232     if ( !iExifCore )
       
  1233         {
       
  1234         User::Leave( KErrGeneral );
       
  1235         }
       
  1236 
       
  1237     return iExifCore->GetTagDataL( KIdRelatedSoundFile );
       
  1238     }
       
  1239 
       
  1240 // -----------------------------------------------------------------------------
       
  1241 // CExifReadImpl::GetFileSource
       
  1242 // Gets the File Source tag data.
       
  1243 // -----------------------------------------------------------------------------
       
  1244 //
       
  1245 TInt CExifReadImpl::GetFileSource( TInt8& aFileSource ) const
       
  1246     {
       
  1247     if ( !iExifCore )
       
  1248         {
       
  1249         return KErrGeneral;
       
  1250         }
       
  1251 
       
  1252     return iExifCore->GetTagData( KIdFileSource, aFileSource );
       
  1253     }
       
  1254 
       
  1255 // -----------------------------------------------------------------------------
       
  1256 // CExifReadImpl::GetDigitalZoomRatio
       
  1257 // Gets the Digital Zoom Ratio tag data.
       
  1258 // -----------------------------------------------------------------------------
       
  1259 //
       
  1260 TInt CExifReadImpl::GetDigitalZoomRatio( 
       
  1261     TUint32& aDigitalZoomRatio1, 
       
  1262     TUint32& aDigitalZoomRatio2 ) const
       
  1263     {
       
  1264     if ( !iExifCore )
       
  1265         {
       
  1266         return KErrGeneral;
       
  1267         }
       
  1268 
       
  1269     return iExifCore->GetTagData( KIdDigitalZoomRatio, 
       
  1270         aDigitalZoomRatio1, aDigitalZoomRatio2 );
       
  1271     }
       
  1272 
       
  1273 // -----------------------------------------------------------------------------
       
  1274 // CExifReadImpl::GetContrast
       
  1275 // Gets the Contrast tag data.
       
  1276 // -----------------------------------------------------------------------------
       
  1277 //
       
  1278 TInt CExifReadImpl::GetContrast( TUint16& aContrast ) const
       
  1279     {
       
  1280     if ( !iExifCore )
       
  1281         {
       
  1282         return KErrGeneral;
       
  1283         }
       
  1284 
       
  1285     return iExifCore->GetTagData( KIdContrast, aContrast );
       
  1286     }
       
  1287 
       
  1288 // -----------------------------------------------------------------------------
       
  1289 // CExifReadImpl::GetSaturation
       
  1290 // Gets the Saturation tag data.
       
  1291 // -----------------------------------------------------------------------------
       
  1292 //
       
  1293 TInt CExifReadImpl::GetSaturation( TUint16& aSaturation ) const
       
  1294     {
       
  1295     if ( !iExifCore )
       
  1296         {
       
  1297         return KErrGeneral;
       
  1298         }
       
  1299 
       
  1300     return iExifCore->GetTagData( KIdSaturation, aSaturation );
       
  1301     }
       
  1302 
       
  1303 // -----------------------------------------------------------------------------
       
  1304 // CExifReadImpl::GetSharpness
       
  1305 // Gets the Sharpness tag data.
       
  1306 // -----------------------------------------------------------------------------
       
  1307 //
       
  1308 TInt CExifReadImpl::GetSharpness( TUint16& aSharpness ) const
       
  1309     {
       
  1310     if ( !iExifCore )
       
  1311         {
       
  1312         return KErrGeneral;
       
  1313         }
       
  1314 
       
  1315     return iExifCore->GetTagData( KIdSharpness, aSharpness );
       
  1316     }
       
  1317 
       
  1318 // -----------------------------------------------------------------------------
       
  1319 // CExifReadImpl::GetExifVersion
       
  1320 // Gets the Exif Version tag data.
       
  1321 // -----------------------------------------------------------------------------
       
  1322 //
       
  1323 TInt CExifReadImpl::GetExifVersion( TUint32& aExifVersion ) const
       
  1324     {
       
  1325     if ( !iExifCore )
       
  1326         {
       
  1327         return KErrGeneral;
       
  1328         }
       
  1329 
       
  1330     return iExifCore->GetTagData( KIdExifVersion, aExifVersion );
       
  1331     }
       
  1332 
       
  1333 // -----------------------------------------------------------------------------
       
  1334 // CExifReadImpl::GetFlashPixVersion
       
  1335 // Gets the Flash Pix Version tag data.
       
  1336 // -----------------------------------------------------------------------------
       
  1337 //
       
  1338 TInt CExifReadImpl::GetFlashPixVersion( TUint32& aFlashPixVersion ) const
       
  1339     {
       
  1340     if ( !iExifCore )
       
  1341         {
       
  1342         return KErrGeneral;
       
  1343         }
       
  1344 
       
  1345     return iExifCore->GetTagData( KIdFlashPixVersion, aFlashPixVersion );
       
  1346     }
       
  1347 
       
  1348 // -----------------------------------------------------------------------------
       
  1349 // CExifReadImpl::GetInteroperabilityIfdPointer
       
  1350 // Gets the Interoperability Ifd Pointer tag data.
       
  1351 // -----------------------------------------------------------------------------
       
  1352 //
       
  1353 TInt CExifReadImpl::GetInteroperabilityIfdPointer( 
       
  1354     TUint32& aInteroperabilityIfdPointer ) const
       
  1355     {
       
  1356     if ( !iExifCore )
       
  1357         {
       
  1358         return KErrGeneral;
       
  1359         }
       
  1360 
       
  1361     return iExifCore->GetTagData( KIdIntOpIfdPointer, 
       
  1362         aInteroperabilityIfdPointer );
       
  1363     }
       
  1364 
       
  1365 // -----------------------------------------------------------------------------
       
  1366 // CExifReadImpl::GetThumbnailXResolution
       
  1367 // Gets the X Resolution tag data of thumbnail.
       
  1368 // -----------------------------------------------------------------------------
       
  1369 //
       
  1370 TInt CExifReadImpl::GetThumbnailXResolution( 
       
  1371     TUint32& aXResolution1, 
       
  1372     TUint32& aXResolution2 ) const
       
  1373     {
       
  1374     if ( !iExifCore )
       
  1375         {
       
  1376         return KErrGeneral;
       
  1377         }
       
  1378 
       
  1379     return iExifCore->GetThumbnailTagData( KIdXResolution, 
       
  1380         aXResolution1, aXResolution2 );
       
  1381     }
       
  1382 
       
  1383 // -----------------------------------------------------------------------------
       
  1384 // CExifReadImpl::GetThumbnailYResolution
       
  1385 // Gets the Y Resolution tag data of thumbnail.
       
  1386 // -----------------------------------------------------------------------------
       
  1387 //
       
  1388 TInt CExifReadImpl::GetThumbnailYResolution( 
       
  1389     TUint32& aYResolution1, 
       
  1390     TUint32& aYResolution2 ) const
       
  1391     {
       
  1392     if ( !iExifCore )
       
  1393         {
       
  1394         return KErrGeneral;
       
  1395         }
       
  1396 
       
  1397     return iExifCore->GetThumbnailTagData( KIdYResolution, 
       
  1398         aYResolution1, 
       
  1399         aYResolution2 );
       
  1400     }
       
  1401 
       
  1402 // -----------------------------------------------------------------------------
       
  1403 // CExifReadImpl::GetThumbnailResolutionUnit
       
  1404 // Gets the ResolutionUnit tag data of thumbnail.
       
  1405 // -----------------------------------------------------------------------------
       
  1406 //
       
  1407 TInt CExifReadImpl::GetThumbnailResolutionUnit( TUint16& aResolutionUnit ) const
       
  1408     {
       
  1409     if ( !iExifCore )
       
  1410         {
       
  1411         return KErrGeneral;
       
  1412         }
       
  1413 
       
  1414     return iExifCore->GetThumbnailTagData( KIdResolutionUnit, aResolutionUnit );
       
  1415     }
       
  1416 
       
  1417 // -----------------------------------------------------------------------------
       
  1418 // CExifReadImpl::GetThumbnailCompression
       
  1419 // Gets the Compression tag data of thumbnail.
       
  1420 // -----------------------------------------------------------------------------
       
  1421 //
       
  1422 TInt CExifReadImpl::GetThumbnailCompression( TUint16& aCompression ) const
       
  1423     {
       
  1424     if ( !iExifCore )
       
  1425         {
       
  1426         return KErrGeneral;
       
  1427         }
       
  1428 
       
  1429     return iExifCore->GetThumbnailTagData( KIdCompression, aCompression );
       
  1430     }
       
  1431 
       
  1432 // -----------------------------------------------------------------------------
       
  1433 // CExifReadImpl::GetJpegInterchangeFormat
       
  1434 // Gets the Jpeg Interchange Format of thumbnail.
       
  1435 // -----------------------------------------------------------------------------
       
  1436 //
       
  1437 TInt CExifReadImpl::GetJpegInterchangeFormat( 
       
  1438     TUint32& aJpegInterchangeFormat ) const
       
  1439     {
       
  1440     if ( !iExifCore )
       
  1441         {
       
  1442         return KErrGeneral;
       
  1443         }
       
  1444 
       
  1445     return iExifCore->GetThumbnailTagData( KIdJpegInterchangeFormat, 
       
  1446         aJpegInterchangeFormat );
       
  1447     }
       
  1448 
       
  1449 // -----------------------------------------------------------------------------
       
  1450 // CExifReadImpl::GetJpegInterchangeFormatLength
       
  1451 // Gets the Jpeg Interchange Format Length of thumbnail.
       
  1452 // -----------------------------------------------------------------------------
       
  1453 //
       
  1454 TInt CExifReadImpl::GetJpegInterchangeFormatLength( 
       
  1455     TUint32& aJpegInterchangeFormatLength ) const
       
  1456     {
       
  1457     if ( !iExifCore )
       
  1458         {
       
  1459         return KErrGeneral;
       
  1460         }
       
  1461 
       
  1462     return iExifCore->GetThumbnailTagData( KIdJpegInterchangeFormatLength, 
       
  1463         aJpegInterchangeFormatLength );
       
  1464     }
       
  1465 
       
  1466 // -----------------------------------------------------------------------------
       
  1467 // CExifReadImpl::GetExifAppSegmentL
       
  1468 // Returns a copy of whole Exif APP1 segment in a descriptor.
       
  1469 // -----------------------------------------------------------------------------
       
  1470 HBufC8* CExifReadImpl::GetExifAppSegmentL() const
       
  1471     {
       
  1472     if ( !iExifCore )
       
  1473         {
       
  1474         User::Leave( KErrGeneral );
       
  1475         }
       
  1476 
       
  1477     User::LeaveIfError( iExifCore->Finalize() );    
       
  1478 
       
  1479     if ( !iExifCore->IsValid() )
       
  1480         {
       
  1481         User::Leave( KErrNotReady );
       
  1482         }
       
  1483 
       
  1484     TUint size = iExifCore->App1Size();
       
  1485     size+=2;
       
  1486     // Allocation amount is even for 2-byte alignment
       
  1487     HBufC8* exifData = HBufC8::NewLC( size + ( size % 2 ) );
       
  1488     exifData->Des().SetLength( size + ( size % 2 ) );
       
  1489     TUint pos = 0;
       
  1490     iExifCore->WriteExifDataL( exifData, pos );
       
  1491     exifData->Des().SetLength( size );
       
  1492     CleanupStack::Pop( exifData );
       
  1493     return exifData;
       
  1494     }
       
  1495 
       
  1496 // -----------------------------------------------------------------------------
       
  1497 // CExifReadImpl::GetShutterSpeedValue
       
  1498 // Gets the Shutter Speed Value tag data.
       
  1499 // -----------------------------------------------------------------------------
       
  1500 //
       
  1501 TInt CExifReadImpl::GetShutterSpeedValue( 
       
  1502     TInt32& aShutterSpeedValue1, 
       
  1503     TInt32& aShutterSpeedValue2 ) const
       
  1504     {
       
  1505     if ( !iExifCore )
       
  1506         {
       
  1507         return KErrGeneral;
       
  1508         }
       
  1509 
       
  1510     return iExifCore->GetTagData( KIdShutterSpeedValue, aShutterSpeedValue1, 
       
  1511         aShutterSpeedValue2 );
       
  1512     }
       
  1513 
       
  1514 // -----------------------------------------------------------------------------
       
  1515 // CExifReadImpl::GetBrightnessSpeedValue
       
  1516 // Gets the Brightness Value tag data.
       
  1517 // -----------------------------------------------------------------------------
       
  1518 //
       
  1519 TInt CExifReadImpl::GetBrightnessValue( 
       
  1520     TInt32& aBrightnessValue1, 
       
  1521     TInt32& aBrightnessValue2 ) const
       
  1522     {
       
  1523     if ( !iExifCore )
       
  1524         {
       
  1525         return KErrGeneral;
       
  1526         }
       
  1527 
       
  1528     return iExifCore->GetTagData( KIdBrightnessValue, aBrightnessValue1, 
       
  1529         aBrightnessValue2 );
       
  1530     }
       
  1531 
       
  1532 // -----------------------------------------------------------------------------
       
  1533 // CExifReadImpl::GetCustomRendered
       
  1534 // Gets the Custom Rendered tag data.
       
  1535 // -----------------------------------------------------------------------------
       
  1536 //
       
  1537 TInt CExifReadImpl::GetCustomRendered( TUint16& aCustomRendered ) const
       
  1538     {
       
  1539     if ( !iExifCore )
       
  1540         {
       
  1541         return KErrGeneral;
       
  1542         }
       
  1543 
       
  1544     return iExifCore->GetTagData( KIdCustomRendered, aCustomRendered );
       
  1545     }
       
  1546 
       
  1547 // -----------------------------------------------------------------------------
       
  1548 // CExifReadImpl::GetGainControl
       
  1549 // Gets the Gain Control tag data.
       
  1550 // -----------------------------------------------------------------------------
       
  1551 //
       
  1552 TInt CExifReadImpl::GetGainControl( TUint16& aGainControl ) const
       
  1553     {
       
  1554     if ( !iExifCore )
       
  1555         {
       
  1556         return KErrGeneral;
       
  1557         }
       
  1558 
       
  1559     return iExifCore->GetTagData( KIdGainControl, aGainControl );
       
  1560     }
       
  1561 
       
  1562 // -----------------------------------------------------------------------------
       
  1563 // CExifReadImpl::GetGpsVersion
       
  1564 // Gets the Gps Version tag data.
       
  1565 // -----------------------------------------------------------------------------
       
  1566 //
       
  1567 TInt CExifReadImpl::GetGpsVersion( TUint32& aGpsVersion ) const
       
  1568     {
       
  1569     if ( !iExifCore )
       
  1570         {
       
  1571         return KErrGeneral;
       
  1572         }
       
  1573 
       
  1574     return iExifCore->GetTagData( KIdGpsVersion, aGpsVersion );
       
  1575     }
       
  1576 
       
  1577 // -----------------------------------------------------------------------------
       
  1578 // CExifReadImpl::ParseJpegDataL
       
  1579 // Parses the Jpeg primary image data and initializes the Jpeg primary image 
       
  1580 // structures.
       
  1581 // -----------------------------------------------------------------------------
       
  1582 //
       
  1583 void CExifReadImpl::ParseJpegDataL( const TDesC8& aJpegData )
       
  1584     {
       
  1585     if ( !iReader )
       
  1586         {
       
  1587         iReader = CExifEndianBase::NewBaseL( aJpegData.Ptr(), aJpegData.Length(), 
       
  1588             EFalse );
       
  1589         }
       
  1590     ParseJpegDataL();
       
  1591     delete iReader;
       
  1592     iReader = NULL;
       
  1593     }