|
1 /* |
|
2 * Copyright (c) 2010 ISB. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "Symbian Foundation License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * ISB - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "ecamwebcameravfactive.h" |
|
19 |
|
20 const TInt KVfWidth = 160; // viewfinder image width |
|
21 const TInt KVfHeight = 120; // viewfinder image height |
|
22 const TInt KVfLineBytes = KVfWidth * 3; // bytes of one line |
|
23 |
|
24 // |
|
25 // CWebCameraVfActive |
|
26 // |
|
27 CWebCameraVfActive* CWebCameraVfActive::NewL(MWebCameraVfActiveCallBack* aOwner, RWebcameraDevice& aDriver) |
|
28 { |
|
29 CWebCameraVfActive* self = new(ELeave) CWebCameraVfActive(aOwner, aDriver); |
|
30 CleanupStack::PushL(self); |
|
31 self->ConstructL(); |
|
32 CleanupStack::Pop(self); |
|
33 |
|
34 return self; |
|
35 } |
|
36 |
|
37 CWebCameraVfActive::CWebCameraVfActive(MWebCameraVfActiveCallBack* aOwner, RWebcameraDevice& aDriver) |
|
38 :CActive(CActive::EPriorityStandard), |
|
39 iOwner(aOwner), |
|
40 iDriver(aDriver), |
|
41 iVfBufPtr(NULL, 0) |
|
42 { |
|
43 CActiveScheduler::Add(this); |
|
44 } |
|
45 |
|
46 CWebCameraVfActive::~CWebCameraVfActive() |
|
47 { |
|
48 delete iVfBitmap; |
|
49 delete iDSA; |
|
50 delete iVfBuf; |
|
51 } |
|
52 |
|
53 void CWebCameraVfActive::ConstructL() |
|
54 { |
|
55 } |
|
56 |
|
57 /** |
|
58 * RunL. |
|
59 */ |
|
60 void CWebCameraVfActive::RunL() |
|
61 { |
|
62 TInt wError = iStatus.Int(); |
|
63 RDebug::Print(_L("CWebCameraVfActive::RunL wError = %d"), wError); |
|
64 |
|
65 if (iViewFinderActive) |
|
66 { |
|
67 //The whole view finder start repeats screen update and the data acquisition. |
|
68 UpdateViewL(); |
|
69 Start(); |
|
70 } |
|
71 } |
|
72 |
|
73 void CWebCameraVfActive::DoCancel() |
|
74 { |
|
75 iDriver.StopViewFinder(); |
|
76 } |
|
77 |
|
78 /** |
|
79 Starts transfer of view finder data to the given portion of the screen using |
|
80 direct screen access. |
|
81 |
|
82 The aScreenRect parameter is in screen co-ordinates and may be modified if, |
|
83 eg, the camera requires the destination to have a certain byte alignment, etc. |
|
84 |
|
85 @param aWs |
|
86 Window server session. |
|
87 @param aScreenDevice |
|
88 Screen device. |
|
89 @param aWindow |
|
90 Displayable window. |
|
91 @param aScreenRect |
|
92 Portion of the screen to which view finder data is to be |
|
93 transferred. This is in screen co-ordinates and may be modified if, for example, |
|
94 the camera requires the destination to have a certain byte alignment. |
|
95 */ |
|
96 void CWebCameraVfActive::StartViewFinderDirectL(RWsSession& aWs, CWsScreenDevice& aScreenDevice, RWindowBase& aWindow, TRect& aScreenRect, TRect& aClipRect) |
|
97 { |
|
98 iScreenRect = aScreenRect; |
|
99 iClipRect = aClipRect; |
|
100 |
|
101 // create buffer for view finder data |
|
102 iVfBuf = HBufC8::NewL(KMaxBufSize); |
|
103 |
|
104 // create DirectScreenAccess |
|
105 delete iDSA; |
|
106 iDSA = NULL; |
|
107 iViewFinderActive = EFalse; |
|
108 iDSA = CDirectScreenAccess::NewL(aWs, aScreenDevice, aWindow, *this); |
|
109 iDSA->StartL(); |
|
110 iViewFinderActive = ETrue; |
|
111 |
|
112 iDSA->Gc()->SetOrigin(); |
|
113 if (!iClipRect.IsEmpty()) |
|
114 { |
|
115 iDSA->Gc()->SetClippingRect(iClipRect); |
|
116 } |
|
117 |
|
118 // start view finder |
|
119 // The division transfer is going to support in the next version. |
|
120 Start(); |
|
121 } |
|
122 |
|
123 /** |
|
124 Stops transfer of view finder data to the screen. |
|
125 */ |
|
126 void CWebCameraVfActive::StopViewFinder() |
|
127 { |
|
128 if (!iViewFinderActive) |
|
129 { |
|
130 return; |
|
131 } |
|
132 |
|
133 iViewFinderActive = EFalse; |
|
134 |
|
135 delete iDSA; |
|
136 iDSA = NULL; |
|
137 |
|
138 delete iVfBuf; |
|
139 iVfBuf = NULL; |
|
140 |
|
141 //Stop view finder |
|
142 iDriver.StopViewFinder(); |
|
143 Cancel(); |
|
144 } |
|
145 |
|
146 /** |
|
147 Queries whether the view finder is active. |
|
148 |
|
149 @return ETrue if the view finder is active. EFalse if the view finder is not |
|
150 active. |
|
151 */ |
|
152 TBool CWebCameraVfActive::ViewFinderActive() |
|
153 { |
|
154 return iViewFinderActive; |
|
155 } |
|
156 |
|
157 /** |
|
158 Start viewfinder process. |
|
159 */ |
|
160 void CWebCameraVfActive::Start() |
|
161 { |
|
162 RDebug::Print(_L("CWebCameraVfActive::Start")); |
|
163 |
|
164 iVfBufPtr.Set(iVfBuf->Des()); |
|
165 iVfBufPtr.SetLength(0); |
|
166 //Start view finder |
|
167 iDriver.StartViewFinder(iStatus, iVfBufPtr); |
|
168 |
|
169 SetActive(); |
|
170 } |
|
171 |
|
172 /** |
|
173 Draw the image of the view finder on screen. |
|
174 */ |
|
175 void CWebCameraVfActive::UpdateViewL() |
|
176 { |
|
177 RDebug::Print(_L("CWebCameraVfActive::UpdateViewL")); |
|
178 |
|
179 delete iVfBitmap; |
|
180 iVfBitmap = NULL; |
|
181 |
|
182 CFbsBitmap* image = new (ELeave) CFbsBitmap(); |
|
183 CleanupStack::PushL(image); |
|
184 User::LeaveIfError(image->Create(TSize(KVfWidth, KVfHeight), EColor16M)); |
|
185 CleanupStack::Pop(image); |
|
186 |
|
187 iVfBitmap = image; |
|
188 |
|
189 // output received data log |
|
190 // RDebug::Print(_L("CWebCameraVfActive::UpdateView iVfBufLength[%d]"), iVfBufPtr.Length()); |
|
191 // TBuf<256> hexBuf; |
|
192 // for (TInt i = 0; i < iVfBufPtr.Length(); i++) |
|
193 // { |
|
194 // hexBuf.AppendFormat(_L("%02X "), iVfBufPtr[i]); |
|
195 // if ((i % 16) == 15) |
|
196 // { |
|
197 // RDebug::Print(hexBuf); |
|
198 // hexBuf = KNullDesC; |
|
199 // } |
|
200 // } |
|
201 // RDebug::Print(hexBuf); |
|
202 |
|
203 // convert buffer data to Bitmap |
|
204 for (TInt height=0; height<KVfHeight; height++) |
|
205 { |
|
206 TInt pos = height * KVfLineBytes; |
|
207 TPtrC8 posptr = iVfBuf->Mid(pos, KVfLineBytes); |
|
208 TBuf8<KVfLineBytes> buf; |
|
209 buf.Copy(posptr); |
|
210 iVfBitmap->SetScanLine(buf, (KVfHeight-1)-height); |
|
211 } |
|
212 |
|
213 // view position setting for test application |
|
214 iScreenRect.iTl.iY = 50; |
|
215 iScreenRect.iBr.iY = 169; |
|
216 |
|
217 // update view |
|
218 iDSA->Gc()->DrawBitmap(iScreenRect, iVfBitmap); |
|
219 iDSA->ScreenDevice()->Update(); |
|
220 } |
|
221 |
|
222 /** |
|
223 from MAbortDirectScreenAccess |
|
224 |
|
225 This function is called by the window server when direct screen access must stop |
|
226 (for example because a dialogue is moved in front of the area where direct screen access is taking place). |
|
227 |
|
228 @param aScreenDevice |
|
229 The reason why direct screen access was terminated. |
|
230 */ |
|
231 void CWebCameraVfActive::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/) |
|
232 { |
|
233 } |
|
234 |
|
235 /** |
|
236 from from MDirectScreenAccess |
|
237 |
|
238 This function is called by the window server as soon as direct screen access can resume. |
|
239 |
|
240 @param aScreenDevice |
|
241 Provides the reason why direct screen access was terminated. |
|
242 */ |
|
243 void CWebCameraVfActive::Restart(RDirectScreenAccess::TTerminationReasons /*aReason*/) |
|
244 { |
|
245 } |
|
246 |