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"
21 const TInt KMaxErrLength=50;
22 _LIT(KErrorFormat,"Error - %d (%S)");
28 void CTCamAppUi::ConstructL()
31 iAppView = new(ELeave) CTCamAppView;
32 iAppView->ConstructL(ClientRect());
33 AddToStackL(iAppView);
35 iCamera = CCamera::NewL(*this,0);
39 CTCamAppUi::~CTCamAppUi()
45 RemoveFromStack(iAppView);
50 void CTCamAppUi::HandleCommandL(TInt aCommand)
57 case ETCamCmdPowerOff:
60 case ETCamCmdViewFinder:
63 case ETCamCmdCaptureImage:
66 case ETCamCmdCaptureVideo:
69 case ETCamCmdIncBrightness:
70 iCamera->SetBrightnessL(iCamera->Brightness() + 10);
72 case ETCamCmdIncContrast:
73 iCamera->SetContrastL(iCamera->Contrast() + 10);
75 case ETCamCmdDecBrightness:
76 iCamera->SetBrightnessL(iCamera->Brightness() - 10);
78 case ETCamCmdDecContrast:
79 iCamera->SetContrastL(iCamera->Contrast() - 10);
81 case ETCamCmdResetBrightness:
82 iCamera->SetBrightnessL(0);
84 case ETCamCmdResetContrast:
85 iCamera->SetContrastL(0);
93 void CTCamAppUi::ViewFinderL()
96 iCamera->EnumerateCaptureSizes(imageSize,1,CCamera::EFormatFbsBitmapColor16M);
97 const TPoint pos = iAppView->DrawBorders(imageSize);
98 TRect screenRect(pos,imageSize);
101 if (!iCamera->ViewFinderActive())
102 iCamera->StartViewFinderDirectL(iCoeEnv->WsSession(),*iCoeEnv->ScreenDevice(),*iAppView->DrawableWindow(),screenRect,clipRect);
104 iCamera->StopViewFinder();
107 void CTCamAppUi::CaptureImageL()
110 iCamera->EnumerateCaptureSizes(size,1,CCamera::EFormatFbsBitmapColor16M);
111 iCamera->PrepareImageCaptureL(CCamera::EFormatFbsBitmapColor16M,1);
112 iCamera->CaptureImage();
115 void CTCamAppUi::CaptureVideoL()
117 if (!iCamera->VideoCaptureActive())
121 iCamera->EnumerateVideoFrameSizes(size,0,CCamera::EFormatFbsBitmapColor16M);
122 iCamera->EnumerateVideoFrameRates(rate,0,CCamera::EFormatFbsBitmapColor16M,0);
123 iCamera->PrepareVideoCaptureL(CCamera::EFormatFbsBitmapColor16M,0,0,2,1);
124 iCamera->StartVideoCapture();
127 iCamera->StopVideoCapture();
130 void CTCamAppUi::ReserveComplete(TInt /*aError*/)
134 void CTCamAppUi::PowerOnComplete(TInt /*aError*/)
138 void CTCamAppUi::ViewFinderFrameReady(CFbsBitmap& /*aFrame*/)
142 void CTCamAppUi::ImageReady(CFbsBitmap* aBitmap,HBufC8* /*aData*/,TInt aError)
144 TBuf<KMaxErrLength> msgBuffer;
145 _LIT(KErrMessage,"CTCamAppUi::ImageReady");
148 iAppView->DrawImage(aBitmap);
153 msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
154 iEikonEnv->InfoMsg(msgBuffer);
158 void CTCamAppUi::FrameBufferReady(MFrameBuffer* aFrameBuffer,TInt aError)
160 TBuf<KMaxErrLength> msgBuffer;
161 _LIT(KErrMessage,"CTCamAppUi::FrameBufferReady");
164 msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
165 iEikonEnv->InfoMsg(msgBuffer);
168 TRAPD(error,iAppView->DrawImage(aFrameBuffer->FrameL(0)));
169 aFrameBuffer->Release();
172 msgBuffer.Format(KErrorFormat,error,&KErrMessage);
173 iEikonEnv->InfoMsg(msgBuffer);
177 _LIT(KContrastDialogTitle,"Contrast");
178 _LIT(KBrightnessDialogTitle,"Brightness");
184 CTCamAppView::CTCamAppView():
188 void CTCamAppView::ConstructL(const TRect& aRect)
196 CTCamAppView::~CTCamAppView()
199 void CTCamAppView::DrawImage(CFbsBitmap* aImage) const
201 CWindowGc& gc = SystemGc();
202 gc.Activate(Window());
203 TRect drawRect(Rect());
205 pos.iX = (drawRect.iBr.iX - aImage->SizeInPixels().iWidth) / 2;
206 pos.iY = (drawRect.iBr.iY - aImage->SizeInPixels().iHeight) / 2;
207 gc.BitBlt(pos,aImage);
209 iCoeEnv->WsSession().Flush();
212 void CTCamAppView::Draw(const TRect& /*aRect*/) const
214 CWindowGc& gc = SystemGc();
215 TRect drawRect(Rect());
216 drawRect.Shrink(1,1);
217 gc.DrawRect(drawRect);
221 TPoint CTCamAppView::DrawBorders(const TSize& aSize) const
223 CWindowGc& gc = SystemGc();
224 gc.Activate(Window());
225 TRect drawRect(Rect());
227 pos.iX = (drawRect.iBr.iX - aSize.iWidth) / 2;
228 pos.iY = (drawRect.iBr.iY - aSize.iHeight) / 2;
229 TRect border(pos,aSize);
231 gc.SetPenColor(KRgbBlack);
234 iCoeEnv->WsSession().Flush();
242 CTCamDocument::CTCamDocument(CEikApplication& aApp)
247 CEikAppUi* CTCamDocument::CreateAppUiL()
249 return new(ELeave) CTCamAppUi;
256 TUid CTCamApp::AppDllUid() const
258 return KUidTestCameraApp;
261 CApaDocument* CTCamApp::CreateDocumentL()
263 return new(ELeave) CTCamDocument(*this);
268 // Base factory function
271 #include <eikstart.h>
272 LOCAL_C CApaApplication* NewApplication()
281 GLDEF_C TInt E32Main()
283 return EikStart::RunApplication(NewApplication);