00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00023 #include "iclexample.h"
00024 #include <imageprocessor/imageprocessor.h>
00025 #include <imageprocessor/imageprocessorobserver.h>
00026 #include <imageprocessor/imageprocessorinputinfo.h>
00027 #include <imageprocessor/imageprocessoroutputinfo.h>
00028 #include <imageprocessor/imageprocessoroverlay.h>
00029 #include <imageprocessor/imageprocessorpreview.h>
00030 #include <imageprocessor/imageprocessoreffect.h>
00031 #include <imageprocessor/imageprocessorprogressinfo.h>
00032 #include <capsimageprocessor/capsimageprocessorextension.h>
00033
00034 using namespace ImageProcessor;
00035
00040 class CImgProcessorObserverStub: public ImageProcessor::MImgProcessorObserver
00041 {
00042 public:
00043 CImgProcessorObserverStub(CConsoleBase& aConsole) : iConsole(aConsole),
00044 iNumberOfDots(0), iCurrentIteration(0), iNumberOfIterations(0) {}
00045
00046 public:
00047 void ImageProcessorInitializingComplete(ImageProcessor::CImgProcessor& , TInt aError)
00048 {
00049 iConsole.Printf(_L("\nImageProcessorInitializingComplete, aError = %d\n"), aError);
00050 iCurrentIteration = 0;
00051 iNumberOfIterations = 0;
00052 iNumberOfDots = 0;
00053 CActiveScheduler::Stop();
00054 }
00055
00056 void ImageProcessorPreviewInitializingComplete(ImageProcessor::CImgProcessor& , TInt aPreviewId, TInt aError)
00057 {
00058 iConsole.Printf(_L("\nImageProcessorPreviewInitializingComplete, aPreviewId = %d, aError = %d\n"), aPreviewId, aError);
00059 iCurrentIteration = 0;
00060 iNumberOfIterations = 0;
00061 iNumberOfDots = 0;
00062 CActiveScheduler::Stop();
00063 }
00064
00065 void ImageProcessingComplete(ImageProcessor::CImgProcessor& , TInt aError)
00066 {
00067 iConsole.Printf(_L("\nImageProcessingComplete, aError = %d\n"), aError);
00068 iCurrentIteration = 0;
00069 iNumberOfIterations = 0;
00070 iNumberOfDots = 0;
00071 CActiveScheduler::Stop();
00072 }
00073
00074 void ImageProcessorPreviewRenderingComplete(ImageProcessor::CImgProcessor& , TInt aPreviewId, TInt aError)
00075 {
00076 iConsole.Printf(_L("\nImageProcessorPreviewRenderingComplete, aPreviewId=%d, aError=%d\n"), aPreviewId, aError);
00077 iCurrentIteration = 0;
00078 iNumberOfIterations = 0;
00079 iNumberOfDots = 0;
00080 CActiveScheduler::Stop();
00081 }
00082
00083 void ImageProcessorEvent(ImageProcessor::CImgProcessor& aImageProcessor, TInt , TUid , TInt )
00084 {
00085
00086
00087
00088
00089 TProgressInfo* progressInfo = NULL;
00090
00091
00092 TInt err = KErrNone;
00093 TRAP(err, progressInfo = aImageProcessor.ProgressInfoL());
00094
00095
00096 if (iNumberOfIterations == 0)
00097 {
00098 TRAP(err, iNumberOfIterations = progressInfo->NumberOfIterationsL());
00099 }
00100
00101
00102 TRAP(err, iCurrentIteration = progressInfo->CurrentIterationL());
00103
00104 if (err == KErrNone)
00105 {
00106
00107 if (10 * iCurrentIteration > iNumberOfDots * iNumberOfIterations)
00108 {
00109 iNumberOfDots++;
00110 iConsole.Printf(_L("."));
00111 }
00112 }
00113
00114 }
00115 private:
00116 CConsoleBase& iConsole;
00117 TInt iNumberOfDots;
00118 TInt iCurrentIteration;
00119 TInt iNumberOfIterations;
00120 };
00121
00125 void CIclExample::BasicImageProcessingL()
00126 {
00127 CImgProcessorObserverStub observer(*iConsole);
00128 ImageProcessor::CImgProcessor* imageProcessor = ImageProcessor::CImgProcessor::NewL(iFs, observer);
00129 CleanupStack::PushL(imageProcessor);
00130
00131
00132
00133 imageProcessor->InitializeL();
00134
00135
00136 CActiveScheduler::Start();
00137
00138
00139 imageProcessor->SetInputL(KInputFileName, KImageTypeJPGUid);
00140 imageProcessor->SetOutputL(KOutputFileName, KImageTypeJPGUid);
00141
00142
00143 TOutputInfo* outputInfo = imageProcessor->OutputInfoL();
00144
00145
00146
00147 TReal32 quality = 0.75f;
00148 outputInfo->SetJpegQualityL(quality);
00149
00150
00151
00152 imageProcessor->ProcessL(TSize(320, 240), ETrue);
00153
00154
00155 CActiveScheduler::Start();
00156
00157 CleanupStack::PopAndDestroy(imageProcessor);
00158 }
00159
00164 void CIclExample::BasicEffectImageProcessingL()
00165 {
00166 CImgProcessorObserverStub observer(*iConsole);
00167 ImageProcessor::CImgProcessor* imageProcessor = ImageProcessor::CImgProcessor::NewL(iFs, observer);
00168 CleanupStack::PushL(imageProcessor);
00169
00170
00171 imageProcessor->InitializeL();
00172
00173
00174 CActiveScheduler::Start();
00175
00176 imageProcessor->SetInputL(KInputFileName, KImageTypeJPGUid);
00177 imageProcessor->SetOutputL(KOutputWithBasicEffectFileName, KImageTypeJPGUid);
00178
00179
00180 TOutputInfo* outputInfo = imageProcessor->OutputInfoL();
00181
00182
00183
00184 TReal32 quality = 0.75f;
00185 outputInfo->SetJpegQualityL(quality);
00186
00187
00188 TInputInfo* inputInfo = imageProcessor->InputInfoL();
00189 TSize inputSize = inputInfo->SizeL();
00190
00191
00192 TRect cropRegion(inputSize.iWidth/4, inputSize.iHeight/4, inputSize.iWidth/2, inputSize.iHeight/2);
00193
00194
00195 imageProcessor->SetInputRectL(cropRegion);
00196
00197
00198
00199
00200 TEffect* effect = imageProcessor->EffectL(KEffectMirrorLeftToRightUid);
00201
00202
00203
00204 effect->BeginL();
00205 effect->EndL();
00206
00207
00208 TGeometricalOperation* operation = static_cast<TGeometricalOperation*>(imageProcessor->EffectL(KGeometricalOperationUid));
00209 operation->BeginL();
00210 operation->SetOperationL(ImageProcessor::CImgProcessor::EOperationRotate270);
00211 operation->EndL();
00212
00213
00214
00215
00216
00217 imageProcessor->ProcessL();
00218
00219
00220 CActiveScheduler::Start();
00221
00222 CleanupStack::PopAndDestroy(imageProcessor);
00223 }
00224
00228 void CIclExample::EffectImageProcessingWithUndoL()
00229 {
00230 CImgProcessorObserverStub observer(*iConsole);
00231 ImageProcessor::CImgProcessor* imageProcessor = ImageProcessor::CImgProcessor::NewL(iFs, observer);
00232 CleanupStack::PushL(imageProcessor);
00233
00234
00235
00236 imageProcessor->InitializeL();
00237
00238
00239 CActiveScheduler::Start();
00240
00241 imageProcessor->SetInputL(KInputFileName, KImageTypeJPGUid);
00242 imageProcessor->SetOutputL(KOutputWithUndoFileName, KImageTypeJPGUid);
00243
00244
00245 TOutputInfo* outputInfo = imageProcessor->OutputInfoL();
00246
00247
00248
00249 TReal32 quality = 0.75f;
00250 outputInfo->SetJpegQualityL(quality);
00251
00252
00253 TEffectRotation* rotationEffect = static_cast<TEffectRotation*>(imageProcessor->EffectL(KEffectRotationUid));
00254 rotationEffect->BeginL();
00255 rotationEffect->SetRotationL(ImageProcessor::TEffectRotation::ERotationScaleModeFitInside, 45.0f);
00256 rotationEffect->EndL();
00257
00258
00259 if (imageProcessor->CanUndoL())
00260 {
00261
00262 imageProcessor->UndoL();
00263 }
00264
00265
00266 imageProcessor->ProcessL();
00267
00268
00269 CActiveScheduler::Start();
00270
00271
00272 CleanupStack::PopAndDestroy(imageProcessor);
00273 }
00274
00278 void CIclExample::EffectImageProcessingWithPreviewL()
00279 {
00280 CImgProcessorObserverStub observer(*iConsole);
00281 ImageProcessor::CImgProcessor* imageProcessor = ImageProcessor::CImgProcessor::NewL(iFs, observer);
00282 CleanupStack::PushL(imageProcessor);
00283
00284
00285
00286 imageProcessor->InitializeL();
00287
00288
00289 CActiveScheduler::Start();
00290
00291
00292 const TDesC* filenames[4] =
00293 {
00294 &KInputFileName01,
00295 &KInputFileName02,
00296 &KInputFileName03,
00297 &KInputFileName04
00298 };
00299
00300
00301 const TDesC* bitmapsnames[4] =
00302 {
00303 &KOutputBitmapFileName01,
00304 &KOutputBitmapFileName02,
00305 &KOutputBitmapFileName03,
00306 &KOutputBitmapFileName04
00307 };
00308
00309
00310
00311 CFbsBitmap* previewBitmap = new (ELeave) CFbsBitmap();
00312 previewBitmap->Create(TSize(320,240), EColor64K);
00313
00314 CleanupStack::PushL(previewBitmap);
00315
00316
00317 const TInt previewId = 1;
00318
00319
00320 TPreview* preview = imageProcessor->PreviewL(previewId);
00321
00322
00323
00324
00325
00326 imageProcessor->SetOptionsL(ImageProcessor::CImgProcessor::EOptionSyncProcessing);
00327
00328
00329 imageProcessor->CreateInputL(TSize(320, 240), TRgb(0, 0, 0));
00330
00331
00332 preview->InitializeL();
00333
00334
00335 preview->SetOutputL(*previewBitmap);
00336
00337
00338 TEffect* effect=imageProcessor->EffectL(KEffectSharpnessUid);
00339
00340
00341 effect->BeginL();
00342 effect->EndL();
00343
00344
00345 effect = imageProcessor->EffectL(KEffectColorBoostUid);
00346
00347
00348 effect->BeginL();
00349 effect->EndL();
00350
00351
00352 effect = imageProcessor->EffectL(KEffectWhiteBalanceUid);
00353
00354
00355 effect->BeginL();
00356 effect->EndL();
00357
00358
00359 for (TInt i = 0; i < 4; i++)
00360 {
00361 imageProcessor->SetInputL(*filenames[i]);
00362 preview->RenderL();
00363
00364
00365
00366 previewBitmap->Save(*bitmapsnames[i]);
00367 }
00368
00369 CleanupStack::PopAndDestroy(2,imageProcessor);
00370 }
00371
00376 void CIclExample::EffectImageProcessingWithOverlayL()
00377 {
00378 CImgProcessorObserverStub observer(*iConsole);
00379 ImageProcessor::CImgProcessor* imageProcessor = ImageProcessor::CImgProcessor::NewL(iFs, observer);
00380 CleanupStack::PushL(imageProcessor);
00381
00382
00383
00384 imageProcessor->InitializeL();
00385
00386
00387 CActiveScheduler::Start();
00388
00389
00390 imageProcessor->SetInputL(KInputFileName, KImageTypeJPGUid);
00391 imageProcessor->SetOutputL(KOutputWithOverlayFileName, KImageTypeJPGUid);
00392
00393
00394 CFbsBitmap* previewBitmap = new (ELeave) CFbsBitmap();
00395 previewBitmap->Create(TSize(320,240), EColor64K);
00396
00397 CleanupStack::PushL(previewBitmap);
00398
00399
00400 const TInt previewId = 1;
00401
00402
00403 TPreview* preview = imageProcessor->PreviewL(previewId);
00404
00405
00406
00407
00408 imageProcessor->SetOptionsL(ImageProcessor::CImgProcessor::EOptionSyncProcessing);
00409
00410
00411 preview->InitializeL();
00412
00413
00414 preview->SetOutputL(*previewBitmap);
00415
00416
00417 preview->RenderL();
00418
00419 TPoint overlayPosition(0,0);
00420
00421
00422 TRect canvasArea = preview->CanvasAreaL();
00423
00424
00425 overlayPosition.iX = (canvasArea.iBr.iX - canvasArea.iTl.iX) / 2;
00426 overlayPosition.iY = (canvasArea.iBr.iY - canvasArea.iTl.iY) / 2;
00427
00428
00429 TPoint tmp(0, 0);
00430 preview->CanvasToCurrentCoordL(overlayPosition, tmp);
00431 overlayPosition = tmp;
00432
00433
00434 TOverlay* overlay = imageProcessor->OverlayL();
00435
00436
00437 overlay->SetInputL(KInputOverlayFileName, KImageTypePNGUid);
00438 overlay->BeginL();
00439
00440
00441 overlay->SetL(1.0f, 1.0f, overlayPosition, 0.0f);
00442
00443
00444 preview->RenderL();
00445
00446 previewBitmap->Save(KOutputBitmapFileName01);
00447
00448
00449
00450
00451
00452 TReal32 overlayScaleX = 0.0f;
00453 TReal32 overlayScaleY = 0.0f;
00454 overlay->GetScaleL(overlayScaleX, overlayScaleY);
00455
00456 overlayScaleX *= 2.0f;
00457 overlayScaleY *= 2.0f;
00458
00459 TReal32 overlayAngle = overlay->AngleL();
00460
00461
00462 overlayAngle += 45.0f;
00463 if (overlayAngle >= 360.0f)
00464 {
00465 overlayAngle = overlayAngle - 360.0f;
00466 }
00467
00468
00469 overlayPosition = overlay->PositionL();
00470 overlayPosition.iY += 10;
00471
00472
00473 overlay->SetL(overlayScaleX, overlayScaleY, overlayPosition, overlayAngle);
00474
00475
00476 overlay->EndL();
00477
00478 preview->RenderL();
00479
00480
00481 previewBitmap->Save(KOutputBitmapFileName02);
00482
00483
00484 imageProcessor->SetOptionsL(imageProcessor->Options() ^ ImageProcessor::CImgProcessor::EOptionSyncProcessing);
00485
00486
00487 imageProcessor->ProcessL();
00488
00489
00490 CActiveScheduler::Start();
00491
00492 CleanupStack::PopAndDestroy(2,imageProcessor);
00493 }
00494
00501 void CIclExample::ImageProcessingWithSpmoL()
00502 {
00503 CImgProcessorObserverStub observer(*iConsole);
00504 ImageProcessor::CImgProcessor* imageProcessor = ImageProcessor::CImgProcessor::NewL(iFs, observer);
00505 CleanupStack::PushL(imageProcessor);
00506
00507
00508
00509 imageProcessor->InitializeL();
00510
00511
00512 CActiveScheduler::Start();
00513
00514
00515 imageProcessor->SetInputL(KInputFileName, KImageTypeJPGUid);
00516 imageProcessor->SetOutputL(KOutputWithSpmoFileName, KImageTypeJPGUid);
00517
00518
00519 imageProcessor->SetOptionsL(ImageProcessor::CImgProcessor::EOptionExifMetadataProcessing);
00520
00521
00522 TCapsImageProcessorExtension* extension = static_cast<TCapsImageProcessorExtension*>(imageProcessor->Extension(KCapsImageProcessorExtensionUid));
00523
00524
00525
00526 extension->SetAddSpmoToOutputL(ETrue, TSize(320, 240));
00527
00528
00529
00530
00531 imageProcessor->ProcessL();
00532
00533
00534 CActiveScheduler::Start();
00535
00536 CleanupStack::PopAndDestroy(imageProcessor);
00537 }
00538