os/graphics/graphicsdeviceinterface/gdi/inc/blendingalgorithms.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef __BLENDINGALGORITHMS_H__
    17 #define __BLENDINGALGORITHMS_H__
    18 
    19 #include <e32def.h>
    20 /**
    21 @file
    22 @internalTechnology
    23 */
    24 
    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.
    28 Blending Equations:
    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).
    34 Optimisations:
    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).
    49 @internalTechnology
    50 @released
    51 */
    52 inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMask);
    53 
    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)
    58 @internalTechnology
    59 @released
    60 */
    61 inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel);
    62 
    63 /**
    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!
    66 @internalTechnology
    67 @released
    68 */
    69 inline TUint32 PMABlend_noChecks(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMaskingFactor);
    70 
    71 /**
    72 The version of PMABlend_noChecks which does the blending in place.
    73 @internalTechnology
    74 @released
    75 */
    76 inline void PMABlend_noChecksInplace(TUint32& aDest_io, const TUint32& aSrcPixel, TUint8 aMaskingFactor);
    77 
    78 /**
    79 The in-place version of the PMAPixelBlend algorithm
    80 @internalTechnology
    81 @released
    82 */
    83 inline void PMAInplaceBlend(TUint32& aDest_io, TUint32& aSrc_in);
    84 /**
    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.
    90 @internalTechnology
    91 @released
    92 */
    93 inline TUint32 NonPMA2PMAPixel(TUint32 aPixel);
    94 
    95 /**
    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.
   106 @internalTechnology
   107 @released
   108 */
   109 inline TUint32 PMA2NonPMAPixel(TUint32 aPixel, const TUint16* aNormTable);
   110 
   111 /**
   112 In-place version of NonPMA2PMAPixel.
   113 @see NonPMA2PMAPixel
   114 @internalTechnology
   115 @released
   116 */
   117 inline void Convert2PMA(TUint32& aInOutValue);
   118 
   119 /**
   120 In-place version of PMA2NonPMAPixel
   121 @see PMA2NonPMAPixel
   122 @internalTechnology
   123 @released
   124 */
   125 inline void Convert2NonPMA(TUint32& aInOutValue, const TUint16* aNormTable);
   126 
   127 #include <graphics/blendingalgorithms.inl>
   128 
   129 #endif //__BLENDINGALGORITHMS_H__