sl@0: // Copyright (c) 2007-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: // testsnapshot.cpp sl@0: // sl@0: // sl@0: sl@0: #include "test_snapshot.h" sl@0: #include sl@0: sl@0: CTestCamSnapshot::CTestCamSnapshot(CTestCamera& aOwner): iOwner(aOwner), iSnapshotBuffer(iSnapshot) sl@0: { sl@0: Init(); sl@0: } sl@0: sl@0: CTestCamSnapshot::~CTestCamSnapshot() sl@0: { sl@0: delete iSnapshotImage; sl@0: iSnapshotImage = NULL; sl@0: delete iSnapshotImageGc; sl@0: iSnapshotImage = NULL; sl@0: delete iSnapshotImageDev; sl@0: iSnapshotImageDev = NULL; sl@0: sl@0: delete iSnapshot; sl@0: iSnapshot = NULL; sl@0: delete iSnapshotGc; sl@0: iSnapshotGc = NULL; sl@0: delete iSnapshotDev; sl@0: iSnapshotDev = NULL; sl@0: sl@0: iSupportedSnapshotRect.Close(); sl@0: sl@0: CDataGlobal* globalData = static_cast (Dll::Tls()); sl@0: if(globalData != NULL) sl@0: { sl@0: if(!globalData->iTestCamPresets && !globalData->iTestCamAdvSet && !globalData->iTestCamImgProc) sl@0: { sl@0: delete globalData; sl@0: Dll::FreeTls(); sl@0: } sl@0: else sl@0: { sl@0: globalData->iTestCamSnapshot = NULL; sl@0: Dll::SetTls(globalData); sl@0: } sl@0: } sl@0: } sl@0: sl@0: CTestCamSnapshot* CTestCamSnapshot::NewL(CTestCamera& aOwner) sl@0: { sl@0: CDataGlobal* globalData = static_cast (Dll::Tls()); sl@0: sl@0: if(globalData == NULL) sl@0: { sl@0: globalData = new (ELeave) CDataGlobal; sl@0: CleanupStack::PushL(globalData); sl@0: globalData->iSnapshotReferenceCount = 0; sl@0: globalData->iTestCamSnapshot = new (ELeave) CTestCamSnapshot(aOwner); sl@0: CleanupStack::PushL(globalData->iTestCamSnapshot); sl@0: globalData->iTestCamSnapshot->ConstructL(); sl@0: globalData->iTestCamSnapshot->iRefCount = 1; sl@0: User::LeaveIfError(Dll::SetTls(globalData)); sl@0: CleanupStack::Pop(globalData->iTestCamSnapshot); sl@0: CleanupStack::Pop(globalData); sl@0: return globalData->iTestCamSnapshot; sl@0: } sl@0: else sl@0: { sl@0: if(globalData->iTestCamSnapshot == NULL) sl@0: { sl@0: globalData->iSnapshotReferenceCount = 0; sl@0: globalData->iTestCamSnapshot = new (ELeave) CTestCamSnapshot(aOwner); sl@0: CleanupStack::PushL(globalData->iTestCamSnapshot); sl@0: globalData->iTestCamSnapshot->ConstructL(); sl@0: globalData->iTestCamSnapshot->iRefCount = 1; sl@0: User::LeaveIfError(Dll::SetTls(globalData)); sl@0: CleanupStack::Pop(globalData->iTestCamSnapshot); sl@0: return globalData->iTestCamSnapshot; sl@0: } sl@0: sl@0: CTestCamSnapshot* self = globalData->iTestCamSnapshot; sl@0: sl@0: globalData->iSnapshotReferenceCount++; sl@0: self->iRefCount = globalData->iSnapshotReferenceCount + 1; sl@0: if (globalData->iSnapshotReferenceCount == KNumOfSnapshotExtensions-1 ) sl@0: { sl@0: globalData->iTestCamSnapshot = NULL; sl@0: if(!globalData->iTestCamPresets && !globalData->iTestCamAdvSet && !globalData->iTestCamImgProc) sl@0: { sl@0: delete globalData; sl@0: Dll::FreeTls(); sl@0: } sl@0: else sl@0: { sl@0: User::LeaveIfError(Dll::SetTls(globalData)); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: User::LeaveIfError(Dll::SetTls(globalData)); sl@0: } sl@0: return self; sl@0: } sl@0: } sl@0: sl@0: void CTestCamSnapshot::Release() sl@0: { sl@0: iRefCount--; sl@0: if(iRefCount == 0) sl@0: { sl@0: iOwner.iSnapshotImpl = NULL; sl@0: delete this; sl@0: } sl@0: } sl@0: sl@0: void CTestCamSnapshot::Init() sl@0: { sl@0: iImageFormatsSupported = 0; sl@0: iImageFormatsSupported |= CCamera::EFormatFbsBitmapColor4K; sl@0: iImageFormatsSupported |= CCamera::EFormatFbsBitmapColor64K; sl@0: iImageFormatsSupported |= CCamera::EFormatFbsBitmapColor16M; sl@0: iSnapshotPrepared = EFalse; sl@0: iSnapshotActive = EFalse; sl@0: iBgColor = KRgbWhite; sl@0: } sl@0: sl@0: void CTestCamSnapshot::ConstructL() sl@0: { sl@0: iSupportedSnapshotRect.Reset(); sl@0: iSupportedSnapshotRect.AppendL(TRect(TPoint(0,0), iOwner.iImageSizes[0])); sl@0: iSupportedSnapshotRect.AppendL(TRect(TPoint(0,0), iOwner.iImageSizes[1])); sl@0: } sl@0: sl@0: TUint32 CTestCamSnapshot::SupportedFormats() sl@0: { sl@0: return iImageFormatsSupported; sl@0: } sl@0: sl@0: void CTestCamSnapshot::PrepareSnapshotL(CCamera::TFormat aFormat, const TPoint& aPosition, const TSize& aSize, const TRgb& aBgColor, TBool /*aMaintainAspectRatio*/) sl@0: { sl@0: iOwner.CheckReserveAndPowerL(); sl@0: sl@0: if (iOwner.iVideoCaptureActive || iOwner.iImageCaptureActive) sl@0: { sl@0: User::Leave(KErrNotReady); sl@0: } sl@0: sl@0: if (!(aFormat & iImageFormatsSupported) ) sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: //check if the snapshot size is supported sl@0: TRect snapshot_rect = TRect(aPosition, aSize); sl@0: sl@0: if(snapshot_rect != iSupportedSnapshotRect[0] && snapshot_rect != iSupportedSnapshotRect[1]) sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: if (iSnapshotPrepared sl@0: && iSnapshotFormat == aFormat sl@0: && iSnapshotImageRect == snapshot_rect sl@0: && iBgColor == aBgColor sl@0: ) sl@0: { sl@0: return; sl@0: } sl@0: sl@0: TDisplayMode displayMode = ENone; sl@0: switch (aFormat) sl@0: { sl@0: case CCamera::EFormatFbsBitmapColor4K : sl@0: displayMode = EColor4K; sl@0: break; sl@0: case CCamera::EFormatFbsBitmapColor64K : sl@0: displayMode = EColor64K; sl@0: break; sl@0: case CCamera::EFormatFbsBitmapColor16M : sl@0: displayMode = EColor16M; sl@0: break; sl@0: default : sl@0: User::Leave(KErrNotSupported); sl@0: break; sl@0: } sl@0: sl@0: delete iSnapshotImage; sl@0: iSnapshotImage = NULL; sl@0: delete iSnapshotImageGc; sl@0: iSnapshotImageGc = NULL; sl@0: delete iSnapshotImageDev; sl@0: iSnapshotImageDev = NULL; sl@0: sl@0: iSnapshotImage = new(ELeave) CFbsBitmap; sl@0: User::LeaveIfError(iSnapshotImage->Create(aSize, displayMode)); sl@0: iSnapshotImageDev = CFbsBitmapDevice::NewL(iSnapshotImage); sl@0: User::LeaveIfError(iSnapshotImageDev->CreateContext(iSnapshotImageGc)); sl@0: iSnapshotImageGc->SetPenColor(KRgbBlack); sl@0: iSnapshotImageGc->SetPenSize(TSize(KFrameFeatureBorderThickness, KFrameFeatureBorderThickness)); sl@0: iSnapshotImageGc->SetBrushColor(aBgColor); sl@0: iSnapshotImageGc->SetFaded(ETrue); sl@0: sl@0: iSnapshotPrepared = ETrue; sl@0: iSnapshotImageRect = snapshot_rect; sl@0: iSnapshotFormat = aFormat; sl@0: iBgColor = aBgColor; sl@0: } sl@0: sl@0: void CTestCamSnapshot::PrepareSnapshotL(CCamera::TFormat /*aFormat*/, const TSize& /*aSize*/, TBool /*aMaintainAspectRatio*/) sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: void CTestCamSnapshot::SetBgColorL(const TRgb& /*aBgColor*/) sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: void CTestCamSnapshot::SetPositionL(const TPoint& /*aPosition*/) sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: TBool CTestCamSnapshot::IsSnapshotActive() const sl@0: { sl@0: return iSnapshotActive; sl@0: } sl@0: sl@0: void CTestCamSnapshot::StartSnapshot() sl@0: { sl@0: TInt error = iOwner.CheckReserveAndPower(); sl@0: sl@0: if(error == KErrNone) sl@0: { sl@0: if(!iSnapshotPrepared) sl@0: { sl@0: error = KErrNotReady; sl@0: } sl@0: } sl@0: sl@0: if(error != KErrNone) sl@0: { sl@0: TECAMEvent ecamevent(KUidECamEventCameraSnapshot, error); sl@0: sl@0: iOwner.iECamEvent = ecamevent; sl@0: iOwner.iHandleEventAsync.CallBack(); sl@0: return; sl@0: } sl@0: sl@0: delete iSnapshot; sl@0: iSnapshot = NULL; sl@0: delete iSnapshotGc; sl@0: iSnapshot = NULL; sl@0: delete iSnapshotDev; sl@0: iSnapshotDev = NULL; sl@0: sl@0: TRAP(error, DoStartSnapshotL()); sl@0: sl@0: if(error != KErrNone) sl@0: { sl@0: TECAMEvent ecamevent(KUidECamEventCameraSnapshot, error); sl@0: sl@0: iOwner.iECamEvent = ecamevent; sl@0: iOwner.iHandleEventAsync.CallBack(); sl@0: } sl@0: } sl@0: sl@0: void CTestCamSnapshot::DoStartSnapshotL() sl@0: { sl@0: CFbsBitmap* snapshot = new(ELeave) CFbsBitmap; sl@0: CleanupStack::PushL(snapshot); sl@0: User::LeaveIfError(snapshot->Create(iSnapshotImageRect.Size(), iSnapshotImage->DisplayMode())); sl@0: CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(snapshot); sl@0: CleanupStack::PushL(dev); sl@0: CFbsBitGc* gc = NULL; sl@0: User::LeaveIfError(dev->CreateContext(gc)); sl@0: CleanupStack::Pop(dev); sl@0: CleanupStack::Pop(snapshot); sl@0: sl@0: iSnapshot = snapshot; sl@0: iSnapshotDev = dev; sl@0: iSnapshotGc = gc; sl@0: sl@0: iSnapshotActive = ETrue; sl@0: } sl@0: sl@0: void CTestCamSnapshot::StopSnapshot() sl@0: { sl@0: delete iSnapshotGc; sl@0: iSnapshotGc = NULL; sl@0: delete iSnapshotDev; sl@0: iSnapshotDev = NULL; sl@0: delete iSnapshot; sl@0: iSnapshot = NULL; sl@0: sl@0: iSnapshotActive = EFalse; sl@0: } sl@0: sl@0: MCameraBuffer& CTestCamSnapshot::SnapshotDataL(RArray& /*aFrameIndexOrder*/) sl@0: { sl@0: iSnapshotBuffer.iAvailable = EFalse; sl@0: return iSnapshotBuffer; sl@0: } sl@0: sl@0: void CTestCamSnapshot::ServiceSnapshot(const CFbsBitGc& aSourceBitmapGc) sl@0: { sl@0: TInt error = KErrNone; sl@0: if(!iSnapshotBuffer.iAvailable) sl@0: { sl@0: error = KErrInUse; sl@0: } sl@0: else sl@0: { sl@0: iSnapshotGc->BitBlt(TPoint(0,0), aSourceBitmapGc); sl@0: } sl@0: sl@0: iOwner.iObserver2->HandleEvent(TECAMEvent(KUidECamEventCameraSnapshot, error)); sl@0: } sl@0: sl@0: void CTestCamSnapshot::ServiceBurstImageSnapshot(const CFbsBitGc& aSourceBitmapGc) sl@0: { sl@0: TInt error = KErrNone; sl@0: if(!iSnapshotBuffer.iAvailable) sl@0: { sl@0: error = KErrInUse; sl@0: } sl@0: else sl@0: { sl@0: iSnapshotGc->BitBlt(TPoint(0,0), aSourceBitmapGc); sl@0: } sl@0: sl@0: iOwner.iObserver2->HandleEvent(TECAMEvent(KUidECamEventCameraSnapshot, error)); sl@0: sl@0: User::After(500000); sl@0: sl@0: iOwner.iStillImagePos.iX += KFramePosIncrement; sl@0: iOwner.iStillImagePos.iY += KFramePosIncrement; sl@0: sl@0: if (iOwner.iStillImagePos.iX >= iOwner.iStillImageSize.iWidth) sl@0: { sl@0: iOwner.iStillImagePos.iX = 0; sl@0: } sl@0: sl@0: if (iOwner.iStillImagePos.iY >= iOwner.iStillImageSize.iHeight) sl@0: { sl@0: iOwner.iStillImagePos.iY = 0; sl@0: } sl@0: } sl@0: