os/graphics/graphicsdeviceinterface/directgdiadaptation/hwsrc/blendingalgorithms.inl
First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 const TUint32 KRBMask = 0x00ff00ff;
17 const TUint32 KAGMask = 0xff00ff00;
18 const TUint32 KGMask = 0x0000ff00;
20 const TUint16 NormalisationTable[256] = {
21 0,65280,32640,21760,16320,13056,10880,9326,8160,7254,6528,
22 5935,5440,5022,4663,4352,4080,3840,3627,3436,3264,
23 3109,2968,2839,2720,2612,2511,2418,2332,2252,2176,
24 2106,2040,1979,1920,1866,1814,1765,1718,1674,1632,
25 1593,1555,1519,1484,1451,1420,1389,1360,1333,1306,
26 1280,1256,1232,1209,1187,1166,1146,1126,1107,1088,
27 1071,1053,1037,1020,1005,990,975,960,947,933,
28 920,907,895,883,871,859,848,837,827,816,
29 806,797,787,778,768,760,751,742,734,726,
30 718,710,702,695,688,680,673,667,660,653,
31 647,640,634,628,622,616,611,605,599,594,
32 589,583,578,573,568,563,558,554,549,544,
33 540,536,531,527,523,519,515,510,507,503,
34 499,495,491,488,484,480,477,474,470,467,
35 463,460,457,454,451,448,445,442,439,436,
36 433,430,427,424,422,419,416,414,411,408,
37 406,403,401,399,396,394,391,389,387,384,
38 382,380,378,376,374,371,369,367,365,363,
39 361,359,357,355,353,351,350,348,346,344,
40 342,340,339,337,335,334,332,330,329,327,
41 325,324,322,320,319,317,316,314,313,311,
42 310,308,307,306,304,303,301,300,299,297,
43 296,295,293,292,291,289,288,287,286,284,
44 283,282,281,279,278,277,276,275,274,272,
45 271,270,269,268,267,266,265,264,263,262,
49 //Algoriths for Premultiplied alpha screenmode/pixel format.
52 Blend A over B. From Porter & Duff:
53 C = CaFa+CbFb, where Ca = aSrcPixel, Cb = aDest_io, Fa = 1, Fb=(1-Alpha(a))
56 @param aDestPixel Destination pixel.
57 @param aSrcPixel Source pixel.
58 @param aMaskingFactor Alpha channel of aSrcPixel.
60 inline TUint32 PMABlend_noChecks(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMaskingFactor)
62 TUint32 src_c = aSrcPixel & KRBMask;
63 TUint32 dst_c = aDestPixel & KRBMask;
64 const TUint32 mask = 0x0100 - aMaskingFactor;
65 dst_c = (src_c + ((mask * dst_c)>>8)) & KRBMask;
66 src_c = (aSrcPixel & KAGMask)>>8;
67 TUint32 dst_ag = (aDestPixel & KAGMask)>>8;
68 dst_c |= ((src_c + ((mask * dst_ag)>>8)) & KRBMask)<<8;
72 inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMask)
76 if(aMask == 0xff) // opaque, so unchanged
82 return PMABlend_noChecks(aDestPixel, aSrcPixel, aMask);
85 else // completely transparent
91 inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel)
93 TUint8 mask = (TUint8)(aSrcPixel >> 24);
94 return PMAPixelBlend(aDestPixel, aSrcPixel, mask);
97 inline TUint32 NonPMA2PMAPixel(TUint32 aPixel)
99 TUint8 tA = (TUint8)(aPixel >> 24);
109 // Use a bias value of 128 rather than 255, but also add 1/256 of the numerator
110 // before dividing the sum by 256.
113 TUint32 scaledRB = (aPixel & KRBMask) * tap1;
114 TUint32 scaledG = (aPixel & KGMask ) * tap1;
115 return (aPixel & 0xff000000) | ((scaledRB>>8) & KRBMask) | ((scaledG>>8)& KGMask);
118 inline TUint32 PMA2NonPMAPixel(TUint32 aPixel)
120 TUint8 alpha = (TUint8)(aPixel >> 24);
129 TUint16 norm = NormalisationTable[alpha];
130 TUint32 norm_rb = (((aPixel & KRBMask) * norm) >> 8) & KRBMask;
131 TUint32 norm_g = (((aPixel & KGMask ) * norm) >> 8) & KGMask;
132 return ((aPixel & 0xff000000) | norm_rb | norm_g);