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