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 GLREF_D const TUint8 ditherlutab[16][4];
19 GLREF_D const TUint8 shadowlutab[256];
21 const TInt KPixelsPerWord = 8;
22 const TInt KPixelsPerByte = 2;
23 const TInt KBitsPerPixel = 4;
25 // CDrawFourBppBitmapGray
27 //Initializes iSize, iDrawRect, iLongWidth, iScanlineWords data members.
28 //It should be called every time when iSize is going to be changed - from Construct().
29 //@param aSize Physical screen size in pixels.
30 //@panic EScreenDriverPanicInvalidSize - Invalid aSize parameter. This might happen if the
31 //device is scaled and the scaling origin goes outside physical drawing rectangle.
32 void CDrawFourBppBitmapGray::SetSize(const TSize& aSize)
34 CDrawBitmap::SetSize(aSize);
35 __ASSERT_DEBUG(iSize == aSize, User::Invariant());
36 iLongWidth = (iSize.iWidth + (KPixelsPerWord - 1)) & ~(KPixelsPerWord - 1);
37 iScanLineWords = iLongWidth / KPixelsPerWord;
40 TInt CDrawFourBppBitmapGray::Construct(TSize aSize)
42 return Construct(aSize, ((aSize.iWidth + (KPixelsPerWord - 1)) & ~(KPixelsPerWord - 1)) / KPixelsPerByte);
45 TInt CDrawFourBppBitmapGray::Construct(TSize aSize, TInt aStride)
49 CDrawBitmap::SetSize(aSize);
50 __ASSERT_DEBUG(iSize == aSize, User::Invariant());
53 iLongWidth = aStride * KPixelsPerByte;
54 if (iLongWidth < aSize.iWidth)
56 iScanLineWords = aStride >> 2;
57 TInt size = 1 + (Max(aSize.iWidth,aSize.iHeight) >> 1);
60 iScanLineBuffer = (TUint32*)(User::Heap().Alloc(size));
61 if (iScanLineBuffer == NULL)
66 void CDrawFourBppBitmapGray::Shadow(TRgb& aColor)
68 aColor = TRgb::_Gray16(ShadowAndFadeGray16(aColor._Gray16()));
71 TUint8 CDrawFourBppBitmapGray::ShadowAndFadeGray16(TInt aGray16)
73 if (iShadowMode & EFade)
74 aGray16 = FadeGray(aGray16 * 17) >> 4;
76 if (iShadowMode & EShadow)
77 aGray16 = Max(aGray16 - 5,0);
79 return (TUint8)aGray16;
82 TUint32 CDrawFourBppBitmapGray::FadeWord(TUint32 aWord)
84 TUint32 fadedWord = 0;
86 for (TInt bitShift = 0; bitShift < 32; bitShift += 4)
88 TInt gray = (aWord >> bitShift) & 0xf;
89 gray = FadeGray(gray * 17) >> 4;
90 fadedWord |= gray << bitShift;
96 TUint32 CDrawFourBppBitmapGray::ColorInt(TRgb aColor) const
98 TUint32 colorWord = aColor._Gray16();
100 colorWord |= colorWord << 4;
101 colorWord |= colorWord << 8;
102 colorWord |= colorWord << 16;
107 void CDrawFourBppBitmapGray::DitherBuffer(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
109 aX += iDitherOrigin.iX;
110 aY += iDitherOrigin.iY;
115 const TInt first = aX + aY;
117 const TInt second = aX + aY;
119 TUint8* bufferPtr = (TUint8*)aBuffer;
120 const TUint8* bufferLimit = bufferPtr + ((aLength + 1) / 2);
122 for (; bufferPtr < bufferLimit; bufferPtr++)
124 TUint8 index1 = bufferPtr[0];
125 TUint8 index2 = TUint8(index1 >> 4);
128 const TUint8 value1 = ditherlutab[index1][first];
129 const TUint8 value2 = ditherlutab[index2][second];
130 bufferPtr[0] = TUint8(value1 | (value2 << 4));
134 TUint32 CDrawFourBppBitmapGray::HashInt(TRgb aColor,TInt aX,TInt aY) const
136 const TUint32 gray = aColor._Gray16();
137 const TUint32 int1 = Hash(gray,aX,aY);
138 const TUint32 int2 = Hash(gray,aX + 1,aY);
140 TUint32 colorWord = int1 | (int2 << 4);
142 colorWord |= colorWord << 8;
143 colorWord |= colorWord << 16;
148 void CDrawFourBppBitmapGray::InvertBuffer(TInt aLength,TUint32* aBuffer)
150 const TUint32* bufferLimit = aBuffer + ((aLength + KPixelsPerWord - 1) / KPixelsPerWord);
152 while (aBuffer < bufferLimit)
153 *aBuffer++ ^= 0xffffffff;
156 /** Copies a number of pixels into a word-aligned buffer without format translation.
157 Note that the byte length to the target buffer is honoured,
158 but the end contents of the last byte are generally overwritten with extra pixel data (or garbage).
159 Note that I am assuming the compiler optimiser will convert all these divides and multiplies into shifts!
160 @param aX x coordinate to start copy from (need not be aligned at all)
161 @param aY y coordinate to copy line from
162 @param aLength number of pixels to copy
163 @param aBuffer target word-aligned buffer (but may or may not be word length)
165 void CDrawFourBppBitmapGray::ReadLine(TInt aX,TInt aY,TInt aLength,TAny* aBuffer) const
167 TUint32* pixelPtr = ScanLine(aY);
168 TInt startLongPix = aX & -KPixelsPerWord;
169 pixelPtr += startLongPix / KPixelsPerWord;
170 TUint32* bufferPtr = (TUint32*)aBuffer;
171 TInt wordsCnt = (aLength+KPixelsPerByte-1) / KPixelsPerWord; //how many words to write to target
172 TInt restPixels = aLength - wordsCnt * KPixelsPerWord; //how many pixels left to copy
173 TInt bytesCnt = (restPixels+KPixelsPerByte-1) / KPixelsPerByte ; //how many target bytes to copy
174 TInt shiftBits = aX - startLongPix;
175 restPixels=shiftBits+restPixels; //How many pixels are read from the second word by the final word copy
176 if (bytesCnt==0 && shiftBits && restPixels<=0)
178 // This correction is required because although a last whole word will be written to the target buffer,
179 // this special test indicates that the required significant data bits plus the shift
180 // add up to one word (or less) to be read.
181 // The copy words optimisation used to copy the main body of the line
182 // will read from the next location after the copy,
183 // but this may not always be accessable memory (on the last scanline)
184 // The correction is not required if the second word would need to be read anyway.
185 //eg we want to copy 7 nibbles with a 1 nibble shift (16 color), restpixels would be 0
189 //How many pixels are read from the second word in the final byte copy?
190 //If zero (or less) then the second word should not be read in the copy bytes phase
191 //really this should be an else of the if above, but this gives the same end condition.
192 //eg we want to copy 5 nibbles with a 2 nibble shift (16 color), restpixels would be -1.
193 restPixels-=KPixelsPerWord;
194 ReadLineCommon(pixelPtr,bufferPtr,wordsCnt,restPixels,bytesCnt,shiftBits*KBitsPerPixel);
198 TRgb CDrawFourBppBitmapGray::ReadRgbNormal(TInt aX,TInt aY) const
200 TUint32 colorWord = *(ScanLine(aY) + (aX / KPixelsPerWord));
201 colorWord >>= ((aX & 7) * KBitsPerPixel);
202 return TRgb::_Gray16(colorWord & 0xf);
205 void CDrawFourBppBitmapGray::ShadowArea(const TRect& aRect)
207 __ASSERT_DEBUG(aRect.iTl.iX>=0 && aRect.iBr.iX<=iSize.iWidth,Panic(EScreenDriverPanicOutOfBounds));
208 __ASSERT_DEBUG(aRect.iTl.iY>=0 && aRect.iBr.iY<=iSize.iHeight,Panic(EScreenDriverPanicOutOfBounds));
210 TInt startLong = (aRect.iTl.iX + KPixelsPerWord - 1) & ~7;
211 TInt finishLong = aRect.iBr.iX & ~7;
212 TInt startShift = (startLong - aRect.iTl.iX) * KBitsPerPixel;
213 TInt finishShift = (KPixelsPerWord - aRect.iBr.iX + finishLong) * KBitsPerPixel;
214 TInt startLongAdjust = startLong / KPixelsPerWord;
215 TInt finishLongAdjust = finishLong / KPixelsPerWord;
216 TUint32* base = ScanLine(aRect.iTl.iY);
218 if (iShadowMode & EFade)
220 TUint32* pixelPtr = base + startLongAdjust;
221 TUint32* pixelPtrLimit = base + finishLongAdjust;
223 if (finishLong < startLong)
225 const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << (32 - startShift));
226 const TUint32 invertedMask = ~mask;
228 for (TInt y = aRect.iTl.iY; y < aRect.iBr.iY; y++)
230 TUint32 shadowed = FadeWord(pixelPtrLimit[0]) & mask;
231 pixelPtrLimit[0] &= invertedMask;
232 pixelPtrLimit[0] |= shadowed;
233 pixelPtrLimit += iScanLineWords;
238 for (TInt y = aRect.iTl.iY; y < aRect.iBr.iY; y++)
240 if (aRect.iTl.iX < startLong)
242 TUint32 shadowed = FadeWord(pixelPtr[-1]);
243 pixelPtr[-1] = PasteInt(pixelPtr[-1],shadowed,startShift);
246 for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
247 tempPixelPtr[0] = FadeWord(tempPixelPtr[0]);
249 if (finishLong < aRect.iBr.iX)
251 TUint32 shadowed = FadeWord(pixelPtrLimit[0]);
252 pixelPtrLimit[0] = PasteInt(shadowed,pixelPtrLimit[0],finishShift);
255 pixelPtr += iScanLineWords;
256 pixelPtrLimit += iScanLineWords;
261 if (iShadowMode & EShadow)
263 if (iUserDispMode == EGray2)
265 WriteRgbMulti(aRect.iTl.iX,aRect.iTl.iY,aRect.Width(),aRect.Height(),KRgbBlack);
269 TUint32* pixelPtr = base + startLongAdjust;
270 TUint32* pixelPtrLimit = base + finishLongAdjust;
272 if (finishLong < startLong)
274 const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << (32 - startShift));
275 const TUint32 invertedMask = ~mask;
277 for (TInt y = aRect.iTl.iY; y < aRect.iBr.iY; y++)
279 TUint32 shadowed = shadowlutab[pixelPtrLimit[0] & 0xff];
280 shadowed |= (shadowlutab[(pixelPtrLimit[0] >> 8) & 0xff] << 8);
281 shadowed |= (shadowlutab[(pixelPtrLimit[0] >> 16) & 0xff] << 16);
282 shadowed |= (shadowlutab[(pixelPtrLimit[0] >> 24) & 0xff] << 24);
284 pixelPtrLimit[0] &= invertedMask;
285 pixelPtrLimit[0] |= (shadowed & mask);
286 pixelPtrLimit += iScanLineWords;
291 for (TInt y = aRect.iTl.iY; y < aRect.iBr.iY; y++)
293 if (aRect.iTl.iX < startLong)
295 TUint32 shadowed = shadowlutab[pixelPtr[-1] & 0xff];
296 shadowed |= (shadowlutab[(pixelPtr[-1] >> 8) & 0xff] << 8);
297 shadowed |= (shadowlutab[(pixelPtr[-1] >> 16) & 0xff] << 16);
298 shadowed |= (shadowlutab[(pixelPtr[-1] >> 24) & 0xff] << 24);
299 pixelPtr[-1] = PasteInt(pixelPtr[-1],shadowed,startShift);
302 for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
304 TUint32 shadowed = shadowlutab[tempPixelPtr[0] & 0xff];
305 shadowed |= (shadowlutab[(tempPixelPtr[0] >> 8) & 0xff] << 8);
306 shadowed |= (shadowlutab[(tempPixelPtr[0] >> 16) & 0xff] << 16);
307 shadowed |= (shadowlutab[(tempPixelPtr[0] >> 24) & 0xff] << 24);
308 tempPixelPtr[0] = shadowed;
311 if (finishLong < aRect.iBr.iX)
313 TUint32 shadowed = shadowlutab[pixelPtrLimit[0] & 0xff];
314 shadowed |= (shadowlutab[(pixelPtrLimit[0] >> 8) & 0xff] << 8);
315 shadowed |= (shadowlutab[(pixelPtrLimit[0] >> 16) & 0xff] << 16);
316 shadowed |= (shadowlutab[(pixelPtrLimit[0] >> 24) & 0xff] << 24);
317 pixelPtrLimit[0] = PasteInt(shadowed,pixelPtrLimit[0],finishShift);
320 pixelPtr += iScanLineWords;
321 pixelPtrLimit += iScanLineWords;
327 void CDrawFourBppBitmapGray::ShadeBuffer(TInt aLength,TUint32* aBuffer)
329 __ASSERT_DEBUG(aBuffer != NULL,Panic(EScreenDriverPanicInvalidParameter));
331 const TUint32* bufferLimit = aBuffer + ((aLength + KPixelsPerWord - 1) / KPixelsPerWord);
333 while (aBuffer < bufferLimit)
335 TUint32 fourthbit = (0x88888888 & aBuffer[0]);
336 aBuffer[0] = fourthbit | (fourthbit >> 1);
337 aBuffer[0] |= aBuffer[0] >> 2;
342 void CDrawFourBppBitmapGray::ShadowBuffer(TInt aLength,TUint32* aBuffer)
344 __ASSERT_DEBUG(aBuffer != NULL,Panic(EScreenDriverPanicInvalidParameter));
346 const TUint32* bufferLimit = aBuffer + ((aLength + KPixelsPerWord - 1) / KPixelsPerWord);
348 if (iShadowMode & EFade)
350 for (TUint32* bufferPtr = aBuffer; bufferPtr < bufferLimit; bufferPtr++)
351 bufferPtr[0] = FadeWord(bufferPtr[0]);
354 if (iShadowMode & EShadow)
356 for (TUint32* bufferPtr = aBuffer; bufferPtr < bufferLimit; bufferPtr++)
358 TUint32 bufferWord = bufferPtr[0];
360 TUint firstbyte = shadowlutab[bufferWord & 0xff];
362 firstbyte |= (shadowlutab[bufferWord & 0xff] << 8);
364 firstbyte |= (shadowlutab[bufferWord & 0xff] << 16);
366 firstbyte |= (shadowlutab[bufferWord & 0xff] << 24);
368 bufferPtr[0] = firstbyte;
373 void CDrawFourBppBitmapGray::WriteRgb(TInt aX,TInt aY,TRgb aColor)
375 TUint32 colorIndex = aColor._Gray16();
377 if (iUserDispMode == EGray2)
378 colorIndex = (colorIndex > 7) ? 15 : 0;
379 else if (iUserDispMode == EGray4)
380 colorIndex = Hash(colorIndex,aX,aY);
382 TUint32* pixelPtr = ScanLine(aY) + (aX / KPixelsPerWord);
383 TInt shift = (aX & 7) * KBitsPerPixel;
385 pixelPtr[0] &= ~(0xf << shift);
386 pixelPtr[0] |= colorIndex << shift;
389 void CDrawFourBppBitmapGray::WriteBinary(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TRgb aColor)
393 const TInt yLimit = aY + aHeight;
394 const TUint32 gray16 = aColor._Gray16();
396 if (iUserDispMode == EGray2)
404 else if (iUserDispMode != EGray4)
410 for (; aY < yLimit; aY++,aData++)
412 if (iUserDispMode == EGray4)
414 color1 = Hash(gray16,aX,aY);
415 color2 = Hash(gray16,aX + 1,aY);
418 TUint32 color = color1;
419 TUint32 dataMask = 1;
420 const TInt xLimit = aX + aLength;
421 TUint8* pixelPtr = ((TUint8*)ScanLine(aY)) + (aX / 2);
423 if (color1 || color2)
425 for (TInt x = aX; x < xLimit; x++,dataMask <<= 1)
427 if (aData[0] & dataMask)
430 pixelPtr[0] = (TUint8)(color << 4 | (pixelPtr[0] & 0x0f));
432 pixelPtr[0] = (TUint8)(color | (pixelPtr[0] & 0xf0));
435 color = (color == color2) ? color1 : color2;
442 TUint8 bytemask = TUint8((aX & 1) ? 0x0f : 0xf0);
444 for (TInt x = aX; x < xLimit; x++,dataMask <<= 1,bytemask = (TUint8)~bytemask)
446 if (aData[0] & dataMask)
447 pixelPtr[0] &= bytemask;
456 void CDrawFourBppBitmapGray::WriteBinaryOp(TInt aX,TInt aY,TUint32* aData,TInt aLength,TInt aHeight,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode)
460 const TUint32 gray16 = aColor._Gray16();
461 const TInt yLimit = aY + aHeight;
463 if (iUserDispMode == EGray2)
471 else if(iUserDispMode != EGray4)
477 for (; aY < yLimit; aY++)
479 if (iUserDispMode == EGray4)
481 color1 = Hash(gray16,aX,aY);
482 color2 = Hash(gray16,aX + 1,aY);
485 TUint32 color = color1;
486 TUint32 dataMask = 1;
487 const TInt xLimit = aX + aLength;
488 TUint8* pixelPtr = ((TUint8*)ScanLine(aY)) + (aX / 2);
492 for (TInt x = aX; x < xLimit; x++,dataMask <<= 1)
494 if (aData[0] & dataMask)
498 if (aDrawMode == CGraphicsContext::EDrawModeXOR)
499 pixelPtr[0] = (TUint8)((color << 4) ^ pixelPtr[0]);
500 else if (aDrawMode == CGraphicsContext::EDrawModeAND)
501 pixelPtr[0] = (TUint8)(((color << 4) | 0x0f) & pixelPtr[0]);
502 else if (aDrawMode==CGraphicsContext::EDrawModeOR)
503 pixelPtr[0] = (TUint8)((color << 4) | pixelPtr[0]);
507 if (aDrawMode == CGraphicsContext::EDrawModeXOR)
508 pixelPtr[0] = (TUint8)(color ^ pixelPtr[0]);
509 else if (aDrawMode == CGraphicsContext::EDrawModeAND)
510 pixelPtr[0] = (TUint8)((color | 0xf0) & pixelPtr[0]);
511 else if (aDrawMode==CGraphicsContext::EDrawModeOR)
512 pixelPtr[0] = (TUint8)(color | pixelPtr[0]);
516 color = (color == color2) ? color1 : color2;
523 TUint8 bytemask = TUint8((aX & 1) ? 0x0f : 0xf0);
525 if (aDrawMode == CGraphicsContext::EDrawModeAND)
527 for (TInt x = aX; x < xLimit; x++,dataMask <<= 1,bytemask = (TUint8)~bytemask)
529 if (aData[0] & dataMask)
530 pixelPtr[0] &= bytemask;
542 void CDrawFourBppBitmapGray::WriteBinaryLineVertical(TInt aX,TInt aY,TUint32* aData,TInt aLength,TRgb aColor,TBool aUp)
544 if (iUserDispMode == EGray2)
545 aColor = TRgb::_Gray2(aColor._Gray2());
549 const TUint32 gray16 = aColor._Gray16();
551 if (iUserDispMode == EGray4 && gray16 % 5 != 0)
553 color1 = Hash(gray16,aX,aY);
554 color2 = Hash(gray16,aX,aY + 1);
557 color1 = color2 = gray16;
559 const TInt yLimit = aY + (aUp ? -aLength : aLength);
560 const TInt scanLineWords = aUp ? -iScanLineWords : iScanLineWords;
561 const TInt startword = aX / KPixelsPerWord;
562 const TInt startShift = (aX & 7) * KBitsPerPixel;
563 TUint32* pixelPtr = ScanLine(aY) + startword;
564 const TUint32* pixelPtrLimit = ScanLine(yLimit) + startword;
565 const TUint32 mask = ~(0xf << startShift);
566 TUint32 dataMask = 1;
568 if (color1 || color2)
570 color1 <<= startShift;
571 color2 <<= startShift;
572 TUint32 color = color1;
574 while (pixelPtr != pixelPtrLimit)
582 if (aData[0] & dataMask)
585 pixelPtr[0] |= color;
589 pixelPtr += scanLineWords;
590 color = (color == color2) ? color1 : color2;
595 while (pixelPtr != pixelPtrLimit)
603 if (aData[0] & dataMask)
607 pixelPtr += scanLineWords;
612 void CDrawFourBppBitmapGray::WriteLine(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
614 if (iUserDispMode == EGray2)
615 ShadeBuffer(aLength,aBuffer);
616 else if (iUserDispMode == EGray4)
617 DitherBuffer(aX,aY,aLength,aBuffer);
619 const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
620 const TInt finishLong = (aX + aLength) & (~7);
621 const TInt startShift = (startLong - aX) * KBitsPerPixel;
622 const TInt startShiftExtra = 32 - startShift;
623 const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
624 TUint32* base = ScanLine(aY);
625 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
626 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
628 if (finishLong < startLong)
630 const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << startShiftExtra);
631 pixelPtrLimit[0] &= ~mask;
632 pixelPtrLimit[0] |= (aBuffer[0] << startShiftExtra) & mask;
636 const TInt wordsToCopy = pixelPtrLimit - pixelPtr;
640 pixelPtr[-1] &= 0xffffffff >> startShift;
641 pixelPtr[-1] |= aBuffer[0] << startShiftExtra;
643 CopyOffset(pixelPtr,aBuffer,wordsToCopy,startShift);
644 aBuffer += wordsToCopy;
646 if (finishLong < aX + aLength)
648 TUint32 first = (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
649 pixelPtrLimit[0] = PasteInt(first,pixelPtrLimit[0],finishShift);
654 while (pixelPtr < pixelPtrLimit)
655 *pixelPtr++ = *aBuffer++;
657 if (finishLong < aX + aLength)
658 pixelPtrLimit[0] = PasteInt(aBuffer[0],pixelPtrLimit[0],finishShift);
662 void CDrawFourBppBitmapGray::WriteLineXOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
664 if (iUserDispMode == EGray2)
665 ShadeBuffer(aLength,aBuffer);
666 else if (iUserDispMode == EGray4)
667 DitherBuffer(aX,aY,aLength,aBuffer);
669 const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
670 const TInt finishLong = (aX + aLength) & (~7);
671 const TInt startShift = (startLong - aX) * KBitsPerPixel;
672 const TInt startShiftExtra = 32 - startShift;
673 const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
674 TUint32* base = ScanLine(aY);
675 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
676 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
678 if (finishLong < startLong)
680 const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << startShiftExtra);
681 pixelPtrLimit[0] ^= (aBuffer[0] << startShiftExtra) & mask;
687 pixelPtr[-1] ^= aBuffer[0] << startShiftExtra;
689 while (pixelPtr < pixelPtrLimit)
691 pixelPtr[0] ^= (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
697 if (finishLong < aX + aLength)
699 TUint32 first = (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
700 pixelPtrLimit[0] ^= PasteInt(first,0,finishShift);
705 while (pixelPtr < pixelPtrLimit)
706 *pixelPtr++ ^= *aBuffer++;
708 if (finishLong < aX + aLength)
709 pixelPtrLimit[0] ^= PasteInt(aBuffer[0],0,finishShift);
713 void CDrawFourBppBitmapGray::WriteLineAND(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
715 if (iUserDispMode == EGray2)
716 ShadeBuffer(aLength,aBuffer);
717 else if (iUserDispMode == EGray4)
718 DitherBuffer(aX,aY,aLength,aBuffer);
720 const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
721 const TInt finishLong = (aX + aLength) & (~7);
722 const TInt startShift = (startLong - aX) * KBitsPerPixel;
723 const TInt startShiftExtra = 32 - startShift;
724 const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
725 TUint32* base = ScanLine(aY);
726 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
727 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
729 if (finishLong < startLong)
731 const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << startShiftExtra);
732 pixelPtrLimit[0] &= (aBuffer[0] << startShiftExtra) | ~mask;
738 pixelPtr[-1] &= (aBuffer[0] << startShiftExtra) | (0xffffffff >> startShift);
740 while (pixelPtr < pixelPtrLimit)
742 pixelPtr[0] &= (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
748 if (finishLong < aX + aLength)
750 TUint32 first = (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
751 pixelPtrLimit[0] &= PasteInt(first,0xffffffff,finishShift);
756 while (pixelPtr < pixelPtrLimit)
757 *pixelPtr++ &= *aBuffer++;
759 if (finishLong < aX + aLength)
760 pixelPtrLimit[0] &= PasteInt(aBuffer[0],0xffffffff,finishShift);
764 void CDrawFourBppBitmapGray::WriteLineOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
766 if (iUserDispMode == EGray2)
767 ShadeBuffer(aLength,aBuffer);
768 else if (iUserDispMode == EGray4)
769 DitherBuffer(aX,aY,aLength,aBuffer);
771 const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
772 const TInt finishLong = (aX + aLength) & (~7);
773 const TInt startShift = (startLong - aX) * KBitsPerPixel;
774 const TInt startShiftExtra = 32 - startShift;
775 const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
776 TUint32* base = ScanLine(aY);
777 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
778 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
780 if (finishLong < startLong)
782 const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << startShiftExtra);
783 pixelPtrLimit[0] |= (aBuffer[0] << startShiftExtra) & mask;
789 pixelPtr[-1] |= aBuffer[0] << startShiftExtra;
791 while (pixelPtr < pixelPtrLimit)
793 pixelPtr[0] |= (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
799 if (finishLong < aX + aLength)
801 TUint32 first = (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
802 pixelPtrLimit[0] |= PasteInt(first,0,finishShift);
807 while (pixelPtr < pixelPtrLimit)
808 *pixelPtr++ |= *aBuffer++;
810 if (finishLong < aX + aLength)
811 pixelPtrLimit[0] |= PasteInt(aBuffer[0],0,finishShift);
816 MAlphaBlend::WriteRgbAlphaLine() implementation.
817 @see MAlphaBlend::WriteRgbAlphaLine()
819 void CDrawFourBppBitmapGray::WriteRgbAlphaLine(TInt aX, TInt aY, TInt aLength,
820 const TUint8* aRgbBuffer,
821 const TUint8* aMaskBuffer,
822 MAlphaBlend::TShadowing aShadowing,
823 CGraphicsContext::TDrawMode /*aDrawMode*/)
825 TUint8* pixelPtr = REINTERPRET_CAST(TUint8*,ScanLine(aY)) + (aX / 2);
830 TRgb srcColor(aRgbBuffer[2],aRgbBuffer[1],aRgbBuffer[0]);
831 if(aShadowing == MAlphaBlend::EShdwBefore)
835 TInt pixelValue = (pixelPtr[0] >> 4) * (255 - aMaskBuffer[0]);
836 TInt srceValue = (((srcColor.Red() << 1) +
837 srcColor.Green() + (srcColor.Green() << 2) +
838 srcColor.Blue()) >> 7) * aMaskBuffer[0];
840 pixelValue += srceValue;
843 pixelClr = TRgb::_Gray16(pixelValue);
844 if(aShadowing == MAlphaBlend::EShdwAfter)
848 MapColorToUserDisplayMode(pixelClr);
851 pixelPtr[0] |= TUint8(pixelClr._Gray16() << 4);
859 const TUint8* pixelPtrLimit = pixelPtr + (aLength / 2);
861 while (pixelPtr < pixelPtrLimit)
863 TRgb srcColor1(aRgbBuffer[2],aRgbBuffer[1],aRgbBuffer[0]);
864 if(aShadowing == MAlphaBlend::EShdwBefore)
868 TInt pixelValue = (pixelPtr[0] & 0x0f) * (255 - aMaskBuffer[0]);
869 TInt srceValue = (((srcColor1.Red() << 1) +
870 srcColor1.Green() + (srcColor1.Green() << 2) +
871 srcColor1.Blue()) >> 7) * aMaskBuffer[0];
873 pixelValue += srceValue;
876 TInt nextValue = (pixelPtr[0] >> 4) * (255 - aMaskBuffer[1]);
878 pixelClr = TRgb::_Gray16(pixelValue);
879 if(aShadowing == MAlphaBlend::EShdwAfter)
883 MapColorToUserDisplayMode(pixelClr);
885 pixelPtr[0] = TUint8(pixelClr._Gray16());
887 TRgb srcColor2(aRgbBuffer[6],aRgbBuffer[5],aRgbBuffer[4]);
888 if(aShadowing == MAlphaBlend::EShdwBefore)
892 srceValue = (((srcColor2.Red() << 1) +
893 srcColor2.Green() + (srcColor2.Green() << 2) +
894 srcColor2.Blue()) >> 7) * aMaskBuffer[1];
896 nextValue += srceValue;
899 pixelClr = TRgb::_Gray16(nextValue);
900 if(aShadowing == MAlphaBlend::EShdwAfter)
904 MapColorToUserDisplayMode(pixelClr);
906 pixelPtr[0] |= TUint8(pixelClr._Gray16() << 4);
915 TRgb srcColor(aRgbBuffer[2],aRgbBuffer[1],aRgbBuffer[0]);
916 if(aShadowing == MAlphaBlend::EShdwBefore)
920 TInt pixelValue = (pixelPtr[0] & 0x0f) * (255 - aMaskBuffer[0]);
921 TInt srceValue = (((srcColor.Red() << 1) +
922 srcColor.Green() + (srcColor.Green() << 2) +
923 srcColor.Blue()) >> 7) * aMaskBuffer[0];
925 pixelValue += srceValue;
928 pixelClr = TRgb::_Gray16(pixelValue);
929 if(aShadowing == MAlphaBlend::EShdwAfter)
933 MapColorToUserDisplayMode(pixelClr);
936 pixelPtr[0] |= TUint8(pixelClr._Gray16());
940 void CDrawFourBppBitmapGray::WriteRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
942 if (iUserDispMode == EGray2)
943 aColor = TRgb::_Gray2(aColor._Gray2());
945 const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
946 const TInt finishLong = (aX + aLength) & (~7);
947 const TInt yLimit = aY + aHeight;
948 const TInt startShift = (startLong - aX) * KBitsPerPixel;
949 const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
950 TUint32* base = ScanLine(aY);
951 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
952 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
954 TUint32 colorWord1,colorWord2;
955 if (iUserDispMode == EGray4 && aColor._Gray16() % 5 != 0)
957 colorWord1 = HashInt(aColor,startLong,aY);
958 colorWord2 = HashInt(aColor,startLong,aY + 1);
961 colorWord1 = colorWord2 = ColorInt(aColor);
962 TUint32 colorWord = colorWord1;
964 if (finishLong < startLong)
966 const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << (32 - startShift));
967 const TUint32 invertedMask = ~mask;
972 for (; aY < yLimit; aY++)
974 pixelPtrLimit[0] &= invertedMask;
975 pixelPtrLimit[0] |= colorWord;
976 pixelPtrLimit += iScanLineWords;
977 colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
982 const TBool extra = (finishLong < aX + aLength);
984 for (; aY < yLimit; aY++)
987 pixelPtr[-1] = PasteInt(pixelPtr[-1],colorWord,startShift);
989 for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
990 tempPixelPtr[0] = colorWord;
993 pixelPtrLimit[0] = PasteInt(colorWord,pixelPtrLimit[0],finishShift);
995 pixelPtr += iScanLineWords;
996 pixelPtrLimit += iScanLineWords;
997 colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
1001 void CDrawFourBppBitmapGray::WriteRgbMultiXOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
1003 if (iUserDispMode == EGray2)
1004 aColor = TRgb::_Gray2(aColor._Gray2());
1006 const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
1007 const TInt finishLong = (aX + aLength) & (~7);
1008 const TInt yLimit = aY + aHeight;
1009 const TInt startShift = (startLong - aX) * KBitsPerPixel;
1010 const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
1011 TUint32* base = ScanLine(aY);
1012 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
1013 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
1015 TUint32 colorWord1,colorWord2;
1016 if (iUserDispMode == EGray4 && aColor._Gray16() % 5 != 0)
1018 colorWord1 = HashInt(aColor,startLong,aY);
1019 colorWord2 = HashInt(aColor,startLong,aY + 1);
1022 colorWord1 = colorWord2 = ColorInt(aColor);
1023 TUint32 colorWord = colorWord1;
1025 if (finishLong < startLong)
1027 const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << (32 - startShift));
1032 for (; aY < yLimit; aY++)
1034 pixelPtrLimit[0] ^= colorWord;
1035 pixelPtrLimit += iScanLineWords;
1036 colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
1041 const TBool extra = (finishLong < aX + aLength);
1043 for (; aY < yLimit; aY++)
1046 pixelPtr[-1] ^= PasteInt(0,colorWord,startShift);
1048 for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
1049 tempPixelPtr[0] ^= colorWord;
1052 pixelPtrLimit[0] ^= PasteInt(colorWord,0,finishShift);
1054 pixelPtr += iScanLineWords;
1055 pixelPtrLimit += iScanLineWords;
1056 colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
1060 void CDrawFourBppBitmapGray::WriteRgbMultiAND(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
1062 if (iUserDispMode == EGray2)
1063 aColor = TRgb::_Gray2(aColor._Gray2());
1065 const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
1066 const TInt finishLong = (aX + aLength) & (~7);
1067 const TInt yLimit = aY + aHeight;
1068 const TInt startShift = (startLong - aX) * KBitsPerPixel;
1069 const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
1070 TUint32* base = ScanLine(aY);
1071 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
1072 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
1074 TUint32 colorWord1,colorWord2;
1075 if (iUserDispMode == EGray4 && aColor._Gray16() % 5 != 0)
1077 colorWord1 = HashInt(aColor,startLong,aY);
1078 colorWord2 = HashInt(aColor,startLong,aY + 1);
1081 colorWord1 = colorWord2 = ColorInt(aColor);
1082 TUint32 colorWord = colorWord1;
1084 if (finishLong < startLong)
1086 const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << (32 - startShift));
1087 const TUint32 invertedMask = ~mask;
1091 colorWord |= invertedMask;
1092 colorWord1 |= invertedMask;
1093 colorWord2 |= invertedMask;
1095 for (; aY < yLimit; aY++)
1097 pixelPtrLimit[0] &= colorWord;
1098 pixelPtrLimit += iScanLineWords;
1099 colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
1104 const TBool extra = (finishLong < aX + aLength);
1106 for (; aY < yLimit; aY++)
1109 pixelPtr[-1] &= PasteInt(0xffffffff,colorWord,startShift);
1111 for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
1112 tempPixelPtr[0] &= colorWord;
1115 pixelPtrLimit[0] &= PasteInt(colorWord,0xffffffff,finishShift);
1117 pixelPtr += iScanLineWords;
1118 pixelPtrLimit += iScanLineWords;
1119 colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
1123 void CDrawFourBppBitmapGray::WriteRgbMultiOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
1125 if (iUserDispMode == EGray2)
1126 aColor = TRgb::_Gray2(aColor._Gray2());
1128 const TInt startLong = (aX + KPixelsPerWord - 1) & (~7);
1129 const TInt finishLong = (aX + aLength) & (~7);
1130 const TInt yLimit = aY + aHeight;
1131 const TInt startShift = (startLong - aX) * KBitsPerPixel;
1132 const TInt finishShift = (KPixelsPerWord - aX - aLength + finishLong) * KBitsPerPixel;
1133 TUint32* base = ScanLine(aY);
1134 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
1135 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
1137 TUint32 colorWord1,colorWord2;
1138 if (iUserDispMode == EGray4 && aColor._Gray16() % 5 != 0)
1140 colorWord1 = HashInt(aColor,startLong,aY);
1141 colorWord2 = HashInt(aColor,startLong,aY + 1);
1144 colorWord1 = colorWord2 = ColorInt(aColor);
1145 TUint32 colorWord = colorWord1;
1147 if (finishLong < startLong)
1149 const TUint32 mask = (0xffffffff >> finishShift) & (0xffffffff << (32 - startShift));
1154 for (; aY < yLimit; aY++)
1156 pixelPtrLimit[0] |= colorWord;
1157 pixelPtrLimit += iScanLineWords;
1158 colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
1163 const TBool extra = (finishLong < aX + aLength);
1165 for (; aY < yLimit; aY++)
1168 pixelPtr[-1] |= PasteInt(0,colorWord,startShift);
1170 for (TUint32* tempPixelPtr = pixelPtr; tempPixelPtr < pixelPtrLimit; tempPixelPtr++)
1171 tempPixelPtr[0] |= colorWord;
1174 pixelPtrLimit[0] |= PasteInt(colorWord,0,finishShift);
1176 pixelPtr += iScanLineWords;
1177 pixelPtrLimit += iScanLineWords;
1178 colorWord = (colorWord == colorWord2) ? colorWord1 : colorWord2;
1182 void CDrawFourBppBitmapGray::WriteRgbAlphaMulti(TInt aX,TInt aY,TInt aLength,TRgb aColor,const TUint8* aMaskBuffer)
1185 TUint8* pixelPtr = REINTERPRET_CAST(TUint8*,ScanLine(aY)) + (aX / 2);
1186 const TBool oddEndCoord = (aX + aLength) & 1;
1187 const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength - (oddEndCoord ? 1 : 0);
1192 const TInt gray = aColor._Gray256();
1195 const TInt upper = ((gray * aMaskBuffer[0]) + ((255 - aMaskBuffer[0]) * (pixelPtr[0] >> 4) * 17)) / (255 * 17);
1196 pixelPtr[0] &= 0x0f;
1197 pixelPtr[0] |= TUint8(upper << 4);
1203 while (aMaskBuffer < maskBufferPtrLimit)
1205 const TInt lower = ((gray * aMaskBuffer[0]) + ((255 - aMaskBuffer[0]) * (pixelPtr[0] & 0x0f) * 17)) / (255 * 17);
1206 const TInt upper = ((gray * aMaskBuffer[1]) + ((255 - aMaskBuffer[1]) * (pixelPtr[0] >> 4) * 17)) / (255 * 17);
1207 pixelPtr[0] = TUint8(lower);
1208 pixelPtr[0] |= TUint8(upper << 4);
1216 const TInt lower = ((gray * aMaskBuffer[0]) + ((255 - aMaskBuffer[0]) * (pixelPtr[0] & 0x0f) * 17)) / (255 * 17);
1217 pixelPtr[0] &= 0xf0;
1218 pixelPtr[0] |= TUint8(lower);
1222 void CDrawFourBppBitmapGray::MapColorToUserDisplayMode(TRgb& aColor)
1224 switch (iUserDispMode)
1227 aColor = TRgb::_Gray2(aColor._Gray2());
1230 aColor = TRgb::_Gray4(aColor._Gray4());
1237 void CDrawFourBppBitmapGray::MapBufferToUserDisplayMode(TInt aLength,TUint32* aBuffer)
1239 TUint8* bufferPtr = (TUint8*)aBuffer;
1240 const TUint8* bufferLimit = bufferPtr + ((aLength + 1) / 2);
1242 switch (iUserDispMode)
1245 while (bufferPtr < bufferLimit)
1247 TUint8 value = TUint8(*bufferPtr & 0x88);
1248 value |= value >> 1;
1249 *bufferPtr++ = TUint8(value | (value >> 2));
1253 while (bufferPtr < bufferLimit)
1255 TUint8 value = TUint8(*bufferPtr & 0xcc);
1256 *bufferPtr++ = TUint8(value | (value >> 2));
1264 TInt CDrawFourBppBitmapGray::WriteRgbOutlineAndShadow(TInt aX, TInt aY, const TInt aLength,
1265 TUint32 aOutlinePenColor, TUint32 aShadowColor,
1266 TUint32 aFillColor, const TUint8* aDataBuffer)
1268 //This is non-optimised since this screen mode is rarely used and is usually
1269 //fast enough without optimisation.
1271 TUint8* pixelPtr = REINTERPRET_CAST(TUint8*,ScanLine(aY)) + (aX / 2);
1272 const TBool oddEndCoord = (aX + aLength) & 1;
1273 const TUint8* dataBufferPtrLimit = aDataBuffer + aLength - (oddEndCoord ? 1 : 0);
1277 TRgb lowerPixelColor;
1278 TRgb upperPixelColor;
1280 TRgb outlinePenColor;
1281 outlinePenColor.SetInternal(aOutlinePenColor);
1283 shadowColor.SetInternal(aShadowColor);
1285 fillColor.SetInternal(aFillColor);
1287 const TInt redOutlinePenColor = outlinePenColor.Red();
1288 const TInt redShadowColor = shadowColor.Red();
1289 const TInt redFillColor = fillColor.Red();
1291 const TInt greenOutlinePenColor = outlinePenColor.Green();
1292 const TInt greenShadowColor = shadowColor.Green();
1293 const TInt greenFillColor = fillColor.Green();
1295 const TInt blueOutlinePenColor = outlinePenColor.Blue();
1296 const TInt blueShadowColor = shadowColor.Blue();
1297 const TInt blueFillColor = fillColor.Blue();
1301 index = *aDataBuffer;
1303 if (255 != FourColorBlendLookup[index][KBackgroundColorIndex])
1305 TRgb backgroundColor = TRgb::_Gray16(pixelPtr[0] >> 4);
1306 finalColor = BlendFourColors(aOutlinePenColor, aShadowColor, aFillColor,
1307 redOutlinePenColor, redShadowColor, redFillColor,
1308 greenOutlinePenColor, greenShadowColor, greenFillColor,
1309 blueOutlinePenColor, blueShadowColor, blueFillColor,
1310 backgroundColor, index);
1311 pixelPtr[0] &= 0x0f;
1312 pixelPtr[0] |= TUint8(finalColor._Gray16() << 4);
1319 while (aDataBuffer < dataBufferPtrLimit)
1321 index = aDataBuffer[0];
1322 TRgb upperPixelBackgroundColor = TRgb::_Gray16(pixelPtr[0] >> 4);
1323 if (255 != FourColorBlendLookup[index][KBackgroundColorIndex])
1325 TRgb lowerPixelBackgroundColor = TRgb::_Gray16(pixelPtr[0] & 0x0f);
1326 lowerPixelColor = BlendFourColors(aOutlinePenColor, aShadowColor, aFillColor,
1327 redOutlinePenColor, redShadowColor, redFillColor,
1328 greenOutlinePenColor, greenShadowColor, greenFillColor,
1329 blueOutlinePenColor, blueShadowColor, blueFillColor,
1330 lowerPixelBackgroundColor, index);
1331 pixelPtr[0] = TUint8(lowerPixelColor._Gray16());
1334 index = aDataBuffer[1];
1335 if (255 != FourColorBlendLookup[index][KBackgroundColorIndex])
1337 upperPixelColor = BlendFourColors(aOutlinePenColor, aShadowColor, aFillColor,
1338 redOutlinePenColor, redShadowColor, redFillColor,
1339 greenOutlinePenColor, greenShadowColor, greenFillColor,
1340 blueOutlinePenColor, blueShadowColor, blueFillColor,
1341 upperPixelBackgroundColor, index);
1342 pixelPtr[0] |= TUint8(upperPixelColor._Gray16() << 4);
1350 index = aDataBuffer[0];
1351 if (255 != FourColorBlendLookup[index][KBackgroundColorIndex])
1353 TRgb backgroundColor = TRgb::_Gray16(pixelPtr[0] & 0x0f);
1354 finalColor = BlendFourColors(aOutlinePenColor, aShadowColor, aFillColor,
1355 redOutlinePenColor, redShadowColor, redFillColor,
1356 greenOutlinePenColor, greenShadowColor, greenFillColor,
1357 blueOutlinePenColor, blueShadowColor, blueFillColor,
1358 backgroundColor, index);
1359 pixelPtr[0] &= 0xf0;
1360 pixelPtr[0] |= TUint8(finalColor._Gray16());
1366 TRgb CDrawFourBppBitmapGray::BlendFourColors(TUint32 aOutlinePenColor, TUint32 aShadowColor, TUint32 aFillColor,
1367 TInt aRedOutlinePenColor, TInt aRedShadowColor, TInt aRedFillColor,
1368 TInt aGreenOutlinePenColor, TInt aGreenShadowColor, TInt aGreenFillColor,
1369 TInt aBlueOutlinePenColor, TInt aBlueShadowColor, TInt aBlueFillColor,
1370 TRgb aBackgroundColor, TUint8 aIndex) const
1373 if (255 == FourColorBlendLookup[aIndex][KFillColorIndex])
1376 finalColor.SetInternal(aFillColor);
1378 else if (255 == FourColorBlendLookup[aIndex][KShadowColorIndex])
1381 finalColor.SetInternal(aShadowColor);
1383 else if (255 == FourColorBlendLookup[aIndex][KOutlineColorIndex])
1386 finalColor.SetInternal(aOutlinePenColor);
1390 TInt blendedRedColor = (aRedOutlinePenColor * FourColorBlendLookup[aIndex][KOutlineColorIndex] +
1391 aRedShadowColor * FourColorBlendLookup[aIndex][KShadowColorIndex] +
1392 aRedFillColor * FourColorBlendLookup[aIndex][KFillColorIndex] +
1393 aBackgroundColor.Red() * FourColorBlendLookup[aIndex][KBackgroundColorIndex]) >> 8;
1395 TInt blendedGreenColor = (aGreenOutlinePenColor * FourColorBlendLookup[aIndex][KOutlineColorIndex] +
1396 aGreenShadowColor * FourColorBlendLookup[aIndex][KShadowColorIndex] +
1397 aGreenFillColor * FourColorBlendLookup[aIndex][KFillColorIndex] +
1398 aBackgroundColor.Green() * FourColorBlendLookup[aIndex][KBackgroundColorIndex]) >> 8;
1400 TInt blendedBlueColor = (aBlueOutlinePenColor * FourColorBlendLookup[aIndex][KOutlineColorIndex] +
1401 aBlueShadowColor * FourColorBlendLookup[aIndex][KShadowColorIndex] +
1402 aBlueFillColor * FourColorBlendLookup[aIndex][KFillColorIndex] +
1403 aBackgroundColor.Blue() * FourColorBlendLookup[aIndex][KBackgroundColorIndex]) >> 8;
1404 finalColor = TRgb(blendedRedColor, blendedGreenColor, blendedBlueColor);