author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:09:54 +0300 | |
branch | RCL_3 |
changeset 67 | 756ad29ed18e |
parent 54 | bac7acad7cb3 |
permissions | -rw-r--r-- |
54 | 1 |
/* |
2 |
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: Implementation of Camera image decoder |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include <imageconversion.h> |
|
20 |
#include <ExifRead.h> |
|
21 |
#include <ecam.h> // MCameraBuffer |
|
22 |
||
23 |
#include <eikenv.h> |
|
24 |
#include <SvgCodecImageConstants.hrh> |
|
25 |
#include <SVGEngineInterfaceImpl.h> |
|
26 |
||
27 |
#include "camlogging.h" |
|
28 |
#include "camfilesaveutility.h" |
|
29 |
#include "cambuffershare.h" |
|
30 |
||
31 |
#include "camimagedecoder.h" |
|
32 |
||
33 |
// =========================================================================== |
|
34 |
// Local constants |
|
35 |
||
36 |
namespace NCamCameraController |
|
37 |
{ |
|
38 |
// Decoding flags |
|
39 |
static const TUint32 KConversionOptions = |
|
40 |
( CImageDecoder::EOptionNone |
|
41 |
| CImageDecoder::EOptionAlwaysThread |
|
42 |
| CImageDecoder::EPreferFastDecode |
|
43 |
); |
|
44 |
||
45 |
// EXIF reader flags |
|
46 |
// Only need the thumbnail, so no need to parse the |
|
47 |
// main (jpeg) image. |
|
48 |
static const TUint KExifReaderFlags = CExifRead::ENoJpeg; |
|
49 |
||
50 |
// Other constants |
|
51 |
static const TInt KMaxRetries = 10; |
|
52 |
static const TInt KPriority = CActive::EPriorityHigh; |
|
53 |
} |
|
54 |
||
55 |
using namespace NCamCameraController; |
|
56 |
||
57 |
// =========================================================================== |
|
58 |
// public constructor and destructor |
|
59 |
||
60 |
CCamImageDecoder* |
|
61 |
CCamImageDecoder::NewL( MCamImageDecoderObserver& aObserver ) |
|
62 |
{ |
|
63 |
CCamImageDecoder* self = |
|
64 |
new (ELeave) CCamImageDecoder( aObserver ); |
|
65 |
||
66 |
CleanupStack::PushL( self ); |
|
67 |
self->ConstructL(); |
|
68 |
CleanupStack::Pop( self ); |
|
69 |
||
70 |
return self; |
|
71 |
} |
|
72 |
||
73 |
||
74 |
CCamImageDecoder::~CCamImageDecoder() |
|
75 |
{ |
|
76 |
PRINT( _L("Camera => ~CCamImageDecoder") ); |
|
77 |
Cancel(); |
|
78 |
||
79 |
delete iDecoder; |
|
80 |
||
81 |
SetImageData( NULL ); |
|
82 |
if(iDecodedBitmap) |
|
83 |
{ |
|
84 |
delete iDecodedBitmap; |
|
85 |
iDecodedBitmap = NULL; |
|
86 |
} |
|
87 |
if ( iDecodedMask ) |
|
88 |
{ |
|
89 |
delete iDecodedMask; |
|
90 |
iDecodedMask = NULL; |
|
91 |
} |
|
92 |
||
93 |
delete iSvgEngine; |
|
94 |
iFs.Close(); |
|
95 |
PRINT( _L("Camera <= ~CCamImageDecoder") ); |
|
96 |
} |
|
97 |
||
98 |
// =========================================================================== |
|
99 |
// public methods |
|
100 |
void |
|
101 |
CCamImageDecoder::StartConversionL( CCamBufferShare* aBuffer ) |
|
102 |
{ |
|
103 |
PRINT( _L("Camera => CCamImageDecoder::StartConversionL") ); |
|
104 |
||
105 |
// Data for CImageDecoder must be available throughout the conversion. |
|
106 |
// Need to stop any outstanding operation before deleting the descriptor. |
|
107 |
Cancel(); |
|
108 |
||
109 |
PRINT( _L("Camera <> CCamImageDecoder: Copying image data..") ); |
|
110 |
||
111 |
SetImageData( aBuffer ); |
|
112 |
||
113 |
// GetImageDataL leaves if no data available. |
|
114 |
TDesC8* imageData = GetImageDataL(); |
|
115 |
||
116 |
PRINT( _L("Camera <> CCamImageDecoder: Creating decoder..") ); |
|
117 |
||
118 |
delete iDecoder; |
|
119 |
iDecoder = NULL; |
|
120 |
iDecoder = CImageDecoder::DataNewL( iFs, *imageData, (CImageDecoder::TOptions)KConversionOptions ); |
|
121 |
||
122 |
if( iDecoder->FrameCount() > 0 ) |
|
123 |
{ |
|
124 |
const TFrameInfo& info( iDecoder->FrameInfo() ); |
|
125 |
||
126 |
#ifdef _DEBUG |
|
127 |
TSize size = info.iOverallSizeInPixels; |
|
128 |
PRINT2( _L("Camera <> CCamImageDecoder: Bmp size(%d,%d)"), size.iWidth, size.iHeight ); |
|
129 |
PRINT1( _L("Camera <> CCamImageDecoder: Bmp dispmode(%d)"), info.iFrameDisplayMode ); |
|
130 |
#endif |
|
131 |
||
132 |
PRINT( _L("Camera <> CCamImageDecoder: Create bitmap for snapshot..") ); |
|
133 |
if( !iDecodedBitmap ) iDecodedBitmap = new (ELeave) CFbsBitmap; |
|
134 |
else iDecodedBitmap->Reset(); |
|
135 |
||
136 |
TInt createError = iDecodedBitmap->Create( info.iOverallSizeInPixels, |
|
137 |
info.iFrameDisplayMode ); |
|
138 |
if( KErrNone != createError ) |
|
139 |
{ |
|
140 |
delete iDecodedBitmap; |
|
141 |
iDecodedBitmap = NULL; |
|
142 |
User::Leave( createError ); |
|
143 |
} |
|
144 |
||
145 |
PRINT( _L("Camera <> CCamImageDecoder: start conversion..") ); |
|
146 |
iRetryCounter = 0; |
|
147 |
iDecoder->Convert( &iStatus, *iDecodedBitmap, 0 ); |
|
148 |
SetActive(); |
|
149 |
} |
|
150 |
else |
|
151 |
{ |
|
152 |
PRINT( _L("Camera <> CCamImageDecoder: No frame provided, leave..") ); |
|
153 |
User::Leave( KErrNotFound ); |
|
154 |
} |
|
155 |
||
156 |
PRINT( _L("Camera <= CCamImageDecoder::StartConversionL") ); |
|
157 |
} |
|
158 |
||
159 |
// --------------------------------------------------------------------------- |
|
160 |
// CCamImageDecoder::StartIconConversionL |
|
161 |
// --------------------------------------------------------------------------- |
|
162 |
// |
|
163 |
void CCamImageDecoder::StartIconConversionL( TDesC* aFilePath, TSize& aSize ) |
|
164 |
{ |
|
165 |
PRINT3( _L("Camera => CCamImageDecoder::StartIconConversionL, file:[%S], size:(%d,%d)"), |
|
166 |
&(*aFilePath), aSize.iWidth, aSize.iHeight ); |
|
167 |
||
168 |
// Delete any previous bitmaps, if any |
|
169 |
delete iDecodedBitmap, |
|
170 |
iDecodedBitmap = NULL; |
|
171 |
delete iDecodedMask; |
|
172 |
iDecodedMask = NULL; |
|
173 |
||
174 |
// Create bitmap for use while decoding |
|
175 |
CFbsBitmap* frameBuffer = new (ELeave) CFbsBitmap; |
|
176 |
CleanupStack::PushL( frameBuffer ); |
|
177 |
||
178 |
TFontSpec spec; |
|
179 |
if ( !iSvgEngine ) |
|
180 |
{ |
|
181 |
iSvgEngine = CSvgEngineInterfaceImpl::NewL( frameBuffer, NULL, spec ); |
|
182 |
} |
|
183 |
||
184 |
TInt domHandle = KErrNotFound; |
|
185 |
MSvgError* serr = iSvgEngine->PrepareDom( *aFilePath, domHandle ); |
|
186 |
PRINT3( _L("Camera <> prepare svg dom reader, warning:%d, err code:%d, description:[%S]"), |
|
187 |
serr->IsWarning(), serr->ErrorCode(), &(serr->Description()) ); |
|
188 |
if ( serr->HasError() && !serr->IsWarning() ) |
|
189 |
{ |
|
190 |
PRINT1( _L("Camera <> leaving with error:%d"), serr->SystemErrorCode() ); |
|
191 |
User::Leave( serr->SystemErrorCode() ); |
|
192 |
} |
|
193 |
||
194 |
// create image bitmap |
|
195 |
PRINT( _L("Camera <> CCamImageDecoder: Create bitmap for snapshot..") ); |
|
196 |
if( !iDecodedBitmap ) iDecodedBitmap = new (ELeave) CFbsBitmap; |
|
197 |
else iDecodedBitmap->Reset(); |
|
198 |
||
199 |
if( !iDecodedMask ) iDecodedMask = new (ELeave) CFbsBitmap; |
|
200 |
else iDecodedMask->Reset(); |
|
201 |
||
202 |
TRAPD ( createError, |
|
203 |
{ |
|
204 |
iDecodedBitmap->Create( aSize, EColor64K ); |
|
205 |
iDecodedMask->Create( aSize, EGray256 ); |
|
206 |
} ); |
|
207 |
if( createError ) |
|
208 |
{ |
|
209 |
PRINT1( _L("Camera <> Error while creating bitmaps:%d"), createError ); |
|
210 |
delete iDecodedBitmap; |
|
211 |
iDecodedBitmap = NULL; |
|
212 |
delete iDecodedMask; |
|
213 |
iDecodedMask = NULL; |
|
214 |
User::Leave( createError ); |
|
215 |
} |
|
216 |
||
217 |
// create soft mask |
|
218 |
iSvgEngine->SetViewportHeight((CSvgDocumentImpl *)domHandle, aSize.iHeight); |
|
219 |
iSvgEngine->SetViewportWidth((CSvgDocumentImpl *)domHandle, aSize.iWidth); |
|
220 |
||
221 |
// render svg image |
|
222 |
serr = iSvgEngine->RenderDom( domHandle, iDecodedBitmap, iDecodedMask ); |
|
223 |
PRINT3( _L("Camera <> render svg, warning:%d, err code:%d, description:[%S]"), |
|
224 |
serr->IsWarning(), serr->ErrorCode(), &(serr->Description()) ); |
|
225 |
if ( serr->HasError() && !serr->IsWarning() ) |
|
226 |
{ |
|
227 |
PRINT1( _L("Camera <> leaving with error:%d"), serr->SystemErrorCode() ); |
|
228 |
User::Leave( serr->SystemErrorCode() ); |
|
229 |
} |
|
230 |
||
231 |
CleanupStack::PopAndDestroy( frameBuffer ); |
|
232 |
if ( !IsActive() ) |
|
233 |
{ |
|
67
756ad29ed18e
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
54
diff
changeset
|
234 |
iStatus=KRequestPending; |
756ad29ed18e
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
54
diff
changeset
|
235 |
TRequestStatus *pS=(&iStatus); |
756ad29ed18e
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
54
diff
changeset
|
236 |
User::RequestComplete(pS,0); |
54 | 237 |
SetActive(); |
238 |
} |
|
239 |
||
240 |
PRINT( _L("Camera <= CCamImageDecoder::StartIconConversionL") ); |
|
241 |
} |
|
242 |
||
243 |
||
244 |
// --------------------------------------------------------------------------- |
|
245 |
// --------------------------------------------------------------------------- |
|
246 |
// |
|
247 |
TDesC8* |
|
248 |
CCamImageDecoder::GetImageDataL() |
|
249 |
{ |
|
250 |
PRINT( _L("Camera => CCamImageDecoder::GetImageDataL") ); |
|
251 |
||
252 |
if( !iSharedImageData || |
|
253 |
!iSharedImageData->SharedBuffer() ) |
|
254 |
{ |
|
255 |
User::Leave( KErrNotFound ); |
|
256 |
} |
|
257 |
||
258 |
TDesC8* data = iSharedImageData->SharedBuffer()->DataL( 0 ); |
|
259 |
||
260 |
if( !data ) |
|
261 |
User::Leave( KErrNotFound ); |
|
262 |
||
263 |
delete iThumbnailData; |
|
264 |
iThumbnailData = ReadExifThumbNail( *data ); // Returns NULL on errors |
|
265 |
||
266 |
#ifdef CAMERAAPP_CREATE_TESTIMAGE |
|
267 |
TRAPD( saveStatus1, SaveImageDataToFileL( *data, _L("testimagefull.jpg") ) ); |
|
268 |
PRINT1( _L("Camera <> CCamImageDecoder: Save full image to file status:%d"), saveStatus1 ); |
|
269 |
if( iThumbnailData ) |
|
270 |
{ |
|
271 |
TRAPD( saveStatus2, SaveImageDataToFileL( *iThumbnailData, _L("testimagethumb.jpg") ) ); |
|
272 |
PRINT1( _L("Camera <> CCamImageDecoder: Save thumbnail to file status:%d"), saveStatus2 ); |
|
273 |
} |
|
274 |
#endif |
|
275 |
||
276 |
||
277 |
if( iThumbnailData ) |
|
278 |
{ |
|
279 |
data = iThumbnailData; |
|
280 |
} |
|
281 |
||
282 |
PRINT1( _L("Camera <= CCamImageDecoder::GetImageDataL, data size:%d"), data->Size() ); |
|
283 |
return data; |
|
284 |
} |
|
285 |
||
286 |
// --------------------------------------------------------------------------- |
|
287 |
// --------------------------------------------------------------------------- |
|
288 |
// |
|
289 |
HBufC8* |
|
290 |
CCamImageDecoder::ReadExifThumbNail( const TDesC8& aExifData ) |
|
291 |
{ |
|
292 |
PRINT( _L("Camera => CCamImageDecoder::ReadExifThumbNailL") ); |
|
293 |
HBufC8* thumb = NULL; |
|
294 |
TRAP_IGNORE( |
|
295 |
{ |
|
296 |
CExifRead* reader = CExifRead::NewL( aExifData, KExifReaderFlags ); |
|
297 |
CleanupStack::PushL( reader ); |
|
298 |
thumb = reader->GetThumbnailL(); |
|
299 |
CleanupStack::PopAndDestroy( reader ); |
|
300 |
}); |
|
301 |
||
302 |
PRINT( _L("Camera <= CCamImageDecoder::ReadExifThumbNailL") ); |
|
303 |
return thumb; |
|
304 |
} |
|
305 |
||
306 |
// =========================================================================== |
|
307 |
// from CActive |
|
308 |
||
309 |
// --------------------------------------------------------------------------- |
|
310 |
// virtual |
|
311 |
// --------------------------------------------------------------------------- |
|
312 |
// |
|
313 |
void |
|
314 |
CCamImageDecoder::DoCancel() |
|
315 |
{ |
|
316 |
PRINT( _L("Camera => CCamImageDecoder::DoCancel") ); |
|
317 |
||
318 |
if( iDecoder ) |
|
319 |
{ |
|
320 |
iDecoder->Cancel(); |
|
321 |
delete iDecoder; |
|
322 |
iDecoder = NULL; |
|
323 |
} |
|
324 |
||
325 |
SetImageData( NULL ); |
|
326 |
||
327 |
PRINT( _L("Camera <= CCamImageDecoder::DoCancel") ); |
|
328 |
} |
|
329 |
||
330 |
||
331 |
// --------------------------------------------------------------------------- |
|
332 |
// virtual |
|
333 |
// --------------------------------------------------------------------------- |
|
334 |
// |
|
335 |
void |
|
336 |
CCamImageDecoder::RunL() |
|
337 |
{ |
|
338 |
PRINT1( _L("Camera => CCamImageDecoder::RunL, iStatus:%d"), iStatus.Int() ); |
|
339 |
||
340 |
switch( iStatus.Int() ) |
|
341 |
{ |
|
342 |
case KErrNone : |
|
343 |
{ |
|
344 |
// CImageDecoder has finished using the data, |
|
345 |
// so we are able to free it. |
|
346 |
if ( iSvgEngine ) |
|
347 |
{ |
|
348 |
iSvgEngine->Destroy(); |
|
349 |
delete iSvgEngine; |
|
350 |
iSvgEngine = NULL; |
|
351 |
} |
|
352 |
SetImageData( NULL ); |
|
353 |
iObserver.ImageDecodedL( iStatus.Int(), iDecodedBitmap, iDecodedMask ); |
|
354 |
break; |
|
355 |
} |
|
356 |
case KErrUnderflow : |
|
357 |
{ |
|
358 |
// Decoder did not have enough data to convert. |
|
359 |
// CImageDecoder documentation recommends calling |
|
360 |
// repeatedly ContinueConvert. |
|
361 |
if( iRetryCounter++ < KMaxRetries ) |
|
362 |
{ |
|
363 |
iStatus = KErrNone; |
|
364 |
iDecoder->ContinueConvert( &iStatus ); |
|
365 |
SetActive(); |
|
366 |
} |
|
367 |
else |
|
368 |
{ |
|
369 |
// Handled in RunError |
|
370 |
User::Leave( KErrUnderflow ); |
|
371 |
} |
|
372 |
break; |
|
373 |
} |
|
374 |
case KErrCancel : |
|
375 |
default : |
|
376 |
{ |
|
377 |
User::Leave( iStatus.Int() ); |
|
378 |
break; |
|
379 |
} |
|
380 |
} |
|
381 |
||
382 |
PRINT( _L("Camera <= CCamImageDecoder::RunL") ); |
|
383 |
} |
|
384 |
||
385 |
||
386 |
// --------------------------------------------------------------------------- |
|
387 |
// virtual |
|
388 |
// --------------------------------------------------------------------------- |
|
389 |
// |
|
390 |
TInt |
|
391 |
CCamImageDecoder::RunError( TInt aError ) |
|
392 |
{ |
|
393 |
PRINT1( _L("Camera => CCamImageDecoder::RunError(%d)"), aError ); |
|
394 |
||
395 |
SetImageData( NULL ); |
|
396 |
// Leave has occurred in RunL. |
|
397 |
// Notify observer with error. |
|
398 |
TRAP_IGNORE(iObserver.ImageDecodedL( aError, NULL, NULL )); |
|
399 |
||
400 |
PRINT( _L("Camera <= CCamImageDecoder::RunError") ); |
|
401 |
return KErrNone; |
|
402 |
} |
|
403 |
||
404 |
||
405 |
// =========================================================================== |
|
406 |
void |
|
407 |
CCamImageDecoder::SetImageData( CCamBufferShare* aBuffer ) |
|
408 |
{ |
|
409 |
if( iSharedImageData ) |
|
410 |
{ |
|
411 |
iSharedImageData->Release(); |
|
412 |
iSharedImageData = NULL; |
|
413 |
} |
|
414 |
||
415 |
iSharedImageData = aBuffer; |
|
416 |
||
417 |
if( iSharedImageData ) |
|
418 |
iSharedImageData->Reserve(); |
|
419 |
} |
|
420 |
||
421 |
// =========================================================================== |
|
422 |
// private constructors |
|
423 |
||
424 |
||
425 |
void |
|
426 |
CCamImageDecoder::ConstructL() |
|
427 |
{ |
|
428 |
User::LeaveIfError( iFs.Connect() ); |
|
429 |
||
430 |
CActiveScheduler::Add( this ); |
|
431 |
} |
|
432 |
||
433 |
||
434 |
||
435 |
CCamImageDecoder::CCamImageDecoder( MCamImageDecoderObserver& aObserver ) |
|
436 |
: CActive( KPriority ), |
|
437 |
iObserver( aObserver ) |
|
438 |
{ |
|
439 |
} |
|
440 |
||
441 |
// end of file |