os/graphics/graphicsdeviceinterface/screendriver/sbit/BMDRAW4M.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "BMDRAW.H"
sl@0
    17
sl@0
    18
GLREF_D const TUint8 ditherlutab[16][4];
sl@0
    19
GLREF_D const TUint8 shadowlutab[256];
sl@0
    20
sl@0
    21
const TInt KPixelsPerWord = 8;
sl@0
    22
const TInt KPixelsPerByte = 2;
sl@0
    23
const TInt KBitsPerPixel = 4;
sl@0
    24
sl@0
    25
// CDrawFourBppBitmapGray
sl@0
    26
sl@0
    27
//Initializes iSize, iDrawRect, iLongWidth, iScanlineWords data members.
sl@0
    28
//It should be called every time when iSize is going to be changed - from Construct().
sl@0
    29
//@param aSize Physical screen size in pixels.
sl@0
    30
//@panic EScreenDriverPanicInvalidSize - Invalid aSize parameter. This might happen if the 
sl@0
    31
//device is scaled and the scaling origin goes outside physical drawing rectangle.
sl@0
    32
void CDrawFourBppBitmapGray::SetSize(const TSize& aSize) 
sl@0
    33
	{
sl@0
    34
	CDrawBitmap::SetSize(aSize);
sl@0
    35
	__ASSERT_DEBUG(iSize == aSize, User::Invariant());
sl@0
    36
	iLongWidth = (iSize.iWidth + (KPixelsPerWord - 1)) & ~(KPixelsPerWord - 1);
sl@0
    37
	iScanLineWords = iLongWidth / KPixelsPerWord;
sl@0
    38
	}
sl@0
    39
 
sl@0
    40
TInt CDrawFourBppBitmapGray::Construct(TSize aSize)
sl@0
    41
	{
sl@0
    42
	return Construct(aSize, ((aSize.iWidth + (KPixelsPerWord - 1)) & ~(KPixelsPerWord - 1)) / KPixelsPerByte);
sl@0
    43
	}
sl@0
    44
sl@0
    45
TInt CDrawFourBppBitmapGray::Construct(TSize aSize, TInt aStride)
sl@0
    46
	{
sl@0
    47
	iBits = NULL;
sl@0
    48
	iDispMode = EGray16;
sl@0
    49
	CDrawBitmap::SetSize(aSize);
sl@0
    50
	__ASSERT_DEBUG(iSize == aSize, User::Invariant());
sl@0
    51
	if (aStride & 3)
sl@0
    52
		return KErrArgument;
sl@0
    53
	iLongWidth = aStride * KPixelsPerByte;
sl@0
    54
	if (iLongWidth < aSize.iWidth)
sl@0
    55
		return KErrArgument;
sl@0
    56
	iScanLineWords = aStride >> 2;
sl@0
    57
	TInt size = 1 + (Max(aSize.iWidth,aSize.iHeight) >> 1);
sl@0
    58
	if(size < 0)
sl@0
    59
		return KErrArgument;
sl@0
    60
	iScanLineBuffer = (TUint32*)(User::Heap().Alloc(size));
sl@0
    61
	if (iScanLineBuffer == NULL)
sl@0
    62
		return KErrNoMemory;
sl@0
    63
	return KErrNone;
sl@0
    64
	}
sl@0
    65
sl@0
    66
void CDrawFourBppBitmapGray::Shadow(TRgb& aColor)
sl@0
    67
	{
sl@0
    68
	aColor = TRgb::_Gray16(ShadowAndFadeGray16(aColor._Gray16()));
sl@0
    69
	}
sl@0
    70
sl@0
    71
TUint8 CDrawFourBppBitmapGray::ShadowAndFadeGray16(TInt aGray16)
sl@0
    72
	{
sl@0
    73
	if (iShadowMode & EFade)
sl@0
    74
		aGray16 = FadeGray(aGray16 * 17) >> 4;
sl@0
    75
sl@0
    76
	if (iShadowMode & EShadow)
sl@0
    77
		aGray16 = Max(aGray16 - 5,0);
sl@0
    78
sl@0
    79
	return (TUint8)aGray16;
sl@0
    80
	}
sl@0
    81
sl@0
    82
TUint32 CDrawFourBppBitmapGray::FadeWord(TUint32 aWord)
sl@0
    83
	{
sl@0
    84
	TUint32 fadedWord = 0;
sl@0
    85
sl@0
    86
	for (TInt bitShift = 0; bitShift < 32; bitShift += 4)
sl@0
    87
		{
sl@0
    88
		TInt gray = (aWord >> bitShift) & 0xf;
sl@0
    89
		gray = FadeGray(gray * 17) >> 4;
sl@0
    90
		fadedWord |= gray << bitShift;
sl@0
    91
		}
sl@0
    92
sl@0
    93
	return fadedWord;
sl@0
    94
	}
sl@0
    95
sl@0
    96
TUint32 CDrawFourBppBitmapGray::ColorInt(TRgb aColor) const
sl@0
    97
	{
sl@0
    98
	TUint32 colorWord = aColor._Gray16();
sl@0
    99
sl@0
   100
	colorWord |= colorWord << 4;
sl@0
   101
	colorWord |= colorWord << 8;
sl@0
   102
	colorWord |= colorWord << 16;
sl@0
   103
sl@0
   104
	return colorWord;
sl@0
   105
	}
sl@0
   106
sl@0
   107
