graphicstest/uibench/src/tdisplaymode_mapping.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2007-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 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code 
       
    20 */
       
    21 
       
    22 #include "tdisplaymode_mapping.h"
       
    23 
       
    24 const TPtrC KPixelFormatNames[] = 
       
    25 	{
       
    26 	_L("EUidPixelFormatUnknown"),
       
    27 	_L("EUidPixelFormatXRGB_8888"),
       
    28 	_L("EUidPixelFormatARGB_8888"),
       
    29 	_L("EUidPixelFormatARGB_8888_PRE"),
       
    30 	_L("EUidPixelFormatRGB_888"),
       
    31 	_L("EUidPixelFormatRGB_565"),
       
    32 	_L("EUidPixelFormatP_8"),
       
    33 	_L("EUidPixelFormatA_8"),
       
    34 	_L("EUidPixelFormatP_2"),
       
    35 	_L("EUidPixelFormatP_1"),
       
    36 	};
       
    37 
       
    38 /**
       
    39 Convert the string of pixel format to TDisplayMode
       
    40 @param aPixelformatString The input string of pixel format
       
    41 @return On return, it contains a display mode enum value
       
    42  */
       
    43 TDisplayMode TDisplayModeMapping::ConvertPixelformatStringToDisplayMode(const TPtrC aPixelformatString)
       
    44 	{
       
    45 	TUidPixelFormat format = ConvertPixelformatStringToPixelFormat(aPixelformatString);
       
    46 	
       
    47 	return MapPixelFormatToDisplayMode(format);	
       
    48 	}
       
    49 
       
    50 /**
       
    51 Convert the string of pixel format to TUidPixelFormat
       
    52 @param aPixelformatString The input string of pixel format
       
    53 @return On return, it contains a pixel format enum value
       
    54  */
       
    55 TUidPixelFormat TDisplayModeMapping::ConvertPixelformatStringToPixelFormat(const TPtrC aPixelformatString)
       
    56 	{
       
    57 	TUidPixelFormat format = EUidPixelFormatUnknown;
       
    58 	
       
    59 	if (aPixelformatString == KPixelFormatNames[1])
       
    60 		{
       
    61 		format =  EUidPixelFormatXRGB_8888;
       
    62 		}
       
    63 	if (aPixelformatString == KPixelFormatNames[2])
       
    64 		{
       
    65 		format =  EUidPixelFormatARGB_8888;
       
    66 		}
       
    67 	if (aPixelformatString == KPixelFormatNames[3])
       
    68 		{
       
    69 		format =  EUidPixelFormatARGB_8888_PRE;
       
    70 		}
       
    71 	if (aPixelformatString == KPixelFormatNames[4])
       
    72 		{
       
    73 		format =  EUidPixelFormatRGB_888;
       
    74 		}
       
    75 	if (aPixelformatString == KPixelFormatNames[5])
       
    76 		{
       
    77 		format =  EUidPixelFormatRGB_565;
       
    78 		}
       
    79 	if (aPixelformatString == KPixelFormatNames[6])
       
    80 		{
       
    81 		format =  EUidPixelFormatP_8;
       
    82 		}
       
    83 	if (aPixelformatString == KPixelFormatNames[7])
       
    84 		{
       
    85 		format =  EUidPixelFormatA_8;
       
    86 		}
       
    87 	if (aPixelformatString == KPixelFormatNames[8])
       
    88 		{
       
    89 		format =  EUidPixelFormatP_2;
       
    90 		}
       
    91 	if (aPixelformatString == KPixelFormatNames[9])
       
    92 		{
       
    93 		format =  EUidPixelFormatP_1;
       
    94 		}
       
    95 	
       
    96 	return format;
       
    97 	}
       
    98 
       
    99 /*
       
   100 Convert the pixel format enum to a string
       
   101 @param aFormat The pixel format enum
       
   102 @return On return, it contains the pixel format string
       
   103  */
       
   104 TPtrC TDisplayModeMapping::ConvertPixelformatToPixelFormatString(const TUidPixelFormat aFormat)
       
   105 	{
       
   106 	TPtrC pixelFormatString(KPixelFormatNames[0]);
       
   107 	
       
   108 	if (aFormat == EUidPixelFormatXRGB_8888)
       
   109 		{
       
   110 		pixelFormatString.Set(KPixelFormatNames[1]);
       
   111 		}
       
   112 	if (aFormat == EUidPixelFormatARGB_8888)
       
   113 		{
       
   114 		pixelFormatString.Set(KPixelFormatNames[2]);
       
   115 		}
       
   116 	if (aFormat == EUidPixelFormatARGB_8888_PRE)
       
   117 		{
       
   118 		pixelFormatString.Set(KPixelFormatNames[3]);
       
   119 		}
       
   120 	if (aFormat == EUidPixelFormatRGB_888)
       
   121 		{
       
   122 		pixelFormatString.Set(KPixelFormatNames[4]);
       
   123 		}
       
   124 	if (aFormat == EUidPixelFormatRGB_565)
       
   125 		{
       
   126 		pixelFormatString.Set(KPixelFormatNames[5]);
       
   127 		}
       
   128 	if (aFormat == EUidPixelFormatP_8)
       
   129 		{
       
   130 		pixelFormatString.Set(KPixelFormatNames[6]);
       
   131 		}
       
   132 	if (aFormat == EUidPixelFormatA_8)
       
   133 		{
       
   134 		pixelFormatString.Set(KPixelFormatNames[7]);
       
   135 		}
       
   136 	if (aFormat == EUidPixelFormatP_2)
       
   137 		{
       
   138 		pixelFormatString.Set(KPixelFormatNames[8]);
       
   139 		}
       
   140 	if (aFormat == EUidPixelFormatP_1)
       
   141 		{
       
   142 		pixelFormatString.Set(KPixelFormatNames[9]);
       
   143 		}
       
   144 	
       
   145 	return pixelFormatString;
       
   146 	}
       
   147 
       
   148 /*
       
   149 Map pixel format enum to display mode enum
       
   150 @param aFormat The pixel format enum
       
   151 @return On return, it contains the display mode enum
       
   152  */
       
   153 TDisplayMode TDisplayModeMapping::MapPixelFormatToDisplayMode(const TUidPixelFormat aFormat)
       
   154 	{
       
   155 	TDisplayMode mode;
       
   156 	
       
   157 	switch(aFormat)
       
   158 	{
       
   159 	/** Display mode with alpha (24bpp colour plus 8bpp alpha) */
       
   160 	case EUidPixelFormatXRGB_8888:
       
   161 	//case EUidPixelFormatBGRX_8888:
       
   162 	//case EUidPixelFormatXBGR_8888: 
       
   163 		mode = EColor16MU; 
       
   164 		break;
       
   165 	
       
   166 	/** Display mode with alpha (24bpp colour plus 8bpp alpha) */
       
   167 	case EUidPixelFormatARGB_8888:
       
   168 	//case EUidPixelFormatBGRA_8888:
       
   169 	//case EUidPixelFormatABGR_8888: 
       
   170 		mode = EColor16MA; 
       
   171 		break;
       
   172 
       
   173 	/** Pre-multiplied Alpha display mode (24bpp color multiplied with the alpha channel value, plus 8bpp alpha) */
       
   174 	case EUidPixelFormatARGB_8888_PRE:
       
   175 	//case EUidPixelFormatABGR_8888_PRE:
       
   176 	//case EUidPixelFormatBGRA_8888_PRE: 
       
   177 		mode = EColor16MAP; 
       
   178 		break;
       
   179 
       
   180 	/** True colour display mode (24 bpp) */
       
   181 	//case EUidPixelFormatBGR_888:
       
   182 	case EUidPixelFormatRGB_888:
       
   183 		mode = EColor16M; 
       
   184 		break;
       
   185 	
       
   186 	/** 64,000 colour display mode (16 bpp) */
       
   187 	case EUidPixelFormatRGB_565:
       
   188 	//case EUidPixelFormatBGR_565:
       
   189 	//case EUidPixelFormatARGB_1555:
       
   190 	//case EUidPixelFormatXRGB_1555:
       
   191 	//case EUidPixelFormatARGB_4444:
       
   192 	//case EUidPixelFormatARGB_8332:
       
   193 	//case EUidPixelFormatBGRX_5551:
       
   194 	//case EUidPixelFormatBGRA_5551:	
       
   195 	//case EUidPixelFormatBGRA_4444:
       
   196 	//case EUidPixelFormatBGRX_4444:
       
   197 	//case EUidPixelFormatAP_88:
       
   198 	//case EUidPixelFormatXRGB_4444:
       
   199 	//case EUidPixelFormatXBGR_4444:
       
   200 		mode = EColor64K; 
       
   201 		break;
       
   202 	
       
   203 	/** 256 colour display mode (8 bpp) */
       
   204 	//case EUidPixelFormatRGB_332:
       
   205 	//case EUidPixelFormatBGR_332:
       
   206 	case EUidPixelFormatP_8:
       
   207 		mode = EColor256;
       
   208 		break;
       
   209 	
       
   210 	/** 256 grayscales display mode (8 bpp) */	
       
   211 	case EUidPixelFormatA_8:
       
   212 		mode = EGray256;
       
   213 		break;
       
   214 
       
   215 	/** Low colour EGA 16 colour display mode (4 bpp) */
       
   216 	//case EUidPixelFormatP_4:
       
   217 	//	mode = EColor16;
       
   218 	//  mode = EGray16 ???
       
   219 	//	break;
       
   220 		
       
   221 	/** Four grayscales display mode (2 bpp) */
       
   222 	case EUidPixelFormatP_2:
       
   223 		mode = EGray4;
       
   224 		break;
       
   225 		
       
   226 	/** Monochrome display mode (1 bpp) */
       
   227 	case EUidPixelFormatP_1:
       
   228 	//case EUidPixelFormatBW_1:
       
   229 		mode = EGray2;
       
   230 		break;
       
   231 
       
   232 	// Unknown display mode
       
   233 	default:
       
   234 	case EUidPixelFormatUnknown:
       
   235 	//case EUidPixelFormatYUV_444Interleaved:
       
   236 	//case EUidPixelFormatYUV_444Planar:
       
   237 	//case EUidPixelFormatYUV_420Interleaved:
       
   238 	//case EUidPixelFormatYUV_420Planar:
       
   239 	//case EUidPixelFormatYUV_420PlanarReversed:
       
   240 	//case EUidPixelFormatYUV_420SemiPlanar:
       
   241 	//case EUidPixelFormatYUV_422Interleaved:
       
   242 	//case EUidPixelFormatYUV_422Planar:
       
   243 	//case EUidPixelFormatYUV_422Reversed:
       
   244 	//case EUidPixelFormatYUV_422SemiPlanar:
       
   245 	//case EUidPixelFormatYUV_422InterleavedReversed:
       
   246 	//case EUidPixelFormatYYUV_422Interleaved:
       
   247 	//case EUidPixelFormatARGB_2101010:
       
   248 	//case EUidPixelFormatABGR_2101010:
       
   249 		mode = ENone; 
       
   250 		break;
       
   251 	}
       
   252 	
       
   253 	return mode;
       
   254 	}
       
   255 
       
   256 /*
       
   257 Map display mode enum to pixel formation enum
       
   258 @param aDisplayMode The display mode enum
       
   259 @return On return, it contains the pixel format enum
       
   260  */
       
   261 TUidPixelFormat TDisplayModeMapping::MapDisplayModeToPixelFormat(const TDisplayMode aDisplayMode)
       
   262 	{
       
   263 	TUidPixelFormat format;
       
   264 	
       
   265 	switch(aDisplayMode)
       
   266 	{
       
   267 	/** Display mode with alpha (24bpp colour plus 8bpp alpha) */
       
   268 	case EColor16MU:
       
   269 	//case EUidPixelFormatBGRX_8888:
       
   270 	//case EUidPixelFormatXBGR_8888: 
       
   271 		format = EUidPixelFormatXRGB_8888; 
       
   272 		break;
       
   273 	
       
   274 	/** Display mode with alpha (24bpp colour plus 8bpp alpha) */
       
   275 	case EColor16MA:
       
   276 	//case EUidPixelFormatBGRA_8888:
       
   277 	//case EUidPixelFormatABGR_8888: 
       
   278 		format = EUidPixelFormatARGB_8888; 
       
   279 		break;
       
   280 
       
   281 	/** Pre-multiplied Alpha display mode (24bpp color multiplied with the alpha channel value, plus 8bpp alpha) */
       
   282 	case EColor16MAP:
       
   283 	//case EUidPixelFormatABGR_8888_PRE:
       
   284 	//case EUidPixelFormatBGRA_8888_PRE: 
       
   285 		format = EUidPixelFormatARGB_8888_PRE; 
       
   286 		break;
       
   287 
       
   288 	/** True colour display mode (24 bpp) */
       
   289 	//case EUidPixelFormatBGR_888:
       
   290 	case EColor16M:
       
   291 		format = EUidPixelFormatRGB_888; 
       
   292 		break;
       
   293 	
       
   294 	/** 64,000 colour display mode (16 bpp) */
       
   295 	case EColor64K:
       
   296 	//case EUidPixelFormatBGR_565:
       
   297 	//case EUidPixelFormatARGB_1555:
       
   298 	//case EUidPixelFormatXRGB_1555:
       
   299 	//case EUidPixelFormatARGB_4444:
       
   300 	//case EUidPixelFormatARGB_8332:
       
   301 	//case EUidPixelFormatBGRX_5551:
       
   302 	//case EUidPixelFormatBGRA_5551:	
       
   303 	//case EUidPixelFormatBGRA_4444:
       
   304 	//case EUidPixelFormatBGRX_4444:
       
   305 	//case EUidPixelFormatAP_88:
       
   306 	//case EUidPixelFormatXRGB_4444:
       
   307 	//case EUidPixelFormatXBGR_4444:
       
   308 		format = EUidPixelFormatRGB_565; 
       
   309 		break;
       
   310 	
       
   311 	/** 256 colour display mode (8 bpp) */
       
   312 	//case EUidPixelFormatRGB_332:
       
   313 	//case EUidPixelFormatBGR_332:
       
   314 	case EColor256:
       
   315 		format = EUidPixelFormatP_8;
       
   316 		break;
       
   317 	
       
   318 	/** 256 grayscales display mode (8 bpp) */	
       
   319 	case EGray256:
       
   320 		format = EUidPixelFormatA_8;
       
   321 		break;
       
   322 
       
   323 	/** Low colour EGA 16 colour display mode (4 bpp) */
       
   324 	//case EUidPixelFormatP_4:
       
   325 	//	mode = EColor16;
       
   326 	//  mode = EGray16 ???
       
   327 	//	break;
       
   328 		
       
   329 	/** Four grayscales display mode (2 bpp) */
       
   330 	case EGray4:
       
   331 		format = EUidPixelFormatP_2;
       
   332 		break;
       
   333 		
       
   334 	/** Monochrome display mode (1 bpp) */
       
   335 	case EGray2:
       
   336 	//case EUidPixelFormatBW_1:
       
   337 		format = EUidPixelFormatP_1;
       
   338 		break;
       
   339 
       
   340 	// Unknown display mode
       
   341 	default:
       
   342 	case ENone:
       
   343 	//case EUidPixelFormatYUV_444Interleaved:
       
   344 	//case EUidPixelFormatYUV_444Planar:
       
   345 	//case EUidPixelFormatYUV_420Interleaved:
       
   346 	//case EUidPixelFormatYUV_420Planar:
       
   347 	//case EUidPixelFormatYUV_420PlanarReversed:
       
   348 	//case EUidPixelFormatYUV_420SemiPlanar:
       
   349 	//case EUidPixelFormatYUV_422Interleaved:
       
   350 	//case EUidPixelFormatYUV_422Planar:
       
   351 	//case EUidPixelFormatYUV_422Reversed:
       
   352 	//case EUidPixelFormatYUV_422SemiPlanar:
       
   353 	//case EUidPixelFormatYUV_422InterleavedReversed:
       
   354 	//case EUidPixelFormatYYUV_422Interleaved:
       
   355 	//case EUidPixelFormatARGB_2101010:
       
   356 	//case EUidPixelFormatABGR_2101010:
       
   357 		format = EUidPixelFormatUnknown; 
       
   358 		break;
       
   359 	}
       
   360 	
       
   361 	return format;
       
   362 	}
       
   363 
       
   364 /**
       
   365  Converts pixel format strings to pixel format enums.
       
   366  @param aPixelFormatInput The pixel format string for testing
       
   367  @param aPixelFormatArray An array of TUidPixelFormats as output.
       
   368  */
       
   369 void TDisplayModeMapping::ConvertPixelFormats(TPtrC aPixelFormatInput, RArray<TUidPixelFormat>& aPixelFormatArray)
       
   370 	{
       
   371 	TPtrC tempBuf = aPixelFormatInput;
       
   372 	TInt position = tempBuf.Find(_L(","));
       
   373 			
       
   374 	while(KErrNotFound != position)
       
   375 		{
       
   376 		aPixelFormatArray.Append(TDisplayModeMapping::ConvertPixelformatStringToPixelFormat(tempBuf.Left(position)));
       
   377 		tempBuf.Set(tempBuf.Mid(position + 2));
       
   378 		position = tempBuf.Find(_L(","));
       
   379 		}	
       
   380 
       
   381 	if (position == KErrNotFound)
       
   382 		{
       
   383 		aPixelFormatArray.Append(TDisplayModeMapping::ConvertPixelformatStringToPixelFormat(tempBuf));
       
   384 		}
       
   385 	}
       
   386