Update contrib.
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 //Algoriths for Premultiplied alpha screenmode/pixel format.
22 inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMask)
26 if(aMask == 0xff) // opaque, so unchanged
32 return PMABlend_noChecks(aDestPixel, aSrcPixel, aMask);
35 else // completely transparent
41 inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel)
43 TUint8 mask = (TUint8)(aSrcPixel >> 24);
44 return PMAPixelBlend(aDestPixel, aSrcPixel, mask);
47 inline TUint32 PMABlend_noChecks(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMaskingFactor)
49 TUint32 src_c = aSrcPixel & KRBMask;
50 TUint32 dst_c = aDestPixel & KRBMask;
51 const TUint32 mask = 0x0100 - aMaskingFactor;
52 dst_c = (src_c + ((mask * dst_c)>>8)) & KRBMask;
53 src_c = (aSrcPixel & KAGMask)>>8;
54 TUint32 dst_ag = (aDestPixel & KAGMask)>>8;
55 dst_c |= ((src_c + ((mask * dst_ag)>>8)) & KRBMask)<<8;
59 inline void PMABlend_noChecksInplace(TUint32& aDest_io, const TUint32& aSrcPixel, TUint8 aMaskingFactor)
61 TUint32 src_c = aSrcPixel & KRBMask;
62 TUint32 dst_ag = (aDest_io & KAGMask) >> 8;
63 aDest_io = aDest_io & KRBMask;
64 const TUint32 mask = 0x0100 - aMaskingFactor;
65 aDest_io = (src_c + ((mask * aDest_io) >> 8)) & KRBMask;
66 src_c = (aSrcPixel & KAGMask) >> 8;
67 aDest_io |= ((src_c + ((mask * dst_ag) >> 8)) & KRBMask)<<8;
70 inline void PMAInplaceBlend(TUint32& aDest_io, TUint32& aSrc_in)
72 TUint8 mask = (TUint8)(aSrc_in >> 24);
75 if(mask == 0xff) // opaque, so dst = src.
81 PMABlend_noChecksInplace(aDest_io, aSrc_in, mask);
84 //else src completely transparent, so dst unchanged.
87 inline TUint32 NonPMA2PMAPixel(TUint32 aPixel)
89 TUint8 tA = (TUint8)(aPixel >> 24);
99 // Use a bias value of 128 rather than 255, but also add 1/256 of the numerator
100 // before dividing the sum by 256.
103 TUint32 scaledRB = (aPixel & KRBMask) * tap1;
104 TUint32 scaledG = (aPixel & KGMask ) * tap1;
105 return (aPixel & 0xff000000) | ((scaledRB>>8) & KRBMask) | ((scaledG>>8)& KGMask);
108 inline TUint32 PMA2NonPMAPixel(TUint32 aPixel, const TUint16* aNormTable)
110 TUint8 alpha = (TUint8)(aPixel >> 24);
119 TUint16 norm = aNormTable[alpha];
120 TUint32 norm_rb = (((aPixel & KRBMask) * norm) >> 8) & KRBMask;
121 TUint32 norm_g = (((aPixel & KGMask ) * norm) >> 8) & KGMask;
122 return ((aPixel & 0xff000000) | norm_rb | norm_g);
125 inline void Convert2PMA(TUint32& aInOutValue)
127 aInOutValue = NonPMA2PMAPixel(aInOutValue);
130 inline void Convert2NonPMA(TUint32& aInOutValue, const TUint16* aNormTable)
132 aInOutValue = PMA2NonPMAPixel(aInOutValue, aNormTable);