os/graphics/graphicsdeviceinterface/screendriver/sbit/BMDRAW8M.CPP
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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
// CDrawEightBppBitmapGray
sl@0
    19
sl@0
    20
TInt CDrawEightBppBitmapGray::Construct(TSize aSize)
sl@0
    21
	{
sl@0
    22
	return Construct(aSize, (aSize.iWidth + 3) & ~3);
sl@0
    23
	}
sl@0
    24
sl@0
    25
TInt CDrawEightBppBitmapGray::Construct(TSize aSize, TInt aStride)
sl@0
    26
	{
sl@0
    27
	iDispMode = EGray256;
sl@0
    28
	return CDrawEightBppBitmapCommon::Construct(aSize, aStride);
sl@0
    29
	}
sl@0
    30
sl@0
    31
void CDrawEightBppBitmapGray::Shadow(TRgb& aColor)
sl@0
    32
	{
sl@0
    33
	if (iShadowMode & EFade)
sl@0
    34
		aColor = TRgb::_Gray256(FadeGray(aColor._Gray256()));
sl@0
    35
sl@0
    36
	if (iShadowMode & EShadow)
sl@0
    37
		{
sl@0
    38
		TInt gray256 = Max(aColor._Gray256() - 85,0);
sl@0
    39
		aColor = TRgb::_Gray256(gray256);
sl@0
    40
		}
sl@0
    41
	}
sl@0
    42
sl@0
    43
TUint8 CDrawEightBppBitmapGray::ShadowAndFade(TInt aGray256)
sl@0
    44
	{
sl@0
    45
	if (iShadowMode & EFade)
sl@0
    46
		aGray256 = FadeGray(aGray256);
sl@0
    47
sl@0
    48
	if (iShadowMode & EShadow)
sl@0
    49
		aGray256 = Max(aGray256 - 85,0);
sl@0
    50
sl@0
    51
	return TUint8(aGray256);
sl@0
    52
	}
sl@0
    53
sl@0
    54
TRgb CDrawEightBppBitmapGray::ReadRgbNormal(TInt aX,TInt aY) const
sl@0
    55
	{
sl@0
    56
	return TRgb::_Gray256(*PixelAddress(aX,aY));
sl@0
    57
	}
sl@0
    58
sl@0
    59
void CDrawEightBppBitmapGray::ShadowArea(const TRect& aRect)
sl@0
    60
	{
sl@0
    61
	const TRect rect(DeOrientate(aRect));
sl@0
    62
sl@0
    63
	__ASSERT_DEBUG(rect.iTl.iX>=0 && rect.iBr.iX<=iSize.iWidth,Panic(EScreenDriverPanicOutOfBounds));
sl@0
    64
	__ASSERT_DEBUG(rect.iTl.iY>=0 && rect.iBr.iY<=iSize.iHeight,Panic(EScreenDriverPanicOutOfBounds));
sl@0
    65
sl@0
    66
	const TInt longWidth = iLongWidth;
sl@0
    67
	TUint8* pixelPtr = PixelAddress(rect.iTl.iX,rect.iTl.iY);
sl@0
    68
	const TUint8* pixelRowPtrLimit = pixelPtr + (rect.Height() * longWidth);
sl@0
    69
sl@0
    70
	if (iShadowMode & EFade)
sl@0
    71
		{
sl@0
    72
		TUint8* pixelRowPtr = pixelPtr;
sl@0
    73
		TUint8* pixelPtrLimit = pixelPtr + rect.Width();
sl@0
    74
sl@0
    75
		while (pixelRowPtr < pixelRowPtrLimit)
sl@0
    76
			{
sl@0
    77
			TUint8* tempPixelPtr = pixelRowPtr;
sl@0
    78
sl@0
    79
			while (tempPixelPtr < pixelPtrLimit)
sl@0
    80
				{
sl@0
    81
				*tempPixelPtr = FadeGray(*tempPixelPtr);
sl@0
    82
				++tempPixelPtr;
sl@0
    83
				}
sl@0
    84
sl@0
    85
			pixelRowPtr += longWidth;
sl@0
    86
			pixelPtrLimit += longWidth;
sl@0
    87
			}
sl@0
    88
		}
sl@0
    89
sl@0
    90
	if (iShadowMode & EShadow)
sl@0
    91
		{
sl@0
    92
		TUint8* pixelRowPtr = pixelPtr;
sl@0
    93
		TUint8* pixelPtrLimit = pixelPtr + rect.Width();
sl@0
    94
sl@0
    95
		while (pixelRowPtr < pixelRowPtrLimit)
sl@0
    96
			{
sl@0
    97
			TUint8* tempPixelPtr = pixelRowPtr;
sl@0
    98
sl@0
    99
			while (tempPixelPtr < pixelPtrLimit)
sl@0
   100
				{
sl@0
   101
				*tempPixelPtr = TUint8(Max(*tempPixelPtr - 85,0));
sl@0
   102
				++tempPixelPtr;
sl@0
   103
				}
sl@0
   104
sl@0
   105
			pixelRowPtr += longWidth;
sl@0
   106
			pixelPtrLimit += longWidth;
sl@0
   107
			}
sl@0
   108
		}
sl@0
   109
	}
