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