diff -r 89d6a7a84779 -r 25a17d01db0c Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/icljpgtoolsandsqueezeexample_8cpp-source.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/Examples/guid-6013a680-57f9-415b-8851-c4fa63356636/icljpgtoolsandsqueezeexample_8cpp-source.html Fri Jan 22 18:26:19 2010 +0000 @@ -0,0 +1,392 @@ + +
+00001 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +00002 // All rights reserved. +00003 // This component and the accompanying materials are made available +00004 // under the terms of "Eclipse Public License v1.0" +00005 // which accompanies this distribution, and is available +00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html". +00007 // +00008 // Initial Contributors: +00009 // Nokia Corporation - initial contribution. +00010 // +00011 // Contributors: +00012 // +00013 // Description: +00014 // This code demonstrates various imagetransformations available in Jpeg Tools and Squeeze +00015 // modules of ICL +00016 // Note 1: For demonstration purposes we create a client side active object which can +00017 // handle the asynchronous request to transform the image. In a standard application the asynchronous +00018 // call would be made passing in a TRequestStatus object associate with an active object +00019 // which is part of that application. We would return to the main UI processing thread in +00020 // which an active scheduler is running and wait for the asynchronous request to complete. In +00021 // this demonstration we need to manually start the active scheduler. +00022 // Note 2: Starts the active scheduler - this is for demonstration purposes. See Note 1: +00023 // +00024 +00025 +00026 +00027 +00028 +00033 #include "iclexample.h" +00034 +00035 #include <imagetransform.h> +00036 #include <icl/squeezetransformextension.h> +00037 #include <icl/orientationtransformextension.h> +00038 #include <icl/overlaytransformextension.h> +00039 #include <iclexifimageframe.h> +00040 #include <imageframe.h> +00041 #include <imageconversion.h> +00042 +00043 +00044 const TUid KImageFramePluginUid = {0x101F7C60}; +00045 +00056 void CIclExample::SqueezeJpgFileToFileL(const TDesC& aSrcFileName, const TDesC& aDestFileName) +00057 { +00058 // Create CImageTransform object and push it on to the cleanup stack +00059 CImageTransform* imageTransform = CImageTransform::NewL(iFs); +00060 CleanupStack::PushL(imageTransform); +00061 +00062 imageTransform->SetSourceFilenameL(aSrcFileName); +00063 imageTransform->SetDestFilenameL(aDestFileName); +00064 imageTransform->SetTransformationsL(CImageTransform::ESqueeze); +00065 imageTransform->SetOptionsL(CImageTransform::EIgnoreExifMetadataProcessing); +00066 imageTransform->SetupL(); +00067 +00068 TUid lSqUid = {KUidSqueezeTransformExtension }; +00069 TInt err = KErrNone; +00070 CSqueezeTransformExtension* lSqExt = static_cast<CSqueezeTransformExtension*>(imageTransform->Extension(lSqUid, err)); +00071 if(!lSqExt) +00072 { +00073 User::Leave(err); +00074 } +00075 +00076 // Squeeze by 20% of size in bytes +00077 TInt squeezeRate = 20; +00078 RFile file; +00079 User::LeaveIfError(file.Open(iFs, aSrcFileName, EFileRead)); +00080 TInt filesize; +00081 User::LeaveIfError(file.Size(filesize)); +00082 file.Close(); +00083 TInt maxdestsize = filesize - ( (filesize * squeezeRate)/100 ); +00084 +00085 // Set the desired max size of the squeezed file on the squeeze extension +00086 lSqExt->SetDestSizeInBytes(maxdestsize); +00087 +00088 // Call Transform() function of CImageTransform for image transform operation +00089 // See Note 1 +00090 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00091 +00092 // Call Transform() function of CImageTransform for image transform operation +00093 imageTransform->Transform(activeListener->iStatus); +00094 +00095 // See Note 2 +00096 CActiveScheduler::Start(); +00097 User::LeaveIfError(activeListener->iStatus.Int()); +00098 +00099 +00100 CleanupStack::PopAndDestroy(2); // activeListener, imageTransform +00101 } +00102 +00103 +00114 void CIclExample::SqueezeJpgBufferToBufferL(const TDesC& aSrcFileName, const TDesC& aDestFileName) +00115 { +00116 TPtr8 imageFromFilePtr = LoadImageIntoMemoryLC(aSrcFileName); +00117 HBufC8* destData = NULL; +00118 +00119 // Create CImageTransform object and push it on to the cleanup stack +00120 CImageTransform* imageTransform = CImageTransform::NewL(iFs); +00121 CleanupStack::PushL(imageTransform); +00122 +00123 imageTransform->SetSourceDataL(imageFromFilePtr); +00124 imageTransform->SetDestDataL(destData); +00125 imageTransform->SetTransformationsL(CImageTransform::ESqueeze); +00126 imageTransform->SetupL(); +00127 +00128 TUid lSqUid = {KUidSqueezeTransformExtension }; +00129 TInt err = KErrNone; +00130 CSqueezeTransformExtension* lSqExt = static_cast<CSqueezeTransformExtension*>(imageTransform->Extension(lSqUid, err)); +00131 if(!lSqExt) +00132 { +00133 User::Leave(err); +00134 } +00135 +00136 // Squeeze by 5% of size in bytes +00137 TInt squeezeRate = 5; +00138 RFile file; +00139 User::LeaveIfError(file.Open(iFs, aSrcFileName, EFileRead)); +00140 TInt filesize; +00141 User::LeaveIfError(file.Size(filesize)); +00142 file.Close(); +00143 TInt maxdestsize = filesize - ( (filesize * squeezeRate)/100 ); +00144 +00145 // Set the desired max size of the squeezed file on the squeeze extension +00146 lSqExt->SetDestSizeInBytes(maxdestsize); +00147 +00148 // Call Transform() function of CImageTransform for image transform operation +00149 // See Note 1 +00150 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00151 +00152 // Call Transform() function of CImageTransform for image transform operation +00153 imageTransform->Transform(activeListener->iStatus); +00154 +00155 // See Note 2 +00156 CActiveScheduler::Start(); +00157 User::LeaveIfError(activeListener->iStatus.Int()); +00158 +00159 // write the descriptor to the output file +00160 User::LeaveIfError(file.Replace(iFs, aDestFileName, EFileWrite)); +00161 file.Write(*destData); +00162 file.Close(); +00163 delete destData; +00164 +00165 CleanupStack::PopAndDestroy(3); // activeListener, imageTransform, image +00166 } +00167 +00168 +00179 void CIclExample::AutoSqueezeJpgFileToFileL(const TDesC& aSrcFileName, const TDesC& aDestFileName) +00180 { +00181 // Create CImageTransform object and push it on to the cleanup stack +00182 CImageTransform* imageTransform = CImageTransform::NewL(iFs); +00183 CleanupStack::PushL(imageTransform); +00184 +00185 imageTransform->SetSourceFilenameL(aSrcFileName); +00186 imageTransform->SetDestFilenameL(aDestFileName); +00187 imageTransform->SetTransformationsL(CImageTransform::ESqueeze); +00188 imageTransform->SetupL(); +00189 +00190 TUid lSqUid = {KUidSqueezeTransformExtension }; +00191 TInt err = KErrNone; +00192 CSqueezeTransformExtension* lSqExt = static_cast<CSqueezeTransformExtension*>(imageTransform->Extension(lSqUid, err)); +00193 if(!lSqExt) +00194 { +00195 User::Leave(err); +00196 } +00197 +00198 // Squeeze by 5% of size in bytes +00199 TInt squeezeRate = 5; +00200 RFile file; +00201 User::LeaveIfError(file.Open(iFs, aSrcFileName, EFileRead)); +00202 TInt filesize; +00203 User::LeaveIfError(file.Size(filesize)); +00204 file.Close(); +00205 TInt maxdestsize = filesize - ( (filesize * squeezeRate)/100 ); +00206 +00207 // Get the pixel size of the image +00208 CJPEGImageFrameDecoder *decoder = NULL; +00209 decoder= static_cast<CJPEGImageFrameDecoder*> (CImageDecoder::FileNewL(iFs, aSrcFileName, CImageDecoder::EOptionNone, KNullUid, KNullUid, KImageFramePluginUid)); +00210 const TFrameInfo* frameInfo = &decoder->FrameInfo();; +00211 TSize imgSizeInPixels = frameInfo->iOverallSizeInPixels; +00212 delete decoder; +00213 +00214 // Max pixel size may be 10% of the original size +00215 TSize maxImageSizeInPixels; +00216 maxImageSizeInPixels.iWidth = imgSizeInPixels.iWidth - (imgSizeInPixels.iWidth *10) /100; +00217 maxImageSizeInPixels.iHeight = imgSizeInPixels.iHeight - (imgSizeInPixels.iHeight *10) /100; +00218 +00219 // Min pixel size may be 30% of the original size +00220 TSize minImageSizeInPixels; +00221 minImageSizeInPixels.iWidth = imgSizeInPixels.iWidth - (imgSizeInPixels.iWidth *30) /100; +00222 minImageSizeInPixels.iHeight = imgSizeInPixels.iHeight - (imgSizeInPixels.iHeight *30) /100; +00223 +00224 // Set the various desired parmas for the auto squeeze +00225 TAdvancedSqueezeParams squeezeAutoResizeParams; +00226 squeezeAutoResizeParams.iMaxDestSizeInBytes = maxdestsize; +00227 squeezeAutoResizeParams.iResizeAction = TAdvancedSqueezeParams::EAutoResizeActionPrioritizeLargeImageSize; +00228 squeezeAutoResizeParams.iMinImageSize = minImageSizeInPixels; +00229 squeezeAutoResizeParams.iMaxImageSize = maxImageSizeInPixels; +00230 squeezeAutoResizeParams.iSamplingUid = KUidSamplingColor422; +00231 squeezeAutoResizeParams.iMinEncodingQuality = 0.8f; +00232 // Set the advance params to the squeeze extension +00233 lSqExt->SetAdvancedSqueezeModeL(&squeezeAutoResizeParams); +00234 +00235 +00236 // Call Transform() function of CImageTransform for image transform operation +00237 // See Note 1 +00238 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00239 +00240 // Call Transform() function of CImageTransform for image transform operation +00241 imageTransform->Transform(activeListener->iStatus); +00242 +00243 // See Note 2 +00244 CActiveScheduler::Start(); +00245 User::LeaveIfError(activeListener->iStatus.Int()); +00246 +00247 +00248 CleanupStack::PopAndDestroy(2); // activeListener, imageTransform +00249 } +00250 +00261 void CIclExample::RotateJpgFileToFileL(const TDesC& aSrcFileName, const TDesC& aDestFileName) +00262 { +00263 // Create CImageTransform object and push it on to the cleanup stack +00264 CImageTransform* imageTransform = CImageTransform::NewL(iFs); +00265 CleanupStack::PushL(imageTransform); +00266 +00267 imageTransform->SetSourceFilenameL(aSrcFileName); +00268 imageTransform->SetDestFilenameL(aDestFileName); +00269 imageTransform->SetTransformationsL(CImageTransform::EOrientation); +00270 imageTransform->SetupL(); +00271 +00272 TUid lRotateUid = {KUidOrientationTransformExtension }; +00273 TInt err = KErrNone; +00274 COrientationTransformExtension* lRotateExt = static_cast<COrientationTransformExtension*>(imageTransform->Extension(lRotateUid, err)); +00275 if(!lRotateExt) +00276 { +00277 User::Leave(err); +00278 } +00279 // Rotate by 90 degree of size in bytes +00280 lRotateExt->SetOrientationL(COrientationTransformExtension::ERotation90DegreesClockwise); +00281 +00282 // Call Transform() function of CImageTransform for image transform operation +00283 // See Note 1 +00284 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00285 +00286 // Call Transform() function of CImageTransform for image transform operation +00287 imageTransform->Transform(activeListener->iStatus); +00288 +00289 // See Note 2 +00290 CActiveScheduler::Start(); +00291 User::LeaveIfError(activeListener->iStatus.Int()); +00292 +00293 +00294 CleanupStack::PopAndDestroy(2); // activeListener, imageTransform +00295 } +00296 +00297 +00309 void CIclExample::OverlayJpgDataToJpgFileToFileL(const TDesC& aSrcFileName, const TDesC& aOverlayFileName, const TDesC& aDestFileName) +00310 { +00311 // Create CImageTransform object and push it on to the cleanup stack +00312 CImageTransform* imageTransform = CImageTransform::NewL(iFs); +00313 CleanupStack::PushL(imageTransform); +00314 +00315 imageTransform->SetSourceFilenameL(aSrcFileName); +00316 imageTransform->SetDestFilenameL(aDestFileName); +00317 imageTransform->SetTransformationsL(CImageTransform::EOverlay); +00318 imageTransform->SetupL(); +00319 +00320 TUid lRotateUid = {KUidOverlayTransformExtension }; +00321 TInt err = KErrNone; +00322 COverlayTransformExtension* lOverlayExt = static_cast<COverlayTransformExtension*>(imageTransform->Extension(lRotateUid, err)); +00323 if(!lOverlayExt) +00324 { +00325 User::Leave(err); +00326 } +00327 // Set the position +00328 TPoint position(0,0); +00329 lOverlayExt->SetPosition(position); +00330 +00331 // Set the overlay file +00332 TPtr8 imageFromFilePtr = LoadImageIntoMemoryLC(aOverlayFileName); +00333 lOverlayExt->SetOverlayDataL(imageFromFilePtr, KImageTypeJPGUid); +00334 +00335 // Call Transform() function of CImageTransform for image transform operation +00336 // See Note 1 +00337 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00338 +00339 // Call Transform() function of CImageTransform for image transform operation +00340 imageTransform->Transform(activeListener->iStatus); +00341 +00342 // See Note 2 +00343 CActiveScheduler::Start(); +00344 User::LeaveIfError(activeListener->iStatus.Int()); +00345 +00346 +00347 CleanupStack::PopAndDestroy(3); // activeListener, overlay image, imageTransform +00348 } +00349 +00361 void CIclExample::OverlayPngFileToJpgFileToFileL(const TDesC& aSrcFileName, const TDesC& aOverlayFileName, const TDesC& aDestFileName) +00362 { +00363 // Create CImageTransform object and push it on to the cleanup stack +00364 CImageTransform* imageTransform = CImageTransform::NewL(iFs); +00365 CleanupStack::PushL(imageTransform); +00366 +00367 imageTransform->SetSourceFilenameL(aSrcFileName); +00368 imageTransform->SetDestFilenameL(aDestFileName); +00369 imageTransform->SetTransformationsL(CImageTransform::EOverlay); +00370 imageTransform->SetupL(); +00371 +00372 TUid lOverlayUid = {KUidOverlayTransformExtension }; +00373 TInt err = KErrNone; +00374 COverlayTransformExtension* lOverlayExt = static_cast<COverlayTransformExtension*>(imageTransform->Extension(lOverlayUid, err)); +00375 if(!lOverlayExt) +00376 { +00377 User::Leave(err); +00378 } +00379 // Set the position +00380 TPoint position(0,0); +00381 lOverlayExt->SetPosition(position); +00382 +00383 // Set the overlay data +00384 TUid pngUid = KImageTypePNGUid; +00385 lOverlayExt->SetOverlayFileL(aOverlayFileName, pngUid); +00386 +00387 // Call Transform() function of CImageTransform for image transform operation +00388 // See Note 1 +00389 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00390 +00391 // Call Transform() function of CImageTransform for image transform operation +00392 imageTransform->Transform(activeListener->iStatus); +00393 +00394 // See Note 2 +00395 CActiveScheduler::Start(); +00396 User::LeaveIfError(activeListener->iStatus.Int()); +00397 +00398 +00399 CleanupStack::PopAndDestroy(2); // activeListener, overlay image, imageTransform +00400 } +00401 +00402 +00414 void CIclExample::OverlayBmpDataToJpgFileToFileL(const TDesC& aSrcFileName, const TDesC& aOverlayFileName, const TDesC& aDestFileName) +00415 { +00416 // Create CImageTransform object and push it on to the cleanup stack +00417 CImageTransform* imageTransform = CImageTransform::NewL(iFs); +00418 CleanupStack::PushL(imageTransform); +00419 +00420 imageTransform->SetSourceFilenameL(aSrcFileName); +00421 imageTransform->SetDestFilenameL(aDestFileName); +00422 imageTransform->SetTransformationsL(CImageTransform::EOverlay); +00423 imageTransform->SetupL(); +00424 +00425 TUid lRotateUid = {KUidOverlayTransformExtension }; +00426 TInt err = KErrNone; +00427 COverlayTransformExtension* lOverlayExt = static_cast<COverlayTransformExtension*>(imageTransform->Extension(lRotateUid, err)); +00428 if(!lOverlayExt) +00429 { +00430 User::Leave(err); +00431 } +00432 // Set the position +00433 TPoint position(0,0); +00434 lOverlayExt->SetPosition(position); +00435 +00436 // Set the overlay bitmap +00437 CFbsBitmap* overlayBitmap = new (ELeave) CFbsBitmap; +00438 CleanupStack::PushL(overlayBitmap); +00439 User::LeaveIfError(overlayBitmap->Load(aOverlayFileName)); +00440 lOverlayExt->SetOverlayImageL(*overlayBitmap); +00441 +00442 +00443 // Call Transform() function of CImageTransform for image transform operation +00444 // See Note 1 +00445 CActiveListener* activeListener = CreateAndInitializeActiveListenerLC(); +00446 +00447 // Call Transform() function of CImageTransform for image transform operation +00448 imageTransform->Transform(activeListener->iStatus); +00449 +00450 // See Note 2 +00451 CActiveScheduler::Start(); +00452 User::LeaveIfError(activeListener->iStatus.Int()); +00453 +00454 +00455 CleanupStack::PopAndDestroy(3); // activeListener, overlay bitmap, imageTransform +00456 } +00457 +