Update contrib.
1 // Copyright (c) 2004-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.
16 #include <graphics/lookuptable.h>
17 #include <graphics/blendingalgorithms.h>
19 #include "BitDrawInterfaceId.h"
21 FORCEINLINE void BlendFromRBandG(TUint32 *aPixelPtr, TUint32 aSrcRB, TUint32 aSrcG, TUint32 aSrcAlpha, TUint32 aMaskX2)
23 const TUint32 d = *aPixelPtr;
24 const TUint32 d_rb = d & 0x00FF00FF;
25 const TUint32 rb = ((((aSrcAlpha * ((0x01000100 + aSrcRB) - d_rb)) >> 8) + d_rb) - aMaskX2) & 0x00FF00FF;
27 const TInt d_g = (d & 0xFF00) >> 8;
28 const TInt g = ((aSrcAlpha * (aSrcG - d_g)) >> 8) + d_g;
30 *aPixelPtr = rb | (g<<8) | 0xff000000;
33 /**Initializes iSize, iDrawRect, iLongWidth, iScanLineBytes, iScanlineWords data members.
34 It should be called every time when iSize is going to be changed - from Construct().
36 @param aSize Physical screen size in pixels.
37 @panic EScreenDriverPanicInvalidSize - Invalid aSize parameter. This might happen if the
38 device is scaled and the scaling origin goes outside physical drawing rectangle. */
39 void CDrawThirtyTwoBppBitmapCommon::SetSize(const TSize& aSize)
41 CDrawBitmap::SetSize(aSize);
42 __ASSERT_DEBUG(iSize == aSize, User::Invariant());
43 iLongWidth = iSize.iWidth;
44 iScanLineWords = iSize.iWidth;
47 TInt CDrawThirtyTwoBppBitmapCommon::Construct(TSize aSize, TInt aStride)
50 CDrawBitmap::SetSize(aSize);
51 __ASSERT_DEBUG(iSize == aSize, User::Invariant());
54 iLongWidth = aStride >> 2;
55 if (iLongWidth < aSize.iWidth)
57 iScanLineWords = iLongWidth;
58 TInt size = Max(aSize.iWidth,aSize.iHeight) << 2;
61 iScanLineBuffer = (TUint32*)(User::Heap().Alloc(size));
62 if (iScanLineBuffer == NULL)
67 void CDrawThirtyTwoBppBitmapCommon::Shadow(TRgb& aColor)
69 TUint32 value = aColor.Internal();
70 const TInt alpha = value >> 24;
72 if (iShadowMode & EFade)
74 #if defined(SYMBIAN_USE_FAST_FADING)
75 value = ((value >> 1) & ~0x00808080) + (SYMBIAN_USE_FAST_FADING);
77 const TInt wordFadeMapOffset = ((iFadeMapOffset & 0xff) << 16) | (iFadeMapOffset & 0xff);
78 const TInt rb = ((((value & 0x00ff00ff) * iFadeMapFactor) >> 8) + wordFadeMapOffset) & 0x00ff00ff;
79 const TInt g = ((((value & 0x0000ff00) * iFadeMapFactor) >> 16) + iFadeMapOffset) << 8;
84 if (iShadowMode & EShadow)
86 const TInt r = (value & 0x00c00000) ? ((value & 0x00ff0000)-0x00400000) : 0;
87 const TInt g = (value & 0x0000c000) ? ((value & 0x0000ff00)-0x00004000) : 0;
88 const TInt b = (value & 0x000000c0) ? ((value & 0x000000ff)-0x00000040) : 0;
92 aColor = TRgb(value,alpha);
95 void CDrawThirtyTwoBppBitmapCommon::Shadow(TUint32& aColor)
97 // aColor is in the format indicated by ScanLineDisplayMode(), which we
98 // assume is EColor16MAP here. If not, this function must be overridden.
99 const TInt alpha = (aColor >> 24) + 1;
100 TUint32 value = aColor & 0x00ffffff;
101 if (iShadowMode & EFade)
103 #if defined(SYMBIAN_USE_FAST_FADING)
104 const TUint32 fast_fade_offset = NonPMA2PMAPixel((aColor & 0xff000000) | SYMBIAN_USE_FAST_FADING) & 0x00ffffff;
105 value = ((value >> 1) & ~0x00808080) + (fast_fade_offset);
107 const TInt fadeMapOffset = ((alpha * iFadeMapOffset) >> 8) & 0xff;
108 const TInt wordFadeMapOffset = ((fadeMapOffset) << 16) | (fadeMapOffset);
109 const TInt rb = ((((value & 0x00ff00ff) * iFadeMapFactor) >> 8) + wordFadeMapOffset) & 0x00ff00ff;
110 const TInt g = ((((value & 0x0000ff00) * iFadeMapFactor) >> 16) + fadeMapOffset) << 8;
115 if (iShadowMode & EShadow)
117 const TInt uLimit = ((0x40) * alpha) >> 8;
118 TInt r = (value >> 16) & 0xff;
119 r = (r > uLimit) ? (r-uLimit) : 0;
120 TInt g = (value >> 8) & 0xff;
121 g = (g > uLimit) ? (g - uLimit) : 0;
122 TInt b = value & 0xff;
123 b = (b > uLimit) ? (b - uLimit) : 0;
124 value = (r << 16) | (g << 8) | b;
126 // alpha is unchanged.
127 aColor = (aColor & 0xff000000) | value;
130 TUint8 CDrawThirtyTwoBppBitmapCommon::ShadowAndFade(TInt aComponent)
132 if (iShadowMode & EFade)
133 aComponent = FadeGray(aComponent);
135 if (iShadowMode & EShadow)
136 aComponent = ShadowComponent(aComponent);
138 return TUint8(aComponent);
141 TUint8 CDrawThirtyTwoBppBitmapCommon::ShadowComponent(TInt aRgbComponent)
143 return TUint8(Max(0,aRgbComponent-0x40));
146 void CDrawThirtyTwoBppBitmapCommon::InvertBuffer(TInt aLength,TUint32* aBuffer)
148 __ASSERT_DEBUG(aLength>0,Panic(EScreenDriverPanicOutOfBounds));
149 __ASSERT_DEBUG(aBuffer,Panic(EScreenDriverPanicNullPointer));
151 TUint32* limit = aBuffer + aLength;
153 while (aBuffer < limit)
155 *aBuffer++ ^= 0x00ffffff;
159 void CDrawThirtyTwoBppBitmapCommon::ReadLine(TInt aX,TInt aY,TInt aLength,TAny* aBuffer) const
161 const TUint32* pixelPtr = PixelAddress(aX,aY);
163 if (iOrientation == EOrientationNormal)
164 Mem::Copy(aBuffer,pixelPtr,aLength << 2);
167 const TInt pixelPtrInc = PixelAddressIncrement();
169 TUint32* bufferPtr = static_cast <TUint32*> (aBuffer);
170 const TUint32* bufferPtrLimit = bufferPtr + aLength;
172 while (bufferPtr < bufferPtrLimit)
174 *bufferPtr++ = *pixelPtr;
175 pixelPtr += pixelPtrInc;
180 TRgb CDrawThirtyTwoBppBitmapCommon::ReadRgbNormal(TInt aX,TInt aY) const
182 return RgbColor(*PixelAddress(aX,aY));
185 void CDrawThirtyTwoBppBitmapCommon::ShadowArea(const TRect& aRect)
187 const TRect rect(DeOrientate(aRect));
189 __ASSERT_DEBUG(rect.iTl.iX>=0 && rect.iBr.iX<=iSize.iWidth,Panic(EScreenDriverPanicOutOfBounds));
190 __ASSERT_DEBUG(rect.iTl.iY>=0 && rect.iBr.iY<=iSize.iHeight,Panic(EScreenDriverPanicOutOfBounds));
192 TUint32* pixelPtr = PixelAddress(rect.iTl.iX,rect.iTl.iY);
193 TUint32* pixelRowPtrLimit = pixelPtr + (rect.Height() * iScanLineWords);
195 TUint32* pixelRowPtr = pixelPtr;
196 TUint32* pixelPtrLimit = pixelPtr + rect.Width();
198 if (iShadowMode & EFade)
200 #if !defined(SYMBIAN_USE_FAST_FADING)
201 const TInt wordFadeMapOffset = ((iFadeMapOffset & 0xff) << 16) | (iFadeMapOffset & 0xff);
203 while (pixelRowPtr < pixelRowPtrLimit)
205 TUint32* tempPixelPtr = pixelRowPtr;
207 while (tempPixelPtr < pixelPtrLimit)
209 #if defined(SYMBIAN_USE_FAST_FADING)
210 *tempPixelPtr++ = 0xff000000 | ((((*tempPixelPtr) >> 1) & ~0x00808080) + (SYMBIAN_USE_FAST_FADING));
212 const TUint32 color = *tempPixelPtr;
213 const TInt rb = ((((color & 0x00ff00ff) * iFadeMapFactor) >> 8) + wordFadeMapOffset) & 0x00ff00ff;
214 const TInt g = ((((color & 0x0000ff00) * iFadeMapFactor) >> 16) + iFadeMapOffset) << 8;
215 *tempPixelPtr++ = 0xff000000 | rb | g;
219 pixelRowPtr += iScanLineWords;
220 pixelPtrLimit += iScanLineWords;
224 if (iShadowMode & EShadow)
226 pixelRowPtr = pixelPtr;
227 pixelPtrLimit = pixelPtr + rect.Width();
228 while (pixelRowPtr < pixelRowPtrLimit)
230 TUint32* tempPixelPtr = pixelRowPtr;
232 while (tempPixelPtr < pixelPtrLimit)
234 const TUint32 color = *tempPixelPtr;
235 const TInt r = (color & 0x00c00000) ? ((color & 0x00ff0000)-0x00400000) : 0;
236 const TInt g = (color & 0x0000c000) ? ((color & 0x0000ff00)-0x00004000) : 0;
237 const TInt b = (color & 0x000000c0) ? ((color & 0x000000ff)-0x00000040) : 0;
238 *tempPixelPtr++ = 0xff000000 | r | g | b;
241 pixelRowPtr += iScanLineWords;
242 pixelPtrLimit += iScanLineWords;
247 void CDrawThirtyTwoBppBitmapCommon::ShadowBuffer(TInt aLength,TUint32* aBuffer)
249 __ASSERT_DEBUG(aLength>0,Panic(EScreenDriverPanicZeroLength));
250 __ASSERT_DEBUG(aBuffer,Panic(EScreenDriverPanicNullPointer));
252 TUint32* limit = aBuffer + aLength;
254 while (aBuffer < limit)
258 void CDrawThirtyTwoBppBitmapCommon::WriteRgb(TInt aX,TInt aY,TRgb aColor)
260 TUint8* componentPtr = reinterpret_cast <TUint8*> (PixelAddress(aX,aY));
261 const TInt sourceAlpha = aColor.Alpha();
265 if(sourceAlpha != 0xff)
267 aColor = AlphaBlend(aColor.Red(), aColor.Green(), aColor.Blue(), TRgb(componentPtr[2], componentPtr[1], componentPtr[0]), sourceAlpha);
270 componentPtr[0] = TUint8(aColor.Blue());
271 componentPtr[1] = TUint8(aColor.Green());
272 componentPtr[2] = TUint8(aColor.Red());
275 void CDrawThirtyTwoBppBitmapCommon::WriteBinary(TInt aX,TInt aY,TUint32* aBuffer,TInt aLength,TInt aHeight,TRgb aColor)
277 const TInt sourceAlpha = aColor.Alpha();
287 case EOrientationNormal:
290 rowInc = iScanLineWords;
293 case EOrientationRotated90:
295 pixelInc = iScanLineWords;
299 case EOrientationRotated180:
302 rowInc = -iScanLineWords;
305 default: // EOrientationRotated270
307 pixelInc = -iScanLineWords;
312 const TUint32* dataLimit = aBuffer + aHeight;
313 const TUint32 dataMaskLimit = (aLength < 32) ? 1 << aLength : 0;
315 TUint32* pixelPtr = PixelAddress(aX,aY);
317 if(sourceAlpha == 255) //we split code on two parts because of performance reasons
319 TInt color = Color(aColor);
320 while (aBuffer < dataLimit)
322 TUint32 dataWord = *aBuffer++;
323 TUint32 dataMask = 1;
324 TUint32* tempPixelPtr = pixelPtr;
326 while (dataMask != dataMaskLimit)
328 if(dataWord & dataMask)
330 *tempPixelPtr = color;
333 tempPixelPtr += pixelInc;
340 else //sourceAlpha != 255
342 const TUint32 sourceInternal=aColor.Internal();
343 const TUint32 s_rb = sourceInternal & 0x00FF00FF;
344 const TUint32 s_g = (sourceInternal & 0xFF00) >> 8;
345 const TUint32 mask2 = sourceAlpha | (sourceAlpha << 16);
346 while (aBuffer < dataLimit)
348 TUint32 dataWord = *aBuffer++;
349 TUint32 dataMask = 1;
350 TUint32* tempPixelPtr = pixelPtr;
352 while (dataMask != dataMaskLimit)
354 if (dataWord & dataMask)
356 BlendFromRBandG(tempPixelPtr,s_rb,s_g,sourceAlpha,mask2);
359 tempPixelPtr += pixelInc;
368 void CDrawThirtyTwoBppBitmapCommon::WriteBinaryOp(TInt aX,TInt aY,TUint32* aBuffer,TInt aLength,TInt aHeight,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode)
374 TUint32* pixelPtr = PixelAddress(aX,aY);
376 const TUint32* dataPtrLimit = aBuffer + aHeight;
377 const TUint32 dataMaskLimit = (aLength < 32) ? 1 << aLength : 0;
382 if (iOrientation == EOrientationNormal)
385 rowInc = iScanLineWords;
387 else if (iOrientation == EOrientationRotated90)
389 pixelInc = iScanLineWords;
392 else if (iOrientation == EOrientationRotated180)
395 rowInc = -iScanLineWords;
397 else // EOrientationRotated270
399 pixelInc = -iScanLineWords;
403 TInt color = Color(aColor);// & 0x00FFFFFF;
407 while (aBuffer < dataPtrLimit)
409 TUint32 dataWord = *aBuffer++;
410 TUint32 dataMask = 1;
411 TUint32* tempPixelPtr = pixelPtr;
413 while (dataMask != dataMaskLimit)
415 if(dataWord & dataMask)
417 if(aDrawMode==CGraphicsContext::EDrawModeXOR)
419 *tempPixelPtr ^= color;
421 else if(aDrawMode==CGraphicsContext::EDrawModeAND)
423 *tempPixelPtr &= color;
425 else if(aDrawMode==CGraphicsContext::EDrawModeOR)
427 *tempPixelPtr |= color;
431 tempPixelPtr += pixelInc;
438 else if (aDrawMode == CGraphicsContext::EDrawModeAND)
440 while (aBuffer < dataPtrLimit)
442 TUint32 dataWord = *aBuffer++;
443 TUint32 dataMask = 1;
444 TUint32* tempPixelPtr = pixelPtr;
446 while (dataMask != dataMaskLimit)
448 if(dataWord & dataMask)
453 tempPixelPtr += pixelInc;
462 void CDrawThirtyTwoBppBitmapCommon::WriteBinaryLineVertical(TInt aX,TInt aY,TUint32* aBuffer,TInt aHeight,TRgb aColor,TBool aUp)
464 const TInt sourceAlpha = aColor.Alpha();
469 TInt scanlineWordLength;
471 if (iOrientation == EOrientationNormal)
472 scanlineWordLength = iScanLineWords;
473 else if (iOrientation == EOrientationRotated90)
474 scanlineWordLength = -1;
475 else if (iOrientation == EOrientationRotated180)
476 scanlineWordLength = -iScanLineWords;
477 else // EOrientationRotated270
478 scanlineWordLength = 1;
481 scanlineWordLength = -scanlineWordLength;
483 TUint32* pixelPtr = PixelAddress(aX,aY);
484 const TUint32* pixelPtrLimit = pixelPtr + (aHeight * scanlineWordLength);
485 TUint32 dataWord = *aBuffer;
486 TUint32 dataMask = 1;
488 if(sourceAlpha == 255) //we split code on two parts because of performance reasons
490 TInt color = Color(aColor);
491 while(pixelPtr != pixelPtrLimit)
500 if(dataWord & dataMask)
506 pixelPtr += scanlineWordLength;
509 else //sourceAlpha != 255
511 const TUint32 sourceInternal=aColor.Internal();
512 const TUint32 s_rb = sourceInternal & 0x00FF00FF;
513 const TUint32 s_g = (sourceInternal & 0xFF00) >> 8;
514 const TUint32 mask2 = sourceAlpha | (sourceAlpha << 16);
515 while(pixelPtr != pixelPtrLimit)
524 if(dataWord & dataMask)
526 BlendFromRBandG(pixelPtr, s_rb, s_g, sourceAlpha, mask2);
530 pixelPtr += scanlineWordLength;
535 void CDrawThirtyTwoBppBitmapCommon::WriteLine(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
537 TUint32* pixelPtr = PixelAddress(aX,aY);
539 if (iOrientation == EOrientationNormal)
540 Mem::Copy(pixelPtr,aBuffer,aLength << 2);
543 const TInt pixelPtrInc = PixelAddressIncrement();
545 TUint32* bufferPtrLimit = aBuffer + aLength;
547 while (aBuffer < bufferPtrLimit)
549 *pixelPtr = *aBuffer++;
550 pixelPtr += pixelPtrInc;
555 void CDrawThirtyTwoBppBitmapCommon::WriteLineXOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
557 TUint32* pixelPtr = PixelAddress(aX,aY);
558 const TInt pixelPtrInc = PixelAddressIncrement();
560 TUint32* bufferPtrLimit = aBuffer + aLength;
562 while (aBuffer < bufferPtrLimit)
564 *pixelPtr ^= *aBuffer++;
565 pixelPtr += pixelPtrInc;
569 void CDrawThirtyTwoBppBitmapCommon::WriteLineAND(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
571 TUint32* pixelPtr = PixelAddress(aX,aY);
572 const TInt pixelPtrInc = PixelAddressIncrement();
574 TUint32* bufferPtrLimit = aBuffer + aLength;
576 while (aBuffer < bufferPtrLimit)
578 *pixelPtr &= *aBuffer++;
579 pixelPtr += pixelPtrInc;
583 void CDrawThirtyTwoBppBitmapCommon::WriteLineOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
585 TUint32* pixelPtr = PixelAddress(aX,aY);
586 const TInt pixelPtrInc = PixelAddressIncrement();
588 TUint32* bufferPtrLimit = aBuffer + aLength;
590 while (aBuffer < bufferPtrLimit)
592 *pixelPtr |= *aBuffer++;
593 pixelPtr += pixelPtrInc;
598 MAlphaBlend::WriteRgbAlphaLine() implementation.
599 @see MAlphaBlend::WriteRgbAlphaLine()
601 void CDrawThirtyTwoBppBitmapCommon::WriteRgbAlphaLine(TInt aX, TInt aY, TInt aLength,
602 const TUint8* aRgbBuffer,
603 const TUint8* aMaskBuffer,
604 MAlphaBlend::TShadowing aShadowing,
605 CGraphicsContext::TDrawMode /*aDrawMode*/)
608 TUint32* pixelPtr = PixelAddress(aX,aY);
609 const TInt pixelPtrInc = PixelAddressIncrement();
610 const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
612 while (aMaskBuffer < maskBufferPtrLimit)
614 TRgb srcColor(aRgbBuffer[2],aRgbBuffer[1],aRgbBuffer[0]);// !! we don't have any alpha information for the source, so assume opaque
617 if(aShadowing == MAlphaBlend::EShdwBefore)
621 TUint8* componentPtr = reinterpret_cast <TUint8*> (pixelPtr);
622 if(aMaskBuffer[0] != 0xff)
624 srcColor = AlphaBlend(srcColor.Red(), srcColor.Green(), srcColor.Blue(), TRgb(componentPtr[2], componentPtr[1], componentPtr[0]), aMaskBuffer[0]);
626 if(aShadowing == MAlphaBlend::EShdwAfter)
630 MapColorToUserDisplayMode(srcColor);
631 componentPtr[0] = TUint8(srcColor.Blue());
632 componentPtr[1] = TUint8(srcColor.Green());
633 componentPtr[2] = TUint8(srcColor.Red());
635 pixelPtr += pixelPtrInc;
641 void CDrawThirtyTwoBppBitmapCommon::WriteRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
643 TUint32* pixelPtr = PixelAddress(aX,aY);
644 TUint32* pixelRowPtrLimit = pixelPtr + (aHeight * iScanLineWords);
646 TInt color = Color(aColor);
648 while (pixelPtr < pixelRowPtrLimit)
650 MemFillTUint32(pixelPtr, aLength, color);
651 pixelPtr += iScanLineWords;
655 void CDrawThirtyTwoBppBitmapCommon::WriteRgbMultiXOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
657 TUint32* pixelPtr = PixelAddress(aX,aY);
658 TUint32* pixelPtrLimit = pixelPtr + aLength;
659 TUint32* pixelRowPtrLimit = pixelPtr + (aHeight * iScanLineWords);
660 TInt color = Color(aColor);
662 while (pixelPtr < pixelRowPtrLimit)
664 for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
666 *tempPixelPtr ^= color;
669 pixelPtr += iScanLineWords;
670 pixelPtrLimit += iScanLineWords;
674 void CDrawThirtyTwoBppBitmapCommon::WriteRgbMultiAND(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
676 TUint32* pixelPtr = PixelAddress(aX,aY);
677 TUint32* pixelPtrLimit = pixelPtr + aLength;
678 TUint32* pixelRowPtrLimit = pixelPtr + (aHeight * iScanLineWords);
679 TInt color = Color(aColor);
681 while (pixelPtr < pixelRowPtrLimit)
683 for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
685 *tempPixelPtr &= color;
688 pixelPtr += iScanLineWords;
689 pixelPtrLimit += iScanLineWords;
693 void CDrawThirtyTwoBppBitmapCommon::WriteRgbMultiOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
695 TUint32* pixelPtr = PixelAddress(aX,aY);
696 TUint32* pixelPtrLimit = pixelPtr + aLength;
697 TUint32* pixelRowPtrLimit = pixelPtr + (aHeight * iScanLineWords);
698 TInt color = Color(aColor);
700 while (pixelPtr < pixelRowPtrLimit)
702 for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
704 *tempPixelPtr |= color;
707 pixelPtr += iScanLineWords;
708 pixelPtrLimit += iScanLineWords;
712 inline TUint32 OptimizedBlend32(TInt aPrimaryRed,TInt aPrimaryGreen,TInt aPrimaryBlue,TUint32 aSecondary,TUint8 aAlphaValue)
714 __ASSERT_DEBUG(!(aPrimaryRed>>8) && !(aPrimaryGreen>>8) && !(aPrimaryBlue>>8) && !(aAlphaValue>>8),
715 Panic(EScreenDriverPanicAlphaBlendInvariant));
717 if(aAlphaValue == 0xff)
719 return (aPrimaryBlue + (aPrimaryGreen<<8) + (aPrimaryRed<<16)) | 0xff000000;
723 const TUint32 alphaValue = (aAlphaValue << 8) + aAlphaValue;
725 const TInt r2 = (aSecondary & 0x00ff0000) >> 16;
726 const TInt g2 = (aSecondary & 0x0000ff00) >> 8;
727 const TInt b2 = aSecondary & 0x000000ff;
729 const TInt r3 = ((alphaValue * (aPrimaryRed - r2)) >> 16) + r2;
730 const TInt g3 = ((alphaValue * (aPrimaryGreen - g2)) >> 16) + g2;
731 const TInt b3 = ((alphaValue * (aPrimaryBlue - b2)) >> 16) + b2;
733 return (b3 & 0xFF) | ((g3<<8) & 0xFF00) | ((r3<<16) & 0xFF0000) | 0xFF000000;
737 void CDrawThirtyTwoBppBitmapCommon::WriteRgbAlphaMulti(TInt aX,TInt aY,TInt aLength,TRgb aColor,const TUint8* aMaskBuffer)
739 const TUint32 sourceAlpha = aColor.Alpha();
740 if (sourceAlpha==0 || aLength<=0)
743 TUint32* pixelPtr = PixelAddress(aX,aY);
744 const TInt pixelPtrInc = PixelAddressIncrement();
745 const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
750 const TUint32 sourceInternal=aColor.Internal();
751 const TUint32 s_rb = sourceInternal & 0x00FF00FF;
752 const TUint32 s_g = (sourceInternal & 0xFF00) >> 8;
753 if (sourceAlpha==0xFF)
755 while (aMaskBuffer < maskBufferPtrLimit)
757 const TUint32 maskAlpha=*aMaskBuffer;
761 *pixelPtr = sourceInternal;
763 BlendFromRBandG(pixelPtr,s_rb,s_g,maskAlpha,maskAlpha|(maskAlpha<<16));
765 pixelPtr += pixelPtrInc;
771 while (aMaskBuffer < maskBufferPtrLimit)
773 const TUint32 maskAlpha=*aMaskBuffer;
776 TUint blendAlpha = sourceAlpha;
778 blendAlpha=((maskAlpha+1) * sourceAlpha)>>8;
779 BlendFromRBandG(pixelPtr,s_rb,s_g,blendAlpha,blendAlpha|(blendAlpha<<16));
781 pixelPtr += pixelPtrInc;
787 void CDrawThirtyTwoBppBitmapCommon::MapColorToUserDisplayMode(TRgb& aColor)
789 const TInt alpha = aColor.Alpha();
790 switch (iUserDispMode)
793 aColor = TRgb::_Gray2(aColor._Gray2());
796 aColor = TRgb::_Gray4(aColor._Gray4());
799 aColor = TRgb::_Gray16(aColor._Gray16());
802 aColor = TRgb::_Gray256(aColor._Gray256());
805 aColor = TRgb::Color16(aColor.Color16());
808 aColor = TRgb::Color256(aColor.Color256());
811 aColor = TRgb::_Color4K(aColor._Color4K());
814 aColor = TRgb::_Color64K(aColor._Color64K());
819 aColor.SetAlpha(alpha);
822 void CDrawThirtyTwoBppBitmapCommon::MapBufferToUserDisplayMode(TInt aLength,TUint32* aBuffer)
824 const TUint32* bufferLimit = aBuffer + aLength;
825 const TUint16* nTable = PtrTo16BitNormalisationTable();
828 switch (iUserDispMode)
831 while (aBuffer < bufferLimit)
833 color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
834 color = TRgb::_Gray2(color._Gray2());
835 *aBuffer++ = color.Internal();
839 while (aBuffer < bufferLimit)
841 color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
842 color = TRgb::_Gray4(color._Gray4());
843 *aBuffer++ = color.Internal();
847 while (aBuffer < bufferLimit)
849 color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
850 color = TRgb::_Gray16(color._Gray16());
851 *aBuffer++ = color.Internal();
855 while (aBuffer < bufferLimit)
857 color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
858 color = TRgb::_Gray256(color._Gray256());
859 *aBuffer++ = color.Internal();
863 while (aBuffer < bufferLimit)
865 color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
866 color = TRgb::Color16(color.Color16());
867 *aBuffer++ = color.Internal();
871 while (aBuffer < bufferLimit)
873 color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
874 color = TRgb::Color256(color.Color256());
875 *aBuffer++ = color.Internal();
879 while (aBuffer < bufferLimit)
881 color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
882 color = TRgb::_Color4K(color._Color4K());
883 *aBuffer++ = color.Internal();
887 while (aBuffer < bufferLimit)
889 color.SetInternal(PMA2NonPMAPixel(*aBuffer, nTable));
890 color = TRgb::_Color64K(color._Color64K());
891 *aBuffer++ = color.Internal();
900 Implementation for CFbsDrawDevice::GetInterface().
901 Retrieves a pointer to a specified interface of CFbsDrawDevice implementation.
902 @param aInterfaceId Interface identifier of the interface to be retrieved.
903 @param aInterface Address of variable that retrieves the specified interface.
904 @return KErrNone If the interface is supported, KErrNotSupported otherwise.
906 TInt CDrawThirtyTwoBppBitmapCommon::GetInterface(TInt aInterfaceId, TAny*& aInterface)
909 TInt ret = KErrNotSupported;
911 if (aInterfaceId == KFastBlit2InterfaceID)
913 aInterface = static_cast<MFastBlit2*>(this);
917 return CDrawBitmap::GetInterface(aInterfaceId, aInterface);
923 CDrawThirtyTwoBppBitmapCommon::WriteBitmapBlock() implementation.
925 @see MFastBlit2::WriteBitmapBlock()
927 TInt CDrawThirtyTwoBppBitmapCommon::WriteBitmapBlock(const TPoint& aDest,
928 CFbsDrawDevice* aSrcDrawDevice,
929 const TRect& aSrcRect)
931 __ASSERT_DEBUG(aSrcDrawDevice && ((aSrcDrawDevice->DisplayMode()==EColor16MU) || (aSrcDrawDevice->DisplayMode()==EColor16MA) ||(aSrcDrawDevice->DisplayMode()==EColor16MAP)), Panic(EScreenDriverPanicInvalidParameter));
933 TAny* interface=NULL;
934 TInt ret = aSrcDrawDevice->GetInterface(KFastBlit2InterfaceID, interface);
937 return KErrNotSupported;
940 TAny* interface1=NULL;
941 ret = aSrcDrawDevice->GetInterface(KScalingSettingsInterfaceID, interface1);
942 if(ret != KErrNone || (interface1 && !reinterpret_cast<MScalingSettings*>(interface1)->IsScalingOff()))
944 return KErrNotSupported;
947 ret = aSrcDrawDevice->GetInterface(KOrientationInterfaceID, interface1);
948 if(ret != KErrNone || (interface1 && reinterpret_cast<MDrawDeviceOrientation*>(interface1)->Orientation() != 0))
950 return KErrNotSupported;
953 ret = aSrcDrawDevice->GetInterface(KDrawDeviceOriginInterfaceID, interface1);
956 return KErrNotSupported;
962 reinterpret_cast<MDrawDeviceOrigin*>(interface1)->Get(pt);
963 if(pt.iX != 0 || pt.iY != 0)
965 return KErrNotSupported;
969 const TUint32* srcBase = reinterpret_cast<MFastBlit2*>(interface)->Bits();
970 __ASSERT_DEBUG(srcBase!=NULL, Panic(EScreenDriverPanicInvalidParameter));
971 TInt srcStride = aSrcDrawDevice->ScanLineBytes();
972 __ASSERT_DEBUG((srcStride&3)==0, Panic(EScreenDriverPanicInvalidParameter)); // stride is assumed to be a multiple of 4
973 TSize srcSize = aSrcDrawDevice->SizeInPixels();
975 return WriteBitmapBlock(aDest, srcBase, srcStride, srcSize, aSrcRect);
979 CDrawThirtyTwoBppBitmapCommon::WriteBitmapBlock() implementation.
981 @see MFastBlit2::WriteBitmapBlock()
983 TInt CDrawThirtyTwoBppBitmapCommon::WriteBitmapBlock(const TPoint& aDest,
984 const TUint32* aSrcBase,
986 const TSize& aSrcSize,
987 const TRect& aSrcRect)
989 __ASSERT_DEBUG(aSrcBase, Panic(EScreenDriverPanicInvalidParameter));
990 __ASSERT_DEBUG((aSrcStride&3)==0, Panic(EScreenDriverPanicInvalidParameter));
991 __ASSERT_DEBUG(iBits, Panic(EScreenDriverPanicInvalidPointer));
993 if (iShadowMode!=NULL ||
994 (iUserDispMode!=NULL && iUserDispMode!=iDispMode) ||
995 iOrientation!=EOrientationNormal ||
999 return KErrNotSupported;
1002 __ASSERT_DEBUG(aSrcRect.iTl.iX >= 0, Panic(EScreenDriverPanicOutOfBounds));
1003 __ASSERT_DEBUG(aSrcRect.iTl.iY >= 0, Panic(EScreenDriverPanicOutOfBounds));
1004 __ASSERT_DEBUG(aSrcRect.iBr.iX <= aSrcSize.iWidth, Panic(EScreenDriverPanicOutOfBounds));
1005 __ASSERT_DEBUG(aSrcRect.iBr.iY <= aSrcSize.iHeight, Panic(EScreenDriverPanicOutOfBounds));
1006 __ASSERT_DEBUG(aDest.iX >= 0, Panic(EScreenDriverPanicOutOfBounds));
1007 __ASSERT_DEBUG(aDest.iY >= 0, Panic(EScreenDriverPanicOutOfBounds));
1008 __ASSERT_DEBUG((aDest.iX + aSrcRect.Width()) <= SizeInPixels().iWidth, Panic(EScreenDriverPanicOutOfBounds));
1009 __ASSERT_DEBUG((aDest.iY + aSrcRect.Height()) <= SizeInPixels().iHeight, Panic(EScreenDriverPanicOutOfBounds));
1011 const TInt srcStrideWords=aSrcStride >> 2;
1012 const TInt dstStrideWords=iScanLineWords;
1014 if (aSrcSize.iWidth == aSrcRect.Width() &&
1015 aSrcSize.iWidth == SizeInPixels().iWidth &&
1016 srcStrideWords == dstStrideWords)
1018 // Optimum case - one memcpy
1019 __ASSERT_DEBUG(aSrcRect.iTl.iX==0 && aDest.iX==0, Panic(EScreenDriverPanicInvalidParameter)); // this is implied by the above conditions
1020 const TUint32* srcPtr = aSrcBase + (iScanLineWords * aSrcRect.iTl.iY);
1021 TUint32* dstPtr = iBits + (iScanLineWords * aDest.iY);
1022 const TInt length = aSrcStride * aSrcRect.Height();
1023 Mem::Move(dstPtr, srcPtr, length);
1027 // Sub-optimal case - one memcpy per line
1028 const TUint32* srcPtr = aSrcBase + (srcStrideWords * aSrcRect.iTl.iY) + aSrcRect.iTl.iX;
1029 TUint32* dstPtr = iBits + (dstStrideWords * aDest.iY ) + aDest.iX;
1030 const TInt length = aSrcRect.Width() << 2;
1031 TInt lines = aSrcRect.Height();
1034 Mem::Move(dstPtr, srcPtr, length);
1035 srcPtr+=srcStrideWords;
1036 dstPtr+=dstStrideWords;
1042 CDrawThirtyTwoBppBitmapCommon::Bits() implementation.
1044 @see MFastBlit2::Bits()
1046 const TUint32* CDrawThirtyTwoBppBitmapCommon::Bits() const