sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include "TestCameraApp.h" sl@0: #include "TestCameraApp.hrh" sl@0: sl@0: const TInt KMaxErrLength=50; sl@0: _LIT(KErrorFormat,"Error - %d (%S)"); sl@0: sl@0: // sl@0: // CTCamAppUi sl@0: // sl@0: sl@0: void CTCamAppUi::ConstructL() sl@0: { sl@0: BaseConstructL(); sl@0: iAppView = new(ELeave) CTCamAppView; sl@0: iAppView->ConstructL(ClientRect()); sl@0: AddToStackL(iAppView); sl@0: sl@0: iCamera = CCamera::NewL(*this,0); sl@0: iCamera->Reserve(); sl@0: } sl@0: sl@0: CTCamAppUi::~CTCamAppUi() sl@0: { sl@0: iCamera->Release(); sl@0: delete iCamera; sl@0: if (iAppView) sl@0: { sl@0: RemoveFromStack(iAppView); sl@0: delete iAppView; sl@0: } sl@0: } sl@0: sl@0: void CTCamAppUi::HandleCommandL(TInt aCommand) sl@0: { sl@0: switch (aCommand) sl@0: { sl@0: case ETCamCmdPowerOn: sl@0: iCamera->PowerOn(); sl@0: break; sl@0: case ETCamCmdPowerOff: sl@0: iCamera->PowerOff(); sl@0: break; sl@0: case ETCamCmdViewFinder: sl@0: ViewFinderL(); sl@0: break; sl@0: case ETCamCmdCaptureImage: sl@0: CaptureImageL(); sl@0: break; sl@0: case ETCamCmdCaptureVideo: sl@0: CaptureVideoL(); sl@0: break; sl@0: case ETCamCmdIncBrightness: sl@0: iCamera->SetBrightnessL(iCamera->Brightness() + 10); sl@0: break; sl@0: case ETCamCmdIncContrast: sl@0: iCamera->SetContrastL(iCamera->Contrast() + 10); sl@0: break; sl@0: case ETCamCmdDecBrightness: sl@0: iCamera->SetBrightnessL(iCamera->Brightness() - 10); sl@0: break; sl@0: case ETCamCmdDecContrast: sl@0: iCamera->SetContrastL(iCamera->Contrast() - 10); sl@0: break; sl@0: case ETCamCmdResetBrightness: sl@0: iCamera->SetBrightnessL(0); sl@0: break; sl@0: case ETCamCmdResetContrast: sl@0: iCamera->SetContrastL(0); sl@0: break; sl@0: case EAknSoftkeyBack: sl@0: Exit(); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CTCamAppUi::ViewFinderL() sl@0: { sl@0: TSize imageSize; sl@0: iCamera->EnumerateCaptureSizes(imageSize,1,CCamera::EFormatFbsBitmapColor16M); sl@0: const TPoint pos = iAppView->DrawBorders(imageSize); sl@0: TRect screenRect(pos,imageSize); sl@0: TRect clipRect; sl@0: sl@0: if (!iCamera->ViewFinderActive()) sl@0: iCamera->StartViewFinderDirectL(iCoeEnv->WsSession(),*iCoeEnv->ScreenDevice(),*iAppView->DrawableWindow(),screenRect,clipRect); sl@0: else sl@0: iCamera->StopViewFinder(); sl@0: } sl@0: sl@0: void CTCamAppUi::CaptureImageL() sl@0: { sl@0: TSize size; sl@0: iCamera->EnumerateCaptureSizes(size,1,CCamera::EFormatFbsBitmapColor16M); sl@0: iCamera->PrepareImageCaptureL(CCamera::EFormatFbsBitmapColor16M,1); sl@0: iCamera->CaptureImage(); sl@0: } sl@0: sl@0: void CTCamAppUi::CaptureVideoL() sl@0: { sl@0: if (!iCamera->VideoCaptureActive()) sl@0: { sl@0: TSize size; sl@0: TReal32 rate = 0; sl@0: iCamera->EnumerateVideoFrameSizes(size,0,CCamera::EFormatFbsBitmapColor16M); sl@0: iCamera->EnumerateVideoFrameRates(rate,0,CCamera::EFormatFbsBitmapColor16M,0); sl@0: iCamera->PrepareVideoCaptureL(CCamera::EFormatFbsBitmapColor16M,0,0,2,1); sl@0: iCamera->StartVideoCapture(); sl@0: } sl@0: else sl@0: iCamera->StopVideoCapture(); sl@0: } sl@0: sl@0: void CTCamAppUi::ReserveComplete(TInt /*aError*/) sl@0: { sl@0: } sl@0: sl@0: void CTCamAppUi::PowerOnComplete(TInt /*aError*/) sl@0: { sl@0: } sl@0: sl@0: void CTCamAppUi::ViewFinderFrameReady(CFbsBitmap& /*aFrame*/) sl@0: { sl@0: } sl@0: sl@0: void CTCamAppUi::ImageReady(CFbsBitmap* aBitmap,HBufC8* /*aData*/,TInt aError) sl@0: { sl@0: TBuf msgBuffer; sl@0: _LIT(KErrMessage,"CTCamAppUi::ImageReady"); sl@0: if (aBitmap) sl@0: { sl@0: iAppView->DrawImage(aBitmap); sl@0: delete aBitmap; sl@0: } sl@0: if (aError) sl@0: { sl@0: msgBuffer.Format(KErrorFormat,aError,&KErrMessage); sl@0: iEikonEnv->InfoMsg(msgBuffer); sl@0: } sl@0: } sl@0: sl@0: void CTCamAppUi::FrameBufferReady(MFrameBuffer* aFrameBuffer,TInt aError) sl@0: { sl@0: TBuf msgBuffer; sl@0: _LIT(KErrMessage,"CTCamAppUi::FrameBufferReady"); sl@0: if (aError) sl@0: { sl@0: msgBuffer.Format(KErrorFormat,aError,&KErrMessage); sl@0: iEikonEnv->InfoMsg(msgBuffer); sl@0: return; sl@0: } sl@0: TRAPD(error,iAppView->DrawImage(aFrameBuffer->FrameL(0))); sl@0: aFrameBuffer->Release(); sl@0: if (error) sl@0: { sl@0: msgBuffer.Format(KErrorFormat,error,&KErrMessage); sl@0: iEikonEnv->InfoMsg(msgBuffer); sl@0: } sl@0: } sl@0: sl@0: _LIT(KContrastDialogTitle,"Contrast"); sl@0: _LIT(KBrightnessDialogTitle,"Brightness"); sl@0: sl@0: // sl@0: // CTCamAppView sl@0: // sl@0: sl@0: CTCamAppView::CTCamAppView(): sl@0: CCoeControl() sl@0: {} sl@0: sl@0: void CTCamAppView::ConstructL(const TRect& aRect) sl@0: { sl@0: CreateWindowL(); sl@0: SetRect(aRect); sl@0: EnableDragEvents(); sl@0: ActivateL(); sl@0: } sl@0: sl@0: CTCamAppView::~CTCamAppView() sl@0: {} sl@0: sl@0: void CTCamAppView::DrawImage(CFbsBitmap* aImage) const sl@0: { sl@0: CWindowGc& gc = SystemGc(); sl@0: gc.Activate(Window()); sl@0: TRect drawRect(Rect()); sl@0: TPoint pos; sl@0: pos.iX = (drawRect.iBr.iX - aImage->SizeInPixels().iWidth) / 2; sl@0: pos.iY = (drawRect.iBr.iY - aImage->SizeInPixels().iHeight) / 2; sl@0: gc.BitBlt(pos,aImage); sl@0: gc.Deactivate(); sl@0: iCoeEnv->WsSession().Flush(); sl@0: } sl@0: sl@0: void CTCamAppView::Draw(const TRect& /*aRect*/) const sl@0: { sl@0: CWindowGc& gc = SystemGc(); sl@0: TRect drawRect(Rect()); sl@0: drawRect.Shrink(1,1); sl@0: gc.DrawRect(drawRect); sl@0: gc.Clear(); sl@0: } sl@0: sl@0: TPoint CTCamAppView::DrawBorders(const TSize& aSize) const sl@0: { sl@0: CWindowGc& gc = SystemGc(); sl@0: gc.Activate(Window()); sl@0: TRect drawRect(Rect()); sl@0: TPoint pos; sl@0: pos.iX = (drawRect.iBr.iX - aSize.iWidth) / 2; sl@0: pos.iY = (drawRect.iBr.iY - aSize.iHeight) / 2; sl@0: TRect border(pos,aSize); sl@0: border.Grow(1,1); sl@0: gc.SetPenColor(KRgbBlack); sl@0: gc.DrawRect(border); sl@0: gc.Deactivate(); sl@0: iCoeEnv->WsSession().Flush(); sl@0: return pos; sl@0: } sl@0: sl@0: // sl@0: // CTCamDocument sl@0: // sl@0: sl@0: CTCamDocument::CTCamDocument(CEikApplication& aApp) sl@0: : CAknDocument(aApp) sl@0: { sl@0: } sl@0: sl@0: CEikAppUi* CTCamDocument::CreateAppUiL() sl@0: { sl@0: return new(ELeave) CTCamAppUi; sl@0: } sl@0: sl@0: // sl@0: // CTCamApp sl@0: // sl@0: sl@0: TUid CTCamApp::AppDllUid() const sl@0: { sl@0: return KUidTestCameraApp; sl@0: } sl@0: sl@0: CApaDocument* CTCamApp::CreateDocumentL() sl@0: { sl@0: return new(ELeave) CTCamDocument(*this); sl@0: } sl@0: sl@0: sl@0: // sl@0: // Base factory function sl@0: // sl@0: sl@0: #include sl@0: LOCAL_C CApaApplication* NewApplication() sl@0: { sl@0: return new CTCamApp; sl@0: } sl@0: sl@0: // sl@0: // EXE Entry point sl@0: // sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: return EikStart::RunApplication(NewApplication); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: