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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 // CDrawEightBppBitmapGray
20 TInt CDrawEightBppBitmapGray::Construct(TSize aSize)
22 return Construct(aSize, (aSize.iWidth + 3) & ~3);
25 TInt CDrawEightBppBitmapGray::Construct(TSize aSize, TInt aStride)
28 return CDrawEightBppBitmapCommon::Construct(aSize, aStride);
31 void CDrawEightBppBitmapGray::Shadow(TRgb& aColor)
33 if (iShadowMode & EFade)
34 aColor = TRgb::_Gray256(FadeGray(aColor._Gray256()));
36 if (iShadowMode & EShadow)
38 TInt gray256 = Max(aColor._Gray256() - 85,0);
39 aColor = TRgb::_Gray256(gray256);
43 TUint8 CDrawEightBppBitmapGray::ShadowAndFade(TInt aGray256)
45 if (iShadowMode & EFade)
46 aGray256 = FadeGray(aGray256);
48 if (iShadowMode & EShadow)
49 aGray256 = Max(aGray256 - 85,0);
51 return TUint8(aGray256);
54 TRgb CDrawEightBppBitmapGray::ReadRgbNormal(TInt aX,TInt aY) const
56 return TRgb::_Gray256(*PixelAddress(aX,aY));
59 void CDrawEightBppBitmapGray::ShadowArea(const TRect& aRect)
61 const TRect rect(DeOrientate(aRect));
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));
66 const TInt longWidth = iLongWidth;
67 TUint8* pixelPtr = PixelAddress(rect.iTl.iX,rect.iTl.iY);
68 const TUint8* pixelRowPtrLimit = pixelPtr + (rect.Height() * longWidth);
70 if (iShadowMode & EFade)
72 TUint8* pixelRowPtr = pixelPtr;
73 TUint8* pixelPtrLimit = pixelPtr + rect.Width();
75 while (pixelRowPtr < pixelRowPtrLimit)
77 TUint8* tempPixelPtr = pixelRowPtr;
79 while (tempPixelPtr < pixelPtrLimit)
81 *tempPixelPtr = FadeGray(*tempPixelPtr);
85 pixelRowPtr += longWidth;
86 pixelPtrLimit += longWidth;
90 if (iShadowMode & EShadow)
92 TUint8* pixelRowPtr = pixelPtr;
93 TUint8* pixelPtrLimit = pixelPtr + rect.Width();
95 while (pixelRowPtr < pixelRowPtrLimit)
97 TUint8* tempPixelPtr = pixelRowPtr;
99 while (tempPixelPtr < pixelPtrLimit)
101 *tempPixelPtr = TUint8(Max(*tempPixelPtr - 85,0));
105 pixelRowPtr += longWidth;
106 pixelPtrLimit += longWidth;
111 void CDrawEightBppBitmapGray::ShadowBuffer(TInt aLength,TUint32* aBuffer)
113 __ASSERT_DEBUG(aLength>0,Panic(EScreenDriverPanicInvalidParameter));
114 __ASSERT_DEBUG(aBuffer!=NULL,Panic(EScreenDriverPanicInvalidParameter));
116 TUint8* limit = ((TUint8*)aBuffer) + aLength;
118 if (iShadowMode & EFade)
120 TUint8* buffer = (TUint8*)aBuffer;
122 while(buffer < limit)
124 *buffer = FadeGray(*buffer);
129 if (iShadowMode & EShadow)
131 TUint8* buffer = (TUint8*)aBuffer;
133 while(buffer < limit)
135 *buffer = TUint8(Max(*buffer - 85,0));
141 void CDrawEightBppBitmapGray::WriteRgb(TInt aX,TInt aY,TRgb aColor)
143 CDrawEightBppBitmapCommon::WriteRgb(aX,aY,TUint8(aColor._Gray256()));
146 void CDrawEightBppBitmapGray::WriteBinary(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TRgb aColor)
148 CDrawEightBppBitmapCommon::WriteBinary(aX,aY,aData,aLength,aHeight,TUint8(aColor._Gray256()));
151 void CDrawEightBppBitmapGray::WriteBinaryOp(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode)
153 CDrawEightBppBitmapCommon::WriteBinaryOp(aX,aY,aData,aLength,aHeight,TUint8(aColor._Gray256()),aDrawMode);
156 void CDrawEightBppBitmapGray::WriteBinaryLineVertical(TInt aX,TInt aY,TUint32* aData,TInt aLength,TRgb aColor,TBool aUp)
158 CDrawEightBppBitmapCommon::WriteBinaryLineVertical(aX,aY,aData,aLength,TUint8(aColor._Gray256()),aUp);
162 MAlphaBlend::WriteRgbAlphaLine() implementation.
163 @see MAlphaBlend::WriteRgbAlphaLine()
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*/)
172 TUint8* pixelPtr = PixelAddress(aX,aY);
173 const TInt pixelPtrInc = LogicalPixelAddressIncrement();
174 const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
177 while (aMaskBuffer < maskBufferPtrLimit)
179 TRgb srcColor(aRgbBuffer[2],aRgbBuffer[1],aRgbBuffer[0]);
180 if(aShadowing == MAlphaBlend::EShdwBefore)
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];
189 pixelValue += srceValue;
190 pixelClr =TRgb::_Gray256(pixelValue / 255);
191 if(aShadowing == MAlphaBlend::EShdwAfter)
195 MapColorToUserDisplayMode(pixelClr);
196 pixelPtr[0] = TUint8(pixelClr._Gray256());
198 pixelPtr += pixelPtrInc;
204 void CDrawEightBppBitmapGray::WriteRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aRows,TRgb aColor)
206 CDrawEightBppBitmapCommon::WriteRgbMulti(aX,aY,aLength,aRows,TUint8(aColor._Gray256()));
209 void CDrawEightBppBitmapGray::WriteRgbMultiXOR(TInt aX,TInt aY,TInt aLength,TInt aRows,TRgb aColor)
211 CDrawEightBppBitmapCommon::WriteRgbMultiXOR(aX,aY,aLength,aRows,TUint8(aColor._Gray256()));
214 void CDrawEightBppBitmapGray::WriteRgbMultiAND(TInt aX,TInt aY,TInt aLength,TInt aRows,TRgb aColor)
216 CDrawEightBppBitmapCommon::WriteRgbMultiAND(aX,aY,aLength,aRows,TUint8(aColor._Gray256()));
219 void CDrawEightBppBitmapGray::WriteRgbMultiOR(TInt aX,TInt aY,TInt aLength,TInt aRows,TRgb aColor)
221 CDrawEightBppBitmapCommon::WriteRgbMultiOR(aX,aY,aLength,aRows,TUint8(aColor._Gray256()));
224 void CDrawEightBppBitmapGray::WriteRgbAlphaMulti(TInt aX,TInt aY,TInt aLength,TRgb aColor,const TUint8* aMaskBuffer)
227 TUint8* pixelPtr = PixelAddress(aX,aY);
228 const TInt pixelPtrInc = PixelAddressIncrement();
229 const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
234 const TInt gray = aColor._Gray256();
235 while (aMaskBuffer < maskBufferPtrLimit)
237 pixelPtr[0] = TUint8(((gray * aMaskBuffer[0]) + ((255 - aMaskBuffer[0]) * pixelPtr[0])) / 255);
239 pixelPtr += pixelPtrInc;
244 void CDrawEightBppBitmapGray::MapColorToUserDisplayMode(TRgb& aColor)
246 switch (iUserDispMode)
249 aColor = TRgb::_Gray2(aColor._Gray2());
253 aColor = TRgb::_Gray4(aColor._Gray4());
257 aColor = TRgb::_Gray16(aColor._Gray16());
264 void CDrawEightBppBitmapGray::MapBufferToUserDisplayMode(TInt aLength,TUint32* aBuffer)
266 TUint8* bufferPtr = (TUint8*)aBuffer;
267 const TUint8* bufferLimit = bufferPtr + aLength;
269 switch (iUserDispMode)
272 while (bufferPtr < bufferLimit)
274 if (*bufferPtr & 0x80)
282 while (bufferPtr < bufferLimit)
284 TUint8 gray4 = TUint8(*bufferPtr >> 6);
285 gray4 |= (gray4 << 2);
286 *bufferPtr++ = TUint8(gray4 | (gray4 << 4));
291 while (bufferPtr < bufferLimit)
293 TUint8 gray16 = TUint8(*bufferPtr >> 4);
294 *bufferPtr++ = TUint8(gray16 | (gray16 << 4));
302 TInt CDrawEightBppBitmapGray::WriteRgbOutlineAndShadow(TInt aX, TInt aY, const TInt aLength,
303 TUint32 aOutlinePenColor, TUint32 aShadowColor,
304 TUint32 aFillColor, const TUint8* aDataBuffer)
306 //This is non-optimised since this screen mode is rarely used and is usually
307 //fast enough without optimisation.
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;
318 TRgb outlinePenColor;
319 outlinePenColor.SetInternal(aOutlinePenColor);
321 shadowColor.SetInternal(aShadowColor);
323 fillColor.SetInternal(aFillColor);
325 const TInt redOutlinePenColor = outlinePenColor.Red();
326 const TInt redShadowColor = shadowColor.Red();
327 const TInt redFillColor = fillColor.Red();
329 const TInt greenOutlinePenColor = outlinePenColor.Green();
330 const TInt greenShadowColor = shadowColor.Green();
331 const TInt greenFillColor = fillColor.Green();
333 const TInt blueOutlinePenColor = outlinePenColor.Blue();
334 const TInt blueShadowColor = shadowColor.Blue();
335 const TInt blueFillColor = fillColor.Blue();
337 while (aDataBuffer < dataBufferPtrLimit)
339 index = *aDataBuffer++;
340 if (255 == FourColorBlendLookup[index][KBackgroundColorIndex])
343 //No drawing required so move on to next pixel.
344 pixelPtr += pixelPtrInc;
347 else if (255 == FourColorBlendLookup[index][KFillColorIndex])
350 finalColor.SetInternal(aFillColor);
352 else if (255 == FourColorBlendLookup[index][KShadowColorIndex])
355 finalColor.SetInternal(aShadowColor);
357 else if (255 == FourColorBlendLookup[index][KOutlineColorIndex])
360 finalColor.SetInternal(aOutlinePenColor);
364 TRgb backgroundColor = TRgb::_Gray256(*pixelPtr);
366 blendedRedColor = (redOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] +
367 redShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
368 redFillColor * FourColorBlendLookup[index][KFillColorIndex] +
369 backgroundColor.Red() * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8;
371 blendedGreenColor = (greenOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] +
372 greenShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
373 greenFillColor * FourColorBlendLookup[index][KFillColorIndex] +
374 backgroundColor.Green() * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8;
376 blendedBlueColor = (blueOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] +
377 blueShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
378 blueFillColor * FourColorBlendLookup[index][KFillColorIndex] +
379 backgroundColor.Blue() * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8;
381 finalColor = TRgb(blendedRedColor, blendedGreenColor, blendedBlueColor);
384 *pixelPtr = TUint8(finalColor._Gray256());
385 pixelPtr += pixelPtrInc;