sl@0
   110
sl@0
   111
void CDrawEightBppBitmapGray::ShadowBuffer(TInt aLength,TUint32* aBuffer)
sl@0
   112
	{
sl@0
   113
	__ASSERT_DEBUG(aLength>0,Panic(EScreenDriverPanicInvalidParameter));
sl@0
   114
	__ASSERT_DEBUG(aBuffer!=NULL,Panic(EScreenDriverPanicInvalidParameter));
sl@0
   115
sl@0
   116
	TUint8* limit = ((TUint8*)aBuffer) + aLength;
sl@0
   117
sl@0
   118
	if (iShadowMode & EFade)
sl@0
   119
		{
sl@0
   120
		TUint8* buffer = (TUint8*)aBuffer;
sl@0
   121
sl@0
   122
		while(buffer < limit)
sl@0
   123
			{
sl@0
   124
			*buffer = FadeGray(*buffer);
sl@0
   125
			++buffer;
sl@0
   126
			}
sl@0
   127
		}
sl@0
   128
sl@0
   129
	if (iShadowMode & EShadow)
sl@0
   130
		{
sl@0
   131
		TUint8* buffer = (TUint8*)aBuffer;
sl@0
   132
sl@0
   133
		while(buffer < limit)
sl@0
   134
			{
sl@0
   135
			*buffer = TUint8(Max(*buffer - 85,0));
sl@0
   136
			++buffer;
sl@0
   137
			}
sl@0
   138
		}
sl@0
   139
	}
sl@0
   140
sl@0
   141
void CDrawEightBppBitmapGray::WriteRgb(TInt aX,TInt aY,TRgb aColor)
sl@0
   142
	{
sl@0
   143
	CDrawEightBppBitmapCommon::WriteRgb(aX,aY,TUint8(aColor._Gray256()));
sl@0
   144
	}
sl@0
   145
sl@0
   146
void CDrawEightBppBitmapGray::WriteBinary(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TRgb aColor)
sl@0
   147
	{
sl@0
   148
	CDrawEightBppBitmapCommon::WriteBinary(aX,aY,aData,aLength,aHeight,TUint8(aColor._Gray256()));
sl@0
   149
	}
sl@0
   150
sl@0
   151
void CDrawEightBppBitmapGray::WriteBinaryOp(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode)
sl@0
   152
	{
sl@0
   153
	CDrawEightBppBitmapCommon::WriteBinaryOp(aX,aY,aData,aLength,aHeight,TUint8(aColor._Gray256()),aDrawMode);
sl@0
   154
	}
sl@0
   155
sl@0
   156
void CDrawEightBppBitmapGray::WriteBinaryLineVertical(TInt aX,TInt aY,TUint32* aData,TInt aLength,TRgb aColor,TBool aUp)
sl@0
   157
	{
sl@0
   158
	CDrawEightBppBitmapCommon::WriteBinaryLineVertical(aX,aY,aData,aLength,TUint8(aColor._Gray256()),aUp);
sl@0
   159
	}
sl@0
   160
sl@0
   161
/**
sl@0
   162
MAlphaBlend::WriteRgbAlphaLine() implementation.
sl@0
   163
@see MAlphaBlend::WriteRgbAlphaLine()
sl@0
   164
*/
sl@0
   165
