os/graphics/graphicsdeviceinterface/directgdi/test/tdisplaymode_mapping.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
 @internalComponent - Internal Symbian test code 
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include "tdisplaymode_mapping.h"
sl@0
    23
sl@0
    24
const TPtrC KPixelFormatNames[] = 
sl@0
    25
	{
sl@0
    26
	_L("EUidPixelFormatUnknown"),              //0
sl@0
    27
	_L("EUidPixelFormatXRGB_8888"),            //1
sl@0
    28
	_L("EUidPixelFormatARGB_8888"),            //2
sl@0
    29
	_L("EUidPixelFormatARGB_8888_PRE"),        //3
sl@0
    30
	_L("EUidPixelFormatRGB_888"),              //4
sl@0
    31
	_L("EUidPixelFormatA_8"),                  //5
sl@0
    32
	_L("EUidPixelFormatRGB_565"),              //6
sl@0
    33
	_L("EUidPixelFormatXRGB_4444"),            //7
sl@0
    34
	_L("EUidPixelFormatP_8"),                  //8
sl@0
    35
	_L("EUidPixelFormatP_4"),                  //9
sl@0
    36
	_L("EUidPixelFormatL_8"),                  //10
sl@0
    37
	_L("EUidPixelFormatL_4"),                  //11
sl@0
    38
	_L("EUidPixelFormatL_2"),                  //12
sl@0
    39
	_L("EUidPixelFormatL_1"),                  //13
sl@0
    40
	};
sl@0
    41
sl@0
    42
const TPtrC KShortPixelFormatNames[] = 
sl@0
    43
	{
sl@0
    44
	_L("Unknown"),              //0
sl@0
    45
	_L("XRGB_8888"),            //1
sl@0
    46
	_L("ARGB_8888"),            //2
sl@0
    47
	_L("ARGB_8888_PRE"),        //3
sl@0
    48
	_L("RGB_888"),              //4
sl@0
    49
	_L("A_8"),                  //5
sl@0
    50
	_L("RGB_565"),              //6
sl@0
    51
	_L("XRGB_4444"),            //7
sl@0
    52
	_L("P_8"),                  //8
sl@0
    53
	_L("P_4"),                  //9
sl@0
    54
	_L("L_8"),                  //10
sl@0
    55
	_L("L_4"),                  //11
sl@0
    56
	_L("L_2"),                  //12
sl@0
    57
	_L("L_1"),                  //13
sl@0
    58
	};
sl@0
    59
sl@0
    60
/**
sl@0
    61
Convert the string of pixel format to TDisplayMode
sl@0
    62
@param aPixelformatString The input string of pixel format
sl@0
    63
@return On return, it contains a display mode enum value
sl@0
    64
 */
sl@0
    65
TDisplayMode TDisplayModeMapping::ConvertPixelFormatStringToDisplayMode(const TPtrC aPixelformatString)
sl@0
    66
	{
sl@0
    67
	TUidPixelFormat format = ConvertPixelFormatStringToPixelFormat(aPixelformatString);
sl@0
    68
	
sl@0
    69
	return MapPixelFormatToDisplayMode(format);	
sl@0
    70
	}
sl@0
    71
sl@0
    72
/**
sl@0
    73
Converts a pixel format string to TUidPixelFormat
sl@0
    74
@see ConvertPixelformatToShortPixelFormatString()
sl@0
    75
@param aPixelformatString The pixel format string to convert
sl@0
    76
@return Returns a pixel format enum value TUidPixelFormat
sl@0
    77
 */
sl@0
    78
