imaging/imagingfws/src/ImageProcessorUtil.cpp
changeset 0 5752a19fdefe
equal deleted inserted replaced
-1:000000000000 0:5752a19fdefe
       
     1 // Copyright (c) 1999-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 <icl/imageprocessor.h>
       
    17 #include "ImageProcessorPriv.h"
       
    18 #include "ImageUtils.h"
       
    19 #include "ImageClientMain.h"
       
    20 
       
    21 //
       
    22 // ImageProcessorUtility
       
    23 //
       
    24 
       
    25 /**
       
    26 Static function to calculate a reduction factor based on the input parameters.
       
    27 This function is deprecated. It is recommended to use CImageDecoder::ReductionFactor  or CImageReadCodec::ReductionFactor(for Plugin writers only) to calculate
       
    28 the reduction factor and then use CImageDecoder::ReducedSize to find the size of the decoded bitmap. 
       
    29 
       
    30 @param  aOriginalSize
       
    31         A reference to the original size of an item.
       
    32 @param  aReducedSize
       
    33         A reference to the new size of an item.
       
    34 @deprecated - Replaced by CImageDecoder::ReductionFactor
       
    35 @return The reduction factor.
       
    36 
       
    37 @see CImageDecoder::ReductionFactor
       
    38 @see CImageDecoder::ReducedSize
       
    39 @see CImageReadCodec::ReductionFactor
       
    40 */
       
    41 EXPORT_C TInt ImageProcessorUtility::ReductionFactor(const TSize& aOriginalSize,const TSize& aReducedSize)
       
    42 	{
       
    43 	if( (aReducedSize.iWidth<=0) || (aReducedSize.iHeight<=0))
       
    44 		return 0;
       
    45 
       
    46 	TInt reductionFactor = 0;
       
    47 
       
    48 	while( ((aOriginalSize.iWidth-1)>>reductionFactor) >= aReducedSize.iWidth || ((aOriginalSize.iHeight-1)>>reductionFactor) >= aReducedSize.iHeight)
       
    49 		reductionFactor++;
       
    50 
       
    51 	return reductionFactor;
       
    52 	}
       
    53 
       
    54 
       
    55 /**
       
    56 Static factory function for creating instances of CImageProcessor derived classes.
       
    57 This fuction is deprecated. It is recommended for plugin writers to use default implementation of CImageReadCodec::ReductionFactor to calculate the
       
    58 reduction factor and then use NewImageProcessorL(const CFbsBitmap& aBitmap,TInt aReductionFactor,TDisplayMode aImageDisplayMode, TBool aDisableErrorDiffusion)
       
    59 
       
    60 @param  aBitmap
       
    61         A reference to the bitmap used.
       
    62 @param  aImageSize
       
    63         The size of image to use.
       
    64 @param  aImageDisplayMode
       
    65         The display mode to use.
       
    66 @param  aDisableErrorDiffusion
       
    67         A flag indicating whether error diffusion should be disabled.
       
    68 @deprecated - Replaced by CImageReadCodec::ReductionFactor & NewImageProcessorL(const CFbsBitmap& aBitmap,TInt aReductionFactor,TDisplayMode aImageDisplayMode, TBool aDisableErrorDiffusion)
       
    69 @return A pointer to a fully constructed CImageProcessor derived object.
       
    70 
       
    71 @see CImageReadCodec::ReductionFactor
       
    72 @see ImageProcessorUtility::NewImageProcessorL(const CFbsBitmap& aBitmap,TInt aReductionFactor,TDisplayMode aImageDisplayMode, TBool aDisableErrorDiffusion)
       
    73 */
       
    74 EXPORT_C CImageProcessor* ImageProcessorUtility::NewImageProcessorL(const CFbsBitmap& aBitmap,const TSize& aImageSize,TDisplayMode aImageDisplayMode, TBool aDisableErrorDiffusion)
       
    75 	{
       
    76 	TInt reductionFactor = ImageProcessorUtility::ReductionFactor(aImageSize,aBitmap.SizeInPixels());
       
    77 	return NewImageProcessorL(aBitmap,reductionFactor, aImageDisplayMode, aDisableErrorDiffusion);
       
    78 	}
       
    79 
       
    80 /**
       
    81 Static factory function for creating instances of CImageProcessor derived classes.
       
    82 
       
    83 @param  aBitmap
       
    84         A reference to the bitmap used.
       
    85 @param  aReductionFactor
       
    86         The value indicating how much to shrink the bitmap.
       
    87 @param  aImageDisplayMode
       
    88         The display mode to use.
       
    89 @param  aDisableErrorDiffusion
       
    90         A flag indicating whether error diffusion should be disabled.
       
    91 
       
    92 @return A pointer to a fully constructed CImageProcessor derived object.
       
    93 */
       
    94 EXPORT_C CImageProcessor* ImageProcessorUtility::NewImageProcessorL(const CFbsBitmap& aBitmap,TInt aReductionFactor,TDisplayMode aImageDisplayMode, TBool aDisableErrorDiffusion)
       
    95 	{
       
    96 	TBool useErrorDiffuser = EFalse;
       
    97 	if(!aDisableErrorDiffusion)
       
    98 		{
       
    99 		useErrorDiffuser = ImageProcessorUtility::UseErrorDiffuser(aBitmap.DisplayMode(), aImageDisplayMode);
       
   100 		}
       
   101 	
       
   102 	TBool monochrome = ImageProcessorUtility::IsMonochrome(aBitmap.DisplayMode(), aImageDisplayMode);
       
   103 	
       
   104 	CImageProcessorExtension* imageProcessor = NULL;
       
   105 	
       
   106 	if(monochrome)
       
   107 		{
       
   108 		if(useErrorDiffuser)
       
   109 			{
       
   110 			imageProcessor = CMonochromeErrorDiffuser::NewL();
       
   111 			}
       
   112 		else
       
   113 			{
       
   114 			imageProcessor = CMonochromePixelWriter::NewL();
       
   115 			}
       
   116 		}
       
   117 	else
       
   118 		{
       
   119 		if(useErrorDiffuser)
       
   120 			{
       
   121 			imageProcessor = CErrorDiffuser::NewL();
       
   122 			}
       
   123 		else
       
   124 			{
       
   125 			imageProcessor = CPixelWriter::NewL();
       
   126 			}
       
   127 		}
       
   128 
       
   129 	if(aReductionFactor)
       
   130 		{
       
   131 		CleanupStack::PushL(imageProcessor);
       
   132 
       
   133 		if(monochrome)
       
   134 			{
       
   135 			imageProcessor = CMonochromeThumbnailProcessor::NewL(imageProcessor,aReductionFactor);
       
   136 			}
       
   137 		else
       
   138 			{
       
   139 			imageProcessor = CThumbnailProcessor::NewL(imageProcessor,aReductionFactor);
       
   140 			}
       
   141 
       
   142 		CleanupStack::Pop();
       
   143 		}
       
   144 
       
   145 	return imageProcessor;
       
   146 	}
       
   147 
       
   148 /**
       
   149 @publishedAll
       
   150 @released
       
   151 
       
   152 Static factory function for creating instances of CImageProcessorExtension derived classes.
       
   153 
       
   154 @param  aBitmap
       
   155         A reference to the bitmap used.
       
   156 @param  aReductionFactor
       
   157         The value indicating how much to shrink the bitmap.
       
   158 @param  aImageDisplayMode
       
   159         The display mode to use.
       
   160 @param  aDisableErrorDiffusion
       
   161         A flag indicating whether error diffusion should be disabled.
       
   162 
       
   163 @return A pointer to a fully constructed CImageProcessorExtension derived object.
       
   164 */
       
   165 EXPORT_C CImageProcessorExtension* ImageProcessorUtility::NewImageProcessorExtensionL(const CFbsBitmap& aBitmap,TInt aReductionFactor,TDisplayMode aImageDisplayMode, TBool aDisableErrorDiffusion)
       
   166 	{
       
   167 	TBool useErrorDiffuser = EFalse;
       
   168 	if(!aDisableErrorDiffusion)
       
   169 		{
       
   170 		useErrorDiffuser = ImageProcessorUtility::UseErrorDiffuser(aBitmap.DisplayMode(), aImageDisplayMode);
       
   171 		}
       
   172 	
       
   173 	TBool monochrome = ImageProcessorUtility::IsMonochrome(aBitmap.DisplayMode(), aImageDisplayMode);
       
   174 	
       
   175 	CImageProcessorExtension* imageProcessor = NULL;
       
   176 	
       
   177 	if(monochrome)
       
   178 		{
       
   179 		if(useErrorDiffuser)
       
   180 			{
       
   181 			imageProcessor = CMonochromeErrorDiffuser::NewL();
       
   182 			}
       
   183 		else
       
   184 			{
       
   185 			imageProcessor = CMonochromePixelWriter::NewL();
       
   186 			}
       
   187 		}
       
   188 	else
       
   189 		{
       
   190 		if(useErrorDiffuser)
       
   191 			{
       
   192 			imageProcessor = CErrorDiffuser::NewL();
       
   193 			}
       
   194 		else
       
   195 			{
       
   196 			imageProcessor = CPixelWriter::NewL();
       
   197 			}
       
   198 		}
       
   199 
       
   200 	if(aReductionFactor)
       
   201 		{
       
   202 		CleanupStack::PushL(imageProcessor);
       
   203 
       
   204 		if(monochrome)
       
   205 			{
       
   206 			imageProcessor = CMonochromeThumbnailProcessor::NewL(imageProcessor,aReductionFactor);
       
   207 			}
       
   208 		else
       
   209 			{
       
   210 			imageProcessor = CThumbnailProcessor::NewL(imageProcessor,aReductionFactor);
       
   211 			}
       
   212 
       
   213 		CleanupStack::Pop();
       
   214 		}
       
   215 
       
   216 	return imageProcessor;
       
   217 	}
       
   218 
       
   219 /**
       
   220 Private static funcion to determine whether an error diffusing image processor is to be created.
       
   221 */
       
   222 TBool ImageProcessorUtility::UseErrorDiffuser(const TDisplayMode& aBitmapDisplayMode, const TDisplayMode& aImageDisplayMode)
       
   223 	{
       
   224 	TBool useErrorDiffuser = EFalse;
       
   225 
       
   226 	if((aBitmapDisplayMode != EGray256) && 
       
   227 		(aBitmapDisplayMode != EColor16M) && 
       
   228 		(aBitmapDisplayMode != ERgb) && 
       
   229 		(aBitmapDisplayMode != EColor16MU) &&
       
   230 		(aBitmapDisplayMode != EColor16MA))
       
   231 		{
       
   232 		switch(aImageDisplayMode)
       
   233 			{
       
   234 			case EGray2:
       
   235 				break;
       
   236 
       
   237 			case EGray4:
       
   238 				if(aBitmapDisplayMode < aImageDisplayMode)
       
   239 					{
       
   240 					useErrorDiffuser = ETrue;
       
   241 					}
       
   242 				break;
       
   243 
       
   244 			case EGray16:
       
   245 				if((aBitmapDisplayMode < aImageDisplayMode)||(aBitmapDisplayMode == EColor16))
       
   246 					{
       
   247 					useErrorDiffuser = ETrue;
       
   248 					}
       
   249 				break;
       
   250 
       
   251 			case EGray256:
       
   252 				useErrorDiffuser = ETrue;
       
   253 				break;
       
   254 
       
   255 			case EColor16:
       
   256 				if(aBitmapDisplayMode < aImageDisplayMode)
       
   257 					{
       
   258 					useErrorDiffuser = ETrue;
       
   259 					}
       
   260 				break;
       
   261 
       
   262 			case EColor256:
       
   263 				if(aBitmapDisplayMode < aImageDisplayMode)
       
   264 					{
       
   265 					useErrorDiffuser = ETrue;
       
   266 					}
       
   267 				break;
       
   268 
       
   269 			case EColor64K:
       
   270 				if(aBitmapDisplayMode == EColor4K)
       
   271 					{
       
   272 					useErrorDiffuser = ETrue;
       
   273 					}
       
   274 				if(aBitmapDisplayMode < aImageDisplayMode)
       
   275 					{
       
   276 					useErrorDiffuser = ETrue;
       
   277 					}
       
   278 				break;
       
   279 
       
   280 			case EColor16M:
       
   281 			case ERgb:
       
   282 			case EColor16MU:
       
   283 				useErrorDiffuser = ETrue;
       
   284 				break;
       
   285 
       
   286 			case EColor4K:
       
   287 				if(aBitmapDisplayMode < EColor64K)
       
   288 					{
       
   289 					useErrorDiffuser = ETrue;
       
   290 					}
       
   291 				break;
       
   292 
       
   293 			default:
       
   294 				break;
       
   295 			}
       
   296 		}
       
   297 	return useErrorDiffuser;
       
   298 	}
       
   299 
       
   300 /**
       
   301 Private static funcion to determine whether a monochrome image processor is to be created.
       
   302 */
       
   303 TBool ImageProcessorUtility::IsMonochrome(const TDisplayMode& aBitmapDisplayMode, const TDisplayMode& aImageDisplayMode)
       
   304 	{
       
   305 	return aBitmapDisplayMode <= EGray256 || aImageDisplayMode <= EGray256;
       
   306 	}
       
   307 	
       
   308 /**
       
   309 Intended for future proofing - will panic if called
       
   310 
       
   311 @panic  EReservedCall
       
   312 */
       
   313 EXPORT_C void CImageProcessor::ReservedVirtual1()
       
   314 	{
       
   315 	Panic(EReservedCall);
       
   316 	}
       
   317 
       
   318 /**
       
   319 Intended for future proofing - will panic if called
       
   320 
       
   321 @panic  EReservedCall
       
   322 */
       
   323 EXPORT_C void CImageProcessor::ReservedVirtual2()
       
   324 	{
       
   325 	Panic(EReservedCall);
       
   326 	}
       
   327 
       
   328 /**
       
   329 Intended for future proofing - will panic if called
       
   330 
       
   331 @panic  EReservedCall
       
   332 */
       
   333 EXPORT_C void CImageProcessor::ReservedVirtual3()
       
   334 	{
       
   335 	Panic(EReservedCall);
       
   336 	}
       
   337 
       
   338 /**
       
   339 Intended for future proofing - will panic if called
       
   340 
       
   341 @panic  EReservedCall
       
   342 */
       
   343 EXPORT_C void CImageProcessor::ReservedVirtual4()
       
   344 	{
       
   345 	Panic(EReservedCall);
       
   346 	}
       
   347 
       
   348 //
       
   349 // CErrorDiffuser
       
   350 //
       
   351 
       
   352 /**
       
   353  * @internalComponent
       
   354  * Static factory function to create CErrorDiffuser objects.
       
   355  *
       
   356  * @return  Pointer to a fully constructed CErrorDiffuser object. 
       
   357  */
       
   358 //Exported for CBitmapConverter in MediaClientImage
       
   359 EXPORT_C CErrorDiffuser* CErrorDiffuser::NewL()
       
   360 	{
       
   361 	return new(ELeave) CErrorDiffuser;
       
   362 	}
       
   363 
       
   364