os/graphics/graphicsdeviceinterface/directgdiadaptation/hwsrc/blendingalgorithms.inl
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/directgdiadaptation/hwsrc/blendingalgorithms.inl Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,134 @@
1.4 +// Copyright (c) 2007-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 +const TUint32 KRBMask = 0x00ff00ff;
1.20 +const TUint32 KAGMask = 0xff00ff00;
1.21 +const TUint32 KGMask = 0x0000ff00;
1.22 +
1.23 +const TUint16 NormalisationTable[256] = {
1.24 + 0,65280,32640,21760,16320,13056,10880,9326,8160,7254,6528,
1.25 + 5935,5440,5022,4663,4352,4080,3840,3627,3436,3264,
1.26 + 3109,2968,2839,2720,2612,2511,2418,2332,2252,2176,
1.27 + 2106,2040,1979,1920,1866,1814,1765,1718,1674,1632,
1.28 + 1593,1555,1519,1484,1451,1420,1389,1360,1333,1306,
1.29 + 1280,1256,1232,1209,1187,1166,1146,1126,1107,1088,
1.30 + 1071,1053,1037,1020,1005,990,975,960,947,933,
1.31 + 920,907,895,883,871,859,848,837,827,816,
1.32 + 806,797,787,778,768,760,751,742,734,726,
1.33 + 718,710,702,695,688,680,673,667,660,653,
1.34 + 647,640,634,628,622,616,611,605,599,594,
1.35 + 589,583,578,573,568,563,558,554,549,544,
1.36 + 540,536,531,527,523,519,515,510,507,503,
1.37 + 499,495,491,488,484,480,477,474,470,467,
1.38 + 463,460,457,454,451,448,445,442,439,436,
1.39 + 433,430,427,424,422,419,416,414,411,408,
1.40 + 406,403,401,399,396,394,391,389,387,384,
1.41 + 382,380,378,376,374,371,369,367,365,363,
1.42 + 361,359,357,355,353,351,350,348,346,344,
1.43 + 342,340,339,337,335,334,332,330,329,327,
1.44 + 325,324,322,320,319,317,316,314,313,311,
1.45 + 310,308,307,306,304,303,301,300,299,297,
1.46 + 296,295,293,292,291,289,288,287,286,284,
1.47 + 283,282,281,279,278,277,276,275,274,272,
1.48 + 271,270,269,268,267,266,265,264,263,262,
1.49 + 261,260,259,258,256,
1.50 +};
1.51 +
1.52 +//Algoriths for Premultiplied alpha screenmode/pixel format.
1.53 +
1.54 +/**
1.55 +Blend A over B. From Porter & Duff:
1.56 +C = CaFa+CbFb, where Ca = aSrcPixel, Cb = aDest_io, Fa = 1, Fb=(1-Alpha(a))
1.57 +C = Ca+Cb(1-Alpha(a))
1.58 +
1.59 +@param aDestPixel Destination pixel.
1.60 +@param aSrcPixel Source pixel.
1.61 +@param aMaskingFactor Alpha channel of aSrcPixel.
1.62 +*/
1.63 +inline TUint32 PMABlend_noChecks(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMaskingFactor)
1.64 + {
1.65 + TUint32 src_c = aSrcPixel & KRBMask;
1.66 + TUint32 dst_c = aDestPixel & KRBMask;
1.67 + const TUint32 mask = 0x0100 - aMaskingFactor;
1.68 + dst_c = (src_c + ((mask * dst_c)>>8)) & KRBMask;
1.69 + src_c = (aSrcPixel & KAGMask)>>8;
1.70 + TUint32 dst_ag = (aDestPixel & KAGMask)>>8;
1.71 + dst_c |= ((src_c + ((mask * dst_ag)>>8)) & KRBMask)<<8;
1.72 + return dst_c;
1.73 + }
1.74 +
1.75 +inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMask)
1.76 + {
1.77 + if(aMask)
1.78 + {
1.79 + if(aMask == 0xff) // opaque, so unchanged
1.80 + {
1.81 + return aSrcPixel;
1.82 + }
1.83 + else
1.84 + {
1.85 + return PMABlend_noChecks(aDestPixel, aSrcPixel, aMask);
1.86 + }
1.87 + }
1.88 + else // completely transparent
1.89 + {
1.90 + return aDestPixel;
1.91 + }
1.92 + }
1.93 +
1.94 +inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel)
1.95 + {
1.96 + TUint8 mask = (TUint8)(aSrcPixel >> 24);
1.97 + return PMAPixelBlend(aDestPixel, aSrcPixel, mask);
1.98 + }
1.99 +
1.100 +inline TUint32 NonPMA2PMAPixel(TUint32 aPixel)
1.101 + {
1.102 + TUint8 tA = (TUint8)(aPixel >> 24);
1.103 + if (tA==0)
1.104 + {
1.105 + return 0;
1.106 + }
1.107 + if (tA==0xff)
1.108 + {
1.109 + return aPixel;
1.110 + }
1.111 +
1.112 + // Use a bias value of 128 rather than 255, but also add 1/256 of the numerator
1.113 + // before dividing the sum by 256.
1.114 +
1.115 + TUint32 tap1=tA+1;
1.116 + TUint32 scaledRB = (aPixel & KRBMask) * tap1;
1.117 + TUint32 scaledG = (aPixel & KGMask ) * tap1;
1.118 + return (aPixel & 0xff000000) | ((scaledRB>>8) & KRBMask) | ((scaledG>>8)& KGMask);
1.119 + }
1.120 +
1.121 +inline TUint32 PMA2NonPMAPixel(TUint32 aPixel)
1.122 + {
1.123 + TUint8 alpha = (TUint8)(aPixel >> 24);
1.124 + if (alpha==0)
1.125 + {
1.126 + return 0;
1.127 + }
1.128 + if (alpha==0xff)
1.129 + {
1.130 + return aPixel;
1.131 + }
1.132 + TUint16 norm = NormalisationTable[alpha];
1.133 + TUint32 norm_rb = (((aPixel & KRBMask) * norm) >> 8) & KRBMask;
1.134 + TUint32 norm_g = (((aPixel & KGMask ) * norm) >> 8) & KGMask;
1.135 + return ((aPixel & 0xff000000) | norm_rb | norm_g);
1.136 + }
1.137 +