void CDrawFourBppBitmapGray::DitherBuffer(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
sl@0
   108
	{
sl@0
   109
	aX += iDitherOrigin.iX;
sl@0
   110
	aY += iDitherOrigin.iY;
sl@0
   111
	aX &= 1;
sl@0
   112
	aY &= 1;
sl@0
   113
	aY <<= 1;
sl@0
   114
sl@0
   115
	const TInt first = aX + aY;
sl@0
   116
	aX ^= 1;
sl@0
   117
	const TInt second = aX + aY;
sl@0
   118
sl@0
   119
	TUint8* bufferPtr = (TUint8*)aBuffer;
sl@0
   120
	const TUint8* bufferLimit = bufferPtr + ((aLength + 1) / 2);
sl@0
   121
sl@0
   122
	for (; bufferPtr < bufferLimit; bufferPtr++)
sl@0
   123
		{
sl@0
   124
		TUint8 index1 = bufferPtr[0];
sl@0
   125
		TUint8 index2 = TUint8(index1 >> 4);
sl@0
   126
		index1 &= 0xf;
sl@0
   127
sl@0
   128
		const TUint8 value1 = ditherlutab[index1][first];
sl@0
   129
		const TUint8 value2 = ditherlutab[index2][second];
sl@0
   130
		bufferPtr[0] = TUint8(value1 | (value2 << 4));
sl@0
   131
		}
sl@0
   132
	}
sl@0
   133
sl@0
   134
TUint32 CDrawFourBppBitmapGray::HashInt(TRgb aColor,TInt aX,TInt aY) const
sl@0
   135
	{
sl@0
   136
	const TUint32 gray = aColor._Gray16();
sl@0
   137
	const TUint32 int1 = Hash(gray,aX,aY);
sl@0
   138
	const TUint32 int2 = Hash(gray,aX + 1,aY);
sl@0
   139
sl@0
   140
	TUint32 colorWord = int1 | (int2 << 4);
sl@0
   141
sl@0
   142
	colorWord |= colorWord << 8;
sl@0
   143
	colorWord |= colorWord << 16;
sl@0
   144
sl@0
   145
	return colorWord;
sl@0
   146
	}
sl@0
   147
sl@0
   148
void CDrawFourBppBitmapGray::InvertBuffer(TInt aLength,TUint32* aBuffer)
sl@0
   149
	{
sl@0
   150
	const TUint32* bufferLimit = aBuffer + ((aLength + KPixelsPerWord - 1) / KPixelsPerWord);
sl@0
   151
sl@0
   152
	while (aBuffer < bufferLimit)
sl@0
   153
		*aBuffer++ ^= 0xffffffff;
sl@0
   154
	}
sl@0
   155
sl@0
   156
/**	Copies a number of pixels into a word-aligned buffer without format translation.
sl@0
   157
	Note that the byte length to the target buffer is honoured, 
sl@0
   158
 	but the end contents of the last byte are generally overwritten with extra pixel data (or garbage).
sl@0
   159
 	Note that I am assuming the compiler optimiser will convert all these divides and multiplies into shifts!  
sl@0
   160
@param	aX		x coordinate to start copy from (need not be aligned at all)
sl@0
   161
@param	aY		y coordinate to copy line from	
sl@0
   162
@param	aLength	number of pixels to copy  
sl@0
   163
@param	aBuffer	target word-aligned buffer (but may or may not be word length) 
sl@0
   164
 **/
sl@0
   165
void CDrawFourBppBitmapGray::ReadLine(TInt aX,TInt aY,TInt aLength,TAny* aBuffer) const
sl@0
   166
	{
sl@0
   167
	TUint32* pixelPtr = ScanLine(aY);
sl@0
   168
	TInt startLongPix = aX & -KPixelsPerWord;
sl@0
   169
	pixelPtr += startLongPix / KPixelsPerWord;
sl@0
   170
	TUint32* bufferPtr = (TUint32*)aBuffer;
sl@0
   171
	TInt wordsCnt = (aLength+KPixelsPerByte-1) / KPixelsPerWord;		//how many words to write to target
sl@0
   172
	TInt restPixels = aLength - wordsCnt * KPixelsPerWord;				//how many pixels left to copy
sl@0
   173
	TInt bytesCnt = (restPixels+KPixelsPerByte-1) / KPixelsPerByte ;	//how many target bytes to copy
sl@0
   174
	TInt shiftBits = aX - startLongPix;
sl@0
   175
	restPixels=shiftBits+restPixels;	//How many pixels are read from the second word by the final word copy
sl@0
   176
	if (bytesCnt==0 && shiftBits && restPixels<=0)
sl@0
   177
		{
sl@0
   178
		// This correction is required because although a last whole word will be written to the target buffer,
sl@0
   179
		// this special test indicates that the required significant data bits plus the shift 
sl@0
   180
		// add up to one word (or less) to be read. 
sl@0
   181
		// The copy words optimisation used to copy the main body of the line 
sl@0
   182
		// will read from the next location after the copy, 
sl@0
   183
		// but this may not always be accessable memory (on the last scanline)
sl@0
   184
		// The correction is not required if the second word would need to be read anyway.
sl@0
   185
		//eg we want to copy 7 nibbles with a 1 nibble shift (16 color), restpixels would be 0
sl@0
   186
		bytesCnt=4;
sl@0
   187
		wordsCnt--;
sl@0
   188
		}
sl@0
   189
	//How many pixels are read from the second word in the final byte copy?
sl@0
   190
	//If zero (or less) then the second word should not be read in the copy bytes phase
sl@0
   191
	//really this should be an else of the if above, but this gives the same end condition.
sl@0
   192
	//eg we want to copy 5 nibbles with a 2 nibble shift (16 color), restpixels would be -1.
sl@0
   193
	restPixels-=KPixelsPerWord;	
sl@0
   194
	ReadLineCommon(pixelPtr,bufferPtr,wordsCnt,restPixels,bytesCnt,shiftBits*KBitsPerPixel);
sl@0
   195
	}
sl@0
   196
sl@0
   197
sl@0
   198
TRgb CDrawFourBppBitmapGray::ReadRgbNormal(TInt aX,TInt aY) const
sl@0
   199
	{
sl@0
   200
	TUint32 colorWord = *(ScanLine(aY) + (aX / KPixelsPerWord));
sl@0
   201
	colorWord >>= ((aX & 7) * KBitsPerPixel);
sl@0
   202
	return TRgb::_Gray16(colorWord & 0xf);
sl@0
   203
	}
sl@0
   204
sl@0
   205
void CDrawFourBppBitmapGray::ShadowArea(const TRect& aRect)
sl@0
   206
	{
sl@0
   207
	__ASSERT_DEBUG(aRect.iTl.iX>=0 && aRect.iBr.iX<=iSize.iWidth,Panic(EScreenDriverPanicOutOfBounds));
sl@0
   208
	__ASSERT_DEBUG(aRect.iTl.iY>=0 && aRect.iBr.iY<=iSize.iHeight,Panic(EScreenDriverPanicOutOfBounds));
sl@0
   209
sl@0
   210
	TInt startLong = (aRect.iTl.iX + KPixelsPerWord - 1) & ~7;
sl@0
   211
	TInt finishLong = aRect.iBr.iX & ~7;
sl@0
   212
	TInt startShift = (startLong - aRect.iTl.iX) * KBitsPerPixel;
sl@0
   213
	TInt finishShift = (KPixelsPerWord - aRect.iBr.iX + finishLong) * KBitsPerPixel;
sl@0
   214
	TInt startLongAdjust = startLong / KPixelsPerWord;
sl@0
   215
	TInt finishLongAdjust = finishLong / KPixelsPerWord;
sl@0
   216
	TUint32* base = ScanLine(aRect.iTl.iY);
sl@0
   217
sl@0
   218
	if (iShadowMode & EFade)
sl@0
   219
		{
sl@0
   220
		TUint32* pixelPtr = base + startLongAdjust;
sl@0
   221
		TUint32* pixelPtrLimit = base + finishLongAdjust;
sl@0
   222
sl@0
   223
		if (finishLong < startLong)
sl@0
   224
			{
sl@0
   225
			const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << (32 - startShift));
sl@0
   226
			const TUint32 invertedMask = ~mask;
sl@0
   227
sl@0
   228
			for (TInt y = aRect.iTl.iY; y < aRect.iBr.iY; y++)
sl@0
   229
				{
sl@0
   230
				TUint32 shadowed = FadeWord(pixelPtrLimit[0]) & mask;
sl@0
   231
				pixelPtrLimit[0] &= invertedMask;
sl@0
   232
				pixelPtrLimit[0] |= shadowed;
sl@0
   233
				pixelPtrLimit += iScanLineWords;
sl@0
   234
				}
sl@0
   235
			}
sl@0
   236
		else
sl@0
   237
			{
sl@0
   238
			for (TInt y = aRect.iTl.iY; y < aRect.iBr.iY; y++)
sl@0
   239
				{
sl@0
   240
				if (aRect.iTl.iX < startLong)
sl@0
   241
					{
sl@0
   242
					TUint32 shadowed = FadeWord(pixelPtr[-1]);
sl@0
   243
					pixelPtr[-1] = PasteInt(pixelPtr[-1],shadowed,startShift);
sl@0
   244
					}
sl@0
   245
sl@0
   246
				for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
sl@0
   247
					tempPixelPtr[0] = FadeWord(tempPixelPtr[0]);
sl@0
   248
sl@0
   249
				if (finishLong < aRect.iBr.iX)
sl@0
   250
					{
sl@0
   251
					TUint32 shadowed = FadeWord(pixelPtrLimit[0]);
sl@0
   252
					pixelPtrLimit[0] = PasteInt(shadowed,pixelPtrLimit[0],finishShift);
sl@0
   253
					}
sl@0
   254
sl@0
   255
				pixelPtr += iScanLineWords;
sl@0
   256
				pixelPtrLimit += iScanLineWords;
sl@0
   257
				}
sl@0
   258
			}
sl@0
   259
		}
sl@0
   260
sl@0
   261
	if (iShadowMode & EShadow)
sl@0
   262
		{
sl@0
   263
		if (iUserDispMode == EGray2)
sl@0
   264
			{
sl@0
   265
			WriteRgbMulti(aRect.iTl.iX,aRect.iTl.iY,aRect.Width(),aRect.Height(),KRgbBlack);
sl@0
   266
			return;
sl@0
   267
			}
sl@0
   268
sl@0
   269
		TUint32* pixelPtr = base + startLongAdjust;
sl@0
   270
		TUint32* pixelPtrLimit = base + finishLongAdjust;
sl@0
   271
sl@0
   272
		if (finishLong < startLong)
sl@0
   273
			{
sl@0
   274
			const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << (32 - startShift));
sl@0
   275
			const TUint32 invertedMask = ~mask;
sl@0
   276
sl@0
   277
			for (TInt y = aRect.iTl.iY; y < aRect.iBr.iY; y++)
sl@0
   278
				{
sl@0
   279
				TUint32 shadowed = shadowlutab[pixelPtrLimit[0] & 0xff];
sl@0
   280
				shadowed |= (shadowlutab[(pixelPtrLimit[0] >> 8) & 0xff] << 8);
sl@0
   281
				shadowed |= (shadowlutab[(pixelPtrLimit[0] >> 16) & 0xff] << 16);
sl@0
   282
				shadowed |= (shadowlutab[(pixelPtrLimit[0] >> 24) & 0xff] << 24);
sl@0
   283
sl@0
   284
				pixelPtrLimit[0] &= invertedMask;
sl@0
   285
				pixelPtrLimit[0] |= (shadowed & mask);
sl@0
   286
				pixelPtrLimit += iScanLineWords;
sl@0
   287
				}
sl@0
   288
			}
sl@0
   289
		else
sl@0
   290
			{
sl@0
   291
			for (TInt y = aRect.iTl.iY; y < aRect.iBr.iY; y++)
sl@0
   292
				{
sl@0
   293
				if (aRect.iTl.iX < startLong)
sl@0
   294
					{
sl@0
   295
					TUint32 shadowed = shadowlutab[pixelPtr[-1] & 0xff];
sl@0
   296
					shadowed |= (shadowlutab[(pixelPtr[-1] >> 8) & 0xff] << 8);
sl@0
   297
					shadowed |= (shadowlutab[(pixelPtr[-1] >> 16) & 0xff] << 16);
sl@0
   298
					shadowed |= (shadowlutab[(pixelPtr[-1] >> 24) & 0xff] << 24);
sl@0
   299
					pixelPtr[-1] = PasteInt(pixelPtr[-1],shadowed,startShift);
sl@0
   300
					}
sl@0
   301
sl@0
   302
				for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
sl@0
   303
					{
sl@0
   304
					TUint32 shadowed = shadowlutab[tempPixelPtr[0] & 0xff];
sl@0
   305
					shadowed |= (shadowlutab[(tempPixelPtr[0] >> 8) & 0xff] << 8);
sl@0
   306
					shadowed |= (shadowlutab[(tempPixelPtr[0] >> 16) & 0xff] << 16);
sl@0
   307
					shadowed |= (shadowlutab[(tempPixelPtr[0] >> 24) & 0xff] << 24);
sl@0
   308
					tempPixelPtr[0] = shadowed;
sl@0
   309
					}
sl@0
   310
sl@0
   311
				if (finishLong < aRect.iBr.iX)
sl@0
   312
					{
sl@0
   313
					TUint32 shadowed = shadowlutab[pixelPtrLimit[0] & 0xff];
sl@0
   314
					shadowed |= (shadowlutab[(pixelPtrLimit[0] >> 8) & 0xff] << 8);
sl@0
   315
					shadowed |= (shadowlutab[(pixelPtrLimit[0] >> 16) & 0xff] << 16);
sl@0
   316
					shadowed |= (shadowlutab[(pixelPtrLimit[0] >> 24) & 0xff] << 24);
sl@0
   317
					pixelPtrLimit[0] = PasteInt(shadowed,pixelPtrLimit[0],finishShift);
sl@0
   318
					}
sl@0
   319
sl@0
   320
				pixelPtr += iScanLineWords;
sl@0
   321
				pixelPtrLimit += iScanLineWords;
sl@0
   322
				}
sl@0
   323
			}
sl@0
   324
		}
sl@0
   325
	}
sl@0
   326
sl@0
   327