TUidPixelFormat TDisplayModeMapping::ConvertPixelFormatStringToPixelFormat(const TPtrC aPixelformatString)
sl@0
    79
	{
sl@0
    80
	TUidPixelFormat format = EUidPixelFormatUnknown;
sl@0
    81
	
sl@0
    82
	if (aPixelformatString == KPixelFormatNames[1])
sl@0
    83
		{
sl@0
    84
		format =  EUidPixelFormatXRGB_8888;
sl@0
    85
		}
sl@0
    86
	else if (aPixelformatString == KPixelFormatNames[2])
sl@0
    87
		{
sl@0
    88
		format =  EUidPixelFormatARGB_8888;
sl@0
    89
		}
sl@0
    90
	else if (aPixelformatString == KPixelFormatNames[3])
sl@0
    91
		{
sl@0
    92
		format =  EUidPixelFormatARGB_8888_PRE;
sl@0
    93
		}
sl@0
    94
	else if (aPixelformatString == KPixelFormatNames[4])
sl@0
    95
		{
sl@0
    96
		format =  EUidPixelFormatRGB_888;
sl@0
    97
		}
sl@0
    98
	else if (aPixelformatString == KPixelFormatNames[5])
sl@0
    99
		{
sl@0
   100
		format =  EUidPixelFormatA_8;
sl@0
   101
		}
sl@0
   102
	else if (aPixelformatString == KPixelFormatNames[6])
sl@0
   103
		{
sl@0
   104
		format =  EUidPixelFormatRGB_565;
sl@0
   105
		}
sl@0
   106
	else if (aPixelformatString == KPixelFormatNames[7])
sl@0
   107
		{
sl@0
   108
		format =  EUidPixelFormatXRGB_4444;
sl@0
   109
		}
sl@0
   110
	else if (aPixelformatString == KPixelFormatNames[8])
sl@0
   111
		{
sl@0
   112
		format =  EUidPixelFormatP_8;
sl@0
   113
		}
sl@0
   114
	else if (aPixelformatString == KPixelFormatNames[9])
sl@0
   115
		{
sl@0
   116
		format =  EUidPixelFormatP_4;
sl@0
   117
		}
sl@0
   118
	else if (aPixelformatString == KPixelFormatNames[10])
sl@0
   119
		{
sl@0
   120
		format =  EUidPixelFormatL_8;
sl@0
   121
		}
sl@0
   122
	else if (aPixelformatString == KPixelFormatNames[11])
sl@0
   123
		{
sl@0
   124
		format =  EUidPixelFormatL_4;
sl@0
   125
		}
sl@0
   126
	else if (aPixelformatString == KPixelFormatNames[12])
sl@0
   127
		{
sl@0
   128
		format =  EUidPixelFormatL_2;
sl@0
   129
		}
sl@0
   130
	else if (aPixelformatString == KPixelFormatNames[13])
sl@0
   131
		{
sl@0
   132
		format =  EUidPixelFormatL_1;
sl@0
   133
		}
sl@0
   134
	
sl@0
   135
	return format;
sl@0
   136
	}
sl@0
   137
sl@0
   138
/*
sl@0
   139
Convert the pixel format enum to a string
sl@0
   140
@param aFormat The pixel format enum
sl@0
   141
@return On return, it contains the pixel format string
sl@0
   142
 */
sl@0
   143
TPtrC TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(const TUidPixelFormat aFormat)
sl@0
   144
	{
sl@0
   145
	TPtrC pixelFormatString(KPixelFormatNames[0]);
sl@0
   146
	
sl@0
   147
	if (aFormat == EUidPixelFormatXRGB_8888)
sl@0
   148
		{
sl@0
   149
		pixelFormatString.Set(KPixelFormatNames[1]);
sl@0
   150
		}
sl@0
   151
	else if (aFormat == EUidPixelFormatARGB_8888)
sl@0
   152
		{
sl@0
   153
		pixelFormatString.Set(KPixelFormatNames[2]);
sl@0
   154
		}
sl@0
   155
	else if (aFormat == EUidPixelFormatARGB_8888_PRE)
sl@0
   156
		{
sl@0
   157
		pixelFormatString.Set(KPixelFormatNames[3]);
sl@0
   158
		}
sl@0
   159
	else if (aFormat == EUidPixelFormatRGB_888)
sl@0
   160
		{
sl@0
   161
		pixelFormatString.Set(KPixelFormatNames[4]);
sl@0
   162
		}
sl@0
   163
	else if (aFormat == EUidPixelFormatA_8)
sl@0
   164
		{
sl@0
   165
		pixelFormatString.Set(KPixelFormatNames[5]);
sl@0
   166
		}
sl@0
   167
	else if (aFormat == EUidPixelFormatRGB_565)
sl@0
   168
		{
sl@0
   169
		pixelFormatString.Set(KPixelFormatNames[6]);
sl@0
   170
		}
sl@0
   171
	else if (aFormat == EUidPixelFormatXRGB_4444)
sl@0
   172
		{
sl@0
   173
		pixelFormatString.Set(KPixelFormatNames[7]);
sl@0
   174
		}
sl@0
   175
	else if (aFormat == EUidPixelFormatP_8)
sl@0
   176
		{
sl@0
   177
		pixelFormatString.Set(KPixelFormatNames[8]);
sl@0
   178
		}
sl@0
   179
	else if (aFormat == EUidPixelFormatP_4)
sl@0
   180
		{
sl@0
   181
		pixelFormatString.Set(KPixelFormatNames[9]);
sl@0
   182
		}
sl@0
   183
	else if (aFormat == EUidPixelFormatL_8)
sl@0
   184
		{
sl@0
   185
		pixelFormatString.Set(KPixelFormatNames[10]);
sl@0
   186
		}
sl@0
   187
	else if (aFormat == EUidPixelFormatL_4)
sl@0
   188
		{
sl@0
   189
		pixelFormatString.Set(KPixelFormatNames[11]);
sl@0
   190
		}
sl@0
   191
	else if (aFormat == EUidPixelFormatL_2)
sl@0
   192
		{
sl@0
   193
		pixelFormatString.Set(KPixelFormatNames[12]);
sl@0
   194
		}
sl@0
   195
	else if (aFormat == EUidPixelFormatL_1)
sl@0
   196
		{
sl@0
   197
		pixelFormatString.Set(KPixelFormatNames[13]);
sl@0
   198
		}	
sl@0
   199
	
sl@0
   200
	return pixelFormatString;
sl@0
   201
	}