void CDrawEightBppBitmapGray::WriteRgbAlphaLine(TInt aX, TInt aY, TInt aLength,
sl@0
   166
                                                const TUint8* aRgbBuffer,
sl@0
   167
                                                const TUint8* aMaskBuffer,
sl@0
   168
                                                MAlphaBlend::TShadowing aShadowing,
sl@0
   169
                                                CGraphicsContext::TDrawMode /*aDrawMode*/)
sl@0
   170
    {
sl@0
   171
	DeOrientate(aX,aY);
sl@0
   172
	TUint8* pixelPtr = PixelAddress(aX,aY);
sl@0
   173
	const TInt pixelPtrInc = LogicalPixelAddressIncrement();
sl@0
   174
	const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
sl@0
   175
	TRgb pixelClr;
sl@0
   176
sl@0
   177
	while (aMaskBuffer < maskBufferPtrLimit)
sl@0
   178
		{
sl@0
   179
        TRgb srcColor(aRgbBuffer[2],aRgbBuffer[1],aRgbBuffer[0]);
sl@0
   180
        if(aShadowing == MAlphaBlend::EShdwBefore)
sl@0
   181
            {
sl@0
   182
		    Shadow(srcColor);
sl@0
   183
            }
sl@0
   184
		TInt pixelValue = pixelPtr[0] * (255 - aMaskBuffer[0]);
sl@0
   185
		TInt srceValue = (((srcColor.Red() << 1) + 
sl@0
   186
                            srcColor.Green() + (srcColor.Green() << 2) + 
sl@0
   187
                            srcColor.Blue()) >> 3) * aMaskBuffer[0];
sl@0
   188
sl@0
   189
		pixelValue += srceValue;
sl@0
   190
		pixelClr =TRgb::_Gray256(pixelValue / 255);
sl@0
   191
        if(aShadowing == MAlphaBlend::EShdwAfter)
sl@0
   192
            {
sl@0
   193
		    Shadow(pixelClr);
sl@0
   194
            }
sl@0
   195
		MapColorToUserDisplayMode(pixelClr);
sl@0
   196
		pixelPtr[0] = TUint8(pixelClr._Gray256());
sl@0
   197
sl@0
   198
		pixelPtr += pixelPtrInc;
sl@0
   199
		aRgbBuffer += 4;
sl@0
   200
		aMaskBuffer++;
sl@0
   201
		}
sl@0
   202
	}
sl@0
   203
sl@0
   204
void CDrawEightBppBitmapGray::WriteRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aRows,TRgb aColor)
sl@0
   205
	{
sl@0
   206
	CDrawEightBppBitmapCommon::WriteRgbMulti(aX,aY,aLength,aRows,TUint8(aColor._Gray256()));
sl@0
   207
	}
sl@0
   208
sl@0
   209
void CDrawEightBppBitmapGray::WriteRgbMultiXOR(TInt aX,TInt aY,TInt aLength,TInt aRows,TRgb aColor)
sl@0
   210
	{
sl@0
   211
	CDrawEightBppBitmapCommon::WriteRgbMultiXOR(aX,aY,aLength,aRows,TUint8(aColor._Gray256()));
sl@0
   212
	}
sl@0
   213
sl@0
   214
void CDrawEightBppBitmapGray::WriteRgbMultiAND(TInt aX,TInt aY,TInt aLength,TInt aRows,TRgb aColor)
sl@0
   215
	{
sl@0
   216
	CDrawEightBppBitmapCommon::WriteRgbMultiAND(aX,aY,aLength,aRows,TUint8(aColor._Gray256()));
sl@0
   217
	}
sl@0
   218
sl@0
   219
void CDrawEightBppBitmapGray::WriteRgbMultiOR(TInt aX,TInt aY,TInt aLength,TInt aRows,TRgb aColor)
sl@0
   220
	{
sl@0
   221
	CDrawEightBppBitmapCommon::WriteRgbMultiOR(aX,aY,aLength,aRows,TUint8(aColor._Gray256()));
sl@0
   222
	}
sl@0
   223
sl@0
   224
