os/graphics/graphicsdeviceinterface/gdi/tgdi/TRGB.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsdeviceinterface/gdi/tgdi/TRGB.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,602 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <palette.h>
    1.20 +#include "TRGB.H"
    1.21 +
    1.22 +
    1.23 +CTRgb::CTRgb(CTestStep* aStep):
    1.24 +	CTGraphicsBase(aStep)
    1.25 +	{
    1.26 +	INFO_PRINTF1(_L("Testing TRgb colour functions"));
    1.27 +	}
    1.28 +
    1.29 +void CTRgb::RunTestCaseL(TInt aCurTestCase)
    1.30 +	{
    1.31 +	((CTRgbStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
    1.32 +	switch(aCurTestCase)
    1.33 +		{
    1.34 +	case 1:
    1.35 +/**
    1.36 +   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0001
    1.37 +*/
    1.38 +        	((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0001"));
    1.39 +		TestGray2();
    1.40 +		break;
    1.41 +	case 2:
    1.42 +/**
    1.43 +   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0002
    1.44 +*/
    1.45 +		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0002"));
    1.46 +		TestGray4();
    1.47 +		break;
    1.48 +	case 3:
    1.49 +/**
    1.50 +   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0003
    1.51 +*/
    1.52 +		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0003"));
    1.53 +		TestGray16();
    1.54 +		break;
    1.55 +	case 4:
    1.56 +/**
    1.57 +   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0004
    1.58 +*/
    1.59 +		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0004"));
    1.60 +		TestGray256();
    1.61 +		break;
    1.62 +	case 5:
    1.63 +/**
    1.64 +   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0005
    1.65 +*/
    1.66 +		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0005"));
    1.67 +		TestColor16();
    1.68 +		break;
    1.69 +	case 6:
    1.70 +/**
    1.71 +   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0006
    1.72 +*/
    1.73 +		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0006"));
    1.74 +		TestColor256();
    1.75 +		break;
    1.76 +	case 7:
    1.77 +/**
    1.78 +   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0007
    1.79 +*/
    1.80 +		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0007"));
    1.81 +		TestColor4K();
    1.82 +		break;
    1.83 +	case 8:
    1.84 +/**
    1.85 +   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0008
    1.86 +*/
    1.87 +		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0008"));
    1.88 +		TestColor64K();
    1.89 +		break;
    1.90 +	case 9:
    1.91 +/**
    1.92 +   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0009
    1.93 +*/
    1.94 +		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0009"));
    1.95 +		TestColor16M();
    1.96 +		break;
    1.97 +	case 10:
    1.98 +/**
    1.99 +   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0010
   1.100 +*/
   1.101 +		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0010"));
   1.102 +		TestColor16MU();
   1.103 +		break;
   1.104 +	case 11:
   1.105 +/**
   1.106 +   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0011
   1.107 +*/
   1.108 +		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0011"));
   1.109 +		TestColor16MA();
   1.110 +		break;
   1.111 +	case 12:
   1.112 +/**
   1.113 +   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0012
   1.114 +*/
   1.115 +		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0012"));
   1.116 +		TestColor256Util();
   1.117 +		break;
   1.118 +	case 13:
   1.119 +/**
   1.120 +   @SYMTestCaseID          	GRAPHICS-GDI-RGB-0013
   1.121 +*/
   1.122 +		((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0013"));
   1.123 +		TestColor16MAP();
   1.124 +		break;
   1.125 +	case 14:
   1.126 +		((CTRgbStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   1.127 +		((CTRgbStep*)iStep)->CloseTMSGraphicsStep();
   1.128 +		TestComplete();
   1.129 +		break;
   1.130 +		}
   1.131 +	    ((CTRgbStep*)iStep)->RecordTestResultL();
   1.132 +	}
   1.133 +
   1.134 +/**
   1.135 +	Test Gray2 colour set
   1.136 +
   1.137 +	Cycle through each Gray2 colour & compare the grayscale value used to create the colour
   1.138 +	against the index value retrieved from the colour palette.
   1.139 +	Cycle through a series of RGB values & compare the Gray2 TRgb value with a subset of the Gray256 colour-set.
   1.140 + 
   1.141 +    Expect the conversion from index value to grayscale colour value & back again produces identical value.
   1.142 +	Expect the Gray2 rgb colour set forms a subset of the Gray256 colour rgb set
   1.143 +*/		
   1.144 +void CTRgb::TestGray2()
   1.145 +	{
   1.146 +	INFO_PRINTF1(_L("Gray2"));
   1.147 +
   1.148 +	for (TInt index = 0; index < 2; index++)
   1.149 +		{
   1.150 +		TRgb color = TRgb::Gray2(index);
   1.151 +		TEST(color.Gray2() == index);
   1.152 +		}
   1.153 +
   1.154 +	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
   1.155 +		{
   1.156 +		TRgb color(value);
   1.157 +		TEST(color.Gray2() == color.Gray256() / 128);
   1.158 +		}
   1.159 +	}
   1.160 +
   1.161 +/**
   1.162 +	Cycle through each Gray4 colour & compare the grayscale value used to create the colour
   1.163 +	against the index value retrieved from the colour palette.
   1.164 +	Cycle through a series of RGB values & compare the Gray4 TRgb colour value with a subset of the Gray256 colour-set.
   1.165 + 
   1.166 +   	Expect conversion from index value to grayscale colour value & back again produces identical value.
   1.167 +	Expect the Gray4 rgb colour set forms a subset of the Gray256 colour rgb set
   1.168 +*/		
   1.169 +void CTRgb::TestGray4()
   1.170 +	{
   1.171 +	INFO_PRINTF1(_L("Gray4"));
   1.172 +
   1.173 +	for (TInt index = 0; index < 4; index++)
   1.174 +		{
   1.175 +		TRgb color = TRgb::Gray4(index);
   1.176 +		TEST(color.Gray4() == index);
   1.177 +		}
   1.178 +
   1.179 +	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
   1.180 +		{
   1.181 +		TRgb color(value);
   1.182 +		TEST(color.Gray4() == color.Gray256() / 64);
   1.183 +		}
   1.184 +	}
   1.185 +
   1.186 +/**
   1.187 +   	Cycle through each Gray16 colour & compare the grayscale value used to create the colour
   1.188 +	against the index value retrieved from the colour palette.
   1.189 +	Cycle through a series of RGB values & compare the Gray16 TRgb value with a subset of the Gray256 colour-set.
   1.190 + 
   1.191 +   	Expect the conversion from index value to grayscale colour value & back again produces identical value.
   1.192 +	Expect the Gray16 rgb colour set forms a subset of the Gray256 colour rgb set
   1.193 +*/		
   1.194 +void CTRgb::TestGray16()
   1.195 +	{
   1.196 +	INFO_PRINTF1(_L("Gray16"));
   1.197 +
   1.198 +	for (TInt index = 0; index < 16; index++)
   1.199 +		{
   1.200 +		TRgb color = TRgb::Gray16(index);
   1.201 +		TEST(color.Gray16() == index);
   1.202 +		}
   1.203 +
   1.204 +	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
   1.205 +		{
   1.206 +		TRgb color(value);
   1.207 +		TEST(color.Gray16() == color.Gray256() / 16);
   1.208 +		}
   1.209 +	}
   1.210 +
   1.211 +/**
   1.212 +   	Cycle through each Gray256 colour & compare the grayscale value used to create the colour
   1.213 +	against the index value retrieved from the colour palette.
   1.214 +	Cycle through a series of RGB values & compare the Gray256 TRgb colour value with the value produced by generic algorithm
   1.215 + 
   1.216 +   	Expect the conversion from index value to grayscale colour value & back again produces identical value.
   1.217 +	Confirm the algorithm used to produce Gray256 colour set 
   1.218 +*/		
   1.219 +void CTRgb::TestGray256()
   1.220 +	{
   1.221 +	INFO_PRINTF1(_L("Gray256"));
   1.222 +
   1.223 +	for (TInt index = 0; index < 256; index++)
   1.224 +		{
   1.225 +		TRgb color = TRgb::Gray256(index);
   1.226 +		TEST(color.Gray256() == index);
   1.227 +		}
   1.228 +
   1.229 +	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
   1.230 +		{
   1.231 +		TRgb color(value);
   1.232 +		TInt algGray256 = (((value & 0xff) * 2) + (((value >> 8) & 0xff) * 5) + ((value >> 16) & 0xff)) / 8;
   1.233 +		TEST(color.Gray256() == algGray256);
   1.234 +		}
   1.235 +	}
   1.236 +
   1.237 +/**
   1.238 +   	Test 16 Colour colour set
   1.239 +
   1.240 +   	Cycle through each Color16 colour & test the value used to create the colour
   1.241 +	against the index value retrieved from the colour palette.
   1.242 +	Compare the rgb value for each Color16 colour matches that returned by the DynamicPalette colour palette
   1.243 + 
   1.244 +   	Expect the RGB colour value returned matches the 16colour palette
   1.245 +*/		
   1.246 +void CTRgb::TestColor16()
   1.247 +	{
   1.248 +	INFO_PRINTF1(_L("Color16"));
   1.249 +
   1.250 +	for (TInt index = 0; index < 16; index++)
   1.251 +		{
   1.252 +		TRgb color = TRgb::Color16(index);
   1.253 +		TEST(color.Color16() == index);
   1.254 +		TEST(TRgb::Color16(index) == TRgb(DynamicPalette::Color16array()[index]));
   1.255 +		}
   1.256 +	}
   1.257 +
   1.258 +/**
   1.259 +	Test 256 colour set
   1.260 +
   1.261 +    Cycle through each Color256 colour & test the value used to create the colour
   1.262 +	against the index value retrieved from the colour palette.
   1.263 +	Compare the rgb value for each Color256 colour against the rgb value returned by the DynamicPalette colour palette
   1.264 +	Cycle through each Color256 colour & confirm it matches the Netscape Colour Cube
   1.265 +							
   1.266 +   	Expect the RGB colour returned matches the 256 colour palette
   1.267 +*/
   1.268 +void CTRgb::TestColor256()
   1.269 +	{
   1.270 +	INFO_PRINTF1(_L("Color256"));
   1.271 +
   1.272 +	const TInt mainValues[6] = {0x00, 0x33, 0x66, 0x99, 0xcc, 0xff };
   1.273 +	const TInt lowerValues[5] = {0x11, 0x22, 0x44, 0x55, 0x77 };
   1.274 +	const TInt upperValues[5] = {0x88, 0xaa, 0xbb, 0xdd, 0xee };
   1.275 +
   1.276 +	TInt index;
   1.277 +	for (index = 0; index < 256; index++)
   1.278 +		{
   1.279 +		TRgb color = TRgb::Color256(index);
   1.280 +		TEST(color.Color256() == index);
   1.281 +		TEST(TRgb::Color256(index) == TRgb(DynamicPalette::DefaultColor256Util()->iColorTable[index]));
   1.282 +		}
   1.283 +
   1.284 +	for (index = 0; index < 108; index++)
   1.285 +		{
   1.286 +		TRgb color = TRgb::Color256(index);
   1.287 +		TEST(color.Red() == mainValues[index % 6]);
   1.288 +		TEST(color.Green() == mainValues[(index / 6) % 6]);
   1.289 +		TEST(color.Blue() == mainValues[(index / 36) % 6]);
   1.290 +		}
   1.291 +	for (; index < 113; index++)
   1.292 +		{
   1.293 +		TRgb color = TRgb::Color256(index);
   1.294 +		TEST(color.Red() == color.Green());
   1.295 +		TEST(color.Green() == color.Blue());
   1.296 +		TEST(color.Blue() == lowerValues[index - 108]);
   1.297 +		}
   1.298 +	for (; index < 118; index++)
   1.299 +		{
   1.300 +		TRgb color = TRgb::Color256(index);
   1.301 +		TEST(color.Red() == lowerValues[index - 113]);
   1.302 +		TEST(color.Green() == 0);
   1.303 +		TEST(color.Blue() == 0);
   1.304 +		}
   1.305 +	for (; index < 123; index++)
   1.306 +		{
   1.307 +		TRgb color = TRgb::Color256(index);
   1.308 +		TEST(color.Red() == 0);
   1.309 +		TEST(color.Green() == lowerValues[index - 118]);
   1.310 +		TEST(color.Blue() == 0);
   1.311 +		}
   1.312 +	for (; index < 128; index++)
   1.313 +		{
   1.314 +		TRgb color = TRgb::Color256(index);
   1.315 +		TEST(color.Red() == 0);
   1.316 +		TEST(color.Green() == 0);
   1.317 +		TEST(color.Blue() == lowerValues[index - 123]);
   1.318 +		}
   1.319 +	for (; index < 133; index++)
   1.320 +		{
   1.321 +		TRgb color = TRgb::Color256(index);
   1.322 +		TEST(color.Red() == 0);
   1.323 +		TEST(color.Green() == 0);
   1.324 +		TEST(color.Blue() == upperValues[index - 128]);
   1.325 +		}
   1.326 +	for (; index < 138; index++)
   1.327 +		{
   1.328 +		TRgb color = TRgb::Color256(index);
   1.329 +		TEST(color.Red() == 0);
   1.330 +		TEST(color.Green() == upperValues[index - 133]);
   1.331 +		TEST(color.Blue() == 0);
   1.332 +		}
   1.333 +	for (; index < 143; index++)
   1.334 +		{
   1.335 +		TRgb color = TRgb::Color256(index);
   1.336 +		TEST(color.Red() == upperValues[index - 138]);
   1.337 +		TEST(color.Green() == 0);
   1.338 +		TEST(color.Blue() == 0);
   1.339 +		}
   1.340 +	for (; index < 148; index++)
   1.341 +		{
   1.342 +		TRgb color = TRgb::Color256(index);
   1.343 +		TEST(color.Red() == color.Green());
   1.344 +		TEST(color.Green() == color.Blue());
   1.345 +		TEST(color.Blue() == upperValues[index - 143]);
   1.346 +		}
   1.347 +	for (; index < 256; index++)
   1.348 +		{
   1.349 +		TRgb color = TRgb::Color256(index);
   1.350 +		TEST(color.Red() == mainValues[(index - 40) % 6]);
   1.351 +		TEST(color.Green() == mainValues[((index - 40) / 6) % 6]);
   1.352 +		TEST(color.Blue() == mainValues[((index - 40) / 36) % 6]);
   1.353 +		}
   1.354 +	}
   1.355 +
   1.356 +/**
   1.357 +	Test 4096 colour set
   1.358 +
   1.359 +   	Cycle through each Color4K colour & compare the colorscale value used to create the colour
   1.360 +	against the index value retrieved from the colour palette.
   1.361 +	Cycle through a series of RGB values & compare the Color4K TRgb value against that produced by the algorithm
   1.362 + 
   1.363 +   	Confirm the conversion from index value to 4096 colour value & back again produces identical value.
   1.364 +	Confirm the algorithm used to produce 4096 colour set
   1.365 +*/	
   1.366 +void CTRgb::TestColor4K()
   1.367 +	{
   1.368 +	INFO_PRINTF1(_L("Color4K"));
   1.369 +
   1.370 +	for (TInt index = 0; index < 4096; index++)
   1.371 +		{
   1.372 +		TRgb color = TRgb::Color4K(index);
   1.373 +		TEST(color.Color4K() == index);
   1.374 +		}
   1.375 +
   1.376 +	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
   1.377 +		{
   1.378 +		TRgb color(value);
   1.379 +		TInt color4K = ((value & 0xf00000) >> 20) | ((value & 0x00f000) >> 8) | ((value & 0x0000f0) << 4);
   1.380 +		TEST(color.Color4K() == color4K);
   1.381 +		}
   1.382 +	}
   1.383 +
   1.384 +/**
   1.385 +   	Test 64K colour set
   1.386 +
   1.387 +   	Cycle through each Color64K colour & compare the TRgb value used to create the colour
   1.388 +	against the index value retrieved from the colour palette.
   1.389 +	Cycle through a series of RGB values & compare the Color64K TRgb value against that produced by the algorithm
   1.390 + 
   1.391 +   	Confirm the conversion from index value to 64K colour value & back again produces identical value.
   1.392 +	Confirm the algorithm used to produce 64K colour set
   1.393 +*/	
   1.394 +void CTRgb::TestColor64K()
   1.395 +	{
   1.396 +	INFO_PRINTF1(_L("Color64K"));
   1.397 +
   1.398 +	for (TInt index = 0; index < 65536; index++)
   1.399 +		{
   1.400 +		TRgb color = TRgb::Color64K(index);
   1.401 +		TEST(color.Color64K() == index);
   1.402 +		}
   1.403 +
   1.404 +	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
   1.405 +		{
   1.406 +		TRgb color(value);
   1.407 +		TInt color64K = ((value & 0xf8) << 8) + ((value & 0xfc00) >> 5) + ((value & 0xf80000) >> 19);
   1.408 +		TEST(color.Color64K() == color64K);
   1.409 +		}
   1.410 +	}
   1.411 +
   1.412 +/**
   1.413 +	Test 16M colour set
   1.414 +
   1.415 + 	Cycle through each Color16M colour & compare the TRgb value used to create the colour
   1.416 +	against the index value retrieved from the colour palette.
   1.417 +	Cycle through a series of RGB values & compare the Color16M TRgb value against that produced by the algorithm
   1.418 + 
   1.419 +   	Confirm the conversion from index value to 16M colour value & back again produces identical value.
   1.420 +	Confirm the algorithm used to produce 16M colour set
   1.421 +*/	
   1.422 +void CTRgb::TestColor16M()
   1.423 +	{
   1.424 +	INFO_PRINTF1(_L("Color16M"));
   1.425 +
   1.426 +	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
   1.427 +		{
   1.428 +		TRgb color(value);
   1.429 +		TInt color16M = ((value & 0xff0000) >> 16) | (value & 0x00ff00) | ((value & 0x0000ff) << 16);
   1.430 +		TRgb generatedColor = TRgb::Color16M(color16M);
   1.431 +		TEST(color == generatedColor);
   1.432 +		TEST(color.Color16M() == color16M);
   1.433 +		}
   1.434 +	}
   1.435 +
   1.436 +/**
   1.437 +	Test 16MU colour set
   1.438 +
   1.439 +   	Cycle through each Color16MU colour & compare the TRgb value used to create the colour
   1.440 +	against the index value retrieved from the colour palette.
   1.441 +	Cycle through a series of RGB values & compare the Color16MU TRgb value against that produced by the algorithm
   1.442 + 
   1.443 +   	Confirm the conversion from index value to 16MU colour value & back again produces identical value.
   1.444 +	Confirm the algorithm used to produce 16MU colour set
   1.445 +*/	
   1.446 +void CTRgb::TestColor16MU()
   1.447 +	{
   1.448 +	INFO_PRINTF1(_L("Color16MU"));
   1.449 +
   1.450 +	for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
   1.451 +		{
   1.452 +		TRgb color(value);
   1.453 +		TInt color16MU = ((value & 0xff0000) >> 16) | (value & 0x00ff00) | ((value & 0x0000ff) << 16);
   1.454 +		TRgb generatedColor = TRgb::Color16MU(color16MU);
   1.455 +		TEST(color == generatedColor);
   1.456 +		TEST(color.Color16MU() == color16MU);
   1.457 +		}
   1.458 +	}
   1.459 +
   1.460 +/**
   1.461 +   	Test 16MA colour set
   1.462 +
   1.463 +   	Cycle through each Color16MA colour & compare the TRgb value used to create the colour
   1.464 +	against the index value retrieved from the colour palette.
   1.465 +	Cycle through a series of RGB values & compare the Color16MA TRgb value against that produced by the algorithm
   1.466 + 
   1.467 +   	Confirm the conversion from index value to 16MA colour value & back again produces identical value.
   1.468 +	Confirm the algorithm used to produce 16MA colour set
   1.469 +*/
   1.470 +void CTRgb::TestColor16MA()
   1.471 +	{
   1.472 +	INFO_PRINTF1(_L("Color16MA"));
   1.473 +
   1.474 +	for (TUint32 high = 0; high <= 0xffff; high += 51)
   1.475 +		for (TUint32 low = 0; low <= 0xffff; low += 51)
   1.476 +			{
   1.477 +			TUint32 value = (high << 16) + low; // '+' operator has higher precedance than '<<'  operator
   1.478 +			TRgb color(value);
   1.479 +			TInt color16MA = (0xff000000 - (value & 0xff000000)) | ((value & 0xff0000) >> 16) | (value & 0x00ff00) | ((value & 0x0000ff) << 16);
   1.480 +			TRgb generatedColor = TRgb::Color16MA(color16MA);
   1.481 +			TEST(color == generatedColor);
   1.482 +			TEST(color.Color16MA() == color16MA);
   1.483 +			}
   1.484 +	}
   1.485 +
   1.486 +/**
   1.487 +   	Test TColor256Util
   1.488 +
   1.489 +   	Test functionality contained within TColor256Util. 
   1.490 +							
   1.491 +   	Confirm TColor256Util converts correctly between TRgb values & the corresponding index in the colour palette
   1.492 +							
   1.493 +*/
   1.494 +void CTRgb::TestColor256Util()
   1.495 +	{
   1.496 +	INFO_PRINTF1(_L("TColor256Util"));
   1.497 +
   1.498 +	__UHEAP_MARK;
   1.499 +
   1.500 +	TColor256Util* util = new TColor256Util;
   1.501 +	CPalette* palette = NULL;
   1.502 +	TRAPD(err,palette = CPalette::NewDefaultL(EColor256));
   1.503 +	TEST(err==KErrNone);
   1.504 +	util->Construct(*palette);
   1.505 +	TEST(Mem::Compare((TUint8*)util,sizeof(TColor256Util),(TUint8*)DynamicPalette::DefaultColor256Util(),sizeof(TColor256Util))==0);
   1.506 +
   1.507 +	TInt index;
   1.508 +	for (index = 0; index < 256; index++)
   1.509 +		{
   1.510 +		TRgb color = TRgb::Color256(index);
   1.511 +		TEST(util->Color256(index) == color);
   1.512 +		TEST(util->Color256(color) == index);
   1.513 +		}
   1.514 +
   1.515 +	TRgb* rgbBuffer = new TRgb[256];
   1.516 +	TUint8* indexBuffer = new TUint8[256];
   1.517 +	for (index = 0; index < 256; index++)
   1.518 +		rgbBuffer[index] = TRgb::Color256(index);
   1.519 +	util->Color256(indexBuffer,rgbBuffer,256);
   1.520 +	for (index = 0; index < 256; index++)
   1.521 +		TEST(indexBuffer[index]==index);
   1.522 +
   1.523 +	delete[] rgbBuffer;
   1.524 +	delete[] indexBuffer;
   1.525 +	delete palette;
   1.526 +	delete util;
   1.527 +
   1.528 +	__UHEAP_MARKEND;
   1.529 +	}
   1.530 +
   1.531 +/**
   1.532 +	Validate the PreMultiplied value and the Non PreMultiplied value with the expected values.
   1.533 +	@param aAlpha Alpha value of the color.
   1.534 +	@param aValue The value of the color channel(ie. one of Red,Green or Blue).
   1.535 +	@param aPreMulVal The PreMutiplied color value for aValue.
   1.536 +	@param aNonPreMulValue The Non PreMutiplied value for aValue
   1.537 +						   (i.e the value received by Non PreMutiplying aPreMulVal).
   1.538 +
   1.539 +*/
   1.540 +void CTRgb::ValidatePMAndNPM(TInt aAlpha, TInt aValue, TInt aPreMulVal, TInt aNonPreMulValue)
   1.541 +	{
   1.542 +	TInt expPreMulValue = (aValue*(aAlpha+1))/256;
   1.543 +	TInt expNonPreMulValMin = (expPreMulValue * 255) / aAlpha;
   1.544 +	TInt expNonPreMulValMax = expNonPreMulValMin + 1;
   1.545 +	if (expNonPreMulValMax > 255)
   1.546 +		{
   1.547 +		expNonPreMulValMax = 255;
   1.548 +		}
   1.549 +	TEST(expPreMulValue == aPreMulVal);
   1.550 +	TEST(expNonPreMulValMin <= aNonPreMulValue && expNonPreMulValMax >= aNonPreMulValue);
   1.551 +	}
   1.552 +
   1.553 +/**
   1.554 +   	DEF103742 - Test the PreMultiply and Non PreMultiply conversion.
   1.555 +
   1.556 +   	Convert the color values into PreMultiplied color values and again back to
   1.557 +   	the Non PreMultiplied color values.
   1.558 +   	Compare the  converted values with the expected values to validate the functionality.
   1.559 + 
   1.560 +   	Confirm the PreMultiplied and Non PreMultiplied color values match with the expected values.
   1.561 +*/		
   1.562 +void CTRgb::TestColor16MAP()
   1.563 +	{
   1.564 +	INFO_PRINTF1(_L("Color16MAP"));
   1.565 +	for (TInt alpha = 0; alpha < 256; alpha += 51)
   1.566 +		{
   1.567 +		for (TUint32 value = 0; value <= 0x00ffffff; value += 0x1f1f)
   1.568 +			{
   1.569 +			TRgb color(value, alpha);
   1.570 +			TUint pmColor = color.Color16MAP();
   1.571 +			TRgb npmColor = TRgb::Color16MAP(pmColor);
   1.572 +
   1.573 +			TInt pmAlpha = (pmColor & 0xFF000000) >> 24;
   1.574 +
   1.575 +			// These really must be right!
   1.576 +			TEST(pmAlpha == alpha);
   1.577 +			TEST(npmColor.Alpha() == alpha);
   1.578 +
   1.579 +			// These definitely ought to be right
   1.580 +			if (alpha == 0)	// Full transparency, expect black
   1.581 +				{
   1.582 +				TEST(pmColor == 0);
   1.583 +				TEST(npmColor.Internal() == 0);
   1.584 +				}
   1.585 +			else if (alpha == 255)	// Full opacity, expect roundtrip
   1.586 +				{
   1.587 +				TEST(pmColor == color.Internal());
   1.588 +				TEST(npmColor == color);
   1.589 +				}
   1.590 +			else
   1.591 +				{
   1.592 +				// Most awkward cases: semi-transparency.
   1.593 +				TInt pmRed   = (pmColor & 0x00FF0000) >> 16;
   1.594 +				TInt pmGreen = (pmColor & 0x0000FF00) >> 8;
   1.595 +				TInt pmBlue  = pmColor & 0xFF;
   1.596 +				ValidatePMAndNPM(alpha, color.Red(), pmRed, npmColor.Red());
   1.597 +				ValidatePMAndNPM(alpha, color.Green(), pmGreen, npmColor.Green());
   1.598 +				ValidatePMAndNPM(alpha, color.Blue(), pmBlue, npmColor.Blue());
   1.599 +				}
   1.600 +			}
   1.601 +		}
   1.602 +	}
   1.603 +
   1.604 +//--------------
   1.605 +__CONSTRUCT_STEP__(Rgb)