Update contrib.
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 // CDrawTwelveBppBitmap
20 TInt CDrawTwelveBppBitmap::Construct(TSize aSize)
22 return Construct(aSize, ((aSize.iWidth + 1) & ~1) << 1);
25 TInt CDrawTwelveBppBitmap::Construct(TSize aSize, TInt aStride)
28 return CDrawSixteenBppBitmapCommon::Construct(aSize, aStride);
31 void CDrawTwelveBppBitmap::Shadow(TRgb& aColor)
33 if (iShadowMode & EFade)
34 aColor = FadeRgb(TRgb::_Color4K(aColor._Color4K()));
36 if (iShadowMode & EShadow)
37 aColor = TRgb::_Color4K(ShadowIndex(TUint16(aColor._Color4K())));
40 TUint16 CDrawTwelveBppBitmap::ShadowIndex(TUint16 aColor4KIndex)
42 TInt red = (aColor4KIndex & 0xf00) >> 8;
43 TInt green = (aColor4KIndex & 0x0f0) >> 4;
44 TInt blue = aColor4KIndex & 0x00f;
47 green = Max(0,green-5);
50 return TUint16((red << 8) | (green << 4) | blue);
53 TUint16 CDrawTwelveBppBitmap::FadeIndex(TUint16 aColor4KIndex)
55 return TUint16(FadeRgb(TRgb::_Color4K(aColor4KIndex))._Color4K());
58 TRgb CDrawTwelveBppBitmap::ReadRgbNormal(TInt aX,TInt aY) const
60 return TRgb::_Color4K(*PixelAddress(aX,aY));
63 void CDrawTwelveBppBitmap::WriteRgb(TInt aX,TInt aY,TRgb aColor)
65 *PixelAddress(aX,aY) = TUint16(aColor._Color4K());
68 void CDrawTwelveBppBitmap::WriteBinary(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TRgb aColor)
70 CDrawSixteenBppBitmapCommon::WriteBinary(aX,aY,aData,aLength,aHeight,(TUint16)aColor._Color4K());
73 void CDrawTwelveBppBitmap::WriteBinaryOp(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode)
75 CDrawSixteenBppBitmapCommon::WriteBinaryOp(aX,aY,aData,aLength,aHeight,(TUint16)aColor._Color4K(),aDrawMode);
78 void CDrawTwelveBppBitmap::WriteBinaryLineVertical(TInt aX,TInt aY,TUint32* aData,TInt aHeight,TRgb aColor,TBool aUp)
80 CDrawSixteenBppBitmapCommon::WriteBinaryLineVertical(aX,aY,aData,aHeight,(TUint16)aColor._Color4K(),aUp);
84 MAlphaBlend::WriteRgbAlphaLine() implementation.
85 @see MAlphaBlend::WriteRgbAlphaLine()
87 void CDrawTwelveBppBitmap::WriteRgbAlphaLine(TInt aX, TInt aY, TInt aLength,
88 const TUint8* aRgbBuffer,
89 const TUint8* aMaskBuffer,
90 MAlphaBlend::TShadowing aShadowing,
91 CGraphicsContext::TDrawMode /*aDrawMode*/)
94 TUint16* pixelPtr = PixelAddress(aX,aY);
95 const TInt pixelPtrInc = PixelAddressIncrement();
96 const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
99 while (aMaskBuffer < maskBufferPtrLimit)
101 TRgb srcColor(aRgbBuffer[2],aRgbBuffer[1],aRgbBuffer[0]);
102 if(aShadowing == MAlphaBlend::EShdwBefore)
106 pixelColor = ::AlphaBlend(srcColor,TRgb::_Color4K(pixelPtr[0]),aMaskBuffer[0]);
107 if(aShadowing == MAlphaBlend::EShdwAfter)
111 MapColorToUserDisplayMode(pixelColor);
112 pixelPtr[0] = TUint16(pixelColor._Color4K());
114 pixelPtr += pixelPtrInc;
120 void CDrawTwelveBppBitmap::WriteRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
122 CDrawSixteenBppBitmapCommon::WriteRgbMulti(aX,aY,aLength,aHeight,(TUint16)aColor._Color4K());
125 void CDrawTwelveBppBitmap::WriteRgbMultiXOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
127 CDrawSixteenBppBitmapCommon::WriteRgbMultiXOR(aX,aY,aLength,aHeight,(TUint16)aColor._Color4K());
130 void CDrawTwelveBppBitmap::WriteRgbMultiAND(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
132 CDrawSixteenBppBitmapCommon::WriteRgbMultiAND(aX,aY,aLength,aHeight,(TUint16)aColor._Color4K());
135 void CDrawTwelveBppBitmap::WriteRgbMultiOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
137 CDrawSixteenBppBitmapCommon::WriteRgbMultiOR(aX,aY,aLength,aHeight,(TUint16)aColor._Color4K());
140 void CDrawTwelveBppBitmap::WriteRgbAlphaMulti(TInt aX,TInt aY,TInt aLength,TRgb aColor,const TUint8* aMaskBuffer)
143 TUint16* pixelPtr = PixelAddress(aX,aY);
144 const TInt pixelPtrInc = PixelAddressIncrement();
145 const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
150 const TInt red = aColor.Red();
151 const TInt green = aColor.Green();
152 const TInt blue = aColor.Blue();
153 while (aMaskBuffer < maskBufferPtrLimit)
155 pixelPtr[0] = TUint16(AlphaBlend(red,green,blue,TRgb::_Color4K(pixelPtr[0]),aMaskBuffer[0])._Color4K());
157 pixelPtr += pixelPtrInc;
162 void CDrawTwelveBppBitmap::MapColorToUserDisplayMode(TRgb& aColor)
164 switch (iUserDispMode)
167 aColor = TRgb::_Gray2(aColor._Gray2());
170 aColor = TRgb::_Gray4(aColor._Gray4());
173 aColor = TRgb::_Gray16(aColor._Gray16());
176 aColor = TRgb::_Gray256(aColor._Gray256());
179 aColor = TRgb::Color16(aColor.Color16());
182 aColor = TRgb::Color256(aColor.Color256());
189 void CDrawTwelveBppBitmap::MapBufferToUserDisplayMode(TInt aLength,TUint32* aBuffer)
191 TUint16* bufferPtr = (TUint16*)aBuffer;
192 const TUint16* bufferLimit = bufferPtr + aLength;
195 switch (iUserDispMode)
198 while (bufferPtr < bufferLimit)
200 color = TRgb::_Color4K(*bufferPtr);
201 color = TRgb::_Gray2(color._Gray2());
202 *bufferPtr++ = TUint16(color._Color4K());
206 while (bufferPtr < bufferLimit)
208 color = TRgb::_Color4K(*bufferPtr);
209 color = TRgb::_Gray4(color._Gray4());
210 *bufferPtr++ = TUint16(color._Color4K());
214 case EGray256: // EGray256 can't be done - nearest is EGray16
215 while (bufferPtr < bufferLimit)
217 color = TRgb::_Color4K(*bufferPtr);
218 color = TRgb::_Gray16(color._Gray16());
219 *bufferPtr++ = TUint16(color._Color4K());
223 while (bufferPtr < bufferLimit)
225 color = TRgb::_Color4K(*bufferPtr);
226 color = TRgb::Color16(color.Color16());
227 *bufferPtr++ = TUint16(color._Color4K());
231 while (bufferPtr < bufferLimit)
233 color = TRgb::_Color4K(*bufferPtr);
234 color = TRgb::Color256(color.Color256());
235 *bufferPtr++ = TUint16(color._Color4K());
243 TInt CDrawTwelveBppBitmap::WriteRgbOutlineAndShadow(TInt aX, TInt aY, const TInt aLength,
244 TUint32 aOutlinePenColor, TUint32 aShadowColor,
245 TUint32 aFillColor, const TUint8* aDataBuffer)
248 TUint16* pixelPtr = PixelAddress(aX,aY);
249 const TInt pixelPtrInc = LogicalPixelAddressIncrement();
250 const TUint8* dataBufferPtrLimit = aDataBuffer + aLength;
251 TInt blendedRedColor;
252 TInt blendedGreenColor;
253 TInt blendedBlueColor;
257 //Get red color. Equivalent to TRgb::Red()
258 const TInt redOutlinePenColor = (aOutlinePenColor & 0xff0000) >> 16;
259 const TInt redShadowColor = (aShadowColor & 0xff0000) >> 16;
260 const TInt redFillColor = (aFillColor & 0xff0000) >> 16;
262 //Get green color. Equivalent to TRgb::Green()
263 const TInt greenOutlinePenColor = (aOutlinePenColor & 0xff00) >> 8;
264 const TInt greenShadowColor = (aShadowColor & 0xff00) >> 8;
265 const TInt greenFillColor = (aFillColor & 0xff00) >> 8;
267 //Get blue color. Equivalent to TRgb::Blue()
268 const TInt blueOutlinePenColor = aOutlinePenColor & 0xff;
269 const TInt blueShadowColor = aShadowColor & 0xff;
270 const TInt blueFillColor = aFillColor & 0xff;
272 while (aDataBuffer < dataBufferPtrLimit)
274 index = *aDataBuffer++;
276 if (255 == FourColorBlendLookup[index][KBackgroundColorIndex])
279 //No drawing required so move on to next pixel.
280 pixelPtr += pixelPtrInc;
283 else if (255 == FourColorBlendLookup[index][KFillColorIndex])
285 //Use fill colour to draw
286 finalColor = aFillColor;
288 else if (255 == FourColorBlendLookup[index][KShadowColorIndex])
290 //Use shadow colour to draw
291 finalColor = aShadowColor;
293 else if (255 == FourColorBlendLookup[index][KOutlineColorIndex])
295 //Use outline colour to draw
296 finalColor = aOutlinePenColor;
300 //Get the background pixel colour. Equivalent to TRgb::_Color4K(TInt)
301 TUint32 color = (*pixelPtr & 0xf00) << 8;
302 color |= (*pixelPtr & 0x0f0) << 4;
303 color |= (*pixelPtr & 0x00f);
305 //Equivalent to TRgb::TRgb(TUint32, TInt) except that alpha is not set in background colour
306 //as it is not used for calculating final colour
307 TUint32 backgroundColor = (((color | (color << 4)) & 0x00ffffff));
309 blendedRedColor = (redOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] +
310 redShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
311 redFillColor * FourColorBlendLookup[index][KFillColorIndex] +
312 ((backgroundColor & 0xff0000) >> 16) * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8;
314 blendedGreenColor = (greenOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] +
315 greenShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
316 greenFillColor * FourColorBlendLookup[index][KFillColorIndex] +
317 ((backgroundColor & 0xff00) >> 8) * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8;
319 blendedBlueColor = (blueOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] +
320 blueShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
321 blueFillColor * FourColorBlendLookup[index][KFillColorIndex] +
322 (backgroundColor & 0xff) * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8;
324 //Equivalent to TRgb::TRgb(TUint32)
325 finalColor = (blendedRedColor << 16) | (blendedGreenColor << 8) | blendedBlueColor | 0xff000000;
328 //Convert 32 bit to 4K colour. Equivalent to TRgb::_Color4K(TInt)
329 TInt finalColor4K = (finalColor & 0x0000f0) >> 4;
330 finalColor4K |= (finalColor & 0x00f000) >> 8;
331 finalColor4K |= (finalColor & 0xf00000) >> 12;
333 //Draw the final colour
334 *pixelPtr = finalColor4K;
335 pixelPtr += pixelPtrInc;