sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
const TUint32 KRBMask = 0x00ff00ff;
|
sl@0
|
17 |
const TUint32 KAGMask = 0xff00ff00;
|
sl@0
|
18 |
const TUint32 KGMask = 0x0000ff00;
|
sl@0
|
19 |
|
sl@0
|
20 |
//Algoriths for Premultiplied alpha screenmode/pixel format.
|
sl@0
|
21 |
|
sl@0
|
22 |
inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMask)
|
sl@0
|
23 |
{
|
sl@0
|
24 |
if(aMask)
|
sl@0
|
25 |
{
|
sl@0
|
26 |
if(aMask == 0xff) // opaque, so unchanged
|
sl@0
|
27 |
{
|
sl@0
|
28 |
return aSrcPixel;
|
sl@0
|
29 |
}
|
sl@0
|
30 |
else
|
sl@0
|
31 |
{
|
sl@0
|
32 |
return PMABlend_noChecks(aDestPixel, aSrcPixel, aMask);
|
sl@0
|
33 |
}
|
sl@0
|
34 |
}
|
sl@0
|
35 |
else // completely transparent
|
sl@0
|
36 |
{
|
sl@0
|
37 |
return aDestPixel;
|
sl@0
|
38 |
}
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
TUint8 mask = (TUint8)(aSrcPixel >> 24);
|
sl@0
|
44 |
return PMAPixelBlend(aDestPixel, aSrcPixel, mask);
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
inline TUint32 PMABlend_noChecks(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMaskingFactor)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
TUint32 src_c = aSrcPixel & KRBMask;
|
sl@0
|
50 |
TUint32 dst_c = aDestPixel & KRBMask;
|
sl@0
|
51 |
const TUint32 mask = 0x0100 - aMaskingFactor;
|
sl@0
|
52 |
dst_c = (src_c + ((mask * dst_c)>>8)) & KRBMask;
|
sl@0
|
53 |
src_c = (aSrcPixel & KAGMask)>>8;
|
sl@0
|
54 |
TUint32 dst_ag = (aDestPixel & KAGMask)>>8;
|
sl@0
|
55 |
dst_c |= ((src_c + ((mask * dst_ag)>>8)) & KRBMask)<<8;
|
sl@0
|
56 |
return dst_c;
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
inline void PMABlend_noChecksInplace(TUint32& aDest_io, const TUint32& aSrcPixel, TUint8 aMaskingFactor)
|
sl@0
|
60 |
{
|
sl@0
|
61 |
TUint32 src_c = aSrcPixel & KRBMask;
|
sl@0
|
62 |
TUint32 dst_ag = (aDest_io & KAGMask) >> 8;
|
sl@0
|
63 |
aDest_io = aDest_io & KRBMask;
|
sl@0
|
64 |
const TUint32 mask = 0x0100 - aMaskingFactor;
|
sl@0
|
65 |
aDest_io = (src_c + ((mask * aDest_io) >> 8)) & KRBMask;
|
sl@0
|
66 |
src_c = (aSrcPixel & KAGMask) >> 8;
|
sl@0
|
67 |
aDest_io |= ((src_c + ((mask * dst_ag) >> 8)) & KRBMask)<<8;
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
inline void PMAInplaceBlend(TUint32& aDest_io, TUint32& aSrc_in)
|
sl@0
|
71 |
{
|
sl@0
|
72 |
TUint8 mask = (TUint8)(aSrc_in >> 24);
|
sl@0
|
73 |
if(mask)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
if(mask == 0xff) // opaque, so dst = src.
|
sl@0
|
76 |
{
|
sl@0
|
77 |
aDest_io = aSrc_in;
|
sl@0
|
78 |
}
|
sl@0
|
79 |
else
|
sl@0
|
80 |
{
|
sl@0
|
81 |
PMABlend_noChecksInplace(aDest_io, aSrc_in, mask);
|
sl@0
|
82 |
}
|
sl@0
|
83 |
}
|
sl@0
|
84 |
//else src completely transparent, so dst unchanged.
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
inline TUint32 NonPMA2PMAPixel(TUint32 aPixel)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
TUint8 tA = (TUint8)(aPixel >> 24);
|
sl@0
|
90 |
if (tA==0)
|
sl@0
|
91 |
{
|
sl@0
|
92 |
return 0;
|
sl@0
|
93 |
}
|
sl@0
|
94 |
if (tA==0xff)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
return aPixel;
|
sl@0
|
97 |
}
|
sl@0
|
98 |
|
sl@0
|
99 |
// Use a bias value of 128 rather than 255, but also add 1/256 of the numerator
|
sl@0
|
100 |
// before dividing the sum by 256.
|
sl@0
|
101 |
|
sl@0
|
102 |
TUint32 tap1=tA+1;
|
sl@0
|
103 |
TUint32 scaledRB = (aPixel & KRBMask) * tap1;
|
sl@0
|
104 |
TUint32 scaledG = (aPixel & KGMask ) * tap1;
|
sl@0
|
105 |
return (aPixel & 0xff000000) | ((scaledRB>>8) & KRBMask) | ((scaledG>>8)& KGMask);
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
inline TUint32 PMA2NonPMAPixel(TUint32 aPixel, const TUint16* aNormTable)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
TUint8 alpha = (TUint8)(aPixel >> 24);
|
sl@0
|
111 |
if (alpha==0)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
return 0;
|
sl@0
|
114 |
}
|
sl@0
|
115 |
if (alpha==0xff)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
return aPixel;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
TUint16 norm = aNormTable[alpha];
|
sl@0
|
120 |
TUint32 norm_rb = (((aPixel & KRBMask) * norm) >> 8) & KRBMask;
|
sl@0
|
121 |
TUint32 norm_g = (((aPixel & KGMask ) * norm) >> 8) & KGMask;
|
sl@0
|
122 |
return ((aPixel & 0xff000000) | norm_rb | norm_g);
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
inline void Convert2PMA(TUint32& aInOutValue)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
aInOutValue = NonPMA2PMAPixel(aInOutValue);
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
inline void Convert2NonPMA(TUint32& aInOutValue, const TUint16* aNormTable)
|
sl@0
|
131 |
{
|
sl@0
|
132 |
aInOutValue = PMA2NonPMAPixel(aInOutValue, aNormTable);
|
sl@0
|
133 |
} |