graphicsdeviceinterface/screendriver/sbit/BMDRAW32PMA.cpp
branchRCL_3
changeset 33 25f95128741d
parent 0 5d03bc08d59c
equal deleted inserted replaced
26:15986eb6c500 33:25f95128741d
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
   694 	
   694 	
   695 TInt CDrawThirtyTwoBppBitmapAlphaPM::WriteRgbOutlineAndShadow(TInt aX, TInt aY, const TInt aLength,
   695 TInt CDrawThirtyTwoBppBitmapAlphaPM::WriteRgbOutlineAndShadow(TInt aX, TInt aY, const TInt aLength,
   696 															TUint32 aOutlinePenColor, TUint32 aShadowColor,
   696 															TUint32 aOutlinePenColor, TUint32 aShadowColor,
   697 															TUint32 aFillColor, const TUint8* aDataBuffer)
   697 															TUint32 aFillColor, const TUint8* aDataBuffer)
   698 	{
   698 	{
   699 	const TUint alphaShifted = aOutlinePenColor & 0xff000000;
       
   700 	const TUint alpha = alphaShifted>>24;
       
   701 	if (alpha==0 || aLength<=0)
       
   702 		return KErrNone;
       
   703 	DeOrientate(aX,aY);
   699 	DeOrientate(aX,aY);
   704 	TUint32* pixelPtr = PixelAddress(aX,aY);
   700 	TUint32* pixelPtr = PixelAddress(aX,aY);
   705 	const TInt pixelPtrInc = PixelAddressIncrement();
   701 	const TInt pixelPtrInc = PixelAddressIncrement();
   706 	const TUint8* dataBufferPtrLimit = aDataBuffer + aLength;
   702 	const TUint8* dataBufferPtrLimit = aDataBuffer + aLength;
   707 	TInt blendedRedColor;
   703 	TInt blendedRedColor;
   708 	TInt blendedGreenColor;
   704 	TInt blendedGreenColor;
   709 	TInt blendedBlueColor;
   705 	TInt blendedBlueColor;
       
   706 	TInt blendedAlpha;
   710 	TUint8 index = 0;
   707 	TUint8 index = 0;
   711 	TUint32 finalColor;
   708 	TUint32 finalColor;
   712 
   709 
   713 	//Get red color. Equivalent to TRgb::Red()
   710 	//Get red color. Equivalent to TRgb::Red()
   714 	const TInt redOutlinePenColor = (aOutlinePenColor & 0xff0000) >> 16;
   711 	const TInt redOutlinePenColor = (aOutlinePenColor & 0xff0000) >> 16;
   722 
   719 
   723 	//Get blue color. Equivalent to TRgb::Blue()
   720 	//Get blue color. Equivalent to TRgb::Blue()
   724 	const TInt blueOutlinePenColor = aOutlinePenColor & 0xff;
   721 	const TInt blueOutlinePenColor = aOutlinePenColor & 0xff;
   725 	const TInt blueShadowColor = aShadowColor & 0xff;
   722 	const TInt blueShadowColor = aShadowColor & 0xff;
   726 	const TInt blueFillColor = aFillColor & 0xff;
   723 	const TInt blueFillColor = aFillColor & 0xff;
   727 	const TUint16* normTable = PtrTo16BitNormalisationTable();
   724 
       
   725 	//Get alpha color. Equivalent to TRgb::Alpha()
       
   726 	const TInt alphaOutlinePenColor = aOutlinePenColor >> 24;
       
   727 	const TInt alphaShadowColor = aShadowColor >> 24;
       
   728 	const TInt alphaFillColor = aFillColor >> 24;
   728 
   729 
   729 	// Calculate PMA values for aFillColor & aOutlinePenColor that we can use for fast blending in the simple cases
   730 	// Calculate PMA values for aFillColor & aOutlinePenColor that we can use for fast blending in the simple cases
   730 	// Don't pre calculate PMA version of aShadowColor as it is presumed not to be used enough to make this worthwhile
   731 	// Don't pre calculate PMA version of aShadowColor as it is presumed not to be used enough to make this worthwhile
   731 	const TUint32 pmaFillColor = NonPMA2PMAPixel((aFillColor&0x00FFFFFF)|alphaShifted);
   732 	const TUint32 pmaFillColor = NonPMA2PMAPixel(aFillColor);
   732 	const TUint32 pmaOutlineColor = NonPMA2PMAPixel(aOutlinePenColor);
   733 	const TUint32 pmaOutlineColor = NonPMA2PMAPixel(aOutlinePenColor);
       
   734 
   733 	while (aDataBuffer < dataBufferPtrLimit)
   735 	while (aDataBuffer < dataBufferPtrLimit)
   734 		{
   736 		{
   735 		TUint backgroundAlpha;
       
   736 		TUint outlineAlpha;
       
   737 		TUint shadowAlpha;
       
   738 		TUint fillAlpha;
       
   739 		index = *aDataBuffer++;
   737 		index = *aDataBuffer++;
   740 		backgroundAlpha = FourColorBlendLookup[index][KBackgroundColorIndex];
   738 		if (255 == FourColorBlendLookup[index][KBackgroundColorIndex])
   741 		if (backgroundAlpha == 255)
       
   742 			{
   739 			{
   743 			//background colour
   740 			//background colour
   744 			//No drawing required so move on to next pixel.
   741 			//No drawing required
   745 			pixelPtr += pixelPtrInc;
   742 			}
   746 			continue;
   743 		else if (255 == FourColorBlendLookup[index][KFillColorIndex])
   747 			}
       
   748 		fillAlpha=FourColorBlendLookup[index][KFillColorIndex];
       
   749 		if (fillAlpha == 255)
       
   750 			{
   744 			{
   751 			//Use fill colour to draw
   745 			//Use fill colour to draw
   752 			finalColor = pmaFillColor;
   746 			finalColor = pmaFillColor;
   753 oneColorBlend:
   747 			PMAInplaceBlend(*pixelPtr, finalColor);
   754 			if (alpha==0xFF)
   748 			}
   755 				*pixelPtr=finalColor;
   749 		else if (255 == FourColorBlendLookup[index][KOutlineColorIndex])
   756 			else
       
   757 				PMABlend_noChecksInplace(*pixelPtr, finalColor, alpha);
       
   758 			pixelPtr += pixelPtrInc;
       
   759 			continue;
       
   760 			}
       
   761 		outlineAlpha = FourColorBlendLookup[index][KOutlineColorIndex];
       
   762 		if (outlineAlpha == 255)
       
   763 			{
   750 			{
   764 			//Use outline colour to draw
   751 			//Use outline colour to draw
   765 			finalColor = pmaOutlineColor;
   752 			finalColor = pmaOutlineColor;
   766 			goto oneColorBlend;
   753 			PMAInplaceBlend(*pixelPtr, finalColor);
   767 			}
   754 			}
   768 		shadowAlpha = FourColorBlendLookup[index][KShadowColorIndex];
   755 		else if (255 == FourColorBlendLookup[index][KShadowColorIndex])
   769 		if (shadowAlpha == 255)
       
   770 			{
   756 			{
   771 			//Use shadow colour to draw
   757 			//Use shadow colour to draw
   772 			finalColor = NonPMA2PMAPixel((aShadowColor&0x00FFFFFF)|alphaShifted);
   758 			finalColor = NonPMA2PMAPixel(aShadowColor);
   773 			goto oneColorBlend;
   759 			PMAInplaceBlend(*pixelPtr, finalColor);
   774 			}
   760 			}
   775 		blendedRedColor = redOutlinePenColor * outlineAlpha + 
       
   776 					   		redShadowColor * shadowAlpha +
       
   777 					  		redFillColor * fillAlpha;
       
   778 
       
   779 		blendedGreenColor = greenOutlinePenColor * outlineAlpha + 
       
   780 							greenShadowColor * shadowAlpha +
       
   781 							greenFillColor * fillAlpha;
       
   782 
       
   783 		blendedBlueColor = blueOutlinePenColor * outlineAlpha + 
       
   784 							blueShadowColor * shadowAlpha +
       
   785 							blueFillColor * fillAlpha;
       
   786 		if (backgroundAlpha)
       
   787 			{
       
   788 			const TUint32 backgroundColor = PMA2NonPMAPixel(*pixelPtr, normTable);
       
   789 			blendedRedColor += ((backgroundColor & 0xff0000) >> 16) * backgroundAlpha;
       
   790 			blendedGreenColor += ((backgroundColor & 0xff00) >> 8) * backgroundAlpha;
       
   791 			blendedBlueColor += (backgroundColor & 0xff) * backgroundAlpha;
       
   792 			}
       
   793 		finalColor = ((blendedRedColor&0xFF00)<<8) | (blendedGreenColor&0xFF00) | (blendedBlueColor>>8);
       
   794 
       
   795 		if (alpha==0xFF)
       
   796 			*pixelPtr=finalColor|0xFF000000;
       
   797 		else
   761 		else
   798 			{
   762 			{
   799 			//pre-multiply, inplace.
   763 			blendedRedColor = (redOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] * alphaOutlinePenColor + 
   800 			finalColor = NonPMA2PMAPixel(finalColor|alphaShifted);
   764 								redShadowColor * FourColorBlendLookup[index][KShadowColorIndex] * alphaShadowColor +
   801 			PMABlend_noChecksInplace(*pixelPtr, finalColor, alpha);
   765 								redFillColor * FourColorBlendLookup[index][KFillColorIndex] * alphaFillColor) >> 16;
       
   766 	
       
   767 			blendedGreenColor = (greenOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] * alphaOutlinePenColor  + 
       
   768 								greenShadowColor * FourColorBlendLookup[index][KShadowColorIndex] * alphaShadowColor +
       
   769 								greenFillColor * FourColorBlendLookup[index][KFillColorIndex] * alphaFillColor) >> 16;
       
   770 	
       
   771 			blendedBlueColor = (blueOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] * alphaOutlinePenColor  + 
       
   772 								blueShadowColor * FourColorBlendLookup[index][KShadowColorIndex] * alphaShadowColor +
       
   773 								blueFillColor * FourColorBlendLookup[index][KFillColorIndex] * alphaFillColor) >> 16;
       
   774 	
       
   775 			blendedAlpha = (alphaOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] + 
       
   776 							alphaShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
       
   777 							alphaFillColor * FourColorBlendLookup[index][KFillColorIndex]) >> 8;
       
   778 
       
   779 			finalColor = (blendedAlpha << 24) | (blendedRedColor << 16) | (blendedGreenColor  << 8 )| (blendedBlueColor);
       
   780 			PMAInplaceBlend(*pixelPtr, finalColor);
   802 			}
   781 			}
   803 		pixelPtr += pixelPtrInc;
   782 		pixelPtr += pixelPtrInc;
   804 		}
   783 		}
   805 	return KErrNone;
   784 	return KErrNone;
   806 	}
   785 	}