Update contrib.
1 // Copyright (c) 2007-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.
18 #include "test_snapshot.h"
19 #include <ecamerrors.h>
21 CTestCamSnapshot::CTestCamSnapshot(CTestCamera& aOwner): iOwner(aOwner), iSnapshotBuffer(iSnapshot)
26 CTestCamSnapshot::~CTestCamSnapshot()
28 delete iSnapshotImage;
29 iSnapshotImage = NULL;
30 delete iSnapshotImageGc;
31 iSnapshotImage = NULL;
32 delete iSnapshotImageDev;
33 iSnapshotImageDev = NULL;
42 iSupportedSnapshotRect.Close();
44 CDataGlobal* globalData = static_cast <CDataGlobal*> (Dll::Tls());
45 if(globalData != NULL)
47 if(!globalData->iTestCamPresets && !globalData->iTestCamAdvSet && !globalData->iTestCamImgProc)
54 globalData->iTestCamSnapshot = NULL;
55 Dll::SetTls(globalData);
60 CTestCamSnapshot* CTestCamSnapshot::NewL(CTestCamera& aOwner)
62 CDataGlobal* globalData = static_cast <CDataGlobal*> (Dll::Tls());
64 if(globalData == NULL)
66 globalData = new (ELeave) CDataGlobal;
67 CleanupStack::PushL(globalData);
68 globalData->iSnapshotReferenceCount = 0;
69 globalData->iTestCamSnapshot = new (ELeave) CTestCamSnapshot(aOwner);
70 CleanupStack::PushL(globalData->iTestCamSnapshot);
71 globalData->iTestCamSnapshot->ConstructL();
72 globalData->iTestCamSnapshot->iRefCount = 1;
73 User::LeaveIfError(Dll::SetTls(globalData));
74 CleanupStack::Pop(globalData->iTestCamSnapshot);
75 CleanupStack::Pop(globalData);
76 return globalData->iTestCamSnapshot;
80 if(globalData->iTestCamSnapshot == NULL)
82 globalData->iSnapshotReferenceCount = 0;
83 globalData->iTestCamSnapshot = new (ELeave) CTestCamSnapshot(aOwner);
84 CleanupStack::PushL(globalData->iTestCamSnapshot);
85 globalData->iTestCamSnapshot->ConstructL();
86 globalData->iTestCamSnapshot->iRefCount = 1;
87 User::LeaveIfError(Dll::SetTls(globalData));
88 CleanupStack::Pop(globalData->iTestCamSnapshot);
89 return globalData->iTestCamSnapshot;
92 CTestCamSnapshot* self = globalData->iTestCamSnapshot;
94 globalData->iSnapshotReferenceCount++;
95 self->iRefCount = globalData->iSnapshotReferenceCount + 1;
96 if (globalData->iSnapshotReferenceCount == KNumOfSnapshotExtensions-1 )
98 globalData->iTestCamSnapshot = NULL;
99 if(!globalData->iTestCamPresets && !globalData->iTestCamAdvSet && !globalData->iTestCamImgProc)
106 User::LeaveIfError(Dll::SetTls(globalData));
111 User::LeaveIfError(Dll::SetTls(globalData));
117 void CTestCamSnapshot::Release()
122 iOwner.iSnapshotImpl = NULL;
127 void CTestCamSnapshot::Init()
129 iImageFormatsSupported = 0;
130 iImageFormatsSupported |= CCamera::EFormatFbsBitmapColor4K;
131 iImageFormatsSupported |= CCamera::EFormatFbsBitmapColor64K;
132 iImageFormatsSupported |= CCamera::EFormatFbsBitmapColor16M;
133 iSnapshotPrepared = EFalse;
134 iSnapshotActive = EFalse;
135 iBgColor = KRgbWhite;
138 void CTestCamSnapshot::ConstructL()
140 iSupportedSnapshotRect.Reset();
141 iSupportedSnapshotRect.AppendL(TRect(TPoint(0,0), iOwner.iImageSizes[0]));
142 iSupportedSnapshotRect.AppendL(TRect(TPoint(0,0), iOwner.iImageSizes[1]));
145 TUint32 CTestCamSnapshot::SupportedFormats()
147 return iImageFormatsSupported;
150 void CTestCamSnapshot::PrepareSnapshotL(CCamera::TFormat aFormat, const TPoint& aPosition, const TSize& aSize, const TRgb& aBgColor, TBool /*aMaintainAspectRatio*/)
152 iOwner.CheckReserveAndPowerL();
154 if (iOwner.iVideoCaptureActive || iOwner.iImageCaptureActive)
156 User::Leave(KErrNotReady);
159 if (!(aFormat & iImageFormatsSupported) )
161 User::Leave(KErrNotSupported);
164 //check if the snapshot size is supported
165 TRect snapshot_rect = TRect(aPosition, aSize);
167 if(snapshot_rect != iSupportedSnapshotRect[0] && snapshot_rect != iSupportedSnapshotRect[1])
169 User::Leave(KErrNotSupported);
172 if (iSnapshotPrepared
173 && iSnapshotFormat == aFormat
174 && iSnapshotImageRect == snapshot_rect
175 && iBgColor == aBgColor
181 TDisplayMode displayMode = ENone;
184 case CCamera::EFormatFbsBitmapColor4K :
185 displayMode = EColor4K;
187 case CCamera::EFormatFbsBitmapColor64K :
188 displayMode = EColor64K;
190 case CCamera::EFormatFbsBitmapColor16M :
191 displayMode = EColor16M;
194 User::Leave(KErrNotSupported);
198 delete iSnapshotImage;
199 iSnapshotImage = NULL;
200 delete iSnapshotImageGc;
201 iSnapshotImageGc = NULL;
202 delete iSnapshotImageDev;
203 iSnapshotImageDev = NULL;
205 iSnapshotImage = new(ELeave) CFbsBitmap;
206 User::LeaveIfError(iSnapshotImage->Create(aSize, displayMode));
207 iSnapshotImageDev = CFbsBitmapDevice::NewL(iSnapshotImage);
208 User::LeaveIfError(iSnapshotImageDev->CreateContext(iSnapshotImageGc));
209 iSnapshotImageGc->SetPenColor(KRgbBlack);
210 iSnapshotImageGc->SetPenSize(TSize(KFrameFeatureBorderThickness, KFrameFeatureBorderThickness));
211 iSnapshotImageGc->SetBrushColor(aBgColor);
212 iSnapshotImageGc->SetFaded(ETrue);
214 iSnapshotPrepared = ETrue;
215 iSnapshotImageRect = snapshot_rect;
216 iSnapshotFormat = aFormat;
220 void CTestCamSnapshot::PrepareSnapshotL(CCamera::TFormat /*aFormat*/, const TSize& /*aSize*/, TBool /*aMaintainAspectRatio*/)
222 User::Leave(KErrNotSupported);
225 void CTestCamSnapshot::SetBgColorL(const TRgb& /*aBgColor*/)
227 User::Leave(KErrNotSupported);
230 void CTestCamSnapshot::SetPositionL(const TPoint& /*aPosition*/)
232 User::Leave(KErrNotSupported);
235 TBool CTestCamSnapshot::IsSnapshotActive() const
237 return iSnapshotActive;
240 void CTestCamSnapshot::StartSnapshot()
242 TInt error = iOwner.CheckReserveAndPower();
244 if(error == KErrNone)
246 if(!iSnapshotPrepared)
248 error = KErrNotReady;
252 if(error != KErrNone)
254 TECAMEvent ecamevent(KUidECamEventCameraSnapshot, error);
256 iOwner.iECamEvent = ecamevent;
257 iOwner.iHandleEventAsync.CallBack();
268 TRAP(error, DoStartSnapshotL());
270 if(error != KErrNone)
272 TECAMEvent ecamevent(KUidECamEventCameraSnapshot, error);
274 iOwner.iECamEvent = ecamevent;
275 iOwner.iHandleEventAsync.CallBack();
279 void CTestCamSnapshot::DoStartSnapshotL()
281 CFbsBitmap* snapshot = new(ELeave) CFbsBitmap;
282 CleanupStack::PushL(snapshot);
283 User::LeaveIfError(snapshot->Create(iSnapshotImageRect.Size(), iSnapshotImage->DisplayMode()));
284 CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(snapshot);
285 CleanupStack::PushL(dev);
286 CFbsBitGc* gc = NULL;
287 User::LeaveIfError(dev->CreateContext(gc));
288 CleanupStack::Pop(dev);
289 CleanupStack::Pop(snapshot);
291 iSnapshot = snapshot;
295 iSnapshotActive = ETrue;
298 void CTestCamSnapshot::StopSnapshot()
307 iSnapshotActive = EFalse;
310 MCameraBuffer& CTestCamSnapshot::SnapshotDataL(RArray<TInt>& /*aFrameIndexOrder*/)
312 iSnapshotBuffer.iAvailable = EFalse;
313 return iSnapshotBuffer;
316 void CTestCamSnapshot::ServiceSnapshot(const CFbsBitGc& aSourceBitmapGc)
318 TInt error = KErrNone;
319 if(!iSnapshotBuffer.iAvailable)
325 iSnapshotGc->BitBlt(TPoint(0,0), aSourceBitmapGc);
328 iOwner.iObserver2->HandleEvent(TECAMEvent(KUidECamEventCameraSnapshot, error));
331 void CTestCamSnapshot::ServiceBurstImageSnapshot(const CFbsBitGc& aSourceBitmapGc)
333 TInt error = KErrNone;
334 if(!iSnapshotBuffer.iAvailable)
340 iSnapshotGc->BitBlt(TPoint(0,0), aSourceBitmapGc);
343 iOwner.iObserver2->HandleEvent(TECAMEvent(KUidECamEventCameraSnapshot, error));
347 iOwner.iStillImagePos.iX += KFramePosIncrement;
348 iOwner.iStillImagePos.iY += KFramePosIncrement;
350 if (iOwner.iStillImagePos.iX >= iOwner.iStillImageSize.iWidth)
352 iOwner.iStillImagePos.iX = 0;
355 if (iOwner.iStillImagePos.iY >= iOwner.iStillImageSize.iHeight)
357 iOwner.iStillImagePos.iY = 0;