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