void CDrawEightBppBitmapGray::WriteRgbAlphaMulti(TInt aX,TInt aY,TInt aLength,TRgb aColor,const TUint8* aMaskBuffer)
sl@0
   225
	{
sl@0
   226
	DeOrientate(aX,aY);
sl@0
   227
	TUint8* pixelPtr = PixelAddress(aX,aY);
sl@0
   228
	const TInt pixelPtrInc = PixelAddressIncrement();
sl@0
   229
	const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
sl@0
   230
sl@0
   231
	if (iShadowMode)
sl@0
   232
		Shadow(aColor);
sl@0
   233
	
sl@0
   234
	const TInt gray = aColor._Gray256();
sl@0
   235
	while (aMaskBuffer < maskBufferPtrLimit)
sl@0
   236
		{
sl@0
   237
		pixelPtr[0] = TUint8(((gray * aMaskBuffer[0]) + ((255 - aMaskBuffer[0]) * pixelPtr[0])) / 255);
sl@0
   238
sl@0
   239
		pixelPtr += pixelPtrInc;
sl@0
   240
		aMaskBuffer++;
sl@0
   241
		}
sl@0
   242
	}
sl@0
   243
sl@0
   244
void CDrawEightBppBitmapGray::MapColorToUserDisplayMode(TRgb& aColor)
sl@0
   245
	{
sl@0
   246
	switch (iUserDispMode)
sl@0
   247
		{
sl@0
   248
	case EGray2:
sl@0
   249
		aColor = TRgb::_Gray2(aColor._Gray2());
sl@0
   250
		break;
sl@0
   251
	case EGray4:
sl@0
   252
	case EColor16:
sl@0
   253
		aColor = TRgb::_Gray4(aColor._Gray4());
sl@0
   254
		break;
sl@0
   255
	case EGray16:
sl@0
   256
	case EColor256:
sl@0
   257
		aColor = TRgb::_Gray16(aColor._Gray16());
sl@0
   258
		break;
sl@0
   259
	default:
sl@0
   260
		break;
sl@0
   261
		}
sl@0
   262
	}
sl@0
   263
sl@0
   264
void CDrawEightBppBitmapGray::MapBufferToUserDisplayMode(TInt aLength,TUint32* aBuffer)
sl@0
   265
	{
sl@0
   266
	TUint8* bufferPtr = (TUint8*)aBuffer;
sl@0
   267
	const TUint8* bufferLimit = bufferPtr + aLength;
sl@0
   268
sl@0
   269
	switch (iUserDispMode)
sl@0
   270
		{
sl@0
   271
	case EGray2:
sl@0
   272
		while (bufferPtr < bufferLimit)
sl@0
   273
			{
sl@0
   274
			if (*bufferPtr & 0x80)
sl@0
   275
				*bufferPtr++ = 0xff;
sl@0
   276
			else
sl@0
   277
				*bufferPtr++ = 0;
sl@0
   278
			}
sl@0
   279
		break;
sl@0
   280
	case EGray4:
sl@0
   281
	case EColor16:
sl@0
   282
		while (bufferPtr < bufferLimit)
sl@0
   283
			{
sl@0
   284
			TUint8 gray4 = TUint8(*bufferPtr >> 6);
sl@0
   285
			gray4 |= (gray4 << 2);
sl@0
   286
			*bufferPtr++ = TUint8(gray4 | (gray4 << 4));
sl@0
   287
			}
sl@0
   288
		break;
sl@0
   289
	case EGray16:
sl@0
   290
	case EColor256:
sl@0
   291
		while (bufferPtr < bufferLimit)
sl@0
   292
			{
sl@0
   293
			TUint8 gray16 = TUint8(*bufferPtr >> 4);
sl@0
   294
			*bufferPtr++ = TUint8(gray16 | (gray16 << 4));
sl@0
   295
			}
sl@0
   296
		break;
sl@0
   297
	default:
sl@0
   298
		break;
sl@0
   299
		}
sl@0
   300
	}
sl@0
   301
sl@0
   302
TInt CDrawEightBppBitmapGray::WriteRgbOutlineAndShadow(TInt aX, TInt aY, const TInt aLength,
sl@0
   303
	                                   TUint32 aOutlinePenColor, TUint32 aShadowColor,
sl@0
   304
	                                   TUint32 aFillColor, const TUint8* aDataBuffer)