void CDrawFourBppBitmapGray::ShadeBuffer(TInt aLength,TUint32* aBuffer)
sl@0
   328
	{
sl@0
   329
	__ASSERT_DEBUG(aBuffer != NULL,Panic(EScreenDriverPanicInvalidParameter));
sl@0
   330
sl@0
   331
	const TUint32* bufferLimit = aBuffer + ((aLength + KPixelsPerWord - 1) / KPixelsPerWord);
sl@0
   332
sl@0
   333
	while (aBuffer < bufferLimit)
sl@0
   334
		{
sl@0
   335
		TUint32 fourthbit = (0x88888888 & aBuffer[0]);
sl@0
   336
		aBuffer[0] = fourthbit | (fourthbit >> 1);
sl@0
   337
		aBuffer[0] |= aBuffer[0] >> 2;
sl@0
   338
		aBuffer++;
sl@0
   339
		}
sl@0
   340
	}
sl@0
   341
sl@0
   342
void CDrawFourBppBitmapGray::ShadowBuffer(TInt aLength,TUint32* aBuffer)
sl@0
   343
	{
sl@0
   344
	__ASSERT_DEBUG(aBuffer != NULL,Panic(EScreenDriverPanicInvalidParameter));
sl@0
   345
sl@0
   346
	const TUint32* bufferLimit = aBuffer + ((aLength + KPixelsPerWord - 1) / KPixelsPerWord);
sl@0
   347
sl@0
   348
	if (iShadowMode & EFade)
sl@0
   349
		{
sl@0
   350
		for (TUint32* bufferPtr = aBuffer; bufferPtr < bufferLimit; bufferPtr++)
sl@0
   351
			bufferPtr[0] = FadeWord(bufferPtr[0]);
sl@0
   352
		}
sl@0
   353
sl@0
   354
	if (iShadowMode & EShadow)
sl@0
   355
		{
sl@0
   356
		for (TUint32* bufferPtr = aBuffer; bufferPtr < bufferLimit; bufferPtr++)
sl@0
   357
			{
sl@0
   358
			TUint32 bufferWord = bufferPtr[0];
sl@0
   359
sl@0
   360
			TUint firstbyte = shadowlutab[bufferWord & 0xff];
sl@0
   361
			bufferWord >>= 8;
sl@0
   362
			firstbyte |= (shadowlutab[bufferWord & 0xff] << 8);
sl@0
   363
			bufferWord >>= 8;
sl@0
   364
			firstbyte |= (shadowlutab[bufferWord & 0xff] << 16);
sl@0
   365
			bufferWord >>= 8;
sl@0
   366
			firstbyte |= (shadowlutab[bufferWord & 0xff] << 24);
sl@0
   367
sl@0
   368
			bufferPtr[0] = firstbyte;
sl@0
   369
			}
sl@0
   370
		}
sl@0
   371
	}
sl@0
   372
sl@0
   373
void CDrawFourBppBitmapGray::WriteRgb(TInt aX,TInt aY,TRgb aColor)
sl@0
   374
	{
sl@0
   375
	TUint32 colorIndex = aColor._Gray16();
sl@0
   376
sl@0
   377
	if (iUserDispMode == EGray2)
sl@0
   378
		colorIndex = (colorIndex > 7) ? 15 : 0;
sl@0
   379
	else if (iUserDispMode == EGray4)
sl@0
   380
		colorIndex = Hash(colorIndex,aX,aY);
sl@0
   381
sl@0
   382
	TUint32* pixelPtr = ScanLine(aY) + (aX / KPixelsPerWord);
sl@0
   383
	TInt shift = (aX & 7) * KBitsPerPixel;
sl@0
   384
sl@0
   385
	pixelPtr[0] &= ~(0xf << shift);
sl@0
   386
	pixelPtr[0] |= colorIndex << shift;
sl@0
   387
	}
sl@0
   388
sl@0
   389
void CDrawFourBppBitmapGray::WriteBinary(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TRgb aColor)
sl@0
   390
	{
sl@0
   391
	TUint32 color1 = 0;
sl@0
   392
	TUint32 color2 = 0;
sl@0
   393
	const TInt yLimit = aY + aHeight;
sl@0
   394
	const TUint32 gray16 = aColor._Gray16();
sl@0
   395
sl@0
   396
	if (iUserDispMode == EGray2)
sl@0
   397
		{
sl@0
   398
		if (gray16 > 7)
sl@0
   399
			{
sl@0
   400
			color1 = 15;
sl@0
   401
			color2 = 15;
sl@0
   402
			}
sl@0
   403
		}
sl@0
   404
	else if (iUserDispMode != EGray4)
sl@0
   405
		{
sl@0
   406
		color1 = gray16;
sl@0
   407
		color2 = gray16;
sl@0
   408
		}
sl@0
   409
sl@0
   410
	for (; aY < yLimit; aY++,aData++)
sl@0
   411
		{
sl@0
   412
		if (iUserDispMode == EGray4)
sl@0
   413
			{
sl@0
   414
			color1 = Hash(gray16,aX,aY);
sl@0
   415
			color2 = Hash(gray16,aX + 1,aY);
sl@0
   416
			}
sl@0
   417
sl@0
   418
		TUint32 color = color1;
sl@0
   419
		TUint32 dataMask = 1;
sl@0
   420
		const TInt xLimit = aX + aLength;
sl@0
   421
		TUint8* pixelPtr = ((TUint8*)ScanLine(aY)) + (aX / 2);
sl@0
   422
sl@0
   423
		if (color1 || color2)
sl@0
   424
			{
sl@0
   425
			for (TInt x = aX; x < xLimit; x++,dataMask <<= 1)
sl@0
   426
				{
sl@0
   427
				if (aData[0] & dataMask)
sl@0
   428
					{
sl@0
   429
					if(x & 1)
sl@0
   430
						pixelPtr[0] = (TUint8)(color << 4 | (pixelPtr[0] & 0x0f));
sl@0
   431
					else
sl@0
   432
						pixelPtr[0] = (TUint8)(color | (pixelPtr[0] & 0xf0));
sl@0
   433
					}
sl@0
   434
sl@0
   435
				color = (color == color2) ? color1 : color2;
sl@0
   436
				if (x & 1)
sl@0
   437
					pixelPtr++;
sl@0
   438
				}
sl@0
   439
			}
sl@0
   440
		else
sl@0
   441
			{
sl@0
   442
			TUint8 bytemask = TUint8((aX & 1) ? 0x0f : 0xf0);
sl@0
   443
sl@0
   444
			for (TInt x = aX; x < xLimit; x++,dataMask <<= 1,bytemask = (TUint8)~bytemask)
sl@0
   445
				{
sl@0
   446
				if (aData[0] & dataMask)
sl@0
   447
					pixelPtr[0] &= bytemask;
sl@0
   448
sl@0
   449
				if (x & 1)
sl@0
   450
					pixelPtr++;
sl@0
   451
				}
sl@0
   452
			}
sl@0
   453
		}
sl@0
   454
	}
sl@0
   455
sl@0
   456
void CDrawFourBppBitmapGray::WriteBinaryOp(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode)
sl@0
   457
	{
sl@0
   458
	TUint32 color1 = 0;
sl@0
   459
	TUint32 color2 = 0;
sl@0
   460
	const TUint32 gray16 = aColor._Gray16();
sl@0
   461
	const TInt yLimit = aY + aHeight;
sl@0
   462
sl@0
   463
	if (iUserDispMode == EGray2)
sl@0
   464
		{
sl@0
   465
		if (gray16 > 7)
sl@0
   466
			{
sl@0
   467
			color1 = 15;
sl@0
   468
			color2 = 15;
sl@0
   469
			}
sl@0
   470
		}
sl@0
   471
	else if(iUserDispMode != EGray4)
sl@0
   472
		{
sl@0
   473
		color1 = gray16;
sl@0
   474
		color2 = gray16;
sl@0
   475
		}
sl@0
   476
sl@0
   477
	for (; aY < yLimit; aY++)
sl@0
   478
		{
sl@0
   479
		if (iUserDispMode == EGray4)
sl@0
   480
			{
sl@0
   481
			color1 = Hash(gray16,aX,aY);
sl@0
   482
			color2 = Hash(gray16,aX + 1,aY);
sl@0
   483
			}
sl@0
   484
sl@0
   485
		TUint32 color = color1;
sl@0
   486
		TUint32 dataMask = 1;
sl@0
   487
		const TInt xLimit = aX + aLength;
sl@0
   488
		TUint8* pixelPtr = ((TUint8*)ScanLine(aY)) + (aX / 2);
sl@0
   489
sl@0
   490
		if(color1 || color2)
sl@0
   491
			{
sl@0
   492
			for (TInt x = aX; x < xLimit; x++,dataMask <<= 1)
sl@0
   493
				{
sl@0
   494
				if (aData[0] & dataMask)
sl@0
   495
					{
sl@0
   496
					if (x & 1)
sl@0
   497
						{
sl@0
   498
						if (aDrawMode == CGraphicsContext::EDrawModeXOR)
sl@0
   499
							pixelPtr[0] = (TUint8)((color << 4) ^ pixelPtr[0]);
sl@0
   500
						else if (aDrawMode == CGraphicsContext::EDrawModeAND)
sl@0
   501
							pixelPtr[0] = (TUint8)(((color << 4) | 0x0f) & pixelPtr[0]);
sl@0
   502
						else if (aDrawMode==CGraphicsContext::EDrawModeOR)
sl@0
   503
							pixelPtr[0] = (TUint8)((color << 4) | pixelPtr[0]);
sl@0
   504
						}
sl@0
   505
					else
sl@0
   506
						{
sl@0
   507
						if (aDrawMode == CGraphicsContext::EDrawModeXOR)
sl@0
   508
							pixelPtr[0] = (TUint8)(color ^ pixelPtr[0]);
sl@0
   509
						else if (aDrawMode == CGraphicsContext::EDrawModeAND)
sl@0
   510
							pixelPtr[0] = (TUint8)((color | 0xf0) & pixelPtr[0]);
sl@0
   511
						else if (aDrawMode==CGraphicsContext::EDrawModeOR)
sl@0
   512
							pixelPtr[0] = (TUint8)(color | pixelPtr[0]);
sl@0
   513
						}
sl@0
   514
					}
sl@0
   515
sl@0
   516
				color = (color == color2) ? color1 : color2;
sl@0
   517
				if (x & 1)
sl@0
   518
					pixelPtr++;
sl@0
   519
				}
sl@0
   520
			}
sl@0
   521
		else
sl@0
   522
			{
sl@0
   523
			TUint8 bytemask = TUint8((aX & 1) ? 0x0f : 0xf0);
sl@0
   524
sl@0
   525
			if (aDrawMode == CGraphicsContext::EDrawModeAND)
sl@0
   526
				{
sl@0
   527
				for (TInt x = aX; x < xLimit; x++,dataMask <<= 1,bytemask = (TUint8)~bytemask)
sl@0
   528
					{
sl@0
   529
					if (aData[0] & dataMask)
sl@0
   530
						pixelPtr[0] &= bytemask;
sl@0
   531
sl@0
   532
					if (x & 1)
sl@0
   533
						pixelPtr++;
sl@0
   534
					}
sl@0
   535
				}
sl@0
   536
			}
sl@0
   537
sl@0
   538
		aData++;
sl@0
   539
		}
sl@0
   540
	}