sl@0
   202
sl@0
   203
/*
sl@0
   204
Convert the pixel format enum to a shorter string than is achieved with ConvertPixelformatToPixelFormatString().
sl@0
   205
The EUidPixelFormat portion of the pixel format string is not added to the string. 
sl@0
   206
@see ConvertPixelformatToPixelFormatString()
sl@0
   207
@param aFormat The pixel format enum
sl@0
   208
@return On return, it contains the pixel format string
sl@0
   209
 */
sl@0
   210
TPtrC TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString(const TUidPixelFormat aFormat)
sl@0
   211
	{
sl@0
   212
	TPtrC pixelFormatString(KShortPixelFormatNames[0]);
sl@0
   213
	
sl@0
   214
	if (aFormat == EUidPixelFormatXRGB_8888)
sl@0
   215
		{
sl@0
   216
		pixelFormatString.Set(KShortPixelFormatNames[1]);
sl@0
   217
		}
sl@0
   218
	else if (aFormat == EUidPixelFormatARGB_8888)
sl@0
   219
		{
sl@0
   220
		pixelFormatString.Set(KShortPixelFormatNames[2]);
sl@0
   221
		}
sl@0
   222
	else if (aFormat == EUidPixelFormatARGB_8888_PRE)
sl@0
   223
		{
sl@0
   224
		pixelFormatString.Set(KShortPixelFormatNames[3]);
sl@0
   225
		}
sl@0
   226
	else if (aFormat == EUidPixelFormatRGB_888)
sl@0
   227
		{
sl@0
   228
		pixelFormatString.Set(KShortPixelFormatNames[4]);
sl@0
   229
		}
sl@0
   230
	else if (aFormat == EUidPixelFormatA_8)
sl@0
   231
		{
sl@0
   232
		pixelFormatString.Set(KShortPixelFormatNames[5]);
sl@0
   233
		}
sl@0
   234
	else if (aFormat == EUidPixelFormatRGB_565)
sl@0
   235
		{
sl@0
   236
		pixelFormatString.Set(KShortPixelFormatNames[6]);
sl@0
   237
		}
sl@0
   238
	else if (aFormat == EUidPixelFormatXRGB_4444)
sl@0
   239
		{
sl@0
   240
		pixelFormatString.Set(KShortPixelFormatNames[7]);
sl@0
   241
		}
sl@0
   242
	else if (aFormat == EUidPixelFormatP_8)
sl@0
   243
		{
sl@0
   244
		pixelFormatString.Set(KShortPixelFormatNames[8]);
sl@0
   245
		}
sl@0
   246
	else if (aFormat == EUidPixelFormatP_4)
sl@0
   247
		{
sl@0
   248
		pixelFormatString.Set(KShortPixelFormatNames[9]);
sl@0
   249
		}
sl@0
   250
	else if (aFormat == EUidPixelFormatL_8)
sl@0
   251
		{
sl@0
   252
		pixelFormatString.Set(KShortPixelFormatNames[10]);
sl@0
   253
		}
sl@0
   254
	else if (aFormat == EUidPixelFormatL_4)
sl@0
   255
		{
sl@0
   256
		pixelFormatString.Set(KShortPixelFormatNames[11]);
sl@0
   257
		}
sl@0
   258
	else if (aFormat == EUidPixelFormatL_2)
sl@0
   259
		{
sl@0
   260
		pixelFormatString.Set(KShortPixelFormatNames[12]);
sl@0
   261
		}
sl@0
   262
	else if (aFormat == EUidPixelFormatL_1)
sl@0
   263
		{
sl@0
   264
		pixelFormatString.Set(KShortPixelFormatNames[13]);
sl@0
   265
		}	
sl@0
   266
	
sl@0
   267
	return pixelFormatString;
sl@0
   268
	}
