common/tools/ats/smoketest/graphics/fbserv/src/T_DataFbsColor256BitmapUtil.cpp
changeset 833 6ffc235847d0
child 872 17498133d9ad
equal deleted inserted replaced
832:9b2bf01d4d36 833:6ffc235847d0
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Symbian Foundation License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 /**
       
    19 @test
       
    20 @internalComponent
       
    21 
       
    22 This contains CT_DataFbsColor256BitmapUtil
       
    23 */
       
    24 
       
    25 //	User includes
       
    26 #include "T_DataFbsColor256BitmapUtil.h"
       
    27 #include "T_GraphicsUtil.h"
       
    28 
       
    29 /*@{*/
       
    30 ///	Parameters
       
    31 _LIT(KDither,							"dither");
       
    32 _LIT(KBitmapFrom,						"bitmap_from");
       
    33 _LIT(KBitmapTo,							"bitmap_to");
       
    34 _LIT(KPalette,							"palette");
       
    35 
       
    36 ///	Enumeration parameter values
       
    37 _LIT(KDitherNoDither,					"ENoDither");
       
    38 _LIT(KDitherFloydSteinberg,				"EFloydSteinberg");
       
    39 
       
    40 ///	Commands
       
    41 _LIT(KCmdNewL,							"NewL");
       
    42 _LIT(KCmdCopyBitmap,					"CopyBitmap");
       
    43 _LIT(KCleanup,							"~");
       
    44 /*@}*/
       
    45 
       
    46 
       
    47 /**
       
    48 * Two phase constructor
       
    49 */
       
    50 CT_DataFbsColor256BitmapUtil* CT_DataFbsColor256BitmapUtil::NewL()
       
    51 	{
       
    52 	CT_DataFbsColor256BitmapUtil* ret = new (ELeave) CT_DataFbsColor256BitmapUtil();
       
    53 	CleanupStack::PushL(ret);
       
    54 	ret->ConstructL();
       
    55 	CleanupStack::Pop(ret);
       
    56 	return ret;
       
    57 	}
       
    58 
       
    59 
       
    60 /**
       
    61 * Protected constructor. First phase construction
       
    62 */
       
    63 CT_DataFbsColor256BitmapUtil::CT_DataFbsColor256BitmapUtil()
       
    64 :	CDataWrapperBase()
       
    65 ,	iFbsColor256BitmapUtil(NULL)
       
    66 	{
       
    67 	}
       
    68 
       
    69 
       
    70 void CT_DataFbsColor256BitmapUtil::ConstructL()
       
    71 	{
       
    72 	}
       
    73 
       
    74 
       
    75 CT_DataFbsColor256BitmapUtil::~CT_DataFbsColor256BitmapUtil()
       
    76 	{
       
    77 	DestroyData();
       
    78 	}
       
    79 
       
    80 
       
    81 /**
       
    82 * Contains cleanup implementation
       
    83 */
       
    84 void CT_DataFbsColor256BitmapUtil::DestroyData()
       
    85 	{
       
    86 	delete iFbsColor256BitmapUtil;
       
    87 	iFbsColor256BitmapUtil = NULL;
       
    88 	}
       
    89 
       
    90 
       
    91 /**
       
    92 * Return a pointer to the object that the data wraps
       
    93 *
       
    94 * @return pointer to the object that the data wraps
       
    95 */
       
    96 TAny* CT_DataFbsColor256BitmapUtil::GetObject()
       
    97 	{
       
    98 	return iFbsColor256BitmapUtil;
       
    99 	}
       
   100 
       
   101 
       
   102 /**
       
   103 * Process a command read from the ini file
       
   104 *
       
   105 * @param aDataWrapper	test step requiring command to be processed
       
   106 * @param aCommand	the command to process
       
   107 * @param aSection		the entry in the ini file requiring the command to be processed
       
   108 *
       
   109 * @return ETrue if the command is processed
       
   110 */
       
   111 TBool CT_DataFbsColor256BitmapUtil::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
   112 	{
       
   113 	TBool retVal = ETrue;
       
   114 
       
   115 	if (aCommand == KCmdNewL)
       
   116 		{
       
   117 		DoCmdNewL(aSection);
       
   118 		}
       
   119 	else if (aCommand == KCmdCopyBitmap)
       
   120 		{
       
   121 		DoCmdCopyBitmapL(aSection);
       
   122 		}
       
   123 	else if (aCommand == KCleanup)
       
   124 		{
       
   125 		DestroyData();
       
   126 		}
       
   127 	else
       
   128 		{
       
   129 		retVal=EFalse;
       
   130 		}
       
   131 
       
   132 	return retVal;
       
   133 	}
       
   134 
       
   135 
       
   136 ////////////////// COMMANDS IMPLEMENTATION  ////////////////////////
       
   137 
       
   138 /** CFbsColor256BitmapUtil::NewL() call */
       
   139 void CT_DataFbsColor256BitmapUtil::DoCmdNewL(const TDesC& aSection)
       
   140 	{
       
   141 	INFO_PRINTF1(_L("CFbsColor256BitmapUtil::NewL() call"));
       
   142 
       
   143 	// cleanup if any
       
   144 	delete iFbsColor256BitmapUtil;
       
   145 	iFbsColor256BitmapUtil = NULL;
       
   146 
       
   147 	// get CPalette object passed as a parameter
       
   148 	CPalette*	palette = NULL;
       
   149 	CT_GraphicsUtil::GetPaletteL(*this, aSection, KPalette(), palette);
       
   150 
       
   151 	// call NewL()
       
   152 	TRAPD(err, iFbsColor256BitmapUtil = CFbsColor256BitmapUtil::NewL(palette));
       
   153 
       
   154 	// check error code
       
   155 	if (err != KErrNone)
       
   156 		{
       
   157 		ERR_PRINTF2(_L("CFbsColor256BitmapUtil::NewL error: %d"), err);
       
   158 		SetError(err);
       
   159 		}
       
   160 	}
       
   161 
       
   162 
       
   163 /** CFbsColor256BitmapUtil::CopyBitmap() call */
       
   164 void CT_DataFbsColor256BitmapUtil::DoCmdCopyBitmapL(const TDesC& aSection)
       
   165 	{
       
   166 	INFO_PRINTF1(_L("CFbsColor256BitmapUtil::CopyBitmap() call"));
       
   167 
       
   168 	// get source CFbsBitmap passed as a parameter
       
   169 	CFbsBitmap*	fbsBitmapFrom = NULL;
       
   170 	CT_GraphicsUtil::GetFbsBitmapL(*this, aSection, KBitmapFrom(), fbsBitmapFrom);
       
   171 
       
   172 	// get destination CFbsBitmap passed as a parameter
       
   173 	CFbsBitmap*	fbsBitmapTo = NULL;
       
   174 	CT_GraphicsUtil::GetFbsBitmapL(*this, aSection, KBitmapTo(), fbsBitmapTo);
       
   175 
       
   176 	// get dither mode from parameters
       
   177 	CFbsColor256BitmapUtil::TDither	dither;
       
   178 	if (!ReadDither(*this, aSection, dither))
       
   179 		{
       
   180 		ERR_PRINTF1(_L("No dither"));
       
   181 		SetBlockResult(EFail);
       
   182 		}
       
   183 	else
       
   184 		{
       
   185 		// call CopyBitmap()
       
   186 		TInt	err = iFbsColor256BitmapUtil->CopyBitmap(fbsBitmapTo, fbsBitmapFrom, dither);
       
   187 
       
   188 		// check error
       
   189 		if (err != KErrNone)
       
   190 			{
       
   191 			ERR_PRINTF2(_L("CopyBitmap failed with error %d"), err);
       
   192 			SetError(err);
       
   193 			}
       
   194 		}
       
   195 	}
       
   196 
       
   197 //////////////////// UTIL METHODS ////////////////////////////
       
   198 
       
   199 
       
   200 TBool CT_DataFbsColor256BitmapUtil::ReadDither(CDataWrapper& aDataWrapper, const TDesC& aSection, CFbsColor256BitmapUtil::TDither& aDither)
       
   201 	{
       
   202 	// Read dither from INI file
       
   203 	TPtrC	ditherStr;
       
   204 	TBool	found=aDataWrapper.GetStringFromConfig(aSection, KDither(), ditherStr);
       
   205 	if ( found )
       
   206 		{
       
   207 		if (ditherStr == KDitherNoDither)
       
   208 			{
       
   209 			aDither = CFbsColor256BitmapUtil::ENoDither;
       
   210 			}
       
   211 		else if (ditherStr == KDitherFloydSteinberg)
       
   212 			{
       
   213 			aDither = CFbsColor256BitmapUtil::EFloydSteinberg;
       
   214 			}
       
   215 		else
       
   216 			{
       
   217         	TInt	dither = 0;
       
   218         	found = aDataWrapper.GetIntFromConfig(aSection, KDither(), dither);
       
   219 			if ( found )
       
   220 				{
       
   221 	        	aDither = (CFbsColor256BitmapUtil::TDither) dither;
       
   222 				}
       
   223 			}
       
   224 		}
       
   225 
       
   226 	return found;
       
   227 	}