sl@0: // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef __BLENDINGALGORITHMS_H__ sl@0: #define __BLENDINGALGORITHMS_H__ sl@0: sl@0: #include sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: /** Premultiplied Alpha (PMA) Blending algorithm. sl@0: Assumes src and target pixels are in PMA format (i.e., the color channels are already multiplied sl@0: with the alpha channel. sl@0: Blending Equations: sl@0: Cd' = Cs + ((255 - As) * Cd)/255 sl@0: Ad' = As + ((255 - As) * Ad)/255 sl@0: where Cd' and Ad' are destination values for color and alpha channels respectively, after blending, sl@0: Cd and Ad are destination values before blending, and Cs and As are source values (color and sl@0: alpha values respectively). sl@0: Optimisations: sl@0: Use of 256 instead of 255 converts the division to shift (faster). sl@0: Red and Blue channels are calculated together in one 32 bit operation. sl@0: Alpha and Green channels are calculated in the same way. However, due the sl@0: position of these channels within the pixel format, an extra shift is required. sl@0: The equations used are: sl@0: Cd' = Cs + (((0x100 - As) * Cd)>>8) sl@0: Ad' = As + (((0x100 - As) * Ad)>>8) sl@0: For the results to not overflow, it is required that the value of any of the color channels sl@0: is no greater than the alpha channel, which is what is exepected of pma format. sl@0: It is also assumed that the aMask is equal to source alpha. sl@0: @param aDestPixel The destination pixel value. sl@0: @param aSrcPixel The source pixel value. sl@0: @param aMask The source alpha. It is assumed to be same as source alpha. sl@0: @return the alpha-blended pixel (within the PMA space). sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMask); sl@0: sl@0: /** Same as inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMask) sl@0: Calls inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMask), with aMask sl@0: extracted from the source pixel. sl@0: @see PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMask) sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel); sl@0: sl@0: /** sl@0: Does the premultiplied alpha blend, but does not check for any pre/post conditions. sl@0: Please DO NOT Add any optimisations to check for these conditions in this code! sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: inline TUint32 PMABlend_noChecks(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMaskingFactor); sl@0: sl@0: /** sl@0: The version of PMABlend_noChecks which does the blending in place. sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: inline void PMABlend_noChecksInplace(TUint32& aDest_io, const TUint32& aSrcPixel, TUint8 aMaskingFactor); sl@0: sl@0: /** sl@0: The in-place version of the PMAPixelBlend algorithm sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: inline void PMAInplaceBlend(TUint32& aDest_io, TUint32& aSrc_in); sl@0: /** sl@0: Premultiplies the color channel values with the Alpha channel value. sl@0: Alpha value remains unchanged. An approximation is used in the operation where the division sl@0: by 255 is approximated by a shift-by-8-bits operation (i.e. division by 256). sl@0: @param aPixel The 32 bit pixel value to be pre-multiplied. sl@0: @return The PMA value. sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: inline TUint32 NonPMA2PMAPixel(TUint32 aPixel); sl@0: sl@0: /** sl@0: Divives the PMA pixel color channels with the Alpha value, to convert them to non-PMA format. sl@0: Alpha value remains unchanged. sl@0: @param aPixel the premultiplied 32 bit pixel value. sl@0: @param aNormTable The lookup table used to do the normalisation (the table converts the division sl@0: to multiplication operation). sl@0: The table is usually obtainable by a call to the method: sl@0: PtrTo16BitNormalisationTable, which is defined in lookuptable.dll(.lib). sl@0: The lookup table for normalised alpha is compluted using this equation: sl@0: Table[index] = (255*256) / index (where index is an 8 bit value). sl@0: @return The NON-PMA 32 bit pixel value. sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: inline TUint32 PMA2NonPMAPixel(TUint32 aPixel, const TUint16* aNormTable); sl@0: sl@0: /** sl@0: In-place version of NonPMA2PMAPixel. sl@0: @see NonPMA2PMAPixel sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: inline void Convert2PMA(TUint32& aInOutValue); sl@0: sl@0: /** sl@0: In-place version of PMA2NonPMAPixel sl@0: @see PMA2NonPMAPixel sl@0: @internalTechnology sl@0: @released sl@0: */ sl@0: inline void Convert2NonPMA(TUint32& aInOutValue, const TUint16* aNormTable); sl@0: sl@0: #include sl@0: sl@0: #endif //__BLENDINGALGORITHMS_H__