sl@0
   541
sl@0
   542
void CDrawFourBppBitmapGray::WriteBinaryLineVertical(TInt aX,TInt aY,TUint32* aData,TInt aLength,TRgb aColor,TBool aUp)
sl@0
   543
	{
sl@0
   544
	if (iUserDispMode == EGray2)
sl@0
   545
		aColor = TRgb::_Gray2(aColor._Gray2());
sl@0
   546
sl@0
   547
	TUint32 color1 = 0;
sl@0
   548
	TUint32 color2 = 0;
sl@0
   549
	const TUint32 gray16 = aColor._Gray16();
sl@0
   550
sl@0
   551
	if (iUserDispMode == EGray4 && gray16 % 5 != 0)
sl@0
   552
		{
sl@0
   553
		color1 = Hash(gray16,aX,aY);
sl@0
   554
		color2 = Hash(gray16,aX,aY + 1);
sl@0
   555
		}
sl@0
   556
	else
sl@0
   557
		color1 = color2 = gray16;
sl@0
   558
sl@0
   559
	const TInt yLimit = aY + (aUp ? -aLength : aLength);
sl@0
   560
	const TInt scanLineWords = aUp ? -iScanLineWords : iScanLineWords;
sl@0
   561
	const TInt startword = aX / KPixelsPerWord;
sl@0
   562
	const TInt startShift = (aX & 7) * KBitsPerPixel;
sl@0
   563
	TUint32* pixelPtr = ScanLine(aY) + startword;
sl@0
   564
	const TUint32* pixelPtrLimit = ScanLine(yLimit) + startword;
sl@0
   565
	const TUint32 mask = ~(0xf << startShift);
sl@0
   566
	TUint32 dataMask = 1;
sl@0
   567
sl@0
   568
	if (color1 || color2)
sl@0
   569
		{
sl@0
   570
		color1 <<= startShift;
sl@0
   571
		color2 <<= startShift;
sl@0
   572
		TUint32 color = color1;
sl@0
   573
sl@0
   574
		while (pixelPtr != pixelPtrLimit)
sl@0
   575
			{
sl@0
   576
			if (!dataMask)
sl@0
   577
				{
sl@0
   578
				dataMask = 1;
sl@0
   579
				aData++;
sl@0
   580
				}
sl@0
   581
sl@0
   582
			if (aData[0] & dataMask)
sl@0
   583
				{
sl@0
   584
				pixelPtr[0] &= mask;
sl@0
   585
				pixelPtr[0] |= color;
sl@0
   586
				}
sl@0
   587
sl@0
   588
			dataMask <<= 1;
sl@0
   589
			pixelPtr += scanLineWords;
sl@0
   590
			color = (color == color2) ? color1 : color2;
sl@0
   591
			}
sl@0
   592
		}
sl@0
   593
	else
sl@0
   594
		{
sl@0
   595
		while (pixelPtr != pixelPtrLimit)
sl@0
   596
			{
sl@0
   597
			if (!dataMask)
sl@0
   598
				{
sl@0
   599
				dataMask = 1;
sl@0
   600
				aData++;
sl@0
   601
				}
sl@0
   602
sl@0
   603
			if (aData[0] & dataMask)
sl@0
   604
				pixelPtr[0] &= mask;
sl@0
   605
sl@0
   606
			dataMask <<= 1;
sl@0
   607
			pixelPtr += scanLineWords;
sl@0
   608
			}
sl@0
   609
		}
sl@0
   610
	}
sl@0
   611
sl@0
   612
