sl@0: // Copyright (c) 2007-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: const TUint32 KRBMask = 0x00ff00ff; sl@0: const TUint32 KAGMask = 0xff00ff00; sl@0: const TUint32 KGMask = 0x0000ff00; sl@0: sl@0: //Algoriths for Premultiplied alpha screenmode/pixel format. sl@0: sl@0: inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMask) sl@0: { sl@0: if(aMask) sl@0: { sl@0: if(aMask == 0xff) // opaque, so unchanged sl@0: { sl@0: return aSrcPixel; sl@0: } sl@0: else sl@0: { sl@0: return PMABlend_noChecks(aDestPixel, aSrcPixel, aMask); sl@0: } sl@0: } sl@0: else // completely transparent sl@0: { sl@0: return aDestPixel; sl@0: } sl@0: } sl@0: sl@0: inline TUint32 PMAPixelBlend(TUint32 aDestPixel, TUint32 aSrcPixel) sl@0: { sl@0: TUint8 mask = (TUint8)(aSrcPixel >> 24); sl@0: return PMAPixelBlend(aDestPixel, aSrcPixel, mask); sl@0: } sl@0: sl@0: inline TUint32 PMABlend_noChecks(TUint32 aDestPixel, TUint32 aSrcPixel, TUint8 aMaskingFactor) sl@0: { sl@0: TUint32 src_c = aSrcPixel & KRBMask; sl@0: TUint32 dst_c = aDestPixel & KRBMask; sl@0: const TUint32 mask = 0x0100 - aMaskingFactor; sl@0: dst_c = (src_c + ((mask * dst_c)>>8)) & KRBMask; sl@0: src_c = (aSrcPixel & KAGMask)>>8; sl@0: TUint32 dst_ag = (aDestPixel & KAGMask)>>8; sl@0: dst_c |= ((src_c + ((mask * dst_ag)>>8)) & KRBMask)<<8; sl@0: return dst_c; sl@0: } sl@0: sl@0: inline void PMABlend_noChecksInplace(TUint32& aDest_io, const TUint32& aSrcPixel, TUint8 aMaskingFactor) sl@0: { sl@0: TUint32 src_c = aSrcPixel & KRBMask; sl@0: TUint32 dst_ag = (aDest_io & KAGMask) >> 8; sl@0: aDest_io = aDest_io & KRBMask; sl@0: const TUint32 mask = 0x0100 - aMaskingFactor; sl@0: aDest_io = (src_c + ((mask * aDest_io) >> 8)) & KRBMask; sl@0: src_c = (aSrcPixel & KAGMask) >> 8; sl@0: aDest_io |= ((src_c + ((mask * dst_ag) >> 8)) & KRBMask)<<8; sl@0: } sl@0: sl@0: inline void PMAInplaceBlend(TUint32& aDest_io, TUint32& aSrc_in) sl@0: { sl@0: TUint8 mask = (TUint8)(aSrc_in >> 24); sl@0: if(mask) sl@0: { sl@0: if(mask == 0xff) // opaque, so dst = src. sl@0: { sl@0: aDest_io = aSrc_in; sl@0: } sl@0: else sl@0: { sl@0: PMABlend_noChecksInplace(aDest_io, aSrc_in, mask); sl@0: } sl@0: } sl@0: //else src completely transparent, so dst unchanged. sl@0: } sl@0: sl@0: inline TUint32 NonPMA2PMAPixel(TUint32 aPixel) sl@0: { sl@0: TUint8 tA = (TUint8)(aPixel >> 24); sl@0: if (tA==0) sl@0: { sl@0: return 0; sl@0: } sl@0: if (tA==0xff) sl@0: { sl@0: return aPixel; sl@0: } sl@0: sl@0: // Use a bias value of 128 rather than 255, but also add 1/256 of the numerator sl@0: // before dividing the sum by 256. sl@0: sl@0: TUint32 tap1=tA+1; sl@0: TUint32 scaledRB = (aPixel & KRBMask) * tap1; sl@0: TUint32 scaledG = (aPixel & KGMask ) * tap1; sl@0: return (aPixel & 0xff000000) | ((scaledRB>>8) & KRBMask) | ((scaledG>>8)& KGMask); sl@0: } sl@0: sl@0: inline TUint32 PMA2NonPMAPixel(TUint32 aPixel, const TUint16* aNormTable) sl@0: { sl@0: TUint8 alpha = (TUint8)(aPixel >> 24); sl@0: if (alpha==0) sl@0: { sl@0: return 0; sl@0: } sl@0: if (alpha==0xff) sl@0: { sl@0: return aPixel; sl@0: } sl@0: TUint16 norm = aNormTable[alpha]; sl@0: TUint32 norm_rb = (((aPixel & KRBMask) * norm) >> 8) & KRBMask; sl@0: TUint32 norm_g = (((aPixel & KGMask ) * norm) >> 8) & KGMask; sl@0: return ((aPixel & 0xff000000) | norm_rb | norm_g); sl@0: } sl@0: sl@0: inline void Convert2PMA(TUint32& aInOutValue) sl@0: { sl@0: aInOutValue = NonPMA2PMAPixel(aInOutValue); sl@0: } sl@0: sl@0: inline void Convert2NonPMA(TUint32& aInOutValue, const TUint16* aNormTable) sl@0: { sl@0: aInOutValue = PMA2NonPMAPixel(aInOutValue, aNormTable); sl@0: }