os/graphics/graphicsdeviceinterface/screendriver/sbit/BMDRAW16.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsdeviceinterface/screendriver/sbit/BMDRAW16.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1513 @@
     1.4 +// Copyright (c) 1997-20010 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "BMDRAW.H"
    1.20 +#include "BitDrawInterfaceId.h"
    1.21 +#include <graphics/lookuptable.h>
    1.22 +#include <graphics/blendingalgorithms.h>
    1.23 +
    1.24 +#if defined(SYMBIAN_USE_FAST_FADING)
    1.25 +// 16bpp fast fade - half the contrast and brighten
    1.26 +const TInt K16bppFastFadeShift = 1;
    1.27 +const TUint16 K16bppFastFadeMask = 0x8410;
    1.28 +// Use the 32 -> 16 bit colour convesrion method to get
    1.29 +// the 16 bit fading constant (K16bppFastFadeOffset)
    1.30 +// from 32 bit fading constant (SYMBIAN_USE_FAST_FADING).
    1.31 +const TUint16 K16bppFastFadeOffset = ((SYMBIAN_USE_FAST_FADING & 0x0000f8) >> 3) |
    1.32 +									((SYMBIAN_USE_FAST_FADING & 0x00fc00) >> 5) |
    1.33 +									((SYMBIAN_USE_FAST_FADING & 0xf80000) >> 8);
    1.34 +#endif
    1.35 +
    1.36 +// CDrawSixteenBppBitmapCommon
    1.37 +
    1.38 +//Initializes iSize, iDrawRect, iLongWidth, iScanlineWords data members.
    1.39 +//It should be called every time when iSize is going to be changed - from Construct().
    1.40 +//@param aSize Physical screen size in pixels.
    1.41 +//@panic EScreenDriverPanicInvalidSize - Invalid aSize parameter. This might happen if the 
    1.42 +//device is scaled and the scaling origin goes outside physical drawing rectangle.
    1.43 +void CDrawSixteenBppBitmapCommon::SetSize(const TSize& aSize) 
    1.44 +	{
    1.45 +	CDrawBitmap::SetSize(aSize);
    1.46 +	__ASSERT_DEBUG(iSize == aSize, User::Invariant());
    1.47 +	iLongWidth = (iSize.iWidth + 1) & ~1;
    1.48 +	iScanLineWords = iLongWidth >> 1;
    1.49 +	}
    1.50 + 
    1.51 +TInt CDrawSixteenBppBitmapCommon::Construct(TSize aSize, TInt aStride)
    1.52 +	{
    1.53 +	iBits = NULL;
    1.54 +	CDrawBitmap::SetSize(aSize);
    1.55 +	__ASSERT_DEBUG(iSize == aSize, User::Invariant());
    1.56 +	if (aStride & 3)
    1.57 +		return KErrArgument;
    1.58 +	iLongWidth = aStride >> 1;
    1.59 +	if (iLongWidth < aSize.iWidth)
    1.60 +		return KErrArgument;
    1.61 +	iScanLineWords = aStride >> 2;
    1.62 +	TInt size = Max(aSize.iWidth,aSize.iHeight) << 1;
    1.63 +	if(size < 0)
    1.64 +		return KErrArgument;
    1.65 +	iScanLineBuffer = (TUint32*)(User::Heap().Alloc(size));
    1.66 +	if (iScanLineBuffer == NULL)
    1.67 +		return KErrNoMemory;
    1.68 +	return KErrNone;
    1.69 +	}
    1.70 +
    1.71 +TUint16* CDrawSixteenBppBitmapCommon::PixelAddress(TInt aX,TInt aY) const
    1.72 +	{
    1.73 +	return(((TUint16*)iBits) + (aY * iLongWidth) + aX);
    1.74 +	}
    1.75 +
    1.76 +void CDrawSixteenBppBitmapCommon::InvertBuffer(TInt aLength,TUint32* aBuffer)
    1.77 +	{
    1.78 +	__ASSERT_DEBUG(aLength>0,Panic(EScreenDriverPanicZeroLength));
    1.79 +	__ASSERT_DEBUG(aBuffer,Panic(EScreenDriverPanicNullPointer));
    1.80 +
    1.81 +	const TUint32* limit = aBuffer + ((aLength + 1) >> 1);
    1.82 +
    1.83 +	while (aBuffer < limit)
    1.84 +		*aBuffer++ ^= 0xffffffff;
    1.85 +	}
    1.86 +
    1.87 +void CDrawSixteenBppBitmapCommon::ShadowArea(const TRect& aRect)
    1.88 +	{
    1.89 +	const TRect rect(DeOrientate(aRect));
    1.90 +
    1.91 +	__ASSERT_DEBUG(rect.iTl.iX>=0 && rect.iBr.iX<=iSize.iWidth,Panic(EScreenDriverPanicOutOfBounds));
    1.92 +	__ASSERT_DEBUG(rect.iTl.iY>=0 && rect.iBr.iY<=iSize.iHeight,Panic(EScreenDriverPanicOutOfBounds));
    1.93 +
    1.94 +	const TInt longWidth = iLongWidth;
    1.95 +	TUint16* pixelPtr = PixelAddress(rect.iTl.iX,rect.iTl.iY);
    1.96 +	const TUint16* pixelRowPtrLimit = pixelPtr + (rect.Height() * longWidth);
    1.97 +
    1.98 +	if (iShadowMode & EFade)
    1.99 +		{
   1.100 +		TUint16* pixelRowPtr = pixelPtr;
   1.101 +		TUint16* pixelPtrLimit = pixelPtr + rect.Width();
   1.102 +
   1.103 +		while (pixelRowPtr < pixelRowPtrLimit)
   1.104 +			{
   1.105 +			for (TUint16* tempPixelPtr = pixelRowPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
   1.106 +				tempPixelPtr[0] = FadeIndex(tempPixelPtr[0]);
   1.107 +
   1.108 +			pixelRowPtr += longWidth;
   1.109 +			pixelPtrLimit += longWidth;
   1.110 +			}
   1.111 +		}
   1.112 +
   1.113 +	if (iShadowMode & EShadow)
   1.114 +		{
   1.115 +		TUint16* pixelRowPtr = pixelPtr;
   1.116 +		TUint16* pixelPtrLimit = pixelPtr + rect.Width();
   1.117 +
   1.118 +		while (pixelRowPtr < pixelRowPtrLimit)
   1.119 +			{
   1.120 +			for (TUint16* tempPixelPtr = pixelRowPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
   1.121 +				tempPixelPtr[0] = ShadowIndex(tempPixelPtr[0]);
   1.122 +
   1.123 +			pixelRowPtr += longWidth;
   1.124 +			pixelPtrLimit += longWidth;
   1.125 +			}
   1.126 +		}
   1.127 +	}
   1.128 +
   1.129 +void CDrawSixteenBppBitmapCommon::ShadowBuffer(TInt aLength,TUint32* aBuffer)
   1.130 +	{
   1.131 +	__ASSERT_DEBUG(aLength>0,Panic(EScreenDriverPanicZeroLength));
   1.132 +	__ASSERT_DEBUG(aBuffer,Panic(EScreenDriverPanicNullPointer));
   1.133 +
   1.134 +	const TUint16* limit = ((TUint16*)aBuffer) + aLength;
   1.135 +
   1.136 +	if (iShadowMode & EFade)
   1.137 +		{
   1.138 +		for (TUint16* buffer = (TUint16*)aBuffer; buffer < limit; buffer++)
   1.139 +			buffer[0] = FadeIndex(buffer[0]);
   1.140 +		}
   1.141 +
   1.142 +	if (iShadowMode & EShadow)
   1.143 +		{
   1.144 +		for (TUint16* buffer = (TUint16*)aBuffer; buffer < limit; buffer++)
   1.145 +			buffer[0] = ShadowIndex(buffer[0]);
   1.146 +		}
   1.147 +	}
   1.148 +
   1.149 +void CDrawSixteenBppBitmapCommon::ReadLine(TInt aX,TInt aY,TInt aLength,TAny* aBuffer) const
   1.150 +	{
   1.151 +	const TUint16* pixelPtr = PixelAddress(aX,aY);
   1.152 +	if (iOrientation == EOrientationNormal && iScalingOff)
   1.153 +		Mem::Copy(aBuffer,pixelPtr,aLength * 2);
   1.154 +	else
   1.155 +		{
   1.156 +		const TInt pixelPtrInc = LogicalPixelAddressIncrement();
   1.157 +		TUint16* bufferPtr = STATIC_CAST(TUint16*,aBuffer);
   1.158 +		const TUint16* bufferPtrLimit = bufferPtr + aLength;
   1.159 +		while (bufferPtr < bufferPtrLimit)
   1.160 +			{
   1.161 +			*bufferPtr++ = *pixelPtr;
   1.162 +			pixelPtr += pixelPtrInc;
   1.163 +			}
   1.164 +		}
   1.165 +	}
   1.166 +
   1.167 +void CDrawSixteenBppBitmapCommon::WriteBinary(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TUint16 aColor)
   1.168 +	{
   1.169 +	DeOrientate(aX,aY);
   1.170 +	TInt pixelInc;
   1.171 +	TInt rowInc;
   1.172 +	SetPixelInc(pixelInc, rowInc);
   1.173 +	const TUint32* dataLimit = aData + aHeight;
   1.174 +	const TUint32 dataMaskLimit = (aLength < 32) ? 1 << aLength : 0;
   1.175 +	TUint16* pixelPtr = PixelAddress(aX,aY);
   1.176 +	const TUint16* bitsStart = reinterpret_cast <const TUint16*> (iBits);
   1.177 +	const TUint16* bitsEnd = bitsStart + iLongWidth * iSize.iHeight;
   1.178 +	TInt orgY = aY;
   1.179 +	while (aData < dataLimit)
   1.180 +		{
   1.181 +		TUint32 dataWord = *aData++;
   1.182 +		TUint32 dataMask = 1;
   1.183 +		TUint16* tempPixelPtr = pixelPtr;
   1.184 +		if (iScalingOff)
   1.185 +			{
   1.186 +			while (dataMask != dataMaskLimit)
   1.187 +				{
   1.188 +				if(dataWord & dataMask)
   1.189 +					*tempPixelPtr = aColor;
   1.190 +
   1.191 +				tempPixelPtr += pixelInc;
   1.192 +				dataMask <<= 1;
   1.193 +				}
   1.194 +			}
   1.195 +		else
   1.196 +			{
   1.197 +			while (dataMask != dataMaskLimit)
   1.198 +				{
   1.199 +				if(dataWord & dataMask)
   1.200 +					{
   1.201 +					const TUint16* pixelRowPtrLimit = bitsStart + (aY + 1) * iLongWidth;
   1.202 +					SetPixels(tempPixelPtr, aColor, pixelRowPtrLimit, bitsStart, bitsEnd);
   1.203 +					}
   1.204 +				tempPixelPtr += pixelInc;
   1.205 +				dataMask <<= 1;
   1.206 +				IncScaledY(aY);
   1.207 +				}
   1.208 +			}
   1.209 +		pixelPtr += rowInc;
   1.210 +		IncScaledY(aY, orgY);		
   1.211 +		}
   1.212 +	}
   1.213 +
   1.214 +void CDrawSixteenBppBitmapCommon::WriteBinaryOp(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TUint16 aColor,CGraphicsContext::TDrawMode aDrawMode)
   1.215 +	{
   1.216 +	if (aLength <= 0)
   1.217 +		return;
   1.218 +
   1.219 +	DeOrientate(aX,aY);
   1.220 +	TUint16* pixelPtr = PixelAddress(aX,aY);
   1.221 +	const TUint32* dataPtrLimit = aData + aHeight;
   1.222 +	const TUint32 dataMaskLimit = (aLength < 32) ? 1 << aLength : 0;
   1.223 +	TInt pixelInc;
   1.224 +	TInt rowInc;
   1.225 +	SetPixelInc(pixelInc, rowInc);
   1.226 +	const TUint16* bitsStart = reinterpret_cast <const TUint16*> (iBits);
   1.227 +	const TUint16* bitsEnd = bitsStart + iLongWidth * iSize.iHeight;
   1.228 +	TInt orgY = aY;
   1.229 +	if (aColor)
   1.230 +		{
   1.231 +		while (aData < dataPtrLimit)
   1.232 +			{
   1.233 +			TUint32 dataWord = *aData++;
   1.234 +			TUint32 dataMask = 1;
   1.235 +			TUint16* tempPixelPtr = pixelPtr;
   1.236 +			if (iScalingOff)
   1.237 +				{
   1.238 +				while (dataMask != dataMaskLimit)
   1.239 +					{
   1.240 +					if(dataWord & dataMask)
   1.241 +						{
   1.242 +						if(aDrawMode==CGraphicsContext::EDrawModeXOR)
   1.243 +							*tempPixelPtr ^= aColor;
   1.244 +						else if(aDrawMode==CGraphicsContext::EDrawModeAND)
   1.245 +							*tempPixelPtr &= aColor;
   1.246 +						else if(aDrawMode==CGraphicsContext::EDrawModeOR)
   1.247 +							*tempPixelPtr |= aColor;
   1.248 +						}
   1.249 +					tempPixelPtr += pixelInc;
   1.250 +					dataMask <<= 1;
   1.251 +					}
   1.252 +				}
   1.253 +			else
   1.254 +				{
   1.255 +				while(dataMask != dataMaskLimit)
   1.256 +					{
   1.257 +					if(dataWord & dataMask)
   1.258 +						{
   1.259 +						const TUint16* pixelRowPtrLimit = bitsStart + (aY + 1) * iLongWidth;
   1.260 +						if(aDrawMode==CGraphicsContext::EDrawModeXOR)
   1.261 +							{
   1.262 +							XORPixels(tempPixelPtr, aColor, pixelRowPtrLimit, bitsStart, bitsEnd);
   1.263 +							}
   1.264 +						else if(aDrawMode==CGraphicsContext::EDrawModeAND)
   1.265 +							{
   1.266 +							ANDPixels(tempPixelPtr, aColor, pixelRowPtrLimit, bitsStart, bitsEnd);
   1.267 +							}
   1.268 +						else if(aDrawMode==CGraphicsContext::EDrawModeOR)
   1.269 +							{
   1.270 +							ORPixels(tempPixelPtr, aColor, pixelRowPtrLimit, bitsStart, bitsEnd);
   1.271 +							}
   1.272 +						}
   1.273 +					tempPixelPtr += pixelInc;
   1.274 +					dataMask <<= 1;
   1.275 +					IncScaledY(aY);
   1.276 +					}
   1.277 +				}
   1.278 +			pixelPtr += rowInc;
   1.279 +			IncScaledY(aY, orgY);			
   1.280 +			}
   1.281 +		}
   1.282 +	else if(aDrawMode==CGraphicsContext::EDrawModeAND)
   1.283 +		{
   1.284 +		while (aData < dataPtrLimit)
   1.285 +			{
   1.286 +			TUint32 dataWord = *aData++;
   1.287 +			TUint32 dataMask = 1;
   1.288 +			TUint16* tempPixelPtr = pixelPtr;
   1.289 +			if (iScalingOff)
   1.290 +				{
   1.291 +				while (dataMask != dataMaskLimit)
   1.292 +					{
   1.293 +					if(dataWord & dataMask)
   1.294 +						*tempPixelPtr = 0;
   1.295 +
   1.296 +					tempPixelPtr += pixelInc;
   1.297 +					dataMask <<= 1;
   1.298 +					}
   1.299 +				}
   1.300 +			else
   1.301 +				{
   1.302 +				while(dataMask != dataMaskLimit)
   1.303 +					{
   1.304 +					if(dataWord & dataMask)
   1.305 +						{
   1.306 +						const TUint16* pixelRowPtrLimit = bitsStart + (aY + 1) * iLongWidth;
   1.307 +						SetPixels(tempPixelPtr, TUint16(0), pixelRowPtrLimit, bitsStart, bitsEnd);
   1.308 +						}
   1.309 +					tempPixelPtr += pixelInc;
   1.310 +					dataMask <<= 1;
   1.311 +					}
   1.312 +				}
   1.313 +			pixelPtr += rowInc;
   1.314 +			IncScaledY(aY, orgY);			
   1.315 +			}
   1.316 +		}
   1.317 +	}
   1.318 +
   1.319 +void CDrawSixteenBppBitmapCommon::WriteBinaryLineVertical(TInt aX,TInt aY,TUint32* aData,TInt aHeight,TUint16 aColor,TBool aUp)
   1.320 +	{
   1.321 +	__ASSERT_DEBUG(iScalingOff, User::Invariant());	
   1.322 +	DeOrientate(aX,aY);
   1.323 +
   1.324 +	TInt scanlineByteLength;
   1.325 +
   1.326 +	switch(iOrientation)
   1.327 +		{
   1.328 +		case EOrientationNormal:
   1.329 +			scanlineByteLength = iLongWidth;
   1.330 +			break;
   1.331 +		case EOrientationRotated90:
   1.332 +			scanlineByteLength = -1;
   1.333 +			break;
   1.334 +		case EOrientationRotated180:
   1.335 +			scanlineByteLength = -iLongWidth;
   1.336 +			break;
   1.337 +		default: // EOrientationRotated270
   1.338 +			scanlineByteLength = 1;	
   1.339 +		}
   1.340 +
   1.341 +	if (aUp)
   1.342 +		scanlineByteLength = -scanlineByteLength;
   1.343 +
   1.344 +	TUint16* pixelPtr = PixelAddress(aX,aY);
   1.345 +	const TUint16* pixelPtrLimit = pixelPtr + (aHeight * scanlineByteLength);
   1.346 +	TUint32 dataWord = *aData;
   1.347 +	TUint32 dataMask = 1;
   1.348 +
   1.349 +	while(pixelPtr != pixelPtrLimit)
   1.350 +		{
   1.351 +		if(!dataMask)
   1.352 +			{
   1.353 +			dataMask = 1;
   1.354 +			aData++;
   1.355 +			dataWord = *aData;
   1.356 +			}
   1.357 +			
   1.358 +		if(dataWord & dataMask)
   1.359 +			*pixelPtr = aColor;
   1.360 +		
   1.361 +		dataMask <<= 1;
   1.362 +		pixelPtr += scanlineByteLength;
   1.363 +		}
   1.364 +	}
   1.365 +
   1.366 +
   1.367 +void CDrawSixteenBppBitmapCommon::WriteRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aHeight,TUint16 aColor)
   1.368 +	{
   1.369 +	const TInt longWidth = iLongWidth;
   1.370 +	const TInt scanLineWords = iScanLineWords;
   1.371 +
   1.372 +	TUint16* pixelPtr = PixelAddress(aX,aY);
   1.373 +	const TUint16* pixelRowPtrLimit = pixelPtr + (aHeight * longWidth);
   1.374 +
   1.375 +	if ((aColor >> 8) == (TUint8)aColor)
   1.376 +		{
   1.377 +		while (pixelPtr < pixelRowPtrLimit)
   1.378 +			{
   1.379 +			Mem::Fill(pixelPtr,aLength * 2,TUint8(aColor));
   1.380 +			pixelPtr += longWidth;
   1.381 +			}
   1.382 +		}
   1.383 +	else
   1.384 +		{
   1.385 +		const TBool leadingPixel = aX & 1;
   1.386 +		const TBool trailingPixel = (aX + aLength) & 1;
   1.387 +		const TUint32 colorWord = (aColor << 16) | aColor;
   1.388 +
   1.389 +		TUint16* lastPixelPtr = pixelPtr + aLength - 1;
   1.390 +		TUint32* wordPtr = REINTERPRET_CAST(TUint32*,pixelPtr + (leadingPixel ? 1 : 0));
   1.391 +		TUint32* wordPtrLimit = REINTERPRET_CAST(TUint32*,lastPixelPtr + (trailingPixel ? 0 : 1));
   1.392 +
   1.393 +		__ASSERT_DEBUG(!(TInt(wordPtr) & 3),Panic(EScreenDriverPanicInvalidPointer));
   1.394 +		__ASSERT_DEBUG(!(TInt(wordPtrLimit) & 3),Panic(EScreenDriverPanicInvalidPointer));
   1.395 +
   1.396 +		if (leadingPixel)
   1.397 +			{
   1.398 +			while (pixelPtr < pixelRowPtrLimit)
   1.399 +				{
   1.400 +				pixelPtr[0] = aColor;
   1.401 +				pixelPtr += longWidth;
   1.402 +				}
   1.403 +			}
   1.404 +
   1.405 +		while (wordPtr < (TUint32*)pixelRowPtrLimit)
   1.406 +			{
   1.407 +			MemFillTUint32(wordPtr, wordPtrLimit-wordPtr, colorWord);
   1.408 +			wordPtr += scanLineWords;
   1.409 +			wordPtrLimit += scanLineWords;
   1.410 +			}
   1.411 +
   1.412 +		if (trailingPixel)
   1.413 +			{
   1.414 +			while (lastPixelPtr < pixelRowPtrLimit)
   1.415 +				{
   1.416 +				lastPixelPtr[0] = aColor;
   1.417 +				lastPixelPtr += longWidth;
   1.418 +				}
   1.419 +			}
   1.420 +		}
   1.421 +	}
   1.422 +
   1.423 +void CDrawSixteenBppBitmapCommon::WriteRgbMultiXOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TUint16 aColor)
   1.424 +	{
   1.425 +	const TInt longWidth = iLongWidth;
   1.426 +	TUint16* pixelPtr = PixelAddress(aX,aY);
   1.427 +	TUint16* pixelPtrLimit = pixelPtr + aLength;
   1.428 +	const TUint16* pixelRowPtrLimit = pixelPtr + (aHeight * longWidth);
   1.429 +
   1.430 +	while (pixelPtr < pixelRowPtrLimit)
   1.431 +		{
   1.432 +		for (TUint16* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
   1.433 +			tempPixelPtr[0] ^= aColor;
   1.434 +
   1.435 +		pixelPtr += longWidth;
   1.436 +		pixelPtrLimit += longWidth;
   1.437 +		}
   1.438 +	}
   1.439 +
   1.440 +void CDrawSixteenBppBitmapCommon::WriteRgbMultiAND(TInt aX,TInt aY,TInt aLength,TInt aHeight,TUint16 aColor)
   1.441 +	{
   1.442 +	const TInt longWidth = iLongWidth;
   1.443 +	TUint16* pixelPtr = PixelAddress(aX,aY);
   1.444 +	TUint16* pixelPtrLimit = pixelPtr + aLength;
   1.445 +	const TUint16* pixelRowPtrLimit = pixelPtr + (aHeight * longWidth);
   1.446 +
   1.447 +	while (pixelPtr < pixelRowPtrLimit)
   1.448 +		{
   1.449 +		for (TUint16* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
   1.450 +			tempPixelPtr[0] &= aColor;
   1.451 +
   1.452 +		pixelPtr += longWidth;
   1.453 +		pixelPtrLimit += longWidth;
   1.454 +		}
   1.455 +	}
   1.456 +
   1.457 +void CDrawSixteenBppBitmapCommon::WriteRgbMultiOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TUint16 aColor)
   1.458 +	{
   1.459 +	const TInt longWidth = iLongWidth;
   1.460 +	TUint16* pixelPtr = PixelAddress(aX,aY);
   1.461 +	TUint16* pixelPtrLimit = pixelPtr + aLength;
   1.462 +	const TUint16* pixelRowPtrLimit = pixelPtr + (aHeight * longWidth);
   1.463 +
   1.464 +	while (pixelPtr < pixelRowPtrLimit)
   1.465 +		{
   1.466 +		for (TUint16* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
   1.467 +			tempPixelPtr[0] |= aColor;
   1.468 +
   1.469 +		pixelPtr += longWidth;
   1.470 +		pixelPtrLimit += longWidth;
   1.471 +		}
   1.472 +	}
   1.473 +
   1.474 +void CDrawSixteenBppBitmapCommon::WriteLine(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
   1.475 +	{
   1.476 +	TUint16* pixelPtr = PixelAddress(aX,aY);
   1.477 +	if (iOrientation == EOrientationNormal && iScalingOff)
   1.478 +		Mem::Copy(pixelPtr,aBuffer,aLength * 2);
   1.479 +	else
   1.480 +		{
   1.481 +		const TInt pixelPtrInc = LogicalPixelAddressIncrement();
   1.482 +		TUint16* bufferPtr = REINTERPRET_CAST(TUint16*,aBuffer);
   1.483 +		TUint16* bufferPtrLimit = bufferPtr + aLength;
   1.484 +		if (iScalingOff)
   1.485 +			{
   1.486 +			while (bufferPtr < bufferPtrLimit)
   1.487 +				{
   1.488 +				*pixelPtr = *bufferPtr++;
   1.489 +				pixelPtr += pixelPtrInc;
   1.490 +				}
   1.491 +			}
   1.492 +		else
   1.493 +			{
   1.494 +			const TUint16* bitsStart = reinterpret_cast <const TUint16*> (iBits);
   1.495 +			const TUint16* bitsEnd = bitsStart + iLongWidth * iSize.iHeight;
   1.496 +			while(bufferPtr < bufferPtrLimit)
   1.497 +				{
   1.498 +				const TUint16* pixelRowPtrLimit = bitsStart + (aY + 1) * iLongWidth;
   1.499 +				SetPixels(pixelPtr, *bufferPtr++, pixelRowPtrLimit, bitsStart, bitsEnd);
   1.500 +				pixelPtr += pixelPtrInc;
   1.501 +				IncScaledY(aY);
   1.502 +				}
   1.503 +			}
   1.504 +		}
   1.505 +	}
   1.506 +
   1.507 +void CDrawSixteenBppBitmapCommon::WriteLineXOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
   1.508 +	{
   1.509 +	TUint16* pixelPtr = PixelAddress(aX,aY);
   1.510 +	const TInt pixelPtrInc = LogicalPixelAddressIncrement();
   1.511 +	TUint16* bufferPtr = REINTERPRET_CAST(TUint16*,aBuffer);
   1.512 +	const TUint16* bufferPtrLimit = bufferPtr + aLength;
   1.513 +	if (iScalingOff)
   1.514 +		{
   1.515 +		while (bufferPtr < bufferPtrLimit)
   1.516 +			{
   1.517 +			*pixelPtr ^= *bufferPtr++;
   1.518 +			pixelPtr += pixelPtrInc;
   1.519 +			}
   1.520 +		}
   1.521 +	else
   1.522 +		{
   1.523 +		const TUint16* bitsStart = reinterpret_cast <const TUint16*> (iBits);
   1.524 +		const TUint16* bitsEnd = bitsStart + iLongWidth * iSize.iHeight;
   1.525 +		while(bufferPtr < bufferPtrLimit)
   1.526 +			{
   1.527 +			const TUint16* pixelRowPtrLimit = bitsStart + (aY + 1) * iLongWidth;
   1.528 +			XORPixels(pixelPtr, *bufferPtr++, pixelRowPtrLimit, bitsStart, bitsEnd);
   1.529 +			pixelPtr += pixelPtrInc;
   1.530 +			IncScaledY(aY);
   1.531 +			}
   1.532 +		}
   1.533 +	}
   1.534 +
   1.535 +void CDrawSixteenBppBitmapCommon::WriteLineAND(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
   1.536 +	{
   1.537 +	TUint16* pixelPtr = PixelAddress(aX,aY);
   1.538 +	const TInt pixelPtrInc = LogicalPixelAddressIncrement();
   1.539 +	TUint16* bufferPtr = REINTERPRET_CAST(TUint16*,aBuffer);
   1.540 +	const TUint16* bufferPtrLimit = bufferPtr + aLength;
   1.541 +	if (iScalingOff)
   1.542 +		{
   1.543 +		while (bufferPtr < bufferPtrLimit)
   1.544 +			{
   1.545 +			*pixelPtr &= *bufferPtr++;
   1.546 +			pixelPtr += pixelPtrInc;
   1.547 +			}
   1.548 +		}
   1.549 +	else
   1.550 +		{
   1.551 +		const TUint16* bitsStart = reinterpret_cast <const TUint16*> (iBits);
   1.552 +		const TUint16* bitsEnd = bitsStart + iLongWidth * iSize.iHeight;
   1.553 +		while(bufferPtr < bufferPtrLimit)
   1.554 +			{
   1.555 +			const TUint16* pixelRowPtrLimit = bitsStart + (aY + 1) * iLongWidth;
   1.556 +			ANDPixels(pixelPtr, *bufferPtr++, pixelRowPtrLimit, bitsStart, bitsEnd);
   1.557 +			pixelPtr += pixelPtrInc;
   1.558 +			IncScaledY(aY);
   1.559 +			}
   1.560 +		}
   1.561 +	}
   1.562 +
   1.563 +void CDrawSixteenBppBitmapCommon::WriteLineOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
   1.564 +	{
   1.565 +	TUint16* pixelPtr = PixelAddress(aX,aY);
   1.566 +	const TInt pixelPtrInc = LogicalPixelAddressIncrement();
   1.567 +	TUint16* bufferPtr = REINTERPRET_CAST(TUint16*,aBuffer);
   1.568 +	const TUint16* bufferPtrLimit = bufferPtr + aLength;
   1.569 +	if (iScalingOff)
   1.570 +		{
   1.571 +		while (bufferPtr < bufferPtrLimit)
   1.572 +			{
   1.573 +			*pixelPtr |= *bufferPtr++;
   1.574 +			pixelPtr += pixelPtrInc;
   1.575 +			}
   1.576 +		}
   1.577 +	else
   1.578 +		{
   1.579 +		const TUint16* bitsStart = reinterpret_cast <const TUint16*> (iBits);
   1.580 +		const TUint16* bitsEnd = bitsStart + iLongWidth * iSize.iHeight;
   1.581 +		while(bufferPtr < bufferPtrLimit)
   1.582 +			{
   1.583 +			const TUint16* pixelRowPtrLimit = bitsStart + (aY + 1) * iLongWidth;
   1.584 +			ORPixels(pixelPtr, *bufferPtr++, pixelRowPtrLimit, bitsStart, bitsEnd);
   1.585 +			pixelPtr += pixelPtrInc;
   1.586 +			IncScaledY(aY);
   1.587 +			}
   1.588 +		}
   1.589 +	}
   1.590 +
   1.591 +/**
   1.592 +Implementation for CFbsDrawDevice::GetInterface().
   1.593 +Retrieves a pointer to a specified interface of CFbsDrawDevice implementation.
   1.594 +@param aInterfaceId Interface identifier of the interface to be retrieved.
   1.595 +@param aInterface Address of variable that retrieves the specified interface.
   1.596 +@return KErrNone If the interface is supported, KErrNotSupported otherwise.
   1.597 +*/
   1.598 +
   1.599 +TInt CDrawSixteenBppBitmapCommon::GetInterface(TInt aInterfaceId, TAny*& aInterface)
   1.600 +	{
   1.601 +	aInterface = NULL;
   1.602 +	TInt ret = KErrNotSupported;
   1.603 +	
   1.604 +	if (aInterfaceId == KFastBlit2InterfaceID)
   1.605 +		{
   1.606 +		aInterface = static_cast<MFastBlit2*>(this);
   1.607 +		ret = KErrNone;
   1.608 +		}
   1.609 +	else 
   1.610 +		return CDrawBitmap::GetInterface(aInterfaceId, aInterface);
   1.611 +		
   1.612 +	return ret;
   1.613 +	}
   1.614 +
   1.615 +/**
   1.616 +CDrawSixteenBppBitmapCommon::WriteBitmapBlock() implementation.
   1.617 +@internalTechnology
   1.618 +@see MFastBlit2::WriteBitmapBlock()
   1.619 +*/
   1.620 +TInt CDrawSixteenBppBitmapCommon::WriteBitmapBlock(const TPoint& aDest,
   1.621 +									CFbsDrawDevice* aSrcDrawDevice,
   1.622 +									const TRect& aSrcRect)
   1.623 +	{
   1.624 +	__ASSERT_DEBUG(aSrcDrawDevice && ((aSrcDrawDevice->DisplayMode()==EColor64K) || (aSrcDrawDevice->DisplayMode()==EColor4K)), Panic(EScreenDriverPanicInvalidParameter));
   1.625 +	
   1.626 +	TAny* interface=NULL;
   1.627 +	TInt ret = aSrcDrawDevice->GetInterface(KFastBlit2InterfaceID, interface);
   1.628 +	if (ret != KErrNone)
   1.629 +		{
   1.630 +		return KErrNotSupported;
   1.631 +		}
   1.632 +
   1.633 +	TAny* interface1=NULL;
   1.634 +	ret = aSrcDrawDevice->GetInterface(KScalingSettingsInterfaceID, interface1);
   1.635 +	if(ret != KErrNone || (interface1 && !reinterpret_cast<MScalingSettings*>(interface1)->IsScalingOff()))
   1.636 +		{
   1.637 +		return KErrNotSupported;
   1.638 +		}
   1.639 +
   1.640 +	ret = aSrcDrawDevice->GetInterface(KOrientationInterfaceID, interface1);
   1.641 +	if(ret != KErrNone || (interface1 && reinterpret_cast<MDrawDeviceOrientation*>(interface1)->Orientation() != 0))
   1.642 +		{
   1.643 +		return KErrNotSupported;
   1.644 +		}
   1.645 +
   1.646 +	ret = aSrcDrawDevice->GetInterface(KDrawDeviceOriginInterfaceID, interface1);
   1.647 +	if(ret != KErrNone)
   1.648 +		{
   1.649 +		return KErrNotSupported;
   1.650 +		}
   1.651 +	
   1.652 +	if(interface1)
   1.653 +		{
   1.654 +	 	TPoint pt;
   1.655 +	 	reinterpret_cast<MDrawDeviceOrigin*>(interface1)->Get(pt);
   1.656 +	 	if(pt.iX != 0 || pt.iY != 0)
   1.657 +	 		{
   1.658 +			return KErrNotSupported;
   1.659 +	 		}
   1.660 +		}
   1.661 +
   1.662 +	const TUint32* srcBase = reinterpret_cast<MFastBlit2*>(interface)->Bits();
   1.663 +	__ASSERT_DEBUG(srcBase!=NULL, Panic(EScreenDriverPanicInvalidParameter));
   1.664 +	TInt srcStride = aSrcDrawDevice->ScanLineBytes();  
   1.665 +	__ASSERT_DEBUG((srcStride&3)==0, Panic(EScreenDriverPanicInvalidParameter));  // stride is assumed to be a multiple of 4
   1.666 +	TSize srcSize = aSrcDrawDevice->SizeInPixels();
   1.667 +
   1.668 +	return WriteBitmapBlock(aDest, srcBase, srcStride, srcSize, aSrcRect);
   1.669 +	}
   1.670 +
   1.671 +								
   1.672 +/**
   1.673 +CDrawSixteenBppBitmapCommon::WriteBitmapBlock() implementation.
   1.674 +@internalTechnology
   1.675 +@see MFastBlit2::WriteBitmapBlock()
   1.676 +*/													
   1.677 +TInt CDrawSixteenBppBitmapCommon::WriteBitmapBlock(const TPoint& aDest,
   1.678 +									const TUint32* aSrcBase,
   1.679 +									TInt aSrcStride,
   1.680 +									const TSize& aSrcSize,
   1.681 +									const TRect& aSrcRect)
   1.682 +	{
   1.683 +	__ASSERT_DEBUG(aSrcBase, Panic(EScreenDriverPanicInvalidParameter));
   1.684 +	__ASSERT_DEBUG((aSrcStride&3)==0, Panic(EScreenDriverPanicInvalidParameter));
   1.685 +	__ASSERT_DEBUG(iBits, Panic(EScreenDriverPanicInvalidPointer));
   1.686 +
   1.687 +	if (iShadowMode!=NULL ||
   1.688 +    	(iUserDispMode!=NULL && iUserDispMode!=iDispMode) ||
   1.689 +    	iOrientation!=EOrientationNormal ||
   1.690 +		!IsScalingOff() ||
   1.691 +		!iOriginIsZero)
   1.692 +		{
   1.693 +		return KErrNotSupported;
   1.694 +		}
   1.695 +	
   1.696 +	__ASSERT_DEBUG(aSrcRect.iTl.iX >= 0, Panic(EScreenDriverPanicOutOfBounds)); 
   1.697 +	__ASSERT_DEBUG(aSrcRect.iTl.iY >= 0, Panic(EScreenDriverPanicOutOfBounds));
   1.698 +	__ASSERT_DEBUG(aSrcRect.iBr.iX <= aSrcSize.iWidth,  Panic(EScreenDriverPanicOutOfBounds));
   1.699 +	__ASSERT_DEBUG(aSrcRect.iBr.iY <= aSrcSize.iHeight, Panic(EScreenDriverPanicOutOfBounds));
   1.700 +	__ASSERT_DEBUG(aDest.iX >= 0, Panic(EScreenDriverPanicOutOfBounds));
   1.701 +	__ASSERT_DEBUG(aDest.iY >= 0, Panic(EScreenDriverPanicOutOfBounds));
   1.702 +	__ASSERT_DEBUG((aDest.iX + aSrcRect.Width())  <= SizeInPixels().iWidth,  Panic(EScreenDriverPanicOutOfBounds));
   1.703 +	__ASSERT_DEBUG((aDest.iY + aSrcRect.Height()) <= SizeInPixels().iHeight, Panic(EScreenDriverPanicOutOfBounds));
   1.704 +	
   1.705 +	const TInt srcStride16 = aSrcStride     >> 1;
   1.706 +	const TInt dstStride16 = iScanLineWords << 1;
   1.707 +	
   1.708 +	if (aSrcSize.iWidth == aSrcRect.Width() &&
   1.709 +		aSrcSize.iWidth == SizeInPixels().iWidth &&
   1.710 +		srcStride16 == dstStride16)
   1.711 +		{
   1.712 +		// Optimum case - one memcpy
   1.713 +		__ASSERT_DEBUG(aSrcRect.iTl.iX==0 && aDest.iX==0, Panic(EScreenDriverPanicInvalidParameter));  // this is implied by the above conditions
   1.714 +		const TUint32* srcPtr = aSrcBase + (iScanLineWords * aSrcRect.iTl.iY);
   1.715 +		TUint32* dstPtr       = iBits    + (iScanLineWords * aDest.iY);
   1.716 +		const TInt length = aSrcStride * aSrcRect.Height();
   1.717 +		Mem::Move(dstPtr, srcPtr, length);
   1.718 +		return KErrNone;
   1.719 +		}
   1.720 +		
   1.721 +	// Sub-optimal case - one memcpy per line
   1.722 +	const TUint16* srcPtr = (TUint16*)aSrcBase + (srcStride16 * aSrcRect.iTl.iY) + aSrcRect.iTl.iX;
   1.723 +	TUint16* dstPtr       = (TUint16*)iBits    + (dstStride16 * aDest.iY       ) + aDest.iX;
   1.724 +	const TInt length = aSrcRect.Width() << 1;
   1.725 +	TInt lines = aSrcRect.Height();
   1.726 +	while (lines--)
   1.727 +		{
   1.728 +		Mem::Copy(dstPtr, srcPtr, length);
   1.729 +		srcPtr += srcStride16;
   1.730 +		dstPtr += dstStride16;
   1.731 +		}
   1.732 +	return KErrNone;
   1.733 +	}
   1.734 +
   1.735 +/**
   1.736 +CDrawSixteenBppBitmapCommon::Bits() implementation.
   1.737 +@internalTechnology
   1.738 +@see MFastBlit2::Bits()
   1.739 +*/
   1.740 +const TUint32* CDrawSixteenBppBitmapCommon::Bits() const
   1.741 +	{
   1.742 +	return iBits;
   1.743 +	}
   1.744 +
   1.745 +// CDrawSixteenBppBitmap
   1.746 +
   1.747 +TInt CDrawSixteenBppBitmap::Construct(TSize aSize)
   1.748 +	{
   1.749 +	return Construct(aSize, ((aSize.iWidth + 1) & ~1) << 1);
   1.750 +	}
   1.751 +
   1.752 +TInt CDrawSixteenBppBitmap::Construct(TSize aSize, TInt aStride)
   1.753 +	{
   1.754 +	iDispMode = EColor64K;
   1.755 +	return CDrawSixteenBppBitmapCommon::Construct(aSize, aStride);
   1.756 +	}
   1.757 +
   1.758 +void CDrawSixteenBppBitmap::Shadow(TRgb& aColor)
   1.759 +	{
   1.760 +	if (iShadowMode & EFade)
   1.761 +		{
   1.762 +#if defined(SYMBIAN_USE_FAST_FADING)
   1.763 +		TUint16 color = aColor._Color64K();
   1.764 +		TInt alpha = aColor.Alpha();
   1.765 +		color = TUint16(((color >> K16bppFastFadeShift) & ~K16bppFastFadeMask) + K16bppFastFadeOffset);
   1.766 +		aColor = TRgb::_Color64K(color);
   1.767 +		aColor.SetAlpha(alpha);
   1.768 +#else
   1.769 +		TRgb fadeColor = TRgb::_Color64K(aColor._Color64K());
   1.770 +		fadeColor.SetAlpha(aColor.Alpha());
   1.771 +		aColor = FadeRgb(fadeColor);
   1.772 +#endif
   1.773 +		}
   1.774 +
   1.775 +	if (iShadowMode & EShadow)
   1.776 +		{
   1.777 +		TRgb shadowColor = TRgb::_Color64K(ShadowIndex(TUint16(aColor._Color64K())));
   1.778 +		shadowColor.SetAlpha(aColor.Alpha());
   1.779 +		aColor = shadowColor;
   1.780 +		}
   1.781 +	}
   1.782 +
   1.783 +/**
   1.784 +The overloaded function for Shadow(TRgb) which works directly with
   1.785 +the Red, Green and Blue colour components to increase the performance.
   1.786 +@param aRed Red component of colour.
   1.787 +@param aGreen Green component of colour.
   1.788 +@param aBlue Blue component of colour.
   1.789 +*/
   1.790 +FORCEINLINE void CDrawSixteenBppBitmap::Shadow(TInt& aRed, TInt& aGreen, TInt& aBlue)
   1.791 +	{
   1.792 +	if (iShadowMode & EFade)
   1.793 +		{
   1.794 +#if defined(SYMBIAN_USE_FAST_FADING)
   1.795 +		TUint16 color = PackColor64K(aRed, aGreen, aBlue);
   1.796 +		color = TUint16(((color >> K16bppFastFadeShift) & ~K16bppFastFadeMask) + K16bppFastFadeOffset);
   1.797 +		UnpackColor64K(color, aRed, aGreen, aBlue);
   1.798 +#else
   1.799 +		FadeRgb(aRed, aGreen, aBlue);
   1.800 +#endif
   1.801 +		}
   1.802 +
   1.803 +	if (iShadowMode & EShadow)
   1.804 +		{
   1.805 +		ShadowIndex(aRed, aGreen, aBlue);
   1.806 +		}
   1.807 +	}
   1.808 +
   1.809 +/**
   1.810 +The overloaded function for Shadow(TRgb) which works directly with
   1.811 +16 bit colour instead of TRgb to increase the performance.
   1.812 +@param a64KColor The 16 bit colour value.
   1.813 +*/
   1.814 +FORCEINLINE void CDrawSixteenBppBitmap::Shadow(TUint16& a64KColor)
   1.815 +	{
   1.816 +	if (iShadowMode & EFade)
   1.817 +		{
   1.818 +#if defined(SYMBIAN_USE_FAST_FADING)
   1.819 +		a64KColor = TUint16(((a64KColor >> K16bppFastFadeShift) & ~K16bppFastFadeMask) + K16bppFastFadeOffset);
   1.820 +#else
   1.821 +		TRgb fadeColor = TRgb::_Color64K(a64KColor);
   1.822 +		fadeColor.SetAlpha(0xFF);
   1.823 +		a64KColor = FadeRgb(fadeColor)._Color64K();
   1.824 +#endif
   1.825 +		}
   1.826 +	if (iShadowMode & EShadow)
   1.827 +		{
   1.828 +		a64KColor = ShadowIndex(a64KColor);
   1.829 +		}
   1.830 +	}
   1.831 +
   1.832 +TUint16 CDrawSixteenBppBitmap::ShadowIndex(TUint16 aColor64KIndex)
   1.833 +	{
   1.834 +	TInt red = (aColor64KIndex & 0xf800) >> 11;
   1.835 +	TInt green = (aColor64KIndex & 0x07e0) >> 5;
   1.836 +	TInt blue = aColor64KIndex & 0x001f;
   1.837 +
   1.838 +	red = Max(0,red-8);
   1.839 +	green = Max(0,green-16);
   1.840 +	blue = Max(0,blue-8);
   1.841 +
   1.842 +	return TUint16((red << 11) | (green << 5) | blue);
   1.843 +	}
   1.844 +
   1.845 +/**
   1.846 +The overloaded function for ShadowIndex(TUint16) which works directly with
   1.847 +the Red, Green and Blue colour components to increase the performance.
   1.848 +@param aRed Red component of colour.
   1.849 +@param aGreen Green component of colour.
   1.850 +@param aBlue Blue component of colour.
   1.851 +*/
   1.852 +FORCEINLINE void CDrawSixteenBppBitmap::ShadowIndex(TInt& aRed, TInt& aGreen, TInt& aBlue)
   1.853 +	{
   1.854 +	aRed = Max(0,aRed-8);
   1.855 +	aGreen = Max(0,aGreen-16);
   1.856 +	aBlue = Max(0,aBlue-8);
   1.857 +	}
   1.858 +
   1.859 +TUint16 CDrawSixteenBppBitmap::FadeIndex(TUint16 aColor64KIndex)
   1.860 +	{
   1.861 +#if defined(SYMBIAN_USE_FAST_FADING)
   1.862 +	return TUint16(((aColor64KIndex >> K16bppFastFadeShift) & ~K16bppFastFadeMask) + K16bppFastFadeOffset);
   1.863 +#else
   1.864 +	return TUint16(FadeRgb(TRgb::_Color64K(aColor64KIndex))._Color64K());
   1.865 +#endif
   1.866 +	}
   1.867 +
   1.868 +TRgb CDrawSixteenBppBitmap::ReadRgbNormal(TInt aX,TInt aY) const
   1.869 +	{
   1.870 +	return TRgb::_Color64K(*PixelAddress(aX,aY));
   1.871 +	}
   1.872 +
   1.873 +void CDrawSixteenBppBitmap::WriteRgb(TInt aX,TInt aY,TRgb aColor)
   1.874 +	{
   1.875 +	register TUint16* pixelAddr = PixelAddress(aX, aY);
   1.876 +	register TUint16 aPixel = TUint16(aColor._Color64K());
   1.877 +	
   1.878 +	const TInt sourceAlpha = aColor.Alpha();	
   1.879 +
   1.880 +	if (sourceAlpha==0)
   1.881 +		return;
   1.882 +	
   1.883 +	if (sourceAlpha<0xff)
   1.884 +		{
   1.885 +		const TUint32 srcInternal=aColor.Internal();
   1.886 +		const TUint32 srcRB=srcInternal & 0x00FF00FF;
   1.887 +		const TUint32 srcG=(srcInternal & 0xFF00) >> 8;
   1.888 +		aPixel = BlendTo16(srcRB, srcG, sourceAlpha, *pixelAddr);
   1.889 +		}
   1.890 +
   1.891 +	if (iScalingOff)
   1.892 +		{
   1.893 +		*pixelAddr = aPixel;
   1.894 +		}
   1.895 +	else
   1.896 +		{
   1.897 +		const TUint16* bitsStart = reinterpret_cast <const TUint16*> (iBits);
   1.898 +		const TUint16* bitsEnd = bitsStart + iLongWidth * iSize.iHeight;
   1.899 +		const TUint16* pixelRowPtrLimit = bitsStart + (aY + 1) * iLongWidth;
   1.900 +		SetPixels(pixelAddr, aPixel, pixelRowPtrLimit, bitsStart, bitsEnd);
   1.901 +		}
   1.902 +	}
   1.903 +
   1.904 +void CDrawSixteenBppBitmap::WriteBinary(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TRgb aColor)
   1.905 +	{
   1.906 +	const TInt sourceAlpha = aColor.Alpha();
   1.907 +	if (sourceAlpha==255)
   1.908 +		{
   1.909 +		CDrawSixteenBppBitmapCommon::WriteBinary(aX,aY,aData,aLength,aHeight,(TUint16)aColor._Color64K());
   1.910 +		return;
   1.911 +		}
   1.912 +	if (sourceAlpha==0)
   1.913 +		return;
   1.914 +
   1.915 +	DeOrientate(aX,aY);
   1.916 +
   1.917 +	TInt pixelInc;
   1.918 +	TInt rowInc;
   1.919 +
   1.920 +	switch(iOrientation)
   1.921 +		{
   1.922 +		case EOrientationNormal:
   1.923 +			{
   1.924 +			pixelInc = 1;
   1.925 +			rowInc = iLongWidth;
   1.926 +			break;
   1.927 +			}
   1.928 +		case EOrientationRotated90:
   1.929 +			{
   1.930 +			pixelInc = iLongWidth;
   1.931 +			rowInc = -1;
   1.932 +			break;
   1.933 +			}
   1.934 +		case EOrientationRotated180:
   1.935 +			{
   1.936 +			pixelInc = -1;
   1.937 +			rowInc = -iLongWidth;
   1.938 +			break;
   1.939 +			}
   1.940 +		default: // EOrientationRotated270
   1.941 +			{
   1.942 +			pixelInc = -iLongWidth;
   1.943 +			rowInc = 1;
   1.944 +			}
   1.945 +		}
   1.946 +
   1.947 +	const TUint32* dataLimit = aData + aHeight;
   1.948 +	const TUint32 dataMaskLimit = (aLength < 32) ? 1 << aLength : 0;
   1.949 +
   1.950 +	TUint16* pixelPtr = PixelAddress(aX,aY);
   1.951 +
   1.952 +	const TUint32 srcInternal=aColor.Internal();
   1.953 +	const TUint32 srcRB=srcInternal & 0x00FF00FF;
   1.954 +	const TUint32 srcG=(srcInternal & 0xFF00) >> 8;
   1.955 +	while (aData < dataLimit)
   1.956 +		{
   1.957 +		TUint32 dataWord = *aData++;
   1.958 +		TUint32 dataMask = 1;
   1.959 +		TUint16* tempPixelPtr = pixelPtr;
   1.960 +
   1.961 +		while (dataMask != dataMaskLimit)
   1.962 +			{
   1.963 +			if(dataWord & dataMask)
   1.964 +				{
   1.965 +				*tempPixelPtr = BlendTo16(srcRB, srcG, sourceAlpha, *tempPixelPtr);
   1.966 +				}
   1.967 +
   1.968 +			tempPixelPtr += pixelInc;
   1.969 +			dataMask <<= 1;
   1.970 +			}
   1.971 +
   1.972 +		pixelPtr += rowInc;
   1.973 +		}
   1.974 +	}
   1.975 +
   1.976 +void CDrawSixteenBppBitmap::WriteBinaryOp(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode)
   1.977 +	{
   1.978 +	CDrawSixteenBppBitmapCommon::WriteBinaryOp(aX,aY,aData,aLength,aHeight,(TUint16)aColor._Color64K(),aDrawMode);
   1.979 +	}
   1.980 +
   1.981 +void CDrawSixteenBppBitmap::WriteBinaryLineVertical(TInt aX,TInt aY,TUint32* aData,TInt aHeight,TRgb aColor,TBool aUp)
   1.982 +	{
   1.983 +	const TInt sourceAlpha = aColor.Alpha();
   1.984 +	if (sourceAlpha==255)
   1.985 +		{
   1.986 +		CDrawSixteenBppBitmapCommon::WriteBinaryLineVertical(aX,aY,aData,aHeight,(TUint16)aColor._Color64K(),aUp);
   1.987 +		return;
   1.988 +		}
   1.989 +	if (sourceAlpha==0)
   1.990 +		return;
   1.991 +
   1.992 +	DeOrientate(aX,aY);
   1.993 +
   1.994 +	TInt scanlineByteLength;
   1.995 +
   1.996 +	switch(iOrientation)
   1.997 +		{
   1.998 +		case EOrientationNormal:
   1.999 +			scanlineByteLength = iLongWidth;
  1.1000 +			break;
  1.1001 +		case EOrientationRotated90:
  1.1002 +			scanlineByteLength = -1;
  1.1003 +			break;
  1.1004 +		case EOrientationRotated180:
  1.1005 +			scanlineByteLength = -iLongWidth;
  1.1006 +			break;
  1.1007 +		default:// EOrientationRotated270
  1.1008 +			scanlineByteLength = 1;	
  1.1009 +		}
  1.1010 +
  1.1011 +	if (aUp)
  1.1012 +		scanlineByteLength = -scanlineByteLength;
  1.1013 +
  1.1014 +	TUint16* pixelPtr = PixelAddress(aX,aY);
  1.1015 +	const TUint16* pixelPtrLimit = pixelPtr + (aHeight * scanlineByteLength);
  1.1016 +	TUint32 dataWord = *aData;
  1.1017 +	TUint32 dataMask = 1;
  1.1018 +
  1.1019 +	const TUint32 srcInternal=aColor.Internal();
  1.1020 +	const TUint32 srcRB=srcInternal & 0x00FF00FF;
  1.1021 +	const TUint32 srcG=(srcInternal & 0xFF00) >> 8;
  1.1022 +	while(pixelPtr != pixelPtrLimit)
  1.1023 +		{
  1.1024 +		if(!dataMask)
  1.1025 +			{
  1.1026 +			dataMask = 1;
  1.1027 +			aData++;
  1.1028 +			dataWord = *aData;
  1.1029 +			}
  1.1030 +
  1.1031 +		if(dataWord & dataMask)
  1.1032 +			{
  1.1033 +			*pixelPtr = BlendTo16(srcRB, srcG, sourceAlpha, *pixelPtr);
  1.1034 +			}
  1.1035 +		dataMask <<= 1;
  1.1036 +		pixelPtr += scanlineByteLength;
  1.1037 +		}
  1.1038 +	}
  1.1039 +
  1.1040 +/**
  1.1041 +MAlphaBlend::WriteRgbAlphaLine2() implementation.
  1.1042 +@see MAlphaBlend::WriteRgbAlphaLine2()
  1.1043 +*/
  1.1044 +void CDrawSixteenBppBitmap::WriteRgbAlphaLine(TInt aX, TInt aY, TInt aLength,
  1.1045 +                                              const TUint8* aRgbBuffer,
  1.1046 +                                              const TUint8* aMaskBuffer,
  1.1047 +                                              MAlphaBlend::TShadowing aShadowing,
  1.1048 +                                              CGraphicsContext::TDrawMode /*aDrawMode*/)
  1.1049 +    {
  1.1050 +	DeOrientate(aX,aY);
  1.1051 +	TUint16* pixelPtr = PixelAddress(aX,aY);
  1.1052 +	const TInt pixelPtrInc = LogicalPixelAddressIncrement();
  1.1053 +	const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
  1.1054 +	TUint16 pixelColor;
  1.1055 +
  1.1056 +	__ASSERT_DEBUG( (((((TUint)pixelPtr)&1)==0) && ((((TUint)aRgbBuffer)&3)==0)), Panic(EScreenDriverPanicInvalidParameter));
  1.1057 +
  1.1058 +	if (iScalingOff)
  1.1059 +		{
  1.1060 +		if (!(iShadowMode & (EFade | EShadow)) && iUserDispMode == ENone)
  1.1061 +			{
  1.1062 +			TUint32* rgbBuffer32 = (TUint32*)aRgbBuffer;
  1.1063 +			while (aMaskBuffer < maskBufferPtrLimit)
  1.1064 +				{
  1.1065 +				pixelPtr[0] = Blend32To16(rgbBuffer32[0], aMaskBuffer[0], pixelPtr[0]);
  1.1066 +				pixelPtr += pixelPtrInc;
  1.1067 +				rgbBuffer32 ++;
  1.1068 +				aMaskBuffer++;
  1.1069 +				}
  1.1070 +			}
  1.1071 +		else
  1.1072 +			{
  1.1073 +			while (aMaskBuffer < maskBufferPtrLimit)
  1.1074 +				{
  1.1075 +				TInt blue = aRgbBuffer[0];
  1.1076 +				TInt green = aRgbBuffer[1];
  1.1077 +				TInt red = aRgbBuffer[2];
  1.1078 +				if(aShadowing == MAlphaBlend::EShdwBefore)
  1.1079 +					{
  1.1080 +					Shadow(red,green,blue);
  1.1081 +					}
  1.1082 +				pixelColor = ::AlphaBlend(red,green,blue, pixelPtr[0],aMaskBuffer[0]);
  1.1083 +				if(aShadowing == MAlphaBlend::EShdwAfter)
  1.1084 +					{
  1.1085 +					Shadow(pixelColor);
  1.1086 +					}
  1.1087 +				MapColorToUserDisplayMode(pixelColor);
  1.1088 +				pixelPtr[0] = pixelColor;
  1.1089 +
  1.1090 +				pixelPtr += pixelPtrInc;
  1.1091 +				aRgbBuffer += 4;
  1.1092 +				aMaskBuffer++;
  1.1093 +				}
  1.1094 +			}
  1.1095 +		}
  1.1096 +	else
  1.1097 +		{
  1.1098 +		const TUint16* bitsStart = reinterpret_cast <const TUint16*> (iBits);
  1.1099 +		const TUint16* bitsEnd = bitsStart + iLongWidth * iSize.iHeight;
  1.1100 +		while (aMaskBuffer < maskBufferPtrLimit)
  1.1101 +			{
  1.1102 +			TInt blue = aRgbBuffer[0];
  1.1103 +			TInt green = aRgbBuffer[1];
  1.1104 +			TInt red = aRgbBuffer[2];
  1.1105 +            if(aShadowing == MAlphaBlend::EShdwBefore)
  1.1106 +                {
  1.1107 +                Shadow(red,green,blue);
  1.1108 +                }
  1.1109 +            pixelColor = ::AlphaBlend(red,green,blue,pixelPtr[0],aMaskBuffer[0]);
  1.1110 +            if(aShadowing == MAlphaBlend::EShdwAfter)
  1.1111 +                {
  1.1112 +		        Shadow(pixelColor);
  1.1113 +                }
  1.1114 +			MapColorToUserDisplayMode(pixelColor);
  1.1115 +			const TUint16* pixelRowPtrLimit = bitsStart + (aY + 1) * iLongWidth;
  1.1116 +			SetPixels(pixelPtr, pixelColor, pixelRowPtrLimit, bitsStart, bitsEnd);
  1.1117 +			pixelPtr += pixelPtrInc;
  1.1118 +			aRgbBuffer += 4;
  1.1119 +			aMaskBuffer++;
  1.1120 +			IncScaledY(aY);
  1.1121 +			}
  1.1122 +		}
  1.1123 +	}
  1.1124 +
  1.1125 +void CDrawSixteenBppBitmap::WriteRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
  1.1126 +	{
  1.1127 +	CDrawSixteenBppBitmapCommon::WriteRgbMulti(aX,aY,aLength,aHeight,(TUint16)aColor._Color64K());
  1.1128 +	}
  1.1129 +
  1.1130 +void CDrawSixteenBppBitmap::BlendRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
  1.1131 +	{
  1.1132 +	const TInt sourceAlpha = aColor.Alpha();
  1.1133 +	if (sourceAlpha==255)// opaque
  1.1134 +		{
  1.1135 +		CDrawSixteenBppBitmapCommon::WriteRgbMulti(aX,aY,aLength,aHeight,(TUint16)aColor._Color64K());
  1.1136 +		return;
  1.1137 +		}
  1.1138 +	if (sourceAlpha==0)// transparent
  1.1139 +		return;
  1.1140 +
  1.1141 +	const TInt sourceRed = aColor.Red();
  1.1142 +	const TInt sourceGreen = aColor.Green();
  1.1143 +	const TInt sourceBlue = aColor.Blue();
  1.1144 +
  1.1145 +	const TInt longWidth = iLongWidth;
  1.1146 +	TUint16* pixelPtr = PixelAddress(aX,aY);
  1.1147 +	TUint16* pixelPtrLimit = pixelPtr + aLength;
  1.1148 +	const TUint16* pixelRowPtrLimit = pixelPtr + (aHeight * longWidth);
  1.1149 +	const TInt mask=aColor.Alpha();
  1.1150 +	const TUint32 srcInternal=aColor.Internal();
  1.1151 +	const TUint32 srcRB=srcInternal & 0x00FF00FF;
  1.1152 +	const TUint32 srcG=(srcInternal & 0xFF00) >> 8;
  1.1153 +	while (pixelPtr < pixelRowPtrLimit)
  1.1154 +		{
  1.1155 +		for (TUint16* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
  1.1156 +			{
  1.1157 +			*tempPixelPtr = BlendTo16(srcRB, srcG, mask, *tempPixelPtr);
  1.1158 +			}
  1.1159 +		pixelPtr += longWidth;
  1.1160 +		pixelPtrLimit += longWidth;
  1.1161 +		}
  1.1162 +	}
  1.1163 +
  1.1164 +void CDrawSixteenBppBitmap::WriteRgbMultiXOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
  1.1165 +	{
  1.1166 +	CDrawSixteenBppBitmapCommon::WriteRgbMultiXOR(aX,aY,aLength,aHeight,(TUint16)aColor._Color64K());
  1.1167 +	}
  1.1168 +
  1.1169 +void CDrawSixteenBppBitmap::WriteRgbMultiAND(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
  1.1170 +	{
  1.1171 +	CDrawSixteenBppBitmapCommon::WriteRgbMultiAND(aX,aY,aLength,aHeight,(TUint16)aColor._Color64K());
  1.1172 +	}
  1.1173 +
  1.1174 +void CDrawSixteenBppBitmap::WriteRgbMultiOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
  1.1175 +	{
  1.1176 +	CDrawSixteenBppBitmapCommon::WriteRgbMultiOR(aX,aY,aLength,aHeight,(TUint16)aColor._Color64K());
  1.1177 +	}
  1.1178 +
  1.1179 +void CDrawSixteenBppBitmap::WriteRgbAlphaMulti(TInt aX,TInt aY,TInt aLength,TRgb aColor,const TUint8* aMaskBuffer)
  1.1180 +	{
  1.1181 +	const TInt alpha = aColor.Alpha();
  1.1182 +	if (alpha==0 || aLength<=0)
  1.1183 +		return;
  1.1184 +	DeOrientate(aX,aY);
  1.1185 +	TUint16* pixelPtr = PixelAddress(aX,aY);
  1.1186 +	const TInt pixelPtrInc = LogicalPixelAddressIncrement();
  1.1187 +	const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
  1.1188 +
  1.1189 + 	if (iShadowMode)
  1.1190 + 		{
  1.1191 + 		Shadow(aColor);
  1.1192 + 		}
  1.1193 + 
  1.1194 +	if (iScalingOff)
  1.1195 +		{
  1.1196 +	    const TUint32 color16bpp=aColor.Color64K();
  1.1197 +		const TUint32 srcInternal=aColor.Internal();
  1.1198 +		const TUint32 srcRB=srcInternal & 0x00FF00FF;
  1.1199 +		const TUint32 srcG=(srcInternal & 0xFF00) >> 8;
  1.1200 +		if (alpha == 0xff)
  1.1201 +			{
  1.1202 +			while (aMaskBuffer < maskBufferPtrLimit)
  1.1203 +				{
  1.1204 +				const TUint32 mask=*aMaskBuffer++;
  1.1205 +				if (mask)
  1.1206 +					{
  1.1207 +					if (mask==0xFF)
  1.1208 +						*pixelPtr = color16bpp;
  1.1209 +					else
  1.1210 +						*pixelPtr = BlendTo16(srcRB, srcG, mask, *pixelPtr);
  1.1211 +					}
  1.1212 +				pixelPtr += pixelPtrInc;
  1.1213 +				}
  1.1214 +			}
  1.1215 +		else
  1.1216 +			{ // pen is semi-transparent, so we must blend using both the mask and pen alpha
  1.1217 +			while (aMaskBuffer < maskBufferPtrLimit)
  1.1218 +				{
  1.1219 +				TUint blendAlpha = alpha;
  1.1220 +				TUint maskAlpha = *aMaskBuffer++;
  1.1221 +				if (maskAlpha)
  1.1222 +					{
  1.1223 +					if (maskAlpha!=0xFF)
  1.1224 +						blendAlpha=((maskAlpha+1) * alpha)>>8;
  1.1225 +					*pixelPtr = BlendTo16(srcRB, srcG, blendAlpha, *pixelPtr);
  1.1226 +					}
  1.1227 +				pixelPtr += pixelPtrInc;
  1.1228 +				}
  1.1229 +			}
  1.1230 +		}
  1.1231 +	else
  1.1232 +		{
  1.1233 +		const TInt red = aColor.Red();
  1.1234 +		const TInt green = aColor.Green();
  1.1235 +		const TInt blue = aColor.Blue();
  1.1236 +		if (alpha == 0xff)
  1.1237 +			{
  1.1238 +			const TUint16* bitsStart = reinterpret_cast <const TUint16*> (iBits);
  1.1239 +			const TUint16* bitsEnd = bitsStart + iLongWidth * iSize.iHeight;
  1.1240 +			while(aMaskBuffer < maskBufferPtrLimit)
  1.1241 +				{
  1.1242 +				TUint16 pixelColor = AlphaBlend(red,green,blue, *pixelPtr, *aMaskBuffer);
  1.1243 +				const TUint16* pixelRowPtrLimit = bitsStart + (aY + 1) * iLongWidth;
  1.1244 +				SetPixels(pixelPtr, pixelColor, pixelRowPtrLimit, bitsStart, bitsEnd);
  1.1245 +				pixelPtr += pixelPtrInc;
  1.1246 +				aMaskBuffer++;
  1.1247 +				IncScaledY(aY);
  1.1248 +				}
  1.1249 +			}
  1.1250 +		else
  1.1251 +			{ // require special handling for different alpha values
  1.1252 +			const TUint16* bitsStart = reinterpret_cast <const TUint16*> (iBits);
  1.1253 +			const TUint16* bitsEnd = bitsStart + iLongWidth * iSize.iHeight;
  1.1254 +			while(aMaskBuffer < maskBufferPtrLimit)
  1.1255 +				{
  1.1256 +				const TInt maskAlpha = *aMaskBuffer;
  1.1257 +				const TInt sourceAlpha = alpha * maskAlpha;
  1.1258 +				const TInt inverseAlpha = 255*255 - sourceAlpha;
  1.1259 +
  1.1260 +				TInt pixelRed;
  1.1261 +				TInt pixelGreen;
  1.1262 +				TInt pixelBlue;
  1.1263 +				UnpackColor64K(*pixelPtr, pixelRed, pixelGreen, pixelBlue);
  1.1264 +				TInt blueAfter = TUint8(((blue * sourceAlpha) + (pixelBlue * inverseAlpha)) / (255*255));
  1.1265 +				TInt greenAfter = TUint8(((green * sourceAlpha) + (pixelGreen * inverseAlpha)) / (255*255));
  1.1266 +				TInt redAfter = TUint8(((red * sourceAlpha) + (pixelRed * inverseAlpha)) / (255*255));
  1.1267 +				TUint16 pixelColor = PackColor64K(redAfter, greenAfter, blueAfter);
  1.1268 +
  1.1269 +				const TUint16* pixelRowPtrLimit = bitsStart + (aY + 1) * iLongWidth;
  1.1270 +				SetPixels(pixelPtr, pixelColor, pixelRowPtrLimit, bitsStart, bitsEnd);
  1.1271 +				pixelPtr += pixelPtrInc;
  1.1272 +				aMaskBuffer++;
  1.1273 +				IncScaledY(aY);
  1.1274 +				}
  1.1275 +			}
  1.1276 +		}
  1.1277 +	}
  1.1278 +
  1.1279 +void CDrawSixteenBppBitmap::MapColorToUserDisplayMode(TRgb& aColor)
  1.1280 +	{
  1.1281 +	switch (iUserDispMode)
  1.1282 +		{
  1.1283 +	case EGray2:
  1.1284 +		aColor = TRgb::_Gray2(aColor._Gray2());
  1.1285 +		break;
  1.1286 +	case EGray4:
  1.1287 +		aColor = TRgb::_Gray4(aColor._Gray4());
  1.1288 +		break;
  1.1289 +	case EGray16:
  1.1290 +		aColor = TRgb::_Gray16(aColor._Gray16());
  1.1291 +		break;
  1.1292 +	case EGray256:
  1.1293 +		aColor = TRgb::_Gray256(aColor._Gray256());
  1.1294 +		break;
  1.1295 +	case EColor16:
  1.1296 +		aColor = TRgb::Color16(aColor.Color16());
  1.1297 +		break;
  1.1298 +	case EColor256:
  1.1299 +		aColor = TRgb::Color256(aColor.Color256());
  1.1300 +		break;
  1.1301 +	case EColor4K:
  1.1302 +		aColor = TRgb::_Color4K(aColor._Color4K());
  1.1303 +		break;
  1.1304 +	default:
  1.1305 +		break;
  1.1306 +		}
  1.1307 +	}
  1.1308 +
  1.1309 +/**
  1.1310 +The overloaded function for MapColorToUserDisplayMode(TRgb) which works directly with
  1.1311 +16 bit colour instead of TRgb to increase the performance.
  1.1312 +@param a64KColor The 16 bit colour value.
  1.1313 +*/
  1.1314 +void CDrawSixteenBppBitmap::MapColorToUserDisplayMode(TUint16& aColor64K)
  1.1315 +	{
  1.1316 +	TRgb color = TRgb::_Color64K(aColor64K);
  1.1317 +
  1.1318 +	switch (iUserDispMode)
  1.1319 +		{
  1.1320 +	case EGray2:
  1.1321 +		{
  1.1322 +		color = TRgb::_Gray2(color._Gray2());
  1.1323 +		}
  1.1324 +		break;
  1.1325 +	case EGray4:
  1.1326 +		{
  1.1327 +		color = TRgb::_Gray4(color._Gray4());
  1.1328 +		}
  1.1329 +		break;
  1.1330 +	case EGray16:
  1.1331 +		{
  1.1332 +		color = TRgb::_Gray16(color._Gray16());
  1.1333 +		}
  1.1334 +		break;
  1.1335 +	case EGray256:
  1.1336 +		{
  1.1337 +		color = TRgb::_Gray256(color._Gray256());
  1.1338 +		}
  1.1339 +		break;
  1.1340 +	case EColor16:
  1.1341 +		{
  1.1342 +		color = TRgb::Color16(color.Color16());
  1.1343 +		}
  1.1344 +		break;
  1.1345 +	case EColor256:
  1.1346 +		{
  1.1347 +		color = TRgb::Color256(color.Color256());
  1.1348 +		}
  1.1349 +		break;
  1.1350 +	case EColor4K:
  1.1351 +		{
  1.1352 +		color = TRgb::_Color4K(color._Color4K());
  1.1353 +		}
  1.1354 +		break;
  1.1355 +	default:
  1.1356 +		break;
  1.1357 +		}
  1.1358 +	aColor64K = color._Color64K();
  1.1359 +	}
  1.1360 +
  1.1361 +void CDrawSixteenBppBitmap::MapBufferToUserDisplayMode(TInt aLength,TUint32* aBuffer)
  1.1362 +	{
  1.1363 +	TUint16* bufferPtr = (TUint16*)aBuffer;
  1.1364 +	const TUint16* bufferLimit = bufferPtr + aLength;
  1.1365 +	TRgb color;
  1.1366 +	
  1.1367 +	switch (iUserDispMode)
  1.1368 +		{
  1.1369 +	case EGray2:
  1.1370 +		while (bufferPtr < bufferLimit)
  1.1371 +			{
  1.1372 +			color = TRgb::_Color64K(*bufferPtr);
  1.1373 +			color = TRgb::_Gray2(color._Gray2());
  1.1374 +			*bufferPtr++ = TUint16(color._Color64K());
  1.1375 +			}
  1.1376 +		break;
  1.1377 +	case EGray4:
  1.1378 +		while (bufferPtr < bufferLimit)
  1.1379 +			{
  1.1380 +			color = TRgb::_Color64K(*bufferPtr);
  1.1381 +			color = TRgb::_Gray4(color._Gray4());
  1.1382 +			*bufferPtr++ = TUint16(color._Color64K());
  1.1383 +			}
  1.1384 +		break;
  1.1385 +	case EGray16:
  1.1386 +		while (bufferPtr < bufferLimit)
  1.1387 +			{
  1.1388 +			color = TRgb::_Color64K(*bufferPtr);
  1.1389 +			color = TRgb::_Gray16(color._Gray16());
  1.1390 +			*bufferPtr++ = TUint16(color._Color64K());
  1.1391 +			}
  1.1392 +		break;
  1.1393 +	case EGray256:
  1.1394 +		while (bufferPtr < bufferLimit)
  1.1395 +			{
  1.1396 +			color = TRgb::_Color64K(*bufferPtr);
  1.1397 +			color = TRgb::_Gray256(color._Gray256());
  1.1398 +			*bufferPtr++ = TUint16(color._Color64K());
  1.1399 +			}
  1.1400 +		break;
  1.1401 +	case EColor16:
  1.1402 +		while (bufferPtr < bufferLimit)
  1.1403 +			{
  1.1404 +			color = TRgb::_Color64K(*bufferPtr);
  1.1405 +			color = TRgb::Color16(color.Color16());
  1.1406 +			*bufferPtr++ = TUint16(color._Color64K());
  1.1407 +			}
  1.1408 +		break;
  1.1409 +	case EColor256:
  1.1410 +		while (bufferPtr < bufferLimit)
  1.1411 +			{
  1.1412 +			color = TRgb::_Color64K(*bufferPtr);
  1.1413 +			color = TRgb::Color256(color.Color256());
  1.1414 +			*bufferPtr++ = TUint16(color._Color64K());
  1.1415 +			}
  1.1416 +		break;
  1.1417 +	case EColor4K:
  1.1418 +		while (bufferPtr < bufferLimit)
  1.1419 +			{
  1.1420 +			color = TRgb::_Color64K(*bufferPtr);
  1.1421 +			color = TRgb::_Color4K(color._Color4K());
  1.1422 +			*bufferPtr++ = TUint16(color._Color64K());
  1.1423 +			}
  1.1424 +		break;
  1.1425 +	default:
  1.1426 +		break;
  1.1427 +		}
  1.1428 +	}
  1.1429 +
  1.1430 +TInt CDrawSixteenBppBitmap::WriteRgbOutlineAndShadow(TInt aX, TInt aY, const TInt aLength, 
  1.1431 +													TUint32 aOutlinePenColor, TUint32 aShadowColor,
  1.1432 +													TUint32 aFillColor, const TUint8* aDataBuffer)
  1.1433 +	{
  1.1434 +	DeOrientate(aX,aY);
  1.1435 +	TUint16* pixelPtr = PixelAddress(aX,aY);
  1.1436 +	const TInt pixelPtrInc = LogicalPixelAddressIncrement();
  1.1437 +	const TUint8* dataBufferPtrLimit = aDataBuffer + aLength;	
  1.1438 +	TInt blendedRedColor;
  1.1439 +	TInt blendedGreenColor;
  1.1440 +	TInt blendedBlueColor;
  1.1441 +	TUint blendedAlpha;
  1.1442 +	TUint32 finalColor;
  1.1443 +	const TUint16* normTable = PtrTo16BitNormalisationTable();
  1.1444 +
  1.1445 +	//Get red color. Equivalent to TRgb::Red()
  1.1446 +	const TInt redOutlinePenColor = (aOutlinePenColor & 0xff0000) >> 16;
  1.1447 +	const TInt redShadowColor = (aShadowColor & 0xff0000) >> 16;
  1.1448 +	const TInt redFillColor = (aFillColor & 0xff0000) >> 16;
  1.1449 +
  1.1450 +	//Get green color. Equivalent to TRgb::Green()
  1.1451 +	const TInt greenOutlinePenColor = (aOutlinePenColor & 0xff00) >> 8;
  1.1452 +	const TInt greenShadowColor = (aShadowColor & 0xff00) >> 8;
  1.1453 +	const TInt greenFillColor = (aFillColor & 0xff00) >> 8;
  1.1454 +
  1.1455 +	//Get blue color. Equivalent to TRgb::Blue()
  1.1456 +	const TInt blueOutlinePenColor = aOutlinePenColor & 0xff;
  1.1457 +	const TInt blueShadowColor = aShadowColor & 0xff;
  1.1458 +	const TInt blueFillColor = aFillColor & 0xff;
  1.1459 +
  1.1460 +	//Get alpha color. Equivalent to TRgb::Alpha()
  1.1461 +	const TUint alphaOutlinePenColor = aOutlinePenColor >> 24;
  1.1462 +	const TUint alphaShadowColor = aShadowColor >> 24;
  1.1463 +	const TUint alphaFillColor = aFillColor >> 24;
  1.1464 +
  1.1465 +	while (aDataBuffer < dataBufferPtrLimit)
  1.1466 +		{
  1.1467 +		TUint8 index = *aDataBuffer++;
  1.1468 +		if (255 == FourColorBlendLookup[index][KBackgroundColorIndex])
  1.1469 +			{
  1.1470 +			//background colour
  1.1471 +			//No drawing required
  1.1472 +			}
  1.1473 +		else if (255 == FourColorBlendLookup[index][KFillColorIndex])
  1.1474 +			{
  1.1475 +			//Use fill colour to draw
  1.1476 +			finalColor = aFillColor;
  1.1477 +			*pixelPtr = Blend32To16((finalColor | 0xff000000), alphaFillColor, *pixelPtr);
  1.1478 +			}
  1.1479 +		else if (255 == FourColorBlendLookup[index][KShadowColorIndex])
  1.1480 +			{
  1.1481 +			//Use shadow colour to draw
  1.1482 +			finalColor = aShadowColor;
  1.1483 +			*pixelPtr = Blend32To16((finalColor | 0xff000000), alphaShadowColor, *pixelPtr);
  1.1484 +			}
  1.1485 +		else if (255 == FourColorBlendLookup[index][KOutlineColorIndex])
  1.1486 +			{
  1.1487 +			//Use outline colour to draw
  1.1488 +			finalColor = aOutlinePenColor; 
  1.1489 +			*pixelPtr = Blend32To16((finalColor | 0xff000000), alphaOutlinePenColor, *pixelPtr);
  1.1490 +			}
  1.1491 +		else
  1.1492 +			{
  1.1493 +			//Get the background pixel colour. Using the lookup table to convert 16 to 32 bit colour
  1.1494 +			blendedRedColor = (redOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] * alphaOutlinePenColor + 
  1.1495 +								redShadowColor * FourColorBlendLookup[index][KShadowColorIndex] * alphaShadowColor +
  1.1496 +								redFillColor * FourColorBlendLookup[index][KFillColorIndex] * alphaFillColor) >> 16;
  1.1497 +	
  1.1498 +			blendedGreenColor = (greenOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] * alphaOutlinePenColor  + 
  1.1499 +								greenShadowColor * FourColorBlendLookup[index][KShadowColorIndex] * alphaShadowColor +
  1.1500 +								greenFillColor * FourColorBlendLookup[index][KFillColorIndex] * alphaFillColor) >> 16;
  1.1501 +	
  1.1502 +			blendedBlueColor = (blueOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] * alphaOutlinePenColor  + 
  1.1503 +								blueShadowColor * FourColorBlendLookup[index][KShadowColorIndex] * alphaShadowColor +
  1.1504 +								blueFillColor * FourColorBlendLookup[index][KFillColorIndex] * alphaFillColor) >> 16;
  1.1505 +	
  1.1506 +			blendedAlpha = (alphaOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] + 
  1.1507 +							alphaShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
  1.1508 +							alphaFillColor * FourColorBlendLookup[index][KFillColorIndex]) >> 8;
  1.1509 +
  1.1510 +			finalColor = PMA2NonPMAPixel((blendedAlpha << 24) | (blendedRedColor << 16) | (blendedGreenColor << 8) | blendedBlueColor, normTable);		
  1.1511 +			*pixelPtr = Blend32To16((finalColor | 0xff000000), blendedAlpha, *pixelPtr);
  1.1512 +			}
  1.1513 +		pixelPtr += pixelPtrInc;
  1.1514 +		}
  1.1515 +	return KErrNone;
  1.1516 +	}