1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/imagingandcamerafws/camerafw/testapps/testcameraapps60/TestCameraApp.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,289 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <eikenv.h>
1.20 +#include <TestCameraApp.rsg>
1.21 +#include "TestCameraApp.h"
1.22 +#include "TestCameraApp.hrh"
1.23 +
1.24 +const TInt KMaxErrLength=50;
1.25 +_LIT(KErrorFormat,"Error - %d (%S)");
1.26 +
1.27 +//
1.28 +// CTCamAppUi
1.29 +//
1.30 +
1.31 +void CTCamAppUi::ConstructL()
1.32 + {
1.33 + BaseConstructL();
1.34 + iAppView = new(ELeave) CTCamAppView;
1.35 + iAppView->ConstructL(ClientRect());
1.36 + AddToStackL(iAppView);
1.37 +
1.38 + iCamera = CCamera::NewL(*this,0);
1.39 + iCamera->Reserve();
1.40 + }
1.41 +
1.42 +CTCamAppUi::~CTCamAppUi()
1.43 + {
1.44 + iCamera->Release();
1.45 + delete iCamera;
1.46 + if (iAppView)
1.47 + {
1.48 + RemoveFromStack(iAppView);
1.49 + delete iAppView;
1.50 + }
1.51 + }
1.52 +
1.53 +void CTCamAppUi::HandleCommandL(TInt aCommand)
1.54 + {
1.55 + switch (aCommand)
1.56 + {
1.57 + case ETCamCmdPowerOn:
1.58 + iCamera->PowerOn();
1.59 + break;
1.60 + case ETCamCmdPowerOff:
1.61 + iCamera->PowerOff();
1.62 + break;
1.63 + case ETCamCmdViewFinder:
1.64 + ViewFinderL();
1.65 + break;
1.66 + case ETCamCmdCaptureImage:
1.67 + CaptureImageL();
1.68 + break;
1.69 + case ETCamCmdCaptureVideo:
1.70 + CaptureVideoL();
1.71 + break;
1.72 + case ETCamCmdIncBrightness:
1.73 + iCamera->SetBrightnessL(iCamera->Brightness() + 10);
1.74 + break;
1.75 + case ETCamCmdIncContrast:
1.76 + iCamera->SetContrastL(iCamera->Contrast() + 10);
1.77 + break;
1.78 + case ETCamCmdDecBrightness:
1.79 + iCamera->SetBrightnessL(iCamera->Brightness() - 10);
1.80 + break;
1.81 + case ETCamCmdDecContrast:
1.82 + iCamera->SetContrastL(iCamera->Contrast() - 10);
1.83 + break;
1.84 + case ETCamCmdResetBrightness:
1.85 + iCamera->SetBrightnessL(0);
1.86 + break;
1.87 + case ETCamCmdResetContrast:
1.88 + iCamera->SetContrastL(0);
1.89 + break;
1.90 + case EAknSoftkeyBack:
1.91 + Exit();
1.92 + break;
1.93 + }
1.94 + }
1.95 +
1.96 +void CTCamAppUi::ViewFinderL()
1.97 + {
1.98 + TSize imageSize;
1.99 + iCamera->EnumerateCaptureSizes(imageSize,1,CCamera::EFormatFbsBitmapColor16M);
1.100 + const TPoint pos = iAppView->DrawBorders(imageSize);
1.101 + TRect screenRect(pos,imageSize);
1.102 + TRect clipRect;
1.103 +
1.104 + if (!iCamera->ViewFinderActive())
1.105 + iCamera->StartViewFinderDirectL(iCoeEnv->WsSession(),*iCoeEnv->ScreenDevice(),*iAppView->DrawableWindow(),screenRect,clipRect);
1.106 + else
1.107 + iCamera->StopViewFinder();
1.108 + }
1.109 +
1.110 +void CTCamAppUi::CaptureImageL()
1.111 + {
1.112 + TSize size;
1.113 + iCamera->EnumerateCaptureSizes(size,1,CCamera::EFormatFbsBitmapColor16M);
1.114 + iCamera->PrepareImageCaptureL(CCamera::EFormatFbsBitmapColor16M,1);
1.115 + iCamera->CaptureImage();
1.116 + }
1.117 +
1.118 +void CTCamAppUi::CaptureVideoL()
1.119 + {
1.120 + if (!iCamera->VideoCaptureActive())
1.121 + {
1.122 + TSize size;
1.123 + TReal32 rate = 0;
1.124 + iCamera->EnumerateVideoFrameSizes(size,0,CCamera::EFormatFbsBitmapColor16M);
1.125 + iCamera->EnumerateVideoFrameRates(rate,0,CCamera::EFormatFbsBitmapColor16M,0);
1.126 + iCamera->PrepareVideoCaptureL(CCamera::EFormatFbsBitmapColor16M,0,0,2,1);
1.127 + iCamera->StartVideoCapture();
1.128 + }
1.129 + else
1.130 + iCamera->StopVideoCapture();
1.131 + }
1.132 +
1.133 +void CTCamAppUi::ReserveComplete(TInt /*aError*/)
1.134 + {
1.135 + }
1.136 +
1.137 +void CTCamAppUi::PowerOnComplete(TInt /*aError*/)
1.138 + {
1.139 + }
1.140 +
1.141 +void CTCamAppUi::ViewFinderFrameReady(CFbsBitmap& /*aFrame*/)
1.142 + {
1.143 + }
1.144 +
1.145 +void CTCamAppUi::ImageReady(CFbsBitmap* aBitmap,HBufC8* /*aData*/,TInt aError)
1.146 + {
1.147 + TBuf<KMaxErrLength> msgBuffer;
1.148 + _LIT(KErrMessage,"CTCamAppUi::ImageReady");
1.149 + if (aBitmap)
1.150 + {
1.151 + iAppView->DrawImage(aBitmap);
1.152 + delete aBitmap;
1.153 + }
1.154 + if (aError)
1.155 + {
1.156 + msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
1.157 + iEikonEnv->InfoMsg(msgBuffer);
1.158 + }
1.159 + }
1.160 +
1.161 +void CTCamAppUi::FrameBufferReady(MFrameBuffer* aFrameBuffer,TInt aError)
1.162 + {
1.163 + TBuf<KMaxErrLength> msgBuffer;
1.164 + _LIT(KErrMessage,"CTCamAppUi::FrameBufferReady");
1.165 + if (aError)
1.166 + {
1.167 + msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
1.168 + iEikonEnv->InfoMsg(msgBuffer);
1.169 + return;
1.170 + }
1.171 + TRAPD(error,iAppView->DrawImage(aFrameBuffer->FrameL(0)));
1.172 + aFrameBuffer->Release();
1.173 + if (error)
1.174 + {
1.175 + msgBuffer.Format(KErrorFormat,error,&KErrMessage);
1.176 + iEikonEnv->InfoMsg(msgBuffer);
1.177 + }
1.178 + }
1.179 +
1.180 +_LIT(KContrastDialogTitle,"Contrast");
1.181 +_LIT(KBrightnessDialogTitle,"Brightness");
1.182 +
1.183 +//
1.184 +// CTCamAppView
1.185 +//
1.186 +
1.187 +CTCamAppView::CTCamAppView():
1.188 + CCoeControl()
1.189 + {}
1.190 +
1.191 +void CTCamAppView::ConstructL(const TRect& aRect)
1.192 + {
1.193 + CreateWindowL();
1.194 + SetRect(aRect);
1.195 + EnableDragEvents();
1.196 + ActivateL();
1.197 + }
1.198 +
1.199 +CTCamAppView::~CTCamAppView()
1.200 + {}
1.201 +
1.202 +void CTCamAppView::DrawImage(CFbsBitmap* aImage) const
1.203 + {
1.204 + CWindowGc& gc = SystemGc();
1.205 + gc.Activate(Window());
1.206 + TRect drawRect(Rect());
1.207 + TPoint pos;
1.208 + pos.iX = (drawRect.iBr.iX - aImage->SizeInPixels().iWidth) / 2;
1.209 + pos.iY = (drawRect.iBr.iY - aImage->SizeInPixels().iHeight) / 2;
1.210 + gc.BitBlt(pos,aImage);
1.211 + gc.Deactivate();
1.212 + iCoeEnv->WsSession().Flush();
1.213 + }
1.214 +
1.215 +void CTCamAppView::Draw(const TRect& /*aRect*/) const
1.216 + {
1.217 + CWindowGc& gc = SystemGc();
1.218 + TRect drawRect(Rect());
1.219 + drawRect.Shrink(1,1);
1.220 + gc.DrawRect(drawRect);
1.221 + gc.Clear();
1.222 + }
1.223 +
1.224 +TPoint CTCamAppView::DrawBorders(const TSize& aSize) const
1.225 + {
1.226 + CWindowGc& gc = SystemGc();
1.227 + gc.Activate(Window());
1.228 + TRect drawRect(Rect());
1.229 + TPoint pos;
1.230 + pos.iX = (drawRect.iBr.iX - aSize.iWidth) / 2;
1.231 + pos.iY = (drawRect.iBr.iY - aSize.iHeight) / 2;
1.232 + TRect border(pos,aSize);
1.233 + border.Grow(1,1);
1.234 + gc.SetPenColor(KRgbBlack);
1.235 + gc.DrawRect(border);
1.236 + gc.Deactivate();
1.237 + iCoeEnv->WsSession().Flush();
1.238 + return pos;
1.239 + }
1.240 +
1.241 +//
1.242 +// CTCamDocument
1.243 +//
1.244 +
1.245 +CTCamDocument::CTCamDocument(CEikApplication& aApp)
1.246 + : CAknDocument(aApp)
1.247 + {
1.248 + }
1.249 +
1.250 +CEikAppUi* CTCamDocument::CreateAppUiL()
1.251 + {
1.252 + return new(ELeave) CTCamAppUi;
1.253 + }
1.254 +
1.255 +//
1.256 +// CTCamApp
1.257 +//
1.258 +
1.259 +TUid CTCamApp::AppDllUid() const
1.260 + {
1.261 + return KUidTestCameraApp;
1.262 + }
1.263 +
1.264 +CApaDocument* CTCamApp::CreateDocumentL()
1.265 + {
1.266 + return new(ELeave) CTCamDocument(*this);
1.267 + }
1.268 +
1.269 +
1.270 +//
1.271 +// Base factory function
1.272 +//
1.273 +
1.274 +#include <eikstart.h>
1.275 +LOCAL_C CApaApplication* NewApplication()
1.276 + {
1.277 + return new CTCamApp;
1.278 + }
1.279 +
1.280 +//
1.281 +// EXE Entry point
1.282 +//
1.283 +
1.284 +GLDEF_C TInt E32Main()
1.285 + {
1.286 + return EikStart::RunApplication(NewApplication);
1.287 + }
1.288 +
1.289 +
1.290 +
1.291 +
1.292 +