Update contrib.
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include <testcameraapp.rsg>
18 #include "TestCameraApp.h"
19 #include "TestCameraApp.hrh"
20 #include "TestCamera.h"
22 const TInt KMaxErrLength=50;
23 _LIT(KErrorFormat,"Error - %d (%S)");
29 void CTCamAppUi::ConstructL()
31 CEikAppUi::ConstructL();
32 iAppView = new(ELeave) CTCamAppView;
33 iAppView->ConstructL(ClientRect());
34 AddToStackL(iAppView);
36 // The plugin relies on a specific file existing
37 // hence this has to be created.
38 CreateDependencyFileL();
40 iCamera = CCamera::NewL(*this,0,0);
42 iCameraAdvSet = CCamera::CCameraAdvancedSettings::NewL(*iCamera);
43 iCameraPresets = CCamera::CCameraPresets::NewL(*iCamera);
44 iCameraImgProc = CCamera::CCameraImageProcessing::NewL(*iCamera);
45 iCameraSnapshot = CCamera::CCameraSnapshot::NewL(*iCamera);
50 CTCamAppUi::~CTCamAppUi()
55 delete iCameraSnapshot;
56 delete iCameraImgProc;
57 delete iCameraPresets;
61 // as the application is being closed, delete the file
62 // so that the plugin will not be reactivated accidentaly
63 RemoveDependencyFile();
67 RemoveFromStack(iAppView);
72 void CTCamAppUi::HandleCommandL(TInt aCommand)
79 case ETCamCmdPowerOff:
82 case ETCamCmdViewFinder:
85 case ETCamCmdCaptureImage:
88 case ETCamCmdBurstMode:
91 case ETCamCmdCaptureVideo:
94 case ETCamCmdIncBrightness:
95 iCamera->SetBrightnessL(iCamera->Brightness() + 10);
97 case ETCamCmdIncContrast:
98 iCamera->SetContrastL(iCamera->Contrast() + 10);
100 case ETCamCmdDecBrightness:
101 iCamera->SetBrightnessL(iCamera->Brightness() - 10);
103 case ETCamCmdDecContrast:
104 iCamera->SetContrastL(iCamera->Contrast() - 10);
106 case ETCamCmdResetBrightness:
107 iCamera->SetBrightnessL(0);
109 case ETCamCmdResetContrast:
110 iCamera->SetContrastL(0);
112 case ETCamCmdIncNumBurstImages:
113 iCameraAdvSet->SetBurstImages(iCameraAdvSet->BurstImages() + 1);
115 case ETCamCmdDecNumBurstImages:
116 iCameraAdvSet->SetBurstImages(iCameraAdvSet->BurstImages() - 1);
118 case ETCamCmdResetNumBurstImages:
119 iCameraAdvSet->SetBurstImages(4);
122 case ETCamCmdFactoryPreset:
123 iCameraPresets->SetPreset(KUidECamPresetFactoryDefault);
126 case ETCamCmdOutdoorPreset:
127 iCameraPresets->SetPreset(KUidECamPresetOutdoor);
130 case ETCamCmdOutdoorSportPreset:
131 iCameraPresets->SetPreset(KUidECamPresetOutdoorSport);
134 case ETCamCmdFogPreset:
135 iCameraPresets->SetPreset(KUidECamPresetFog);
138 case ETCamCmdNightPartyIndoorPreset:
139 iCameraPresets->SetPreset(KUidECamPresetNightPartyIndoor);
142 case ETCamCmdTextDocumentPreset:
143 iCameraPresets->SetPreset(KUidECamPresetTextDocument);
146 case ETCamCmdImgProcIncBrightness:
147 IncImgProcAdjustmentL(KUidECamEventImageProcessingAdjustBrightness);
150 case ETCamCmdImgProcDecBrightness:
151 DecImgProcAdjustmentL(KUidECamEventImageProcessingAdjustBrightness);
154 case ETCamCmdImgProcIncContrast:
155 IncImgProcAdjustmentL(KUidECamEventImageProcessingAdjustContrast);
158 case ETCamCmdImgProcDecContrast:
159 DecImgProcAdjustmentL(KUidECamEventImageProcessingAdjustContrast);
162 case ETCamCmdEnableSnapshot:
166 case ETCamCmdDisableSnapshot:
176 void CTCamAppUi::ViewFinderL()
179 iCamera->EnumerateCaptureSizes(imageSize,1,CCamera::EFormatFbsBitmapColor16M);
180 const TPoint pos = iAppView->DrawBorders(imageSize);
181 TRect screenRect(pos,imageSize);
184 if (!iCamera->ViewFinderActive())
186 iCamera->StartViewFinderDirectL(iCoeEnv->WsSession(),*iCoeEnv->ScreenDevice(),*iAppView->DrawableWindow(),screenRect,clipRect);
190 iCamera->StopViewFinder();
194 void CTCamAppUi::BurstModeL()
198 User::Leave(KErrNotSupported);
201 if(CCamera::CCameraAdvancedSettings::EDriveModeBurst & iCameraAdvSet->SupportedDriveModes() )
203 iCameraAdvSet->SetDriveMode(CCamera::CCameraAdvancedSettings::EDriveModeBurst);
207 User::Leave(KErrNotSupported);
211 void CTCamAppUi::EnableSnapshotL()
213 if(!iCameraSnapshot->IsSnapshotActive())
216 iCamera->EnumerateCaptureSizes(size,1,CCamera::EFormatFbsBitmapColor16M);
217 if(iCameraSnapshot->SupportedFormats() & CCamera::EFormatFbsBitmapColor4K)
219 iCameraSnapshot->PrepareSnapshotL(CCamera::EFormatFbsBitmapColor4K, TPoint(0,0), size, KRgbWhite, EFalse);
220 iCameraSnapshot->StartSnapshot();
225 void CTCamAppUi::DisableSnapshot()
227 if(iCameraSnapshot->IsSnapshotActive())
229 iCameraSnapshot->StopSnapshot();
233 void CTCamAppUi::SingleShotL()
237 User::Leave(KErrNotSupported);
240 if(CCamera::CCameraAdvancedSettings::EDriveModeSingleShot & iCameraAdvSet->SupportedDriveModes() )
242 iCameraAdvSet->SetDriveMode(CCamera::CCameraAdvancedSettings::EDriveModeSingleShot);
246 User::Leave(KErrNotSupported);
250 void CTCamAppUi::CaptureImageL()
253 iCamera->EnumerateCaptureSizes(size,1,CCamera::EFormatFbsBitmapColor16M);
254 iCamera->PrepareImageCaptureL(CCamera::EFormatFbsBitmapColor16M,1);
255 iCamera->CaptureImage();
258 void CTCamAppUi::CaptureVideoL()
260 if (!iCamera->VideoCaptureActive())
262 iCameraSnapshot->StopSnapshot();
266 iCamera->EnumerateVideoFrameSizes(size,0,CCamera::EFormatFbsBitmapColor16M);
267 iCamera->EnumerateVideoFrameRates(rate,0,CCamera::EFormatFbsBitmapColor16M,0);
268 iCamera->PrepareVideoCaptureL(CCamera::EFormatFbsBitmapColor16M,0,0,2,1);
269 iCamera->StartVideoCapture();
273 iCamera->StopVideoCapture();
277 void CTCamAppUi::IncImgProcAdjustmentL(TUid aTransformation)
281 User::Leave(KErrNotSupported);
284 RArray<TUid> supportedTransformations;
285 CleanupClosePushL(supportedTransformations);
286 iCameraImgProc->GetSupportedTransformationsL(supportedTransformations);
288 TInt error = supportedTransformations.Find(aTransformation);
289 CleanupStack::PopAndDestroy();
291 if(error == KErrNotFound)
297 User::LeaveIfError(iCameraImgProc->GetTransformationValue(aTransformation, valuetx));
299 iCameraImgProc->SetTransformationValue(aTransformation, valuetx + 10);
302 void CTCamAppUi::DecImgProcAdjustmentL(TUid aTransformation)
306 User::Leave(KErrNotSupported);
309 RArray<TUid> supportedTransformations;
310 CleanupClosePushL(supportedTransformations);
311 iCameraImgProc->GetSupportedTransformationsL(supportedTransformations);
313 TInt error = supportedTransformations.Find(aTransformation);
314 CleanupStack::PopAndDestroy();
316 if(error == KErrNotFound)
322 User::LeaveIfError(iCameraImgProc->GetTransformationValue(aTransformation, valuetx));
324 iCameraImgProc->SetTransformationValue(aTransformation, valuetx - 10);
327 void CTCamAppUi::ReserveComplete(TInt /*aError*/)
331 void CTCamAppUi::PowerOnComplete(TInt /*aError*/)
335 void CTCamAppUi::ViewFinderFrameReady(CFbsBitmap& /*aFrame*/)
339 void CTCamAppUi::ImageReady(CFbsBitmap* aBitmap,HBufC8* /*aData*/,TInt aError)
341 TBuf<KMaxErrLength> msgBuffer;
342 _LIT(KErrMessage,"CTCamAppUi::ImageReady");
345 iAppView->DrawImage(aBitmap);
350 msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
351 iEikonEnv->InfoMsg(msgBuffer);
355 void CTCamAppUi::FrameBufferReady(MFrameBuffer* aFrameBuffer,TInt aError)
357 TBuf<KMaxErrLength> msgBuffer;
358 _LIT(KErrMessage,"CTCamAppUi::FrameBufferReady");
361 msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
362 iEikonEnv->InfoMsg(msgBuffer);
365 TRAPD(error,iAppView->DrawImage(aFrameBuffer->FrameL(0)));
366 aFrameBuffer->Release();
369 msgBuffer.Format(KErrorFormat,error,&KErrMessage);
370 iEikonEnv->InfoMsg(msgBuffer);
374 void CTCamAppUi::HandleEvent(const TECAMEvent& aEvent)
376 if(!TECAMEvent2::IsEventEncapsulationValid(aEvent))
378 HandleEvent1(aEvent);
382 HandleEvent2(static_cast<const TECAMEvent2&>(aEvent));
386 void CTCamAppUi::HandleEvent2(const TECAMEvent2& /*aEvent2*/)
391 void CTCamAppUi::HandleEvent1(const TECAMEvent& aEvent)
393 TBuf<KMaxErrLength> msgBuffer;
395 switch(aEvent.iEventType.iUid)
397 case KUidECamEventCameraSettingDriveModeUidValue:
399 if(!aEvent.iErrorCode)
401 TRAPD(error,CaptureImageL());
404 _LIT(KErrMessage,"CaptureImage");
405 msgBuffer.Format(KErrorFormat,error,&KErrMessage);
406 iEikonEnv->InfoMsg(msgBuffer);
411 _LIT(KErrMessage,"SettingDriveMode");
412 msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
413 iEikonEnv->InfoMsg(msgBuffer);
417 case KUidECamEventBurstImagesUidValue:
419 if(aEvent.iErrorCode)
421 _LIT(KErrMessage,"SettingNumOfBurstImage");
422 msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
423 iEikonEnv->InfoMsg(msgBuffer);
427 case KUidECamEventSnapshotUidValue:
429 if(aEvent.iErrorCode)
431 _LIT(KErrMessage,"SnapshotDataNotification");
432 msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
433 iEikonEnv->InfoMsg(msgBuffer);
437 if(iCamera->ViewFinderActive())
439 iCamera->StopViewFinder();
442 TRAPD(error, SnapshotDataDisplayL());
444 if(error != KErrNone)
446 _LIT(KErrMessage,"SnapshotDataDisplay");
447 msgBuffer.Format(KErrorFormat,error,&KErrMessage);
448 iEikonEnv->InfoMsg(msgBuffer);
454 case KUidECamPresetFactoryDefaultUidValue:
456 if(aEvent.iErrorCode)
458 _LIT(KErrMessage,"FactoryPreset");
459 msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
460 iEikonEnv->InfoMsg(msgBuffer);
465 case KUidECamPresetOutdoorUidValue:
467 if(aEvent.iErrorCode)
469 _LIT(KErrMessage,"OutdoorPreset");
470 msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
471 iEikonEnv->InfoMsg(msgBuffer);
476 case KUidECamPresetOutdoorSportUidValue:
478 if(aEvent.iErrorCode)
480 _LIT(KErrMessage,"OutdoorSportPreset");
481 msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
482 iEikonEnv->InfoMsg(msgBuffer);
487 case KUidECamPresetFogUidValue:
489 if(aEvent.iErrorCode)
491 _LIT(KErrMessage,"FogPreset");
492 msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
493 iEikonEnv->InfoMsg(msgBuffer);
498 case KUidECamPresetNightPartyIndoorUidValue:
500 if(aEvent.iErrorCode)
502 _LIT(KErrMessage,"NightPartyIndoorPreset");
503 msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
504 iEikonEnv->InfoMsg(msgBuffer);
509 case KUidECamPresetTextDocumentUidValue:
511 if(aEvent.iErrorCode)
513 _LIT(KErrMessage,"TextDocumentPreset");
514 msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
515 iEikonEnv->InfoMsg(msgBuffer);
520 case KUidECamEventImageProcessingAdjustBrightnessUidValue:
522 if(aEvent.iErrorCode)
524 _LIT(KErrMessage,"ImageProcessingAdjustBrightness");
525 msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
526 iEikonEnv->InfoMsg(msgBuffer);
531 case KUidECamEventImageProcessingAdjustContrastUidValue:
533 if(aEvent.iErrorCode)
535 _LIT(KErrMessage,"ImageProcessingAdjustContrast");
536 msgBuffer.Format(KErrorFormat,aEvent.iErrorCode,&KErrMessage);
537 iEikonEnv->InfoMsg(msgBuffer);
547 void CTCamAppUi::ViewFinderReady(MCameraBuffer& /*aCameraBuffer*/,TInt /*aError*/)
552 void CTCamAppUi::ImageBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
554 TBuf<KMaxErrLength> msgBuffer;
555 _LIT(KErrMessage,"CTCamAppUi::ImageBufferReady");
558 msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
559 iEikonEnv->InfoMsg(msgBuffer);
562 if(!iCameraSnapshot->IsSnapshotActive())
564 if (iCamera->ViewFinderActive())
566 iCamera->StopViewFinder();
568 TRAP(aError,iAppView->DrawImage(&aCameraBuffer.BitmapL(0)));
571 aCameraBuffer.Release();
575 msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
576 iEikonEnv->InfoMsg(msgBuffer);
581 void CTCamAppUi::VideoBufferReady(MCameraBuffer& aCameraBuffer,TInt aError)
583 TBuf<KMaxErrLength> msgBuffer;
584 _LIT(KErrMessage,"CTCamAppUi::FrameBufferReady");
587 msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
588 iEikonEnv->InfoMsg(msgBuffer);
591 TRAPD(error,iAppView->DrawImage(&aCameraBuffer.BitmapL(0)));
592 aCameraBuffer.Release();
595 msgBuffer.Format(KErrorFormat,error,&KErrMessage);
596 iEikonEnv->InfoMsg(msgBuffer);
600 void CTCamAppUi::SnapshotDataDisplayL()
604 RTestCameraFrameBuffer& buffer = static_cast<RTestCameraFrameBuffer&>(iCameraSnapshot->SnapshotDataL(array));
605 iAppView->DrawImage(&buffer.BitmapL(0));
610 void CTCamAppUi::CreateDependencyFileL()
612 // enforce dependency
613 // create the file the plugin depends on.
614 User::LeaveIfError(ifsSession.Connect());
616 TInt err = file.Replace(ifsSession, KTestCameraPluginName, EFileShareAny);
620 User::LeaveIfError(KErrNotSupported);
624 void CTCamAppUi::RemoveDependencyFile()
626 ifsSession.Delete(KTestCameraPluginName);
634 CTCamAppView::CTCamAppView():
639 void CTCamAppView::ConstructL(const TRect& /*aRect*/)
643 SetExtentToWholeScreen();
647 CTCamAppView::~CTCamAppView()
651 void CTCamAppView::DrawImage(CFbsBitmap* aImage) const
653 CWindowGc& gc = SystemGc();
654 gc.Activate(Window());
655 TRect drawRect=Rect();
657 pos.iX = (3 * drawRect.iBr.iX / 4) - (aImage->SizeInPixels().iWidth / 2);
658 pos.iY = (drawRect.iBr.iY - aImage->SizeInPixels().iWidth) / 2;
659 gc.BitBlt(pos,aImage);
660 TRect border(pos,aImage->SizeInPixels());
664 iCoeEnv->WsSession().Flush();
667 void CTCamAppView::Draw(const TRect& /*aRect*/) const
669 CWindowGc& gc = SystemGc();
670 TRect drawRect(Rect());
671 drawRect.Shrink(1,1);
672 gc.DrawRect(drawRect);
676 TPoint CTCamAppView::DrawBorders(const TSize& aSize) const
678 CWindowGc& gc = SystemGc();
679 gc.Activate(Window());
680 TRect drawRect(Rect());
682 pos.iX = (drawRect.iBr.iX / 4) - (aSize.iWidth / 2);
683 pos.iY = (drawRect.iBr.iY - aSize.iWidth) / 2;
684 TRect border(pos,aSize);
686 gc.SetPenColor(KRgbBlack);
689 iCoeEnv->WsSession().Flush();
697 CTCamDocument::CTCamDocument(CEikApplication& aApp)
702 CEikAppUi* CTCamDocument::CreateAppUiL()
704 return new(ELeave) CTCamAppUi;
711 TUid CTCamApp::AppDllUid() const
713 return KUidTestCameraApp;
716 CApaDocument* CTCamApp::CreateDocumentL()
718 return new(ELeave) CTCamDocument(*this);
724 // Base factory function
727 #include <eikstart.h>
728 LOCAL_C CApaApplication* NewApplication()
737 GLDEF_C TInt E32Main()
739 return EikStart::RunApplication(NewApplication);