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 //Initializes iSize, iDrawRect, iLongWidth, iScanLineBytes, iScanlineWords data members.
19 //It should be called every time when iSize is going to be changed - from Construct().
20 //@param aSize Physical screen size in pixels.
21 //@panic EScreenDriverPanicInvalidSize - Invalid aSize parameter. This might happen if the
22 //device is scaled and the scaling origin goes outside physical drawing rectangle.
23 void CDrawTwentyFourBppBitmap::SetSize(const TSize& aSize)
25 CDrawBitmap::SetSize(aSize);
26 __ASSERT_DEBUG(iSize == aSize, User::Invariant());
27 iScanLineBytes = (((iSize.iWidth * 3) + 11) / 12) * 12;
28 iLongWidth = iScanLineBytes / 3;
29 iScanLineWords = iScanLineBytes / 4;
32 TInt CDrawTwentyFourBppBitmap::Construct(TSize aSize)
34 return Construct(aSize, (((aSize.iWidth * 3) + 11) / 12) * 12);
37 TInt CDrawTwentyFourBppBitmap::Construct(TSize aSize, TInt aStride)
40 iDispMode = EColor16M;
41 CDrawBitmap::SetSize(aSize);
42 __ASSERT_DEBUG(iSize == aSize, User::Invariant());
45 iScanLineBytes = aStride;
46 iLongWidth = aStride / 3;
47 if (iLongWidth < aSize.iWidth)
49 iScanLineWords = aStride >> 2;
50 TInt size = (((Max(aSize.iWidth,aSize.iHeight) * 3) + 11) / 12) * 12;
53 iScanLineBuffer = (TUint32*)(User::Heap().Alloc(size));
54 if (iScanLineBuffer == NULL)
59 inline TInt CDrawTwentyFourBppBitmap::PixelAddressIncrement() const
63 case EOrientationNormal:
65 case EOrientationRotated90:
66 return iScanLineBytes;
67 case EOrientationRotated180:
69 case EOrientationRotated270:
70 return -iScanLineBytes;
76 inline void CDrawTwentyFourBppBitmap::PixelAddressIncrement(TInt& aPixelInc,TInt& aRowInc) const
80 case EOrientationNormal:
82 aRowInc = iScanLineBytes;
84 case EOrientationRotated90:
85 aPixelInc = iScanLineBytes;
88 case EOrientationRotated180:
90 aRowInc = -iScanLineBytes;
92 case EOrientationRotated270:
93 aPixelInc = -iScanLineBytes;
102 void CDrawTwentyFourBppBitmap::FadeRgb(TInt& red,TInt& green,TInt& blue)
104 blue = ((blue * iFadeMapFactor) >> 8) + iFadeMapOffset;
105 green = ((green * iFadeMapFactor) >> 16) + iFadeMapOffset;
106 red = ((red * iFadeMapFactor) >> 8) + iFadeMapOffset;
109 void CDrawTwentyFourBppBitmap::Shadow(TRgb& aColor)
111 if (iShadowMode & EFade)
112 aColor = CDrawBitmap::FadeRgb(aColor);
114 if (iShadowMode & EShadow)
116 TInt r = ShadowComponentInl(aColor.Red());
117 TInt g = ShadowComponentInl(aColor.Green());
118 TInt b = ShadowComponentInl(aColor.Blue());
119 aColor = TRgb(r,g,b);
123 void CDrawTwentyFourBppBitmap::Shadow(TInt& red,TInt& green,TInt& blue)
125 if (iShadowMode & EFade)
126 FadeRgb(red,green,blue);
128 if (iShadowMode & EShadow)
130 red = ShadowComponentInl(red);
131 green = ShadowComponentInl(green);
132 blue = ShadowComponentInl(blue);
136 TUint8 CDrawTwentyFourBppBitmap::ShadowAndFade(TInt aComponent)
138 if (iShadowMode & EFade)
139 aComponent = FadeGray(aComponent);
141 if (iShadowMode & EShadow)
142 aComponent = ShadowComponentInl(aComponent);
144 return TUint8(aComponent);
147 TUint8 CDrawTwentyFourBppBitmap::ShadowComponentInl(TInt aRgbComponent)
149 return TUint8(Max(0,aRgbComponent-0x40));
152 TUint8 CDrawTwentyFourBppBitmap::ShadowComponent(TInt aRgbComponent)
154 return ShadowComponentInl(aRgbComponent);
157 void CDrawTwentyFourBppBitmap::InvertBuffer(TInt aLength,TUint32* aBuffer)
159 __ASSERT_DEBUG(aLength>0,Panic(EScreenDriverPanicOutOfBounds));
160 __ASSERT_DEBUG(aBuffer,Panic(EScreenDriverPanicNullPointer));
162 TUint8* buffer = (TUint8*)aBuffer;
163 TUint8* limit = buffer + (aLength * 3);
165 while (buffer < limit)
169 void CDrawTwentyFourBppBitmap::ReadLine(TInt aX,TInt aY,TInt aLength,TAny* aBuffer) const
171 const TUint8* pixelPtr = PixelAddress(aX,aY);
173 if (iOrientation == EOrientationNormal)
174 Mem::Copy(aBuffer,pixelPtr,aLength * 3);
177 const TInt pixelPtrInc = PixelAddressIncrement();
179 TUint8* bufferPtr = STATIC_CAST(TUint8*,aBuffer);
180 const TUint8* bufferPtrLimit = bufferPtr + (aLength * 3);
182 while (bufferPtr < bufferPtrLimit)
184 *bufferPtr++ = pixelPtr[0];
185 *bufferPtr++ = pixelPtr[1];
186 *bufferPtr++ = pixelPtr[2];
187 pixelPtr += pixelPtrInc;
192 TRgb CDrawTwentyFourBppBitmap::ReadRgbNormal(TInt aX,TInt aY) const
194 TUint8* pixelPtr = PixelAddress(aX,aY);
195 return TRgb(pixelPtr[2],pixelPtr[1],pixelPtr[0]);
198 void CDrawTwentyFourBppBitmap::ShadowArea(const TRect& aRect)
200 const TRect rect(DeOrientate(aRect));
202 __ASSERT_DEBUG(rect.iTl.iX>=0 && rect.iBr.iX<=iSize.iWidth,Panic(EScreenDriverPanicOutOfBounds));
203 __ASSERT_DEBUG(rect.iTl.iY>=0 && rect.iBr.iY<=iSize.iHeight,Panic(EScreenDriverPanicOutOfBounds));
205 TUint8* pixelPtr = PixelAddress(rect.iTl.iX,rect.iTl.iY);
206 TUint8* pixelRowPtrLimit = pixelPtr + (rect.Height() * iScanLineBytes);
208 if (iShadowMode & EFade)
210 TUint8* pixelRowPtr = pixelPtr;
211 TUint8* pixelPtrLimit = pixelPtr + (rect.Width() * 3);
213 while (pixelRowPtr < pixelRowPtrLimit)
215 TUint8* tempPixelPtr = pixelRowPtr;
217 while (tempPixelPtr < pixelPtrLimit)
219 *tempPixelPtr = FadeGray(*tempPixelPtr);
223 pixelRowPtr += iScanLineBytes;
224 pixelPtrLimit += iScanLineBytes;
228 if (iShadowMode & EShadow)
230 TUint8* pixelRowPtr = pixelPtr;
231 TUint8* pixelPtrLimit = pixelPtr + (rect.Width() * 3);
233 while (pixelRowPtr < pixelRowPtrLimit)
235 TUint8* tempPixelPtr = pixelRowPtr;
237 while (tempPixelPtr < pixelPtrLimit)
239 *tempPixelPtr = ShadowComponent(*tempPixelPtr);
243 pixelRowPtr += iScanLineBytes;
244 pixelPtrLimit += iScanLineBytes;
249 void CDrawTwentyFourBppBitmap::ShadowBuffer(TInt aLength,TUint32* aBuffer)
251 __ASSERT_DEBUG(aLength>0,Panic(EScreenDriverPanicZeroLength));
252 __ASSERT_DEBUG(aBuffer,Panic(EScreenDriverPanicNullPointer));
254 TUint8* limit = ((TUint8*)aBuffer) + (aLength * 3);
256 if (iShadowMode & EFade)
258 TUint8* buffer = (TUint8*)aBuffer;
260 while (buffer < limit)
262 *buffer = FadeGray(*buffer);
267 if (iShadowMode & EShadow)
269 TUint8* buffer = (TUint8*)aBuffer;
271 while (buffer < limit)
273 *buffer = ShadowComponent(*buffer);
279 void CDrawTwentyFourBppBitmap::WriteRgb(TInt aX,TInt aY,TRgb aColor)
281 TUint8* pixelPtr = PixelAddress(aX,aY);
282 pixelPtr[0] = TUint8(aColor.Blue());
283 pixelPtr[1] = TUint8(aColor.Green());
284 pixelPtr[2] = TUint8(aColor.Red());
287 void CDrawTwentyFourBppBitmap::WriteBinary(TInt aX,TInt aY,TUint32* aBuffer,TInt aLength,TInt aHeight,TRgb aColor)
294 PixelAddressIncrement(pixelInc,rowInc);
296 const TUint32* dataLimit = aBuffer + aHeight;
297 const TUint32 dataMaskLimit = (aLength < 32) ? 1 << aLength : 0;
299 TUint8* pixelPtr = PixelAddress(aX,aY);
301 const TUint8 r = (TUint8)aColor.Red();
302 const TUint8 g = (TUint8)aColor.Green();
303 const TUint8 b = (TUint8)aColor.Blue();
305 while (aBuffer < dataLimit)
307 TUint32 dataWord = *aBuffer++;
308 TUint32 dataMask = 1;
309 TUint8* tempPixelPtr = pixelPtr;
311 while (dataMask != dataMaskLimit)
313 if(dataWord & dataMask)
320 tempPixelPtr += pixelInc;
328 void CDrawTwentyFourBppBitmap::WriteBinaryOp(TInt aX,TInt aY,TUint32* aBuffer,TInt aLength,TInt aHeight,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode)
334 TUint8* pixelPtr = PixelAddress(aX,aY);
336 const TUint32* dataPtrLimit = aBuffer + aHeight;
337 const TUint32 dataMaskLimit = (aLength < 32) ? 1 << aLength : 0;
342 PixelAddressIncrement(pixelInc,rowInc);
344 const TUint8 r = (TUint8)aColor.Red();
345 const TUint8 g = (TUint8)aColor.Green();
346 const TUint8 b = (TUint8)aColor.Blue();
350 while (aBuffer < dataPtrLimit)
352 TUint32 dataWord = *aBuffer++;
353 TUint32 dataMask = 1;
354 TUint8* tempPixelPtr = pixelPtr;
356 while (dataMask != dataMaskLimit)
358 if(dataWord & dataMask)
362 case CGraphicsContext::EDrawModeXOR:
363 tempPixelPtr[0] ^= b;
364 tempPixelPtr[1] ^= g;
365 tempPixelPtr[2] ^= r;
367 case CGraphicsContext::EDrawModeAND:
368 tempPixelPtr[0] &= b;
369 tempPixelPtr[1] &= g;
370 tempPixelPtr[2] &= r;
372 case CGraphicsContext::EDrawModeOR:
373 tempPixelPtr[0] |= b;
374 tempPixelPtr[1] |= g;
375 tempPixelPtr[2] |= r;
381 tempPixelPtr += pixelInc;
388 else if (aDrawMode == CGraphicsContext::EDrawModeAND)
390 while (aBuffer < dataPtrLimit)
392 TUint32 dataWord = *aBuffer++;
393 TUint32 dataMask = 1;
394 TUint8* tempPixelPtr = pixelPtr;
396 while (dataMask != dataMaskLimit)
398 if(dataWord & dataMask)
405 tempPixelPtr += pixelInc;
414 void CDrawTwentyFourBppBitmap::WriteBinaryLineVertical(TInt aX,TInt aY,TUint32* aBuffer,TInt aHeight,TRgb aColor,TBool aUp)
418 TInt scanlineByteLength;
420 switch (iOrientation)
422 case EOrientationNormal:
423 scanlineByteLength = iScanLineBytes;
425 case EOrientationRotated90:
426 scanlineByteLength = -3;
428 case EOrientationRotated180:
429 scanlineByteLength = -iScanLineBytes;
431 default: // EOrientationRotated270
432 scanlineByteLength = 3;
437 scanlineByteLength = -scanlineByteLength;
439 TUint8* pixelPtr = PixelAddress(aX,aY);
440 const TUint8* pixelPtrLimit = pixelPtr + (aHeight * scanlineByteLength);
441 TUint32 dataWord = *aBuffer;
442 TUint32 dataMask = 1;
444 const TUint8 r = (TUint8)aColor.Red();
445 const TUint8 g = (TUint8)aColor.Green();
446 const TUint8 b = (TUint8)aColor.Blue();
448 while(pixelPtr != pixelPtrLimit)
457 if(dataWord & dataMask)
465 pixelPtr += scanlineByteLength;
469 void CDrawTwentyFourBppBitmap::WriteLine(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
471 TUint8* pixelPtr = PixelAddress(aX,aY);
473 if (iOrientation == EOrientationNormal)
474 Mem::Copy(pixelPtr,aBuffer,aLength * 3);
477 const TInt pixelPtrInc = PixelAddressIncrement();
479 TUint8* bufferPtr = REINTERPRET_CAST(TUint8*,aBuffer);
480 TUint8* bufferPtrLimit = bufferPtr + (aLength * 3);
482 while (bufferPtr < bufferPtrLimit)
484 pixelPtr[0] = *bufferPtr++;
485 pixelPtr[1] = *bufferPtr++;
486 pixelPtr[2] = *bufferPtr++;
487 pixelPtr += pixelPtrInc;
492 void CDrawTwentyFourBppBitmap::WriteLineXOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
494 TUint8* pixelPtr = PixelAddress(aX,aY);
495 const TInt pixelPtrInc = PixelAddressIncrement();
497 TUint8* bufferPtr = REINTERPRET_CAST(TUint8*,aBuffer);
498 TUint8* bufferPtrLimit = bufferPtr + (aLength * 3);
500 while (bufferPtr < bufferPtrLimit)
502 pixelPtr[0] ^= *bufferPtr++;
503 pixelPtr[1] ^= *bufferPtr++;
504 pixelPtr[2] ^= *bufferPtr++;
505 pixelPtr += pixelPtrInc;
509 void CDrawTwentyFourBppBitmap::WriteLineAND(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
511 TUint8* pixelPtr = PixelAddress(aX,aY);
512 const TInt pixelPtrInc = PixelAddressIncrement();
514 TUint8* bufferPtr = REINTERPRET_CAST(TUint8*,aBuffer);
515 TUint8* bufferPtrLimit = bufferPtr + (aLength * 3);
517 while (bufferPtr < bufferPtrLimit)
519 pixelPtr[0] &= *bufferPtr++;
520 pixelPtr[1] &= *bufferPtr++;
521 pixelPtr[2] &= *bufferPtr++;
522 pixelPtr += pixelPtrInc;
526 void CDrawTwentyFourBppBitmap::WriteLineOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
528 TUint8* pixelPtr = PixelAddress(aX,aY);
529 const TInt pixelPtrInc = PixelAddressIncrement();
531 TUint8* bufferPtr = REINTERPRET_CAST(TUint8*,aBuffer);
532 TUint8* bufferPtrLimit = bufferPtr + (aLength * 3);
534 while (bufferPtr < bufferPtrLimit)
536 pixelPtr[0] |= *bufferPtr++;
537 pixelPtr[1] |= *bufferPtr++;
538 pixelPtr[2] |= *bufferPtr++;
539 pixelPtr += pixelPtrInc;
544 MAlphaBlend::WriteRgbAlphaLine() implementation.
545 @see MAlphaBlend::WriteRgbAlphaLine()
547 void CDrawTwentyFourBppBitmap::WriteRgbAlphaLine(TInt aX, TInt aY, TInt aLength,
548 const TUint8* aRgbBuffer,
549 const TUint8* aMaskBuffer,
550 MAlphaBlend::TShadowing aShadowing,
551 CGraphicsContext::TDrawMode /*aDrawMode*/)
554 TUint8* pixelPtr = PixelAddress(aX,aY);
555 const TInt pixelPtrInc = PixelAddressIncrement();
556 const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
558 while (aMaskBuffer < maskBufferPtrLimit)
560 TInt mask = aMaskBuffer[0];
564 TInt red = aRgbBuffer[2];
565 TInt green = aRgbBuffer[1];
566 TInt blue = aRgbBuffer[0];
568 if(aShadowing == MAlphaBlend::EShdwBefore)
570 Shadow(red,green,blue);
573 if(aMaskBuffer[0] != 0xff) // Blend 24bpp
576 red = (((red - pixelPtr[2]) * mask) >> 16) + pixelPtr[2];
577 green = (((green - pixelPtr[1]) * mask) >> 16) + pixelPtr[1];
578 blue = (((blue - pixelPtr[0]) * mask) >> 16) + pixelPtr[0];
581 if(aShadowing == MAlphaBlend::EShdwAfter)
583 Shadow(red,green,blue);
585 CDrawBitmap::MapColorToUserDisplayMode(red,green,blue);
586 pixelPtr[0] = TUint8(blue);
587 pixelPtr[1] = TUint8(green);
588 pixelPtr[2] = TUint8(red);
590 pixelPtr += pixelPtrInc;
596 const TUint32 KWordAlignedCount = 4;
597 const TUint32 KWordAlignedMask = 3;
598 const TUint32 KFinishEarlyByThree = 3;
600 void WriteTwentyFourBppColourAsWords(TUint8& r, TUint8& g, TUint8& b, TUint8* pixelPtr, const TInt byteLength, TUint8* pixelRowPtrLimit, const TInt scanLineBytes)
606 TUint32 bgrb = b+(g<<8)+(r<<16)+(b<<24);
607 TUint32 grbg = g+(r<<8)+(b<<16)+(g<<24);
608 TUint32 rbgr = r+(b<<8)+(g<<16)+(r<<24);
610 TUint8* pixelPtrLimit = pixelPtr + byteLength;
612 TInt leadingPixels = KWordAlignedCount-((TUint32)pixelPtr)&KWordAlignedMask;
613 if (leadingPixels == KWordAlignedCount)
615 const TInt trailingPixels = ((TUint32)pixelPtrLimit & KWordAlignedMask);
617 while (pixelPtr < pixelRowPtrLimit)
619 TUint8* tempPixelPtr;
620 TUint32* tempWordPtr;
622 TUint8* leadingPixelPtrLimit = pixelPtr+leadingPixels;
623 for (tempPixelPtr = pixelPtr; tempPixelPtr < leadingPixelPtrLimit; tempPixelPtr++)
625 tempPixelPtr[0] = bgr[nextOfBgr++];
628 if (nextOfBgr == (KWordAlignedCount-1))
631 TUint32* wordPtrLimit = ((TUint32*)(pixelPtrLimit-trailingPixels))-KFinishEarlyByThree;
633 tempWordPtr = (TUint32*)tempPixelPtr;
637 if (tempWordPtr < wordPtrLimit)
639 *tempWordPtr++ = grbg;
644 if (tempWordPtr < wordPtrLimit)
646 *tempWordPtr++ = rbgr;
651 while (tempWordPtr < wordPtrLimit)
653 *tempWordPtr++ = bgrb;
654 *tempWordPtr++ = grbg;
655 *tempWordPtr++ = rbgr;
658 for (tempPixelPtr = (TUint8*)tempWordPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
660 tempPixelPtr[0] = bgr[nextOfBgr++];
665 pixelPtr += scanLineBytes;
666 pixelPtrLimit += scanLineBytes;
671 Writes a specific colour to the screen, optimised to use mem fill if the colour is shade of grey
672 and word aligned access the three possible combinations of the colour bytes.
674 void CDrawTwentyFourBppBitmap::WriteRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
676 const TInt scanLineBytes = iScanLineBytes;
677 const TInt byteLength = aLength * 3;
679 TUint8* pixelPtr = PixelAddress(aX,aY);
680 TUint8* pixelRowPtrLimit = pixelPtr + (aHeight * scanLineBytes);
682 TUint8 r = TUint8(aColor.Red());
683 TUint8 g = TUint8(aColor.Green());
684 TUint8 b = TUint8(aColor.Blue());
686 if ((r == g) && (g == b))
688 while (pixelPtr < pixelRowPtrLimit)
690 Mem::Fill(pixelPtr,byteLength,r);
691 pixelPtr += scanLineBytes;
696 WriteTwentyFourBppColourAsWords(r, g, b, pixelPtr, byteLength, pixelRowPtrLimit, scanLineBytes);
700 void CDrawTwentyFourBppBitmap::WriteRgbMultiXOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
702 TUint8* pixelPtr = PixelAddress(aX,aY);
703 TUint8* pixelPtrLimit = pixelPtr + (aLength * 3);
704 TUint8* pixelRowPtrLimit = pixelPtr + (aHeight * iScanLineBytes);
706 TUint8 r = TUint8(aColor.Red());
707 TUint8 g = TUint8(aColor.Green());
708 TUint8 b = TUint8(aColor.Blue());
710 while (pixelPtr < pixelRowPtrLimit)
712 for (TUint8* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr += 3)
714 tempPixelPtr[0] ^= b;
715 tempPixelPtr[1] ^= g;
716 tempPixelPtr[2] ^= r;
719 pixelPtr += iScanLineBytes;
720 pixelPtrLimit += iScanLineBytes;
724 void CDrawTwentyFourBppBitmap::WriteRgbMultiAND(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
726 TUint8* pixelPtr = PixelAddress(aX,aY);
727 TUint8* pixelPtrLimit = pixelPtr + (aLength * 3);
728 TUint8* pixelRowPtrLimit = pixelPtr + (aHeight * iScanLineBytes);
729 TUint8 r = TUint8(aColor.Red());
730 TUint8 g = TUint8(aColor.Green());
731 TUint8 b = TUint8(aColor.Blue());
733 while (pixelPtr < pixelRowPtrLimit)
735 for (TUint8* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr += 3)
737 tempPixelPtr[0] &= b;
738 tempPixelPtr[1] &= g;
739 tempPixelPtr[2] &= r;
742 pixelPtr += iScanLineBytes;
743 pixelPtrLimit += iScanLineBytes;
747 void CDrawTwentyFourBppBitmap::WriteRgbMultiOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
749 TUint8* pixelPtr = PixelAddress(aX,aY);
750 TUint8* pixelPtrLimit = pixelPtr + (aLength * 3);
751 TUint8* pixelRowPtrLimit = pixelPtr + (aHeight * iScanLineBytes);
752 TUint8 r = TUint8(aColor.Red());
753 TUint8 g = TUint8(aColor.Green());
754 TUint8 b = TUint8(aColor.Blue());
756 while (pixelPtr < pixelRowPtrLimit)
758 for (TUint8* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr += 3)
760 tempPixelPtr[0] |= b;
761 tempPixelPtr[1] |= g;
762 tempPixelPtr[2] |= r;
765 pixelPtr += iScanLineBytes;
766 pixelPtrLimit += iScanLineBytes;
770 void CDrawTwentyFourBppBitmap::WriteRgbAlphaMulti(TInt aX,TInt aY,TInt aLength,TRgb aColor,const TUint8* aMaskBuffer)
773 TUint8* pixelPtr = PixelAddress(aX,aY);
774 const TInt pixelPtrInc = PixelAddressIncrement();
775 const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
780 const TInt red = aColor.Red();
781 const TInt green = aColor.Green();
782 const TInt blue = aColor.Blue();
783 while (aMaskBuffer < maskBufferPtrLimit)
789 if(aMaskBuffer[0] != 0xff)
791 pixelClr = AlphaBlend(red, green, blue, TRgb(pixelPtr[2], pixelPtr[1], pixelPtr[0]), aMaskBuffer[0]);
798 pixelPtr[0] = TUint8(pixelClr.Blue());
799 pixelPtr[1] = TUint8(pixelClr.Green());
800 pixelPtr[2] = TUint8(pixelClr.Red());
802 pixelPtr += pixelPtrInc;
807 void CDrawTwentyFourBppBitmap::MapColorToUserDisplayMode(TRgb& aColor)
809 switch (iUserDispMode)
812 aColor = TRgb::_Gray2(aColor._Gray2());
815 aColor = TRgb::_Gray4(aColor._Gray4());
818 aColor = TRgb::_Gray16(aColor._Gray16());
821 aColor = TRgb::_Gray256(aColor._Gray256());
824 aColor = TRgb::Color16(aColor.Color16());
827 aColor = TRgb::Color256(aColor.Color256());
830 aColor = TRgb::_Color4K(aColor._Color4K());
833 aColor = TRgb::_Color64K(aColor._Color64K());
840 void CDrawTwentyFourBppBitmap::MapBufferToUserDisplayMode(TInt aLength,TUint32* aBuffer)
842 TUint8* bufferPtr = (TUint8*)aBuffer;
843 const TUint8* bufferLimit = bufferPtr + (aLength * 3);
845 switch (iUserDispMode)
848 while (bufferPtr < bufferLimit)
850 TInt blue = bufferPtr[0];
851 TInt green = bufferPtr[1];
852 TInt red = bufferPtr[2];
853 TRgb color(red,green,blue);
854 color = TRgb::_Gray2(color._Gray2());
855 bufferPtr[0] = TUint8(color.Blue());
856 bufferPtr[1] = TUint8(color.Green());
857 bufferPtr[2] = TUint8(color.Red());
862 while (bufferPtr < bufferLimit)
864 TInt blue = bufferPtr[0];
865 TInt green = bufferPtr[1];
866 TInt red = bufferPtr[2];
867 TRgb color(red,green,blue);
868 color = TRgb::_Gray4(color._Gray4());
869 bufferPtr[0] = TUint8(color.Blue());
870 bufferPtr[1] = TUint8(color.Green());
871 bufferPtr[2] = TUint8(color.Red());
876 while (bufferPtr < bufferLimit)
878 TInt blue = bufferPtr[0];
879 TInt green = bufferPtr[1];
880 TInt red = bufferPtr[2];
881 TRgb color(red,green,blue);
882 color = TRgb::_Gray16(color._Gray16());
883 bufferPtr[0] = TUint8(color.Blue());
884 bufferPtr[1] = TUint8(color.Green());
885 bufferPtr[2] = TUint8(color.Red());
890 while (bufferPtr < bufferLimit)
892 TInt blue = bufferPtr[0];
893 TInt green = bufferPtr[1];
894 TInt red = bufferPtr[2];
895 TRgb color(red,green,blue);
896 color = TRgb::_Gray256(color._Gray256());
897 bufferPtr[0] = TUint8(color.Blue());
898 bufferPtr[1] = TUint8(color.Green());
899 bufferPtr[2] = TUint8(color.Red());
904 while (bufferPtr < bufferLimit)
906 TInt blue = bufferPtr[0];
907 TInt green = bufferPtr[1];
908 TInt red = bufferPtr[2];
909 TRgb color(red,green,blue);
910 color = TRgb::Color16(color.Color16());
911 bufferPtr[0] = TUint8(color.Blue());
912 bufferPtr[1] = TUint8(color.Green());
913 bufferPtr[2] = TUint8(color.Red());
918 while (bufferPtr < bufferLimit)
920 TInt blue = bufferPtr[0];
921 TInt green = bufferPtr[1];
922 TInt red = bufferPtr[2];
923 TRgb color(red,green,blue);
924 color = TRgb::Color256(color.Color256());
925 bufferPtr[0] = TUint8(color.Blue());
926 bufferPtr[1] = TUint8(color.Green());
927 bufferPtr[2] = TUint8(color.Red());
932 while (bufferPtr < bufferLimit)
934 TInt blue = bufferPtr[0];
935 TInt green = bufferPtr[1];
936 TInt red = bufferPtr[2];
937 TRgb color(red,green,blue);
938 color = TRgb::_Color4K(color._Color4K());
939 bufferPtr[0] = TUint8(color.Blue());
940 bufferPtr[1] = TUint8(color.Green());
941 bufferPtr[2] = TUint8(color.Red());
946 while (bufferPtr < bufferLimit)
948 TInt blue = bufferPtr[0];
949 TInt green = bufferPtr[1];
950 TInt red = bufferPtr[2];
951 TRgb color(red,green,blue);
952 color = TRgb::_Color64K(color._Color64K());
953 bufferPtr[0] = TUint8(color.Blue());
954 bufferPtr[1] = TUint8(color.Green());
955 bufferPtr[2] = TUint8(color.Red());
964 TInt CDrawTwentyFourBppBitmap::WriteRgbOutlineAndShadow(TInt aX, TInt aY, const TInt aLength,
965 TUint32 aOutlinePenColor, TUint32 aShadowColor,
966 TUint32 aFillColor, const TUint8* aDataBuffer)
969 TUint8* pixelPtr = PixelAddress(aX,aY);
970 const TInt pixelPtrInc = PixelAddressIncrement();
971 const TUint8* dataBufferPtrLimit = aDataBuffer + aLength;
972 TInt blendedRedColor;
973 TInt blendedGreenColor;
974 TInt blendedBlueColor;
978 TRgb outlinePenColor;
979 outlinePenColor.SetInternal(aOutlinePenColor);
981 shadowColor.SetInternal(aShadowColor);
983 fillColor.SetInternal(aFillColor);
985 const TInt redOutlinePenColor = outlinePenColor.Red();
986 const TInt redShadowColor = shadowColor.Red();
987 const TInt redFillColor = fillColor.Red();
989 const TInt greenOutlinePenColor = outlinePenColor.Green();
990 const TInt greenShadowColor = shadowColor.Green();
991 const TInt greenFillColor = fillColor.Green();
993 const TInt blueOutlinePenColor = outlinePenColor.Blue();
994 const TInt blueShadowColor = shadowColor.Blue();
995 const TInt blueFillColor = fillColor.Blue();
996 const TInt alpha = aOutlinePenColor >> 24;
998 while (aDataBuffer < dataBufferPtrLimit)
1000 index = *aDataBuffer++;
1001 if (255 == FourColorBlendLookup[index][KBackgroundColorIndex])
1004 //No drawing required so move on to next pixel.
1005 pixelPtr += pixelPtrInc;
1008 else if (255 == FourColorBlendLookup[index][KFillColorIndex])
1011 finalColor.SetInternal(aFillColor);
1013 else if (255 == FourColorBlendLookup[index][KShadowColorIndex])
1016 finalColor.SetInternal(aShadowColor);
1018 else if (255 == FourColorBlendLookup[index][KOutlineColorIndex])
1021 finalColor.SetInternal(aOutlinePenColor);
1025 TRgb backgroundColor = TRgb::_Color16M(TRgb(pixelPtr[2], pixelPtr[1], pixelPtr[0])._Color16M());
1027 blendedRedColor = (redOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] +
1028 redShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
1029 redFillColor * FourColorBlendLookup[index][KFillColorIndex] +
1030 backgroundColor.Red() * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8;
1032 blendedGreenColor = (greenOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] +
1033 greenShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
1034 greenFillColor * FourColorBlendLookup[index][KFillColorIndex] +
1035 backgroundColor.Green() * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8;
1037 blendedBlueColor = (blueOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] +
1038 blueShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
1039 blueFillColor * FourColorBlendLookup[index][KFillColorIndex] +
1040 backgroundColor.Blue() * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8;
1044 TRgb alphablend = AlphaBlend(blendedRedColor, blendedGreenColor, blendedBlueColor, TRgb(pixelPtr[2], pixelPtr[1], pixelPtr[0]), alpha);
1045 pixelPtr[0] = TUint8(alphablend.Blue());
1046 pixelPtr[1] = TUint8(alphablend.Green());
1047 pixelPtr[2] = TUint8(alphablend.Red());
1052 pixelPtr[0] = TUint8(blendedBlueColor);
1053 pixelPtr[1] = TUint8(blendedGreenColor);
1054 pixelPtr[2] = TUint8(blendedRedColor);
1056 pixelPtr += pixelPtrInc;
1062 TRgb alphablend = AlphaBlend(finalColor, TRgb(pixelPtr[2], pixelPtr[1], pixelPtr[0]), alpha);
1063 pixelPtr[0] = TUint8(alphablend.Blue());
1064 pixelPtr[1] = TUint8(alphablend.Green());
1065 pixelPtr[2] = TUint8(alphablend.Red());
1069 pixelPtr[0] = TUint8(finalColor.Blue());
1070 pixelPtr[1] = TUint8(finalColor.Green());
1071 pixelPtr[2] = TUint8(finalColor.Red());
1073 pixelPtr += pixelPtrInc;
1078 void CDrawTwentyFourBppBitmap::BlendRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
1080 const TInt sourceAlpha = aColor.Alpha();
1082 if (sourceAlpha == 0xFF) //Fully opaque
1084 WriteRgbMulti(aX,aY,aLength,aHeight,aColor);
1087 else if (sourceAlpha == 0x00) //Fully transparent
1091 else //Perform alpha blending
1093 TUint8* pixelPtr = PixelAddress(aX,aY);
1094 const TInt pixelPtrInc = PixelAddressIncrement();
1095 TUint8* pixelPtrEnd = pixelPtr + (aLength * pixelPtrInc);
1101 //Perform pre-multiplication on values from aColor
1102 const TUint8 pmsr = (sourceAlpha * aColor.Red()) / 255;
1103 const TUint8 pmsg = (sourceAlpha * aColor.Green()) / 255;
1104 const TUint8 pmsb = (sourceAlpha * aColor.Blue()) / 255;
1106 for (TInt ii = 0 ; ii <= aHeight; ii++)
1108 while (pixelPtr != pixelPtrEnd)
1114 //Target has no alpha channel so assume to be 0xFF (opaque)
1115 pixelPtr[0] = pmsb + ((0xFF-sourceAlpha) * db)/255;
1116 pixelPtr[1] = pmsg + ((0xFF-sourceAlpha) * dg)/255;
1117 pixelPtr[2] = pmsr + ((0xFF-sourceAlpha) * dr)/255;
1119 pixelPtr+=pixelPtrInc;
1121 pixelPtr = PixelAddress(aX, ii+aY);
1122 pixelPtrEnd = pixelPtr + (aLength * pixelPtrInc);