|
1 // Copyright (c) 2004-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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // TS_MM_ICL_FRM_CP.cpp |
|
15 // This file contains the test steps ICL testing |
|
16 // |
|
17 // |
|
18 |
|
19 // EPOC includes |
|
20 #include <e32base.h> |
|
21 #include <caf/caf.h> |
|
22 |
|
23 // Test system includes |
|
24 #include <testframework.h> |
|
25 |
|
26 // Specific includes for this test suite |
|
27 #include "TestSuite_TSI_ICL_FRM_00.h" |
|
28 |
|
29 // Specific includes for these test steps |
|
30 #include "TestStepConversion.h" |
|
31 |
|
32 #include "ICLFbsSessionTest.h" |
|
33 // use classes in the CAF namespace directly |
|
34 using namespace ContentAccess; |
|
35 |
|
36 const TUid KImageTypeTestUid = {0x101f7bf7}; |
|
37 const TUid KImageSubTypeTestUid = {0x101f7bf8}; |
|
38 |
|
39 |
|
40 const TInt KDefaultQualityFactor = 50; //JPEG |
|
41 const TInt KDefaultSampling = 3; //JPEG |
|
42 |
|
43 /* |
|
44 * |
|
45 * Open and decoder image from file, then compare |
|
46 * with reference bitmap |
|
47 * |
|
48 * @param "const TDesC& aFilename" |
|
49 * destination file |
|
50 * |
|
51 * @return "TInt" |
|
52 * Error |
|
53 */ |
|
54 TInt CTestStepConversion::OpenImageForDecodeFromFileL(const TDesC& aFilename, |
|
55 TUid aCodecUid) |
|
56 { |
|
57 |
|
58 TInt theRes = KErrNone; |
|
59 |
|
60 TFileName theSourceFilename; |
|
61 Directory(EInput, theSourceFilename); |
|
62 theSourceFilename.Append(aFilename); |
|
63 |
|
64 User::LeaveIfError(iFs.Connect()); |
|
65 |
|
66 INFO_PRINTF2(_L("Openning the file : %S"), &theSourceFilename); |
|
67 |
|
68 CImageDecoder *theImageDecoder = NULL; |
|
69 if(aCodecUid.iUid == 0) |
|
70 { |
|
71 TRAP(theRes, theImageDecoder=CImageDecoder::FileNewL(iFs, theSourceFilename)); |
|
72 } |
|
73 else |
|
74 { |
|
75 TRAP(theRes, theImageDecoder=CImageDecoder::FileNewL(iFs, theSourceFilename, CImageDecoder::EOptionNone, aCodecUid)); |
|
76 } |
|
77 if(theRes != KErrNone) |
|
78 { |
|
79 iFs.Close(); |
|
80 INFO_PRINTF2(_L("Cannot open file %S"), &theSourceFilename); |
|
81 return theRes; |
|
82 } |
|
83 |
|
84 if(theImageDecoder == NULL) |
|
85 return KErrUnknown; |
|
86 |
|
87 CleanupStack::PushL(theImageDecoder); |
|
88 INFO_PRINTF2(_L("The file : %S had been opened"), &theSourceFilename); |
|
89 |
|
90 //[ Create an active Listener and push it on the cleanup stack] |
|
91 CActiveListener* activeListener = new(ELeave)CActiveListener; |
|
92 CleanupStack::PushL( activeListener ); |
|
93 |
|
94 CFbsBitmap* theDestination = new(ELeave) CFbsBitmap; |
|
95 CleanupStack::PushL(theDestination); |
|
96 |
|
97 const TFrameInfo* theFrameInfo = &theImageDecoder -> FrameInfo(); |
|
98 |
|
99 // >>>>>>>>> WMF ONLY <<<<<<<<<<<<<<<< |
|
100 // Instead of using the Frame info width and height (in pixels) we use fixed values |
|
101 // that we know are the correct values for the reference raster bitmap |
|
102 // which is used for comparison. |
|
103 // This is because the WMF is a vector image and its exact pixel size depends |
|
104 // on the screen device characteristics, i.e. the Twips to Pixel ratio. |
|
105 // In other words, different Dots Per Inch (DPI) screens will produce different |
|
106 // pixel size image from the same WMF file. |
|
107 |
|
108 // known target bitmap size in pixels. Size of the reference bitmap used for comparison. |
|
109 // this is the pixel frame size in wins platform, and it's different to the arm4 equivalent. |
|
110 // if iImageTypeUid == KImageTypeWMFUid and the particular test |
|
111 if (iTestStepName.Compare(_L("MM-ICL-FRM-I-0009-CP")) == 0) |
|
112 { |
|
113 TSize fixedPixelSize(465, 454); |
|
114 |
|
115 User::LeaveIfError(theDestination->Create(fixedPixelSize, |
|
116 theFrameInfo->iFrameDisplayMode ));//EColor256));// |
|
117 } |
|
118 else |
|
119 { |
|
120 User::LeaveIfError(theDestination->Create(theFrameInfo->iOverallSizeInPixels, |
|
121 theFrameInfo->iFrameDisplayMode ));//EColor256));// |
|
122 } |
|
123 |
|
124 activeListener ->InitialiseActiveListener(); |
|
125 |
|
126 theImageDecoder->Convert(& activeListener -> iStatus, *theDestination, 0); |
|
127 CActiveScheduler::Start(); |
|
128 |
|
129 theRes = activeListener -> iStatus.Int(); |
|
130 |
|
131 if(theRes == KErrNone) |
|
132 INFO_PRINTF2(_L("Conversion of file %S was successfull"), &theSourceFilename); |
|
133 else |
|
134 INFO_PRINTF2(_L("Fail during conversion the file : %S"), &theSourceFilename); |
|
135 |
|
136 TFileName theReferenceFilename; |
|
137 TBuf<KLenBufferExtension> theExtension; |
|
138 |
|
139 Directory(EReference, theReferenceFilename); |
|
140 TInt theSeparatorPos = aFilename.LocateReverse('.') + 1; |
|
141 theReferenceFilename.Append(aFilename.Left(theSeparatorPos)); |
|
142 GetImageExtension(KImageTypeMBMUid, theExtension); |
|
143 theReferenceFilename.Append(theExtension); |
|
144 if(theRes == KErrNone) |
|
145 theRes = CheckBitmapL(*theDestination, theReferenceFilename); |
|
146 |
|
147 iFs.Close(); |
|
148 |
|
149 theDestination->Reset(); |
|
150 CleanupStack::PopAndDestroy(3,theImageDecoder); // theDestination,CActiveListener, CImageDecoder |
|
151 |
|
152 return theRes; |
|
153 } |
|
154 |
|
155 /* |
|
156 * |
|
157 * Open and decode image from file |
|
158 * |
|
159 * @param "const TDesC& aFilename" |
|
160 * destination file |
|
161 * |
|
162 * @return "TInt" |
|
163 * Error |
|
164 */ |
|
165 TInt CTestStepConversion::OpenPpmImageForDecodeFromFileL(const TDesC& aFilename, |
|
166 TUid aCodecUid, |
|
167 const TUid aPpmDecodeUid) |
|
168 { |
|
169 TInt theRes = KErrNone; |
|
170 |
|
171 TFileName theSourceFilename; |
|
172 Directory(EInput, theSourceFilename); |
|
173 theSourceFilename.Append(aFilename); |
|
174 |
|
175 User::LeaveIfError(iFs.Connect()); |
|
176 |
|
177 INFO_PRINTF2(_L("Openning the file : %S"), &theSourceFilename); |
|
178 |
|
179 CImageDecoder *theImageDecoder = NULL; |
|
180 if((aCodecUid.iUid == 0)&&(aPpmDecodeUid.iUid == 0)) |
|
181 { |
|
182 TRAP(theRes, theImageDecoder=CImageDecoder::FileNewL(iFs, theSourceFilename)); |
|
183 } |
|
184 else |
|
185 { |
|
186 TRAP(theRes, theImageDecoder=CImageDecoder::FileNewL(iFs, theSourceFilename, CImageDecoder::EOptionNone, aCodecUid, KNullUid, aPpmDecodeUid)); |
|
187 } |
|
188 if(theRes != KErrNone) |
|
189 { |
|
190 iFs.Close(); |
|
191 INFO_PRINTF2(_L("Cannot open file %S"), &theSourceFilename); |
|
192 return theRes; |
|
193 } |
|
194 |
|
195 if(theImageDecoder == NULL) |
|
196 return KErrUnknown; |
|
197 |
|
198 CleanupStack::PushL(theImageDecoder); |
|
199 INFO_PRINTF2(_L("The file : %S had been opened"), &theSourceFilename); |
|
200 |
|
201 //[ Create an active Listener and push it on the cleanup stack] |
|
202 CActiveListener* activeListener = new(ELeave)CActiveListener; |
|
203 CleanupStack::PushL( activeListener ); |
|
204 |
|
205 CFbsBitmap* theDestination = new(ELeave) CFbsBitmap; |
|
206 CleanupStack::PushL(theDestination); |
|
207 |
|
208 const TFrameInfo* theFrameInfo = &theImageDecoder -> FrameInfo(); |
|
209 User::LeaveIfError(theDestination->Create(theFrameInfo->iOverallSizeInPixels, |
|
210 theFrameInfo->iFrameDisplayMode ));//EColor256));// |
|
211 |
|
212 activeListener ->InitialiseActiveListener(); |
|
213 |
|
214 theImageDecoder->Convert(& activeListener -> iStatus, *theDestination, 0); |
|
215 CActiveScheduler::Start(); |
|
216 |
|
217 theRes = activeListener -> iStatus.Int(); |
|
218 |
|
219 if(theRes == KErrNone) |
|
220 { |
|
221 INFO_PRINTF2(_L("Conversion of file %S was successfull"), &theSourceFilename); |
|
222 } |
|
223 else |
|
224 { |
|
225 INFO_PRINTF2(_L("Fail during conversion the file : %S"), &theSourceFilename); |
|
226 } |
|
227 |
|
228 iFs.Close(); |
|
229 |
|
230 theDestination->Reset(); |
|
231 CleanupStack::PopAndDestroy(3,theImageDecoder); // theDestination,CActiveListener, CImageDecoder |
|
232 |
|
233 return theRes; |
|
234 } |
|
235 |
|
236 void CTestStepConversion::OpenImageForDecodeFromFileWithIntentL(const TDesC& aFilename, |
|
237 TIntent aIntent, |
|
238 const TDesC8& aMimeType) |
|
239 { |
|
240 |
|
241 TInt err = KErrNone; |
|
242 |
|
243 TFileName theSourceFilename; |
|
244 Directory(EInput, theSourceFilename); |
|
245 theSourceFilename.Append(aFilename); |
|
246 |
|
247 User::LeaveIfError(iFs.Connect()); |
|
248 |
|
249 INFO_PRINTF2(_L("Openning the file : %S"), &theSourceFilename); |
|
250 |
|
251 CImageDecoder *theImageDecoder = NULL; |
|
252 |
|
253 if(aMimeType != KNullDesC8) |
|
254 { |
|
255 TRAP(err, theImageDecoder=CImageDecoder::FileNewL(iFs, theSourceFilename, aMimeType, aIntent)); |
|
256 } |
|
257 else |
|
258 { |
|
259 TRAP(err, theImageDecoder=CImageDecoder::FileNewL(iFs, theSourceFilename, aIntent)); |
|
260 } |
|
261 if(err != KErrNone) |
|
262 { |
|
263 iFs.Close(); |
|
264 INFO_PRINTF2(_L("Cannot open file %S"), &theSourceFilename); |
|
265 User::Leave(err); |
|
266 } |
|
267 |
|
268 if(theImageDecoder == NULL) |
|
269 User::Leave(KErrUnknown); |
|
270 CleanupStack::PushL(theImageDecoder); |
|
271 INFO_PRINTF2(_L("The file : %S had been opened"), &theSourceFilename); |
|
272 |
|
273 //[ Create an active Listener and push it on the cleanup stack] |
|
274 CActiveListener* activeListener = new(ELeave)CActiveListener; |
|
275 CleanupStack::PushL( activeListener ); |
|
276 |
|
277 CFbsBitmap* theDestination = new(ELeave) CFbsBitmap; |
|
278 CleanupStack::PushL(theDestination); |
|
279 |
|
280 const TFrameInfo* theFrameInfo = &theImageDecoder -> FrameInfo(); |
|
281 |
|
282 User::LeaveIfError(theDestination->Create(theFrameInfo->iOverallSizeInPixels, |
|
283 theFrameInfo->iFrameDisplayMode )); |
|
284 |
|
285 activeListener ->InitialiseActiveListener(); |
|
286 |
|
287 theImageDecoder->Convert(& activeListener -> iStatus, *theDestination, 0); |
|
288 CActiveScheduler::Start(); |
|
289 |
|
290 err = activeListener -> iStatus.Int(); |
|
291 |
|
292 if(err == KErrNone) |
|
293 INFO_PRINTF2(_L("Conversion of file %S was successfull"), &theSourceFilename); |
|
294 else |
|
295 INFO_PRINTF2(_L("Fail during conversion the file : %S"), &theSourceFilename); |
|
296 |
|
297 TFileName theReferenceFilename; |
|
298 TBuf<KLenBufferExtension> theExtension; |
|
299 |
|
300 Directory(EReference, theReferenceFilename); |
|
301 TInt theSeparatorPos = aFilename.LocateReverse('.') + 1; |
|
302 theReferenceFilename.Append(aFilename.Left(theSeparatorPos)); |
|
303 GetImageExtension(KImageTypeMBMUid, theExtension); |
|
304 theReferenceFilename.Append(theExtension); |
|
305 |
|
306 if(err == KErrNone) |
|
307 err = CheckBitmapL(*theDestination, theReferenceFilename); |
|
308 |
|
309 iFs.Close(); |
|
310 theDestination->Reset(); |
|
311 |
|
312 CleanupStack::PopAndDestroy(3,theImageDecoder); // theDestination,CActiveListener, CImageDecoder |
|
313 |
|
314 User::LeaveIfError(err); |
|
315 |
|
316 } |
|
317 |
|
318 void CTestStepConversion::OpenImageForDecodeFromFileWithIntentL(const TDesC& aFilename, |
|
319 TIntent aIntent, |
|
320 TUid aImageTypeUid, |
|
321 TUid aDecoderUid) |
|
322 { |
|
323 |
|
324 TInt err = KErrNone; |
|
325 |
|
326 TFileName theSourceFilename; |
|
327 Directory(EInput, theSourceFilename); |
|
328 theSourceFilename.Append(aFilename); |
|
329 |
|
330 User::LeaveIfError(iFs.Connect()); |
|
331 |
|
332 INFO_PRINTF2(_L("Openning the file : %S"), &theSourceFilename); |
|
333 |
|
334 CImageDecoder *theImageDecoder = NULL; |
|
335 |
|
336 TRAP(err, theImageDecoder=CImageDecoder::FileNewL(iFs, theSourceFilename, aIntent, CImageDecoder::EOptionNone, aImageTypeUid, KNullUid, aDecoderUid)); |
|
337 |
|
338 if(err != KErrNone) |
|
339 { |
|
340 iFs.Close(); |
|
341 INFO_PRINTF2(_L("Cannot open file %S"), &theSourceFilename); |
|
342 User::Leave(err); |
|
343 } |
|
344 |
|
345 if(theImageDecoder == NULL) |
|
346 User::Leave(KErrUnknown); |
|
347 |
|
348 CleanupStack::PushL(theImageDecoder); |
|
349 INFO_PRINTF2(_L("The file : %S had been opened"), &theSourceFilename); |
|
350 |
|
351 //[ Create an active Listener and push it on the cleanup stack] |
|
352 CActiveListener* activeListener = new(ELeave)CActiveListener; |
|
353 CleanupStack::PushL( activeListener ); |
|
354 |
|
355 CFbsBitmap* theDestination = new(ELeave) CFbsBitmap; |
|
356 CleanupStack::PushL(theDestination); |
|
357 |
|
358 const TFrameInfo* theFrameInfo = &theImageDecoder -> FrameInfo(); |
|
359 User::LeaveIfError(theDestination->Create(theFrameInfo->iOverallSizeInPixels, |
|
360 theFrameInfo->iFrameDisplayMode )); |
|
361 |
|
362 activeListener ->InitialiseActiveListener(); |
|
363 |
|
364 theImageDecoder->Convert(& activeListener -> iStatus, *theDestination, 0); |
|
365 CActiveScheduler::Start(); |
|
366 |
|
367 err = activeListener -> iStatus.Int(); |
|
368 |
|
369 if(err == KErrNone) |
|
370 INFO_PRINTF2(_L("Conversion of file %S was successfull"), &theSourceFilename); |
|
371 else |
|
372 INFO_PRINTF2(_L("Fail during conversion the file : %S"), &theSourceFilename); |
|
373 |
|
374 TFileName theReferenceFilename; |
|
375 TBuf<KLenBufferExtension> theExtension; |
|
376 |
|
377 Directory(EReference, theReferenceFilename); |
|
378 TInt theSeparatorPos = aFilename.LocateReverse('.') + 1; |
|
379 theReferenceFilename.Append(aFilename.Left(theSeparatorPos)); |
|
380 GetImageExtension(KImageTypeMBMUid, theExtension); |
|
381 theReferenceFilename.Append(theExtension); |
|
382 |
|
383 if(err == KErrNone) |
|
384 err = CheckBitmapL(*theDestination, theReferenceFilename); |
|
385 |
|
386 iFs.Close(); |
|
387 theDestination->Reset(); |
|
388 //Active Listiner |
|
389 CleanupStack::PopAndDestroy(3,theImageDecoder); // theDestination,CActiveListener, CImageDecoder |
|
390 |
|
391 User::LeaveIfError(err); |
|
392 |
|
393 } |
|
394 |
|
395 |
|
396 /* |
|
397 * |
|
398 * get size of step to increment |
|
399 * |
|
400 * @param "TInt aValue" |
|
401 * wanted buffer size |
|
402 * |
|
403 * @return "TInt" |
|
404 * step |
|
405 */ |
|
406 inline TInt CTestStepConversion::StreamIncrement(TInt aValue) |
|
407 { |
|
408 return (aValue<KStreamBreakpoint)?KStreamInitialIncrement:KStreamSecondaryIncrement; |
|
409 |
|
410 } |
|
411 |
|
412 /* |
|
413 * |
|
414 * Read and decode an image incrementally then compare with reference |
|
415 * |
|
416 * @param "const TDesC& aFileName" |
|
417 * "TInt aStepBeforeCancel" |
|
418 * request cancel of load/decode from the client app before completion |
|
419 * (only if aStepBeforeCancel > 0 ) |
|
420 * |
|
421 * @return "TInt" |
|
422 * error |
|
423 */ |
|
424 TInt CTestStepConversion::ReadAndDecodeIncrementallyL(const TDesC& aFileName, TInt aStepBeforeCancel) |
|
425 { |
|
426 TInt aFrameNo = 0; |
|
427 TInt theRes; |
|
428 |
|
429 User::LeaveIfError(iFs.Connect()); |
|
430 |
|
431 TFileName sourceFileName; |
|
432 Directory(EInput, sourceFileName); |
|
433 sourceFileName.Append(aFileName); |
|
434 |
|
435 theRes = iFile.Open(iFs, sourceFileName, EFileShareReadersOnly|EFileStream|EFileRead); |
|
436 |
|
437 if(theRes != KErrNone) |
|
438 { |
|
439 iFs.Close(); |
|
440 INFO_PRINTF2(_L("Cannot open file : %S"), &sourceFileName); |
|
441 |
|
442 return theRes; |
|
443 } |
|
444 else |
|
445 { |
|
446 INFO_PRINTF2(_L("File %S was opened successfully"), &sourceFileName); |
|
447 } |
|
448 |
|
449 CleanupClosePushL(iFile); |
|
450 TInt fileSize = 0; |
|
451 User::LeaveIfError(iFile.Size(fileSize)); |
|
452 |
|
453 TPtr8 buffer(STATIC_CAST(TUint8*, User::AllocLC(1024)), 0, 1024); |
|
454 |
|
455 RFile destFile; |
|
456 |
|
457 TFileName destFileName; |
|
458 Directory(EOutput, destFileName); |
|
459 destFileName.Append(aFileName); |
|
460 TInt destFileLength = 0; |
|
461 |
|
462 theRes = destFile.Create(iFs, destFileName, EFileShareAny|EFileStream|EFileWrite); |
|
463 //theRes = destFile.Create(iFs, destFileName, EFileShareAny); |
|
464 if(theRes == KErrAlreadyExists) |
|
465 User::LeaveIfError(theRes = destFile.Replace(iFs, destFileName, EFileShareAny|EFileStream|EFileWrite)); |
|
466 else if(theRes) |
|
467 { |
|
468 INFO_PRINTF2(_L("Cannot create destination file %S"), &destFileName); |
|
469 User::LeaveIfError(theRes); |
|
470 } |
|
471 |
|
472 CleanupClosePushL(destFile); |
|
473 |
|
474 INFO_PRINTF2(_L("Destination file %S was created successfully"), &destFileName); |
|
475 |
|
476 TInt wantedBufferSize=1; |
|
477 |
|
478 User::LeaveIfError(iFile.Read(buffer, wantedBufferSize)); |
|
479 ASSERT(buffer.Length()==wantedBufferSize); // should always work on emulator |
|
480 User::LeaveIfError(destFile.Write(buffer)); |
|
481 destFileLength += wantedBufferSize; |
|
482 CImageDecoder *theImageDecoder = NULL; |
|
483 // gradually increment buffer size until we can open the decoder |
|
484 for (;;) |
|
485 { |
|
486 TRAPD(error, theImageDecoder = CImageDecoder::FileNewL(iFs, destFileName, |
|
487 CImageDecoder::EOptionNone));//, |
|
488 if (error==KErrNone) |
|
489 break; |
|
490 if (error!=KErrUnderflow || wantedBufferSize>=fileSize) |
|
491 { |
|
492 INFO_PRINTF2(_L("Cannot create image decoder for file %S"), &destFileName); |
|
493 |
|
494 if(KErrAccessDenied == error) |
|
495 INFO_PRINTF1(_L("Access denied")); |
|
496 |
|
497 User::Leave(error); |
|
498 } |
|
499 TInt increment = StreamIncrement(wantedBufferSize); |
|
500 wantedBufferSize = Min(fileSize, wantedBufferSize+increment); |
|
501 TInt extra = wantedBufferSize - destFileLength; |
|
502 ASSERT(extra>0); |
|
503 User::LeaveIfError(iFile.Read(buffer, extra)); |
|
504 ASSERT(buffer.Length()==extra); // should always work on emulator |
|
505 User::LeaveIfError(destFile.Write(buffer)); |
|
506 destFileLength += extra; |
|
507 } |
|
508 CleanupStack::PushL(theImageDecoder); |
|
509 |
|
510 // gradually increment buffer size until we get info about the given frame |
|
511 |
|
512 while (theImageDecoder->IsImageHeaderProcessingComplete() == (TBool)EFalse && |
|
513 wantedBufferSize<fileSize) |
|
514 { |
|
515 TInt increment = StreamIncrement(wantedBufferSize); |
|
516 wantedBufferSize = Min(fileSize, wantedBufferSize+increment); |
|
517 TInt extra = wantedBufferSize - destFileLength; |
|
518 ASSERT(extra>0); |
|
519 User::LeaveIfError(iFile.Read(buffer, extra)); |
|
520 ASSERT(buffer.Length()==extra); // should always work on emulator |
|
521 User::LeaveIfError(destFile.Write(buffer)); |
|
522 destFileLength += extra; |
|
523 |
|
524 theImageDecoder->ContinueProcessingHeaderL(); |
|
525 } |
|
526 |
|
527 // resize the bitmap - since we now know the size |
|
528 TFrameInfo frameInfo(theImageDecoder->FrameInfo()); |
|
529 TSize frameSize(frameInfo.iFrameCoordsInPixels.Width(), |
|
530 frameInfo.iFrameCoordsInPixels.Height()); |
|
531 |
|
532 CFbsBitmap* theBitmap = new(ELeave) CFbsBitmap; |
|
533 CleanupStack::PushL( theBitmap ); |
|
534 User::LeaveIfError(theBitmap->Create(frameSize, frameInfo.iFrameDisplayMode)); |
|
535 |
|
536 // the conversion itself |
|
537 TBool first = ETrue; |
|
538 CActiveListener* activeListener = new(ELeave)CActiveListener; |
|
539 CleanupStack::PushL( activeListener ); |
|
540 if(aStepBeforeCancel > 0) |
|
541 iActiveScheduler->SetDecoder(theImageDecoder, activeListener, aStepBeforeCancel); |
|
542 for(;;) |
|
543 { |
|
544 activeListener->InitialiseActiveListener(); |
|
545 if (first) |
|
546 theImageDecoder->Convert(&activeListener->iStatus,*theBitmap,aFrameNo); |
|
547 else |
|
548 theImageDecoder->ContinueConvert(&activeListener->iStatus); |
|
549 |
|
550 first = EFalse; |
|
551 |
|
552 CActiveScheduler::Start(); |
|
553 TInt error = activeListener->iStatus.Int(); |
|
554 if (error==KErrNone) |
|
555 break; |
|
556 |
|
557 if(error == KErrCancel) |
|
558 { |
|
559 //The incremental load was canceled at the client before completion |
|
560 theRes = KErrCancel; |
|
561 break; |
|
562 } |
|
563 if (error!=KErrUnderflow || wantedBufferSize>=fileSize) |
|
564 User::Leave(error); |
|
565 TInt increment = StreamIncrement(wantedBufferSize); |
|
566 wantedBufferSize = Min(fileSize, wantedBufferSize+increment); |
|
567 TInt extra = wantedBufferSize - destFileLength; |
|
568 |
|
569 ASSERT(extra>0); |
|
570 |
|
571 if(iFile.SubSessionHandle()) |
|
572 User::LeaveIfError(iFile.Read(buffer, extra)); |
|
573 |
|
574 ASSERT(buffer.Length()==extra); // should always work on emulator |
|
575 |
|
576 if(destFile.SubSessionHandle()) |
|
577 { |
|
578 User::LeaveIfError(destFile.Write(buffer)); |
|
579 destFileLength += extra; |
|
580 } |
|
581 } |
|
582 |
|
583 TFileName refFileName; |
|
584 TBuf<KLenBufferExtension> imageExtension; |
|
585 Directory(EReference, refFileName); |
|
586 refFileName.Append(aFileName.Left(aFileName.Length()-3)); |
|
587 GetImageExtension(KImageTypeMBMUid, imageExtension); |
|
588 refFileName.Append(imageExtension); |
|
589 |
|
590 if(theRes == KErrNone && aStepBeforeCancel == 0) |
|
591 theRes = CheckBitmapL(*theBitmap, refFileName); |
|
592 |
|
593 theBitmap->Reset(); |
|
594 CleanupStack::PopAndDestroy(6); // theImageDecoder, destFile, buffer, file, theBitmap, activeListener |
|
595 |
|
596 iFs.Close(); |
|
597 |
|
598 return theRes; |
|
599 } |
|
600 |
|
601 |
|
602 /* |
|
603 * |
|
604 * Read and decode image from buffer |
|
605 * |
|
606 * @param "const TDesC& aFileName" |
|
607 * "TUid aUid" |
|
608 * using for negative test |
|
609 * @return "TInt" |
|
610 * error |
|
611 */ |
|
612 TInt CTestStepConversion::OpenImageForDecodeFromBufferL(const TDesC& aFilename, TUid aUid) |
|
613 { |
|
614 |
|
615 TInt theRes = KErrNone; |
|
616 |
|
617 TFileName theSourceFilename; |
|
618 Directory(EInput, theSourceFilename); |
|
619 theSourceFilename.Append(aFilename); |
|
620 |
|
621 User::LeaveIfError(iFs.Connect()); |
|
622 |
|
623 TInt fileSize = 0; |
|
624 |
|
625 theRes = iFile.Open(iFs, theSourceFilename, EFileRead); |
|
626 |
|
627 if(theRes == KErrNone) |
|
628 iFile.Size(fileSize); |
|
629 // if aFilename.Length() == 0 - we try negative test "Request data where no frame is loaded |
|
630 else if(aFilename.Length() != 0) |
|
631 { |
|
632 INFO_PRINTF2(_L("Cannot open source file %S"), &theSourceFilename); |
|
633 return theRes; |
|
634 } |
|
635 |
|
636 HBufC8 *theImageFromFile = HBufC8::NewMaxLC(fileSize); |
|
637 |
|
638 TPtr8 imageFromFilePtr = theImageFromFile->Des(); |
|
639 if(iFile.SubSessionHandle()) |
|
640 iFile.Read(imageFromFilePtr); |
|
641 iFile.Close(); |
|
642 |
|
643 CImageDecoder* theImageDecoder = NULL; |
|
644 |
|
645 if(aUid.iUid == 0) |
|
646 { |
|
647 TRAP(theRes, theImageDecoder = CImageDecoder::DataNewL(iFs, imageFromFilePtr)); |
|
648 } |
|
649 else |
|
650 {//for negative testing |
|
651 TRAP(theRes, theImageDecoder = CImageDecoder::DataNewL(iFs, imageFromFilePtr, CImageDecoder::EOptionNone, KImageTypeWMFUid)); |
|
652 } |
|
653 |
|
654 iFs.Close(); |
|
655 |
|
656 if(theRes != KErrNone) |
|
657 { |
|
658 CleanupStack::PopAndDestroy(theImageFromFile); |
|
659 |
|
660 INFO_PRINTF1(_L("Cannot create image decoder from file's pointer")); |
|
661 return theRes; |
|
662 } |
|
663 |
|
664 if(theImageDecoder == NULL) |
|
665 { |
|
666 CleanupStack::PopAndDestroy(theImageFromFile); |
|
667 return KErrUnknown; |
|
668 } |
|
669 |
|
670 CleanupStack::PushL(theImageDecoder); |
|
671 |
|
672 CFbsBitmap* theDestination = new(ELeave) CFbsBitmap; |
|
673 CleanupStack::PushL(theDestination); |
|
674 |
|
675 const TFrameInfo* theFrameInfo = &theImageDecoder-> FrameInfo(); |
|
676 User::LeaveIfError(theDestination->Create(theFrameInfo->iOverallSizeInPixels, |
|
677 theFrameInfo->iFrameDisplayMode )); |
|
678 // Create an active Listener and push it on the cleanup stack |
|
679 CActiveListener* activeListener = new(ELeave)CActiveListener; |
|
680 CleanupStack::PushL( activeListener ); |
|
681 activeListener->InitialiseActiveListener(); |
|
682 |
|
683 theImageDecoder->Convert(& activeListener -> iStatus, *theDestination); |
|
684 CActiveScheduler::Start(); |
|
685 theRes = activeListener -> iStatus.Int(); |
|
686 if(theRes == KErrNone) |
|
687 { |
|
688 INFO_PRINTF2(_L("File %S was converted successfully"), &theSourceFilename); |
|
689 } |
|
690 else |
|
691 { |
|
692 INFO_PRINTF2(_L("Fail during conversion file %S"), &theSourceFilename); |
|
693 } |
|
694 |
|
695 TFileName theReferenceFilename; |
|
696 TBuf<KLenBufferExtension> theExtension; |
|
697 |
|
698 Directory(EReference, theReferenceFilename); |
|
699 theReferenceFilename.Append(aFilename.Left(aFilename.Length()-3)); |
|
700 GetImageExtension(KImageTypeMBMUid, theExtension); |
|
701 theReferenceFilename.Append(theExtension); |
|
702 |
|
703 if(theRes == KErrNone) |
|
704 theRes = CheckBitmapL(*theDestination, theReferenceFilename); |
|
705 |
|
706 theDestination->Reset(); |
|
707 CleanupStack::PopAndDestroy(4,theImageFromFile); // CActiveListener, theDestination, theImageDecoder, theImageFromFile |
|
708 return theRes; |
|
709 } |
|
710 |
|
711 /* |
|
712 Read and decode a given frame from an image buffer with a specific codec (Uid) and decode options |
|
713 @param const TDesC& aFileName The file to be read into a data buffer (for use in CImageDecoder::DataNewL()) |
|
714 @param TInt aFrameNumber The frame to be decoded (0 is the first frame). |
|
715 @param TUid aUid The Uid of the codec to be used for the decode. |
|
716 @param CImageDecoder::TOptions aOptions Any decoder options (EOptionNone is the default). |
|
717 */ |
|
718 void CTestStepConversion::OpenBufferedImageL(const TDesC& aFilename, TInt aFrameNumber, TUid aUid, const CImageDecoder::TOptions aOptions) |
|
719 { |
|
720 TInt err = KErrNone; |
|
721 |
|
722 TFileName theSourceFilename; |
|
723 Directory(EInput, theSourceFilename); |
|
724 theSourceFilename.Append(aFilename); |
|
725 |
|
726 User::LeaveIfError(iFs.Connect()); |
|
727 |
|
728 TInt fileSize = 0; |
|
729 |
|
730 err = iFile.Open(iFs, theSourceFilename, EFileRead); |
|
731 |
|
732 if(err == KErrNone) |
|
733 { |
|
734 iFile.Size(fileSize); |
|
735 } |
|
736 else |
|
737 { |
|
738 INFO_PRINTF2(_L("Cannot open source file %S"), &theSourceFilename); |
|
739 User::Leave(err); |
|
740 } |
|
741 |
|
742 HBufC8* theImageFromFile = HBufC8::NewMaxLC(fileSize); |
|
743 |
|
744 TPtr8 imageFromFilePtr = theImageFromFile->Des(); |
|
745 if(iFile.SubSessionHandle()) |
|
746 { |
|
747 iFile.Read(imageFromFilePtr); |
|
748 } |
|
749 iFile.Close(); |
|
750 |
|
751 CImageDecoder* theImageDecoder = NULL; |
|
752 |
|
753 TRAP(err, theImageDecoder = CImageDecoder::DataNewL(iFs, imageFromFilePtr, aOptions, KNullUid, KNullUid, aUid)); |
|
754 |
|
755 iFs.Close(); |
|
756 |
|
757 if(err != KErrNone) |
|
758 { |
|
759 INFO_PRINTF1(_L("Cannot create image decoder from file's pointer")); |
|
760 User::Leave(err); |
|
761 } |
|
762 |
|
763 CleanupStack::PushL(theImageDecoder); |
|
764 |
|
765 if(aFrameNumber >= theImageDecoder->FrameCount()) |
|
766 { |
|
767 INFO_PRINTF1(_L("Requested to decode unavailable image frame.")); |
|
768 User::Leave(KErrArgument); |
|
769 } |
|
770 |
|
771 CFbsBitmap* theDestination = new(ELeave) CFbsBitmap; |
|
772 CleanupStack::PushL(theDestination); |
|
773 |
|
774 const TFrameInfo* theFrameInfo = &theImageDecoder->FrameInfo(aFrameNumber); |
|
775 User::LeaveIfError(theDestination->Create(theFrameInfo->iOverallSizeInPixels, |
|
776 theFrameInfo->iFrameDisplayMode)); |
|
777 |
|
778 // Create an active Listener and push it on the cleanup stack |
|
779 CActiveListener* activeListener = new(ELeave)CActiveListener; |
|
780 CleanupStack::PushL(activeListener); |
|
781 activeListener->InitialiseActiveListener(); |
|
782 theImageDecoder->Convert(&activeListener->iStatus, *theDestination, aFrameNumber); |
|
783 |
|
784 CActiveScheduler::Start(); |
|
785 |
|
786 err = activeListener->iStatus.Int(); |
|
787 if(err == KErrNone) |
|
788 { |
|
789 INFO_PRINTF3(_L("Frame %d of file %S was converted successfully"), aFrameNumber, &theSourceFilename); |
|
790 } |
|
791 else |
|
792 { |
|
793 INFO_PRINTF3(_L("Fail during conversion of frame %d of file %S"), aFrameNumber, &theSourceFilename); |
|
794 User::Leave(err); |
|
795 } |
|
796 |
|
797 TFileName theReferenceFilename; |
|
798 TBuf<KLenBufferExtension> theExtension; |
|
799 |
|
800 Directory(EReference, theReferenceFilename); |
|
801 TInt theSeparatorPos = aFilename.LocateReverse('.') + 1; |
|
802 theReferenceFilename.Append(aFilename.Left(theSeparatorPos)); |
|
803 GetImageExtension(KImageTypeMBMUid, theExtension); |
|
804 theReferenceFilename.Append(theExtension); |
|
805 |
|
806 // Uncomment to save the decoded bitmap |
|
807 // User::LeaveIfError(theDestination->Save(theReferenceFilename)); |
|
808 |
|
809 if(err == KErrNone) |
|
810 { |
|
811 TInt err1 = KErrNone; |
|
812 TRAP(err, err1 = CheckBitmapL(*theDestination, theReferenceFilename)); |
|
813 if(err != KErrNone || err1 != KErrNone) |
|
814 { |
|
815 INFO_PRINTF1(_L("Bitmap check failed")); |
|
816 User::Leave(KErrGeneral); |
|
817 } |
|
818 } |
|
819 |
|
820 theDestination->Reset(); |
|
821 CleanupStack::PopAndDestroy(4, theImageFromFile); // CActiveListener, theDestination, theImageDecoder, theImageFromFile |
|
822 } |
|
823 |
|
824 |
|
825 /* |
|
826 * |
|
827 * Read and encode image from file to memory |
|
828 * |
|
829 * @param "const TDesC& aFileName" |
|
830 * "TUid aTypeImage" |
|
831 * codec Uid |
|
832 * |
|
833 * @return "TInt" |
|
834 * error |
|
835 */ |
|
836 TInt CTestStepConversion::EncodeImageToMemoryL(const TDesC& aFilename, |
|
837 TUid aTypeImage) |
|
838 { |
|
839 TInt theRes = KErrNone; |
|
840 CICLFbsSessionTest* fbsSession = CICLFbsSessionTest::NewLC(); |
|
841 |
|
842 TFileName theSourceFileName; |
|
843 Directory( EReference, theSourceFileName); |
|
844 theSourceFileName.Append(aFilename); |
|
845 |
|
846 CFbsBitmap *theBitmap = new(ELeave) CFbsBitmap; |
|
847 CleanupStack::PushL(theBitmap); |
|
848 theRes = theBitmap->Load(theSourceFileName); |
|
849 |
|
850 if(theRes == KErrNone) |
|
851 theRes = EncodeImageFromBitmapToMemoryL(aFilename, |
|
852 theBitmap, |
|
853 aTypeImage); |
|
854 else |
|
855 INFO_PRINTF2(_L("File : %S not found"), &theSourceFileName); |
|
856 |
|
857 CleanupStack::PopAndDestroy(2, fbsSession); |
|
858 |
|
859 return theRes; |
|
860 } |
|
861 |
|
862 |
|
863 /* |
|
864 * |
|
865 * Read and encode image from bitmap to memory |
|
866 * |
|
867 * @param "const TDesC& aFileName" |
|
868 * "CFbsBitmap *theBitmap" |
|
869 * "TUid aTypeImage" |
|
870 * codec Uid |
|
871 * |
|
872 * @return "TInt" |
|
873 * error |
|
874 */ |
|
875 TInt CTestStepConversion::EncodeImageFromBitmapToMemoryL(const TDesC& aFilename, |
|
876 CFbsBitmap *theBitmap, |
|
877 TUid aImageTypeId) |
|
878 { |
|
879 |
|
880 TInt theRes = KErrNone; |
|
881 |
|
882 TFileName theSourceFileName; |
|
883 Directory( EReference, theSourceFileName); |
|
884 theSourceFileName.Append(aFilename); |
|
885 |
|
886 HBufC8 *theDestinationImage = NULL; |
|
887 CImageEncoder *theImageEncoder = NULL; |
|
888 |
|
889 // creating encoder |
|
890 TBuf<KLenBufferExtension> theExtension; |
|
891 GetImageExtension(aImageTypeId, theExtension); |
|
892 ERR_PRINTF3(_L("Creating encoder %S, Uid = %d"), &theExtension, aImageTypeId); |
|
893 |
|
894 TRAP(theRes, theImageEncoder = CImageEncoder::DataNewL( theDestinationImage, |
|
895 CImageEncoder::EOptionNone, aImageTypeId )); |
|
896 if(theRes != KErrNone) |
|
897 { |
|
898 ERR_PRINTF2(_L("Cannot create image encoder buffer for Uid = %d"), |
|
899 aImageTypeId.iUid); |
|
900 return theRes; |
|
901 |
|
902 } |
|
903 CleanupStack::PushL(theImageEncoder); |
|
904 |
|
905 ERR_PRINTF1(_L("Image buffer was created successfully")); |
|
906 |
|
907 //prepare encode data |
|
908 TConvertInfo theConvInfo; |
|
909 theConvInfo.iImageTypeId = iImageTypeUid; |
|
910 theConvInfo.iDisplayMode = theBitmap->DisplayMode(); |
|
911 |
|
912 TImageDataBlock* imageData = NULL; |
|
913 TFrameDataBlock* frameData = NULL; |
|
914 |
|
915 CFrameImageData* theFrameImageData = CFrameImageData::NewL(); |
|
916 CleanupStack::PushL(theFrameImageData); |
|
917 |
|
918 theRes = PrepareEncodeDataL(theConvInfo, &imageData, &frameData); |
|
919 // |
|
920 if(imageData) |
|
921 { |
|
922 CleanupStack::PushL(imageData); |
|
923 User::LeaveIfError(theFrameImageData->AppendImageData(imageData)); |
|
924 CleanupStack::Pop(imageData); |
|
925 } |
|
926 if(frameData) |
|
927 { |
|
928 CleanupStack::PushL(frameData); |
|
929 User::LeaveIfError(theFrameImageData->AppendFrameData(frameData)); |
|
930 CleanupStack::Pop(frameData); |
|
931 } |
|
932 // do conversion |
|
933 CActiveListener* activeListener = new(ELeave)CActiveListener; |
|
934 CleanupStack::PushL( activeListener ); |
|
935 |
|
936 activeListener->InitialiseActiveListener(); |
|
937 theImageEncoder->Convert(&activeListener->iStatus,*theBitmap, theFrameImageData); |
|
938 CActiveScheduler::Start(); |
|
939 |
|
940 theRes = activeListener->iStatus.Int(); |
|
941 |
|
942 if(theRes == KErrNone) |
|
943 ERR_PRINTF1(_L("Conversion was successful")); |
|
944 else |
|
945 ERR_PRINTF1(_L("Fail during conversion")); |
|
946 |
|
947 if(theRes == KErrNone) |
|
948 theRes = CompareFileL(aFilename, theDestinationImage, |
|
949 aImageTypeId, |
|
950 EInput); |
|
951 // |
|
952 delete theDestinationImage; |
|
953 theDestinationImage = NULL; |
|
954 |
|
955 CleanupStack::PopAndDestroy(3, theImageEncoder); |
|
956 |
|
957 return theRes; |
|
958 } |
|
959 |
|
960 |
|
961 /* |
|
962 * |
|
963 * Read and encode image from bitmap to file |
|
964 * After encoding load file into a flat buffer and do bitwise compare |
|
965 * |
|
966 * @param "const TDesC& aFileName" |
|
967 * "TUid aTypeImage" |
|
968 * |
|
969 * @return "TInt" |
|
970 * error |
|
971 */ |
|
972 TInt CTestStepConversion::EncodeImageFromBitmapToFileL(const TDesC& aFilename, |
|
973 TUid aImageTypeId) |
|
974 { |
|
975 TFileName theSourceFile; |
|
976 Directory(EReference, theSourceFile); |
|
977 theSourceFile.Append(aFilename); |
|
978 |
|
979 CFbsBitmap *theBitmap = new(ELeave) CFbsBitmap; |
|
980 CleanupStack::PushL(theBitmap); |
|
981 TInt theRes = theBitmap->Load(theSourceFile); |
|
982 |
|
983 if(theRes != KErrNone) |
|
984 { |
|
985 CleanupStack::PopAndDestroy(theBitmap); |
|
986 |
|
987 ERR_PRINTF2(_L("File %S cannot be louded" ), &theSourceFile); |
|
988 return theRes; |
|
989 } |
|
990 |
|
991 User::LeaveIfError(iFs.Connect()); |
|
992 |
|
993 // call for a convertor |
|
994 // |
|
995 TFileName theDestinationFileName; |
|
996 TBuf<KLenBuffer> theExtinsion; |
|
997 |
|
998 Directory(EOutput, theDestinationFileName); |
|
999 theDestinationFileName.Append(aFilename.Left(aFilename.Length()-3)); |
|
1000 |
|
1001 GetImageExtension(aImageTypeId, theExtinsion); |
|
1002 theDestinationFileName.Append(theExtinsion); |
|
1003 |
|
1004 CImageEncoder* theImageEncoder = NULL; |
|
1005 TRAP(theRes, theImageEncoder = |
|
1006 CImageEncoder::FileNewL(iFs, theDestinationFileName, |
|
1007 CImageEncoder::EOptionNone, aImageTypeId)); |
|
1008 |
|
1009 if(theRes != KErrNone) |
|
1010 { |
|
1011 CleanupStack::PopAndDestroy(theBitmap); |
|
1012 |
|
1013 iFs.Close(); |
|
1014 ERR_PRINTF3(_L("Error during creating Image Encoder UId %d to file %S" ), aImageTypeId, &theDestinationFileName); |
|
1015 if(KErrPathNotFound == theRes) |
|
1016 ERR_PRINTF2(_L("Path %S not found" ), &theDestinationFileName); |
|
1017 |
|
1018 if(theRes == KErrAccessDenied) |
|
1019 ERR_PRINTF1(_L("Access denied" )); |
|
1020 |
|
1021 return theRes; |
|
1022 } |
|
1023 CleanupStack::PushL(theImageEncoder); |
|
1024 //----------- |
|
1025 //prepare encode data |
|
1026 TConvertInfo theConvInfo; |
|
1027 theConvInfo.iImageTypeId = iImageTypeUid; |
|
1028 theConvInfo.iDisplayMode = theBitmap->DisplayMode(); |
|
1029 |
|
1030 //TJpegImageData::TColorSampling iSampling; |
|
1031 //TInt iQualityFactor; // 0 to 100 inclusive |
|
1032 TImageDataBlock* imageData = NULL; |
|
1033 TFrameDataBlock* frameData = NULL; |
|
1034 |
|
1035 CFrameImageData* theFrameImageData = CFrameImageData::NewL(); |
|
1036 CleanupStack::PushL(theFrameImageData); |
|
1037 |
|
1038 theRes = PrepareEncodeDataL(theConvInfo, &imageData, &frameData); |
|
1039 // |
|
1040 if(imageData) |
|
1041 { |
|
1042 CleanupStack::PushL(imageData); |
|
1043 User::LeaveIfError(theFrameImageData->AppendImageData(imageData)); |
|
1044 CleanupStack::Pop(imageData); |
|
1045 } |
|
1046 if(frameData) |
|
1047 { |
|
1048 CleanupStack::PushL(frameData); |
|
1049 User::LeaveIfError(theFrameImageData->AppendFrameData(frameData)); |
|
1050 CleanupStack::Pop(frameData); |
|
1051 } |
|
1052 //-------------- |
|
1053 // do conversion |
|
1054 CActiveListener* activeListener = new(ELeave)CActiveListener; |
|
1055 CleanupStack::PushL( activeListener ); |
|
1056 |
|
1057 iActiveScheduler->SetEncoder(theImageEncoder, activeListener, 0); |
|
1058 iActiveScheduler->SetStep(this); |
|
1059 |
|
1060 activeListener->InitialiseActiveListener(); |
|
1061 theImageEncoder->Convert(&activeListener->iStatus, *theBitmap, theFrameImageData); |
|
1062 CActiveScheduler::Start(); |
|
1063 |
|
1064 |
|
1065 theRes = activeListener->iStatus.Int(); |
|
1066 iActiveScheduler->SetStep(NULL); |
|
1067 |
|
1068 // ! this function will be removed from API |
|
1069 //TInt nSize = iImageEncoder->CurrentImageSizeL(); |
|
1070 // |
|
1071 |
|
1072 CleanupStack::PopAndDestroy(4, theBitmap); //active sheduler |
|
1073 |
|
1074 if(theRes != KErrNone) |
|
1075 { |
|
1076 ERR_PRINTF1(_L("Error during conversion" )); |
|
1077 return theRes; |
|
1078 } |
|
1079 else |
|
1080 { |
|
1081 ERR_PRINTF1(_L("Conversion was successful" )); |
|
1082 } |
|
1083 // |
|
1084 //compare two file into a flat buffer |
|
1085 |
|
1086 TInt fileSize; |
|
1087 |
|
1088 iFile.Open(iFs, theDestinationFileName, EFileRead); |
|
1089 iFile.Size(fileSize); |
|
1090 HBufC8 *theCreatedImage = HBufC8::NewMaxLC(fileSize); |
|
1091 |
|
1092 TPtr8 imageFromFilePtr = theCreatedImage->Des(); |
|
1093 iFile.Read(imageFromFilePtr); |
|
1094 iFile.Close(); |
|
1095 |
|
1096 theRes = CompareFileL(aFilename, theCreatedImage, aImageTypeId, EInput); |
|
1097 |
|
1098 CleanupStack::PopAndDestroy(theCreatedImage); |
|
1099 // |
|
1100 iFs.Close(); |
|
1101 |
|
1102 return theRes; |
|
1103 } |
|
1104 |
|
1105 |
|
1106 |
|
1107 /* |
|
1108 * |
|
1109 * Prepare encode data |
|
1110 * |
|
1111 * @param "TConvertInfo &aConvInfo" |
|
1112 * input information |
|
1113 * "TImageDataBlock** imageData" |
|
1114 * "TFrameDataBlock** frameData" |
|
1115 * |
|
1116 * @return "TInt" |
|
1117 * error |
|
1118 */ |
|
1119 TInt CTestStepConversion::PrepareEncodeDataL(TConvertInfo &aConvInfo, |
|
1120 TImageDataBlock** aImageData, |
|
1121 TFrameDataBlock** aFrameData) |
|
1122 { |
|
1123 TBuf<KLenBuffer> nameSection; |
|
1124 TInt theRes = KErrNone; |
|
1125 TBool theColor = ETrue; |
|
1126 if(aConvInfo.iDisplayMode == EGray2) |
|
1127 theColor = EFalse; |
|
1128 |
|
1129 if(aConvInfo.iImageTypeId == KImageTypeMBMUid) |
|
1130 { |
|
1131 *aFrameData = new (ELeave) TMbmEncodeData; |
|
1132 TMbmEncodeData* data = STATIC_CAST(TMbmEncodeData*, *aFrameData); |
|
1133 TInt displaymode; |
|
1134 data->iDisplayMode = aConvInfo.iDisplayMode; |
|
1135 // |
|
1136 if(GetIntFromConfig(nameSection, _L("displaymode"), displaymode) == (TBool)ETrue) |
|
1137 { |
|
1138 switch(displaymode) |
|
1139 { |
|
1140 case 1: data->iDisplayMode = EGray2; break; |
|
1141 case 2: data->iDisplayMode = EGray4; break; |
|
1142 case 3: data->iDisplayMode = EGray16;break; |
|
1143 case 4: data->iDisplayMode = EGray256;break; |
|
1144 case 5: data->iDisplayMode = EColor16;break; |
|
1145 case 6: data->iDisplayMode = EColor256;break; |
|
1146 case 7: data->iDisplayMode = EColor64K;break; |
|
1147 case 8: data->iDisplayMode = EColor16M;break; |
|
1148 default: break; |
|
1149 } |
|
1150 } |
|
1151 } |
|
1152 else if(aConvInfo.iImageTypeId == KImageTypeGIFUid) |
|
1153 { |
|
1154 //the encoder is not configurable |
|
1155 } |
|
1156 else if(aConvInfo.iImageTypeId == KImageTypeBMPUid) |
|
1157 { |
|
1158 *aImageData= new(ELeave) TBmpImageData; |
|
1159 TBmpImageData* data = STATIC_CAST(TBmpImageData*, *aImageData); |
|
1160 |
|
1161 TPtrC ptr = iTestStepName; |
|
1162 nameSection = ptr.Right(KLenNameInSection); |
|
1163 TInt nBitsPerPixel = 0; |
|
1164 if(GetIntFromConfig(nameSection, _L("BitsPerPixel"), nBitsPerPixel) == EFalse) |
|
1165 { |
|
1166 |
|
1167 switch(aConvInfo.iDisplayMode) |
|
1168 { |
|
1169 case EGray2: data->iBitsPerPixel = 1; break; |
|
1170 case EGray4: data->iBitsPerPixel = 2; break; |
|
1171 case EGray16: data->iBitsPerPixel = 4; break; |
|
1172 case EGray256: data->iBitsPerPixel = 8;break; |
|
1173 case EColor16: data->iBitsPerPixel = 4; break; |
|
1174 case EColor256: data->iBitsPerPixel = 8; break; |
|
1175 case EColor64K: data->iBitsPerPixel = 16;break; |
|
1176 case EColor16M: data-> iBitsPerPixel = 24;break; |
|
1177 default: data->iBitsPerPixel = 0; break; |
|
1178 } |
|
1179 } |
|
1180 else |
|
1181 data->iBitsPerPixel = nBitsPerPixel; |
|
1182 } |
|
1183 else if(aConvInfo.iImageTypeId == KImageTypeJPGUid) |
|
1184 { |
|
1185 // read config file |
|
1186 TInt theQualityFactor = KDefaultQualityFactor; |
|
1187 TInt theSampling = KDefaultSampling; |
|
1188 |
|
1189 TPtrC ptr = iTestStepName; |
|
1190 nameSection = ptr.Right(KLenNameInSection); |
|
1191 GetIntFromConfig(nameSection, _L("QualityFactor"), theQualityFactor); |
|
1192 GetIntFromConfig(nameSection, _L("Sampling"), theSampling); |
|
1193 // |
|
1194 |
|
1195 *aImageData = new (ELeave) TJpegImageData; |
|
1196 TJpegImageData* data = STATIC_CAST(TJpegImageData*, *aImageData); |
|
1197 |
|
1198 if(!theColor) |
|
1199 data->iSampleScheme = TJpegImageData::EMonochrome; |
|
1200 else |
|
1201 data->iSampleScheme=TJpegImageData::TColorSampling(theSampling); |
|
1202 data->iQualityFactor=theQualityFactor; |
|
1203 } |
|
1204 |
|
1205 return theRes; |
|
1206 } |
|
1207 /* |
|
1208 * |
|
1209 * List all available decoders MIME types |
|
1210 * |
|
1211 * @return "TInt" |
|
1212 * error |
|
1213 */ |
|
1214 TInt CTestStepConversion::ListAvailableMIMEDecoders() |
|
1215 { |
|
1216 TInt theRes; |
|
1217 RFileExtensionMIMETypeArray theFileExtensionArray; |
|
1218 |
|
1219 TRAP(theRes, CImageDecoder::GetFileTypesL(theFileExtensionArray)); |
|
1220 |
|
1221 if(theRes != KErrNone) |
|
1222 { |
|
1223 theFileExtensionArray.ResetAndDestroy(); |
|
1224 return theRes; |
|
1225 } |
|
1226 |
|
1227 |
|
1228 INFO_PRINTF1(_L("A List of decoder file extensions and MIME types")); |
|
1229 |
|
1230 for (TInt index=0; index<theFileExtensionArray.Count(); index++) |
|
1231 { |
|
1232 CFileExtensionMIMEType& fileExtAndMIMEType = *theFileExtensionArray[index]; |
|
1233 |
|
1234 const TDesC& extension = fileExtAndMIMEType.FileExtension(); |
|
1235 const TDesC8& mimeType = fileExtAndMIMEType.MIMEType(); |
|
1236 TBuf<KLenBuffer> mimeType16; |
|
1237 |
|
1238 mimeType16.Copy(mimeType); |
|
1239 |
|
1240 INFO_PRINTF3(_L("Extension : %S, MIME Type : %S"), &extension, &mimeType16); |
|
1241 |
|
1242 } |
|
1243 |
|
1244 theFileExtensionArray.ResetAndDestroy(); |
|
1245 |
|
1246 return theRes; |
|
1247 } |
|
1248 |
|
1249 |
|
1250 /* |
|
1251 * |
|
1252 * List all available encoders MIME types |
|
1253 * |
|
1254 * @return "TInt" |
|
1255 * error |
|
1256 */ |
|
1257 TInt CTestStepConversion::ListAvailableMIMEEncoders() |
|
1258 { |
|
1259 TInt theRes = KErrNone; |
|
1260 |
|
1261 RFileExtensionMIMETypeArray theFileExtensionArray; |
|
1262 |
|
1263 TRAP(theRes, CImageEncoder::GetFileTypesL(theFileExtensionArray)); |
|
1264 |
|
1265 if(theRes != KErrNone) |
|
1266 { |
|
1267 theFileExtensionArray.ResetAndDestroy(); |
|
1268 return theRes; |
|
1269 } |
|
1270 INFO_PRINTF1(_L("\n")); |
|
1271 INFO_PRINTF1(_L("A List of encoder file extensions and MIME types")); |
|
1272 |
|
1273 for (TInt index=0; index<theFileExtensionArray.Count(); index++) |
|
1274 { |
|
1275 CFileExtensionMIMEType& fileExtAndMIMEType = *theFileExtensionArray[index]; |
|
1276 |
|
1277 const TDesC& extension = fileExtAndMIMEType.FileExtension(); |
|
1278 const TDesC8& mimeType = fileExtAndMIMEType.MIMEType(); |
|
1279 TBuf<KLenBuffer> mimeType16; |
|
1280 |
|
1281 mimeType16.Copy(mimeType); |
|
1282 |
|
1283 INFO_PRINTF3(_L("Extension: %S, MIME Type : %S") , &extension, &mimeType16); |
|
1284 |
|
1285 } |
|
1286 theFileExtensionArray.ResetAndDestroy(); |
|
1287 |
|
1288 return theRes; |
|
1289 } |
|
1290 |
|
1291 /* |
|
1292 * |
|
1293 * List all available decoders |
|
1294 * |
|
1295 * @return "TInt" |
|
1296 * error |
|
1297 */ |
|
1298 TInt CTestStepConversion::ListAllAvailableDecoders() |
|
1299 { |
|
1300 TInt theRes = KErrNone; |
|
1301 |
|
1302 |
|
1303 // find out UID and then name of the codec |
|
1304 RImageTypeDescriptionArray imageDecTypeArray; |
|
1305 TRAP(theRes, CImageDecoder::GetImageTypesL(imageDecTypeArray)); |
|
1306 // find a description with the same image type and, if subtype given, subtype too |
|
1307 |
|
1308 if(theRes != KErrNone) |
|
1309 { |
|
1310 return theRes; |
|
1311 } |
|
1312 |
|
1313 TInt index; |
|
1314 |
|
1315 if(imageDecTypeArray.Count() > 0) |
|
1316 INFO_PRINTF1(_L("A List of available Decoder plugins!")); |
|
1317 |
|
1318 for (index=0; index<imageDecTypeArray.Count(); index++) |
|
1319 { |
|
1320 CImageTypeDescription& description = *imageDecTypeArray[index]; |
|
1321 |
|
1322 const TDesC& theBufDes = description.Description(); |
|
1323 |
|
1324 INFO_PRINTF1(theBufDes); |
|
1325 // |
|
1326 TUid theUid = description.ImageType(); |
|
1327 RImageTypeDescriptionArray theSubTypeArray; |
|
1328 |
|
1329 TInt theRes1; |
|
1330 TRAP(theRes1, CImageDecoder::GetImageSubTypesL(theUid, theSubTypeArray)); |
|
1331 |
|
1332 if(theRes1 == KErrNone) |
|
1333 { |
|
1334 if(theSubTypeArray.Count() > 0) |
|
1335 INFO_PRINTF1(_L("A List of available Sub Types:")); |
|
1336 TInt index1; |
|
1337 for (index1=0; index1<theSubTypeArray.Count(); index1++) |
|
1338 { |
|
1339 CImageTypeDescription& description1 = *theSubTypeArray[index1]; |
|
1340 const TDesC& theBufDes1 = description1.Description(); |
|
1341 |
|
1342 INFO_PRINTF2(_L(" %S"), &theBufDes1); |
|
1343 |
|
1344 } |
|
1345 theSubTypeArray.ResetAndDestroy(); |
|
1346 } |
|
1347 // |
|
1348 INFO_PRINTF1(_L("\n")); |
|
1349 } |
|
1350 imageDecTypeArray.ResetAndDestroy(); |
|
1351 |
|
1352 return theRes; // |
|
1353 } |
|
1354 |
|
1355 /* |
|
1356 * |
|
1357 * List all available encoders |
|
1358 * |
|
1359 * @return "TInt" |
|
1360 * error |
|
1361 */ |
|
1362 TInt CTestStepConversion::ListAllAvailableEncoders() |
|
1363 { |
|
1364 TInt theRes = KErrNone; |
|
1365 |
|
1366 // find out UID and then name of the codec |
|
1367 RImageTypeDescriptionArray imageEncTypeArray; |
|
1368 |
|
1369 TRAP(theRes, CImageEncoder::GetImageTypesL(imageEncTypeArray)); |
|
1370 |
|
1371 if(theRes != KErrNone) |
|
1372 return theRes; |
|
1373 // find a description with the same image type and, if subtype given, subtype too |
|
1374 TInt index; |
|
1375 |
|
1376 if(imageEncTypeArray.Count() > 0) |
|
1377 INFO_PRINTF1(_L("A List of available Encoder plugins!")); |
|
1378 |
|
1379 for (index=0; index<imageEncTypeArray.Count(); index++) |
|
1380 { |
|
1381 CImageTypeDescription& description = *imageEncTypeArray[index]; |
|
1382 |
|
1383 const TDesC& theBufDes = description.Description(); |
|
1384 |
|
1385 INFO_PRINTF1(theBufDes); |
|
1386 |
|
1387 // |
|
1388 TUid theUid = description.ImageType(); |
|
1389 RImageTypeDescriptionArray theSubTypeArray; |
|
1390 |
|
1391 TInt theRes1; |
|
1392 TRAP(theRes1, CImageEncoder::GetImageSubTypesL(theUid, theSubTypeArray)); |
|
1393 |
|
1394 if(theRes1 == KErrNone) |
|
1395 { |
|
1396 if(theSubTypeArray.Count() > 0) |
|
1397 INFO_PRINTF1(_L("A List of available Sub Types:")); |
|
1398 TInt index1; |
|
1399 for (index1=0; index1<theSubTypeArray.Count(); index1++) |
|
1400 { |
|
1401 CImageTypeDescription& description1 = *theSubTypeArray[index1]; |
|
1402 const TDesC& theBufDes1 = description1.Description(); |
|
1403 |
|
1404 INFO_PRINTF2(_L(" %S"), &theBufDes1); |
|
1405 |
|
1406 } |
|
1407 theSubTypeArray.ResetAndDestroy(); |
|
1408 } |
|
1409 // |
|
1410 |
|
1411 } |
|
1412 imageEncTypeArray.ResetAndDestroy(); |
|
1413 |
|
1414 return theRes; |
|
1415 } |
|
1416 |
|
1417 /* |
|
1418 * |
|
1419 * Enquire MIME type of an unopened image |
|
1420 * |
|
1421 * @param "const TDesC& aFileName" |
|
1422 * |
|
1423 * @return "TInt" |
|
1424 * error |
|
1425 */ |
|
1426 TInt CTestStepConversion::FindMimeTypeL(const TDesC& aFileName) |
|
1427 { |
|
1428 TInt theRes = KErrNone; |
|
1429 |
|
1430 TBuf8<KLenBuffer> theMimeType; |
|
1431 |
|
1432 INFO_PRINTF1(_L("Enquire MIME type of an unopened images")); |
|
1433 |
|
1434 User::LeaveIfError(iFs.Connect()); |
|
1435 |
|
1436 TFileName theSourceFilename; |
|
1437 Directory(EInput, theSourceFilename); |
|
1438 theSourceFilename.Append(aFileName); |
|
1439 |
|
1440 CImageDecoder::GetMimeTypeFileL(iFs, theSourceFilename, theMimeType); |
|
1441 TBuf<KLenBuffer> mimeType; |
|
1442 mimeType.Copy(theMimeType); |
|
1443 INFO_PRINTF3(_L("File : %S, MimeType %S"), &theSourceFilename, &mimeType); |
|
1444 //------------- |
|
1445 TInt fileSize; |
|
1446 |
|
1447 iFile.Open(iFs, theSourceFilename, EFileRead); |
|
1448 iFile.Size(fileSize); |
|
1449 HBufC8 *theImageFromFile = HBufC8::NewMaxLC(fileSize); |
|
1450 |
|
1451 TPtr8 imageFromFilePtr = theImageFromFile->Des(); |
|
1452 iFile.Read(imageFromFilePtr); |
|
1453 iFile.Close(); |
|
1454 |
|
1455 iFs.Close(); |
|
1456 |
|
1457 TBuf8<KLenBuffer> theMimeType1; |
|
1458 |
|
1459 CImageDecoder::GetMimeTypeDataL(imageFromFilePtr, theMimeType1); |
|
1460 |
|
1461 mimeType.Copy(theMimeType1); |
|
1462 INFO_PRINTF3(_L("Reading from buffer, File : %S, MimeType %S\n"), |
|
1463 &theSourceFilename, &mimeType); |
|
1464 |
|
1465 CleanupStack::PopAndDestroy(); |
|
1466 |
|
1467 return theRes; |
|
1468 } |
|
1469 |
|
1470 |
|
1471 /* |
|
1472 * |
|
1473 * Enquire UID of a loaded decoder & Implementation Info |
|
1474 * |
|
1475 * @param "const TDesC& aFileName" |
|
1476 * |
|
1477 * @return "TInt" |
|
1478 * error |
|
1479 */ |
|
1480 TInt CTestStepConversion::EnquireDecoderUIDAndImplementationInfoL(const TDesC& aFileName) |
|
1481 { |
|
1482 TInt theRes = KErrNone; |
|
1483 |
|
1484 User::LeaveIfError(iFs.Connect()); |
|
1485 |
|
1486 TFileName theSourceFilename; |
|
1487 Directory(EInput, theSourceFilename); |
|
1488 theSourceFilename.Append(aFileName); |
|
1489 |
|
1490 CImageDecoder *theImageDecoder = CImageDecoder::FileNewL(iFs, theSourceFilename); |
|
1491 if(theImageDecoder == NULL) |
|
1492 return KErrUnknown; |
|
1493 |
|
1494 TUid uid = theImageDecoder->ImplementationUid(); |
|
1495 INFO_PRINTF3(_L("UID of a loaded decoder during reading file %S = %x\n"), |
|
1496 &theSourceFilename, uid); |
|
1497 |
|
1498 delete theImageDecoder; |
|
1499 theImageDecoder = NULL; |
|
1500 //------------------------ |
|
1501 TInt fileSize; |
|
1502 |
|
1503 iFile.Open(iFs, theSourceFilename, EFileRead); |
|
1504 iFile.Size(fileSize); |
|
1505 HBufC8 *theImageFromFile = HBufC8::NewMaxLC(fileSize); |
|
1506 |
|
1507 TPtr8 imageFromFilePtr = theImageFromFile->Des(); |
|
1508 iFile.Read(imageFromFilePtr); |
|
1509 iFile.Close(); |
|
1510 iFs.Close(); |
|
1511 |
|
1512 |
|
1513 theImageDecoder = CImageDecoder::DataNewL(iFs, imageFromFilePtr); |
|
1514 if(theImageDecoder == NULL) |
|
1515 return KErrUnknown; |
|
1516 CleanupStack::PushL(theImageDecoder); |
|
1517 TUid uid1 = theImageDecoder->ImplementationUid(); |
|
1518 |
|
1519 INFO_PRINTF2(_L("UID of a loaded decoder from buffer = 0x%08x\n"), |
|
1520 uid1); |
|
1521 //------ |
|
1522 //Request ImplementationInformation |
|
1523 CImplementationInformationType* theImplementationInfo = |
|
1524 CImageDecoder::GetImplementationInformationL(uid1); |
|
1525 CleanupStack::PushL(theImplementationInfo); |
|
1526 TInt theVersion = theImplementationInfo->Version(); |
|
1527 const TDesC& dispName = theImplementationInfo->DisplayName(); |
|
1528 const TDesC8& dataType8 = theImplementationInfo->DataType(); |
|
1529 const TDesC8& opaqueData8 = theImplementationInfo->OpaqueData(); |
|
1530 |
|
1531 TBuf<KLenBuffer> dataType; |
|
1532 TBuf<KLenBuffer> opaqueData; |
|
1533 |
|
1534 dataType.Copy(dataType8); |
|
1535 opaqueData.Copy(opaqueData8); |
|
1536 //------------------ |
|
1537 TUid theUid; |
|
1538 TUid theUidSubType; |
|
1539 |
|
1540 theImageDecoder->ImageType(0, theUid, theUidSubType); |
|
1541 |
|
1542 TInt versionNo = 0; |
|
1543 TBuf<KLenBuffer> bufDisplayName; |
|
1544 const TUint8* defaultDataPtr = NULL; |
|
1545 const TUint8* opaqueDataPtr = NULL; |
|
1546 TInt lenDefaultData = 0; |
|
1547 TInt lenOpaqueData = 0; |
|
1548 |
|
1549 TInt versionNoJPEG = 1; |
|
1550 const TUint8 defaultDataJPEG[] = {0xFF, 0xD8}; |
|
1551 static const TUint8 opaqueDataJPEG[] = {0, 0x10, 0x1F, 0x45, 0xD8, 0, 0, 0, 0, 1, 0x2E, 0x6A, 0x70, 0x67, 0x0D, 1, 0x69, 0x6D, 0x61, 0x67, 0x65, 0x2F, 0x6A, 0x70, 0x65, 0x67, 0x0D}; |
|
1552 |
|
1553 TInt versionNoGIF = 1; |
|
1554 const TUint8 defaultDataGIF[] = {0x47, 0x49, 0x46, 0x38, 0x3F, 0x61}; |
|
1555 static const TUint8 opaqueDataGIF[] = {0, 0x10, 0x1F, 0x45, 0xB3, 0, 0, 0, 0, 1, 0x2E, 0x67, 0x69, 0x66, 0x0D, 1, 0x69, 0x6D, 0x61, 0x67, 0x65, 0x2F, 0x67, 0x69, 0x66, 0x0D}; |
|
1556 |
|
1557 TInt versionNoBMP = 1; |
|
1558 const TUint8 defaultDataBMP[] = {0x42, 0x4D}; |
|
1559 static const TUint8 opaqueDataBMP[] = {0, 0x10, 0x1F, 0x45, 0xB0, 0, 0, 0, 0, 1, 0x2E, 0x62, 0x6D, 0x70, 0x0D, 2, 0x69, 0x6D, 0x61, 0x67, 0x65, 0x2F, 0x78, 0x2D, 0x62, 0x6D, 0x70, 0x0D, 0x69, 0x6D, 0x61, 0x67, 0x65, 0x2F, 0x62, 0x6D, 0x70, 0x0D}; |
|
1560 |
|
1561 if(theUid == KImageTypeJPGUid) |
|
1562 { |
|
1563 versionNo = versionNoJPEG; |
|
1564 bufDisplayName = _L("JPEG"); |
|
1565 defaultDataPtr = defaultDataJPEG; |
|
1566 opaqueDataPtr = opaqueDataJPEG; |
|
1567 lenDefaultData = sizeof(defaultDataJPEG) / sizeof(defaultDataJPEG[0]); |
|
1568 lenOpaqueData = sizeof(opaqueDataJPEG) / sizeof(opaqueDataJPEG[0]); |
|
1569 } |
|
1570 else if(theUid == KImageTypeGIFUid) |
|
1571 { |
|
1572 versionNo = versionNoGIF; |
|
1573 bufDisplayName = _L("GIF"); |
|
1574 defaultDataPtr = defaultDataGIF; |
|
1575 opaqueDataPtr = opaqueDataGIF; |
|
1576 lenDefaultData = sizeof(defaultDataGIF) / sizeof(defaultDataGIF[0]); |
|
1577 lenOpaqueData = sizeof(opaqueDataGIF) / sizeof(opaqueDataGIF[0]); |
|
1578 } |
|
1579 else if(theUid == KImageTypeBMPUid) |
|
1580 { |
|
1581 versionNo = versionNoBMP; |
|
1582 bufDisplayName = _L("BMP"); |
|
1583 defaultDataPtr = defaultDataBMP; |
|
1584 opaqueDataPtr = opaqueDataBMP; |
|
1585 lenDefaultData = sizeof(defaultDataBMP) / sizeof(defaultDataBMP[0]); |
|
1586 lenOpaqueData = sizeof(opaqueDataBMP) / sizeof(opaqueDataBMP[0]); |
|
1587 } |
|
1588 |
|
1589 if(versionNo != theVersion) |
|
1590 theRes = KErrNotIdentical; |
|
1591 |
|
1592 if(theRes == KErrNone) |
|
1593 theRes = Mem::Compare(defaultDataPtr, lenDefaultData, |
|
1594 dataType8.Ptr(), dataType8.Length()); |
|
1595 |
|
1596 |
|
1597 |
|
1598 if(theRes == KErrNone) |
|
1599 { |
|
1600 theRes = Mem::Compare(opaqueDataPtr, lenOpaqueData, |
|
1601 opaqueData8.Ptr(), opaqueData8.Length()); |
|
1602 if (theUid == KImageTypeJPGUid && theRes!=KErrNone) |
|
1603 { |
|
1604 INFO_PRINTF1(_L("Known issue: EXIF plug-in has got different data, ignoring diffs.")); |
|
1605 theRes=KErrNone; |
|
1606 } |
|
1607 } |
|
1608 //------------ |
|
1609 INFO_PRINTF1(_L("Implementation information")); |
|
1610 INFO_PRINTF2(_L("Display name : %S"), &dispName); |
|
1611 INFO_PRINTF2(_L("Version : %d"), theVersion); |
|
1612 //INFO_PRINTF2(_L("Data type : %S"), &dataType); |
|
1613 //INFO_PRINTF2(_L("Opaque data : %S"), &opaqueData); |
|
1614 |
|
1615 //------- |
|
1616 CleanupStack::PopAndDestroy(3, theImageFromFile); //theImageDecoder, theImageFromFile, theImplementationInfo |
|
1617 |
|
1618 return theRes; // |
|
1619 } |
|
1620 |
|
1621 /* |
|
1622 * |
|
1623 * Enquire UID of a loaded encoder |
|
1624 * |
|
1625 * @param "const TDesC& aFileName" |
|
1626 * |
|
1627 * @return "TInt" |
|
1628 * error |
|
1629 */ |
|
1630 TInt CTestStepConversion::EnquireEncoderUIDL(const TDesC& aFileName, |
|
1631 TUid aTypeImageUid) |
|
1632 { |
|
1633 TInt theRes = KErrNotSupported; |
|
1634 |
|
1635 |
|
1636 User::LeaveIfError(iFs.Connect()); |
|
1637 |
|
1638 TFileName theDestinationFilename; |
|
1639 Directory(EOutput, theDestinationFilename); |
|
1640 theDestinationFilename.Append(aFileName); |
|
1641 |
|
1642 CImageEncoder *theImageEncoder = NULL; |
|
1643 TRAP(theRes, theImageEncoder = CImageEncoder::FileNewL(iFs, theDestinationFilename, |
|
1644 CImageEncoder::EOptionNone, aTypeImageUid)); |
|
1645 if(theRes != KErrNone) |
|
1646 { |
|
1647 iFs.Close(); |
|
1648 INFO_PRINTF2(_L("Cannot create file with Uid = %d\n"), |
|
1649 aTypeImageUid); |
|
1650 |
|
1651 if(KErrPathNotFound == theRes) |
|
1652 INFO_PRINTF2(_L("Path %S not found"), &theDestinationFilename); |
|
1653 return theRes; |
|
1654 } |
|
1655 CleanupStack::PushL(theImageEncoder); |
|
1656 TUid uid1 = theImageEncoder->ImplementationUid(); |
|
1657 INFO_PRINTF3(_L("UID of a loaded decoder during openning file %S = %d\n"), |
|
1658 &theDestinationFilename, uid1); |
|
1659 |
|
1660 CleanupStack::PopAndDestroy(theImageEncoder); |
|
1661 |
|
1662 return theRes; |
|
1663 } |
|
1664 |
|
1665 /* |
|
1666 * |
|
1667 * Request number frames in image |
|
1668 * |
|
1669 * @param "const TDesC& aFileName" |
|
1670 * |
|
1671 * @return "TInt" |
|
1672 * error |
|
1673 */ |
|
1674 TInt CTestStepConversion::RequestNumberFramesL(const TDesC& aFileName) |
|
1675 { |
|
1676 TInt theRes = KErrNone; |
|
1677 |
|
1678 User::LeaveIfError(iFs.Connect()); |
|
1679 |
|
1680 TFileName theSourceFilename; |
|
1681 Directory(EInput, theSourceFilename); |
|
1682 theSourceFilename.Append(aFileName); |
|
1683 |
|
1684 CImageDecoder *theImageDecoder = CImageDecoder::FileNewL(iFs, theSourceFilename); |
|
1685 CleanupStack::PushL(theImageDecoder); |
|
1686 if(theImageDecoder == NULL) |
|
1687 return KErrUnknown; |
|
1688 |
|
1689 TInt theFrameCount = theImageDecoder->FrameCount(); |
|
1690 |
|
1691 CleanupStack::PopAndDestroy(theImageDecoder); |
|
1692 |
|
1693 iFs.Close(); |
|
1694 |
|
1695 INFO_PRINTF3(_L("Number of frames from a file %S = %d\n"), |
|
1696 &theSourceFilename, theFrameCount); |
|
1697 |
|
1698 return theRes; |
|
1699 } |
|
1700 |
|
1701 |
|
1702 /* |
|
1703 * |
|
1704 * Print frame information |
|
1705 * |
|
1706 * @param "const TFrameInfo& aFrameInfo" |
|
1707 * |
|
1708 */ |
|
1709 TAny CTestStepConversion::PrintFrameInfo(const TFrameInfo& aFrameInfo) |
|
1710 { |
|
1711 TBuf<KLenBuffer> theBuf; |
|
1712 //TRect iFrameCoordsInPixels; |
|
1713 //TSize iFrameSizeInTwips; |
|
1714 //TInt iBitsPerPixel; |
|
1715 //TTimeIntervalMicroSeconds iDelay; |
|
1716 //TUint32 iFlags; |
|
1717 //TSize iOverallSizeInPixels; |
|
1718 //TDisplayMode iFrameDisplayMode; |
|
1719 //TRgb iBackgroundColor; |
|
1720 |
|
1721 INFO_PRINTF5(_L("Frame's coordinates (left, top, right, bottom) = %d, %d, %d, %d\n"), |
|
1722 aFrameInfo.iFrameCoordsInPixels.iTl.iX, aFrameInfo.iFrameCoordsInPixels.iTl.iY, |
|
1723 aFrameInfo.iFrameCoordsInPixels.iBr.iX, aFrameInfo.iFrameCoordsInPixels.iBr.iY); |
|
1724 |
|
1725 INFO_PRINTF3(_L("Frame's size in twips = %d, %d\n"), |
|
1726 aFrameInfo.iFrameSizeInTwips.iWidth, aFrameInfo.iFrameSizeInTwips.iHeight); |
|
1727 |
|
1728 INFO_PRINTF2(_L("Bits per pixel = %d\n"), |
|
1729 aFrameInfo.iBitsPerPixel); |
|
1730 |
|
1731 TInt64 int64 = aFrameInfo.iDelay.Int64(); |
|
1732 TInt delay = I64INT(int64); |
|
1733 |
|
1734 INFO_PRINTF2(_L("Delay in microseconds = %d\n"), |
|
1735 delay); |
|
1736 |
|
1737 INFO_PRINTF3(_L("Overall size in pixel = %d, %d\n"), |
|
1738 aFrameInfo.iOverallSizeInPixels.iWidth, aFrameInfo.iOverallSizeInPixels.iHeight); |
|
1739 |
|
1740 FrameDisplayMode(aFrameInfo.iFrameDisplayMode, theBuf); |
|
1741 INFO_PRINTF2(_L("Frame display mode = %S\n"), |
|
1742 &theBuf); |
|
1743 |
|
1744 INFO_PRINTF4(_L("Background color Red, Green, Blue = %d, %d, %d \n"), |
|
1745 aFrameInfo.iBackgroundColor.Red(), |
|
1746 aFrameInfo.iBackgroundColor.Green(), |
|
1747 aFrameInfo.iBackgroundColor.Blue()); |
|
1748 |
|
1749 } |
|
1750 |
|
1751 /* |
|
1752 * |
|
1753 * Request decode information & options for frames in a loaded image |
|
1754 * and print it |
|
1755 * |
|
1756 * @param "const TDesC& aFileName" |
|
1757 * "TInt aParam" |
|
1758 * KShowFrameInformation - show Frame Information |
|
1759 * KShowFrameOption - show frame option |
|
1760 * |
|
1761 * @return "TInt" |
|
1762 * error |
|
1763 */ |
|
1764 TInt CTestStepConversion::RequestDecodeDataL(const TDesC& aFileName, TInt aParam) |
|
1765 { |
|
1766 TInt theErr = KErrNone; |
|
1767 |
|
1768 User::LeaveIfError(iFs.Connect()); |
|
1769 |
|
1770 TFileName theSourceFilename; |
|
1771 Directory(EInput, theSourceFilename); |
|
1772 theSourceFilename.Append(aFileName); |
|
1773 |
|
1774 CImageDecoder *theImageDecoder = NULL; |
|
1775 TRAP(theErr, theImageDecoder = CImageDecoder::FileNewL(iFs, theSourceFilename)); |
|
1776 CleanupStack::PushL(theImageDecoder); |
|
1777 if(theErr != KErrNone) |
|
1778 { |
|
1779 INFO_PRINTF2(_L("Cannot open decoder for file %S\n"), &theSourceFilename); |
|
1780 |
|
1781 |
|
1782 return theErr; |
|
1783 } |
|
1784 INFO_PRINTF2(_L("The file %S had been loaded successfully\n"), &theSourceFilename); |
|
1785 |
|
1786 //frames loop |
|
1787 TInt theFrameCount = theImageDecoder->FrameCount(); |
|
1788 for(TInt theCurFrame = 0; theCurFrame < theFrameCount;theCurFrame++ ) |
|
1789 { |
|
1790 const TFrameInfo& theFrameInfo = theImageDecoder->FrameInfo(theCurFrame); |
|
1791 |
|
1792 INFO_PRINTF1(_L("------------\n")); |
|
1793 INFO_PRINTF2(_L("The frame number %d\n"), |
|
1794 theCurFrame); |
|
1795 if(aParam & KShowFrameInformation) |
|
1796 { |
|
1797 PrintFrameInfo(theFrameInfo); |
|
1798 |
|
1799 //--------------------- |
|
1800 const CFrameImageData& theFrameData = theImageDecoder->FrameData(theCurFrame); |
|
1801 TInt theImageDataCount = theFrameData.ImageDataCount(); |
|
1802 TInt theFrameCount = theFrameData.FrameDataCount(); |
|
1803 INFO_PRINTF2(_L("Number frame data entries %d"), theFrameCount); |
|
1804 TInt index; |
|
1805 for(index = 0; index < theFrameCount; index++) |
|
1806 { |
|
1807 const TFrameDataBlock* theFrameDataBlock = theFrameData.GetFrameData(index); |
|
1808 INFO_PRINTF3(_L("Frame Data Block # %d, UId %d"), |
|
1809 index, theFrameDataBlock->DataType()); |
|
1810 |
|
1811 } |
|
1812 |
|
1813 INFO_PRINTF2(_L("Number image data entries %d"), theImageDataCount); |
|
1814 for(index = 0; index < theImageDataCount; index++) |
|
1815 { |
|
1816 const TImageDataBlock* theImageDataBlock = theFrameData.GetImageData(index); |
|
1817 INFO_PRINTF3(_L("Image Data Block # %d, UId %d"), |
|
1818 index, theImageDataBlock->DataType()); |
|
1819 |
|
1820 } |
|
1821 } |
|
1822 //-------------- |
|
1823 |
|
1824 if(aParam & KShowFrameOption) |
|
1825 PrintFrameOptions(theFrameInfo); |
|
1826 } |
|
1827 |
|
1828 CleanupStack::PopAndDestroy(theImageDecoder); |
|
1829 iFs.Close(); |
|
1830 |
|
1831 return theErr; |
|
1832 } |
|
1833 |
|
1834 |
|
1835 /* |
|
1836 * |
|
1837 * Print frame options |
|
1838 * |
|
1839 * @param "const TFrameInfo& aFrameInfo" |
|
1840 * |
|
1841 */ |
|
1842 TAny CTestStepConversion::PrintFrameOptions(const TFrameInfo& aFrameInfo) |
|
1843 { |
|
1844 _LIT(theBufYes, "Yes"); |
|
1845 _LIT(theBufNo, "No"); |
|
1846 |
|
1847 // iFlags; |
|
1848 |
|
1849 //EColor = 0x00000001 Grayscale if not set |
|
1850 //ETransparencyPossible = 0x00000002 Fully opaque if not set |
|
1851 //EFullyScaleable = 0x00000004 Will only scale to 1/2,1/4 & 1/8th if not set |
|
1852 //EConstantAspectRatio = 0x00000008 Scaling need not maintain aspect ratio if not set |
|
1853 //ECanDither = 0x00000010 Will not use error diffusion if not set |
|
1854 //EAlphaChannel = 0x00000020 Set if the image contains alpha-blending information |
|
1855 //ELeaveInPlace = 0x00000040 |
|
1856 //ERestoreToBackground = 0x00000080 Mutually exclusive image disposal methods |
|
1857 //ERestoreToPrevious = 0x00000100 |
|
1858 //EPartialDecodeInvalid = 0x00000200 Where CImageDecoder::Convert fails on KErrUnderflow, image not suitable for display |
|
1859 |
|
1860 if(TFrameInfo::EColor & aFrameInfo.iFlags) |
|
1861 INFO_PRINTF2(_L("Color = %S \n"), |
|
1862 &theBufYes); |
|
1863 else |
|
1864 INFO_PRINTF2(_L("Color = %S \n"), |
|
1865 &theBufNo); |
|
1866 |
|
1867 if(TFrameInfo::ETransparencyPossible & aFrameInfo.iFlags) |
|
1868 INFO_PRINTF2(_L("Transparency = %S \n"), |
|
1869 &theBufYes); |
|
1870 else |
|
1871 INFO_PRINTF2(_L("Transparency = %S \n"), |
|
1872 &theBufNo); |
|
1873 |
|
1874 if(TFrameInfo::EFullyScaleable & aFrameInfo.iFlags) |
|
1875 INFO_PRINTF2(_L("Fully scaleable = %S \n"), |
|
1876 &theBufYes); |
|
1877 else |
|
1878 INFO_PRINTF2(_L("Fully scaleable = %S \n"), |
|
1879 &theBufNo); |
|
1880 |
|
1881 if(TFrameInfo::EConstantAspectRatio & aFrameInfo.iFlags) |
|
1882 INFO_PRINTF2(_L("Aspect ratio = %S \n"), |
|
1883 &theBufYes); |
|
1884 else |
|
1885 INFO_PRINTF2(_L("Aspect ratio = %S \n"), |
|
1886 &theBufNo); |
|
1887 |
|
1888 if(TFrameInfo::ECanDither & aFrameInfo.iFlags) |
|
1889 INFO_PRINTF2(_L("Can dither = %S \n"), |
|
1890 &theBufYes); |
|
1891 else |
|
1892 INFO_PRINTF2(_L("Can dither = %S \n"), |
|
1893 &theBufNo); |
|
1894 |
|
1895 if(TFrameInfo::EAlphaChannel & aFrameInfo.iFlags) |
|
1896 INFO_PRINTF2(_L("Alpha channel = %S \n"), |
|
1897 &theBufYes); |
|
1898 else |
|
1899 INFO_PRINTF2(_L("Alpha channel = %S \n"), |
|
1900 &theBufNo); |
|
1901 |
|
1902 if(TFrameInfo::ELeaveInPlace & aFrameInfo.iFlags) |
|
1903 INFO_PRINTF2(_L("Leave in place = %S \n"), |
|
1904 &theBufYes); |
|
1905 else |
|
1906 INFO_PRINTF2(_L("Leave in place = %S \n"), |
|
1907 &theBufNo); |
|
1908 |
|
1909 if(TFrameInfo::ERestoreToBackground & aFrameInfo.iFlags) |
|
1910 INFO_PRINTF2(_L("Restore to background = %S \n"), |
|
1911 &theBufYes); |
|
1912 else |
|
1913 INFO_PRINTF2(_L("Restore to background = %S \n"), |
|
1914 &theBufNo); |
|
1915 |
|
1916 if(TFrameInfo::ERestoreToPrevious & aFrameInfo.iFlags) |
|
1917 INFO_PRINTF2(_L("Restore to previos = %S \n"), |
|
1918 &theBufYes); |
|
1919 else |
|
1920 INFO_PRINTF2(_L("Restore to previos = %S \n"), |
|
1921 &theBufNo); |
|
1922 |
|
1923 if(TFrameInfo::EPartialDecodeInvalid & aFrameInfo.iFlags) |
|
1924 INFO_PRINTF2(_L("Partial decode invalid = %S \n"), |
|
1925 &theBufYes); |
|
1926 else |
|
1927 INFO_PRINTF2(_L("Partial decode invalid = %S \n"), |
|
1928 &theBufNo); |
|
1929 |
|
1930 } |
|
1931 |
|
1932 /* |
|
1933 * |
|
1934 * Open image and retrieve embedded image comments |
|
1935 * |
|
1936 * @param "TUid aImageTypeId" |
|
1937 * Uid encoder |
|
1938 * |
|
1939 * @return "TInt" |
|
1940 * error |
|
1941 */ |
|
1942 TInt CTestStepConversion::RetrieveEmbeddedCommentsL(const TDesC& aFilename) |
|
1943 { |
|
1944 |
|
1945 TInt theRes = KErrNone; |
|
1946 |
|
1947 TFileName theSourceFilename; |
|
1948 Directory(EInput, theSourceFilename); |
|
1949 theSourceFilename.Append(aFilename); |
|
1950 |
|
1951 User::LeaveIfError(iFs.Connect()); |
|
1952 |
|
1953 // |
|
1954 CImageDecoder *theImageDecoder = NULL; |
|
1955 TRAP(theRes, (theImageDecoder = CImageDecoder::FileNewL(iFs, theSourceFilename)));//, |
|
1956 |
|
1957 if(theRes != KErrNone) |
|
1958 { |
|
1959 INFO_PRINTF2(_L("Cannot open file %S"), |
|
1960 &theSourceFilename); |
|
1961 return theRes; |
|
1962 |
|
1963 } |
|
1964 if(theImageDecoder == NULL) |
|
1965 return KErrUnknown; |
|
1966 CleanupStack::PushL(theImageDecoder); |
|
1967 TInt theNumComment=theImageDecoder->NumberOfImageComments(); |
|
1968 |
|
1969 INFO_PRINTF3(_L("Number of image comments in the file %S = %d\n"), |
|
1970 &theSourceFilename, |
|
1971 theNumComment); |
|
1972 for(TInt theCurComment = 0; theCurComment < theNumComment ;theCurComment++) |
|
1973 { |
|
1974 HBufC* commentBuf = theImageDecoder->ImageCommentL(theCurComment); |
|
1975 if(commentBuf) |
|
1976 { |
|
1977 |
|
1978 TPtr imageCommentPtr = commentBuf->Des(); |
|
1979 |
|
1980 INFO_PRINTF3(_L("Frame %d, comment - %S \n"), |
|
1981 theCurComment, |
|
1982 &imageCommentPtr); |
|
1983 |
|
1984 delete commentBuf; |
|
1985 } |
|
1986 } |
|
1987 |
|
1988 CleanupStack::PopAndDestroy(theImageDecoder); |
|
1989 |
|
1990 iFs.Close(); |
|
1991 |
|
1992 return theRes; |
|
1993 } |
|
1994 |
|
1995 /* |
|
1996 * |
|
1997 * Open image and retrieve frame info |
|
1998 * |
|
1999 * @param "const TDesC& aFilename" |
|
2000 * |
|
2001 * @return "TInt" |
|
2002 * error |
|
2003 */ |
|
2004 TInt CTestStepConversion::RetrieveFrameInfoL(const TDesC& aFilename) |
|
2005 { |
|
2006 TInt theRes = KErrNone; |
|
2007 |
|
2008 TFileName theSourceFilename; |
|
2009 Directory(EInput, theSourceFilename); |
|
2010 theSourceFilename.Append(aFilename); |
|
2011 |
|
2012 User::LeaveIfError(iFs.Connect()); |
|
2013 // |
|
2014 CImageDecoder* theImageDecoder = NULL; |
|
2015 TRAP(theRes, (theImageDecoder = CImageDecoder::FileNewL(iFs, theSourceFilename, |
|
2016 CImageDecoder::EOptionNone))); |
|
2017 CleanupStack::PushL(theImageDecoder); |
|
2018 if(theRes != KErrNone) |
|
2019 { |
|
2020 INFO_PRINTF2(_L("Cannot open file %S"), |
|
2021 &theSourceFilename); |
|
2022 return theRes; |
|
2023 |
|
2024 } |
|
2025 if(theImageDecoder == NULL) |
|
2026 return KErrUnknown; |
|
2027 |
|
2028 TInt theNumOfFrameComments = theImageDecoder->NumberOfFrameComments(0); |
|
2029 INFO_PRINTF2(_L("Number of frame comments : %d"), theNumOfFrameComments); |
|
2030 |
|
2031 // GIF doesn't support frame comments |
|
2032 // HBufC* theBuf = iImageDecoder->FrameCommentL(0, 0); |
|
2033 // TPtr theBufPtr = theBuf->Des(); |
|
2034 // INFO_PRINTF2(_L("Frame comments : %S\n"), &theBufPtr); |
|
2035 // |
|
2036 // delete theBuf; |
|
2037 // theBuf = NULL; |
|
2038 |
|
2039 TInt imageComments = theImageDecoder->NumberOfImageComments(); |
|
2040 INFO_PRINTF2(_L("Number of image comments : %d"), imageComments); |
|
2041 |
|
2042 HBufC* theBuf = theImageDecoder->ImageCommentL(0); |
|
2043 TPtr theBufPtr = theBuf->Des(); |
|
2044 INFO_PRINTF2(_L("Image comments : %S\n"), &theBufPtr); |
|
2045 |
|
2046 delete theBuf; |
|
2047 theBuf = NULL; |
|
2048 |
|
2049 |
|
2050 INFO_PRINTF1(_L("Call function FrameInfoStringsL\n")); |
|
2051 CFrameInfoStrings* theStr = theImageDecoder->FrameInfoStringsL(0); |
|
2052 |
|
2053 TInt index; |
|
2054 for(index = 0; index < theStr->Count(); index++) |
|
2055 { |
|
2056 const TPtrC str = theStr->String(index); |
|
2057 INFO_PRINTF3(_L("String # %d : %S"), |
|
2058 index, &str); |
|
2059 } |
|
2060 delete theStr; |
|
2061 theStr = NULL; |
|
2062 |
|
2063 INFO_PRINTF1(_L("Call function FrameInfoStringsLC")); |
|
2064 CFrameInfoStrings* theStr1 = theImageDecoder->FrameInfoStringsLC(0); |
|
2065 for(index = 0; index < theStr1->Count(); index++) |
|
2066 { |
|
2067 const TPtrC str = theStr1->String(index); |
|
2068 INFO_PRINTF3(_L("String # %d : %S"), |
|
2069 index, &str); |
|
2070 } |
|
2071 |
|
2072 CleanupStack::Pop(); |
|
2073 delete theStr1; |
|
2074 |
|
2075 TInt theFrameNumber = 0; |
|
2076 TUid theImageType; |
|
2077 TUid theImageSubType; |
|
2078 |
|
2079 theImageDecoder->ImageType(theFrameNumber, theImageType, theImageSubType); |
|
2080 INFO_PRINTF5(_L("Image type Uid: %d (expected %d), Image sub type Uid %d (expected %d)"), |
|
2081 theImageType, KImageTypeTestUid, theImageSubType, |
|
2082 KImageSubTypeTestUid); |
|
2083 |
|
2084 CleanupStack::PopAndDestroy(theImageDecoder); |
|
2085 iFs.Close(); |
|
2086 |
|
2087 return theRes; |
|
2088 } |
|
2089 |
|
2090 // dummy Hal call for heap balance on target |
|
2091 // Need to do this BEFORE doing any allocation testing ! |
|
2092 TInt CTestStepConversion::DummyHalCall() |
|
2093 { |
|
2094 TInt err1 = FbsStartup(); |
|
2095 if (err1 != KErrNone) |
|
2096 { |
|
2097 INFO_PRINTF2(_L("FbsStartup failed, err = %d"), err1); |
|
2098 return EInconclusive; |
|
2099 } |
|
2100 |
|
2101 err1 = RFbsSession::Connect(); |
|
2102 if (err1 != KErrNone) |
|
2103 { |
|
2104 INFO_PRINTF2(_L("RFbsSession::Connect() failed, err = %d"), err1); |
|
2105 return EInconclusive; |
|
2106 } |
|
2107 |
|
2108 TInt displayMode = EColor256; |
|
2109 CFbsScreenDevice* screenDevice = NULL; |
|
2110 TInt err; |
|
2111 while(displayMode < EColorLast) |
|
2112 { |
|
2113 TRAP(err, screenDevice = CFbsScreenDevice::NewL(_L("NotUsed"),(TDisplayMode)displayMode)); |
|
2114 delete screenDevice; |
|
2115 screenDevice = NULL; |
|
2116 if(err == KErrNone) |
|
2117 { |
|
2118 break; |
|
2119 } |
|
2120 displayMode++; |
|
2121 } |
|
2122 |
|
2123 RFbsSession::Disconnect(); |
|
2124 if (err != KErrNone) |
|
2125 { |
|
2126 INFO_PRINTF2(_L("Unable to create CFbsScreenDevice, err = %d"), err); |
|
2127 } |
|
2128 return err; |
|
2129 } |
|
2130 |
|
2131 //MS3.4 File Handles// |
|
2132 /* |
|
2133 * |
|
2134 * Decode a Bitmap, supplied a Decoder Object |
|
2135 * After encoding load file into a flat buffer and do bitwise compare |
|
2136 * |
|
2137 * @param "CImageDecoder& aImageDecoder" |
|
2138 * "TDesC& aFileName" |
|
2139 * |
|
2140 * @return "TInt" |
|
2141 * error |
|
2142 */ |
|
2143 TInt CTestStepConversion::DecodeUsingDecoderL(const TDesC& aFileName) |
|
2144 { |
|
2145 TInt theRes = KErrNone; |
|
2146 |
|
2147 if(iImageDecoder == NULL) |
|
2148 { |
|
2149 return KErrUnknown; |
|
2150 } |
|
2151 |
|
2152 //[ Create an active Listener and push it on the cleanup stack ] |
|
2153 CActiveListener* activeListener = new(ELeave)CActiveListener; |
|
2154 CleanupStack::PushL( activeListener ); |
|
2155 |
|
2156 //[ Create a destination Bitmap ] |
|
2157 CFbsBitmap* theDestination = new(ELeave) CFbsBitmap; |
|
2158 CleanupStack::PushL(theDestination); |
|
2159 |
|
2160 const TFrameInfo* theFrameInfo = &iImageDecoder->FrameInfo(); |
|
2161 User::LeaveIfError(theDestination->Create(theFrameInfo->iOverallSizeInPixels, theFrameInfo->iFrameDisplayMode));//EColor256));// |
|
2162 |
|
2163 //[ Convert Method of the Decoder ] |
|
2164 activeListener->InitialiseActiveListener(); |
|
2165 iImageDecoder->Convert(&activeListener->iStatus, *theDestination, 0); |
|
2166 |
|
2167 CActiveScheduler::Start(); |
|
2168 theRes = activeListener->iStatus.Int(); |
|
2169 |
|
2170 if(theRes == KErrNone) |
|
2171 { |
|
2172 INFO_PRINTF2(_L("Decoding of file %S was successful"), &aFileName); |
|
2173 } |
|
2174 else |
|
2175 { |
|
2176 INFO_PRINTF2(_L("Failed to Decode the file : %S"), &aFileName); |
|
2177 } |
|
2178 |
|
2179 //[ Checking with Reference Bitmaps at the end ] |
|
2180 TFileName theReferenceFilename; |
|
2181 TBuf<KLenBufferExtension> theExtension; |
|
2182 |
|
2183 Directory(EReference, theReferenceFilename); |
|
2184 TInt theSeparatorPos = aFileName.LocateReverse('.') + 1; |
|
2185 theReferenceFilename.Append(aFileName.Left(theSeparatorPos)); |
|
2186 GetImageExtension(KImageTypeMBMUid, theExtension); |
|
2187 theReferenceFilename.Append(theExtension); |
|
2188 |
|
2189 if(theRes == KErrNone) |
|
2190 { |
|
2191 theRes = CheckBitmapL(*theDestination, theReferenceFilename); |
|
2192 } |
|
2193 theDestination->Reset(); |
|
2194 CleanupStack::PopAndDestroy(2,activeListener); // theDestination,CActiveListener |
|
2195 |
|
2196 return theRes; |
|
2197 } |
|
2198 |
|
2199 /* |
|
2200 * |
|
2201 * Read and encode image from bitmap to file |
|
2202 * After encoding load file into a flat buffer and do bitwise compare |
|
2203 * |
|
2204 * @param "const TDesC& aFileName" |
|
2205 * "TUid aTypeImage" |
|
2206 * |
|
2207 */ |
|
2208 void CTestStepConversion::EncodeUsingEncoderL(const TDesC& aFileNameSrc) |
|
2209 { |
|
2210 TInt theRes = KErrNone; |
|
2211 |
|
2212 if(iImageEncoder == NULL) |
|
2213 { |
|
2214 User::Leave(KErrUnknown); |
|
2215 } |
|
2216 |
|
2217 //[ Open the Source Bitmap ] |
|
2218 TFileName theSourceFile; |
|
2219 Directory(EReference, theSourceFile); |
|
2220 theSourceFile.Append(aFileNameSrc); |
|
2221 |
|
2222 CFbsBitmap *theBitmap = new(ELeave) CFbsBitmap; |
|
2223 CleanupStack::PushL(theBitmap); |
|
2224 |
|
2225 theRes = theBitmap->Load(theSourceFile); |
|
2226 |
|
2227 if(theRes != KErrNone) |
|
2228 { |
|
2229 ERR_PRINTF2(_L("File %S cannot be loaded." ), &theSourceFile); |
|
2230 User::Leave(theRes); |
|
2231 } |
|
2232 |
|
2233 //[ Prepare Encode Data ] |
|
2234 TConvertInfo theConvInfo; |
|
2235 theConvInfo.iImageTypeId = iImageTypeUid; |
|
2236 theConvInfo.iDisplayMode = theBitmap->DisplayMode(); |
|
2237 |
|
2238 TImageDataBlock* imageData = NULL; |
|
2239 TFrameDataBlock* frameData = NULL; |
|
2240 |
|
2241 CFrameImageData* theFrameImageData = CFrameImageData::NewL(); |
|
2242 CleanupStack::PushL(theFrameImageData); |
|
2243 |
|
2244 theRes = PrepareEncodeDataL(theConvInfo, &imageData, &frameData); |
|
2245 // |
|
2246 if(imageData) |
|
2247 { |
|
2248 CleanupStack::PushL(imageData); |
|
2249 User::LeaveIfError(theFrameImageData->AppendImageData(imageData)); |
|
2250 CleanupStack::Pop(imageData); |
|
2251 } |
|
2252 if(frameData) |
|
2253 { |
|
2254 CleanupStack::PushL(frameData); |
|
2255 User::LeaveIfError(theFrameImageData->AppendFrameData(frameData)); |
|
2256 CleanupStack::Pop(frameData); |
|
2257 } |
|
2258 |
|
2259 //[ Create an active Listener and push it on the cleanup stack ] |
|
2260 CActiveListener* activeListener = new(ELeave)CActiveListener; |
|
2261 CleanupStack::PushL( activeListener ); |
|
2262 |
|
2263 iActiveScheduler->SetEncoder(iImageEncoder, activeListener, 0); |
|
2264 iActiveScheduler->SetStep(this); |
|
2265 |
|
2266 //[ Convert Method of the Encoder ] |
|
2267 activeListener->InitialiseActiveListener(); |
|
2268 iImageEncoder->Convert(&activeListener->iStatus, *theBitmap, theFrameImageData); |
|
2269 CActiveScheduler::Start(); |
|
2270 theRes = activeListener->iStatus.Int(); |
|
2271 iActiveScheduler->SetStep(NULL); |
|
2272 |
|
2273 if(theRes == KErrNone) |
|
2274 { |
|
2275 INFO_PRINTF2(_L("Encoding of file %S was successful"), &aFileNameSrc); |
|
2276 } |
|
2277 else |
|
2278 { |
|
2279 INFO_PRINTF2(_L("Failed to Encode the file : %S"), &aFileNameSrc); |
|
2280 User::Leave(theRes); |
|
2281 } |
|
2282 |
|
2283 //[ Compare two files into a flat buffer ] |
|
2284 TFileName theDestinationFileName; |
|
2285 TBuf<KLenBuffer> theExtension; |
|
2286 |
|
2287 Directory(EOutput, theDestinationFileName); |
|
2288 theDestinationFileName.Append(aFileNameSrc.Left(aFileNameSrc.Length()-3)); |
|
2289 GetImageExtension(iImageTypeUid, theExtension); |
|
2290 theDestinationFileName.Append(theExtension); |
|
2291 |
|
2292 iFile.Close(); //- As a precaution. |
|
2293 |
|
2294 TInt fileSize; |
|
2295 theRes = iFile.Open(iFs, theDestinationFileName, EFileWrite); |
|
2296 if(theRes != KErrNone) |
|
2297 { |
|
2298 INFO_PRINTF2(_L("Cannot open file: %S to Compare"), &theDestinationFileName); |
|
2299 User::Leave(theRes); |
|
2300 } |
|
2301 iFile.Size(fileSize); |
|
2302 HBufC8 *theCreatedImage = HBufC8::NewMaxLC(fileSize); |
|
2303 |
|
2304 TPtr8 imageFromFilePtr = theCreatedImage->Des(); |
|
2305 iFile.Read(imageFromFilePtr); |
|
2306 |
|
2307 iFile.Close(); |
|
2308 |
|
2309 //[ Call the CompareFileL Function ] |
|
2310 theRes = CompareFileL(aFileNameSrc, theCreatedImage, iImageTypeUid, EInput); |
|
2311 User::LeaveIfError(theRes); |
|
2312 //[ Delete the Local Objects ] |
|
2313 CleanupStack::PopAndDestroy(4,theBitmap); //CActiveListener |
|
2314 } |
|
2315 |