os/graphics/graphicsdeviceinterface/gdi/tgdi/TRGB.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1998-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
#include <palette.h>
sl@0
    17
#include "TRGB.H"
sl@0
    18
sl@0
    19
sl@0
    20
CTRgb::CTRgb(CTestStep* aStep):
sl@0
    21
	CTGraphicsBase(aStep)
sl@0
    22
	{
sl@0
    23
	INFO_PRINTF1(_L("Testing TRgb colour functions"));
sl@0
    24
	}
sl@0
    25
sl@0
    26
void CTRgb::RunTestCaseL(TInt aCurTestCase)
sl@0
    27
	{
sl@0
    28
	((CTRgbStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
sl@0
    29
	switch(aCurTestCase)
sl@0
    30
		{
sl@0
    31
	case 1:
sl@0
    32
/**
sl@0
    33
   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0001
sl@0
    34
*/
sl@0
    35
        	((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0001"));
sl@0
    36
		TestGray2();
sl@0
    37
		break;
sl@0
    38
	case 2:
sl@0
    39
/**
sl@0
    40
   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0002
sl@0
    41
*/
sl@0
    42
		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0002"));
sl@0
    43
		TestGray4();
sl@0
    44
		break;
sl@0
    45
	case 3:
sl@0
    46
/**
sl@0
    47
   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0003
sl@0
    48
*/
sl@0
    49
		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0003"));
sl@0
    50
		TestGray16();
sl@0
    51
		break;
sl@0
    52
	case 4:
sl@0
    53
/**
sl@0
    54
   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0004
sl@0
    55
*/
sl@0
    56
		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0004"));
sl@0
    57
		TestGray256();
sl@0
    58
		break;
sl@0
    59
	case 5:
sl@0
    60
/**
sl@0
    61
   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0005
sl@0
    62
*/
sl@0
    63
		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0005"));
sl@0
    64
		TestColor16();
sl@0
    65
		break;
sl@0
    66
	case 6:
sl@0
    67
/**
sl@0
    68
   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0006
sl@0
    69
*/
sl@0
    70
		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0006"));
sl@0
    71
		TestColor256();
sl@0
    72
		break;
sl@0
    73
	case 7:
sl@0
    74
/**
sl@0
    75
   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0007
sl@0
    76
*/
sl@0
    77
		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0007"));
sl@0
    78
		TestColor4K();
sl@0
    79
		break;
sl@0
    80
	case 8:
sl@0
    81
/**
sl@0
    82
   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0008
sl@0
    83
*/
sl@0
    84
		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0008"));
sl@0
    85
		TestColor64K();
sl@0
    86
		break;
sl@0
    87
	case 9:
sl@0
    88
/**
sl@0
    89
   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0009
sl@0
    90
*/
sl@0
    91
		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0009"));
sl@0
    92
		TestColor16M();
sl@0
    93
		break;
sl@0
    94
	case 10:
sl@0
    95
/**
sl@0
    96
   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0010
sl@0
    97
*/
sl@0
    98
		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0010"));
sl@0
    99
		TestColor16MU();
sl@0
   100
		break;
sl@0
   101
	case 11:
sl@0
   102
/**
sl@0
   103
   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0011
sl@0
   104
*/
sl@0
   105
		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0011"));
sl@0
   106
		TestColor16MA();
sl@0
   107
		break;
sl@0
   108
	case 12:
sl@0
   109
/**
sl@0
   110
   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0012
sl@0
   111
*/
sl@0
   112
		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0012"));
sl@0
   113
		TestColor256Util();
sl@0
   114
		break;
sl@0
   115
	case 13:
sl@0
   116
/**
sl@0
   117
   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0013
sl@0
   118
*/
sl@0
   119
		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0013"));
sl@0
   120
		TestColor16MAP();
sl@0
   121
		break;
sl@0
   122
	case 14:
sl@0
   123
		((CTRgbStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
sl@0
   124
		((CTRgbStep*)iStep)->CloseTMSGraphicsStep();
sl@0
   125
		TestComplete();
sl@0
   126
		break;
sl@0
   127
		}
sl@0
   128
	    ((CTRgbStep*)iStep)->RecordTestResultL();
sl@0
   129
	}
sl@0
   130
sl@0
   131
/**
sl@0
   132
	Test Gray2 colour set
sl@0
   133
sl@0
   134
	Cycle through each Gray2 colour & compare the grayscale value used to create the colour
sl@0
   135
	against the index value retrieved from the colour palette.
sl@0
   136
	Cycle through a series of RGB values & compare the Gray2 TRgb value with a subset of the Gray256 colour-set.
sl@0
   137
 
sl@0
   138
    Expect the conversion from index value to grayscale colour value & back again produces identical value.
sl@0
   139
	Expect the Gray2 rgb colour set forms a subset of the Gray256 colour rgb set
sl@0
   140
*/		
sl@0
   141
void CTRgb::TestGray2()
sl@0
   142
	{
sl@0
   143
	INFO_PRINTF1(_L("Gray2"));
sl@0
   144
sl@0
   145
	for (TInt index = 0; index < 2; index++)
sl@0
   146
		{
sl@0
   147
		TRgb color = TRgb::Gray2(index);
sl@0
   148
		TEST(color.Gray2() == index);
sl@0
   149
		}
sl@0
   150
sl@0
   151
	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
sl@0
   152
		{
sl@0
   153
		TRgb color(value);
sl@0
   154
		TEST(color.Gray2() == color.Gray256() / 128);
sl@0
   155
		}
sl@0
   156
	}
sl@0
   157
sl@0
   158
/**
sl@0
   159
	Cycle through each Gray4 colour & compare the grayscale value used to create the colour
sl@0
   160
	against the index value retrieved from the colour palette.
sl@0
   161
	Cycle through a series of RGB values & compare the Gray4 TRgb colour value with a subset of the Gray256 colour-set.
sl@0
   162
 
sl@0
   163
   	Expect conversion from index value to grayscale colour value & back again produces identical value.
sl@0
   164
	Expect the Gray4 rgb colour set forms a subset of the Gray256 colour rgb set
sl@0
   165
*/		
sl@0
   166
void CTRgb::TestGray4()
sl@0
   167
	{
sl@0
   168
	INFO_PRINTF1(_L("Gray4"));
sl@0
   169
sl@0
   170
	for (TInt index = 0; index < 4; index++)
sl@0
   171
		{
sl@0
   172
		TRgb color = TRgb::Gray4(index);
sl@0
   173
		TEST(color.Gray4() == index);
sl@0
   174
		}
sl@0
   175
sl@0
   176
	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
sl@0
   177
		{
sl@0
   178
		TRgb color(value);
sl@0
   179
		TEST(color.Gray4() == color.Gray256() / 64);
sl@0
   180
		}
sl@0
   181
	}
sl@0
   182
sl@0
   183
/**
sl@0
   184
   	Cycle through each Gray16 colour & compare the grayscale value used to create the colour
sl@0
   185
	against the index value retrieved from the colour palette.
sl@0
   186
	Cycle through a series of RGB values & compare the Gray16 TRgb value with a subset of the Gray256 colour-set.
sl@0
   187
 
sl@0
   188
   	Expect the conversion from index value to grayscale colour value & back again produces identical value.
sl@0
   189
	Expect the Gray16 rgb colour set forms a subset of the Gray256 colour rgb set
sl@0
   190
*/		
sl@0
   191
void CTRgb::TestGray16()
sl@0
   192
	{
sl@0
   193
	INFO_PRINTF1(_L("Gray16"));
sl@0
   194
sl@0
   195
	for (TInt index = 0; index < 16; index++)
sl@0
   196
		{
sl@0
   197
		TRgb color = TRgb::Gray16(index);
sl@0
   198
		TEST(color.Gray16() == index);
sl@0
   199
		}
sl@0
   200
sl@0
   201
	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
sl@0
   202
		{
sl@0
   203
		TRgb color(value);
sl@0
   204
		TEST(color.Gray16() == color.Gray256() / 16);
sl@0
   205
		}
sl@0
   206
	}
sl@0
   207
sl@0
   208
/**
sl@0
   209
   	Cycle through each Gray256 colour & compare the grayscale value used to create the colour
sl@0
   210
	against the index value retrieved from the colour palette.
sl@0
   211
	Cycle through a series of RGB values & compare the Gray256 TRgb colour value with the value produced by generic algorithm
sl@0
   212
 
sl@0
   213
   	Expect the conversion from index value to grayscale colour value & back again produces identical value.
sl@0
   214
	Confirm the algorithm used to produce Gray256 colour set 
sl@0
   215
*/		
sl@0
   216
void CTRgb::TestGray256()
sl@0
   217
	{
sl@0
   218
	INFO_PRINTF1(_L("Gray256"));
sl@0
   219
sl@0
   220
	for (TInt index = 0; index < 256; index++)
sl@0
   221
		{
sl@0
   222
		TRgb color = TRgb::Gray256(index);
sl@0
   223
		TEST(color.Gray256() == index);
sl@0
   224
		}
sl@0
   225
sl@0
   226
	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
sl@0
   227
		{
sl@0
   228
		TRgb color(value);
sl@0
   229
		TInt algGray256 = (((value & 0xff) * 2) + (((value >> 8) & 0xff) * 5) + ((value >> 16) & 0xff)) / 8;
sl@0
   230
		TEST(color.Gray256() == algGray256);
sl@0
   231
		}
sl@0
   232
	}
sl@0
   233
sl@0
   234
/**
sl@0
   235
   	Test 16 Colour colour set
sl@0
   236
sl@0
   237
   	Cycle through each Color16 colour & test the value used to create the colour
sl@0
   238
	against the index value retrieved from the colour palette.
sl@0
   239
	Compare the rgb value for each Color16 colour matches that returned by the DynamicPalette colour palette
sl@0
   240
 
sl@0
   241
   	Expect the RGB colour value returned matches the 16colour palette
sl@0
   242
*/		
sl@0
   243
void CTRgb::TestColor16()
sl@0
   244
	{
sl@0
   245
	INFO_PRINTF1(_L("Color16"));
sl@0
   246
sl@0
   247
	for (TInt index = 0; index < 16; index++)
sl@0
   248
		{
sl@0
   249
		TRgb color = TRgb::Color16(index);
sl@0
   250
		TEST(color.Color16() == index);
sl@0
   251
		TEST(TRgb::Color16(index) == TRgb(DynamicPalette::Color16array()[index]));
sl@0
   252
		}
sl@0
   253
	}
sl@0
   254
sl@0
   255
/**
sl@0
   256
	Test 256 colour set
sl@0
   257
sl@0
   258
    Cycle through each Color256 colour & test the value used to create the colour
sl@0
   259
	against the index value retrieved from the colour palette.
sl@0
   260
	Compare the rgb value for each Color256 colour against the rgb value returned by the DynamicPalette colour palette
sl@0
   261
	Cycle through each Color256 colour & confirm it matches the Netscape Colour Cube
sl@0
   262
							
sl@0
   263
   	Expect the RGB colour returned matches the 256 colour palette
sl@0
   264
*/
sl@0
   265
void CTRgb::TestColor256()
sl@0
   266
	{
sl@0
   267
	INFO_PRINTF1(_L("Color256"));
sl@0
   268
sl@0
   269
	const TInt mainValues[6] = {0x00, 0x33, 0x66, 0x99, 0xcc, 0xff };
sl@0
   270
	const TInt lowerValues[5] = {0x11, 0x22, 0x44, 0x55, 0x77 };
sl@0
   271
	const TInt upperValues[5] = {0x88, 0xaa, 0xbb, 0xdd, 0xee };
sl@0
   272
sl@0
   273
	TInt index;
sl@0
   274
	for (index = 0; index < 256; index++)
sl@0
   275
		{
sl@0
   276
		TRgb color = TRgb::Color256(index);
sl@0
   277
		TEST(color.Color256() == index);
sl@0
   278
		TEST(TRgb::Color256(index) == TRgb(DynamicPalette::DefaultColor256Util()->iColorTable[index]));
sl@0
   279
		}
sl@0
   280
sl@0
   281
	for (index = 0; index < 108; index++)
sl@0
   282
		{
sl@0
   283
		TRgb color = TRgb::Color256(index);
sl@0
   284
		TEST(color.Red() == mainValues[index % 6]);
sl@0
   285
		TEST(color.Green() == mainValues[(index / 6) % 6]);
sl@0
   286
		TEST(color.Blue() == mainValues[(index / 36) % 6]);
sl@0
   287
		}
sl@0
   288
	for (; index < 113; index++)
sl@0
   289
		{
sl@0
   290
		TRgb color = TRgb::Color256(index);
sl@0
   291
		TEST(color.Red() == color.Green());
sl@0
   292
		TEST(color.Green() == color.Blue());
sl@0
   293
		TEST(color.Blue() == lowerValues[index - 108]);
sl@0
   294
		}
sl@0
   295
	for (; index < 118; index++)
sl@0
   296
		{
sl@0
   297
		TRgb color = TRgb::Color256(index);
sl@0
   298
		TEST(color.Red() == lowerValues[index - 113]);
sl@0
   299
		TEST(color.Green() == 0);
sl@0
   300
		TEST(color.Blue() == 0);
sl@0
   301
		}
sl@0
   302
	for (; index < 123; index++)
sl@0
   303
		{
sl@0
   304
		TRgb color = TRgb::Color256(index);
sl@0
   305
		TEST(color.Red() == 0);
sl@0
   306
		TEST(color.Green() == lowerValues[index - 118]);
sl@0
   307
		TEST(color.Blue() == 0);
sl@0
   308
		}
sl@0
   309
	for (; index < 128; index++)
sl@0
   310
		{
sl@0
   311
		TRgb color = TRgb::Color256(index);
sl@0
   312
		TEST(color.Red() == 0);
sl@0
   313
		TEST(color.Green() == 0);
sl@0
   314
		TEST(color.Blue() == lowerValues[index - 123]);
sl@0
   315
		}
sl@0
   316
	for (; index < 133; index++)
sl@0
   317
		{
sl@0
   318
		TRgb color = TRgb::Color256(index);
sl@0
   319
		TEST(color.Red() == 0);
sl@0
   320
		TEST(color.Green() == 0);
sl@0
   321
		TEST(color.Blue() == upperValues[index - 128]);
sl@0
   322
		}
sl@0
   323
	for (; index < 138; index++)
sl@0
   324
		{
sl@0
   325
		TRgb color = TRgb::Color256(index);
sl@0
   326
		TEST(color.Red() == 0);
sl@0
   327
		TEST(color.Green() == upperValues[index - 133]);
sl@0
   328
		TEST(color.Blue() == 0);
sl@0
   329
		}
sl@0
   330
	for (; index < 143; index++)
sl@0
   331
		{
sl@0
   332
		TRgb color = TRgb::Color256(index);
sl@0
   333
		TEST(color.Red() == upperValues[index - 138]);
sl@0
   334
		TEST(color.Green() == 0);
sl@0
   335
		TEST(color.Blue() == 0);
sl@0
   336
		}
sl@0
   337
	for (; index < 148; index++)
sl@0
   338
		{
sl@0
   339
		TRgb color = TRgb::Color256(index);
sl@0
   340
		TEST(color.Red() == color.Green());
sl@0
   341
		TEST(color.Green() == color.Blue());
sl@0
   342
		TEST(color.Blue() == upperValues[index - 143]);
sl@0
   343
		}
sl@0
   344
	for (; index < 256; index++)
sl@0
   345
		{
sl@0
   346
		TRgb color = TRgb::Color256(index);
sl@0
   347
		TEST(color.Red() == mainValues[(index - 40) % 6]);
sl@0
   348
		TEST(color.Green() == mainValues[((index - 40) / 6) % 6]);
sl@0
   349
		TEST(color.Blue() == mainValues[((index - 40) / 36) % 6]);
sl@0
   350
		}
sl@0
   351
	}
sl@0
   352
sl@0
   353
/**
sl@0
   354
	Test 4096 colour set
sl@0
   355
sl@0
   356
   	Cycle through each Color4K colour & compare the colorscale value used to create the colour
sl@0
   357
	against the index value retrieved from the colour palette.
sl@0
   358
	Cycle through a series of RGB values & compare the Color4K TRgb value against that produced by the algorithm
sl@0
   359
 
sl@0
   360
   	Confirm the conversion from index value to 4096 colour value & back again produces identical value.
sl@0
   361
	Confirm the algorithm used to produce 4096 colour set
sl@0
   362
*/	
sl@0
   363
void CTRgb::TestColor4K()
sl@0
   364
	{
sl@0
   365
	INFO_PRINTF1(_L("Color4K"));
sl@0
   366
sl@0
   367
	for (TInt index = 0; index < 4096; index++)
sl@0
   368
		{
sl@0
   369
		TRgb color = TRgb::Color4K(index);
sl@0
   370
		TEST(color.Color4K() == index);
sl@0
   371
		}
sl@0
   372
sl@0
   373
	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
sl@0
   374
		{
sl@0
   375
		TRgb color(value);
sl@0
   376
		TInt color4K = ((value & 0xf00000) >> 20) | ((value & 0x00f000) >> 8) | ((value & 0x0000f0) << 4);
sl@0
   377
		TEST(color.Color4K() == color4K);
sl@0
   378
		}
sl@0
   379
	}
sl@0
   380
sl@0
   381
/**
sl@0
   382
   	Test 64K colour set
sl@0
   383
sl@0
   384
   	Cycle through each Color64K colour & compare the TRgb value used to create the colour
sl@0
   385
	against the index value retrieved from the colour palette.
sl@0
   386
	Cycle through a series of RGB values & compare the Color64K TRgb value against that produced by the algorithm
sl@0
   387
 
sl@0
   388
   	Confirm the conversion from index value to 64K colour value & back again produces identical value.
sl@0
   389
	Confirm the algorithm used to produce 64K colour set
sl@0
   390
*/	
sl@0
   391
void CTRgb::TestColor64K()
sl@0
   392
	{
sl@0
   393
	INFO_PRINTF1(_L("Color64K"));
sl@0
   394
sl@0
   395
	for (TInt index = 0; index < 65536; index++)
sl@0
   396
		{
sl@0
   397
		TRgb color = TRgb::Color64K(index);
sl@0
   398
		TEST(color.Color64K() == index);
sl@0
   399
		}
sl@0
   400
sl@0
   401
	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
sl@0
   402
		{
sl@0
   403
		TRgb color(value);
sl@0
   404
		TInt color64K = ((value & 0xf8) << 8) + ((value & 0xfc00) >> 5) + ((value & 0xf80000) >> 19);
sl@0
   405
		TEST(color.Color64K() == color64K);
sl@0
   406
		}
sl@0
   407
	}
sl@0
   408
sl@0
   409
/**
sl@0
   410
	Test 16M colour set
sl@0
   411
sl@0
   412
 	Cycle through each Color16M colour & compare the TRgb value used to create the colour
sl@0
   413
	against the index value retrieved from the colour palette.
sl@0
   414
	Cycle through a series of RGB values & compare the Color16M TRgb value against that produced by the algorithm
sl@0
   415
 
sl@0
   416
   	Confirm the conversion from index value to 16M colour value & back again produces identical value.
sl@0
   417
	Confirm the algorithm used to produce 16M colour set
sl@0
   418
*/	
sl@0
   419
void CTRgb::TestColor16M()
sl@0
   420
	{
sl@0
   421
	INFO_PRINTF1(_L("Color16M"));
sl@0
   422
sl@0
   423
	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
sl@0
   424
		{
sl@0
   425
		TRgb color(value);
sl@0
   426
		TInt color16M = ((value & 0xff0000) >> 16) | (value & 0x00ff00) | ((value & 0x0000ff) << 16);
sl@0
   427
		TRgb generatedColor = TRgb::Color16M(color16M);
sl@0
   428
		TEST(color == generatedColor);
sl@0
   429
		TEST(color.Color16M() == color16M);
sl@0
   430
		}
sl@0
   431
	}
sl@0
   432
sl@0
   433
/**
sl@0
   434
	Test 16MU colour set
sl@0
   435
sl@0
   436
   	Cycle through each Color16MU colour & compare the TRgb value used to create the colour
sl@0
   437
	against the index value retrieved from the colour palette.
sl@0
   438
	Cycle through a series of RGB values & compare the Color16MU TRgb value against that produced by the algorithm
sl@0
   439
 
sl@0
   440
   	Confirm the conversion from index value to 16MU colour value & back again produces identical value.
sl@0
   441
	Confirm the algorithm used to produce 16MU colour set
sl@0
   442
*/	
sl@0
   443
void CTRgb::TestColor16MU()
sl@0
   444
	{
sl@0
   445
	INFO_PRINTF1(_L("Color16MU"));
sl@0
   446
sl@0
   447
	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
sl@0
   448
		{
sl@0
   449
		TRgb color(value);
sl@0
   450
		TInt color16MU = ((value & 0xff0000) >> 16) | (value & 0x00ff00) | ((value & 0x0000ff) << 16);
sl@0
   451
		TRgb generatedColor = TRgb::Color16MU(color16MU);
sl@0
   452
		TEST(color == generatedColor);
sl@0
   453
		TEST(color.Color16MU() == color16MU);
sl@0
   454
		}
sl@0
   455
	}
sl@0
   456
sl@0
   457
/**
sl@0
   458
   	Test 16MA colour set
sl@0
   459
sl@0
   460
   	Cycle through each Color16MA colour & compare the TRgb value used to create the colour
sl@0
   461
	against the index value retrieved from the colour palette.
sl@0
   462
	Cycle through a series of RGB values & compare the Color16MA TRgb value against that produced by the algorithm
sl@0
   463
 
sl@0
   464
   	Confirm the conversion from index value to 16MA colour value & back again produces identical value.
sl@0
   465
	Confirm the algorithm used to produce 16MA colour set
sl@0
   466
*/
sl@0
   467
void CTRgb::TestColor16MA()
sl@0
   468
	{
sl@0
   469
	INFO_PRINTF1(_L("Color16MA"));
sl@0
   470
sl@0
   471
	for (TUint32 high = 0; high <= 0xffff; high += 51)
sl@0
   472
		for (TUint32 low = 0; low <= 0xffff; low += 51)
sl@0
   473
			{
sl@0
   474
			TUint32 value = (high << 16) + low; // '+' operator has higher precedance than '<<'  operator
sl@0
   475
			TRgb color(value);
sl@0
   476
			TInt color16MA = (0xff000000 - (value & 0xff000000)) | ((value & 0xff0000) >> 16) | (value & 0x00ff00) | ((value & 0x0000ff) << 16);
sl@0
   477
			TRgb generatedColor = TRgb::Color16MA(color16MA);
sl@0
   478
			TEST(color == generatedColor);
sl@0
   479
			TEST(color.Color16MA() == color16MA);
sl@0
   480
			}
sl@0
   481
	}
sl@0
   482
sl@0
   483
/**
sl@0
   484
   	Test TColor256Util
sl@0
   485
sl@0
   486
   	Test functionality contained within TColor256Util. 
sl@0
   487
							
sl@0
   488
   	Confirm TColor256Util converts correctly between TRgb values & the corresponding index in the colour palette
sl@0
   489
							
sl@0
   490
*/
sl@0
   491
void CTRgb::TestColor256Util()
sl@0
   492
	{
sl@0
   493
	INFO_PRINTF1(_L("TColor256Util"));
sl@0
   494
sl@0
   495
	__UHEAP_MARK;
sl@0
   496
sl@0
   497
	TColor256Util* util = new TColor256Util;
sl@0
   498
	CPalette* palette = NULL;
sl@0
   499
	TRAPD(err,palette = CPalette::NewDefaultL(EColor256));
sl@0
   500
	TEST(err==KErrNone);
sl@0
   501
	util->Construct(*palette);
sl@0
   502
	TEST(Mem::Compare((TUint8*)util,sizeof(TColor256Util),(TUint8*)DynamicPalette::DefaultColor256Util(),sizeof(TColor256Util))==0);
sl@0
   503
sl@0
   504
	TInt index;
sl@0
   505
	for (index = 0; index < 256; index++)
sl@0
   506
		{
sl@0
   507
		TRgb color = TRgb::Color256(index);
sl@0
   508
		TEST(util->Color256(index) == color);
sl@0
   509
		TEST(util->Color256(color) == index);
sl@0
   510
		}
sl@0
   511
sl@0
   512
	TRgb* rgbBuffer = new TRgb[256];
sl@0
   513
	TUint8* indexBuffer = new TUint8[256];
sl@0
   514
	for (index = 0; index < 256; index++)
sl@0
   515
		rgbBuffer[index] = TRgb::Color256(index);
sl@0
   516
	util->Color256(indexBuffer,rgbBuffer,256);
sl@0
   517
	for (index = 0; index < 256; index++)
sl@0
   518
		TEST(indexBuffer[index]==index);
sl@0
   519
sl@0
   520
	delete[] rgbBuffer;
sl@0
   521
	delete[] indexBuffer;
sl@0
   522
	delete palette;
sl@0
   523
	delete util;
sl@0
   524
sl@0
   525
	__UHEAP_MARKEND;
sl@0
   526
	}
sl@0
   527
sl@0
   528
/**
sl@0
   529
	Validate the PreMultiplied value and the Non PreMultiplied value with the expected values.
sl@0
   530
	@param aAlpha Alpha value of the color.
sl@0
   531
	@param aValue The value of the color channel(ie. one of Red,Green or Blue).
sl@0
   532
	@param aPreMulVal The PreMutiplied color value for aValue.
sl@0
   533
	@param aNonPreMulValue The Non PreMutiplied value for aValue
sl@0
   534
						   (i.e the value received by Non PreMutiplying aPreMulVal).
sl@0
   535
sl@0
   536
*/
sl@0
   537
void CTRgb::ValidatePMAndNPM(TInt aAlpha, TInt aValue, TInt aPreMulVal, TInt aNonPreMulValue)
sl@0
   538
	{
sl@0
   539
	TInt expPreMulValue = (aValue*(aAlpha+1))/256;
sl@0
   540
	TInt expNonPreMulValMin = (expPreMulValue * 255) / aAlpha;
sl@0
   541
	TInt expNonPreMulValMax = expNonPreMulValMin + 1;
sl@0
   542
	if (expNonPreMulValMax > 255)
sl@0
   543
		{
sl@0
   544
		expNonPreMulValMax = 255;
sl@0
   545
		}
sl@0
   546
	TEST(expPreMulValue == aPreMulVal);
sl@0
   547
	TEST(expNonPreMulValMin <= aNonPreMulValue && expNonPreMulValMax >= aNonPreMulValue);
sl@0
   548
	}
sl@0
   549
sl@0
   550
/**
sl@0
   551
   	DEF103742 - Test the PreMultiply and Non PreMultiply conversion.
sl@0
   552
sl@0
   553
   	Convert the color values into PreMultiplied color values and again back to
sl@0
   554
   	the Non PreMultiplied color values.
sl@0
   555
   	Compare the  converted values with the expected values to validate the functionality.
sl@0
   556
 
sl@0
   557
   	Confirm the PreMultiplied and Non PreMultiplied color values match with the expected values.
sl@0
   558
*/		
sl@0
   559
void CTRgb::TestColor16MAP()
sl@0
   560
	{
sl@0
   561
	INFO_PRINTF1(_L("Color16MAP"));
sl@0
   562
	for (TInt alpha = 0; alpha < 256; alpha += 51)
sl@0
   563
		{
sl@0
   564
		for (TUint32 value = 0; value <= 0x00ffffff; value += 0x1f1f)
sl@0
   565
			{
sl@0
   566
			TRgb color(value, alpha);
sl@0
   567
			TUint pmColor = color.Color16MAP();
sl@0
   568
			TRgb npmColor = TRgb::Color16MAP(pmColor);
sl@0
   569
sl@0
   570
			TInt pmAlpha = (pmColor & 0xFF000000) >> 24;
sl@0
   571
sl@0
   572
			// These really must be right!
sl@0
   573
			TEST(pmAlpha == alpha);
sl@0
   574
			TEST(npmColor.Alpha() == alpha);
sl@0
   575
sl@0
   576
			// These definitely ought to be right
sl@0
   577
			if (alpha == 0)	// Full transparency, expect black
sl@0
   578
				{
sl@0
   579
				TEST(pmColor == 0);
sl@0
   580
				TEST(npmColor.Internal() == 0);
sl@0
   581
				}
sl@0
   582
			else if (alpha == 255)	// Full opacity, expect roundtrip
sl@0
   583
				{
sl@0
   584
				TEST(pmColor == color.Internal());
sl@0
   585
				TEST(npmColor == color);
sl@0
   586
				}
sl@0
   587
			else
sl@0
   588
				{
sl@0
   589
				// Most awkward cases: semi-transparency.
sl@0
   590
				TInt pmRed   = (pmColor & 0x00FF0000) >> 16;
sl@0
   591
				TInt pmGreen = (pmColor & 0x0000FF00) >> 8;
sl@0
   592
				TInt pmBlue  = pmColor & 0xFF;
sl@0
   593
				ValidatePMAndNPM(alpha, color.Red(), pmRed, npmColor.Red());
sl@0
   594
				ValidatePMAndNPM(alpha, color.Green(), pmGreen, npmColor.Green());
sl@0
   595
				ValidatePMAndNPM(alpha, color.Blue(), pmBlue, npmColor.Blue());
sl@0
   596
				}
sl@0
   597
			}
sl@0
   598
		}
sl@0
   599
	}
sl@0
   600
sl@0
   601
//--------------
sl@0
   602
__CONSTRUCT_STEP__(Rgb)