Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/iclimageprocessorexample_8cpp-source.html
Week 12 contribution of SDK documentation_content. See release notes for details. Fixes Bug 1892, Bug 1522, Bug 1520, Bug 394, Bug 1319, Bug 344, Bug 1897
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>TB10.1 Example Applications: examples/Multimedia/ICL/ICLExample/iclimageprocessorexample.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.3 -->
<h1>examples/Multimedia/ICL/ICLExample/iclimageprocessorexample.cpp</h1><a href="iclimageprocessorexample_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).</span>
<a name="l00002"></a>00002 <span class="comment">// All rights reserved.</span>
<a name="l00003"></a>00003 <span class="comment">// This component and the accompanying materials are made available</span>
<a name="l00004"></a>00004 <span class="comment">// under the terms of "Eclipse Public License v1.0"</span>
<a name="l00005"></a>00005 <span class="comment">// which accompanies this distribution, and is available</span>
<a name="l00006"></a>00006 <span class="comment">// at the URL "http://www.eclipse.org/legal/epl-v10.html".</span>
<a name="l00007"></a>00007 <span class="comment">//</span>
<a name="l00008"></a>00008 <span class="comment">// Initial Contributors:</span>
<a name="l00009"></a>00009 <span class="comment">// Nokia Corporation - initial contribution.</span>
<a name="l00010"></a>00010 <span class="comment">//</span>
<a name="l00011"></a>00011 <span class="comment">// Contributors:</span>
<a name="l00012"></a>00012 <span class="comment">//</span>
<a name="l00013"></a>00013 <span class="comment">// Description:</span>
<a name="l00014"></a>00014 <span class="comment">// The code demonstrates Image Processor functionality</span>
<a name="l00015"></a>00015 <span class="comment">//</span>
<a name="l00016"></a>00016
<a name="l00017"></a>00017
<a name="l00018"></a>00018
<a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="iclexample_8h.html">iclexample.h</a>"</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include <imageprocessor/imageprocessor.h></span>
<a name="l00025"></a>00025 <span class="preprocessor">#include <imageprocessor/imageprocessorobserver.h></span>
<a name="l00026"></a>00026 <span class="preprocessor">#include <imageprocessor/imageprocessorinputinfo.h></span>
<a name="l00027"></a>00027 <span class="preprocessor">#include <imageprocessor/imageprocessoroutputinfo.h></span>
<a name="l00028"></a>00028 <span class="preprocessor">#include <imageprocessor/imageprocessoroverlay.h></span>
<a name="l00029"></a>00029 <span class="preprocessor">#include <imageprocessor/imageprocessorpreview.h></span>
<a name="l00030"></a>00030 <span class="preprocessor">#include <imageprocessor/imageprocessoreffect.h></span>
<a name="l00031"></a>00031 <span class="preprocessor">#include <imageprocessor/imageprocessorprogressinfo.h></span>
<a name="l00032"></a>00032 <span class="preprocessor">#include <capsimageprocessor/capsimageprocessorextension.h></span>
<a name="l00033"></a>00033
<a name="l00034"></a>00034 <span class="keyword">using namespace </span>ImageProcessor;
<a name="l00035"></a>00035
<a name="l00040"></a>00040 <span class="keyword">class </span>CImgProcessorObserverStub: <span class="keyword">public</span> ImageProcessor::MImgProcessorObserver
<a name="l00041"></a>00041 {
<a name="l00042"></a>00042 <span class="keyword">public</span>:
<a name="l00043"></a>00043 CImgProcessorObserverStub(CConsoleBase& aConsole) : iConsole(aConsole),
<a name="l00044"></a>00044 iNumberOfDots(0), iCurrentIteration(0), iNumberOfIterations(0) {}
<a name="l00045"></a>00045
<a name="l00046"></a>00046 <span class="keyword">public</span>:
<a name="l00047"></a>00047 <span class="keywordtype">void</span> ImageProcessorInitializingComplete(ImageProcessor::CImgProcessor& <span class="comment">/*aImageProcessor*/</span>, TInt aError)
<a name="l00048"></a>00048 {
<a name="l00049"></a>00049 iConsole.Printf(_L(<span class="stringliteral">"\nImageProcessorInitializingComplete, aError = %d\n"</span>), aError);
<a name="l00050"></a>00050 iCurrentIteration = 0;
<a name="l00051"></a>00051 iNumberOfIterations = 0;
<a name="l00052"></a>00052 iNumberOfDots = 0;
<a name="l00053"></a>00053 CActiveScheduler::Stop();
<a name="l00054"></a>00054 }
<a name="l00055"></a>00055
<a name="l00056"></a>00056 <span class="keywordtype">void</span> ImageProcessorPreviewInitializingComplete(ImageProcessor::CImgProcessor& <span class="comment">/*aImageProcessor*/</span>, TInt aPreviewId, TInt aError)
<a name="l00057"></a>00057 {
<a name="l00058"></a>00058 iConsole.Printf(_L(<span class="stringliteral">"\nImageProcessorPreviewInitializingComplete, aPreviewId = %d, aError = %d\n"</span>), aPreviewId, aError);
<a name="l00059"></a>00059 iCurrentIteration = 0;
<a name="l00060"></a>00060 iNumberOfIterations = 0;
<a name="l00061"></a>00061 iNumberOfDots = 0;
<a name="l00062"></a>00062 CActiveScheduler::Stop();
<a name="l00063"></a>00063 }
<a name="l00064"></a>00064
<a name="l00065"></a>00065 <span class="keywordtype">void</span> ImageProcessingComplete(ImageProcessor::CImgProcessor& <span class="comment">/*aImageProcessor*/</span>, TInt aError)
<a name="l00066"></a>00066 {
<a name="l00067"></a>00067 iConsole.Printf(_L(<span class="stringliteral">"\nImageProcessingComplete, aError = %d\n"</span>), aError);
<a name="l00068"></a>00068 iCurrentIteration = 0;
<a name="l00069"></a>00069 iNumberOfIterations = 0;
<a name="l00070"></a>00070 iNumberOfDots = 0;
<a name="l00071"></a>00071 CActiveScheduler::Stop();
<a name="l00072"></a>00072 }
<a name="l00073"></a>00073
<a name="l00074"></a>00074 <span class="keywordtype">void</span> ImageProcessorPreviewRenderingComplete(ImageProcessor::CImgProcessor& <span class="comment">/*aImageProcessor*/</span>, TInt aPreviewId, TInt aError)
<a name="l00075"></a>00075 {
<a name="l00076"></a>00076 iConsole.Printf(_L(<span class="stringliteral">"\nImageProcessorPreviewRenderingComplete, aPreviewId=%d, aError=%d\n"</span>), aPreviewId, aError);
<a name="l00077"></a>00077 iCurrentIteration = 0;
<a name="l00078"></a>00078 iNumberOfIterations = 0;
<a name="l00079"></a>00079 iNumberOfDots = 0;
<a name="l00080"></a>00080 CActiveScheduler::Stop();
<a name="l00081"></a>00081 }
<a name="l00082"></a>00082
<a name="l00083"></a>00083 <span class="keywordtype">void</span> ImageProcessorEvent(ImageProcessor::CImgProcessor& aImageProcessor, TInt <span class="comment">/*aEventId*/</span>, TUid <span class="comment">/*aUid*/</span>, TInt <span class="comment">/*aId*/</span>)
<a name="l00084"></a>00084 {
<a name="l00085"></a>00085 <span class="comment">// We try to emulate a progress bar by printing out </span>
<a name="l00086"></a>00086 <span class="comment">// a dot per one tenth of all iterations completed. </span>
<a name="l00087"></a>00087 <span class="comment">// So ten dots are printed out when the processing is finished.</span>
<a name="l00088"></a>00088
<a name="l00089"></a>00089 TProgressInfo* progressInfo = NULL;
<a name="l00090"></a>00090
<a name="l00091"></a>00091 <span class="comment">// Get TProgressInfo interface to get progress information</span>
<a name="l00092"></a>00092 TInt err = KErrNone;
<a name="l00093"></a>00093 TRAP(err, progressInfo = aImageProcessor.ProgressInfoL());
<a name="l00094"></a>00094
<a name="l00095"></a>00095 <span class="comment">// Get total number of iterations for the processing/rendering</span>
<a name="l00096"></a>00096 <span class="keywordflow">if</span> (iNumberOfIterations == 0)
<a name="l00097"></a>00097 {
<a name="l00098"></a>00098 TRAP(err, iNumberOfIterations = progressInfo->NumberOfIterationsL());
<a name="l00099"></a>00099 }
<a name="l00100"></a>00100
<a name="l00101"></a>00101 <span class="comment">// Get current iteration</span>
<a name="l00102"></a>00102 TRAP(err, iCurrentIteration = progressInfo->CurrentIterationL());
<a name="l00103"></a>00103
<a name="l00104"></a>00104 <span class="keywordflow">if</span> (err == KErrNone)
<a name="l00105"></a>00105 {
<a name="l00106"></a>00106 <span class="comment">// Print out another dot if next one tenth is processed</span>
<a name="l00107"></a>00107 <span class="keywordflow">if</span> (10 * iCurrentIteration > iNumberOfDots * iNumberOfIterations)
<a name="l00108"></a>00108 {
<a name="l00109"></a>00109 iNumberOfDots++;
<a name="l00110"></a>00110 iConsole.Printf(_L(<span class="stringliteral">"."</span>));
<a name="l00111"></a>00111 }
<a name="l00112"></a>00112 }
<a name="l00113"></a>00113
<a name="l00114"></a>00114 }
<a name="l00115"></a>00115 <span class="keyword">private</span>:
<a name="l00116"></a>00116 CConsoleBase& iConsole;
<a name="l00117"></a>00117 TInt iNumberOfDots;
<a name="l00118"></a>00118 TInt iCurrentIteration;
<a name="l00119"></a>00119 TInt iNumberOfIterations;
<a name="l00120"></a>00120 };
<a name="l00121"></a>00121
<a name="l00125"></a><a class="code" href="class_c_icl_example.html#16e34be3bbdf829cf58dba907e9bc53c">00125</a> <span class="keywordtype">void</span> <a class="code" href="class_c_icl_example.html#16e34be3bbdf829cf58dba907e9bc53c">CIclExample::BasicImageProcessingL</a>()
<a name="l00126"></a>00126 {
<a name="l00127"></a>00127 CImgProcessorObserverStub observer(*iConsole);
<a name="l00128"></a>00128 ImageProcessor::CImgProcessor* imageProcessor = ImageProcessor::CImgProcessor::NewL(iFs, observer);
<a name="l00129"></a>00129 CleanupStack::PushL(imageProcessor);
<a name="l00130"></a>00130
<a name="l00131"></a>00131 <span class="comment">// Initialize the Image Processor instance. By default the initialization is asynchronous.</span>
<a name="l00132"></a>00132 <span class="comment">// (It might take some time to load Image Processor plugin and initialize it).</span>
<a name="l00133"></a>00133 imageProcessor->InitializeL();
<a name="l00134"></a>00134
<a name="l00135"></a>00135 <span class="comment">// Wait for asynchronous callback</span>
<a name="l00136"></a>00136 CActiveScheduler::Start();
<a name="l00137"></a>00137
<a name="l00138"></a>00138 <span class="comment">// Set input and output images</span>
<a name="l00139"></a>00139 imageProcessor->SetInputL(KInputFileName, KImageTypeJPGUid);
<a name="l00140"></a>00140 imageProcessor->SetOutputL(KOutputFileName, KImageTypeJPGUid);
<a name="l00141"></a>00141
<a name="l00142"></a>00142 <span class="comment">// Get TOutputInfo interface</span>
<a name="l00143"></a>00143 TOutputInfo* outputInfo = imageProcessor->OutputInfoL();
<a name="l00144"></a>00144
<a name="l00145"></a>00145 <span class="comment">// Set 0.75 quality for the output image.</span>
<a name="l00146"></a>00146 <span class="comment">// (Note. Default quality value for the output image is the same as for the input image.)</span>
<a name="l00147"></a>00147 TReal32 quality = 0.75f;
<a name="l00148"></a>00148 outputInfo->SetJpegQualityL(quality);
<a name="l00149"></a>00149
<a name="l00150"></a>00150 <span class="comment">// Process the input image to the output image. </span>
<a name="l00151"></a>00151 <span class="comment">// The output image size is QVGA and the output image keeps the same aspect ratio as the input image. </span>
<a name="l00152"></a>00152 imageProcessor->ProcessL(TSize(320, 240), ETrue);
<a name="l00153"></a>00153
<a name="l00154"></a>00154 <span class="comment">// Wait for asynchronous callback</span>
<a name="l00155"></a>00155 CActiveScheduler::Start();
<a name="l00156"></a>00156
<a name="l00157"></a>00157 CleanupStack::PopAndDestroy(imageProcessor);
<a name="l00158"></a>00158 }
<a name="l00159"></a>00159
<a name="l00164"></a><a class="code" href="class_c_icl_example.html#2a279b168c7145fb92f6fe6fc534c0f1">00164</a> <span class="keywordtype">void</span> <a class="code" href="class_c_icl_example.html#2a279b168c7145fb92f6fe6fc534c0f1">CIclExample::BasicEffectImageProcessingL</a>()
<a name="l00165"></a>00165 {
<a name="l00166"></a>00166 CImgProcessorObserverStub observer(*iConsole);
<a name="l00167"></a>00167 ImageProcessor::CImgProcessor* imageProcessor = ImageProcessor::CImgProcessor::NewL(iFs, observer);
<a name="l00168"></a>00168 CleanupStack::PushL(imageProcessor);
<a name="l00169"></a>00169
<a name="l00170"></a>00170 <span class="comment">// Initialize the Image Processor instance. By default the initialization is asynchronous.</span>
<a name="l00171"></a>00171 imageProcessor->InitializeL();
<a name="l00172"></a>00172
<a name="l00173"></a>00173 <span class="comment">// Wait for asynchronous callback</span>
<a name="l00174"></a>00174 CActiveScheduler::Start();
<a name="l00175"></a>00175
<a name="l00176"></a>00176 imageProcessor->SetInputL(KInputFileName, KImageTypeJPGUid);
<a name="l00177"></a>00177 imageProcessor->SetOutputL(KOutputWithBasicEffectFileName, KImageTypeJPGUid);
<a name="l00178"></a>00178
<a name="l00179"></a>00179 <span class="comment">// The TOutputInfo interface is used to set quality and sampling scheme for JPEG output</span>
<a name="l00180"></a>00180 TOutputInfo* outputInfo = imageProcessor->OutputInfoL();
<a name="l00181"></a>00181
<a name="l00182"></a>00182 <span class="comment">// Set 0.75 quality for the output image.</span>
<a name="l00183"></a>00183 <span class="comment">// (Note. Default quality value for the output image is the same as for the input image.)</span>
<a name="l00184"></a>00184 TReal32 quality = 0.75f;
<a name="l00185"></a>00185 outputInfo->SetJpegQualityL(quality);
<a name="l00186"></a>00186
<a name="l00187"></a>00187 <span class="comment">// Get information about the input image</span>
<a name="l00188"></a>00188 TInputInfo* inputInfo = imageProcessor->InputInfoL();
<a name="l00189"></a>00189 TSize inputSize = inputInfo->SizeL();
<a name="l00190"></a>00190
<a name="l00191"></a>00191 <span class="comment">// Define crop region - eighth size</span>
<a name="l00192"></a>00192 TRect cropRegion(inputSize.iWidth/4, inputSize.iHeight/4, inputSize.iWidth/2, inputSize.iHeight/2);
<a name="l00193"></a>00193
<a name="l00194"></a>00194 <span class="comment">// Apply crop gives a quarter size image</span>
<a name="l00195"></a>00195 imageProcessor->SetInputRectL(cropRegion);
<a name="l00196"></a>00196
<a name="l00197"></a>00197 <span class="comment">// Get TEffect interface for Mirror Left To Right effect. </span>
<a name="l00198"></a>00198 <span class="comment">// Note. All effects can be handled via generic TEffect interface. For more advanced functionality</span>
<a name="l00199"></a>00199 <span class="comment">// the interface pointer must be cast to a derived effect interface.</span>
<a name="l00200"></a>00200 TEffect* effect = imageProcessor->EffectL(KEffectMirrorLeftToRightUid);
<a name="l00201"></a>00201
<a name="l00202"></a>00202 <span class="comment">// Standard sequence of function calls to apply the default behaviour for an effect </span>
<a name="l00203"></a>00203 <span class="comment">// is to simply call BeginL() and then EndL().</span>
<a name="l00204"></a>00204 effect->BeginL();
<a name="l00205"></a>00205 effect->EndL();
<a name="l00206"></a>00206
<a name="l00207"></a>00207 <span class="comment">// Some effects do not have a default behaviour and need to use the specialized interface.</span>
<a name="l00208"></a>00208 TGeometricalOperation* operation = <span class="keyword">static_cast<</span>TGeometricalOperation*<span class="keyword">></span>(imageProcessor->EffectL(KGeometricalOperationUid));
<a name="l00209"></a>00209 operation->BeginL();
<a name="l00210"></a>00210 operation->SetOperationL(ImageProcessor::CImgProcessor::EOperationRotate270);
<a name="l00211"></a>00211 operation->EndL();
<a name="l00212"></a>00212
<a name="l00213"></a>00213 <span class="comment">// Process the input image to the output image. </span>
<a name="l00214"></a>00214 <span class="comment">// If an output size is not given then its size will be equal to the current input image after any cropping and </span>
<a name="l00215"></a>00215 <span class="comment">// geometrical operations are applied, so preserving the aspect ratio.</span>
<a name="l00216"></a>00216 <span class="comment">// For this example the output size is (inputSize.iHeight/4, inputSize.iWidth/4)). </span>
<a name="l00217"></a>00217 imageProcessor->ProcessL();
<a name="l00218"></a>00218
<a name="l00219"></a>00219 <span class="comment">// Wait for asynchronous callback</span>
<a name="l00220"></a>00220 CActiveScheduler::Start();
<a name="l00221"></a>00221
<a name="l00222"></a>00222 CleanupStack::PopAndDestroy(imageProcessor);
<a name="l00223"></a>00223 }
<a name="l00224"></a>00224
<a name="l00228"></a><a class="code" href="class_c_icl_example.html#0a48c925a0ce381333c16d8e046aea2f">00228</a> <span class="keywordtype">void</span> <a class="code" href="class_c_icl_example.html#0a48c925a0ce381333c16d8e046aea2f">CIclExample::EffectImageProcessingWithUndoL</a>()
<a name="l00229"></a>00229 {
<a name="l00230"></a>00230 CImgProcessorObserverStub observer(*iConsole);
<a name="l00231"></a>00231 ImageProcessor::CImgProcessor* imageProcessor = ImageProcessor::CImgProcessor::NewL(iFs, observer);
<a name="l00232"></a>00232 CleanupStack::PushL(imageProcessor);
<a name="l00233"></a>00233
<a name="l00234"></a>00234 <span class="comment">// Initialize the Image Processor instance. By default the initialization is asynchronous.</span>
<a name="l00235"></a>00235 <span class="comment">// (It might take some time to load Image Processor plugin and initialize it).</span>
<a name="l00236"></a>00236 imageProcessor->InitializeL();
<a name="l00237"></a>00237
<a name="l00238"></a>00238 <span class="comment">// Wait for asynchronous callback</span>
<a name="l00239"></a>00239 CActiveScheduler::Start();
<a name="l00240"></a>00240
<a name="l00241"></a>00241 imageProcessor->SetInputL(KInputFileName, KImageTypeJPGUid);
<a name="l00242"></a>00242 imageProcessor->SetOutputL(KOutputWithUndoFileName, KImageTypeJPGUid);
<a name="l00243"></a>00243
<a name="l00244"></a>00244 <span class="comment">// The TOutputInfo interface is used to set quality and sampling scheme for JPEG output</span>
<a name="l00245"></a>00245 TOutputInfo* outputInfo = imageProcessor->OutputInfoL();
<a name="l00246"></a>00246
<a name="l00247"></a>00247 <span class="comment">// Set 0.75 quality for the output image.</span>
<a name="l00248"></a>00248 <span class="comment">// (Note. Default quality value for the output image is the same as for the input image.)</span>
<a name="l00249"></a>00249 TReal32 quality = 0.75f;
<a name="l00250"></a>00250 outputInfo->SetJpegQualityL(quality);
<a name="l00251"></a>00251
<a name="l00252"></a>00252 <span class="comment">// The rotation effect can be used via derived interface only.</span>
<a name="l00253"></a>00253 TEffectRotation* rotationEffect = <span class="keyword">static_cast<</span>TEffectRotation*<span class="keyword">></span>(imageProcessor->EffectL(KEffectRotationUid));
<a name="l00254"></a>00254 rotationEffect->BeginL();
<a name="l00255"></a>00255 rotationEffect->SetRotationL(ImageProcessor::TEffectRotation::ERotationScaleModeFitInside, 45.0f);
<a name="l00256"></a>00256 rotationEffect->EndL();
<a name="l00257"></a>00257
<a name="l00258"></a>00258 <span class="comment">// Check if we can undo last applied effect</span>
<a name="l00259"></a>00259 <span class="keywordflow">if</span> (imageProcessor->CanUndoL())
<a name="l00260"></a>00260 {
<a name="l00261"></a>00261 <span class="comment">// Undo the effect</span>
<a name="l00262"></a>00262 imageProcessor->UndoL();
<a name="l00263"></a>00263 }
<a name="l00264"></a>00264
<a name="l00265"></a>00265 <span class="comment">// Process the input image to the output image. </span>
<a name="l00266"></a>00266 imageProcessor->ProcessL();
<a name="l00267"></a>00267
<a name="l00268"></a>00268 <span class="comment">// Wait for asynchronous callback</span>
<a name="l00269"></a>00269 CActiveScheduler::Start();
<a name="l00270"></a>00270
<a name="l00271"></a>00271 <span class="comment">// resultant image looks similar and has same image size as the input image but has some differences due to quality settings.</span>
<a name="l00272"></a>00272 CleanupStack::PopAndDestroy(imageProcessor);
<a name="l00273"></a>00273 }
<a name="l00274"></a>00274
<a name="l00278"></a><a class="code" href="class_c_icl_example.html#882b254fff2e471331d2f690d4e485aa">00278</a> <span class="keywordtype">void</span> <a class="code" href="class_c_icl_example.html#882b254fff2e471331d2f690d4e485aa">CIclExample::EffectImageProcessingWithPreviewL</a>()
<a name="l00279"></a>00279 {
<a name="l00280"></a>00280 CImgProcessorObserverStub observer(*iConsole);
<a name="l00281"></a>00281 ImageProcessor::CImgProcessor* imageProcessor = ImageProcessor::CImgProcessor::NewL(iFs, observer);
<a name="l00282"></a>00282 CleanupStack::PushL(imageProcessor);
<a name="l00283"></a>00283
<a name="l00284"></a>00284 <span class="comment">// Initialize the Image Processor instance. By default the initialization is asynchronous.</span>
<a name="l00285"></a>00285 <span class="comment">// (It might take some time to load Image Processor plugin and initialize it).</span>
<a name="l00286"></a>00286 imageProcessor->InitializeL();
<a name="l00287"></a>00287
<a name="l00288"></a>00288 <span class="comment">// Wait for asynchronous callback</span>
<a name="l00289"></a>00289 CActiveScheduler::Start();
<a name="l00290"></a>00290
<a name="l00291"></a>00291 <span class="comment">// Initialize the list of images filenames</span>
<a name="l00292"></a>00292 <span class="keyword">const</span> TDesC* filenames[4] =
<a name="l00293"></a>00293 {
<a name="l00294"></a>00294 &KInputFileName01,
<a name="l00295"></a>00295 &KInputFileName02,
<a name="l00296"></a>00296 &KInputFileName03,
<a name="l00297"></a>00297 &KInputFileName04
<a name="l00298"></a>00298 };
<a name="l00299"></a>00299
<a name="l00300"></a>00300 <span class="comment">// Initialize the list of bitmaps filenames</span>
<a name="l00301"></a>00301 <span class="keyword">const</span> TDesC* bitmapsnames[4] =
<a name="l00302"></a>00302 {
<a name="l00303"></a>00303 &KOutputBitmapFileName01,
<a name="l00304"></a>00304 &KOutputBitmapFileName02,
<a name="l00305"></a>00305 &KOutputBitmapFileName03,
<a name="l00306"></a>00306 &KOutputBitmapFileName04
<a name="l00307"></a>00307 };
<a name="l00308"></a>00308
<a name="l00309"></a>00309 <span class="comment">// Create the output bitmap for the preview.</span>
<a name="l00310"></a>00310 <span class="comment">// In this case the output bitmap should be considered as a offscreen buffer </span>
<a name="l00311"></a>00311 CFbsBitmap* previewBitmap = <span class="keyword">new</span> (ELeave) CFbsBitmap();
<a name="l00312"></a>00312 previewBitmap->Create(TSize(320,240), EColor64K);
<a name="l00313"></a>00313
<a name="l00314"></a>00314 CleanupStack::PushL(previewBitmap);
<a name="l00315"></a>00315
<a name="l00316"></a>00316 <span class="comment">// Define preview id for the preview</span>
<a name="l00317"></a>00317 <span class="keyword">const</span> TInt previewId = 1;
<a name="l00318"></a>00318
<a name="l00319"></a>00319 <span class="comment">// Get TPreview interface using preview id</span>
<a name="l00320"></a>00320 TPreview* preview = imageProcessor->PreviewL(previewId);
<a name="l00321"></a>00321
<a name="l00322"></a>00322 <span class="comment">// Set all image processor operations including preview rendering to be synchronous.</span>
<a name="l00323"></a>00323 <span class="comment">// The preview rendering should be reasonably quick so it is preferable to use</span>
<a name="l00324"></a>00324 <span class="comment">// the option here and get better performance over asynchronous operations.</span>
<a name="l00325"></a>00325 <span class="comment">// No callbacks to an observer are made in this case.</span>
<a name="l00326"></a>00326 imageProcessor->SetOptionsL(ImageProcessor::CImgProcessor::EOptionSyncProcessing);
<a name="l00327"></a>00327
<a name="l00328"></a>00328 <span class="comment">// Create a blank input and set up a chain of the effects before rendering the first preview.</span>
<a name="l00329"></a>00329 imageProcessor->CreateInputL(TSize(320, 240), TRgb(0, 0, 0));
<a name="l00330"></a>00330
<a name="l00331"></a>00331 <span class="comment">// Initialize the preview</span>
<a name="l00332"></a>00332 preview->InitializeL();
<a name="l00333"></a>00333
<a name="l00334"></a>00334 <span class="comment">// Set output for the preview. </span>
<a name="l00335"></a>00335 preview->SetOutputL(*previewBitmap);
<a name="l00336"></a>00336
<a name="l00337"></a>00337 <span class="comment">// Get sharpness effect</span>
<a name="l00338"></a>00338 TEffect* effect=imageProcessor->EffectL(KEffectSharpnessUid);
<a name="l00339"></a>00339
<a name="l00340"></a>00340 <span class="comment">// Apply default level of sharpness</span>
<a name="l00341"></a>00341 effect->BeginL();
<a name="l00342"></a>00342 effect->EndL();
<a name="l00343"></a>00343
<a name="l00344"></a>00344 <span class="comment">// Get color boost effect</span>
<a name="l00345"></a>00345 effect = imageProcessor->EffectL(KEffectColorBoostUid);
<a name="l00346"></a>00346
<a name="l00347"></a>00347 <span class="comment">// Apply default level of color boost</span>
<a name="l00348"></a>00348 effect->BeginL();
<a name="l00349"></a>00349 effect->EndL();
<a name="l00350"></a>00350
<a name="l00351"></a>00351 <span class="comment">// Get white balance effect</span>
<a name="l00352"></a>00352 effect = imageProcessor->EffectL(KEffectWhiteBalanceUid);
<a name="l00353"></a>00353
<a name="l00354"></a>00354 <span class="comment">// Apply default white balance </span>
<a name="l00355"></a>00355 effect->BeginL();
<a name="l00356"></a>00356 effect->EndL();
<a name="l00357"></a>00357
<a name="l00358"></a>00358 <span class="comment">// Go through the images and render the preview for each of them</span>
<a name="l00359"></a>00359 <span class="keywordflow">for</span> (TInt i = 0; i < 4; i++)
<a name="l00360"></a>00360 {
<a name="l00361"></a>00361 imageProcessor->SetInputL(*filenames[i]);
<a name="l00362"></a>00362 preview->RenderL();
<a name="l00363"></a>00363
<a name="l00364"></a>00364 <span class="comment">// Here a code to update the screen using the preview bitmap can be placed</span>
<a name="l00365"></a>00365 <span class="comment">// In our case we just save the bitmap.</span>
<a name="l00366"></a>00366 previewBitmap->Save(*bitmapsnames[i]);
<a name="l00367"></a>00367 }
<a name="l00368"></a>00368
<a name="l00369"></a>00369 CleanupStack::PopAndDestroy(2,imageProcessor); <span class="comment">//previewBitmap imageProcessor</span>
<a name="l00370"></a>00370 }
<a name="l00371"></a>00371
<a name="l00376"></a><a class="code" href="class_c_icl_example.html#da63b9baa84fb3fe22b1976ca84a2156">00376</a> <span class="keywordtype">void</span> <a class="code" href="class_c_icl_example.html#da63b9baa84fb3fe22b1976ca84a2156">CIclExample::EffectImageProcessingWithOverlayL</a>()
<a name="l00377"></a>00377 {
<a name="l00378"></a>00378 CImgProcessorObserverStub observer(*iConsole);
<a name="l00379"></a>00379 ImageProcessor::CImgProcessor* imageProcessor = ImageProcessor::CImgProcessor::NewL(iFs, observer);
<a name="l00380"></a>00380 CleanupStack::PushL(imageProcessor);
<a name="l00381"></a>00381
<a name="l00382"></a>00382 <span class="comment">// Initialize the Image Processor instance. By default the initialization is asynchronous.</span>
<a name="l00383"></a>00383 <span class="comment">// (It might take some time to load Image Processor plugin and initialize it).</span>
<a name="l00384"></a>00384 imageProcessor->InitializeL();
<a name="l00385"></a>00385
<a name="l00386"></a>00386 <span class="comment">// Wait for asynchronous callback</span>
<a name="l00387"></a>00387 CActiveScheduler::Start();
<a name="l00388"></a>00388
<a name="l00389"></a>00389 <span class="comment">// Set input and output files </span>
<a name="l00390"></a>00390 imageProcessor->SetInputL(KInputFileName, KImageTypeJPGUid);
<a name="l00391"></a>00391 imageProcessor->SetOutputL(KOutputWithOverlayFileName, KImageTypeJPGUid);
<a name="l00392"></a>00392
<a name="l00393"></a>00393 <span class="comment">// Create the output bitmap for the preview.</span>
<a name="l00394"></a>00394 CFbsBitmap* previewBitmap = <span class="keyword">new</span> (ELeave) CFbsBitmap();
<a name="l00395"></a>00395 previewBitmap->Create(TSize(320,240), EColor64K);
<a name="l00396"></a>00396
<a name="l00397"></a>00397 CleanupStack::PushL(previewBitmap);
<a name="l00398"></a>00398
<a name="l00399"></a>00399 <span class="comment">// Define preview id for the preview</span>
<a name="l00400"></a>00400 <span class="keyword">const</span> TInt previewId = 1;
<a name="l00401"></a>00401
<a name="l00402"></a>00402 <span class="comment">// Get TPreview interface using preview id</span>
<a name="l00403"></a>00403 TPreview* preview = imageProcessor->PreviewL(previewId);
<a name="l00404"></a>00404
<a name="l00405"></a>00405 <span class="comment">// Set all image processor operation like preview rendering to be synchronous</span>
<a name="l00406"></a>00406 <span class="comment">// The preview rendering should be reasonably quick so it is preferable to use</span>
<a name="l00407"></a>00407 <span class="comment">// the option here.</span>
<a name="l00408"></a>00408 imageProcessor->SetOptionsL(ImageProcessor::CImgProcessor::EOptionSyncProcessing);
<a name="l00409"></a>00409
<a name="l00410"></a>00410 <span class="comment">// Initialize the preview</span>
<a name="l00411"></a>00411 preview->InitializeL();
<a name="l00412"></a>00412
<a name="l00413"></a>00413 <span class="comment">// Set output for the preview. </span>
<a name="l00414"></a>00414 preview->SetOutputL(*previewBitmap);
<a name="l00415"></a>00415
<a name="l00416"></a>00416 <span class="comment">// we can check what this looks like by rendering to the preview</span>
<a name="l00417"></a>00417 preview->RenderL();
<a name="l00418"></a>00418
<a name="l00419"></a>00419 TPoint overlayPosition(0,0);
<a name="l00420"></a>00420
<a name="l00421"></a>00421 <span class="comment">// Get preview canvas rectangle </span>
<a name="l00422"></a>00422 TRect canvasArea = preview->CanvasAreaL();
<a name="l00423"></a>00423
<a name="l00424"></a>00424 <span class="comment">// Set overlay position to the center of the preview canvas area </span>
<a name="l00425"></a>00425 overlayPosition.iX = (canvasArea.iBr.iX - canvasArea.iTl.iX) / 2;
<a name="l00426"></a>00426 overlayPosition.iY = (canvasArea.iBr.iY - canvasArea.iTl.iY) / 2;
<a name="l00427"></a>00427
<a name="l00428"></a>00428 <span class="comment">// Convert the preview canvas coordinates to the input current coordinates </span>
<a name="l00429"></a>00429 TPoint tmp(0, 0);
<a name="l00430"></a>00430 preview->CanvasToCurrentCoordL(overlayPosition, tmp);
<a name="l00431"></a>00431 overlayPosition = tmp;
<a name="l00432"></a>00432
<a name="l00433"></a>00433 <span class="comment">// Get TOverlay interface</span>
<a name="l00434"></a>00434 TOverlay* overlay = imageProcessor->OverlayL();
<a name="l00435"></a>00435
<a name="l00436"></a>00436 <span class="comment">// Begin the overlay with a overlay file</span>
<a name="l00437"></a>00437 overlay->SetInputL(KInputOverlayFileName, KImageTypePNGUid);
<a name="l00438"></a>00438 overlay->BeginL();
<a name="l00439"></a>00439
<a name="l00440"></a>00440 <span class="comment">// Set overlay with 1.0 x/y scale (un-scaled), position at the center of the preview canvas, 0.0 angle (no rotation)</span>
<a name="l00441"></a>00441 overlay->SetL(1.0f, 1.0f, overlayPosition, 0.0f);
<a name="l00442"></a>00442
<a name="l00443"></a>00443 <span class="comment">// we can check what this looks like by rendering to the preview</span>
<a name="l00444"></a>00444 preview->RenderL();
<a name="l00445"></a>00445 <span class="comment">// save the content of the preview bitmap to check the result</span>
<a name="l00446"></a>00446 previewBitmap->Save(KOutputBitmapFileName01);
<a name="l00447"></a>00447
<a name="l00448"></a>00448 <span class="comment">// We can then double the size of the overlaid, rotate it 45 degrees clockwise </span>
<a name="l00449"></a>00449 <span class="comment">// and move it down ten screen pixels.</span>
<a name="l00450"></a>00450
<a name="l00451"></a>00451 <span class="comment">// Double the size of the overlay </span>
<a name="l00452"></a>00452 TReal32 overlayScaleX = 0.0f;
<a name="l00453"></a>00453 TReal32 overlayScaleY = 0.0f;
<a name="l00454"></a>00454 overlay->GetScaleL(overlayScaleX, overlayScaleY);
<a name="l00455"></a>00455
<a name="l00456"></a>00456 overlayScaleX *= 2.0f;
<a name="l00457"></a>00457 overlayScaleY *= 2.0f;
<a name="l00458"></a>00458
<a name="l00459"></a>00459 TReal32 overlayAngle = overlay->AngleL();
<a name="l00460"></a>00460
<a name="l00461"></a>00461 <span class="comment">// Rotate the overlay 45 degrees </span>
<a name="l00462"></a>00462 overlayAngle += 45.0f;
<a name="l00463"></a>00463 <span class="keywordflow">if</span> (overlayAngle >= 360.0f)
<a name="l00464"></a>00464 {
<a name="l00465"></a>00465 overlayAngle = overlayAngle - 360.0f;
<a name="l00466"></a>00466 }
<a name="l00467"></a>00467
<a name="l00468"></a>00468 <span class="comment">// Move down the position of the overlay 10 screen pixels</span>
<a name="l00469"></a>00469 overlayPosition = overlay->PositionL();
<a name="l00470"></a>00470 overlayPosition.iY += 10;
<a name="l00471"></a>00471
<a name="l00472"></a>00472 <span class="comment">// Set overlay with new parameters</span>
<a name="l00473"></a>00473 overlay->SetL(overlayScaleX, overlayScaleY, overlayPosition, overlayAngle);
<a name="l00474"></a>00474
<a name="l00475"></a>00475 <span class="comment">// Apply overlay parameters and finish with overlay</span>
<a name="l00476"></a>00476 overlay->EndL();
<a name="l00477"></a>00477
<a name="l00478"></a>00478 preview->RenderL();
<a name="l00479"></a>00479
<a name="l00480"></a>00480 <span class="comment">//save the content of the preview bitmap to check the result</span>
<a name="l00481"></a>00481 previewBitmap->Save(KOutputBitmapFileName02);
<a name="l00482"></a>00482
<a name="l00483"></a>00483 <span class="comment">// Restore default asyncronous processing</span>
<a name="l00484"></a>00484 imageProcessor->SetOptionsL(imageProcessor->Options() ^ ImageProcessor::CImgProcessor::EOptionSyncProcessing);
<a name="l00485"></a>00485
<a name="l00486"></a>00486 <span class="comment">// Process the input image to the output image. </span>
<a name="l00487"></a>00487 imageProcessor->ProcessL();
<a name="l00488"></a>00488
<a name="l00489"></a>00489 <span class="comment">// Wait for asynchronous callback</span>
<a name="l00490"></a>00490 CActiveScheduler::Start();
<a name="l00491"></a>00491
<a name="l00492"></a>00492 CleanupStack::PopAndDestroy(2,imageProcessor); <span class="comment">//previewBitmap imageProcessor</span>
<a name="l00493"></a>00493 }
<a name="l00494"></a>00494
<a name="l00501"></a><a class="code" href="class_c_icl_example.html#906019f9b590b09c52f78f246d681437">00501</a> <span class="keywordtype">void</span> <a class="code" href="class_c_icl_example.html#906019f9b590b09c52f78f246d681437">CIclExample::ImageProcessingWithSpmoL</a>()
<a name="l00502"></a>00502 {
<a name="l00503"></a>00503 CImgProcessorObserverStub observer(*iConsole);
<a name="l00504"></a>00504 ImageProcessor::CImgProcessor* imageProcessor = ImageProcessor::CImgProcessor::NewL(iFs, observer);
<a name="l00505"></a>00505 CleanupStack::PushL(imageProcessor);
<a name="l00506"></a>00506
<a name="l00507"></a>00507 <span class="comment">// Initialize the Image Processor instance. By default the initialization is asynchronous.</span>
<a name="l00508"></a>00508 <span class="comment">// (It might take some time to load Image Processor plugin and initialize it).</span>
<a name="l00509"></a>00509 imageProcessor->InitializeL();
<a name="l00510"></a>00510
<a name="l00511"></a>00511 <span class="comment">// Wait for asynchronous callback</span>
<a name="l00512"></a>00512 CActiveScheduler::Start();
<a name="l00513"></a>00513
<a name="l00514"></a>00514 <span class="comment">// Set input image. This one does not have Spmo, but it could have.</span>
<a name="l00515"></a>00515 imageProcessor->SetInputL(KInputFileName, KImageTypeJPGUid);
<a name="l00516"></a>00516 imageProcessor->SetOutputL(KOutputWithSpmoFileName, KImageTypeJPGUid);
<a name="l00517"></a>00517
<a name="l00518"></a>00518 <span class="comment">// transfer exif from the input (this is not mandatory)</span>
<a name="l00519"></a>00519 imageProcessor->SetOptionsL(ImageProcessor::CImgProcessor::EOptionExifMetadataProcessing);
<a name="l00520"></a>00520
<a name="l00521"></a>00521 <span class="comment">// To access Spmo functionality it is necessary to get Caps image processor extension interface @publishedpartner.</span>
<a name="l00522"></a>00522 TCapsImageProcessorExtension* extension = <span class="keyword">static_cast<</span>TCapsImageProcessorExtension*<span class="keyword">></span>(imageProcessor->Extension(KCapsImageProcessorExtensionUid));
<a name="l00523"></a>00523
<a name="l00524"></a>00524 <span class="comment">// Set add Spmo to the output. The Spmo will be optimized for preview at QVGA screen size.</span>
<a name="l00525"></a>00525 <span class="comment">// The code below will be commented in when DTW-MM00213 is fixed</span>
<a name="l00526"></a>00526 extension->SetAddSpmoToOutputL(ETrue, TSize(320, 240));
<a name="l00527"></a>00527
<a name="l00528"></a>00528 <span class="comment">// it is not possible to apply effects AND set Speedview object to the output</span>
<a name="l00529"></a>00529
<a name="l00530"></a>00530 <span class="comment">// Process the input image to the output image. </span>
<a name="l00531"></a>00531 imageProcessor->ProcessL();
<a name="l00532"></a>00532
<a name="l00533"></a>00533 <span class="comment">// Wait for asynchronous callback</span>
<a name="l00534"></a>00534 CActiveScheduler::Start();
<a name="l00535"></a>00535
<a name="l00536"></a>00536 CleanupStack::PopAndDestroy(imageProcessor);
<a name="l00537"></a>00537 }
<a name="l00538"></a>00538
</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu Jan 21 10:32:59 2010 for TB10.1 Example Applications by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
</body>
</html>