examples/Multimedia/CameraExample/Camera_AppUi.cpp

Go to the documentation of this file.
00001 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 // This  file handles application-wide aspects of the application's UI
00015 // such as the menu bar, opening and closing files and 
00016 // exiting the application cleanly.
00017 // The code demonstrates how to perform basic and advanced operations on a camera using ECam.
00018 // Symbian does not provide the plugins for implementation of camera API. So this example runs
00019 // only if the kit you are using supports camera implementation.
00020 //
00021 
00022 
00023 
00028 #include "CameraExample.h"
00029 #include <ecamuids.hrh>
00030 #include <ecom/ecomresolverparams.h>
00031 #include <ecamadvsettings.h>
00032 #include <icl/imagedata.h>
00033 #include <camerahistogram.h>
00034 
00035 const TInt KMaxErrLength = 50;
00036 TInt error;
00037 
00038 // List of Info messages
00039 _LIT(KErrorFormat,"Error - %d (%S)");
00040 _LIT(KFeatureNotSupported, "This feature is not supported by the camera implementation");
00041 _LIT(KError,"\n Could not create the camera object due to either insufficient memory, out of bounds camera index or capability");
00042 
00043 _LIT(KNotSupported, "Not supported. So cannot be set. Try to set another value");
00044 _LIT(KSupportedFocusModes, "Getting supported focus modes");
00045 
00046 _LIT(KPrepareImageCaptureErr, "PrepareImageCaptureL() failed");
00047 _LIT(KPrepareVideoCaptureErr, "PrepareVideoCaptureL() failed");
00048 _LIT(KImageSize, "Capturing image of size %d x %d");
00049 _LIT(KVideoCapture, "Capturing video with capture rate %f and size % d x %d");
00050 _LIT(KErrMessage,"CCameraAppUi::ImageBufferReady");
00051 
00052 _LIT(KFocusModeSet, "Setting the focus mode successful");
00053 _LIT(KFocusModeRetrieval, "Retrieval of focus mode successful");
00054 _LIT(KSupportedFocusRanges, "Getting supported focus ranges");
00055 
00056 _LIT(KSupportedFocusTypes, "Getting the supported focus types");
00057 _LIT(KFocusTypeSet, "Setting the focus type to auto");
00058 _LIT(KFocusTypeRetrieval, "Retrieval of focus type successful");
00059 _LIT(KFocusRangeAuto,  "Setting focus range to automatic");
00060 _LIT(KFocusRangeRetrieval, "Retrieval of focus range successful");
00061 
00062 _LIT(KSupportedDriveModes, "Getting supported drive modes");
00063 _LIT(KDriveModeSet, "Setting drive mode");
00064 _LIT(KDriveModeRetrieval, "Getting the set drive mode");
00065 _LIT(KSupportedBracketModes, "Getting supported bracket modes");
00066 _LIT(KBracketModeRetrieval, "Getting the set bracket mode");
00067 
00068 _LIT(KSupportedSnapshotFormats, "Getting the supported formats for snapshot");
00069 _LIT(KPrepareSnapshot, "Preparing the snapshot was successful");
00070 _LIT(KPrepareSnapshotErr, "Prepare snapshot failed");
00071 _LIT(KSnapshotFormat,"Set the snapshot format to  EFormatJpeg");
00072 _LIT(KSnapshotFormatErr,"The format you are trying to set is not supported");
00073 _LIT(KStartSnapshot, "Starting the snapshot successful");
00074 _LIT(KStopSnapshot, "Snapshot stopped");
00075 
00076 _LIT(KViewFinderInactive, "View finder state inactive");
00077 _LIT(KViewFinderPause , "Pausing the view finder successful");
00078 _LIT(KViewFinderPauseErr, "Pausing the view finder failed");
00079 _LIT(KViewFinderStatePaused,  "View finder state paused");
00080 _LIT(KViewFinderResume, "Resuming view finder was successful");
00081 _LIT(KViewFinderResumeErr, "Resuming view finder failed");
00082 _LIT(KViewFinderStateActive, "View finder state active");
00083 
00084 _LIT(KCreateHistogram, "Creating the non-DSA histogram was successful");
00085 _LIT(KHistStart,"Start Histogram Successful");
00086 _LIT(KHistStartErr,"Start Histogram failed");
00087 _LIT(KHistStop,"Stopping the histogram successful");
00088 _LIT(KHistStopErr,"Stopping histogram failed");
00089 _LIT(KDestroyHistogram, "Destruction of histogram successful");
00090 _LIT(KDestroyHistogramErr, "Destruction of histogram failed");
00091 
00092 _LIT(KCreateoverlay ,"Creating overlay successful");
00093 _LIT(KCreateoverlayErr , "Creating overlay failed.Cannot proceed further");
00094 _LIT(KOverLayMode,"Set the current mode to  EModeStillImage");
00095 _LIT(KOverLayModeErr,"The mode you are trying to set is not supported");
00096 _LIT(KCurrentTypeErr,"The type you are trying to set is not supported");
00097 _LIT(KOverlayType,"Blending is set to per pixel basis");
00098 _LIT(KSetoverlayBmp , "Setting the Overlay Bitmap successful");
00099 _LIT(KSetoverlayBmpErr , "Setting the Overlay Bitmap failed");
00100 _LIT(KGetoverlayBmp, "Getting Overlay Bitmap successful");
00101 _LIT(KGetoverlayBmpErr, "Getting Overlay Bitmap failed");
00102 _LIT(KGetoverlayParams , "Getting the Overlay Bitmap successful");
00103 _LIT(KGetoverlayParamsErr , "Getting the Overlay Bitmap failed");
00104 _LIT(KSetoverlayParams , "Setting Overlay Parameters successful");
00105 _LIT(KSetoverlayParamsErr , "Setting Overlay Parameters failed");
00106 _LIT(KGetAllOverlays, "Getting All Overlays successful");
00107 _LIT(KGetAllOverlaysErr , "Getting All Overlays failed");
00108 _LIT(KReleaseOverlay, "Releasing Overlay successful");
00109 _LIT(KReleaseOverlayErr, "Releasing Overlay failed");
00110 
00111 _LIT(KGetAffectedSettings, "Getting the affected settings successful");
00112 _LIT(KGetAffectedSettingsErr, "Getting the affected settings failed");
00113 _LIT(KSupportedPresets, "Getting the supported presets");
00114 _LIT(KEmptyArray, "Getting the presets failed. The array of Uids is empty");
00115 _LIT(KSetBrightness, "Adjusting brightness to maximum value");
00116 _LIT(KImageEffect, "Set monochrome effect");
00117 
00118 
00123 void CCameraAppUi::ConstructL()
00124     {
00125     
00126     CEikAppUi::ConstructL();
00127         iAppView = new(ELeave) CCameraAppView;
00128         iAppView->ConstructL(ClientRect());
00129         
00130         AddToStackL(iAppView);
00131         TRAP(error,iCamera = CCamera::NewL(*this,0,0));
00132         if (error != KErrNone)
00133                 {
00134                 iEikonEnv->InfoMsg(KError);
00135                 User::Leave(error);
00136                 }
00137 
00138         // Asynchronous function that performs any required initialization 
00139         // and reserves the camera for exclusive use.
00140         iCamera->Reserve();
00141 
00142         }
00143 
00147 CCameraAppUi::~CCameraAppUi()
00148         {
00149         if (iCamera!=NULL)
00150                 iCamera->Release();
00151         delete iCamera;
00152                 
00153         if (iAppView)
00154                 {
00155                 RemoveFromStack(iAppView);
00156                 delete iAppView;
00157                 }
00158         ifsSession.Close();
00159         }
00160 
00161 
00166 void CCameraAppUi::HandleCommandL(TInt aCommand)
00167         {
00168 
00169         switch (aCommand)
00170                 {
00171         case ETCamCmdPowerOn:
00172                 iCamera->PowerOn();
00173                 break;
00174         case ETCamCmdPowerOff:
00175                 iCamera->PowerOff();
00176                 break;
00177         case ETCamCmdViewFinder:
00178                 ViewFinderL();
00179                 break;
00180         case ETCamCmdCaptureImage:
00181                 CaptureImageL();
00182                 break;
00183         case ETCamCmdCaptureVideo:
00184                 CaptureVideoL();
00185                 break;
00186         case ETCamCmdIncBrightness:
00187                 iCamera->SetBrightnessL(iCamera->Brightness() + 10);
00188                 break;
00189         case ETCamCmdIncContrast:
00190                 iCamera->SetContrastL(iCamera->Contrast() + 10);
00191                 break;
00192         case ETCamCmdDecBrightness:
00193                 iCamera->SetBrightnessL(iCamera->Brightness() - 10);
00194                 break;
00195         case ETCamCmdDecContrast:
00196                 iCamera->SetContrastL(iCamera->Contrast() - 10);
00197                 break;
00198         case ETCamCmdAdvancedCamFeatures:
00199                 AdvancedCamFeaturesL(); 
00200                 break;  
00201         case ETCamCmdSnapShot:
00202                 SnapShotL();
00203                 break;  
00204         case ETCamCmdDirectViewFinder:
00205                 DirectViewFinderL();    
00206                 break;  
00207         case ETCamCmdHistogram:
00208                 HistogramL();   
00209                 break;  
00210         case ETCamCmdOverLay:
00211                 OverLayL();     
00212                 break;  
00213         case ETCamCmdPreset:
00214                 PresetL();      
00215                 break;  
00216         case ETCamCmdImageProcessing:
00217                 ImageProcessingL();             
00218                 break;  
00219         case EEikCmdExit:
00220                 Exit();
00221                 break;
00222                 }
00223         }
00224 
00231 void CCameraAppUi::ViewFinderL()
00232         {
00233         TSize imageSize;
00234         iCamera->EnumerateCaptureSizes(imageSize,1,CCamera::EFormatFbsBitmapColor16M);
00235         const TPoint pos = iAppView->DrawBorders(imageSize);
00236         
00237         TRect screenRect(pos,imageSize);
00238         TRect clipRect;
00239 
00240         if (!iCamera->ViewFinderActive())
00241                 {
00242                 iCamera->StartViewFinderDirectL(iCoeEnv->WsSession(),*iCoeEnv->ScreenDevice(),*iAppView->DrawableWindow(),screenRect,clipRect);         
00243                 }
00244         else
00245                 {
00246                 iCamera->StopViewFinder();
00247                 }
00248         }
00249 
00258 void CCameraAppUi::CaptureImageL()
00259         {
00260         TSize imageSize;
00261         iCamera->EnumerateCaptureSizes(imageSize,1,CCamera::EFormatFbsBitmapColor16M);
00262         TRAP(error, iCamera->PrepareImageCaptureL(CCamera::EFormatFbsBitmapColor16M,1));
00263         if(error!= KErrNone)
00264                 {
00265                 InfoMessage(KPrepareImageCaptureErr);
00266                 User::Leave(error);     
00267                 }
00268         
00269         iCamera->CaptureImage();
00270         
00271         // Displays the captured image size
00272         TBuf<100> buffer;
00273     buffer.Format(KImageSize,imageSize.iWidth,imageSize.iHeight);
00274         InfoMessage(buffer);
00275                 
00276         }
00277 
00282 void CCameraAppUi::CaptureVideoL()
00283         {
00284         TSize frameSize;
00285         TReal32 frameRate = 0;
00286         iCamera->EnumerateVideoFrameSizes(frameSize,0,CCamera::EFormatFbsBitmapColor16M);
00287         iCamera->EnumerateVideoFrameRates(frameRate,0,CCamera::EFormatFbsBitmapColor16M,0);
00288         
00289         if (!iCamera->VideoCaptureActive())
00290                 {
00291                 TRAP(error, iCamera->PrepareVideoCaptureL(CCamera::EFormatFbsBitmapColor16M,0,0,2,1));
00292                 if(error!= KErrNone)
00293                         {
00294                         InfoMessage(KPrepareVideoCaptureErr);
00295                         User::Leave(error);     
00296                         }
00297                 
00298                 iCamera->StartVideoCapture();
00299                 
00300                 // Displays the captured video size and rate of capture
00301                 TBuf<100> videoBuf;
00302         videoBuf.Format(KVideoCapture,frameRate,frameSize.iWidth,frameSize.iHeight);
00303                 InfoMessage(videoBuf);
00304                 }
00305         else
00306                 {
00307                 iCamera->StopVideoCapture();
00308                 }       
00309         }
00310 
00332 void CCameraAppUi::HandleEvent(const TECAMEvent& /*aEvent*/)
00333         {
00334         }
00335         
00336 
00342 void CCameraAppUi::ViewFinderReady(MCameraBuffer& /*aCameraBuffer*/,TInt /*aError*/)
00343         {
00344         
00345         }
00346 
00354 void CCameraAppUi::ImageBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
00355         {
00356         if (iCamera->ViewFinderActive())
00357                 {       
00358                 iCamera->StopViewFinder();
00359                 }
00360         TBuf<KMaxErrLength> msgBuffer;
00361         if(aError)
00362                 {
00363                 msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
00364                 iEikonEnv->InfoMsg(msgBuffer);
00365                 return;
00366                 }
00367                 TRAPD(error,iAppView->DrawImage(&aCameraBuffer.BitmapL(0)));
00368                 aCameraBuffer.Release();
00369         if (error)
00370                 {
00371                 msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
00372                 iEikonEnv->InfoMsg(msgBuffer);
00373                 }
00374                 
00375         }
00387 void CCameraAppUi::VideoBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
00388         {
00389         TBuf<KMaxErrLength> msgBuffer;
00390         _LIT(KErrMessage,"CCameraAppUi::FrameBufferReady");
00391         if (aError)
00392                 {
00393                 msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
00394                 iEikonEnv->InfoMsg(msgBuffer);
00395                 return;
00396                 }
00397         TRAPD(error,iAppView->DrawImage(&aCameraBuffer.BitmapL(0)));
00398         aCameraBuffer.Release();
00399         if (error)
00400                 {
00401                 msgBuffer.Format(KErrorFormat,error,&KErrMessage);
00402                 iEikonEnv->InfoMsg(msgBuffer);
00403                 }       
00404         }
00405 
00415 void CCameraAppUi::AdvancedCamFeaturesL()
00416         {
00417         CCamera::CCameraAdvancedSettings* settings = NULL;
00418         settings = CCamera::CCameraAdvancedSettings::NewL(*iCamera);
00419         if (settings == NULL)
00420                 {
00421                 iEikonEnv->InfoMsg(KFeatureNotSupported);
00422                 return;
00423                 }
00424         CleanupStack::PushL(settings);
00425         
00426         // Assigns the focus mode to be set     
00427         CCamera::CCameraAdvancedSettings::TFocusMode focusMode = CCamera::CCameraAdvancedSettings::EFocusModeFixed;
00428         
00429         // Gets the supported modes
00430         TInt suppFocusModes = settings->SupportedFocusModes();
00431         InfoMessage(KSupportedFocusModes);
00432         
00433         // Checks if the focus mode is supported before setting it.
00434         if (focusMode & suppFocusModes)
00435             {
00436                 // Sets the focus mode if it is supported
00437             settings->SetFocusMode(focusMode);
00438             InfoMessage(KFocusModeSet);         
00439             }
00440         else
00441             {
00442             InfoMessage(KNotSupported);
00443                 // Set auto mode since other mode is not supported
00444                 CCamera::CCameraAdvancedSettings::TFocusMode focusMode = CCamera::CCameraAdvancedSettings::EFocusModeAuto;
00445                 settings->SetFocusMode(focusMode);   
00446             }
00447             
00448         // Retrieves the set focus mode 
00449         focusMode = settings->FocusMode();
00450         InfoMessage(KFocusModeRetrieval);   
00451         
00452         // Assigns the focus range to auto and checks if it is supported
00453         CCamera::CCameraAdvancedSettings::TFocusRange focusRange = CCamera::CCameraAdvancedSettings::EFocusRangeHyperfocal;
00454             
00455         // Gets the supported ranges            
00456         TInt suppRanges = settings->SupportedFocusRanges();
00457         InfoMessage(KSupportedFocusRanges);
00458         
00459         // Checks if the focus range is supported before setting it.
00460         if (focusRange & suppRanges) 
00461             {
00462                 // Sets the focus range if it is supported
00463             settings->SetFocusRange(focusRange);
00464             InfoMessage(KFocusRangeAuto);
00465             // Gets the set focus range 
00466             focusRange = settings->FocusRange();
00467                 InfoMessage(KFocusRangeRetrieval);              
00468             }
00469         else
00470             {
00471             InfoMessage(KNotSupported); 
00472             }
00473                 
00474         // Assigns the focus type to EAutoFocusTypeOff
00475         CCamera::CCameraAdvancedSettings::TAutoFocusType focusType = CCamera::CCameraAdvancedSettings::EAutoFocusTypeOff;
00476         
00477         // Gets the supported focus types
00478         TInt suppFocusTypes = settings->SupportedAutoFocusTypes();
00479         InfoMessage(KSupportedFocusTypes);
00480         
00481         // Checks if the focus type is supported before setting it.
00482         if (focusType & suppFocusTypes)
00483             {
00484             // Sets the focus type if it is supported
00485             settings->SetAutoFocusType(focusType);
00486             InfoMessage(KFocusTypeSet);                 
00487             }
00488         else
00489             {
00490             InfoMessage(KNotSupported);
00491                 // Sets another type if the above type is not supported
00492                 CCamera::CCameraAdvancedSettings::TAutoFocusType autoFocusType = CCamera::CCameraAdvancedSettings::EAutoFocusTypeSingle;
00493                 settings->SetAutoFocusType(autoFocusType);
00494             
00495             }
00496             // Retrieves the set focus mode     
00497             focusType = settings->AutoFocusType();
00498                 InfoMessage(KFocusTypeRetrieval);  
00499                 
00500         // Assigns the drive mode to the value you want to check        
00501         CCamera::CCameraAdvancedSettings::TDriveMode driveMode = CCamera::CCameraAdvancedSettings::EDriveModeSingleShot;
00502         
00503         // Gets the supported drive modes
00504         TInt suppDriveModes = settings->SupportedDriveModes();
00505         InfoMessage(KSupportedDriveModes);
00506         
00507         // Checks if the drive mode is supported before setting it.
00508         if (driveMode & suppDriveModes) 
00509             {
00510                 // Sets the drive mode.
00511             settings->SetDriveMode(driveMode);
00512             InfoMessage(KDriveModeSet);         
00513             }
00514         else
00515             {
00516             InfoMessage(KNotSupported);
00517                 // Sets auto mode if other type is not supported
00518                 CCamera::CCameraAdvancedSettings::TDriveMode defaultDriveMode = CCamera::CCameraAdvancedSettings::EDriveModeAuto;
00519                 settings->SetDriveMode(defaultDriveMode);       
00520             }
00521             
00522         // Retrieves the set drive mode 
00523         driveMode = settings->DriveMode();
00524         InfoMessage(KDriveModeRetrieval);  
00525         
00526         // Assigns bracket mode to EBracketMode3Image
00527         CCamera::CCameraAdvancedSettings::TBracketMode bracketMode = CCamera::CCameraAdvancedSettings::EBracketMode3Image;
00528         
00529         // Gets the supported bracket modes
00530         TInt suppBracketModes = settings->SupportedBracketModes();
00531         InfoMessage(KSupportedBracketModes);
00532         
00533         // Checks if the bracket mode is supported before setting it.
00534         if (bracketMode & suppBracketModes) 
00535             {
00536             settings->SetBracketMode(bracketMode);      
00537                 // Retrieve the set bracket mode        
00538                 bracketMode = settings->BracketMode();  
00539             }
00540             
00541         else
00542                 {
00543                 InfoMessage(KNotSupported);
00544                 // Sets other mode since the previously set mode is not supported
00545                 CCamera::CCameraAdvancedSettings::TBracketMode bracketMode = CCamera::CCameraAdvancedSettings::EBracketModeOff;
00546                 settings->SetBracketMode(bracketMode);
00547                 bracketMode = settings->BracketMode(); 
00548                 InfoMessage(KBracketModeRetrieval);
00549                 }
00550                 
00551         TBool redEye = settings->RedEyeReduceOn();
00552         // If red eye reduction is turned off, turn it on
00553         if(redEye == EFalse)
00554                 {
00555                 settings->SetRedEyeReduceOn(ETrue);     
00556                 }
00557         
00558         CleanupStack::PopAndDestroy(settings);
00559         }
00560 
00568 void CCameraAppUi::SnapShotL()
00569         {
00570         CCamera::CCameraSnapshot* snap = NULL;
00571         TRAPD(error, snap  = CCamera::CCameraSnapshot::NewL(*iCamera)); 
00572         if (snap == NULL)
00573                 {
00574                 iEikonEnv->InfoMsg(KFeatureNotSupported);
00575                 return;
00576                 }
00577            
00578     CleanupStack::PushL(snap);          
00579     // Gets the list of camera formats for which the 
00580     // ECam Server supports snapshots.
00581         TUint suppFormats = snap->SupportedFormats();
00582         InfoMessage(KSupportedSnapshotFormats); 
00583         
00584         CCamera::TFormat format = CCamera::EFormatJpeg;
00585         if(suppFormats & format)
00586                 {
00587                 InfoMessage(KSnapshotFormat);
00588                 }
00589         else
00590                 {
00591                 InfoMessage(KSnapshotFormatErr);
00592                 User::Leave(KErrNotSupported);
00593                 }
00594                 
00595         TSize sShotSize(90,50);
00596         TRgb bgrndColor(100,100,100);
00597     TBool aspectRatio = ETrue;
00598     TPoint orgPos(2,2);
00599      
00600     // Sets the properties of the snapshot data including 
00601     // background colour and the position of the snapshot  
00602     TRAP(error,snap->PrepareSnapshotL(format, orgPos, sShotSize, bgrndColor,aspectRatio));
00603     if(error!= KErrNone)
00604                 {
00605                 InfoMessage(KPrepareSnapshotErr);
00606                 User::Leave(error);     
00607                 }
00608                 
00609     InfoMessage(KPrepareSnapshot);
00610         
00611         TBool isActive = EFalse;
00612         isActive = User::LeaveIfError(snap->IsSnapshotActive());
00613     User::LeaveIfError(isActive);
00614     
00615     // A callback to HandleEvent() will occur when the snapshot data 
00616     // is ready to be retrieved.
00617     // On success eventUid in HandleEvent() should have the value KUidECamEventCameraSnapshot
00618         snap->StartSnapshot();
00619         InfoMessage(KStartSnapshot);
00620 
00621     // Deactivates the snapshot feature if it is active
00622     snap->StopSnapshot();
00623     InfoMessage(KStopSnapshot);
00624         CleanupStack::PopAndDestroy(snap);                      
00625         }                               
00626 
00631 void CCameraAppUi::DirectViewFinderL()
00632         {
00633         CCamera::CCameraDirectViewFinder* directviewfinder = NULL;
00634         TRAPD(error, directviewfinder  = CCamera::CCameraDirectViewFinder::NewL(*iCamera));     
00635         if (directviewfinder == NULL)
00636                 {
00637                 iEikonEnv->InfoMsg(KFeatureNotSupported);
00638                 return;
00639                 }
00640         
00641         CleanupStack::PushL(directviewfinder);
00642 
00643         // Gets the default viewfinder state
00644         directviewfinder->ViewFinderState();
00645         InfoMessage(KViewFinderInactive);       
00646         
00647         // Assumption is that meanwhile direct viewfinder has been started. This would be done by calling CCamera::StartViewFinderDirectL(). 
00648         // This function starts the direct viewfinder and hence changes the state to active. 
00649         // Also performs initial boundary checking that 'viewfinder remains inactive before its called'. So, the vfstate changes to active.
00650         // The next step is to pause the direct viewfinder
00651         
00652         TRAP(error, directviewfinder->PauseViewFinderDirectL());
00653         InfoMessage(error, KViewFinderPause, KViewFinderPauseErr);      
00654 
00655         directviewfinder->ViewFinderState();
00656         InfoMessage(KViewFinderStatePaused);    
00657         
00658         // The next step is to resume the direct viewfinder
00659         TRAP(error, directviewfinder->ResumeViewFinderDirectL());
00660         InfoMessage(error, KViewFinderResume, KViewFinderResumeErr);    
00661 
00662         directviewfinder->ViewFinderState();
00663         InfoMessage(KViewFinderStateActive);    
00664         
00665         CleanupStack::PopAndDestroy(directviewfinder);
00666         }
00667 
00676 void CCameraAppUi::HistogramL()
00677         {
00678         CCamera::CCameraHistogram* hist = NULL;
00679         
00680         TRAPD(error, hist = CCamera::CCameraHistogram::NewL(*iCamera));
00681         if (hist == NULL)
00682                 {
00683                 iEikonEnv->InfoMsg(KFeatureNotSupported);
00684                 return;
00685                 }
00686         CleanupStack::PushL(hist);
00687         
00688         // Gets the supported set of values
00689         TUint32 suppHists = hist->SupportedHistograms();
00690         
00691         // The array should not be empty 
00692         if (suppHists == 0)
00693                 {
00694                 User::Leave(KErrNotSupported);
00695                 }
00696                 
00697         // Assigns the histogram type to ELuminance     
00698         CCamera::CCameraHistogram::THistogramType histType = CCamera::CCameraHistogram::ELuminance;
00699                 
00700         // Checks if the histogram type is supported before setting it.
00701         if (suppHists & histType)
00702             {
00703                 // Prepare Non-DSA based histogram
00704                 TUint histhandle = 0;
00705                 
00706                 TRAP(error, histhandle = hist->PrepareHistogramL(CCamera::CCameraHistogram::ELuminance));
00707                 if(error != KErrNone)
00708                         {
00709                         User::Leave(error);
00710                         }
00711                 InfoMessage(KCreateHistogram);
00712         
00713                 // Starts getting histogram notifications               
00714                 TRAP(error,hist->StartHistogramL(histhandle));
00715                 InfoMessage(error, KHistStart, KHistStartErr);  
00716             
00717                 // After a KUidECamEventCameraHistogram event is received in HandleEventL(), a  
00718                 // histogram data buffer can be obtained using HistogramDataL(). The data buffer
00719                 // should be released after use, using MHistogramBuffer::Release().
00720                 // TRAP(error,MHistogramBuffer& buffer = hist->HistogramDataL());
00721         
00722                 // Stops getting histogram notifications
00723                 TRAP(error, hist->StopHistogramL(histhandle));
00724         InfoMessage(error, KHistStop, KHistStopErr);
00725         
00726                 // Destroys the histogram on the ECam server and releases its handle
00727         TRAP(error, hist->DestroyHistogramL(histhandle));
00728                 InfoMessage(error, KDestroyHistogram,KDestroyHistogramErr);
00729         
00730                 }
00731                 else
00732                 {
00733                 InfoMessage(KNotSupported);
00734                 User::Leave(KErrNotSupported);    
00735                 }
00736                 CleanupStack::PopAndDestroy(hist);
00737         }
00738 
00746 void CCameraAppUi::OverLayL()
00747         {
00748         CCamera::CCameraOverlay* overlay = NULL;
00749 
00750         TRAPD(error, overlay = CCamera::CCameraOverlay::NewL(*iCamera));
00751         if (overlay == NULL)
00752                 {
00753                 iEikonEnv->InfoMsg(KFeatureNotSupported);
00754                 return;
00755                 }
00756 
00757         CleanupStack::PushL(overlay);
00758         
00759         CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
00760         CleanupStack::PushL(bitmap);            
00761         
00762         // Creates an overlay of hardcoded size 20x20
00763         User::LeaveIfError(bitmap->Create(TSize(20,20), EColor16M));
00764 
00765         CCamera::CCameraOverlay::TOverlayParameters parameters;
00766         
00767         CCamera::CCameraOverlay::TOverlaySupportInfo suppInfo;
00768         // Gets information on the overlay functionality supported by the ECam server.
00769         overlay->GetOverlaySupport(suppInfo);
00770         
00771         TUint currentModes = suppInfo.iSupportedModes;
00772         if(currentModes & CCamera::CCameraOverlay::EModeStillImage)
00773                 {
00774                 // Sets the camera mode in which the image overlay can be used.
00775                 parameters.iCurrentModes = CCamera::CCameraOverlay::EModeStillImage;
00776                 InfoMessage(KOverLayMode);
00777                 }
00778         else
00779                 {
00780                 InfoMessage(KOverLayModeErr);
00781                 User::Leave(KErrNotSupported);
00782                 }
00783                 
00784         TUint currentTypes = suppInfo.iSupportedTypes;
00785         if(currentTypes & CCamera::CCameraOverlay::EPerPixel)
00786                 {
00787                 // Sets the camera type in which the image overlay can be used
00788                 parameters.iCurrentTypes = CCamera::CCameraOverlay::EPerPixel;
00789                 InfoMessage(KOverlayType);
00790                 // Sets the camera type to EPerPixel needs this value to be set to zero.
00791                 parameters.iAlphaValue = 0;     
00792                 }
00793         else
00794                 {
00795                 InfoMessage(KCurrentTypeErr);
00796                 User::Leave(KErrNotSupported);
00797                 }
00798         
00799         // Sets the size of the overlay image in pixels.        
00800         //parameters.Size() = TSize(20,20);
00801 
00802         // Top left corner within the original image, where the overlay image is to be blended.         
00803         parameters.iPosition = TPoint(2,2);     
00804         
00805         // The z-order of the overlay to indicate depth 
00806         parameters.iZOrder = 1;
00807         
00808         // Creates an image overlay object on the ECam server.
00809         // Returns handle to the newly created object.
00810         TUint overlayHandle =0; 
00811         TRAP(error, overlayHandle = overlay->CreateOverlayL(parameters, bitmap));
00812         if(error!= KErrNone)
00813                 {
00814                 InfoMessage(KCreateoverlayErr);
00815                 User::Leave(error);     
00816                 }
00817         
00818         InfoMessage(KCreateoverlay);
00819         
00820         // Allows the overlay image data to be changed if it was 
00821         // not specified when the overlay was created using CreateOverlayL()
00822         TRAP(error, overlay->SetOverlayBitmapL(overlayHandle, bitmap));
00823         InfoMessage(error, KSetoverlayBmp, KSetoverlayBmpErr);  
00824 
00825         // Gets the overlay image data for a specified overlay.
00826         TRAP(error, overlay->GetOverlayBitmapL(overlayHandle, bitmap));
00827         InfoMessage(error, KGetoverlayBmp, KGetoverlayBmpErr);  
00828 
00829         // Gets the parameters that characterize a given overlay.
00830         TRAP(error, overlay->GetOverlayParametersL(overlayHandle, parameters));
00831         InfoMessage(error, KGetoverlayParams, KGetoverlayParamsErr);    
00832         
00833         // Sets new parameters that characterize a given overlay.       
00834         TRAP(error, overlay->SetOverlayParametersL(overlayHandle, parameters));
00835         InfoMessage(error, KSetoverlayParams, KSetoverlayParamsErr);    
00836          
00837         RArray<TUint> overlayHandlesArray;
00838         // Gets all the overlay handles maintained by the ECam server. 
00839         TRAP(error, overlay->GetAllOverlaysInZOrderL(overlayHandlesArray));
00840         InfoMessage(error, KGetAllOverlays, KGetAllOverlaysErr);        
00841                 
00842     // Releases the overlay handle.
00843     TRAP(error, overlay->ReleaseOverlay(overlayHandle));
00844     InfoMessage(error,KReleaseOverlay, KReleaseOverlayErr);
00845     
00846         CleanupStack::PopAndDestroy(2, overlay); //bitmap, overlay
00847     }
00848 
00856 void CCameraAppUi::PresetL()
00857         {
00858         CCamera::CCameraPresets* presets = NULL;
00859         TRAPD(error, presets  = CCamera::CCameraPresets::NewL(*iCamera));
00860         if (presets == NULL)
00861                 {
00862                 iEikonEnv->InfoMsg(KFeatureNotSupported);
00863                 return;
00864                 }
00865         
00866         CleanupStack::PushL(presets);
00867         
00868         // Gets the supported set of values  
00869         RArray<TUid> resultSet;
00870         
00871         // Gets the presets supported by the camera. 
00872         // These are identified by UIDs and relate to a known predefined outcome. 
00873         TRAP(error,presets->GetSupportedPresetsL(resultSet));
00874         InfoMessage(error,KSupportedPresets, KEmptyArray);
00875                 
00876         // Sets preset after checking if it is supported
00877         TUid inputEventUid = KUidECamPresetOutdoor;
00878         TInt index = resultSet.Find(inputEventUid);
00879         if(index == -1)
00880                 {
00881                 User::Leave(KErrNotFound);      
00882                 }
00883         
00884         presets->SetPreset(inputEventUid);
00885 
00886         // All the settings which are related to the preset in question will 
00887         // be included in the list, even though the value might not have changed.
00888         TRAP(error,presets->GetAffectedSettingsL(resultSet));
00889         
00890         InfoMessage(error, KGetAffectedSettings, KGetAffectedSettingsErr);
00891         resultSet.Reset();
00892         CleanupStack::PopAndDestroy(presets);
00893         }
00894 
00895 
00902 void CCameraAppUi::ImageProcessingL()
00903         {
00904         CCamera::CCameraImageProcessing* imageprocess = NULL;
00905         imageprocess = CCamera::CCameraImageProcessing::NewL(*iCamera);
00906         if (imageprocess == NULL)
00907                 {
00908                 iEikonEnv->InfoMsg(KFeatureNotSupported);
00909                 return;
00910                 }
00911 
00912         CleanupStack::PushL(imageprocess);
00913         
00914         // Gets array of supported transformations
00915         RArray<TUid> supportedTransforms;       
00916     CleanupClosePushL(supportedTransforms);     
00917         imageprocess->GetSupportedTransformationsL(supportedTransforms);
00918         
00919         // Uses the adjust brightness transformation
00920         TUid transformUid = KUidECamEventImageProcessingAdjustBrightness;
00921         if (supportedTransforms.Find(transformUid) != KErrNotFound)
00922                 {
00923                 // Reads a list of the supported effects into an array
00924                 RArray<TInt> supportedValues;
00925             CleanupClosePushL(supportedValues);                         
00926                 TValueInfo info = ENotActive;
00927                 imageprocess->GetTransformationSupportedValuesL(transformUid, supportedValues, info);
00928                 
00929                 // For the brightness transform, expects supported values to give the minimum and maximum range
00930                 if (info == EContinuousRangeMinMax) 
00931                         {                       
00932                         // Adjusts brightness by the first of the supported values
00933                         TInt brightValue = supportedValues[1];
00934                         imageprocess->SetTransformationValue(transformUid, brightValue);
00935                         InfoMessage(KSetBrightness);
00936                         }
00937                 CleanupStack::PopAndDestroy(); // supportedValues
00938                 }
00939         
00940         // Uses the monochrome effect   
00941         transformUid = KUidECamEventImageProcessingEffect;
00942         if (supportedTransforms.Find(transformUid) != KErrNotFound)
00943                 {
00944                 // Reads a list of the supported effects into an array
00945                 RArray<TInt> supportedValues;
00946             CleanupClosePushL(supportedValues);                         
00947                 TValueInfo info = ENotActive;
00948                 imageprocess->GetTransformationSupportedValuesL(transformUid, supportedValues, info);
00949                 // For effects, expects first member of the supported values to a bitfield of the supported effects
00950                 TInt effects = supportedValues[0];
00951                 CleanupStack::PopAndDestroy(); // supportedValues               
00952                 if(effects & CCamera::CCameraImageProcessing::EEffectMonochrome)
00953                 {       
00954                         imageprocess->SetTransformationValue(transformUid, CCamera::CCameraImageProcessing::EEffectMonochrome);
00955                         InfoMessage(KImageEffect);
00956                         }
00957                 }
00958 
00959         CleanupStack::PopAndDestroy(2); //supportedTransforms, imageprocess
00960         }
00961 
00967 void CCameraAppUi::InfoMessage(const TDesC& aMsg)
00968         {
00969         iEikonEnv->InfoMsg(aMsg);
00970         User::After(500000); // pause .5 seconds
00971         }
00972 
00980 void CCameraAppUi::InfoMessage(TInt aError, const TDesC& aSuccessMsg, const TDesC& aErrMsg)
00981         {
00982         if (aError==KErrNone) iEikonEnv->InfoMsg(aSuccessMsg); else iEikonEnv->InfoMsg(aErrMsg);
00983         User::After(500000); // pause .5 seconds
00984         }
00985 

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