sl@0
|
1 |
// Copyright (c) 2002-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 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <eikenv.h>
|
sl@0
|
17 |
#include <TestCameraApp.rsg>
|
sl@0
|
18 |
#include "TestCameraApp.h"
|
sl@0
|
19 |
#include "TestCameraApp.hrh"
|
sl@0
|
20 |
|
sl@0
|
21 |
const TInt KMaxErrLength=50;
|
sl@0
|
22 |
_LIT(KErrorFormat,"Error - %d (%S)");
|
sl@0
|
23 |
|
sl@0
|
24 |
//
|
sl@0
|
25 |
// CTCamAppUi
|
sl@0
|
26 |
//
|
sl@0
|
27 |
|
sl@0
|
28 |
void CTCamAppUi::ConstructL()
|
sl@0
|
29 |
{
|
sl@0
|
30 |
BaseConstructL();
|
sl@0
|
31 |
iAppView = new(ELeave) CTCamAppView;
|
sl@0
|
32 |
iAppView->ConstructL(ClientRect());
|
sl@0
|
33 |
AddToStackL(iAppView);
|
sl@0
|
34 |
|
sl@0
|
35 |
iCamera = CCamera::NewL(*this,0);
|
sl@0
|
36 |
iCamera->Reserve();
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
CTCamAppUi::~CTCamAppUi()
|
sl@0
|
40 |
{
|
sl@0
|
41 |
iCamera->Release();
|
sl@0
|
42 |
delete iCamera;
|
sl@0
|
43 |
if (iAppView)
|
sl@0
|
44 |
{
|
sl@0
|
45 |
RemoveFromStack(iAppView);
|
sl@0
|
46 |
delete iAppView;
|
sl@0
|
47 |
}
|
sl@0
|
48 |
}
|
sl@0
|
49 |
|
sl@0
|
50 |
void CTCamAppUi::HandleCommandL(TInt aCommand)
|
sl@0
|
51 |
{
|
sl@0
|
52 |
switch (aCommand)
|
sl@0
|
53 |
{
|
sl@0
|
54 |
case ETCamCmdPowerOn:
|
sl@0
|
55 |
iCamera->PowerOn();
|
sl@0
|
56 |
break;
|
sl@0
|
57 |
case ETCamCmdPowerOff:
|
sl@0
|
58 |
iCamera->PowerOff();
|
sl@0
|
59 |
break;
|
sl@0
|
60 |
case ETCamCmdViewFinder:
|
sl@0
|
61 |
ViewFinderL();
|
sl@0
|
62 |
break;
|
sl@0
|
63 |
case ETCamCmdCaptureImage:
|
sl@0
|
64 |
CaptureImageL();
|
sl@0
|
65 |
break;
|
sl@0
|
66 |
case ETCamCmdCaptureVideo:
|
sl@0
|
67 |
CaptureVideoL();
|
sl@0
|
68 |
break;
|
sl@0
|
69 |
case ETCamCmdIncBrightness:
|
sl@0
|
70 |
iCamera->SetBrightnessL(iCamera->Brightness() + 10);
|
sl@0
|
71 |
break;
|
sl@0
|
72 |
case ETCamCmdIncContrast:
|
sl@0
|
73 |
iCamera->SetContrastL(iCamera->Contrast() + 10);
|
sl@0
|
74 |
break;
|
sl@0
|
75 |
case ETCamCmdDecBrightness:
|
sl@0
|
76 |
iCamera->SetBrightnessL(iCamera->Brightness() - 10);
|
sl@0
|
77 |
break;
|
sl@0
|
78 |
case ETCamCmdDecContrast:
|
sl@0
|
79 |
iCamera->SetContrastL(iCamera->Contrast() - 10);
|
sl@0
|
80 |
break;
|
sl@0
|
81 |
case ETCamCmdResetBrightness:
|
sl@0
|
82 |
iCamera->SetBrightnessL(0);
|
sl@0
|
83 |
break;
|
sl@0
|
84 |
case ETCamCmdResetContrast:
|
sl@0
|
85 |
iCamera->SetContrastL(0);
|
sl@0
|
86 |
break;
|
sl@0
|
87 |
case EAknSoftkeyBack:
|
sl@0
|
88 |
Exit();
|
sl@0
|
89 |
break;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
void CTCamAppUi::ViewFinderL()
|
sl@0
|
94 |
{
|
sl@0
|
95 |
TSize imageSize;
|
sl@0
|
96 |
iCamera->EnumerateCaptureSizes(imageSize,1,CCamera::EFormatFbsBitmapColor16M);
|
sl@0
|
97 |
const TPoint pos = iAppView->DrawBorders(imageSize);
|
sl@0
|
98 |
TRect screenRect(pos,imageSize);
|
sl@0
|
99 |
TRect clipRect;
|
sl@0
|
100 |
|
sl@0
|
101 |
if (!iCamera->ViewFinderActive())
|
sl@0
|
102 |
iCamera->StartViewFinderDirectL(iCoeEnv->WsSession(),*iCoeEnv->ScreenDevice(),*iAppView->DrawableWindow(),screenRect,clipRect);
|
sl@0
|
103 |
else
|
sl@0
|
104 |
iCamera->StopViewFinder();
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
void CTCamAppUi::CaptureImageL()
|
sl@0
|
108 |
{
|
sl@0
|
109 |
TSize size;
|
sl@0
|
110 |
iCamera->EnumerateCaptureSizes(size,1,CCamera::EFormatFbsBitmapColor16M);
|
sl@0
|
111 |
iCamera->PrepareImageCaptureL(CCamera::EFormatFbsBitmapColor16M,1);
|
sl@0
|
112 |
iCamera->CaptureImage();
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
void CTCamAppUi::CaptureVideoL()
|
sl@0
|
116 |
{
|
sl@0
|
117 |
if (!iCamera->VideoCaptureActive())
|
sl@0
|
118 |
{
|
sl@0
|
119 |
TSize size;
|
sl@0
|
120 |
TReal32 rate = 0;
|
sl@0
|
121 |
iCamera->EnumerateVideoFrameSizes(size,0,CCamera::EFormatFbsBitmapColor16M);
|
sl@0
|
122 |
iCamera->EnumerateVideoFrameRates(rate,0,CCamera::EFormatFbsBitmapColor16M,0);
|
sl@0
|
123 |
iCamera->PrepareVideoCaptureL(CCamera::EFormatFbsBitmapColor16M,0,0,2,1);
|
sl@0
|
124 |
iCamera->StartVideoCapture();
|
sl@0
|
125 |
}
|
sl@0
|
126 |
else
|
sl@0
|
127 |
iCamera->StopVideoCapture();
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
void CTCamAppUi::ReserveComplete(TInt /*aError*/)
|
sl@0
|
131 |
{
|
sl@0
|
132 |
}
|
sl@0
|
133 |
|
sl@0
|
134 |
void CTCamAppUi::PowerOnComplete(TInt /*aError*/)
|
sl@0
|
135 |
{
|
sl@0
|
136 |
}
|
sl@0
|
137 |
|
sl@0
|
138 |
void CTCamAppUi::ViewFinderFrameReady(CFbsBitmap& /*aFrame*/)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
void CTCamAppUi::ImageReady(CFbsBitmap* aBitmap,HBufC8* /*aData*/,TInt aError)
|
sl@0
|
143 |
{
|
sl@0
|
144 |
TBuf<KMaxErrLength> msgBuffer;
|
sl@0
|
145 |
_LIT(KErrMessage,"CTCamAppUi::ImageReady");
|
sl@0
|
146 |
if (aBitmap)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
iAppView->DrawImage(aBitmap);
|
sl@0
|
149 |
delete aBitmap;
|
sl@0
|
150 |
}
|
sl@0
|
151 |
if (aError)
|
sl@0
|
152 |
{
|
sl@0
|
153 |
msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
|
sl@0
|
154 |
iEikonEnv->InfoMsg(msgBuffer);
|
sl@0
|
155 |
}
|
sl@0
|
156 |
}
|
sl@0
|
157 |
|
sl@0
|
158 |
void CTCamAppUi::FrameBufferReady(MFrameBuffer* aFrameBuffer,TInt aError)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
TBuf<KMaxErrLength> msgBuffer;
|
sl@0
|
161 |
_LIT(KErrMessage,"CTCamAppUi::FrameBufferReady");
|
sl@0
|
162 |
if (aError)
|
sl@0
|
163 |
{
|
sl@0
|
164 |
msgBuffer.Format(KErrorFormat,aError,&KErrMessage);
|
sl@0
|
165 |
iEikonEnv->InfoMsg(msgBuffer);
|
sl@0
|
166 |
return;
|
sl@0
|
167 |
}
|
sl@0
|
168 |
TRAPD(error,iAppView->DrawImage(aFrameBuffer->FrameL(0)));
|
sl@0
|
169 |
aFrameBuffer->Release();
|
sl@0
|
170 |
if (error)
|
sl@0
|
171 |
{
|
sl@0
|
172 |
msgBuffer.Format(KErrorFormat,error,&KErrMessage);
|
sl@0
|
173 |
iEikonEnv->InfoMsg(msgBuffer);
|
sl@0
|
174 |
}
|
sl@0
|
175 |
}
|
sl@0
|
176 |
|
sl@0
|
177 |
_LIT(KContrastDialogTitle,"Contrast");
|
sl@0
|
178 |
_LIT(KBrightnessDialogTitle,"Brightness");
|
sl@0
|
179 |
|
sl@0
|
180 |
//
|
sl@0
|
181 |
// CTCamAppView
|
sl@0
|
182 |
//
|
sl@0
|
183 |
|
sl@0
|
184 |
CTCamAppView::CTCamAppView():
|
sl@0
|
185 |
CCoeControl()
|
sl@0
|
186 |
{}
|
sl@0
|
187 |
|
sl@0
|
188 |
void CTCamAppView::ConstructL(const TRect& aRect)
|
sl@0
|
189 |
{
|
sl@0
|
190 |
CreateWindowL();
|
sl@0
|
191 |
SetRect(aRect);
|
sl@0
|
192 |
EnableDragEvents();
|
sl@0
|
193 |
ActivateL();
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
CTCamAppView::~CTCamAppView()
|
sl@0
|
197 |
{}
|
sl@0
|
198 |
|
sl@0
|
199 |
void CTCamAppView::DrawImage(CFbsBitmap* aImage) const
|
sl@0
|
200 |
{
|
sl@0
|
201 |
CWindowGc& gc = SystemGc();
|
sl@0
|
202 |
gc.Activate(Window());
|
sl@0
|
203 |
TRect drawRect(Rect());
|
sl@0
|
204 |
TPoint pos;
|
sl@0
|
205 |
pos.iX = (drawRect.iBr.iX - aImage->SizeInPixels().iWidth) / 2;
|
sl@0
|
206 |
pos.iY = (drawRect.iBr.iY - aImage->SizeInPixels().iHeight) / 2;
|
sl@0
|
207 |
gc.BitBlt(pos,aImage);
|
sl@0
|
208 |
gc.Deactivate();
|
sl@0
|
209 |
iCoeEnv->WsSession().Flush();
|
sl@0
|
210 |
}
|
sl@0
|
211 |
|
sl@0
|
212 |
void CTCamAppView::Draw(const TRect& /*aRect*/) const
|
sl@0
|
213 |
{
|
sl@0
|
214 |
CWindowGc& gc = SystemGc();
|
sl@0
|
215 |
TRect drawRect(Rect());
|
sl@0
|
216 |
drawRect.Shrink(1,1);
|
sl@0
|
217 |
gc.DrawRect(drawRect);
|
sl@0
|
218 |
gc.Clear();
|
sl@0
|
219 |
}
|
sl@0
|
220 |
|
sl@0
|
221 |
TPoint CTCamAppView::DrawBorders(const TSize& aSize) const
|
sl@0
|
222 |
{
|
sl@0
|
223 |
CWindowGc& gc = SystemGc();
|
sl@0
|
224 |
gc.Activate(Window());
|
sl@0
|
225 |
TRect drawRect(Rect());
|
sl@0
|
226 |
TPoint pos;
|
sl@0
|
227 |
pos.iX = (drawRect.iBr.iX - aSize.iWidth) / 2;
|
sl@0
|
228 |
pos.iY = (drawRect.iBr.iY - aSize.iHeight) / 2;
|
sl@0
|
229 |
TRect border(pos,aSize);
|
sl@0
|
230 |
border.Grow(1,1);
|
sl@0
|
231 |
gc.SetPenColor(KRgbBlack);
|
sl@0
|
232 |
gc.DrawRect(border);
|
sl@0
|
233 |
gc.Deactivate();
|
sl@0
|
234 |
iCoeEnv->WsSession().Flush();
|
sl@0
|
235 |
return pos;
|
sl@0
|
236 |
}
|
sl@0
|
237 |
|
sl@0
|
238 |
//
|
sl@0
|
239 |
// CTCamDocument
|
sl@0
|
240 |
//
|
sl@0
|
241 |
|
sl@0
|
242 |
CTCamDocument::CTCamDocument(CEikApplication& aApp)
|
sl@0
|
243 |
: CAknDocument(aApp)
|
sl@0
|
244 |
{
|
sl@0
|
245 |
}
|
sl@0
|
246 |
|
sl@0
|
247 |
CEikAppUi* CTCamDocument::CreateAppUiL()
|
sl@0
|
248 |
{
|
sl@0
|
249 |
return new(ELeave) CTCamAppUi;
|
sl@0
|
250 |
}
|
sl@0
|
251 |
|
sl@0
|
252 |
//
|
sl@0
|
253 |
// CTCamApp
|
sl@0
|
254 |
//
|
sl@0
|
255 |
|
sl@0
|
256 |
TUid CTCamApp::AppDllUid() const
|
sl@0
|
257 |
{
|
sl@0
|
258 |
return KUidTestCameraApp;
|
sl@0
|
259 |
}
|
sl@0
|
260 |
|
sl@0
|
261 |
CApaDocument* CTCamApp::CreateDocumentL()
|
sl@0
|
262 |
{
|
sl@0
|
263 |
return new(ELeave) CTCamDocument(*this);
|
sl@0
|
264 |
}
|
sl@0
|
265 |
|
sl@0
|
266 |
|
sl@0
|
267 |
//
|
sl@0
|
268 |
// Base factory function
|
sl@0
|
269 |
//
|
sl@0
|
270 |
|
sl@0
|
271 |
#include <eikstart.h>
|
sl@0
|
272 |
LOCAL_C CApaApplication* NewApplication()
|
sl@0
|
273 |
{
|
sl@0
|
274 |
return new CTCamApp;
|
sl@0
|
275 |
}
|
sl@0
|
276 |
|
sl@0
|
277 |
//
|
sl@0
|
278 |
// EXE Entry point
|
sl@0
|
279 |
//
|
sl@0
|
280 |
|
sl@0
|
281 |
GLDEF_C TInt E32Main()
|
sl@0
|
282 |
{
|
sl@0
|
283 |
return EikStart::RunApplication(NewApplication);
|
sl@0
|
284 |
}
|
sl@0
|
285 |
|
sl@0
|
286 |
|
sl@0
|
287 |
|
sl@0
|
288 |
|
sl@0
|
289 |
|