examples/Multimedia/ICL/ICLExample/iclmainexample.cpp

Go to the documentation of this file.
00001 // iclmainexample.cpp
00002 //
00003 // // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
00004 // All rights reserved.
00005 // This component and the accompanying materials are made available
00006 // under the terms of "Eclipse Public License v1.0"
00007 // which accompanies this distribution, and is available
00008 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00009 //
00010 // Initial Contributors:
00011 // Nokia Corporation - initial contribution.
00012 //
00013 // Contributors:
00014 //
00015 // Description:
00016 // 
00017 //
00018 
00025 #include "iclexample.h"
00026 #include <f32file.h>
00027 
00032 CActiveListener* CActiveListener::NewLC()
00033         {
00034     CActiveListener* self = new(ELeave) CActiveListener();
00035         CleanupStack::PushL(self);
00036         return self;
00037         }
00038 
00042 CActiveListener::CActiveListener() : CActive(EPriorityLow)
00043         {
00044         CActiveScheduler::Add(this);
00045         }
00046 
00050 CActiveListener::~CActiveListener()
00051         {
00052         }
00053 
00058 void CActiveListener::RunL()
00059         {
00060         CActiveScheduler::Stop();
00061         }
00062 
00067 void CActiveListener::DoCancel()
00068         {
00069         }
00070 
00074 void CActiveListener::Initialize()
00075         {
00076         iStatus = KRequestPending;
00077         SetActive();
00078         }
00079 
00084 TBool CActiveListener::IsRequestCancelled()
00085         {
00086         return (iStatus == KErrCancel);
00087         }
00088 
00089 
00090 
00096 CIclExample* CIclExample::NewLC()
00097         {
00098         CIclExample* self = new(ELeave) CIclExample();
00099         CleanupStack::PushL(self);
00100         self->ConstructL();
00101         return self;
00102         }
00103 
00107 CIclExample::CIclExample()
00108         {
00109         }
00110 
00111 void CIclExample::ConstructL()
00112         {
00113         User::LeaveIfError(iFs.Connect());
00114         User::LeaveIfError(RFbsSession::Connect());
00115         }
00116 
00120 CIclExample::~CIclExample()
00121         {
00122         RFbsSession::Disconnect();
00123         iFs.Close();
00124 
00125         // Close REComSession
00126         REComSession::FinalClose();
00127         }
00128 
00129 
00136 TPtr8 CIclExample::LoadImageIntoMemoryLC(const TDesC& aFileName)
00137         {
00138     RFile file;
00139         TInt fileSize = 0;
00140 
00141     // Open the file for decoding.
00142         User::LeaveIfError(file.Open(iFs, aFileName, EFileRead));
00143         CleanupClosePushL(file);
00144         User::LeaveIfError(file.Size(fileSize));
00145 
00146         HBufC8* imageInMemory = HBufC8::NewMaxL(fileSize);
00147         TPtr8 imageInMemoryPtr = imageInMemory->Des();
00148 
00149         // We must reorder the cleanupstack.
00150         CleanupStack::Pop(); // file
00151         CleanupStack::PushL(imageInMemory); // imageInMemory
00152         CleanupClosePushL(file);
00153 
00154         if (file.SubSessionHandle())
00155                 {
00156                 User::LeaveIfError(file.Read(imageInMemoryPtr));
00157                 }
00158 
00159         CleanupStack::PopAndDestroy(); // file
00160         return imageInMemoryPtr;
00161         }
00162 
00163 
00168 CActiveListener* CIclExample::CreateAndInitializeActiveListenerLC()
00169         {
00170         // Create an active Listener and push it on the cleanup stack
00171         CActiveListener* activeListener = CActiveListener::NewLC();
00172         activeListener->Initialize();
00173         return activeListener;
00174         }
00175 
00176 
00177 LOCAL_C void MainL()
00178         {
00179         // Create a CConsoleBase to define console interface
00180         CConsoleBase* gConsole = Console::NewL(KTitle, TSize(KConsFullScreen, KConsFullScreen));
00181         CleanupStack::PushL(gConsole);
00182 
00183         // Create an active scheduler to handle asychronous calls
00184         CActiveScheduler* scheduler = new(ELeave) CActiveScheduler();
00185         CleanupStack::PushL(scheduler);
00186         CActiveScheduler::Install(scheduler);
00187 
00188         CIclExample* app = CIclExample::NewLC();
00189         app->SetConsole(gConsole);
00190 
00191         gConsole->Printf(KWelcomeMessage);
00192         gConsole->Printf(KPressAKeyMsg);
00193         gConsole->Getch();
00194 
00195         //Panorama Stitching
00196         gConsole->Printf(KPanoramaStitching);
00197         
00198         //Stitch images already captured to form a panorama
00199         _LIT(KPath,"z:\\resource\\plugins\\");
00200         _LIT(KFile,"panoramaplugin.rsc");
00201         
00202     /*
00203     Check for the availability of the panorama plugin. If it is not available, skip the code that uses it.
00204         */
00205         RFs fsSession;// Connect session
00206         User::LeaveIfError(fsSession.Connect());
00207         
00208         TFindFile file(fsSession);
00209         TInt panoramaPluginSupport;
00210         panoramaPluginSupport = file.FindByPath(KFile(),&KPath());
00211         
00212         if(panoramaPluginSupport == KErrNone)
00213                 {
00214                 app->BasicPanoramaStitchingL();
00215                 gConsole->Printf(KBPStitching);
00216             //Stitch images together to form a panorama based on viewfinder tracking
00217                 app->ViewFinderImageTrackingL();
00218                 gConsole->Printf(KVFTStitching);
00219                 }
00220         
00221         gConsole->Printf(KPressAKey);
00222         gConsole->Getch();
00223 
00224         /*
00225         Various Decode functions
00226         */
00227         gConsole->Printf(KDecode);
00228 
00229         // Decode descriptor to bitmap
00230         app->DecodeFromDescriptorToBitmapL(KBitmapFile);
00231         gConsole->Printf(KDecodeFromDescriptorToBitmap);
00232 
00233         // Decode from image file to bitmap
00234         app->DecodeFromFileToBitmapL(KBitmapFile);
00235         gConsole->Printf(KDecodeFromDescriptorAndFile, &KBitmapFile);
00236 
00237         // Decode to image frame YUV
00238         app->DecodeToYuvFrameL(KYuvBitmap);
00239         gConsole->Printf(KDecodeToYuv, &KYuvBitmap);
00240 
00241         // Decode to ½, ¼ and 1/8 sized bitmaps
00242         app->DecodeToHalfFourthAndEighthSizedBitmapL(KBitmapFile);
00243         gConsole->Printf(KDecodeToHalfFourthAndEighthSizedBmp, &KBitmapFile);
00244 
00245         // Decode using image mask
00246         app->DecodeUsingImageMaskL(KMultiFrameClock);
00247         gConsole->Printf(KDecodeUsingImageMask);
00248 
00249         // Multi-frame Image Decode
00250         app->MultiFrameImageDecodeL(KMultiFrameClock);
00251         gConsole->Printf(KImageMaskAndMultiFrameImageDecode, &KMultiFrameClock);
00252 
00253     // Decode using separate thread
00254         app->DecodeUsingSepThreadL(KBitmapFile);
00255         gConsole->Printf(KDecodeUsingSepThread);
00256 
00257         // Decode using continue convert
00258         app->DecodeUsingContinueConvertL(KBitmapFile);
00259         gConsole->Printf(KSeparateThreadAndCancelAndContinueConvert, &KBitmapFile);
00260 
00261         // JPEG thumbnail access
00262         app->AccessThumbnailToDecodeL(KThumbFile);
00263         gConsole->Printf(KAccessThumbnailToDecode);
00264 
00265         // Access Exif metadata
00266         app->AccessExifMetadataL(KBitmapExif);
00267         gConsole->Printf(KAccessExifMetadata);
00268 
00269         // Decode the thumbnail part of the image
00270         app->DecodeTheThumbnailL(KThumbFile);
00271         gConsole->Printf(KAccessExifThumbnailAndDecodeThumbnail, &KThumbFile);
00272 
00273         // Decode and display image comments
00274         app->DisplayingImageCommentsL(KBitmapComment);
00275         gConsole->Printf(KDisplayingImageComments);
00276 
00277         // Decode and display frame comments
00278         app->DisplayingFrameCommentsL(KBitmapFrameComment);
00279         gConsole->Printf(KImageAndFrameComment);
00280 
00281         // Get the MIME type of a source image descriptor, and load a decoder using a MIME type
00282         app->GettingMimeTypeOfSourceDescriptorL(KBitmapFile);
00283         gConsole->Printf(KGettingMimeTypeOfSourceDescriptor);
00284 
00285         // Get the MIME type of a source image file, and load a decoder using a MIME type
00286         app->GettingMimeTypeOfSourceFileL(KBitmapFile);
00287         gConsole->Printf(KGettingMimeTypeFromSourceAndFile, &KBitmapFile);
00288 
00289         // Decode Bitmap including rotating an image
00290         app->DecodeWithRotateL(KBitmapFile);
00291         gConsole->Printf(KFileRotateAfterDecode, &KBitmapFile);
00292 
00293         // Load a Plugin by specific UID
00294         app->LoadPluginByUidL(KBitmapExif, KImageTypeJPGUid);
00295         gConsole->Printf(KPluginLoadedSpecificToUID);
00296         
00297         // Stream Decode and stream encode YUV image frame 
00298         app->BlockStreamDecodeAndEncodeYuvFrameL(KYuvBitmap, KDestStreamFile);
00299         gConsole->Printf(KStreamYuv, &KYuvBitmap);
00300 
00301         // Apply clipping, scaling and rotation during image decode.
00302         app->ClipAndRotateDuringDecodeL();         
00303 
00304         gConsole->Printf(KPressAKey);
00305         gConsole->Getch();
00306 
00307 
00308         /*
00309         various encode functions
00310         */
00311         gConsole->Printf(KEncode);
00312 
00313         // Encode image frame (YUV) to descriptor
00314         app->EncodeBitmapToDescriptorL(KSourceBitmap);
00315         gConsole->Printf(KFileEncode, &KSourceBitmap);
00316 
00317         // JPEG thumbnail access
00318         app->EncodeImageWithThumbnailL(KSourceBitmap);
00319         gConsole->Printf(KEncodeImageWithThumbnail);
00320 
00321         // Setting EXIF metadata
00322         app->SettingExifMetadataL(KSourceBitmap);
00323         gConsole->Printf(KAccessToThumbnailAndExifSetting);
00324 
00325         // Rotating a bitmap
00326         app->RotateBitmapL(KSourceBitmap);
00327         gConsole->Printf(KFileRotate);
00328 
00329         // Scaling a bitmap (including optional selection of low memory and quality algorithms)
00330         app->ScaleBitmapL(KSourceBitmap);
00331         gConsole->Printf(KScaleBitmap);
00332 
00333         // Set Source to File and destination to descriptor and resize
00334         app->SetSourceDestinationandResizeL(KBitmapExif);
00335         gConsole->Printf(KSetSourceDestinationandResize);
00336 
00337         // Set Source to descriptor and destination to File and resize
00338         app->SettingWithUseOfPreserveImageDataL(KYuvBitmap,KYuvDestBitmap);
00339         gConsole->Printf(KSetSourceAndDestinationAndResize);
00340 
00341         // Adding thumbnail to JPEG file
00342         app->AddThumbnailToJpegFileL(KBitmapExif, KYuvDestBitmap);
00343         gConsole->Printf(KAddThumbnailToJpegFile);
00344 
00345         // Adding Exif data to JPEG file
00346         app->AddExifDataToJpegFileL(KSourceBitmap);
00347         gConsole->Printf(KExifAndThumbnailAdded);
00348 
00349         // Apply rotation operation while encoding bitmap to Jpeg
00350         app->EncodeBitmapToFileUsingOperationExtensionL(KBitmapRotateWhileEncodeToJpeg, KDestRotateFile);
00351         gConsole->Printf(KEncodeRotate, &KDestRotateFile);
00352         
00353         gConsole->Printf(KPressAKey);
00354         gConsole->Getch();
00355         
00356         // Spmo
00357         // Generating Spmo
00358         gConsole->Printf(KGeneratingSpmo);
00359         app->GeneratingSpmoL();
00360 
00361         // Generating Spmo iteratively
00362         gConsole->Printf(KGeneratingSpmoIteratively);
00363         app->GeneratingSpmoIterativelyL();
00364 
00365         gConsole->Printf(KPressAKey);
00366         gConsole->Getch();
00367         
00368         // Image Processor
00369         // Basic image processing
00370         _LIT(KFile1,"capsimageprocessorplugin.rsc");
00371         TInt imageProcessorPluginSupport;
00372         imageProcessorPluginSupport = file.FindByPath(KFile1(),&KPath());
00373         if(imageProcessorPluginSupport == KErrNone)
00374                 {
00375                 gConsole->Printf(KBasicImageProcessing);
00376                 app->BasicImageProcessingL();
00377                 // Basic image processing with effects applied
00378                 gConsole->Printf(KBasicEffectImageProcessing);
00379                 app->BasicEffectImageProcessingL();
00380             // Image processing with undo
00381                 gConsole->Printf(KEffectImageProcessingWithUndo);
00382                 app->EffectImageProcessingWithUndoL();
00383                 // Image processing with preview
00384                 gConsole->Printf(KEffectImageProcessingWithPreview);
00385                 app->EffectImageProcessingWithPreviewL();
00386                 // Image processing with overlay
00387                 gConsole->Printf(KEffectImageProcessingWithOverlay);
00388                 app->EffectImageProcessingWithOverlayL();
00389                 // Image processing with spmo
00390                 gConsole->Printf(KImageProcessingWithSpmo);
00391                 app->ImageProcessingWithSpmoL();
00392                 }
00393         
00394         // Various Image Transform Functions
00395         gConsole->Printf(KImageTransform);
00396         // Squeeze a Jpg Image in a file to a file
00397         _LIT(KFile2,"capsimagetransformplugin.rsc");
00398         TInt imageTransformPluginSupport;
00399         imageTransformPluginSupport = file.FindByPath(KFile2(),&KPath());
00400         if(imageTransformPluginSupport == KErrNone)
00401                 {
00402                 gConsole->Printf(KSqueezeFileToFile);
00403                 app->SqueezeJpgFileToFileL(KSourceJpgDatetree, KSqueezeDestJpgDatetreeFileToFile);
00404                 // Squeeze a Jpg Image in a buffer to a buffer
00405                 gConsole->Printf(KSqueezeBufferToBuffer);
00406                 app->SqueezeJpgBufferToBufferL(KSourceJpgDatetree, KSqueezeDestJpgDatetreeBufferToBuffer);
00407                 // Auto-Squeeze a Jpg Image in a file to a file
00408                 gConsole->Printf(KAutoSqueezeFileToFile);
00409                 app->AutoSqueezeJpgFileToFileL(KSourceJpgCapstest, KAutoSqueezeDestJpgCapstest);
00410                 // Rotate a Jpg Image in a file to a file
00411                 gConsole->Printf(KRotateFileToFile);
00412                 app->RotateJpgFileToFileL(KSourceJpgCapstest, KRotate90DestJpgCapstest);
00413                 // Overlay a Jpg Image in a buffer to a file to a file
00414                 gConsole->Printf(KOverlayJpgDataFileToFile);
00415                 app->OverlayJpgDataToJpgFileToFileL(KSourceJpgDatetree, KSourceJpgOverlay, KOverlayDestJpgDataFileToFile);
00416                 // Overlay a Bitmap in a buffer to a file to a file
00417                 gConsole->Printf(KOverlayBmpDataFileToFile);
00418                 app->OverlayBmpDataToJpgFileToFileL(KSourceJpgCapstest, KSourceMbmOverlay, KOverlayDestBitmapFileToFile);
00419                 // Overlay a Png Image in a file to a file to a file
00420                 gConsole->Printf(KOverlayPngFileToFile);
00421                 app->OverlayPngFileToJpgFileToFileL(KSourceJpgCapstest, KSourcePngOverlay, KOverlayDestPngFileToFile);
00422                 }
00423         gConsole->Printf(KExitMsg);
00424         gConsole->Getch();
00425         fsSession.Close();
00426         CleanupStack::PopAndDestroy(3);// app, scheduler, gConsole
00427         }
00428 
00429 
00430 GLDEF_C TInt E32Main()
00431         {
00432         __UHEAP_MARK;
00433 
00434         CTrapCleanup* cleanup = CTrapCleanup::New();
00435         if (cleanup == NULL)
00436                 {
00437                 return KErrNoMemory;
00438                 }
00439 
00440         TRAPD(err, MainL());
00441 
00442         delete cleanup;
00443         __UHEAP_MARKEND;
00444 
00445         return err;
00446         }

Generated on Thu Jan 21 10:32:59 2010 for TB10.1 Example Applications by  doxygen 1.5.3