graphicsdeviceinterface/screendriver/sbit/BMDRAW24U.CPP
branchRCL_3
changeset 33 25f95128741d
parent 0 5d03bc08d59c
equal deleted inserted replaced
26:15986eb6c500 33:25f95128741d
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2003-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".
    14 //
    14 //
    15 
    15 
    16 #include "BMDRAW.H"
    16 #include "BMDRAW.H"
    17 #include "BitDrawInterfaceId.h"
    17 #include "BitDrawInterfaceId.h"
    18 #include <graphics/lookuptable.h>
    18 #include <graphics/lookuptable.h>
       
    19 #include <graphics/blendingalgorithms.h>
    19 
    20 
    20 TInt CDrawUTwentyFourBppBitmap::Construct(TSize aSize)
    21 TInt CDrawUTwentyFourBppBitmap::Construct(TSize aSize)
    21 	{
    22 	{
    22 	return Construct(aSize, aSize.iWidth << 2);
    23 	return Construct(aSize, aSize.iWidth << 2);
    23 	}
    24 	}
  1182 
  1183 
  1183 TInt CDrawUTwentyFourBppBitmap::WriteRgbOutlineAndShadow(TInt aX, TInt aY, const TInt aLength,
  1184 TInt CDrawUTwentyFourBppBitmap::WriteRgbOutlineAndShadow(TInt aX, TInt aY, const TInt aLength,
  1184 														TUint32 aOutlinePenColor, TUint32 aShadowColor,
  1185 														TUint32 aOutlinePenColor, TUint32 aShadowColor,
  1185 														TUint32 aFillColor, const TUint8* aDataBuffer)
  1186 														TUint32 aFillColor, const TUint8* aDataBuffer)
  1186 	{
  1187 	{
  1187 	const TInt alpha = aOutlinePenColor >> 24;
       
  1188 	if (alpha==0 || aLength<=0)
       
  1189 		return KErrNone;
       
  1190 	DeOrientate(aX,aY);
  1188 	DeOrientate(aX,aY);
  1191 	TUint32* pixelPtr = PixelAddress(aX,aY);
  1189 	TUint32* pixelPtr = PixelAddress(aX,aY);
  1192 	const TInt pixelPtrInc = PixelAddressIncrement();
  1190 	const TInt pixelPtrInc = PixelAddressIncrement();
  1193 	const TUint8* dataBufferPtrLimit = aDataBuffer + aLength;
  1191 	const TUint8* dataBufferPtrLimit = aDataBuffer + aLength;
  1194 	TInt blendedRedColor;
  1192 	TInt blendedRedColor;
  1195 	TInt blendedGreenColor;
  1193 	TInt blendedGreenColor;
  1196 	TInt blendedBlueColor;
  1194 	TInt blendedBlueColor;
       
  1195 	TInt blendedAlpha;
  1197 	TUint8 index = 0;
  1196 	TUint8 index = 0;
  1198 	TUint32 finalColor;
  1197 	TUint32 finalColor;
       
  1198 	const TUint16* normTable = PtrTo16BitNormalisationTable();
  1199 
  1199 
  1200 	//Get red color. Equivalent to TRgb::Red()
  1200 	//Get red color. Equivalent to TRgb::Red()
  1201 	const TInt redOutlinePenColor = (aOutlinePenColor & 0xff0000) >> 16;
  1201 	const TInt redOutlinePenColor = (aOutlinePenColor & 0xff0000) >> 16;
  1202 	const TInt redShadowColor = (aShadowColor & 0xff0000) >> 16;
  1202 	const TInt redShadowColor = (aShadowColor & 0xff0000) >> 16;
  1203 	const TInt redFillColor = (aFillColor & 0xff0000) >> 16;
  1203 	const TInt redFillColor = (aFillColor & 0xff0000) >> 16;
  1210 	//Get blue color. Equivalent to TRgb::Blue()
  1210 	//Get blue color. Equivalent to TRgb::Blue()
  1211 	const TInt blueOutlinePenColor = aOutlinePenColor & 0xff;
  1211 	const TInt blueOutlinePenColor = aOutlinePenColor & 0xff;
  1212 	const TInt blueShadowColor = aShadowColor & 0xff;
  1212 	const TInt blueShadowColor = aShadowColor & 0xff;
  1213 	const TInt blueFillColor = aFillColor & 0xff;
  1213 	const TInt blueFillColor = aFillColor & 0xff;
  1214 
  1214 
  1215 	const TUint32 mask2 = alpha | (alpha << 16);
  1215 	//Get alpha color. Equivalent to TRgb::Alpha()
       
  1216 	const TInt alphaOutlinePenColor = aOutlinePenColor >> 24;
       
  1217 	const TInt alphaShadowColor = aShadowColor >> 24;
       
  1218 	const TInt alphaFillColor = aFillColor >> 24;
       
  1219 
  1216 	while (aDataBuffer < dataBufferPtrLimit)
  1220 	while (aDataBuffer < dataBufferPtrLimit)
  1217 		{
  1221 		{
  1218 		index = *aDataBuffer++;
  1222 		index = *aDataBuffer++;
  1219 		
       
  1220 		if (255 == FourColorBlendLookup[index][KBackgroundColorIndex])
  1223 		if (255 == FourColorBlendLookup[index][KBackgroundColorIndex])
  1221 			{
  1224 			{
  1222 			//background colour
  1225 			//background colour
  1223 			//No drawing required so move on to next pixel.
  1226 			//No drawing required
  1224 			pixelPtr += pixelPtrInc;
       
  1225 			continue;
       
  1226 			}
  1227 			}
  1227 		else if (255 == FourColorBlendLookup[index][KFillColorIndex])
  1228 		else if (255 == FourColorBlendLookup[index][KFillColorIndex])
  1228 			{
  1229 			{
  1229 			//Use fill colour to draw
  1230 			//Use fill colour to draw
  1230 			finalColor = aFillColor;
  1231 			finalColor = aFillColor;
       
  1232 			AlphaBlendPixelToDest((finalColor | 0xff000000), alphaFillColor, pixelPtr);
  1231 			}
  1233 			}
  1232 		else if (255 == FourColorBlendLookup[index][KShadowColorIndex])
  1234 		else if (255 == FourColorBlendLookup[index][KShadowColorIndex])
  1233 			{
  1235 			{
  1234 			//Use shadow colour to draw
  1236 			//Use shadow colour to draw
  1235 			finalColor = aShadowColor;
  1237 			finalColor = aShadowColor;
       
  1238 			AlphaBlendPixelToDest((finalColor | 0xff000000), alphaShadowColor, pixelPtr);
  1236 			}
  1239 			}
  1237 		else if (255 == FourColorBlendLookup[index][KOutlineColorIndex])
  1240 		else if (255 == FourColorBlendLookup[index][KOutlineColorIndex])
  1238 			{
  1241 			{
  1239 			//Use outline colour to draw
  1242 			//Use outline colour to draw
  1240 			finalColor = aOutlinePenColor;
  1243 			finalColor = aOutlinePenColor;
       
  1244 			AlphaBlendPixelToDest((finalColor | 0xff000000), alphaOutlinePenColor, pixelPtr);
  1241 			}
  1245 			}
  1242 		else
  1246 		else
  1243 			{
  1247 			{
  1244 			TUint32 backgroundColor = *pixelPtr;
  1248 			blendedRedColor = (redOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] * alphaOutlinePenColor + 
  1245 			blendedRedColor =   redOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] + 
  1249 						   		redShadowColor * FourColorBlendLookup[index][KShadowColorIndex] * alphaShadowColor +
  1246 						   		redShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
  1250 						  		redFillColor * FourColorBlendLookup[index][KFillColorIndex] * alphaFillColor) >> 16;
  1247 						  		redFillColor * FourColorBlendLookup[index][KFillColorIndex] + 
  1251 
  1248 						  		((backgroundColor & 0xff0000) >> 16) * FourColorBlendLookup[index][KBackgroundColorIndex];
  1252 			blendedGreenColor = (greenOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] * alphaOutlinePenColor  + 
  1249 
  1253 								greenShadowColor * FourColorBlendLookup[index][KShadowColorIndex] * alphaShadowColor +
  1250 			blendedGreenColor = greenOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] + 
  1254 								greenFillColor * FourColorBlendLookup[index][KFillColorIndex] * alphaFillColor) >> 16;
  1251 								greenShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
  1255 
  1252 								greenFillColor * FourColorBlendLookup[index][KFillColorIndex] + 
  1256 			blendedBlueColor = (blueOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] * alphaOutlinePenColor  + 
  1253 								((backgroundColor & 0xff00) >> 8) * FourColorBlendLookup[index][KBackgroundColorIndex];
  1257 								blueShadowColor * FourColorBlendLookup[index][KShadowColorIndex] * alphaShadowColor +
  1254 
  1258 								blueFillColor * FourColorBlendLookup[index][KFillColorIndex] * alphaFillColor) >> 16;
  1255 			blendedBlueColor =  blueOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] + 
  1259 
  1256 								blueShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
  1260 			blendedAlpha = (alphaOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] + 
  1257 								blueFillColor * FourColorBlendLookup[index][KFillColorIndex] + 
  1261 							alphaShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
  1258 								(backgroundColor & 0xff) * FourColorBlendLookup[index][KBackgroundColorIndex];
  1262 							alphaFillColor * FourColorBlendLookup[index][KFillColorIndex]) >> 8;
  1259 
  1263 
  1260 			//Equivalent to TRgb::TRgb(TUint32)
  1264 			finalColor = PMA2NonPMAPixel((blendedAlpha << 24) | (blendedRedColor << 16) | (blendedGreenColor << 8) | blendedBlueColor, normTable);		
  1261 			finalColor = ((blendedRedColor&0xFF00) << 8) | (blendedGreenColor&0xFF00) | (blendedBlueColor>>8);
  1265 			AlphaBlendPixelToDest(finalColor | 0xff000000, blendedAlpha, pixelPtr);
  1262 			}
  1266 			}
  1263 
       
  1264 		if (alpha != 0xff)
       
  1265 			{
       
  1266 			TUint32 backgroundColor = *pixelPtr;
       
  1267 			//Draw the final colour
       
  1268 //
       
  1269 			const TUint32 s_rb = finalColor & 0x00FF00FF;
       
  1270 			const TUint32 s_g = (finalColor & 0xFF00) >> 8;
       
  1271 			const TUint32 d_rb = backgroundColor & 0x00FF00FF;
       
  1272 			const TUint32 rb = ((((alpha * ((0x01000100 + s_rb) - d_rb)) >> 8) + d_rb) - mask2) & 0x00FF00FF;
       
  1273 
       
  1274 			const TInt d_g = (backgroundColor & 0xFF00) >> 8;
       
  1275 			const TInt g = ((alpha * (s_g - d_g)) >> 8) + d_g;
       
  1276 	
       
  1277 			finalColor = rb | (g<<8);
       
  1278 			}
       
  1279 
       
  1280 		*pixelPtr = (finalColor | 0xff000000);
       
  1281 		pixelPtr += pixelPtrInc;
  1267 		pixelPtr += pixelPtrInc;
  1282 		}
  1268 		}
  1283 	return KErrNone;
  1269 	return KErrNone;
  1284 	}
  1270 	}