sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// testsnapshot.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "test_snapshot.h"
|
sl@0
|
19 |
#include <ecamerrors.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
CTestCamSnapshot::CTestCamSnapshot(CTestCamera& aOwner): iOwner(aOwner), iSnapshotBuffer(iSnapshot)
|
sl@0
|
22 |
{
|
sl@0
|
23 |
Init();
|
sl@0
|
24 |
}
|
sl@0
|
25 |
|
sl@0
|
26 |
CTestCamSnapshot::~CTestCamSnapshot()
|
sl@0
|
27 |
{
|
sl@0
|
28 |
delete iSnapshotImage;
|
sl@0
|
29 |
iSnapshotImage = NULL;
|
sl@0
|
30 |
delete iSnapshotImageGc;
|
sl@0
|
31 |
iSnapshotImage = NULL;
|
sl@0
|
32 |
delete iSnapshotImageDev;
|
sl@0
|
33 |
iSnapshotImageDev = NULL;
|
sl@0
|
34 |
|
sl@0
|
35 |
delete iSnapshot;
|
sl@0
|
36 |
iSnapshot = NULL;
|
sl@0
|
37 |
delete iSnapshotGc;
|
sl@0
|
38 |
iSnapshotGc = NULL;
|
sl@0
|
39 |
delete iSnapshotDev;
|
sl@0
|
40 |
iSnapshotDev = NULL;
|
sl@0
|
41 |
|
sl@0
|
42 |
iSupportedSnapshotRect.Close();
|
sl@0
|
43 |
|
sl@0
|
44 |
CDataGlobal* globalData = static_cast <CDataGlobal*> (Dll::Tls());
|
sl@0
|
45 |
if(globalData != NULL)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
if(!globalData->iTestCamPresets && !globalData->iTestCamAdvSet && !globalData->iTestCamImgProc)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
delete globalData;
|
sl@0
|
50 |
Dll::FreeTls();
|
sl@0
|
51 |
}
|
sl@0
|
52 |
else
|
sl@0
|
53 |
{
|
sl@0
|
54 |
globalData->iTestCamSnapshot = NULL;
|
sl@0
|
55 |
Dll::SetTls(globalData);
|
sl@0
|
56 |
}
|
sl@0
|
57 |
}
|
sl@0
|
58 |
}
|
sl@0
|
59 |
|
sl@0
|
60 |
CTestCamSnapshot* CTestCamSnapshot::NewL(CTestCamera& aOwner)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
CDataGlobal* globalData = static_cast <CDataGlobal*> (Dll::Tls());
|
sl@0
|
63 |
|
sl@0
|
64 |
if(globalData == NULL)
|
sl@0
|
65 |
{
|
sl@0
|
66 |
globalData = new (ELeave) CDataGlobal;
|
sl@0
|
67 |
CleanupStack::PushL(globalData);
|
sl@0
|
68 |
globalData->iSnapshotReferenceCount = 0;
|
sl@0
|
69 |
globalData->iTestCamSnapshot = new (ELeave) CTestCamSnapshot(aOwner);
|
sl@0
|
70 |
CleanupStack::PushL(globalData->iTestCamSnapshot);
|
sl@0
|
71 |
globalData->iTestCamSnapshot->ConstructL();
|
sl@0
|
72 |
globalData->iTestCamSnapshot->iRefCount = 1;
|
sl@0
|
73 |
User::LeaveIfError(Dll::SetTls(globalData));
|
sl@0
|
74 |
CleanupStack::Pop(globalData->iTestCamSnapshot);
|
sl@0
|
75 |
CleanupStack::Pop(globalData);
|
sl@0
|
76 |
return globalData->iTestCamSnapshot;
|
sl@0
|
77 |
}
|
sl@0
|
78 |
else
|
sl@0
|
79 |
{
|
sl@0
|
80 |
if(globalData->iTestCamSnapshot == NULL)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
globalData->iSnapshotReferenceCount = 0;
|
sl@0
|
83 |
globalData->iTestCamSnapshot = new (ELeave) CTestCamSnapshot(aOwner);
|
sl@0
|
84 |
CleanupStack::PushL(globalData->iTestCamSnapshot);
|
sl@0
|
85 |
globalData->iTestCamSnapshot->ConstructL();
|
sl@0
|
86 |
globalData->iTestCamSnapshot->iRefCount = 1;
|
sl@0
|
87 |
User::LeaveIfError(Dll::SetTls(globalData));
|
sl@0
|
88 |
CleanupStack::Pop(globalData->iTestCamSnapshot);
|
sl@0
|
89 |
return globalData->iTestCamSnapshot;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
CTestCamSnapshot* self = globalData->iTestCamSnapshot;
|
sl@0
|
93 |
|
sl@0
|
94 |
globalData->iSnapshotReferenceCount++;
|
sl@0
|
95 |
self->iRefCount = globalData->iSnapshotReferenceCount + 1;
|
sl@0
|
96 |
if (globalData->iSnapshotReferenceCount == KNumOfSnapshotExtensions-1 )
|
sl@0
|
97 |
{
|
sl@0
|
98 |
globalData->iTestCamSnapshot = NULL;
|
sl@0
|
99 |
if(!globalData->iTestCamPresets && !globalData->iTestCamAdvSet && !globalData->iTestCamImgProc)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
delete globalData;
|
sl@0
|
102 |
Dll::FreeTls();
|
sl@0
|
103 |
}
|
sl@0
|
104 |
else
|
sl@0
|
105 |
{
|
sl@0
|
106 |
User::LeaveIfError(Dll::SetTls(globalData));
|
sl@0
|
107 |
}
|
sl@0
|
108 |
}
|
sl@0
|
109 |
else
|
sl@0
|
110 |
{
|
sl@0
|
111 |
User::LeaveIfError(Dll::SetTls(globalData));
|
sl@0
|
112 |
}
|
sl@0
|
113 |
return self;
|
sl@0
|
114 |
}
|
sl@0
|
115 |
}
|
sl@0
|
116 |
|
sl@0
|
117 |
void CTestCamSnapshot::Release()
|
sl@0
|
118 |
{
|
sl@0
|
119 |
iRefCount--;
|
sl@0
|
120 |
if(iRefCount == 0)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
iOwner.iSnapshotImpl = NULL;
|
sl@0
|
123 |
delete this;
|
sl@0
|
124 |
}
|
sl@0
|
125 |
}
|
sl@0
|
126 |
|
sl@0
|
127 |
void CTestCamSnapshot::Init()
|
sl@0
|
128 |
{
|
sl@0
|
129 |
iImageFormatsSupported = 0;
|
sl@0
|
130 |
iImageFormatsSupported |= CCamera::EFormatFbsBitmapColor4K;
|
sl@0
|
131 |
iImageFormatsSupported |= CCamera::EFormatFbsBitmapColor64K;
|
sl@0
|
132 |
iImageFormatsSupported |= CCamera::EFormatFbsBitmapColor16M;
|
sl@0
|
133 |
iSnapshotPrepared = EFalse;
|
sl@0
|
134 |
iSnapshotActive = EFalse;
|
sl@0
|
135 |
iBgColor = KRgbWhite;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
|
sl@0
|
138 |
void CTestCamSnapshot::ConstructL()
|
sl@0
|
139 |
{
|
sl@0
|
140 |
iSupportedSnapshotRect.Reset();
|
sl@0
|
141 |
iSupportedSnapshotRect.AppendL(TRect(TPoint(0,0), iOwner.iImageSizes[0]));
|
sl@0
|
142 |
iSupportedSnapshotRect.AppendL(TRect(TPoint(0,0), iOwner.iImageSizes[1]));
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
TUint32 CTestCamSnapshot::SupportedFormats()
|
sl@0
|
146 |
{
|
sl@0
|
147 |
return iImageFormatsSupported;
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
void CTestCamSnapshot::PrepareSnapshotL(CCamera::TFormat aFormat, const TPoint& aPosition, const TSize& aSize, const TRgb& aBgColor, TBool /*aMaintainAspectRatio*/)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
iOwner.CheckReserveAndPowerL();
|
sl@0
|
153 |
|
sl@0
|
154 |
if (iOwner.iVideoCaptureActive || iOwner.iImageCaptureActive)
|
sl@0
|
155 |
{
|
sl@0
|
156 |
User::Leave(KErrNotReady);
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
if (!(aFormat & iImageFormatsSupported) )
|
sl@0
|
160 |
{
|
sl@0
|
161 |
User::Leave(KErrNotSupported);
|
sl@0
|
162 |
}
|
sl@0
|
163 |
|
sl@0
|
164 |
//check if the snapshot size is supported
|
sl@0
|
165 |
TRect snapshot_rect = TRect(aPosition, aSize);
|
sl@0
|
166 |
|
sl@0
|
167 |
if(snapshot_rect != iSupportedSnapshotRect[0] && snapshot_rect != iSupportedSnapshotRect[1])
|
sl@0
|
168 |
{
|
sl@0
|
169 |
User::Leave(KErrNotSupported);
|
sl@0
|
170 |
}
|
sl@0
|
171 |
|
sl@0
|
172 |
if (iSnapshotPrepared
|
sl@0
|
173 |
&& iSnapshotFormat == aFormat
|
sl@0
|
174 |
&& iSnapshotImageRect == snapshot_rect
|
sl@0
|
175 |
&& iBgColor == aBgColor
|
sl@0
|
176 |
)
|
sl@0
|
177 |
{
|
sl@0
|
178 |
return;
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
TDisplayMode displayMode = ENone;
|
sl@0
|
182 |
switch (aFormat)
|
sl@0
|
183 |
{
|
sl@0
|
184 |
case CCamera::EFormatFbsBitmapColor4K :
|
sl@0
|
185 |
displayMode = EColor4K;
|
sl@0
|
186 |
break;
|
sl@0
|
187 |
case CCamera::EFormatFbsBitmapColor64K :
|
sl@0
|
188 |
displayMode = EColor64K;
|
sl@0
|
189 |
break;
|
sl@0
|
190 |
case CCamera::EFormatFbsBitmapColor16M :
|
sl@0
|
191 |
displayMode = EColor16M;
|
sl@0
|
192 |
break;
|
sl@0
|
193 |
default :
|
sl@0
|
194 |
User::Leave(KErrNotSupported);
|
sl@0
|
195 |
break;
|
sl@0
|
196 |
}
|
sl@0
|
197 |
|
sl@0
|
198 |
delete iSnapshotImage;
|
sl@0
|
199 |
iSnapshotImage = NULL;
|
sl@0
|
200 |
delete iSnapshotImageGc;
|
sl@0
|
201 |
iSnapshotImageGc = NULL;
|
sl@0
|
202 |
delete iSnapshotImageDev;
|
sl@0
|
203 |
iSnapshotImageDev = NULL;
|
sl@0
|
204 |
|
sl@0
|
205 |
iSnapshotImage = new(ELeave) CFbsBitmap;
|
sl@0
|
206 |
User::LeaveIfError(iSnapshotImage->Create(aSize, displayMode));
|
sl@0
|
207 |
iSnapshotImageDev = CFbsBitmapDevice::NewL(iSnapshotImage);
|
sl@0
|
208 |
User::LeaveIfError(iSnapshotImageDev->CreateContext(iSnapshotImageGc));
|
sl@0
|
209 |
iSnapshotImageGc->SetPenColor(KRgbBlack);
|
sl@0
|
210 |
iSnapshotImageGc->SetPenSize(TSize(KFrameFeatureBorderThickness, KFrameFeatureBorderThickness));
|
sl@0
|
211 |
iSnapshotImageGc->SetBrushColor(aBgColor);
|
sl@0
|
212 |
iSnapshotImageGc->SetFaded(ETrue);
|
sl@0
|
213 |
|
sl@0
|
214 |
iSnapshotPrepared = ETrue;
|
sl@0
|
215 |
iSnapshotImageRect = snapshot_rect;
|
sl@0
|
216 |
iSnapshotFormat = aFormat;
|
sl@0
|
217 |
iBgColor = aBgColor;
|
sl@0
|
218 |
}
|
sl@0
|
219 |
|
sl@0
|
220 |
void CTestCamSnapshot::PrepareSnapshotL(CCamera::TFormat /*aFormat*/, const TSize& /*aSize*/, TBool /*aMaintainAspectRatio*/)
|
sl@0
|
221 |
{
|
sl@0
|
222 |
User::Leave(KErrNotSupported);
|
sl@0
|
223 |
}
|
sl@0
|
224 |
|
sl@0
|
225 |
void CTestCamSnapshot::SetBgColorL(const TRgb& /*aBgColor*/)
|
sl@0
|
226 |
{
|
sl@0
|
227 |
User::Leave(KErrNotSupported);
|
sl@0
|
228 |
}
|
sl@0
|
229 |
|
sl@0
|
230 |
void CTestCamSnapshot::SetPositionL(const TPoint& /*aPosition*/)
|
sl@0
|
231 |
{
|
sl@0
|
232 |
User::Leave(KErrNotSupported);
|
sl@0
|
233 |
}
|
sl@0
|
234 |
|
sl@0
|
235 |
TBool CTestCamSnapshot::IsSnapshotActive() const
|
sl@0
|
236 |
{
|
sl@0
|
237 |
return iSnapshotActive;
|
sl@0
|
238 |
}
|
sl@0
|
239 |
|
sl@0
|
240 |
void CTestCamSnapshot::StartSnapshot()
|
sl@0
|
241 |
{
|
sl@0
|
242 |
TInt error = iOwner.CheckReserveAndPower();
|
sl@0
|
243 |
|
sl@0
|
244 |
if(error == KErrNone)
|
sl@0
|
245 |
{
|
sl@0
|
246 |
if(!iSnapshotPrepared)
|
sl@0
|
247 |
{
|
sl@0
|
248 |
error = KErrNotReady;
|
sl@0
|
249 |
}
|
sl@0
|
250 |
}
|
sl@0
|
251 |
|
sl@0
|
252 |
if(error != KErrNone)
|
sl@0
|
253 |
{
|
sl@0
|
254 |
TECAMEvent ecamevent(KUidECamEventCameraSnapshot, error);
|
sl@0
|
255 |
|
sl@0
|
256 |
iOwner.iECamEvent = ecamevent;
|
sl@0
|
257 |
iOwner.iHandleEventAsync.CallBack();
|
sl@0
|
258 |
return;
|
sl@0
|
259 |
}
|
sl@0
|
260 |
|
sl@0
|
261 |
delete iSnapshot;
|
sl@0
|
262 |
iSnapshot = NULL;
|
sl@0
|
263 |
delete iSnapshotGc;
|
sl@0
|
264 |
iSnapshot = NULL;
|
sl@0
|
265 |
delete iSnapshotDev;
|
sl@0
|
266 |
iSnapshotDev = NULL;
|
sl@0
|
267 |
|
sl@0
|
268 |
TRAP(error, DoStartSnapshotL());
|
sl@0
|
269 |
|
sl@0
|
270 |
if(error != KErrNone)
|
sl@0
|
271 |
{
|
sl@0
|
272 |
TECAMEvent ecamevent(KUidECamEventCameraSnapshot, error);
|
sl@0
|
273 |
|
sl@0
|
274 |
iOwner.iECamEvent = ecamevent;
|
sl@0
|
275 |
iOwner.iHandleEventAsync.CallBack();
|
sl@0
|
276 |
}
|
sl@0
|
277 |
}
|
sl@0
|
278 |
|
sl@0
|
279 |
void CTestCamSnapshot::DoStartSnapshotL()
|
sl@0
|
280 |
{
|
sl@0
|
281 |
CFbsBitmap* snapshot = new(ELeave) CFbsBitmap;
|
sl@0
|
282 |
CleanupStack::PushL(snapshot);
|
sl@0
|
283 |
User::LeaveIfError(snapshot->Create(iSnapshotImageRect.Size(), iSnapshotImage->DisplayMode()));
|
sl@0
|
284 |
CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(snapshot);
|
sl@0
|
285 |
CleanupStack::PushL(dev);
|
sl@0
|
286 |
CFbsBitGc* gc = NULL;
|
sl@0
|
287 |
User::LeaveIfError(dev->CreateContext(gc));
|
sl@0
|
288 |
CleanupStack::Pop(dev);
|
sl@0
|
289 |
CleanupStack::Pop(snapshot);
|
sl@0
|
290 |
|
sl@0
|
291 |
iSnapshot = snapshot;
|
sl@0
|
292 |
iSnapshotDev = dev;
|
sl@0
|
293 |
iSnapshotGc = gc;
|
sl@0
|
294 |
|
sl@0
|
295 |
iSnapshotActive = ETrue;
|
sl@0
|
296 |
}
|
sl@0
|
297 |
|
sl@0
|
298 |
void CTestCamSnapshot::StopSnapshot()
|
sl@0
|
299 |
{
|
sl@0
|
300 |
delete iSnapshotGc;
|
sl@0
|
301 |
iSnapshotGc = NULL;
|
sl@0
|
302 |
delete iSnapshotDev;
|
sl@0
|
303 |
iSnapshotDev = NULL;
|
sl@0
|
304 |
delete iSnapshot;
|
sl@0
|
305 |
iSnapshot = NULL;
|
sl@0
|
306 |
|
sl@0
|
307 |
iSnapshotActive = EFalse;
|
sl@0
|
308 |
}
|
sl@0
|
309 |
|
sl@0
|
310 |
MCameraBuffer& CTestCamSnapshot::SnapshotDataL(RArray<TInt>& /*aFrameIndexOrder*/)
|
sl@0
|
311 |
{
|
sl@0
|
312 |
iSnapshotBuffer.iAvailable = EFalse;
|
sl@0
|
313 |
return iSnapshotBuffer;
|
sl@0
|
314 |
}
|
sl@0
|
315 |
|
sl@0
|
316 |
void CTestCamSnapshot::ServiceSnapshot(const CFbsBitGc& aSourceBitmapGc)
|
sl@0
|
317 |
{
|
sl@0
|
318 |
TInt error = KErrNone;
|
sl@0
|
319 |
if(!iSnapshotBuffer.iAvailable)
|
sl@0
|
320 |
{
|
sl@0
|
321 |
error = KErrInUse;
|
sl@0
|
322 |
}
|
sl@0
|
323 |
else
|
sl@0
|
324 |
{
|
sl@0
|
325 |
iSnapshotGc->BitBlt(TPoint(0,0), aSourceBitmapGc);
|
sl@0
|
326 |
}
|
sl@0
|
327 |
|
sl@0
|
328 |
iOwner.iObserver2->HandleEvent(TECAMEvent(KUidECamEventCameraSnapshot, error));
|
sl@0
|
329 |
}
|
sl@0
|
330 |
|
sl@0
|
331 |
void CTestCamSnapshot::ServiceBurstImageSnapshot(const CFbsBitGc& aSourceBitmapGc)
|
sl@0
|
332 |
{
|
sl@0
|
333 |
TInt error = KErrNone;
|
sl@0
|
334 |
if(!iSnapshotBuffer.iAvailable)
|
sl@0
|
335 |
{
|
sl@0
|
336 |
error = KErrInUse;
|
sl@0
|
337 |
}
|
sl@0
|
338 |
else
|
sl@0
|
339 |
{
|
sl@0
|
340 |
iSnapshotGc->BitBlt(TPoint(0,0), aSourceBitmapGc);
|
sl@0
|
341 |
}
|
sl@0
|
342 |
|
sl@0
|
343 |
iOwner.iObserver2->HandleEvent(TECAMEvent(KUidECamEventCameraSnapshot, error));
|
sl@0
|
344 |
|
sl@0
|
345 |
User::After(500000);
|
sl@0
|
346 |
|
sl@0
|
347 |
iOwner.iStillImagePos.iX += KFramePosIncrement;
|
sl@0
|
348 |
iOwner.iStillImagePos.iY += KFramePosIncrement;
|
sl@0
|
349 |
|
sl@0
|
350 |
if (iOwner.iStillImagePos.iX >= iOwner.iStillImageSize.iWidth)
|
sl@0
|
351 |
{
|
sl@0
|
352 |
iOwner.iStillImagePos.iX = 0;
|
sl@0
|
353 |
}
|
sl@0
|
354 |
|
sl@0
|
355 |
if (iOwner.iStillImagePos.iY >= iOwner.iStillImageSize.iHeight)
|
sl@0
|
356 |
{
|
sl@0
|
357 |
iOwner.iStillImagePos.iY = 0;
|
sl@0
|
358 |
}
|
sl@0
|
359 |
}
|
sl@0
|
360 |
|