imagingandcamerafws/imagingfws/ImageTransform/src/ImageTransform.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2008-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 //
       
    15 
       
    16 #include "ImageTransform.h"
       
    17 #include "ImageTransformFramework.h"
       
    18 #include "ImageTransformMain.h"
       
    19 
       
    20 /**
       
    21 Constructs a CImageTransform object.
       
    22 
       
    23 @param	aFs
       
    24         A reference to a file server session for the transform API to use.
       
    25 @return	A pointer to a fully constructed CImageTransform.
       
    26 
       
    27 */
       
    28 EXPORT_C CImageTransform* CImageTransform::NewL(RFs& aFs)
       
    29 	{
       
    30 	CImageTransform* self = new(ELeave) CImageTransform();
       
    31 	CleanupStack::PushL(self);
       
    32 	self->ConstructL(aFs);
       
    33 	CleanupStack::Pop(self);
       
    34 	return self;
       
    35 	}
       
    36 
       
    37 /**
       
    38 Constructor for this class.
       
    39 */
       
    40 CImageTransform::CImageTransform()
       
    41 	{
       
    42 	}
       
    43 
       
    44 
       
    45 /**
       
    46 Performs second phase of contruction
       
    47 
       
    48 @param	aFs
       
    49         A reference to a file server session for the transform API to use.
       
    50 */
       
    51 void CImageTransform::ConstructL(RFs& aFs)
       
    52 	{
       
    53 	iBody = CImageTransformFramework::NewL(*this, aFs);
       
    54 	}
       
    55 
       
    56 
       
    57 /**
       
    58 This is the destructor for this class
       
    59 and is responsible for deallocating all resources
       
    60 */
       
    61 
       
    62 EXPORT_C CImageTransform::~CImageTransform()
       
    63 	{
       
    64 	delete iBody;
       
    65 	}
       
    66 
       
    67 /**
       
    68 Specifies the UID of the image transform plugin to load
       
    69 
       
    70 @param	aPluginUid
       
    71         The plugin's implementation UID
       
    72 @leave	KErrArgument
       
    73 		The UID is KNullUid
       
    74 */
       
    75 EXPORT_C void CImageTransform::SetPluginUidL(TUid aPluginUid)
       
    76 	{
       
    77 	ASSERT(iBody);
       
    78 	iBody->SetPluginUidL(aPluginUid);
       
    79 	}
       
    80 
       
    81 /**
       
    82 Specifies the name of the source file containing the image to transform
       
    83 
       
    84 @param	aFilename
       
    85         The source filename
       
    86 @leave	KNotFound
       
    87 		The file does not exist
       
    88 */
       
    89 EXPORT_C void CImageTransform::SetSourceFilenameL(const TDesC& aFilename)
       
    90 	{
       
    91 	ASSERT(iBody);
       
    92 	iBody->SetSourceFilenameL(aFilename);
       
    93 	}
       
    94 
       
    95 /**
       
    96 Specifies the source descriptor containing the image to transform.
       
    97 Note that this descriptor must persist while the the image is transformed.
       
    98 i.e. the transformation operation does not make a copy of the data. 
       
    99 Special care must be taken when passing a TPtrC8 or TPtr8 to this function:
       
   100 The TPtrC8/TPtr8 itself (as well as the data it points to) must be persistent.
       
   101 
       
   102 @param	aData
       
   103         The source descriptor
       
   104 @leave	KErrArgument
       
   105 		The length is zero
       
   106 */
       
   107 EXPORT_C void CImageTransform::SetSourceDataL(const TDesC8& aData)
       
   108 	{
       
   109 	ASSERT(iBody);
       
   110 	iBody->SetSourceDataL(aData);
       
   111 	}
       
   112 
       
   113 /**
       
   114 Specifies the MIME type of the source image.
       
   115 
       
   116 @param	aMIMEType
       
   117         The MIME type of the source image 
       
   118 @leave	KErrArgument
       
   119 		The length is zero
       
   120 */
       
   121 EXPORT_C void CImageTransform::SetSourceMimeTypeL(const TDesC8& aMIMEType)
       
   122 	{
       
   123 	ASSERT(iBody);
       
   124 	iBody->SetSourceMimeTypeL(aMIMEType);
       
   125 	}
       
   126 
       
   127 /**
       
   128 Specifies the source image's type and (optionally) its subtype
       
   129 
       
   130 @param	aImageType
       
   131         The UID of the source image's type
       
   132 @param	aImageSubType
       
   133         The UID of the source image's subtype
       
   134 @leave	KErrArgument
       
   135 		aImageType is KNullUid
       
   136 */
       
   137 EXPORT_C void CImageTransform::SetSourceImageTypeL(TUid aImageType, TUid aImageSubType)
       
   138 	{
       
   139 	ASSERT(iBody);
       
   140 	iBody->SetSourceImageTypeL(aImageType, aImageSubType);
       
   141 	}
       
   142 
       
   143 /**
       
   144 Defines a clipping region. Only the specified region will be converted.
       
   145 It is not supported by the Symbian Jpeg ImageTransform Plugin.
       
   146 
       
   147 @param	aRect
       
   148         The coordinates of the clipping region
       
   149 */
       
   150 EXPORT_C void CImageTransform::SetSourceRect(const TRect& aRect)
       
   151 	{
       
   152 	ASSERT(iBody);
       
   153 	iBody->SetSourceRect(aRect);
       
   154 	}
       
   155 
       
   156 /**
       
   157 Clears the clipping region. 
       
   158 */
       
   159 EXPORT_C void CImageTransform::ClearSourceRect()
       
   160 	{
       
   161 	ASSERT(iBody);
       
   162 	iBody->ClearSourceRect();
       
   163 	}
       
   164 
       
   165 /**
       
   166 Specifies the name of the destination file where the transformed image
       
   167 is to be written to.
       
   168 
       
   169 @param	aFilename
       
   170         The destination filename
       
   171 @leave	KArgument
       
   172 		The length is zero
       
   173 */
       
   174 EXPORT_C void CImageTransform::SetDestFilenameL(const TDesC& aFilename)
       
   175 	{
       
   176 	ASSERT(iBody);
       
   177 	iBody->SetDestFilenameL(aFilename);
       
   178 	}
       
   179 
       
   180 /**
       
   181 Defines the destination descriptor. 
       
   182 This is a reference to a pointer that is owned by the client app. 
       
   183 The pointer should be NULL; the plugin will take responsibility for 
       
   184 allocating (and potentially growing) the descriptor. 
       
   185 
       
   186 @param	aData
       
   187 		The destination descriptor.
       
   188 @leave	KErrArgument
       
   189 		The pointer is not NULL
       
   190 */
       
   191 EXPORT_C void CImageTransform::SetDestDataL(HBufC8*& aData)
       
   192 	{
       
   193 	ASSERT(iBody);
       
   194 	iBody->SetDestDataL(aData);
       
   195 	}
       
   196 
       
   197 /**
       
   198 Specifies the requested destination image size. 
       
   199 
       
   200 @param	aDestinationSize
       
   201 		The requested size of the destination size in pixels.
       
   202 @param	aMaintainAspectRatio
       
   203 		Requests that the aspect ratio be maintained as far as possible.
       
   204 		Defaults to ETrue.
       
   205 @leave	KErrArgument
       
   206 		The destination size is zero.
       
   207 
       
   208 */
       
   209 EXPORT_C void CImageTransform::SetDestSizeInPixelsL(const TSize& aDestinationSize, TBool aMaintainAspectRatio)
       
   210 	{
       
   211 	ASSERT(iBody);
       
   212 	iBody->SetDestSizeInPixelsL(aDestinationSize, aMaintainAspectRatio);
       
   213 	}
       
   214 
       
   215 /**
       
   216 Defines the options for the image transformation. The specified option must be one of the 
       
   217 options supported or a combination of them, see CImageTransform::TOptions.
       
   218 
       
   219 @param	aOptions 
       
   220 		The required option or combination of options from CImageTransform::TOptions
       
   221 @leave	KErrArgument
       
   222 		One or more of the specified option flags is invalid
       
   223 */
       
   224 EXPORT_C void CImageTransform::SetOptionsL(TUint aOptions)
       
   225 	{
       
   226 	ASSERT(iBody);
       
   227 	iBody->SetOptionsL(aOptions);
       
   228 	}
       
   229 
       
   230 /**
       
   231 Defines the transformations to be supported by the desired plug-in. The specified transformation must be one of the 
       
   232 transformations specified in CImageTransform::TTransformations or combination of them, see CImageTransform::TTransformations.
       
   233 
       
   234 @param	aTransformations 
       
   235 		The required transformation or combination of transformations from CImageTransform::TTransformations.
       
   236 @leave	KErrArgument
       
   237 		One or more of the specified transformation flags is invalid.
       
   238 */
       
   239 EXPORT_C void CImageTransform::SetTransformationsL(TUint aTransformations)
       
   240 	{
       
   241 	ASSERT(iBody);
       
   242 	iBody->SetTransformationsL(aTransformations);
       
   243 	}
       
   244 
       
   245 /**
       
   246 Specifies that either the original image data is to preserved, as far as possible, 
       
   247 or that the image data should be re-encoded to produce a more size-efficient image.
       
   248 @param	aPreserveImageData Requests that the aspect ratio be preserved
       
   249 		                   Defaults to false
       
   250 */
       
   251 EXPORT_C void CImageTransform::SetPreserveImageData(TBool aPreserveImageData)
       
   252 	{
       
   253 	ASSERT(iBody);
       
   254 	iBody->SetPreserveImageData(aPreserveImageData);
       
   255 	}
       
   256 
       
   257 /**
       
   258 Requests that a suitable plugin be selected and instantiated. 
       
   259 
       
   260 @leave	KErrNotFound
       
   261 		No suitable plugin was found
       
   262 
       
   263 @leave KErrNotReady
       
   264 		A required parameter was not set before this call.
       
   265 
       
   266 @leave	KErrArgument
       
   267 		A parameter incompatible with the transformation options was previously set.
       
   268 */
       
   269 EXPORT_C void CImageTransform::SetupL()
       
   270 	{
       
   271 	ASSERT(iBody);
       
   272 	iBody->SetupL();
       
   273 	}
       
   274 
       
   275 /**
       
   276 Initiates an asynchronous image transform operation. 
       
   277 The framework will panic if no plugin has been instantiated already.
       
   278 
       
   279 @param	aStatus
       
   280 		Request status to signal when scaling is complete.
       
   281 @panic	EIllegalCallSequence
       
   282 		No plugin loaded.
       
   283 */
       
   284 EXPORT_C void CImageTransform::Transform(TRequestStatus& aStatus)
       
   285 	{
       
   286 	ASSERT(iBody);
       
   287 	iBody->Transform(aStatus);
       
   288 	}
       
   289 
       
   290 /**
       
   291 Cancels any asynchronous image transform operation currently in progress.
       
   292 */
       
   293 EXPORT_C void CImageTransform::CancelTransform()
       
   294 	{
       
   295 	ASSERT(iBody);
       
   296 	iBody->CancelTransform();
       
   297 	}
       
   298 
       
   299 /**
       
   300 Resets all SetXXX() calls so that the state is the same as that immediately 
       
   301 after a call to NewL(). Deletes the plugin if one is loaded.
       
   302 */
       
   303 EXPORT_C void CImageTransform::Reset()
       
   304 	{
       
   305 	ASSERT(iBody);
       
   306 	iBody->Reset();
       
   307 	}
       
   308 
       
   309 /**
       
   310 Gets a pointer to a plugin extension
       
   311 @panic	EIllegalCallSequence
       
   312 		No plugin loaded.
       
   313 @return	A pointer to a fully constructed CImageTransformPluginExtension
       
   314 		NULL, if there is no extension to the plugin
       
   315 */
       
   316 EXPORT_C CImageTransformPluginExtension* CImageTransform::Extension() const
       
   317 	{
       
   318 	ASSERT(iBody);
       
   319 	return iBody->Extension();
       
   320 	}
       
   321 
       
   322 /**
       
   323 Gets a pointer to a plugin extension
       
   324 @panic	EIllegalCallSequence
       
   325 		No plugin loaded.
       
   326 @param  "aExtensionUid"		
       
   327 		Uid of the required extension
       
   328 @param	"aError"
       
   329 		System wide error
       
   330 @return	A pointer to a fully constructed CImageTransformPluginExtension
       
   331 		NULL, if there is no extension to the plugin
       
   332 */
       
   333 EXPORT_C CImageTransformPluginExtension* CImageTransform::Extension(TUid aExtensionUid, TInt& aError) const
       
   334 	{
       
   335 	ASSERT(iBody);
       
   336 	return iBody->Extension(aExtensionUid, aError);
       
   337 	}