williamr@2
|
1 |
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@2
|
2 |
// All rights reserved.
|
williamr@2
|
3 |
// This component and the accompanying materials are made available
|
williamr@2
|
4 |
// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
|
williamr@2
|
5 |
// which accompanies this distribution, and is available
|
williamr@2
|
6 |
// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
|
williamr@2
|
7 |
//
|
williamr@2
|
8 |
// Initial Contributors:
|
williamr@2
|
9 |
// Nokia Corporation - initial contribution.
|
williamr@2
|
10 |
//
|
williamr@2
|
11 |
// Contributors:
|
williamr@2
|
12 |
//
|
williamr@2
|
13 |
// Description:
|
williamr@2
|
14 |
//
|
williamr@2
|
15 |
|
williamr@2
|
16 |
#ifndef __BLENDINGALGORITHMS_H__
|
williamr@2
|
17 |
#define __BLENDINGALGORITHMS_H__
|
williamr@2
|
18 |
|
williamr@2
|
19 |
#include <e32def.h>
|
williamr@2
|
20 |
/**
|
williamr@2
|
21 |
@file
|
williamr@2
|
22 |
@internalTechnology
|
williamr@2
|
23 |
*/
|
williamr@2
|
24 |
|
williamr@2
|
25 |
/** Premultiplied Alpha (PMA) Blending algorithm.
|
williamr@2
|
26 |
Assumes src and target pixels are in PMA format (i.e., the color channels are already multiplied
|
williamr@2
|
27 |
with the alpha channel.
|
williamr@2
|
28 |
Blending Equations:
|
williamr@2
|
29 |
Cd' = Cs + ((255 - As) * Cd)/255
|
williamr@2
|
30 |
Ad' = As + ((255 - As) * Ad)/255
|
williamr@2
|
31 |
where Cd' and Ad' are destination values for color and alpha channels respectively, after blending,
|
williamr@2
|
32 |
Cd and Ad are destination values before blending, and Cs and As are source values (color and
|
williamr@2
|
33 |
alpha values respectively).
|
williamr@2
|
34 |
Optimisations:
|
williamr@2
|
35 |
Use of 256 instead of 255 converts the division to shift (faster).
|
williamr@2
|
36 |
Red and Blue channels are calculated together in one 32 bit operation.
|
williamr@2
|
37 |
Alpha and Green channels are calculated in the same way. However, due the
|
williamr@2
|
38 |
position of these channels within the pixel format, an extra shift is required.
|
williamr@2
|
39 |
The equations used are:
|
williamr@2
|
40 |
Cd' = Cs + (((0x100 - As) * Cd)>>8)
|
williamr@2
|
41 |
Ad' = As + (((0x100 - As) * Ad)>>8)
|
williamr@2
|
42 |
For the results to not overflow, it is required that the value of any of the color channels
|
williamr@2
|
43 |
is no greater than the alpha channel, which is what is exepected of pma format.
|
williamr@2
|
44 |
It is also assumed that the aMask is equal to source alpha.
|
williamr@2
|
45 |
@param aDestPixel The destination pixel value.
|
williamr@2
|
46 |
@param aSrcPixel The source pixel value.
|
williamr@2
|
47 |
@param aMask The source alpha. It is assumed to be same as source alpha.
|
williamr@2
|
48 |
@return the alpha-blended pixel (within the PMA space).
|
williamr@2
|
49 |
@internalTechnology
|
williamr@2
|
50 |
@released
|
williamr@2
|
51 |
*/
|
williamr@2
|
52 |
inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMask);
|
williamr@2
|
53 |
|
williamr@2
|
54 |
/** Same as inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMask)
|
williamr@2
|
55 |
Calls inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMask), with aMask
|
williamr@2
|
56 |
extracted from the source pixel.
|
williamr@2
|
57 |
@see PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMask)
|
williamr@2
|
58 |
@internalTechnology
|
williamr@2
|
59 |
@released
|
williamr@2
|
60 |
*/
|
williamr@2
|
61 |
inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel);
|
williamr@2
|
62 |
|
williamr@2
|
63 |
/**
|
williamr@2
|
64 |
Does the premultiplied alpha blend, but does not check for any pre/post conditions.
|
williamr@2
|
65 |
Please DO NOT Add any optimisations to check for these conditions in this code!
|
williamr@2
|
66 |
@internalTechnology
|
williamr@2
|
67 |
@released
|
williamr@2
|
68 |
*/
|
williamr@2
|
69 |
inline TUint32 PMABlend_noChecks(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMaskingFactor);
|
williamr@2
|
70 |
|
williamr@2
|
71 |
/**
|
williamr@2
|
72 |
The version of PMABlend_noChecks which does the blending in place.
|
williamr@2
|
73 |
@internalTechnology
|
williamr@2
|
74 |
@released
|
williamr@2
|
75 |
*/
|
williamr@2
|
76 |
inline void PMABlend_noChecksInplace(TUint32& aDest_io, TUint32& aSrcPixel,TUint8& aMaskingFactor);
|
williamr@2
|
77 |
|
williamr@2
|
78 |
/**
|
williamr@2
|
79 |
The in-place version of the PMAPixelBlend algorithm
|
williamr@2
|
80 |
@internalTechnology
|
williamr@2
|
81 |
@released
|
williamr@2
|
82 |
*/
|
williamr@2
|
83 |
inline void PMAInplaceBlend(TUint32& aDest_io, TUint32& aSrc_in);
|
williamr@2
|
84 |
/**
|
williamr@2
|
85 |
Premultiplies the color channel values with the Alpha channel value.
|
williamr@2
|
86 |
Alpha value remains unchanged. An approximation is used in the operation where the division
|
williamr@2
|
87 |
by 255 is approximated by a shift-by-8-bits operation (i.e. division by 256).
|
williamr@2
|
88 |
@param aPixel The 32 bit pixel value to be pre-multiplied.
|
williamr@2
|
89 |
@return The PMA value.
|
williamr@2
|
90 |
@internalTechnology
|
williamr@2
|
91 |
@released
|
williamr@2
|
92 |
*/
|
williamr@2
|
93 |
inline TUint32 NonPMA2PMAPixel(TUint32 aPixel);
|
williamr@2
|
94 |
|
williamr@2
|
95 |
/**
|
williamr@2
|
96 |
Divives the PMA pixel color channels with the Alpha value, to convert them to non-PMA format.
|
williamr@2
|
97 |
Alpha value remains unchanged.
|
williamr@2
|
98 |
@param aPixel the premultiplied 32 bit pixel value.
|
williamr@2
|
99 |
@param aNormTable The lookup table used to do the normalisation (the table converts the division
|
williamr@2
|
100 |
to multiplication operation).
|
williamr@2
|
101 |
The table is usually obtainable by a call to the method:
|
williamr@2
|
102 |
PtrTo16BitNormalisationTable, which is defined in lookuptable.dll(.lib).
|
williamr@2
|
103 |
The lookup table for normalised alpha is compluted using this equation:
|
williamr@2
|
104 |
Table[index] = (255*256) / index (where index is an 8 bit value).
|
williamr@2
|
105 |
@return The NON-PMA 32 bit pixel value.
|
williamr@2
|
106 |
@internalTechnology
|
williamr@2
|
107 |
@released
|
williamr@2
|
108 |
*/
|
williamr@2
|
109 |
inline TUint32 PMA2NonPMAPixel(TUint32 aPixel, const TUint16* aNormTable);
|
williamr@2
|
110 |
|
williamr@2
|
111 |
/**
|
williamr@2
|
112 |
In-place version of NonPMA2PMAPixel.
|
williamr@2
|
113 |
@see NonPMA2PMAPixel
|
williamr@2
|
114 |
@internalTechnology
|
williamr@2
|
115 |
@released
|
williamr@2
|
116 |
*/
|
williamr@2
|
117 |
inline void Convert2PMA(TUint32& aInOutValue);
|
williamr@2
|
118 |
|
williamr@2
|
119 |
/**
|
williamr@2
|
120 |
In-place version of PMA2NonPMAPixel
|
williamr@2
|
121 |
@see PMA2NonPMAPixel
|
williamr@2
|
122 |
@internalTechnology
|
williamr@2
|
123 |
@released
|
williamr@2
|
124 |
*/
|
williamr@2
|
125 |
inline void Convert2NonPMA(TUint32& aInOutValue, const TUint16* aNormTable);
|
williamr@2
|
126 |
|
williamr@2
|
127 |
|
williamr@2
|
128 |
#include <graphics/blendingalgorithms.inl>
|
williamr@2
|
129 |
|
williamr@2
|
130 |
#endif //__BLENDINGALGORITHMS_H__
|