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