First public contribution.
1 // Copyright (c) 1998-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 CTRgb::CTRgb(CTestStep* aStep):
23 INFO_PRINTF1(_L("Testing TRgb colour functions"));
26 void CTRgb::RunTestCaseL(TInt aCurTestCase)
28 ((CTRgbStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
33 @SYMTestCaseID GRAPHICS-GDI-RGB-0001
35 ((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0001"));
40 @SYMTestCaseID GRAPHICS-GDI-RGB-0002
42 ((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0002"));
47 @SYMTestCaseID GRAPHICS-GDI-RGB-0003
49 ((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0003"));
54 @SYMTestCaseID GRAPHICS-GDI-RGB-0004
56 ((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0004"));
61 @SYMTestCaseID GRAPHICS-GDI-RGB-0005
63 ((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0005"));
68 @SYMTestCaseID GRAPHICS-GDI-RGB-0006
70 ((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0006"));
75 @SYMTestCaseID GRAPHICS-GDI-RGB-0007
77 ((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0007"));
82 @SYMTestCaseID GRAPHICS-GDI-RGB-0008
84 ((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0008"));
89 @SYMTestCaseID GRAPHICS-GDI-RGB-0009
91 ((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0009"));
96 @SYMTestCaseID GRAPHICS-GDI-RGB-0010
98 ((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0010"));
103 @SYMTestCaseID GRAPHICS-GDI-RGB-0011
105 ((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0011"));
110 @SYMTestCaseID GRAPHICS-GDI-RGB-0012
112 ((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0012"));
117 @SYMTestCaseID GRAPHICS-GDI-RGB-0013
119 ((CTRgbStep*)iStep)->SetTestStepID(_L("GRAPHICS-GDI-RGB-0013"));
123 ((CTRgbStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
124 ((CTRgbStep*)iStep)->CloseTMSGraphicsStep();
128 ((CTRgbStep*)iStep)->RecordTestResultL();
132 Test Gray2 colour set
134 Cycle through each Gray2 colour & compare the grayscale value used to create the colour
135 against the index value retrieved from the colour palette.
136 Cycle through a series of RGB values & compare the Gray2 TRgb value with a subset of the Gray256 colour-set.
138 Expect the conversion from index value to grayscale colour value & back again produces identical value.
139 Expect the Gray2 rgb colour set forms a subset of the Gray256 colour rgb set
141 void CTRgb::TestGray2()
143 INFO_PRINTF1(_L("Gray2"));
145 for (TInt index = 0; index < 2; index++)
147 TRgb color = TRgb::Gray2(index);
148 TEST(color.Gray2() == index);
151 for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
154 TEST(color.Gray2() == color.Gray256() / 128);
159 Cycle through each Gray4 colour & compare the grayscale value used to create the colour
160 against the index value retrieved from the colour palette.
161 Cycle through a series of RGB values & compare the Gray4 TRgb colour value with a subset of the Gray256 colour-set.
163 Expect conversion from index value to grayscale colour value & back again produces identical value.
164 Expect the Gray4 rgb colour set forms a subset of the Gray256 colour rgb set
166 void CTRgb::TestGray4()
168 INFO_PRINTF1(_L("Gray4"));
170 for (TInt index = 0; index < 4; index++)
172 TRgb color = TRgb::Gray4(index);
173 TEST(color.Gray4() == index);
176 for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
179 TEST(color.Gray4() == color.Gray256() / 64);
184 Cycle through each Gray16 colour & compare the grayscale value used to create the colour
185 against the index value retrieved from the colour palette.
186 Cycle through a series of RGB values & compare the Gray16 TRgb value with a subset of the Gray256 colour-set.
188 Expect the conversion from index value to grayscale colour value & back again produces identical value.
189 Expect the Gray16 rgb colour set forms a subset of the Gray256 colour rgb set
191 void CTRgb::TestGray16()
193 INFO_PRINTF1(_L("Gray16"));
195 for (TInt index = 0; index < 16; index++)
197 TRgb color = TRgb::Gray16(index);
198 TEST(color.Gray16() == index);
201 for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
204 TEST(color.Gray16() == color.Gray256() / 16);
209 Cycle through each Gray256 colour & compare the grayscale value used to create the colour
210 against the index value retrieved from the colour palette.
211 Cycle through a series of RGB values & compare the Gray256 TRgb colour value with the value produced by generic algorithm
213 Expect the conversion from index value to grayscale colour value & back again produces identical value.
214 Confirm the algorithm used to produce Gray256 colour set
216 void CTRgb::TestGray256()
218 INFO_PRINTF1(_L("Gray256"));
220 for (TInt index = 0; index < 256; index++)
222 TRgb color = TRgb::Gray256(index);
223 TEST(color.Gray256() == index);
226 for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
229 TInt algGray256 = (((value & 0xff) * 2) + (((value >> 8) & 0xff) * 5) + ((value >> 16) & 0xff)) / 8;
230 TEST(color.Gray256() == algGray256);
235 Test 16 Colour colour set
237 Cycle through each Color16 colour & test the value used to create the colour
238 against the index value retrieved from the colour palette.
239 Compare the rgb value for each Color16 colour matches that returned by the DynamicPalette colour palette
241 Expect the RGB colour value returned matches the 16colour palette
243 void CTRgb::TestColor16()
245 INFO_PRINTF1(_L("Color16"));
247 for (TInt index = 0; index < 16; index++)
249 TRgb color = TRgb::Color16(index);
250 TEST(color.Color16() == index);
251 TEST(TRgb::Color16(index) == TRgb(DynamicPalette::Color16array()[index]));
258 Cycle through each Color256 colour & test the value used to create the colour
259 against the index value retrieved from the colour palette.
260 Compare the rgb value for each Color256 colour against the rgb value returned by the DynamicPalette colour palette
261 Cycle through each Color256 colour & confirm it matches the Netscape Colour Cube
263 Expect the RGB colour returned matches the 256 colour palette
265 void CTRgb::TestColor256()
267 INFO_PRINTF1(_L("Color256"));
269 const TInt mainValues[6] = {0x00, 0x33, 0x66, 0x99, 0xcc, 0xff };
270 const TInt lowerValues[5] = {0x11, 0x22, 0x44, 0x55, 0x77 };
271 const TInt upperValues[5] = {0x88, 0xaa, 0xbb, 0xdd, 0xee };
274 for (index = 0; index < 256; index++)
276 TRgb color = TRgb::Color256(index);
277 TEST(color.Color256() == index);
278 TEST(TRgb::Color256(index) == TRgb(DynamicPalette::DefaultColor256Util()->iColorTable[index]));
281 for (index = 0; index < 108; index++)
283 TRgb color = TRgb::Color256(index);
284 TEST(color.Red() == mainValues[index % 6]);
285 TEST(color.Green() == mainValues[(index / 6) % 6]);
286 TEST(color.Blue() == mainValues[(index / 36) % 6]);
288 for (; index < 113; index++)
290 TRgb color = TRgb::Color256(index);
291 TEST(color.Red() == color.Green());
292 TEST(color.Green() == color.Blue());
293 TEST(color.Blue() == lowerValues[index - 108]);
295 for (; index < 118; index++)
297 TRgb color = TRgb::Color256(index);
298 TEST(color.Red() == lowerValues[index - 113]);
299 TEST(color.Green() == 0);
300 TEST(color.Blue() == 0);
302 for (; index < 123; index++)
304 TRgb color = TRgb::Color256(index);
305 TEST(color.Red() == 0);
306 TEST(color.Green() == lowerValues[index - 118]);
307 TEST(color.Blue() == 0);
309 for (; index < 128; index++)
311 TRgb color = TRgb::Color256(index);
312 TEST(color.Red() == 0);
313 TEST(color.Green() == 0);
314 TEST(color.Blue() == lowerValues[index - 123]);
316 for (; index < 133; index++)
318 TRgb color = TRgb::Color256(index);
319 TEST(color.Red() == 0);
320 TEST(color.Green() == 0);
321 TEST(color.Blue() == upperValues[index - 128]);
323 for (; index < 138; index++)
325 TRgb color = TRgb::Color256(index);
326 TEST(color.Red() == 0);
327 TEST(color.Green() == upperValues[index - 133]);
328 TEST(color.Blue() == 0);
330 for (; index < 143; index++)
332 TRgb color = TRgb::Color256(index);
333 TEST(color.Red() == upperValues[index - 138]);
334 TEST(color.Green() == 0);
335 TEST(color.Blue() == 0);
337 for (; index < 148; index++)
339 TRgb color = TRgb::Color256(index);
340 TEST(color.Red() == color.Green());
341 TEST(color.Green() == color.Blue());
342 TEST(color.Blue() == upperValues[index - 143]);
344 for (; index < 256; index++)
346 TRgb color = TRgb::Color256(index);
347 TEST(color.Red() == mainValues[(index - 40) % 6]);
348 TEST(color.Green() == mainValues[((index - 40) / 6) % 6]);
349 TEST(color.Blue() == mainValues[((index - 40) / 36) % 6]);
356 Cycle through each Color4K colour & compare the colorscale value used to create the colour
357 against the index value retrieved from the colour palette.
358 Cycle through a series of RGB values & compare the Color4K TRgb value against that produced by the algorithm
360 Confirm the conversion from index value to 4096 colour value & back again produces identical value.
361 Confirm the algorithm used to produce 4096 colour set
363 void CTRgb::TestColor4K()
365 INFO_PRINTF1(_L("Color4K"));
367 for (TInt index = 0; index < 4096; index++)
369 TRgb color = TRgb::Color4K(index);
370 TEST(color.Color4K() == index);
373 for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
376 TInt color4K = ((value & 0xf00000) >> 20) | ((value & 0x00f000) >> 8) | ((value & 0x0000f0) << 4);
377 TEST(color.Color4K() == color4K);
384 Cycle through each Color64K colour & compare the TRgb value used to create the colour
385 against the index value retrieved from the colour palette.
386 Cycle through a series of RGB values & compare the Color64K TRgb value against that produced by the algorithm
388 Confirm the conversion from index value to 64K colour value & back again produces identical value.
389 Confirm the algorithm used to produce 64K colour set
391 void CTRgb::TestColor64K()
393 INFO_PRINTF1(_L("Color64K"));
395 for (TInt index = 0; index < 65536; index++)
397 TRgb color = TRgb::Color64K(index);
398 TEST(color.Color64K() == index);
401 for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
404 TInt color64K = ((value & 0xf8) << 8) + ((value & 0xfc00) >> 5) + ((value & 0xf80000) >> 19);
405 TEST(color.Color64K() == color64K);
412 Cycle through each Color16M colour & compare the TRgb value used to create the colour
413 against the index value retrieved from the colour palette.
414 Cycle through a series of RGB values & compare the Color16M TRgb value against that produced by the algorithm
416 Confirm the conversion from index value to 16M colour value & back again produces identical value.
417 Confirm the algorithm used to produce 16M colour set
419 void CTRgb::TestColor16M()
421 INFO_PRINTF1(_L("Color16M"));
423 for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
426 TInt color16M = ((value & 0xff0000) >> 16) | (value & 0x00ff00) | ((value & 0x0000ff) << 16);
427 TRgb generatedColor = TRgb::Color16M(color16M);
428 TEST(color == generatedColor);
429 TEST(color.Color16M() == color16M);
436 Cycle through each Color16MU colour & compare the TRgb value used to create the colour
437 against the index value retrieved from the colour palette.
438 Cycle through a series of RGB values & compare the Color16MU TRgb value against that produced by the algorithm
440 Confirm the conversion from index value to 16MU colour value & back again produces identical value.
441 Confirm the algorithm used to produce 16MU colour set
443 void CTRgb::TestColor16MU()
445 INFO_PRINTF1(_L("Color16MU"));
447 for (TUint32 value = 0; value <= 0x00ffffff; value += 31)
450 TInt color16MU = ((value & 0xff0000) >> 16) | (value & 0x00ff00) | ((value & 0x0000ff) << 16);
451 TRgb generatedColor = TRgb::Color16MU(color16MU);
452 TEST(color == generatedColor);
453 TEST(color.Color16MU() == color16MU);
460 Cycle through each Color16MA colour & compare the TRgb value used to create the colour
461 against the index value retrieved from the colour palette.
462 Cycle through a series of RGB values & compare the Color16MA TRgb value against that produced by the algorithm
464 Confirm the conversion from index value to 16MA colour value & back again produces identical value.
465 Confirm the algorithm used to produce 16MA colour set
467 void CTRgb::TestColor16MA()
469 INFO_PRINTF1(_L("Color16MA"));
471 for (TUint32 high = 0; high <= 0xffff; high += 51)
472 for (TUint32 low = 0; low <= 0xffff; low += 51)
474 TUint32 value = (high << 16) + low; // '+' operator has higher precedance than '<<' operator
476 TInt color16MA = (0xff000000 - (value & 0xff000000)) | ((value & 0xff0000) >> 16) | (value & 0x00ff00) | ((value & 0x0000ff) << 16);
477 TRgb generatedColor = TRgb::Color16MA(color16MA);
478 TEST(color == generatedColor);
479 TEST(color.Color16MA() == color16MA);
486 Test functionality contained within TColor256Util.
488 Confirm TColor256Util converts correctly between TRgb values & the corresponding index in the colour palette
491 void CTRgb::TestColor256Util()
493 INFO_PRINTF1(_L("TColor256Util"));
497 TColor256Util* util = new TColor256Util;
498 CPalette* palette = NULL;
499 TRAPD(err,palette = CPalette::NewDefaultL(EColor256));
501 util->Construct(*palette);
502 TEST(Mem::Compare((TUint8*)util,sizeof(TColor256Util),(TUint8*)DynamicPalette::DefaultColor256Util(),sizeof(TColor256Util))==0);
505 for (index = 0; index < 256; index++)
507 TRgb color = TRgb::Color256(index);
508 TEST(util->Color256(index) == color);
509 TEST(util->Color256(color) == index);
512 TRgb* rgbBuffer = new TRgb[256];
513 TUint8* indexBuffer = new TUint8[256];
514 for (index = 0; index < 256; index++)
515 rgbBuffer[index] = TRgb::Color256(index);
516 util->Color256(indexBuffer,rgbBuffer,256);
517 for (index = 0; index < 256; index++)
518 TEST(indexBuffer[index]==index);
521 delete[] indexBuffer;
529 Validate the PreMultiplied value and the Non PreMultiplied value with the expected values.
530 @param aAlpha Alpha value of the color.
531 @param aValue The value of the color channel(ie. one of Red,Green or Blue).
532 @param aPreMulVal The PreMutiplied color value for aValue.
533 @param aNonPreMulValue The Non PreMutiplied value for aValue
534 (i.e the value received by Non PreMutiplying aPreMulVal).
537 void CTRgb::ValidatePMAndNPM(TInt aAlpha, TInt aValue, TInt aPreMulVal, TInt aNonPreMulValue)
539 TInt expPreMulValue = (aValue*(aAlpha+1))/256;
540 TInt expNonPreMulValMin = (expPreMulValue * 255) / aAlpha;
541 TInt expNonPreMulValMax = expNonPreMulValMin + 1;
542 if (expNonPreMulValMax > 255)
544 expNonPreMulValMax = 255;
546 TEST(expPreMulValue == aPreMulVal);
547 TEST(expNonPreMulValMin <= aNonPreMulValue && expNonPreMulValMax >= aNonPreMulValue);
551 DEF103742 - Test the PreMultiply and Non PreMultiply conversion.
553 Convert the color values into PreMultiplied color values and again back to
554 the Non PreMultiplied color values.
555 Compare the converted values with the expected values to validate the functionality.
557 Confirm the PreMultiplied and Non PreMultiplied color values match with the expected values.
559 void CTRgb::TestColor16MAP()
561 INFO_PRINTF1(_L("Color16MAP"));
562 for (TInt alpha = 0; alpha < 256; alpha += 51)
564 for (TUint32 value = 0; value <= 0x00ffffff; value += 0x1f1f)
566 TRgb color(value, alpha);
567 TUint pmColor = color.Color16MAP();
568 TRgb npmColor = TRgb::Color16MAP(pmColor);
570 TInt pmAlpha = (pmColor & 0xFF000000) >> 24;
572 // These really must be right!
573 TEST(pmAlpha == alpha);
574 TEST(npmColor.Alpha() == alpha);
576 // These definitely ought to be right
577 if (alpha == 0) // Full transparency, expect black
580 TEST(npmColor.Internal() == 0);
582 else if (alpha == 255) // Full opacity, expect roundtrip
584 TEST(pmColor == color.Internal());
585 TEST(npmColor == color);
589 // Most awkward cases: semi-transparency.
590 TInt pmRed = (pmColor & 0x00FF0000) >> 16;
591 TInt pmGreen = (pmColor & 0x0000FF00) >> 8;
592 TInt pmBlue = pmColor & 0xFF;
593 ValidatePMAndNPM(alpha, color.Red(), pmRed, npmColor.Red());
594 ValidatePMAndNPM(alpha, color.Green(), pmGreen, npmColor.Green());
595 ValidatePMAndNPM(alpha, color.Blue(), pmBlue, npmColor.Blue());
602 __CONSTRUCT_STEP__(Rgb)