sl@0
   269
sl@0
   270
/*
sl@0
   271
Maps a pixel format enum to a display mode enum
sl@0
   272
@param aFormat The pixel format enum
sl@0
   273
@return Returns the display mode enum
sl@0
   274
 */
sl@0
   275
TDisplayMode TDisplayModeMapping::MapPixelFormatToDisplayMode(const TUidPixelFormat aFormat)
sl@0
   276
	{
sl@0
   277
	TDisplayMode mode;
sl@0
   278
	
sl@0
   279
	switch(aFormat)
sl@0
   280
	{
sl@0
   281
	/** Display mode with alpha (24bpp colour plus 8bpp alpha) */
sl@0
   282
	case EUidPixelFormatXRGB_8888:
sl@0
   283
		mode = EColor16MU; 
sl@0
   284
		break;
sl@0
   285
	
sl@0
   286
	/** Display mode with alpha (24bpp colour plus 8bpp alpha) */
sl@0
   287
	case EUidPixelFormatARGB_8888:
sl@0
   288
		mode = EColor16MA; 
sl@0
   289
		break;
sl@0
   290
sl@0
   291
	/** Pre-multiplied Alpha display mode (24bpp color multiplied with the alpha channel value, plus 8bpp alpha) */
sl@0
   292
	case EUidPixelFormatARGB_8888_PRE:
sl@0
   293
		mode = EColor16MAP; 
sl@0
   294
		break;
sl@0
   295
sl@0
   296
	/** True colour display mode (24 bpp) */
sl@0
   297
	case EUidPixelFormatRGB_888:
sl@0
   298
		mode = EColor16M; 
sl@0
   299
		break;
sl@0
   300
	
sl@0
   301
	case EUidPixelFormatXRGB_4444:
sl@0
   302
		mode = EColor4K; 
sl@0
   303
		break;
sl@0
   304
sl@0
   305
	/** 64,000 colour display mode (16 bpp) */
sl@0
   306
	case EUidPixelFormatRGB_565:
sl@0
   307
		mode = EColor64K; 
sl@0
   308
		break;
sl@0
   309
		
sl@0
   310
	/** 256 grayscales display mode (8 bpp) */	
sl@0
   311
	case EUidPixelFormatA_8:
sl@0
   312
		mode = EGray256;
sl@0
   313
		break;
sl@0
   314
sl@0
   315
	/** 256 grayscales (8 bpp) */
sl@0
   316
	case EUidPixelFormatL_8:
sl@0
   317
		mode = EGray256;
sl@0
   318
		break;
sl@0
   319
			
sl@0
   320
	/** Eight grayscales (4 bpp) */
sl@0
   321
	case EUidPixelFormatL_4:
sl@0
   322
	  	mode = EGray16;
sl@0
   323
		break;
sl@0
   324
		
sl@0
   325
	/** Four grayscales display mode (2 bpp) */
sl@0
   326
	case EUidPixelFormatL_2:
sl@0
   327
		mode = EGray4;
sl@0
   328
		break;
sl@0
   329
		
sl@0
   330
	/** Two grayscales (black and white) display mode (1 bpp) */
sl@0
   331
	case EUidPixelFormatL_1:
sl@0
   332
		mode = EGray2;
sl@0
   333
		break;
sl@0
   334
sl@0
   335
	/** 256 colour display mode (8 bpp) */
sl@0
   336
	case EUidPixelFormatP_8:
sl@0
   337
		mode = EColor256;
sl@0
   338
		break;
sl@0
   339
			
sl@0
   340
	/** Low colour EGA 16 colour display mode (4 bpp) */
sl@0
   341
	case EUidPixelFormatP_4:
sl@0
   342
	  	mode = EColor16;
sl@0
   343
		break;
sl@0
   344
		
sl@0
   345
	/** Monochrome display mode (1 bpp) */
sl@0
   346
	case EUidPixelFormatP_1:
sl@0
   347
		mode = EGray2;
sl@0
   348
		break;
sl@0
   349
		
sl@0
   350
	// Unknown display mode
sl@0
   351
	default:
sl@0
   352
	case EUidPixelFormatUnknown:
sl@0
   353
		mode = ENone; 
sl@0
   354
		break;
sl@0
   355
	}
sl@0
   356
	
sl@0
   357
	return mode;
sl@0
   358
	}
