imagingext_pub/exif_api/tsrc/src/ExifIopTest.cpp
changeset 0 469c91dae73b
equal deleted inserted replaced
-1:000000000000 0:469c91dae73b
       
     1 /*
       
     2 * Copyright (c) 2009 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: ExifLibTest
       
    15 *
       
    16 */
       
    17 #include "ExifLibTestInc.h"
       
    18 
       
    19 const TInt gpsTagsNo = 3;
       
    20 const TUint gpsTags[3][4] =	{	
       
    21 								{5,1,1,0}, 
       
    22 								{27,7,1,0},
       
    23 								{28,7,1,0}
       
    24 							};
       
    25 // Exif.Iop.001
       
    26 // Parse the data of various Exif images 
       
    27 // Writes the Exif data and the thumbnail image of each image into associated files.
       
    28 void CExifIopTest::ExifIop001L()
       
    29 	{
       
    30 //Various Exif images having different versions and content.
       
    31 	TFindFile file_finder(iFs); 
       
    32     CDir* file_list; 
       
    33     TInt error = file_finder.FindWildByDir(_L("Exif*.jpg"), KIopDir, file_list);
       
    34     while (error == KErrNone)
       
    35         {
       
    36 		CleanupStack::PushL(file_list);
       
    37         TInt i;
       
    38         for (i=0; i<file_list->Count(); i++) 
       
    39             {
       
    40             TParse fullentry;
       
    41             fullentry.Set((*file_list)[i].iName,& file_finder.File(),NULL); 
       
    42   			ExifIop1L(fullentry.FullName());
       
    43             }
       
    44 		CleanupStack::PopAndDestroy(file_list);;
       
    45         error = file_finder.FindWild(file_list); 
       
    46         }	
       
    47     if(error == KErrNoMemory)
       
    48         {
       
    49         User::Leave(KErrNoMemory);
       
    50         }
       
    51 	}
       
    52 
       
    53 
       
    54 // Exif.Iop.002
       
    55 // Modify the data of various Exif images.
       
    56 // Writes out the modified Exif images into new files.
       
    57 void CExifIopTest::ExifIop002L()
       
    58 	{
       
    59 //Various Exif images having different versions and content.
       
    60 	TFindFile file_finder(iFs); 
       
    61     CDir* file_list; 
       
    62 
       
    63     TInt error = file_finder.FindWildByDir(_L("Exif*.jpg"), KIopDir, file_list);
       
    64     while (error == KErrNone)
       
    65         {
       
    66 		CleanupStack::PushL(file_list);
       
    67         TInt i;
       
    68         for (i=0; i<file_list->Count(); i++) 
       
    69             {
       
    70             TParse fullentry;
       
    71             fullentry.Set((*file_list)[i].iName,& file_finder.File(),NULL); 
       
    72   			ExifIop2L(fullentry.FullName());
       
    73             }
       
    74 		CleanupStack::PopAndDestroy(file_list);;
       
    75         error = file_finder.FindWild(file_list); 
       
    76         }
       
    77     if(error == KErrNoMemory)
       
    78         {
       
    79         User::Leave(KErrNoMemory);
       
    80         }
       
    81 	}
       
    82 
       
    83 // Exif.Iop.003
       
    84 // Create new Exif images
       
    85 // Writes out the new Exif images into new files.
       
    86 void CExifIopTest::ExifIop003L()
       
    87 	{
       
    88 //Various Jpeg images having different content.
       
    89 	TFindFile file_finder(iFs); 
       
    90     CDir* file_list; 
       
    91 	HBufC8* buffer2 = TUtils::ReadFileL(iFs, KFullExif);
       
    92 	CleanupStack::PushL(buffer2);
       
    93 	CExifRead* exifRead = 0;
       
    94 	exifRead = CExifRead::NewL(*buffer2);
       
    95 	CleanupStack::PushL(exifRead);
       
    96 
       
    97     TInt error = file_finder.FindWildByDir(_L("*.jpg"), KIopDir, file_list);
       
    98     while (error == KErrNone)
       
    99         {
       
   100 		CleanupStack::PushL(file_list);
       
   101         TInt i;
       
   102 #if ( ( defined __WINS__ ) || ( defined __WINSCW__) )
       
   103         for (i=0; i<file_list->Count(); i++) 
       
   104 #else
       
   105         for (i=0; i<76; i++) 
       
   106 #endif
       
   107             {
       
   108             TParse fullentry;
       
   109             fullentry.Set((*file_list)[i].iName,& file_finder.File(),NULL); 
       
   110   			ExifIop3L(exifRead, fullentry.FullName());
       
   111             }
       
   112 		CleanupStack::PopAndDestroy(file_list);;
       
   113 //#if ( ( defined __WINS__ ) || ( defined __WINSCW__) )
       
   114 //        error = file_finder.FindWild(file_list); 
       
   115 //#else
       
   116         error = KErrNotFound;
       
   117 //#endif
       
   118         }	
       
   119     if(error == KErrNoMemory)
       
   120         {
       
   121         User::Leave(KErrNoMemory);
       
   122         }
       
   123 	CleanupStack::PopAndDestroy(exifRead);
       
   124 	CleanupStack::PopAndDestroy(buffer2);
       
   125 	}
       
   126 
       
   127 // Exif.Iop.MEM.004
       
   128 // Test the behavior of the previous test cases in OOM situations.
       
   129 // Successfully operates or leaves with OOM error, without any memory leaks.
       
   130 void CExifIopTest::ExifIop004L()
       
   131 	{
       
   132 	// OOM in EXIF.IOP.001- EXIF.IOP.003
       
   133 
       
   134 	iWrite = EFalse;
       
   135 	TInt error = KErrGeneral;
       
   136 	TInt i = 0;
       
   137 #if ( ( defined __WINS__ ) || ( defined __WINSCW__) )
       
   138 	for(i = 1; i < 1500; i+=30)
       
   139 #else
       
   140     for(i = 1; i < 10; i++)
       
   141 #endif
       
   142 		{
       
   143 		__UHEAP_MARK;
       
   144 #if ( ( defined __WINS__ ) || ( defined __WINSCW__) )
       
   145 		__UHEAP_SETFAIL( RHeap::EFailNext, i );
       
   146 #else
       
   147         __UHEAP_SETFAIL( RHeap::ERandom, i );
       
   148 #endif
       
   149 		TRAP(error, ExifIop001L());
       
   150 		if(error)
       
   151 			{
       
   152 			if(error != KErrNoMemory)
       
   153 				{
       
   154 				__UHEAP_SETFAIL( RHeap::ENone, 0 );
       
   155 				User::Leave(KErrGeneral);
       
   156 				}
       
   157 			}
       
   158 		else
       
   159 			{
       
   160 			__UHEAP_MARKEND;
       
   161 			break;
       
   162 			}
       
   163 		__UHEAP_MARKEND;
       
   164 		}
       
   165 
       
   166 #if ( ( defined __WINS__ ) || ( defined __WINSCW__) )
       
   167 	for(i = 1; i < 1500; i+=30)
       
   168 #else
       
   169     for(i = 1; i < 10; i++)
       
   170 #endif
       
   171 		{
       
   172 		__UHEAP_MARK;
       
   173 #if ( ( defined __WINS__ ) || ( defined __WINSCW__) )
       
   174 		__UHEAP_SETFAIL( RHeap::EFailNext, i );
       
   175 #else
       
   176         __UHEAP_SETFAIL( RHeap::ERandom, i );
       
   177 #endif
       
   178 		TRAP(error, ExifIop002L());
       
   179 		if(error)
       
   180 			{
       
   181 			if(error != KErrNoMemory)
       
   182 				{
       
   183 				__UHEAP_SETFAIL( RHeap::ENone, 0 );
       
   184 				User::Leave(KErrGeneral);
       
   185 				}
       
   186 			}
       
   187 		else
       
   188 			{
       
   189 			__UHEAP_MARKEND;
       
   190 			break;
       
   191 			}
       
   192 		__UHEAP_MARKEND;
       
   193 		}
       
   194 
       
   195 #if ( ( defined __WINS__ ) || ( defined __WINSCW__) )
       
   196 	for(i = 1; i < 1500; i+=30)
       
   197 #else
       
   198     for(i = 1; i < 10; i++)
       
   199 #endif
       
   200 		{
       
   201 		__UHEAP_MARK;
       
   202 #if ( ( defined __WINS__ ) || ( defined __WINSCW__) )
       
   203 		__UHEAP_SETFAIL( RHeap::EFailNext, i );
       
   204 #else
       
   205         __UHEAP_SETFAIL( RHeap::ERandom, i );
       
   206 #endif
       
   207 		TRAP(error, ExifIop003L());
       
   208 		if(error)
       
   209 			{
       
   210 			if(error != KErrNoMemory)
       
   211 				{
       
   212 				__UHEAP_SETFAIL( RHeap::ENone, 0 );
       
   213 				User::Leave(KErrGeneral);
       
   214 				}
       
   215 			}
       
   216 		else
       
   217 			{
       
   218 			__UHEAP_MARKEND;
       
   219 			break;
       
   220 			}
       
   221 		__UHEAP_MARKEND;
       
   222 		}
       
   223 	}
       
   224 
       
   225 // Exif.Iop.005
       
   226 // Test case for CameraAPI project.
       
   227 void CExifIopTest::ExifIop005L()
       
   228 	{
       
   229 	HBufC8* jpeg = TUtils::ReadFileL(iFs, KCameraAPIJpeg);
       
   230 	CleanupStack::PushL(jpeg);
       
   231 
       
   232     // Create EXIF modifier object.
       
   233     CExifModify* exifModifier = CExifModify::NewL( jpeg->Des(), CExifModify::ECreate );
       
   234     
       
   235     CleanupStack::PushL( exifModifier );
       
   236     // Mandatory EXIF tags:
       
   237 
       
   238     // EXIF tag: Orientation
       
   239     exifModifier->SetOrientationL( 1 );
       
   240 
       
   241     // EXIF tag: YCbCrPositioning
       
   242     exifModifier->SetYCbCrPositioningL( 1 );
       
   243 
       
   244     // EXIF tag: XResolution
       
   245     exifModifier->SetXResolutionL( 300, 1 );
       
   246     
       
   247     // EXIF tag: YResolution
       
   248     exifModifier->SetYResolutionL( 300, 1 );
       
   249 
       
   250     // EXIF tag: ResolutionUnit
       
   251     exifModifier->SetResolutionUnitL( 2 );
       
   252     
       
   253     // EXIF tag: ColorSpace
       
   254     exifModifier->SetColorSpaceL( 1 );
       
   255     
       
   256     // EXIF tag: ComponentsConfiguration
       
   257     exifModifier->SetComponentsConfigurationL( 1, 2, 3, 0 );
       
   258     
       
   259     TSize size(1152, 864);
       
   260 
       
   261     // EXIF tag: PixelXDimension
       
   262     exifModifier->SetPixelXDimensionL( size.iWidth );
       
   263     
       
   264     // EXIF tag: PixelYDimension
       
   265     exifModifier->SetPixelYDimensionL( size.iHeight );
       
   266 
       
   267     // Optional EXIF tags:
       
   268 
       
   269     // Get and format home time
       
   270     TBuf8<20> timeStr;
       
   271     TTime time;
       
   272     TDateTime dateTime;
       
   273     time.HomeTime();
       
   274     dateTime=time.DateTime();
       
   275     _LIT8(KFormatTxt,"%4d:%02d:%02d %02d:%02d:%02d\0");
       
   276     timeStr.Format( KFormatTxt,
       
   277                     dateTime.Year(),
       
   278                     // Day and month ranges begin at zero (0-30 and 0-11), 
       
   279                     // so add one when formatting
       
   280                     TInt(dateTime.Month()+1), 
       
   281                     dateTime.Day()+1, 
       
   282                     dateTime.Hour(), 
       
   283                     dateTime.Minute(), 
       
   284                     dateTime.Second() );
       
   285 
       
   286     // EXIF tag: DateTimeOriginal
       
   287     exifModifier->SetDateTimeOriginalL( timeStr );
       
   288 
       
   289     // EXIF tag: DateTimeDigitized
       
   290     exifModifier->SetDateTimeDigitizedL( timeStr );
       
   291 
       
   292     // Get pointer to ancillary data
       
   293     TUint8 timeByte1, timeByte2, timeByte3, fpsByte;
       
   294     
       
   295     // Read fps value from ancillary data
       
   296     fpsByte = 100;
       
   297 
       
   298     // Read exposure time(1) bytes
       
   299     timeByte1 = 1;
       
   300     timeByte2 = 2;
       
   301     timeByte3 = 3;
       
   302 
       
   303     // Concatenate exposure time bytes together
       
   304     TUint32 timeHorizPeriods;
       
   305     timeHorizPeriods = ( (timeByte3 & 0x07) << 14 ) | 
       
   306                        ( (timeByte2 & 0x7F) << 7 )  | 
       
   307                          (timeByte1 & 0x7F);
       
   308 
       
   309     TInt horizPeriodsInSec;
       
   310     if ( fpsByte & 0x01 )
       
   311         {
       
   312         // 15 fps
       
   313         horizPeriodsInSec = 15;
       
   314         }
       
   315     else 
       
   316         {
       
   317         // 7.5 fps
       
   318         horizPeriodsInSec = 15/2;
       
   319         }
       
   320 
       
   321     // Exposure time = 1/2 periods (=never happens?)
       
   322     if ( !timeHorizPeriods )
       
   323         {
       
   324         timeHorizPeriods = 1;
       
   325         horizPeriodsInSec *= 2;
       
   326         }
       
   327 
       
   328     // EXIF tag: ExposureTime 
       
   329     exifModifier->SetExposureTimeL( timeHorizPeriods, horizPeriodsInSec );
       
   330 
       
   331     // Scene capture type can be normal or night
       
   332     exifModifier->SetSceneCaptureTypeL( 0 );
       
   333 
       
   334     // EXIF tag: Make 
       
   335     exifModifier->SetMakeL( _L8("NOKIA") );
       
   336     exifModifier->SetModelL( _L8("66xx") );
       
   337 
       
   338     // Setting FNumber does not have custom method in EXIF lib -> must use SetTagL()
       
   339 	TExifTagInfo fNumberTag( 0x829d , CExifTag::ETagRational, 1 ); // Tag id = 0x829d, data type = Rational, Data count = 1
       
   340     TBuf8<8> tagValue;
       
   341     tagValue.SetLength(8);
       
   342     *reinterpret_cast<TUint32*>(const_cast<TUint8*>(tagValue.Ptr())) = 28;
       
   343     *reinterpret_cast<TUint32*>(const_cast<TUint8*>(tagValue.Ptr()+4)) = 10;
       
   344 
       
   345     // EXIF tag: FNumber 
       
   346 	exifModifier->SetTagL( EIfdExif, fNumberTag, tagValue ); // The tag goes into the Exif IFD.
       
   347     
       
   348     // Setting FocalLength does not have custom method in EXIF lib -> must use SetTagL()
       
   349 	TExifTagInfo focalLengthTag( 0x920a, CExifTag::ETagRational, 1 ); // Tag id = 0x920a, data type = Rational, Data count = 1
       
   350     *reinterpret_cast<TUint32*>(const_cast<TUint8*>(tagValue.Ptr())) = 37;
       
   351     *reinterpret_cast<TUint32*>(const_cast<TUint8*>(tagValue.Ptr()+4)) = 10;
       
   352 
       
   353     // EXIF tag: FocalLength 
       
   354 	exifModifier->SetTagL( EIfdExif, focalLengthTag, tagValue ); // The tag goes into the Exif IFD.
       
   355     
       
   356     // EXIF tag: ExposureMode 
       
   357     exifModifier->SetExposureModeL( 0 ); // auto
       
   358 
       
   359     // EXIF tag: WhiteBalance 
       
   360     exifModifier->SetWhiteBalanceL( 0 ); // auto
       
   361 
       
   362     TExifTagInfo tag( 1, CExifTag::ETagAscii, 3 );
       
   363     exifModifier->SetTagL( EIfdIntOp, tag, _L8("R98") );
       
   364     tag.iDataCount = 4;
       
   365     tag.iDataType = CExifTag::ETagUndefined;
       
   366     tag.iId = 2;
       
   367     TBuf8<4> buf;
       
   368     buf.Copy( _L8("0100") );
       
   369     exifModifier->SetTagL( EIfdIntOp, tag, buf );
       
   370 
       
   371 	HBufC8* thumbnail = TUtils::ReadFileL(iFs, KValidThumbnail);
       
   372 	CleanupStack::PushL(thumbnail);
       
   373 	exifModifier->SetThumbnailL(thumbnail->Des());
       
   374 	CleanupStack::PopAndDestroy(thumbnail);
       
   375     exifModifier->SetThumbnailResolutionUnitL( 2 );
       
   376     exifModifier->SetThumbnailXResolutionL( 72, 1 );
       
   377     exifModifier->SetThumbnailYResolutionL( 72, 1 );
       
   378 
       
   379 
       
   380     TReal tmp = 1;
       
   381 
       
   382     TReal isoSpeedRating = 1600;	
       
   383 
       
   384     // Round isoSpeedRating to one of the values listed in
       
   385     // ISO 12232:1998
       
   386     const TUint16 isoSpeedRatingsLut[35] = { 4, 5, 6, 8, 10, 12, 16, 20, 25, 32, 40, 50, 64, 80,
       
   387                                              100, 125, 160, 200, 250, 320, 400, 500, 640, 800,
       
   388                                              1000, 1250, 1600, 2000, 2500, 3200, 4000, 5000, 6400, 8000, 
       
   389                                              10000 };  
       
   390 
       
   391     if ( isoSpeedRating > 10000 )
       
   392         {
       
   393         isoSpeedRating = 10000;
       
   394         }
       
   395     else
       
   396         {
       
   397         TInt i=1;
       
   398         while ( isoSpeedRatingsLut[i] < isoSpeedRating )
       
   399             {
       
   400             i++;
       
   401             }
       
   402         isoSpeedRating = isoSpeedRatingsLut[i-1];
       
   403         }
       
   404 
       
   405     // Put the iso speed rating value in a descriptor
       
   406     TBuf8<2> isoSpeedDes;
       
   407     isoSpeedDes.SetLength(2);
       
   408     *reinterpret_cast<TUint16*>(const_cast<TUint8*>(isoSpeedDes.Ptr())) = static_cast<TUint16>(isoSpeedRating);
       
   409     
       
   410     // EXIF tag: IsoSpeedRatings
       
   411     exifModifier->SetIsoSpeedRatingsL( isoSpeedDes );
       
   412 
       
   413     // Setting ShutterSpeedValue does not have custom method in EXIF lib -> must use SetTagL()
       
   414 	TExifTagInfo shutterSpeedValueTag( 0x9201, CExifTag::ETagSrational, 1 ); // Tag id = 0x9201, data type = Rational, Data count = 1
       
   415 
       
   416     // Log( exposure time )
       
   417     *reinterpret_cast<TInt32*>(const_cast<TUint8*>(tagValue.Ptr())) =  static_cast<TInt32>(-1*tmp/0.00030103);// =-1*tmp/(log(2)/1000)
       
   418     *reinterpret_cast<TInt32*>(const_cast<TUint8*>(tagValue.Ptr()+4)) = static_cast<TInt32>(1000);
       
   419 
       
   420     // EXIF tag: ShutterSpeedValue
       
   421 	exifModifier->SetTagL( EIfdExif, shutterSpeedValueTag, tagValue ); // The tag goes into the Exif IFD.
       
   422 
       
   423     // EXIF tag: ApertureValue
       
   424     exifModifier->SetApertureValueL( 30, 10 );
       
   425     
       
   426     // EXIF tag: DigitalZoomRatio
       
   427     exifModifier->SetDigitalZoomRatioL( 100, 100 );
       
   428 
       
   429     // Setting GainControl does not have custom method in EXIF lib -> must use SetTagL()
       
   430 	TExifTagInfo gainControlTag( 0xa407, CExifTag::ETagShort, 1 ); // Tag id = 0xa407, data type = Short, Data count = 1
       
   431 
       
   432     // Put the gain control value in a descriptor
       
   433     TBuf8<2> gainControlDes;
       
   434     gainControlDes.SetLength(2);
       
   435     TReal analogGain = 3;
       
   436     if ( analogGain < -0.1 )
       
   437         {
       
   438         *reinterpret_cast<TUint16*>(const_cast<TUint8*>(gainControlDes.Ptr())) = static_cast<TUint16>( 3 ); // low gain down
       
   439         }
       
   440     else if ( analogGain >= -0.1 && analogGain < 0.1 )
       
   441         {
       
   442         *reinterpret_cast<TUint16*>(const_cast<TUint8*>(gainControlDes.Ptr())) = static_cast<TUint16>( 0 ); // none
       
   443         }
       
   444     else if ( analogGain >= 0.1 && analogGain < 6.0 )
       
   445         {
       
   446         *reinterpret_cast<TUint16*>(const_cast<TUint8*>(gainControlDes.Ptr())) = static_cast<TUint16>( 1 ); // low gain up
       
   447         }
       
   448     else // analogGain => 6.0 
       
   449         {
       
   450         *reinterpret_cast<TUint16*>(const_cast<TUint8*>(gainControlDes.Ptr())) = static_cast<TUint16>( 2 ); // high gain up
       
   451         }
       
   452 
       
   453     // EXIF tag: GainControl
       
   454 	exifModifier->SetTagL( EIfdExif, gainControlTag, gainControlDes ); // The tag goes into the Exif IFD.
       
   455 
       
   456     // EXIF tag: LightSource
       
   457     exifModifier->SetLightSourceL( 0 ); // unknown
       
   458 
       
   459     HBufC8* exif = exifModifier->WriteDataL(jpeg->Des());
       
   460     CleanupStack::PushL(exif);
       
   461 
       
   462     RFile file;
       
   463 	TBuf<255> fileName;
       
   464 
       
   465     fileName.Copy(KRootOut);
       
   466 	fileName.Append(_L("out\\"));
       
   467     // Create out folder, ignore errors
       
   468    	iFs.MkDir(fileName);
       
   469 	fileName.Append(_L("CameraApi.jpg"));
       
   470 	if(file.Open(iFs, fileName, EFileWrite) != KErrNone)
       
   471         {
       
   472 		if(file.Create(iFs, fileName, EFileWrite) != KErrNone)
       
   473             {
       
   474             fileName.Copy(KRootC);
       
   475 	        fileName.Append(_L("out\\"));
       
   476 	        // Create out folder, ignore errors
       
   477         	iFs.MkDir(fileName);
       
   478 	        fileName.Append(_L("CameraApi.jpg"));
       
   479 	        if(file.Open(iFs, fileName, EFileWrite) != KErrNone)
       
   480                 {
       
   481 		        if(file.Create(iFs, fileName, EFileWrite) != KErrNone)
       
   482                     {
       
   483                     fileName.Copy(KRootData);
       
   484 	                fileName.Append(_L("out\\"));
       
   485         	        // Create out folder, ignore errors
       
   486                 	iFs.MkDir(fileName);
       
   487 	                fileName.Append(_L("CameraApi.jpg"));
       
   488 	                if(file.Open(iFs, fileName, EFileWrite) != KErrNone)
       
   489                         {
       
   490                         User::LeaveIfError(file.Create(iFs, fileName, EFileWrite));    
       
   491                         }
       
   492                     }
       
   493                 }
       
   494             }
       
   495         }
       
   496  
       
   497 
       
   498     file.Write(exif->Des());
       
   499     file.Close();
       
   500     CleanupStack::PopAndDestroy(exif);
       
   501     CleanupStack::PopAndDestroy(exifModifier);
       
   502     CleanupStack::PopAndDestroy(jpeg);
       
   503     }
       
   504 
       
   505 void CExifIopTest::ExifIop1L(const TDesC& aFileName)
       
   506 	{
       
   507 	RDebug::Print(aFileName);
       
   508 	//RDebug::Print(_L("Read File..."));
       
   509 	HBufC8* buffer = TUtils::ReadFileL(iFs,aFileName);
       
   510 	CleanupStack::PushL(buffer);
       
   511 
       
   512 	//RDebug::Print(_L("Create reader.."));
       
   513 	CExifRead* exifRead = 0;
       
   514 	exifRead = CExifRead::NewL(*buffer);
       
   515 	CleanupStack::PushL(exifRead);
       
   516 
       
   517 	//RDebug::Print(_L("Get ifds.."));
       
   518 	TInt noIfds = 0;
       
   519 	TExifIfdType* ifds = exifRead->GetIfdTypesL(noIfds);
       
   520 	CleanupStack::PushL(ifds);
       
   521 	if((!ifds) || (!noIfds))
       
   522 		return;
       
   523 
       
   524 	//RDebug::Print(_L("Create file.."));
       
   525 	RFile file;
       
   526 	TBuf<255> fileName;
       
   527 	TInt flen = KIopDir.iTypeLength; // folder length
       
   528 	if(iWrite)
       
   529 		{
       
   530 		fileName.Copy(aFileName);
       
   531 		fileName.Insert(flen,_L("out\\"));
       
   532         // Create out folder, ignore errors
       
   533        	iFs.MkDir(fileName);
       
   534 		fileName.Append(_L(".txt"));
       
   535 		if(file.Open(iFs, fileName, EFileWrite) != KErrNone)
       
   536 			User::LeaveIfError(file.Create(iFs, fileName, EFileWrite));
       
   537 		}
       
   538 
       
   539 	for(TInt i=0; i<noIfds; ++i)
       
   540 		{
       
   541 		if(iWrite)
       
   542 			{
       
   543 			User::LeaveIfError(file.Write(_L8("______________________________________________\n")));
       
   544 			switch(ifds[i])
       
   545 				{
       
   546 				case EIfd0:
       
   547 					User::LeaveIfError(file.Write(_L8("Ifd 0:\n\n")));
       
   548 					break;
       
   549 				case EIfdExif:
       
   550 					User::LeaveIfError(file.Write(_L8("Ifd Exif:\n\n")));
       
   551 					break;
       
   552 				case EIfd1:
       
   553 					User::LeaveIfError(file.Write(_L8("Ifd 1:\n\n")));
       
   554 					break;
       
   555 				case EIfdGps:
       
   556 					User::LeaveIfError(file.Write(_L8("Ifd GPS:\n\n")));
       
   557 					break;
       
   558 				case EIfdIntOp:
       
   559 					User::LeaveIfError(file.Write(_L8("Ifd IOP:\n\n")));
       
   560 				}
       
   561 			}
       
   562 		
       
   563 		TInt noTags = 0;
       
   564 
       
   565 		//RDebug::Print(_L("Retrieve tag ids..."));
       
   566 		TUint16* tags = exifRead->GetTagIdsL(ifds[i], noTags);
       
   567 		//RDebug::Print(_L("Retrieved tag ids."));
       
   568 		CleanupStack::PushL(tags);
       
   569 		if((!tags) || (!noTags))
       
   570 			continue;
       
   571 
       
   572 		//RDebug::Print(_L("Write tags..."));
       
   573 		for(TInt j=0; j<noTags; ++j)
       
   574 			{
       
   575 			TBuf8<48> tagHeader;
       
   576 			tagHeader.Insert(0, _L8("Inf: "));
       
   577 			TBuf8<8> num;
       
   578 			TInt id = (exifRead->GetTagL(ifds[i], tags[j]))->TagInfo().iId;
       
   579 			num.Num(id, EHex);
       
   580 			tagHeader.Append(num);
       
   581 			tagHeader.Append(_L("\t"));
       
   582 			num.Num((exifRead->GetTagL(ifds[i], tags[j]))->TagInfo().iDataType);
       
   583 			tagHeader.Append(num);
       
   584 			tagHeader.Append(_L("\t"));
       
   585 			num.Num(static_cast<TUint16>( (exifRead->GetTagL(ifds[i], tags[j]))->TagInfo().iDataCount));
       
   586 			tagHeader.Append(num);
       
   587 			tagHeader.Append(_L("\t"));
       
   588 			if(iWrite)
       
   589 				{
       
   590 				User::LeaveIfError(file.Write(tagHeader));
       
   591 				User::LeaveIfError(file.Write((exifRead->GetTagL(ifds[i], tags[j]))->Data()));
       
   592 				User::LeaveIfError(file.Write(_L8("\n")));
       
   593 				}
       
   594 			}
       
   595 		CleanupStack::PopAndDestroy(tags);
       
   596 		}
       
   597 	if(iWrite)
       
   598 		file.Close();
       
   599 
       
   600 	//Thumbnail
       
   601 	TInt error;
       
   602 	HBufC8* thumbnail = 0;
       
   603 	//RDebug::Print(_L("Retrieve thumnail..."));
       
   604 	TRAP(error, thumbnail = exifRead->GetThumbnailL());
       
   605 	CleanupStack::PushL(thumbnail);
       
   606 	if(!error)
       
   607 		{
       
   608 		//RDebug::Print(_L("Thumbnail retrieved"));
       
   609 		fileName.Copy(aFileName);
       
   610 		fileName.Insert(flen,_L("out\\"));
       
   611         // Create out folder, ignore errors
       
   612        	iFs.MkDir(fileName);
       
   613 		fileName.Append(_L(".thm.jpg"));
       
   614 		//RDebug::Print(_L("Open file..."));
       
   615 		if(iWrite)
       
   616 			{
       
   617 			if(file.Open(iFs, fileName, EFileWrite) != KErrNone)
       
   618 				User::LeaveIfError(file.Create(iFs, fileName, EFileWrite));
       
   619 			}
       
   620 		//RDebug::Print(_L("File opened"));
       
   621 		if(iWrite)
       
   622 			file.Write(thumbnail->Des());
       
   623 		//RDebug::Print(_L("File written."));
       
   624 		if(iWrite)
       
   625 			file.Close();
       
   626 		}
       
   627 	CleanupStack::PopAndDestroy(thumbnail);
       
   628 	CleanupStack::PopAndDestroy(ifds);
       
   629 	CleanupStack::PopAndDestroy(exifRead);
       
   630 	CleanupStack::PopAndDestroy(buffer);
       
   631 	}
       
   632 
       
   633 void CExifIopTest::ExifIop2L(const TDesC& aFileName)
       
   634 	{
       
   635 	RDebug::Print(aFileName);
       
   636 	HBufC8* buffer = TUtils::ReadFileL(iFs, aFileName);
       
   637 	CleanupStack::PushL(buffer);
       
   638 
       
   639 	CExifModify* exifModify = 0;
       
   640 	exifModify = CExifModify::NewL(*buffer, CExifModify::EModify);
       
   641 	CleanupStack::PushL(exifModify);
       
   642 
       
   643 	HBufC8* buf = 0;
       
   644 	TUint16 tmp1 = 0;
       
   645 	TUint32 tmp2 = 0;
       
   646 	TUint32 tmp3 = 0;
       
   647 	TInt error = 0;
       
   648 
       
   649 	buf = TUtils::CreateDummyBufL(5);
       
   650 	CleanupStack::PushL(buf);
       
   651 	exifModify->SetImageDescriptionL(buf->Des());
       
   652 	CleanupStack::PopAndDestroy(buf);
       
   653 	buf = 0;
       
   654 	
       
   655 	error = exifModify->Reader()->GetXResolution(tmp2,tmp3);
       
   656 	exifModify->SetXResolutionL(tmp2,tmp3);
       
   657 	error = exifModify->Reader()->GetYResolution(tmp2,tmp3);
       
   658 	exifModify->SetYResolutionL(tmp2,tmp3);
       
   659 	error = exifModify->Reader()->GetResolutionUnit(tmp1);
       
   660 	exifModify->SetResolutionUnitL(tmp1);
       
   661 
       
   662 	
       
   663 	buf = TUtils::CreateDummyBufL(768*2);
       
   664 	CleanupStack::PushL(buf);
       
   665 	exifModify->SetTransferFunctionL(buf->Des());
       
   666 	CleanupStack::PopAndDestroy(buf);
       
   667 	buf = 0;
       
   668 	
       
   669 	
       
   670 	HBufC8* buffer2 = exifModify->WriteDataL(*buffer);
       
   671 	CleanupStack::PushL(buffer2);
       
   672 
       
   673 	if(iWrite)
       
   674 		{
       
   675 		RFile file;
       
   676 		TBuf<255> fileName;
       
   677     	TInt flen = KIopDir.iTypeLength; // folder length
       
   678 		fileName.Copy(aFileName);
       
   679 		fileName.Insert(flen,_L("out\\"));
       
   680         // Create out folder, ignore errors
       
   681        	iFs.MkDir(fileName);
       
   682 		fileName.Append(_L(".cpy.jpg"));
       
   683 		if(file.Open(iFs, fileName, EFileWrite) != KErrNone)
       
   684 			User::LeaveIfError(file.Create(iFs, fileName, EFileWrite));
       
   685 
       
   686 		User::LeaveIfError(file.Write(*buffer2, buffer2->Length()));
       
   687 		file.Close();
       
   688 		}
       
   689 	CleanupStack::PopAndDestroy(buffer2);
       
   690 	CleanupStack::PopAndDestroy();
       
   691 	CleanupStack::PopAndDestroy(buffer);
       
   692 	}
       
   693 
       
   694 void CExifIopTest::ExifIop3L(CExifRead* aExifRead, const TDesC& aFileName)
       
   695 	{
       
   696 	RDebug::Print(aFileName);
       
   697 	CExifRead* exifRead = aExifRead;
       
   698 	HBufC8* buffer = TUtils::ReadFileL(iFs, aFileName);
       
   699 	CleanupStack::PushL(buffer);
       
   700 
       
   701 	CExifModify* exifModify = 0;
       
   702 	exifModify = CExifModify::NewL(*buffer, CExifModify::ECreate);
       
   703 	CleanupStack::PushL(exifModify);
       
   704 
       
   705 	// Insert Tags
       
   706 	HBufC8* tmp = 0;
       
   707 	HBufC8* buf = 0;
       
   708 	TUint16 tmp1 = 0;
       
   709 	TUint32 tmp3 = 1;
       
   710 	TUint32 tmp4 = 2;
       
   711 
       
   712 	buf = TUtils::CreateDummyBufL(5);
       
   713 	CleanupStack::PushL(buf);
       
   714 	exifModify->SetImageDescriptionL(buf->Des());
       
   715 	CleanupStack::PopAndDestroy(buf);
       
   716 	buf = 0;
       
   717 
       
   718 
       
   719 	buf = TUtils::CreateDummyBufL(768*2);
       
   720 	CleanupStack::PushL(buf);
       
   721 	exifModify->SetTransferFunctionL(buf->Des());
       
   722 	CleanupStack::PopAndDestroy(buf);
       
   723 	buf = 0;
       
   724 	
       
   725 	tmp = exifRead->GetDateTimeL();
       
   726 	CleanupStack::PushL(tmp);
       
   727 	exifModify->SetDateTimeL(tmp->Des());
       
   728 	CleanupStack::PopAndDestroy(tmp);
       
   729 
       
   730 	User::LeaveIfError(exifRead->GetYCbCrPositioning(tmp1));
       
   731 	exifModify->SetYCbCrPositioningL(tmp1);
       
   732 
       
   733 	buf = TUtils::CreateDummyBufL(5);
       
   734 	CleanupStack::PushL(buf);
       
   735 	exifModify->SetSoftwareL(buf->Des());
       
   736 	CleanupStack::PopAndDestroy(buf);
       
   737 	buf = 0;
       
   738 
       
   739 	buf = TUtils::CreateDummyBufL(5);
       
   740 	CleanupStack::PushL(buf);
       
   741 	exifModify->SetCopyrightL(buf->Des());
       
   742 	CleanupStack::PopAndDestroy(buf);
       
   743 	buf = 0;
       
   744 
       
   745 	exifModify->SetExposureTimeL(tmp3, tmp4);
       
   746 
       
   747 	User::LeaveIfError(exifRead->GetXResolution(tmp3, tmp4));
       
   748 	exifModify->SetXResolutionL(tmp3, tmp4);
       
   749 	User::LeaveIfError(exifRead->GetYResolution(tmp3, tmp4));
       
   750 	exifModify->SetYResolutionL(tmp3, tmp4);
       
   751 	User::LeaveIfError(exifRead->GetResolutionUnit(tmp1));
       
   752 	exifModify->SetResolutionUnitL(tmp1);
       
   753 
       
   754 	User::LeaveIfError(exifRead->GetPixelXDimension(tmp3));
       
   755 	exifModify->SetPixelXDimensionL(tmp3);
       
   756 	User::LeaveIfError(exifRead->GetPixelYDimension(tmp3));
       
   757 	exifModify->SetPixelYDimensionL(tmp3);
       
   758 
       
   759 	exifModify->SetComponentsConfigurationL(1, 2, 3, 0);
       
   760 	User::LeaveIfError(exifRead->GetFlash(tmp1));
       
   761 	exifModify->SetFlashL(tmp1);
       
   762 	User::LeaveIfError(exifRead->GetColorSpace(tmp1));
       
   763 	exifModify->SetColorSpaceL(tmp1);
       
   764 
       
   765 	exifModify->SetExposureModeL(0);
       
   766 	exifModify->SetWhiteBalanceL(0);
       
   767 	exifModify->SetSceneCaptureTypeL(0);
       
   768 	exifModify->SetExposureProgramL(0);
       
   769 	
       
   770 	buf = TUtils::CreateDummyBufL(6);
       
   771 	CleanupStack::PushL(buf);
       
   772 	exifModify->SetIsoSpeedRatingsL(buf->Des());
       
   773 	CleanupStack::PopAndDestroy(buf);
       
   774 	buf = 0;
       
   775 	
       
   776 	exifModify->SetLightSourceL(0);
       
   777 
       
   778 	buf = TUtils::CreateDummyBufL(16);
       
   779 	CleanupStack::PushL(buf);
       
   780 	exifModify->SetMakerNoteL(buf->Des());
       
   781 	CleanupStack::PopAndDestroy(buf);
       
   782 	buf = 0;
       
   783 
       
   784 	buf = TUtils::CreateDummyBufL(12);
       
   785 	CleanupStack::PushL(buf);
       
   786 	exifModify->SetRelatedSoundFileL(buf->Des());
       
   787 	CleanupStack::PopAndDestroy(buf);
       
   788 	buf = 0;
       
   789 	
       
   790 	InsertGpsTagsL(exifModify);
       
   791 
       
   792 	exifModify->SetDigitalZoomRatioL(0,1);
       
   793 	exifModify->SetContrastL(0);
       
   794 	exifModify->SetSaturationL(0);
       
   795 	exifModify->SetSharpnessL(0);
       
   796 
       
   797 	buf = exifRead->GetThumbnailL();
       
   798 	CleanupStack::PushL(buf);
       
   799 	exifModify->SetThumbnailL(buf->Des());
       
   800 	CleanupStack::PopAndDestroy(buf);
       
   801 	User::LeaveIfError(exifRead->GetThumbnailResolutionUnit(tmp1));
       
   802 	exifModify->SetThumbnailResolutionUnitL(tmp1);
       
   803 	User::LeaveIfError(exifRead->GetThumbnailXResolution(tmp3, tmp4));
       
   804 	exifModify->SetThumbnailXResolutionL(tmp3, tmp4);
       
   805 	User::LeaveIfError(exifRead->GetThumbnailYResolution(tmp3, tmp4));
       
   806 	exifModify->SetThumbnailYResolutionL(tmp3, tmp4);
       
   807 
       
   808 		
       
   809 	HBufC8* buffer3 = exifModify->WriteDataL(*buffer);
       
   810 	CleanupStack::PushL(buffer3);
       
   811 
       
   812 	if(iWrite)
       
   813 		{
       
   814 		RFile file;
       
   815 		TBuf<255> fileName;
       
   816     	TInt flen = KIopDir.iTypeLength; // folder length
       
   817 		fileName.Copy(aFileName);
       
   818 		fileName.Insert(flen,_L("out\\"));
       
   819         // Create out folder, ignore errors
       
   820        	iFs.MkDir(fileName);
       
   821 		fileName.Append(_L(".new.jpg"));
       
   822 		if(file.Open(iFs, fileName, EFileWrite) != KErrNone)
       
   823 			User::LeaveIfError(file.Create(iFs, fileName, EFileWrite));
       
   824 
       
   825 		User::LeaveIfError(file.Write(*buffer3, buffer3->Length()));
       
   826 		file.Close();
       
   827 		}
       
   828 
       
   829 	CleanupStack::PopAndDestroy(buffer3);
       
   830 	CleanupStack::PopAndDestroy();
       
   831 	CleanupStack::PopAndDestroy(buffer);
       
   832 	}
       
   833 
       
   834 void CExifIopTest::InsertGpsTagsL(CExifModify* aModify)
       
   835 	{
       
   836 	for(TInt i = 0; i< gpsTagsNo; i++)
       
   837 		{
       
   838 		HBufC8* buf = HBufC8::NewL(1);
       
   839 		CleanupStack::PushL(buf);
       
   840 		buf->Des().SetLength(1);
       
   841 		*((TUint8*)buf + 4) = gpsTags[i][3];
       
   842 		TExifTagInfo tag(gpsTags[i][0], (CExifTag::TExifTagDataType)gpsTags[i][1], gpsTags[i][2]);
       
   843 		aModify->SetTagL(EIfdGps, tag, buf->Des());
       
   844 		CleanupStack::PopAndDestroy(buf);
       
   845 		}
       
   846 	}