void CDrawFourBppBitmapGray::WriteLine(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
sl@0
   613
	{
sl@0
   614
	if (iUserDispMode == EGray2)
sl@0
   615
		ShadeBuffer(aLength,aBuffer);
sl@0
   616
	else if (iUserDispMode == EGray4)
sl@0
   617
		DitherBuffer(aX,aY,aLength,aBuffer);
sl@0
   618
sl@0
   619
	const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
sl@0
   620
	const TInt finishLong = (aX + aLength) & (~7);
sl@0
   621
	const TInt startShift = (startLong - aX) * KBitsPerPixel;
sl@0
   622
	const TInt startShiftExtra = 32 - startShift;
sl@0
   623
	const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
sl@0
   624
	TUint32* base = ScanLine(aY);
sl@0
   625
	TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
sl@0
   626
	TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
sl@0
   627
sl@0
   628
	if (finishLong < startLong)
sl@0
   629
		{
sl@0
   630
		const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << startShiftExtra);
sl@0
   631
		pixelPtrLimit[0] &= ~mask;
sl@0
   632
		pixelPtrLimit[0] |= (aBuffer[0] << startShiftExtra) & mask;
sl@0
   633
		return;
sl@0
   634
		}
sl@0
   635
sl@0
   636
	const TInt wordsToCopy = pixelPtrLimit - pixelPtr;
sl@0
   637
sl@0
   638
	if (startShift > 0)
sl@0
   639
		{
sl@0
   640
		pixelPtr[-1] &= 0xffffffff >> startShift;
sl@0
   641
		pixelPtr[-1] |= aBuffer[0] << startShiftExtra;
sl@0
   642
sl@0
   643
		CopyOffset(pixelPtr,aBuffer,wordsToCopy,startShift);
sl@0
   644
		aBuffer += wordsToCopy;
sl@0
   645
sl@0
   646
		if (finishLong < aX + aLength)
sl@0
   647
			{
sl@0
   648
			TUint32 first = (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
sl@0
   649
			pixelPtrLimit[0] = PasteInt(first,pixelPtrLimit[0],finishShift);
sl@0
   650
			}
sl@0
   651
		}
sl@0
   652
	else
sl@0
   653
		{
sl@0
   654
		while (pixelPtr < pixelPtrLimit)
sl@0
   655
			*pixelPtr++ = *aBuffer++;
sl@0
   656
sl@0
   657
		if (finishLong < aX + aLength)
sl@0
   658
			pixelPtrLimit[0] = PasteInt(aBuffer[0],pixelPtrLimit[0],finishShift);
sl@0
   659
		}
sl@0
   660
	}
sl@0
   661
sl@0
   662
void CDrawFourBppBitmapGray::WriteLineXOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
sl@0
   663
	{
sl@0
   664
	if (iUserDispMode == EGray2)
sl@0
   665
		ShadeBuffer(aLength,aBuffer);
sl@0
   666
	else if (iUserDispMode == EGray4)
sl@0
   667
		DitherBuffer(aX,aY,aLength,aBuffer);
sl@0
   668
sl@0
   669
	const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
sl@0
   670
	const TInt finishLong = (aX + aLength) & (~7);
sl@0
   671
	const TInt startShift = (startLong - aX) * KBitsPerPixel;
sl@0
   672
	const TInt startShiftExtra = 32 - startShift;
sl@0
   673
	const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
sl@0
   674
	TUint32* base = ScanLine(aY);
sl@0
   675
	TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
sl@0
   676
	TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
sl@0
   677
sl@0
   678
	if (finishLong < startLong)
sl@0
   679
		{
sl@0
   680
		const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << startShiftExtra);
sl@0
   681
		pixelPtrLimit[0] ^= (aBuffer[0] << startShiftExtra) & mask;
sl@0
   682
		return;
sl@0
   683
		}
sl@0
   684
sl@0
   685
	if (startShift > 0)
sl@0
   686
		{
sl@0
   687
		pixelPtr[-1] ^= aBuffer[0] << startShiftExtra;
sl@0
   688
sl@0
   689
		while (pixelPtr < pixelPtrLimit)
sl@0
   690
			{
sl@0
   691
			pixelPtr[0] ^= (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
sl@0
   692
sl@0
   693
			pixelPtr++;
sl@0
   694
			aBuffer++;
sl@0
   695
			}
sl@0
   696
sl@0
   697
		if (finishLong < aX + aLength)
sl@0
   698
			{
sl@0
   699
			TUint32 first = (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
sl@0
   700
			pixelPtrLimit[0] ^= PasteInt(first,0,finishShift);
sl@0
   701
			}
sl@0
   702
		}
sl@0
   703
	else
sl@0
   704
		{
sl@0
   705
		while (pixelPtr < pixelPtrLimit)
sl@0
   706
			*pixelPtr++ ^= *aBuffer++;
sl@0
   707
sl@0
   708
		if (finishLong < aX + aLength)
sl@0
   709
			pixelPtrLimit[0] ^= PasteInt(aBuffer[0],0,finishShift);
sl@0
   710
		}
sl@0
   711
	}
sl@0
   712
sl@0
   713
void CDrawFourBppBitmapGray::WriteLineAND(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
sl@0
   714
	{
sl@0
   715
	if (iUserDispMode == EGray2)
sl@0
   716
		ShadeBuffer(aLength,aBuffer);
sl@0
   717
	else if (iUserDispMode == EGray4)
sl@0
   718
		DitherBuffer(aX,aY,aLength,aBuffer);
sl@0
   719
sl@0
   720
	const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
sl@0
   721
	const TInt finishLong = (aX + aLength) & (~7);
sl@0
   722
	const TInt startShift = (startLong - aX) * KBitsPerPixel;
sl@0
   723
	const TInt startShiftExtra = 32 - startShift;
sl@0
   724
	const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
sl@0
   725
	TUint32* base = ScanLine(aY);
sl@0
   726
	TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
sl@0
   727
	TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
sl@0
   728
sl@0
   729
	if (finishLong < startLong)
sl@0
   730
		{
sl@0
   731
		const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << startShiftExtra);
sl@0
   732
		pixelPtrLimit[0] &= (aBuffer[0] << startShiftExtra) | ~mask;
sl@0
   733
		return;
sl@0
   734
		}
sl@0
   735
sl@0
   736
	if (startShift > 0)
sl@0
   737
		{
sl@0
   738
		pixelPtr[-1] &= (aBuffer[0] << startShiftExtra) | (0xffffffff >> startShift);
sl@0
   739
sl@0
   740
		while (pixelPtr < pixelPtrLimit)
sl@0
   741
			{
sl@0
   742
			pixelPtr[0] &= (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
sl@0
   743
sl@0
   744
			pixelPtr++;
sl@0
   745
			aBuffer++;
sl@0
   746
			}
sl@0
   747
sl@0
   748
		if (finishLong < aX + aLength)
sl@0
   749
			{
sl@0
   750
			TUint32 first = (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
sl@0
   751
			pixelPtrLimit[0] &= PasteInt(first,0xffffffff,finishShift);
sl@0
   752
			}
sl@0
   753
		}
sl@0
   754
	else
sl@0
   755
		{
sl@0
   756
		while (pixelPtr < pixelPtrLimit)
sl@0
   757
			*pixelPtr++ &= *aBuffer++;
sl@0
   758
sl@0
   759
		if (finishLong < aX + aLength)
sl@0
   760
			pixelPtrLimit[0] &= PasteInt(aBuffer[0],0xffffffff,finishShift);
sl@0
   761
		}
sl@0
   762
	}
sl@0
   763
sl@0
   764
void CDrawFourBppBitmapGray::WriteLineOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
sl@0
   765
	{
sl@0
   766
	if (iUserDispMode == EGray2)
sl@0
   767
		ShadeBuffer(aLength,aBuffer);
sl@0
   768
	else if (iUserDispMode == EGray4)
sl@0
   769
		DitherBuffer(aX,aY,aLength,aBuffer);
sl@0
   770
sl@0
   771
	const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
sl@0
   772
	const TInt finishLong = (aX + aLength) & (~7);
sl@0
   773
	const TInt startShift = (startLong - aX) * KBitsPerPixel;
sl@0
   774
	const TInt startShiftExtra = 32 - startShift;
sl@0
   775
	const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
sl@0
   776
	TUint32* base = ScanLine(aY);
sl@0
   777
	TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
sl@0
   778
	TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
sl@0
   779
sl@0
   780
	if (finishLong < startLong)
sl@0
   781
		{
sl@0
   782
		const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << startShiftExtra);
sl@0
   783
		pixelPtrLimit[0] |= (aBuffer[0] << startShiftExtra) & mask;
sl@0
   784
		return;
sl@0
   785
		}
sl@0
   786
sl@0
   787
	if (startShift > 0)
sl@0
   788
		{
sl@0
   789
		pixelPtr[-1] |= aBuffer[0] << startShiftExtra;
sl@0
   790
sl@0
   791
		while (pixelPtr < pixelPtrLimit)
sl@0
   792
			{
sl@0
   793
			pixelPtr[0] |= (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
sl@0
   794
sl@0
   795
			pixelPtr++;
sl@0
   796
			aBuffer++;
sl@0
   797
			}
sl@0
   798
sl@0
   799
		if (finishLong < aX + aLength)
sl@0
   800
			{
sl@0
   801
			TUint32 first = (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
sl@0
   802
			pixelPtrLimit[0] |= PasteInt(first,0,finishShift);
sl@0
   803
			}
sl@0
   804
		}
sl@0
   805
	else
sl@0
   806
		{
sl@0
   807
		while (pixelPtr < pixelPtrLimit)
sl@0
   808
			*pixelPtr++ |= *aBuffer++;
sl@0
   809
sl@0
   810
		if (finishLong < aX + aLength)
sl@0
   811
			pixelPtrLimit[0] |= PasteInt(aBuffer[0],0,finishShift);
sl@0
   812
		}
sl@0
   813
	}
sl@0
   814
sl@0
   815
/**
sl@0
   816
MAlphaBlend::WriteRgbAlphaLine() implementation.
sl@0
   817
@see MAlphaBlend::WriteRgbAlphaLine()
sl@0
   818
*/
sl@0
   819
void CDrawFourBppBitmapGray::WriteRgbAlphaLine(TInt aX, TInt aY, TInt aLength,
sl@0
   820
                                               const TUint8* aRgbBuffer,
sl@0
   821
                                               const TUint8* aMaskBuffer,
sl@0
   822
                                               MAlphaBlend::TShadowing aShadowing,
sl@0
   823
                                               CGraphicsContext::TDrawMode /*aDrawMode*/)
sl@0
   824
    {
sl@0
   825
	TUint8* pixelPtr = REINTERPRET_CAST(TUint8*,ScanLine(aY)) + (aX / 2);
sl@0
   826
	TRgb pixelClr;
sl@0
   827
sl@0
   828
	if (aX & 1)
sl@0
   829
		{
sl@0
   830
        TRgb srcColor(aRgbBuffer[2],aRgbBuffer[1],aRgbBuffer[0]);
sl@0
   831
        if(aShadowing == MAlphaBlend::EShdwBefore)
sl@0
   832
            {
sl@0
   833
		    Shadow(srcColor);
sl@0
   834
            }
sl@0
   835
		TInt pixelValue = (pixelPtr[0] >> 4) * (255 - aMaskBuffer[0]);
sl@0
   836
		TInt srceValue = (((srcColor.Red() << 1) + 
sl@0
   837
                            srcColor.Green() + (srcColor.Green() << 2) + 
sl@0
   838
                            srcColor.Blue()) >> 7) * aMaskBuffer[0];
sl@0
   839
sl@0
   840
		pixelValue += srceValue;
sl@0
   841
		pixelValue /= 255;
sl@0
   842
sl@0
   843
		pixelClr = TRgb::_Gray16(pixelValue);
sl@0
   844
        if(aShadowing == MAlphaBlend::EShdwAfter)
sl@0
   845
            {
sl@0
   846
	    	Shadow(pixelClr);
sl@0
   847
            }
sl@0
   848
		MapColorToUserDisplayMode(pixelClr);
sl@0
   849
sl@0
   850
		pixelPtr[0] &= 0x0f;
sl@0
   851
		pixelPtr[0] |= TUint8(pixelClr._Gray16() << 4);
sl@0
   852
sl@0
   853
		pixelPtr++;
sl@0
   854
		aRgbBuffer += 4;
sl@0
   855
		aMaskBuffer++;
sl@0
   856
		aLength--;
sl@0
   857
		}
sl@0
   858
sl@0
   859
	const TUint8* pixelPtrLimit = pixelPtr + (aLength / 2);
sl@0
   860
sl@0
   861
	while (pixelPtr < pixelPtrLimit)
sl@0
   862
		{
sl@0
   863
        TRgb srcColor1(aRgbBuffer[2],aRgbBuffer[1],aRgbBuffer[0]);
sl@0
   864
        if(aShadowing == MAlphaBlend::EShdwBefore)
sl@0
   865
            {
sl@0
   866
		    Shadow(srcColor1);
sl@0
   867
            }
sl@0
   868
		TInt pixelValue = (pixelPtr[0] & 0x0f) * (255 - aMaskBuffer[0]);
sl@0
   869
		TInt srceValue = (((srcColor1.Red() << 1) + 
sl@0
   870
                            srcColor1.Green() + (srcColor1.Green() << 2) + 
sl@0
   871
                            srcColor1.Blue()) >> 7) * aMaskBuffer[0];
sl@0
   872
sl@0
   873
		pixelValue += srceValue;
sl@0
   874
		pixelValue /= 255;
sl@0
   875
sl@0
   876
		TInt nextValue = (pixelPtr[0] >> 4) * (255 - aMaskBuffer[1]);
sl@0
   877
sl@0
   878
		pixelClr = TRgb::_Gray16(pixelValue);
sl@0
   879
        if(aShadowing == MAlphaBlend::EShdwAfter)
sl@0
   880
            {
sl@0
   881
	    	Shadow(pixelClr);
sl@0
   882
            }
sl@0
   883
		MapColorToUserDisplayMode(pixelClr);
sl@0
   884
sl@0
   885
		pixelPtr[0] = TUint8(pixelClr._Gray16());
sl@0
   886
sl@0
   887
        TRgb srcColor2(aRgbBuffer[6],aRgbBuffer[5],aRgbBuffer[4]);
sl@0
   888
        if(aShadowing == MAlphaBlend::EShdwBefore)
sl@0
   889
            {
sl@0
   890
		    Shadow(srcColor2);
sl@0
   891
            }
sl@0
   892
		srceValue = (((srcColor2.Red() << 1) + 
sl@0
   893
                       srcColor2.Green() + (srcColor2.Green() << 2) + 
sl@0
   894
                       srcColor2.Blue()) >> 7) * aMaskBuffer[1];
sl@0
   895
sl@0
   896
		nextValue += srceValue;
sl@0
   897
		nextValue /= 255;
sl@0
   898
sl@0
   899
		pixelClr = TRgb::_Gray16(nextValue);
sl@0
   900
        if(aShadowing == MAlphaBlend::EShdwAfter)
sl@0
   901
            {
sl@0
   902
	    	Shadow(pixelClr);
sl@0
   903
            }
sl@0
   904
		MapColorToUserDisplayMode(pixelClr);
sl@0
   905
sl@0
   906
		pixelPtr[0] |= TUint8(pixelClr._Gray16() << 4);
sl@0
   907
sl@0
   908
		pixelPtr++;
sl@0
   909
		aRgbBuffer += 8;
sl@0
   910
		aMaskBuffer += 2;
sl@0
   911
		}
sl@0
   912
sl@0
   913
	if (aLength & 1)
sl@0
   914
		{
sl@0
   915
        TRgb srcColor(aRgbBuffer[2],aRgbBuffer[1],aRgbBuffer[0]);
sl@0
   916
        if(aShadowing == MAlphaBlend::EShdwBefore)
sl@0
   917
            {
sl@0
   918
		    Shadow(srcColor);
sl@0
   919
            }
sl@0
   920
		TInt pixelValue = (pixelPtr[0] & 0x0f) * (255 - aMaskBuffer[0]);
sl@0
   921
		TInt srceValue = (((srcColor.Red() << 1) + 
sl@0
   922
                            srcColor.Green() + (srcColor.Green() << 2) + 
sl@0
   923
                            srcColor.Blue()) >> 7) * aMaskBuffer[0];
sl@0
   924
sl@0
   925
		pixelValue += srceValue;
sl@0
   926
		pixelValue /= 255;
sl@0
   927
sl@0
   928
		pixelClr = TRgb::_Gray16(pixelValue);
sl@0
   929
        if(aShadowing == MAlphaBlend::EShdwAfter)
sl@0
   930
            {
sl@0
   931
	    	Shadow(pixelClr);
sl@0
   932
            }
sl@0
   933
		MapColorToUserDisplayMode(pixelClr);
sl@0
   934
sl@0
   935
		pixelPtr[0] &= 0xf0;
sl@0
   936
		pixelPtr[0] |= TUint8(pixelClr._Gray16());
sl@0
   937
		}
sl@0
   938
	}
sl@0
   939
sl@0
   940
void CDrawFourBppBitmapGray::WriteRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
sl@0
   941
	{
sl@0
   942
	if (iUserDispMode == EGray2)
sl@0
   943
		aColor = TRgb::_Gray2(aColor._Gray2());
sl@0
   944
sl@0
   945
	const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
sl@0
   946
	const TInt finishLong = (aX + aLength) & (~7);
sl@0
   947
	const TInt yLimit = aY + aHeight;
sl@0
   948
	const TInt startShift = (startLong - aX) * KBitsPerPixel;
sl@0
   949
	const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
sl@0
   950
	TUint32* base = ScanLine(aY);
sl@0
   951
	TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
sl@0
   952
	TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
sl@0
   953
sl@0
   954
	TUint32 colorWord1,colorWord2;
sl@0
   955
	if (iUserDispMode == EGray4 && aColor._Gray16() % 5 != 0)
sl@0
   956
		{
sl@0
   957
		colorWord1 = HashInt(aColor,startLong,aY);
sl@0
   958
		colorWord2 = HashInt(aColor,startLong,aY + 1);
sl@0
   959
		}
sl@0
   960
	else
sl@0
   961
		colorWord1 = colorWord2 = ColorInt(aColor);
sl@0
   962
	TUint32 colorWord = colorWord1;
sl@0
   963
sl@0
   964
	if (finishLong < startLong)
sl@0
   965
		{
sl@0
   966
		const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << (32 - startShift));
sl@0
   967
		const TUint32 invertedMask = ~mask;
sl@0
   968
		colorWord &= mask;
sl@0
   969
		colorWord1 &= mask;
sl@0
   970
		colorWord2 &= mask;
sl@0
   971
sl@0
   972
		for (; aY < yLimit; aY++)
sl@0
   973
			{
sl@0
   974
			pixelPtrLimit[0] &= invertedMask;
sl@0
   975
			pixelPtrLimit[0] |= colorWord;
sl@0
   976
			pixelPtrLimit += iScanLineWords;
sl@0
   977
			colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
sl@0
   978
			}
sl@0
   979
		return;
sl@0
   980
		}
sl@0
   981
sl@0
   982
	const TBool extra = (finishLong < aX + aLength);
sl@0
   983
sl@0
   984
	for (; aY < yLimit; aY++)
sl@0
   985
		{
sl@0
   986
		if (startShift > 0)
sl@0
   987
			pixelPtr[-1] = PasteInt(pixelPtr[-1],colorWord,startShift);
sl@0
   988
sl@0
   989
		for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
sl@0
   990
			tempPixelPtr[0] = colorWord;
sl@0
   991
sl@0
   992
		if (extra)
sl@0
   993
			pixelPtrLimit[0] = PasteInt(colorWord,pixelPtrLimit[0],finishShift);
sl@0
   994
sl@0
   995
		pixelPtr += iScanLineWords;
sl@0
   996
		pixelPtrLimit += iScanLineWords;
sl@0
   997
		colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
sl@0
   998
		}
sl@0
   999
	}
sl@0
  1000
sl@0
  1001
void CDrawFourBppBitmapGray::WriteRgbMultiXOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
sl@0
  1002
	{
sl@0
  1003
	if (iUserDispMode == EGray2)
sl@0
  1004
		aColor = TRgb::_Gray2(aColor._Gray2());
sl@0
  1005
sl@0
  1006
	const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
sl@0
  1007
	const TInt finishLong = (aX + aLength) & (~7);
sl@0
  1008
	const TInt yLimit = aY + aHeight;
sl@0
  1009
	const TInt startShift = (startLong - aX) * KBitsPerPixel;
sl@0
  1010
	const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
sl@0
  1011
	TUint32* base = ScanLine(aY);
sl@0
  1012
	TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
sl@0
  1013
	TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
sl@0
  1014
sl@0
  1015
	TUint32 colorWord1,colorWord2;
sl@0
  1016
	if (iUserDispMode == EGray4 && aColor._Gray16() % 5 != 0)
sl@0
  1017
		{
sl@0
  1018
		colorWord1 = HashInt(aColor,startLong,aY);
sl@0
  1019
		colorWord2 = HashInt(aColor,startLong,aY + 1);
sl@0
  1020
		}
sl@0
  1021
	else
sl@0
  1022
		colorWord1 = colorWord2 = ColorInt(aColor);
sl@0
  1023
	TUint32 colorWord = colorWord1;
sl@0
  1024
sl@0
  1025
	if (finishLong < startLong)
sl@0
  1026
		{
sl@0
  1027
		const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << (32 - startShift));
sl@0
  1028
		colorWord &= mask;
sl@0
  1029
		colorWord1 &= mask;
sl@0
  1030
		colorWord2 &= mask;
sl@0
  1031
sl@0
  1032
		for (; aY < yLimit; aY++)
sl@0
  1033
			{
sl@0
  1034
			pixelPtrLimit[0] ^= colorWord;
sl@0
  1035
			pixelPtrLimit += iScanLineWords;
sl@0
  1036
			colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
sl@0
  1037
			}
sl@0
  1038
		return;
sl@0
  1039
		}
sl@0
  1040
sl@0
  1041
	const TBool extra = (finishLong < aX + aLength);
sl@0
  1042
sl@0
  1043
	for (; aY < yLimit; aY++)
sl@0
  1044
		{
sl@0
  1045
		if (startShift > 0)
sl@0
  1046
			pixelPtr[-1] ^= PasteInt(0,colorWord,startShift);
sl@0
  1047
sl@0
  1048
		for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
sl@0
  1049
			tempPixelPtr[0] ^= colorWord;
sl@0
  1050
sl@0
  1051
		if (extra)
sl@0
  1052
			pixelPtrLimit[0] ^= PasteInt(colorWord,0,finishShift);
sl@0
  1053
sl@0
  1054
		pixelPtr += iScanLineWords;
sl@0
  1055
		pixelPtrLimit += iScanLineWords;
sl@0
  1056
		colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
sl@0
  1057
		}
sl@0
  1058
	}
sl@0
  1059
sl@0
  1060
void CDrawFourBppBitmapGray::WriteRgbMultiAND(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
sl@0
  1061
	{
sl@0
  1062
	if (iUserDispMode == EGray2)
sl@0
  1063
		aColor = TRgb::_Gray2(aColor._Gray2());
sl@0
  1064
sl@0
  1065
	const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
sl@0
  1066
	const TInt finishLong = (aX + aLength) & (~7);
sl@0
  1067
	const TInt yLimit = aY + aHeight;
sl@0
  1068
	const TInt startShift = (startLong - aX) * KBitsPerPixel;
sl@0
  1069
	const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
sl@0
  1070
	TUint32* base = ScanLine(aY);
sl@0
  1071
	TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
sl@0
  1072
	TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
sl@0
  1073
sl@0
  1074
	TUint32 colorWord1,colorWord2;
sl@0
  1075
	if (iUserDispMode == EGray4 && aColor._Gray16() % 5 != 0)
sl@0
  1076
		{
sl@0
  1077
		colorWord1 = HashInt(aColor,startLong,aY);
sl@0
  1078
		colorWord2 = HashInt(aColor,startLong,aY + 1);
sl@0
  1079
		}
sl@0
  1080
	else
sl@0
  1081
		colorWord1 = colorWord2 = ColorInt(aColor);
sl@0
  1082
	TUint32 colorWord = colorWord1;
sl@0
  1083
sl@0
  1084
	if (finishLong < startLong)
sl@0
  1085
		{
sl@0
  1086
		const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << (32 - startShift));
sl@0
  1087
		const TUint32 invertedMask = ~mask;
sl@0
  1088
		colorWord &= mask;
sl@0
  1089
		colorWord1 &= mask;
sl@0
  1090
		colorWord2 &= mask;
sl@0
  1091
		colorWord |= invertedMask;
sl@0
  1092
		colorWord1 |= invertedMask;
sl@0
  1093
		colorWord2 |= invertedMask;
sl@0
  1094
sl@0
  1095
		for (; aY < yLimit; aY++)
sl@0
  1096
			{
sl@0
  1097
			pixelPtrLimit[0] &= colorWord;
sl@0
  1098
			pixelPtrLimit += iScanLineWords;
sl@0
  1099
			colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
sl@0
  1100
			}
sl@0
  1101
		return;
sl@0
  1102
		}
sl@0
  1103
sl@0
  1104
	const TBool extra = (finishLong < aX + aLength);
sl@0
  1105
sl@0
  1106
	for (; aY < yLimit; aY++)
sl@0
  1107
		{
sl@0
  1108
		if (startShift > 0)
sl@0
  1109
			pixelPtr[-1] &= PasteInt(0xffffffff,colorWord,startShift);
sl@0
  1110
sl@0
  1111
		for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
sl@0
  1112
			tempPixelPtr[0] &= colorWord;
sl@0
  1113
sl@0
  1114
		if (extra)
sl@0
  1115
			pixelPtrLimit[0] &= PasteInt(colorWord,0xffffffff,finishShift);
sl@0
  1116
sl@0
  1117
		pixelPtr += iScanLineWords;
sl@0
  1118
		pixelPtrLimit += iScanLineWords;
sl@0
  1119
		colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
sl@0
  1120
		}
sl@0
  1121
	}
sl@0
  1122
sl@0
  1123
void CDrawFourBppBitmapGray::WriteRgbMultiOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
sl@0
  1124
	{
sl@0
  1125
	if (iUserDispMode == EGray2)
sl@0
  1126
		aColor = TRgb::_Gray2(aColor._Gray2());
sl@0
  1127
sl@0
  1128
	const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
sl@0
  1129
	const TInt finishLong = (aX + aLength) & (~7);
sl@0
  1130
	const TInt yLimit = aY + aHeight;
sl@0
  1131
	const TInt startShift = (startLong - aX) * KBitsPerPixel;
sl@0
  1132
	const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
sl@0
  1133
	TUint32* base = ScanLine(aY);
sl@0
  1134
	TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
sl@0
  1135
	TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
sl@0
  1136
sl@0
  1137
	TUint32 colorWord1,colorWord2;
sl@0
  1138
	if (iUserDispMode == EGray4 && aColor._Gray16() % 5 != 0)
sl@0
  1139
		{
sl@0
  1140
		colorWord1 = HashInt(aColor,startLong,aY);
sl@0
  1141
		colorWord2 = HashInt(aColor,startLong,aY + 1);
sl@0
  1142
		}
sl@0
  1143
	else
sl@0
  1144
		colorWord1 = colorWord2 = ColorInt(aColor);
sl@0
  1145
	TUint32 colorWord = colorWord1;
sl@0
  1146
sl@0
  1147
	if (finishLong < startLong)
sl@0
  1148
		{
sl@0
  1149
		const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << (32 - startShift));
sl@0
  1150
		colorWord &= mask;
sl@0
  1151
		colorWord1 &= mask;
sl@0
  1152
		colorWord2 &= mask;
sl@0
  1153
sl@0
  1154
		for (; aY < yLimit; aY++)
sl@0
  1155
			{
sl@0
  1156
			pixelPtrLimit[0] |= colorWord;
sl@0
  1157
			pixelPtrLimit += iScanLineWords;
sl@0
  1158
			colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
sl@0
  1159
			}
sl@0
  1160
		return;
sl@0
  1161
		}
sl@0
  1162
sl@0
  1163
	const TBool extra = (finishLong < aX + aLength);
sl@0
  1164
sl@0
  1165
	for (; aY < yLimit; aY++)
sl@0
  1166
		{
sl@0
  1167
		if (startShift > 0)
sl@0
  1168
			pixelPtr[-1] |= PasteInt(0,colorWord,startShift);
sl@0
  1169
sl@0
  1170
		for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
sl@0
  1171
			tempPixelPtr[0] |= colorWord;
sl@0
  1172
sl@0
  1173
		if (extra)
sl@0
  1174
			pixelPtrLimit[0] |= PasteInt(colorWord,0,finishShift);
sl@0
  1175
sl@0
  1176
		pixelPtr += iScanLineWords;
sl@0
  1177
		pixelPtrLimit += iScanLineWords;
sl@0
  1178
		colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
sl@0
  1179
		}
sl@0
  1180
	}
sl@0
  1181
sl@0
  1182
void CDrawFourBppBitmapGray::WriteRgbAlphaMulti(TInt aX,TInt aY,TInt aLength,TRgb aColor,const TUint8* aMaskBuffer)
sl@0
  1183
	{
sl@0
  1184
	DeOrientate(aX,aY);
sl@0
  1185
	TUint8* pixelPtr = REINTERPRET_CAST(TUint8*,ScanLine(aY)) + (aX / 2);
sl@0
  1186
	const TBool oddEndCoord = (aX + aLength) & 1;
sl@0
  1187
	const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength - (oddEndCoord ? 1 : 0);
sl@0
  1188
sl@0
  1189
	if (iShadowMode)
sl@0
  1190
		Shadow(aColor);
sl@0
  1191
	
sl@0
  1192
	const TInt gray = aColor._Gray256();
sl@0
  1193
	if (aX & 1)
sl@0
  1194
		{
sl@0
  1195
		const TInt upper = ((gray * aMaskBuffer[0]) + ((255 - aMaskBuffer[0]) * (pixelPtr[0] >> 4) * 17)) / (255 * 17);
sl@0
  1196
		pixelPtr[0] &= 0x0f;
sl@0
  1197
		pixelPtr[0] |= TUint8(upper << 4);
sl@0
  1198
sl@0
  1199
		pixelPtr++;
sl@0
  1200
		aMaskBuffer++;
sl@0
  1201
		}
sl@0
  1202
sl@0
  1203
	while (aMaskBuffer < maskBufferPtrLimit)
sl@0
  1204
		{
sl@0
  1205
		const TInt lower = ((gray * aMaskBuffer[0]) + ((255 - aMaskBuffer[0]) * (pixelPtr[0] & 0x0f) * 17)) / (255 * 17);
sl@0
  1206
		const TInt upper = ((gray * aMaskBuffer[1]) + ((255 - aMaskBuffer[1]) * (pixelPtr[0] >> 4) * 17)) / (255 * 17);
sl@0
  1207
		pixelPtr[0] = TUint8(lower);
sl@0
  1208
		pixelPtr[0] |= TUint8(upper << 4);
sl@0
  1209
sl@0
  1210
		pixelPtr++;
sl@0
  1211
		aMaskBuffer += 2;
sl@0
  1212
		}
sl@0
  1213
sl@0
  1214
	if (oddEndCoord)
sl@0
  1215
		{
sl@0
  1216
		const TInt lower = ((gray * aMaskBuffer[0]) + ((255 - aMaskBuffer[0]) * (pixelPtr[0] & 0x0f) * 17)) / (255 * 17);
sl@0
  1217
		pixelPtr[0] &= 0xf0;
sl@0
  1218
		pixelPtr[0] |= TUint8(lower);
sl@0
  1219
		}
sl@0
  1220
	}
sl@0
  1221
sl@0
  1222
void CDrawFourBppBitmapGray::MapColorToUserDisplayMode(TRgb& aColor)
sl@0
  1223
	{
sl@0
  1224
	switch (iUserDispMode)
sl@0
  1225
		{
sl@0
  1226
	case EGray2:
sl@0
  1227
		aColor = TRgb::_Gray2(aColor._Gray2());
sl@0
  1228
		break;
sl@0
  1229
	case EColor16:
sl@0
  1230
		aColor = TRgb::_Gray4(aColor._Gray4());
sl@0
  1231
		break;
sl@0
  1232
	default:
sl@0
  1233
		break;
sl@0
  1234
		}
sl@0
  1235
	}
sl@0
  1236
sl@0
  1237
void CDrawFourBppBitmapGray::MapBufferToUserDisplayMode(TInt aLength,TUint32* aBuffer)
sl@0
  1238
	{
sl@0
  1239
	TUint8* bufferPtr = (TUint8*)aBuffer;
sl@0
  1240
	const TUint8* bufferLimit = bufferPtr + ((aLength + 1) / 2);
sl@0
  1241
sl@0
  1242
	switch (iUserDispMode)
sl@0
  1243
		{
sl@0
  1244
	case EGray2:
sl@0
  1245
		while (bufferPtr < bufferLimit)
sl@0
  1246
			{
sl@0
  1247
			TUint8 value = TUint8(*bufferPtr & 0x88);
sl@0
  1248
			value |= value >> 1;
sl@0
  1249
			*bufferPtr++ = TUint8(value | (value >> 2));
sl@0
  1250
			}
sl@0
  1251
		break;
sl@0
  1252
	case EColor16:
sl@0
  1253
		while (bufferPtr < bufferLimit)
sl@0
  1254
			{
sl@0
  1255
			TUint8 value = TUint8(*bufferPtr & 0xcc);
sl@0
  1256
			*bufferPtr++ = TUint8(value | (value >> 2));
sl@0
  1257
			}
sl@0
  1258
		break;
sl@0
  1259
	default:
sl@0
  1260
		break;
sl@0
  1261
		}
sl@0
  1262
	}
sl@0
  1263
sl@0
  1264
TInt CDrawFourBppBitmapGray::WriteRgbOutlineAndShadow(TInt aX, TInt aY, const TInt aLength,
sl@0
  1265
	                                   TUint32 aOutlinePenColor, TUint32 aShadowColor,
sl@0
  1266
	                                   TUint32 aFillColor, const TUint8* aDataBuffer)
sl@0
  1267
	{
sl@0
  1268
	//This is non-optimised since this screen mode is rarely used and is usually 
sl@0
  1269
	//fast enough without optimisation.
sl@0
  1270
	DeOrientate(aX,aY);
sl@0
  1271
	TUint8* pixelPtr = REINTERPRET_CAST(TUint8*,ScanLine(aY)) + (aX / 2);
sl@0
  1272
	const TBool oddEndCoord = (aX + aLength) & 1;
sl@0
  1273
	const TUint8* dataBufferPtrLimit = aDataBuffer + aLength - (oddEndCoord ? 1 : 0);
sl@0
  1274
sl@0
  1275
	TUint8 index = 0;
sl@0
  1276
	TRgb finalColor;
sl@0
  1277
	TRgb lowerPixelColor;
sl@0
  1278
	TRgb upperPixelColor;
sl@0
  1279
sl@0
  1280
	TRgb outlinePenColor;
sl@0
  1281
	outlinePenColor.SetInternal(aOutlinePenColor);
sl@0
  1282
	TRgb shadowColor;
sl@0
  1283
	shadowColor.SetInternal(aShadowColor);
sl@0
  1284
	TRgb fillColor;
sl@0
  1285
	fillColor.SetInternal(aFillColor);
sl@0
  1286
sl@0
  1287
	const TInt redOutlinePenColor = outlinePenColor.Red();
sl@0
  1288
	const TInt redShadowColor = shadowColor.Red();
sl@0
  1289
	const TInt redFillColor = fillColor.Red();
sl@0
  1290
sl@0
  1291
	const TInt greenOutlinePenColor = outlinePenColor.Green();
sl@0
  1292
	const TInt greenShadowColor = shadowColor.Green();
sl@0
  1293
	const TInt greenFillColor = fillColor.Green();
sl@0
  1294
sl@0
  1295
	const TInt blueOutlinePenColor = outlinePenColor.Blue();
sl@0
  1296
	const TInt blueShadowColor = shadowColor.Blue();
sl@0
  1297
	const TInt blueFillColor = fillColor.Blue();
sl@0
  1298
sl@0
  1299
	if (aX & 1)
sl@0
  1300
		{
sl@0
  1301
		index = *aDataBuffer;
sl@0
  1302
		
sl@0
  1303
		if (255 != FourColorBlendLookup[index][KBackgroundColorIndex])
sl@0
  1304
			{
sl@0
  1305
			TRgb backgroundColor = TRgb::_Gray16(pixelPtr[0] >> 4);
sl@0
  1306
			finalColor = BlendFourColors(aOutlinePenColor, aShadowColor, aFillColor,
sl@0
  1307
										redOutlinePenColor, redShadowColor, redFillColor,
sl@0
  1308
										greenOutlinePenColor, greenShadowColor, greenFillColor,
sl@0
  1309
										blueOutlinePenColor, blueShadowColor, blueFillColor,
sl@0
  1310
										backgroundColor, index);
sl@0
  1311
			pixelPtr[0] &= 0x0f;
sl@0
  1312
			pixelPtr[0] |= TUint8(finalColor._Gray16() << 4);
sl@0
  1313
			}
sl@0
  1314
			
sl@0
  1315
		pixelPtr++;
sl@0
  1316
		aDataBuffer++;
sl@0
  1317
		}
sl@0
  1318
sl@0
  1319
	while (aDataBuffer < dataBufferPtrLimit)
sl@0
  1320
		{
sl@0
  1321
		index = aDataBuffer[0];
sl@0
  1322
		TRgb upperPixelBackgroundColor = TRgb::_Gray16(pixelPtr[0] >> 4);
sl@0
  1323
		if (255 != FourColorBlendLookup[index][KBackgroundColorIndex])
sl@0
  1324
			{
sl@0
  1325
			TRgb lowerPixelBackgroundColor = TRgb::_Gray16(pixelPtr[0] & 0x0f);
sl@0
  1326
			lowerPixelColor = BlendFourColors(aOutlinePenColor, aShadowColor, aFillColor,
sl@0
  1327
											redOutlinePenColor, redShadowColor, redFillColor,
sl@0
  1328
											greenOutlinePenColor, greenShadowColor, greenFillColor,
sl@0
  1329
											blueOutlinePenColor, blueShadowColor, blueFillColor,
sl@0
  1330
											lowerPixelBackgroundColor, index);
sl@0
  1331
			pixelPtr[0] = TUint8(lowerPixelColor._Gray16());
sl@0
  1332
			}
sl@0
  1333
		
sl@0
  1334
		index = aDataBuffer[1];
sl@0
  1335
		if (255 != FourColorBlendLookup[index][KBackgroundColorIndex])
sl@0
  1336
			{
sl@0
  1337
			upperPixelColor = BlendFourColors(aOutlinePenColor, aShadowColor, aFillColor,
sl@0
  1338
											redOutlinePenColor, redShadowColor, redFillColor,
sl@0
  1339
											greenOutlinePenColor, greenShadowColor, greenFillColor,
sl@0
  1340
											blueOutlinePenColor, blueShadowColor, blueFillColor,
sl@0
  1341
											upperPixelBackgroundColor, index);
sl@0
  1342
			pixelPtr[0] |= TUint8(upperPixelColor._Gray16() << 4);
sl@0
  1343
			}
sl@0
  1344
		pixelPtr++;
sl@0
  1345
		aDataBuffer += 2;
sl@0
  1346
		}
sl@0
  1347
sl@0
  1348
	if (oddEndCoord)
sl@0
  1349
		{
sl@0
  1350
		index = aDataBuffer[0];
sl@0
  1351
		if (255 != FourColorBlendLookup[index][KBackgroundColorIndex])
sl@0
  1352
			{
sl@0
  1353
			TRgb backgroundColor = TRgb::_Gray16(pixelPtr[0] & 0x0f);
sl@0
  1354
			finalColor = BlendFourColors(aOutlinePenColor, aShadowColor, aFillColor,
sl@0
  1355
										redOutlinePenColor, redShadowColor, redFillColor,
sl@0
  1356
										greenOutlinePenColor, greenShadowColor, greenFillColor,
sl@0
  1357
										blueOutlinePenColor, blueShadowColor, blueFillColor,
sl@0
  1358
										backgroundColor, index);
sl@0
  1359
			pixelPtr[0] &= 0xf0;
sl@0
  1360
			pixelPtr[0] |= TUint8(finalColor._Gray16());
sl@0
  1361
			}
sl@0
  1362
		}
sl@0
  1363
	return KErrNone;
sl@0
  1364
	}
sl@0
  1365
sl@0
  1366
TRgb CDrawFourBppBitmapGray::BlendFourColors(TUint32 aOutlinePenColor, TUint32 aShadowColor, TUint32 aFillColor,
sl@0
  1367
											TInt aRedOutlinePenColor, TInt aRedShadowColor, TInt aRedFillColor,
sl@0
  1368
											TInt aGreenOutlinePenColor, TInt aGreenShadowColor, TInt aGreenFillColor,
sl@0
  1369
											TInt aBlueOutlinePenColor,	TInt aBlueShadowColor,	TInt aBlueFillColor,
sl@0
  1370
											TRgb aBackgroundColor, TUint8 aIndex) const
sl@0
  1371
	{
sl@0
  1372
	TRgb finalColor;
sl@0
  1373
	if (255 == FourColorBlendLookup[aIndex][KFillColorIndex])
sl@0
  1374
		{
sl@0
  1375
		//fill colour
sl@0
  1376
		finalColor.SetInternal(aFillColor);
sl@0
  1377
		}
sl@0
  1378
	else if (255 == FourColorBlendLookup[aIndex][KShadowColorIndex])
sl@0
  1379
		{
sl@0
  1380
		//Shadow colour
sl@0
  1381
		finalColor.SetInternal(aShadowColor);
sl@0
  1382
		}
sl@0
  1383
	else if (255 == FourColorBlendLookup[aIndex][KOutlineColorIndex])
sl@0
  1384
		{
sl@0
  1385
		//Outline colour
sl@0
  1386
		finalColor.SetInternal(aOutlinePenColor);
sl@0
  1387
		}
sl@0
  1388
	else
sl@0
  1389
		{
sl@0
  1390
		TInt blendedRedColor = (aRedOutlinePenColor * FourColorBlendLookup[aIndex][KOutlineColorIndex] + 
sl@0
  1391
						   		aRedShadowColor * FourColorBlendLookup[aIndex][KShadowColorIndex] +
sl@0
  1392
						  		aRedFillColor * FourColorBlendLookup[aIndex][KFillColorIndex] + 
sl@0
  1393
						  		aBackgroundColor.Red() * FourColorBlendLookup[aIndex][KBackgroundColorIndex]) >> 8;
sl@0
  1394
sl@0
  1395
		TInt blendedGreenColor = (aGreenOutlinePenColor * FourColorBlendLookup[aIndex][KOutlineColorIndex] + 
sl@0
  1396
								aGreenShadowColor * FourColorBlendLookup[aIndex][KShadowColorIndex] +
sl@0
  1397
								aGreenFillColor * FourColorBlendLookup[aIndex][KFillColorIndex] + 
sl@0
  1398
								aBackgroundColor.Green() * FourColorBlendLookup[aIndex][KBackgroundColorIndex]) >> 8;
sl@0
  1399
sl@0
  1400
		TInt blendedBlueColor = (aBlueOutlinePenColor * FourColorBlendLookup[aIndex][KOutlineColorIndex] + 
sl@0
  1401
								aBlueShadowColor * FourColorBlendLookup[aIndex][KShadowColorIndex] +
sl@0
  1402
								aBlueFillColor * FourColorBlendLookup[aIndex][KFillColorIndex] + 
sl@0
  1403
								aBackgroundColor.Blue() * FourColorBlendLookup[aIndex][KBackgroundColorIndex]) >> 8;
sl@0
  1404
		finalColor = TRgb(blendedRedColor, blendedGreenColor, blendedBlueColor);
sl@0
  1405
		}
sl@0
  1406
	return finalColor;
sl@0
  1407
	}