sl@0
   359
sl@0
   360
/*
sl@0
   361
Map display mode enum to pixel formation enum
sl@0
   362
@param aDisplayMode The display mode enum
sl@0
   363
@return On return, it contains the pixel format enum
sl@0
   364
 */
sl@0
   365
TUidPixelFormat TDisplayModeMapping::MapDisplayModeToPixelFormat(const TDisplayMode aDisplayMode)
sl@0
   366
	{
sl@0
   367
	TUidPixelFormat format;
sl@0
   368
	
sl@0
   369
	switch(aDisplayMode)
sl@0
   370
	{
sl@0
   371
	/** Display mode with alpha (24bpp colour plus 8bpp alpha) */
sl@0
   372
	case EColor16MU:
sl@0
   373
		format = EUidPixelFormatXRGB_8888; 
sl@0
   374
		break;
sl@0
   375
	
sl@0
   376
	/** Display mode with alpha (24bpp colour plus 8bpp alpha) */
sl@0
   377
	case EColor16MA:
sl@0
   378
		format = EUidPixelFormatARGB_8888; 
sl@0
   379
		break;
sl@0
   380
sl@0
   381
	/** Pre-multiplied Alpha display mode (24bpp color multiplied with the alpha channel value, plus 8bpp alpha) */
sl@0
   382
	case EColor16MAP:
sl@0
   383
		format = EUidPixelFormatARGB_8888_PRE; 
sl@0
   384
		break;
sl@0
   385
sl@0
   386
	/** True colour display mode (24 bpp) */
sl@0
   387
	case EColor16M:
sl@0
   388
		format = EUidPixelFormatRGB_888; 
sl@0
   389
		break;
sl@0
   390
	
sl@0
   391
	case EColor4K:
sl@0
   392
		format = EUidPixelFormatXRGB_4444;
sl@0
   393
		break;
sl@0
   394
sl@0
   395
	/** 64,000 colour display mode (16 bpp) */
sl@0
   396
	case EColor64K:
sl@0
   397
		format = EUidPixelFormatRGB_565; 
sl@0
   398
		break;
sl@0
   399
	
sl@0
   400
		/** 256 grayscale display mode (8 bpp) */
sl@0
   401
	case EGray256:
sl@0
   402
		format = EUidPixelFormatL_8;
sl@0
   403
		break;
sl@0
   404
		
sl@0
   405
	/** Sixteen grayscales display mode (4 bpp) */
sl@0
   406
	case EGray16:
sl@0
   407
		format = EUidPixelFormatL_4;
sl@0
   408
		break;
sl@0
   409
sl@0
   410
	/** Four grayscales display mode (2 bpp) */
sl@0
   411
	case EGray4:
sl@0
   412
		format = EUidPixelFormatL_2;
sl@0
   413
		break;
sl@0
   414
sl@0
   415
	/** Monochrome display mode (1 bpp) */
sl@0
   416
	case EGray2:
sl@0
   417
		format = EUidPixelFormatL_1;
sl@0
   418
		break;
sl@0
   419
		
sl@0
   420
	/** 256 Color paletised (8 bpp) */
sl@0
   421
	case EColor256:
sl@0
   422
		format = EUidPixelFormatP_8;
sl@0
   423
		break;
sl@0
   424
sl@0
   425
	/** Sixteen Colour paletised (4 bpp)*/
sl@0
   426
	case EColor16:
sl@0
   427
		format = EUidPixelFormatP_4;
sl@0
   428
		break;
sl@0
   429
sl@0
   430
	// Unknown display mode
sl@0
   431
	default:
sl@0
   432
	case ENone:
sl@0
   433
		format = EUidPixelFormatUnknown; 
sl@0
   434
		break;
sl@0
   435
	}
sl@0
   436
	
sl@0
   437
	return format;
sl@0
   438
	}
sl@0
   439