sl@0
   305
	{
sl@0
   306
	//This is non-optimised since this screen mode is rarely used and is usually 
sl@0
   307
	//fast enough without optimisation.
sl@0
   308
	DeOrientate(aX,aY);
sl@0
   309
	TUint8* pixelPtr = PixelAddress(aX,aY);
sl@0
   310
	const TInt pixelPtrInc = LogicalPixelAddressIncrement();
sl@0
   311
	const TUint8* dataBufferPtrLimit = aDataBuffer + aLength;
sl@0
   312
	TInt blendedRedColor;
sl@0
   313
	TInt blendedGreenColor;
sl@0
   314
	TInt blendedBlueColor;
sl@0
   315
	TUint8 index = 0;
sl@0
   316
	TRgb finalColor;
sl@0
   317
sl@0
   318
	TRgb outlinePenColor;
sl@0
   319
	outlinePenColor.SetInternal(aOutlinePenColor);
sl@0
   320
	TRgb shadowColor;
sl@0
   321
	shadowColor.SetInternal(aShadowColor);
sl@0
   322
	TRgb fillColor;
sl@0
   323
	fillColor.SetInternal(aFillColor);
sl@0
   324
sl@0
   325
	const TInt redOutlinePenColor = outlinePenColor.Red();
sl@0
   326
	const TInt redShadowColor = shadowColor.Red();
sl@0
   327
	const TInt redFillColor = fillColor.Red();
sl@0
   328
sl@0
   329
	const TInt greenOutlinePenColor = outlinePenColor.Green();
sl@0
   330
	const TInt greenShadowColor = shadowColor.Green();
sl@0
   331
	const TInt greenFillColor = fillColor.Green();
sl@0
   332
sl@0
   333
	const TInt blueOutlinePenColor = outlinePenColor.Blue();
sl@0
   334
	const TInt blueShadowColor = shadowColor.Blue();
sl@0
   335
	const TInt blueFillColor = fillColor.Blue();
sl@0
   336
	
sl@0
   337
	while (aDataBuffer < dataBufferPtrLimit)
sl@0
   338
		{
sl@0
   339
		index = *aDataBuffer++;
sl@0
   340
		if (255 == FourColorBlendLookup[index][KBackgroundColorIndex])
sl@0
   341
			{
sl@0
   342
			//background colour
sl@0
   343
			//No drawing required so move on to next pixel.
sl@0
   344
			pixelPtr += pixelPtrInc;
sl@0
   345
			continue;
sl@0
   346
			}
sl@0
   347
		else if (255 == FourColorBlendLookup[index][KFillColorIndex])
sl@0
   348
			{
sl@0
   349
			//fill colour
sl@0
   350
			finalColor.SetInternal(aFillColor);
sl@0
   351
			}
sl@0
   352
		else if (255 == FourColorBlendLookup[index][KShadowColorIndex])
sl@0
   353
			{
sl@0
   354
			//Shadow colour
sl@0
   355
			finalColor.SetInternal(aShadowColor);
sl@0
   356
			}
sl@0
   357
		else if (255 == FourColorBlendLookup[index][KOutlineColorIndex])
sl@0
   358
			{
sl@0
   359
			//Outline colour
sl@0
   360
			finalColor.SetInternal(aOutlinePenColor);
sl@0
   361
			}
sl@0
   362
		else
sl@0
   363
			{
sl@0
   364
			TRgb backgroundColor = TRgb::_Gray256(*pixelPtr);
sl@0
   365
	
sl@0
   366
			blendedRedColor = (redOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] + 
sl@0
   367
						   		redShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
sl@0
   368
						  		redFillColor * FourColorBlendLookup[index][KFillColorIndex] + 
sl@0
   369
						  		backgroundColor.Red() * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8;
sl@0
   370
sl@0
   371
			blendedGreenColor = (greenOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] + 
sl@0
   372
								greenShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
sl@0
   373
								greenFillColor * FourColorBlendLookup[index][KFillColorIndex] + 
sl@0
   374
								backgroundColor.Green() * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8;
sl@0
   375
sl@0
   376
			blendedBlueColor = (blueOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] + 
sl@0
   377
								blueShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
sl@0
   378
								blueFillColor * FourColorBlendLookup[index][KFillColorIndex] + 
sl@0
   379
								backgroundColor.Blue() * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8;
sl@0
   380
sl@0
   381
			finalColor = TRgb(blendedRedColor, blendedGreenColor, blendedBlueColor);
sl@0
   382
			}
sl@0
   383
sl@0
   384
		*pixelPtr = TUint8(finalColor._Gray256());
sl@0
   385
		pixelPtr += pixelPtrInc;
sl@0
   386
		}
sl@0
   387
	return KErrNone;
sl@0
   388
	}