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 const TInt KPixelsPerByte = 8;
19 const TInt KPixelsPerWord = 32;
21 //Initializes iSize, iDrawRect, iLongWidth, iScanlineWords data members.
22 //It should be called every time when iSize is going to be changed - from Construct().
23 //@param aSize Physical screen size in pixels.
24 //@panic EScreenDriverPanicInvalidSize - Invalid aSize parameter. This might happen if the
25 //device is scaled and the scaling origin goes outside physical drawing rectangle.
26 void CDrawOneBppBitmap::SetSize(const TSize& aSize)
28 CDrawBitmap::SetSize(aSize);
29 __ASSERT_DEBUG(iSize == aSize, User::Invariant());
30 iLongWidth = (iSize.iWidth + (KPixelsPerWord - 1)) & ~(KPixelsPerWord - 1);
31 iScanLineWords = iLongWidth / KPixelsPerWord;
34 TInt CDrawOneBppBitmap::Construct(TSize aSize)
36 return Construct(aSize, ((aSize.iWidth + (KPixelsPerWord - 1)) & ~(KPixelsPerWord - 1)) / KPixelsPerByte);
39 TInt CDrawOneBppBitmap::Construct(TSize aSize, TInt aStride)
43 CDrawBitmap::SetSize(aSize);
44 __ASSERT_DEBUG(iSize == aSize, User::Invariant());
47 iLongWidth = aStride * KPixelsPerByte;
48 if (iLongWidth < aSize.iWidth)
50 iScanLineWords = aStride >> 2;
51 TInt size = 1 + (Max(aSize.iWidth,aSize.iHeight) >> 3);
54 iScanLineBuffer = (TUint32*)(User::Heap().Alloc(size));
55 if (iScanLineBuffer == NULL)
60 void CDrawOneBppBitmap::Shadow(TRgb& aColor)
62 if (iShadowMode & EFade)
63 aColor = FadeRgb(TRgb::_Gray2(aColor._Gray2()));
65 if (iShadowMode & EShadow)
69 void CDrawOneBppBitmap::InvertBuffer(TInt aLength,TUint32* aBuffer)
71 __ASSERT_DEBUG(aLength > 0,Panic(EScreenDriverPanicZeroLength));
72 __ASSERT_DEBUG(aBuffer,Panic(EScreenDriverPanicNullPointer));
74 const TUint32* const limit = aBuffer + ((aLength + KPixelsPerWord - 1) / KPixelsPerWord);
76 while (aBuffer < limit)
77 *aBuffer++ ^= 0xffffffff;
80 /** Copies a number of pixels into a word-aligned buffer without format translation.
81 Note that the byte length to the target buffer is honoured,
82 but the end contents of the last byte are generally overwritten with extra pixel data (or garbage)
83 Note that I am assuming the compiler optimiser will convert all these divides and multiplies into shifts!
84 @param aX x coordinate to start copy from (need not be aligned at all)
85 @param aY y coordinate to copy line from
86 @param aLength number of pixels to copy
87 @param aBuffer target word-aligned buffer (but may or may not be word length)
89 void CDrawOneBppBitmap::ReadLine(TInt aX,TInt aY,TInt aLength,TAny* aBuffer) const
91 TUint32* pixelPtr = ScanLine(aY);
92 TInt startLongPix = aX & -KPixelsPerWord;
93 pixelPtr += startLongPix / KPixelsPerWord;
94 TUint32* bufferPtr = (TUint32*)aBuffer;
95 TInt wordsCnt = (aLength+KPixelsPerByte-1) / KPixelsPerWord; //how many words to write to target
96 TInt restPixels = aLength - wordsCnt * KPixelsPerWord; //how many pixels left to copy
97 TInt bytesCnt = (restPixels+KPixelsPerByte-1) / KPixelsPerByte ; //how many target bytes to copy
98 TInt shiftBits = aX - startLongPix;
99 restPixels=shiftBits+restPixels; //How many pixels are read from the second word by the final word copy
100 if (bytesCnt==0 && shiftBits && restPixels<=0)
102 // This correction is required because although a last whole word will be written to the target buffer,
103 // this special test indicates that the required significant data bits plus the shift
104 // add up to one word (or less) to be read.
105 // The copy words optimisation used to copy the main body of the line
106 // will read from the next location after the copy,
107 // but this may not always be accessable memory (on the last scanline)
108 // The correction is not required if the second word would need to be read anyway.
109 //eg we want to copy 7 nibbles with a 1 nibble shift (16 color), restpixels would be 0
113 //How many pixels are read from the second word in the final byte copy?
114 //If zero (or less) then the second word should not be read in the copy bytes phase
115 //really this should be an else of the if above, but this gives the same end condition.
116 //eg we want to copy 5 nibbles with a 2 nibble shift (16 color), restpixels would be -1.
117 restPixels-=KPixelsPerWord;
118 ReadLineCommon(pixelPtr,bufferPtr,wordsCnt,restPixels,bytesCnt,shiftBits);
122 TRgb CDrawOneBppBitmap::ReadRgbNormal(TInt aX,TInt aY) const
124 TUint32 colorWord = *(ScanLine(aY) + (aX / KPixelsPerWord));
126 if (colorWord & (1 << (aX & 0x1f)))
132 void CDrawOneBppBitmap::ShadowArea(const TRect& aRect)
134 __ASSERT_DEBUG(aRect.iTl.iX>=0 && aRect.iBr.iX<=iSize.iWidth,Panic(EScreenDriverPanicOutOfBounds));
135 __ASSERT_DEBUG(aRect.iTl.iY>=0 && aRect.iBr.iY<=iSize.iHeight,Panic(EScreenDriverPanicOutOfBounds));
137 if (iShadowMode & EFade)
139 TInt fadedWhite = FadeRgb(KRgbWhite)._Gray2();
140 TInt fadedBlack = FadeRgb(KRgbBlack)._Gray2();
144 if (fadedBlack) // Everything fades to white
145 WriteRgbMulti(aRect.iTl.iX,aRect.iTl.iY,aRect.Width(),aRect.Height(),KRgbWhite);
146 // else Nothing changes
150 if (fadedBlack) // Everything inverted
151 WriteRgbMultiXOR(aRect.iTl.iX,aRect.iTl.iY,aRect.Width(),aRect.Height(),KRgbWhite);
152 else // Everything fades to black
153 WriteRgbMulti(aRect.iTl.iX,aRect.iTl.iY,aRect.Width(),aRect.Height(),KRgbBlack);
157 if (iShadowMode & EShadow)
159 const TInt x = aRect.iTl.iX;
160 TInt y = aRect.iTl.iY;
161 const TInt startLong = (x + KPixelsPerWord - 1) & (~0x1f);
162 const TInt finishLong = (aRect.iBr.iX) & (~0x1f);
163 const TInt startShift = startLong - x;
164 TUint32* base = ScanLine(y);
165 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
166 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
168 if (finishLong < startLong)
170 TUint32 mask = (0xffffffff >> (startLong - aRect.iBr.iX)) & (0xffffffff << (x - finishLong));
173 for (; y < aRect.iBr.iY; y++)
175 pixelPtrLimit[0] &= mask;
176 pixelPtrLimit += iScanLineWords;
182 const TInt bytesToFill = (pixelPtrLimit - pixelPtr) * sizeof(TUint32);
183 const TInt finishShift = 32 - aRect.iBr.iX + finishLong;
185 for (;y<aRect.iBr.iY;y++)
188 pixelPtr[-1] = PasteInt(pixelPtr[-1],0,startShift);
190 Mem::FillZ(pixelPtr,bytesToFill);
192 if (finishLong < aRect.iBr.iX)
193 pixelPtrLimit[0] = PasteInt(0,pixelPtrLimit[0],finishShift);
195 pixelPtr += iScanLineWords;
196 pixelPtrLimit += iScanLineWords;
201 void CDrawOneBppBitmap::ShadowBuffer(TInt aLength,TUint32* aBuffer)
203 __ASSERT_DEBUG(aLength>0,Panic(EScreenDriverPanicZeroLength));
204 __ASSERT_DEBUG(aBuffer,Panic(EScreenDriverPanicNullPointer));
206 const TInt byteLength = (aLength + 7) / 8;
208 if (iShadowMode & EFade)
210 TInt fadedWhite = FadeRgb(KRgbWhite)._Gray2();
211 TInt fadedBlack = FadeRgb(KRgbBlack)._Gray2();
215 if (fadedBlack) // Everything fades to white
216 Mem::Fill(aBuffer,byteLength,0xff);
217 // else Nothing changes
221 if (fadedBlack) // Everything inverted
223 TUint8* bufferPtr = REINTERPRET_CAST(TUint8*,aBuffer);
224 const TUint8* bufferPtrLimit = bufferPtr + byteLength;
226 while (bufferPtr < bufferPtrLimit)
229 else // Everything fades to black
230 Mem::FillZ(aBuffer,byteLength);
234 if (iShadowMode & EShadow)
235 Mem::FillZ(aBuffer,byteLength);
238 void CDrawOneBppBitmap::WriteRgb(TInt aX,TInt aY,TRgb aColor)
240 TUint32* pixelPtr = ScanLine(aY) + (aX / KPixelsPerWord);
241 const TUint32 mask = 1 << (aX & 0x1f);
246 pixelPtr[0] &= ~mask;
249 void CDrawOneBppBitmap::WriteBinary(TInt aX,TInt aY,TUint32* aBuffer,TInt aLength,TInt aHeight,TRgb aColor)
251 const TBool white = (aColor._Gray2() == 1);
252 TUint32* pixelPtr = ScanLine(aY) + (aX / KPixelsPerWord);
253 const TUint32* pixelPtrLimit = pixelPtr + (aHeight * iScanLineWords);
255 while (pixelPtr < pixelPtrLimit)
257 TUint32 dataMask = 1;
258 TUint32 mask = 1 << (aX & 0x1f);
259 TUint32* tempPixelPtr = pixelPtr;
261 for (TInt count = 0; count < aLength; count++,dataMask <<= 1,mask <<= 1)
269 if (aBuffer[0] & dataMask)
272 tempPixelPtr[0] |= mask;
274 tempPixelPtr[0] &= ~mask;
279 pixelPtr += iScanLineWords;
283 void CDrawOneBppBitmap::WriteBinaryOp(TInt aX,TInt aY,TUint32* aBuffer,TInt aLength,TInt aHeight,TRgb aColor,CGraphicsContext::TDrawMode aDrawMode)
285 const TBool white = (aColor._Gray2() == 1);
286 TUint32* pixelPtr = ScanLine(aY) + (aX / KPixelsPerWord);
287 const TUint32* pixelPtrLimit = pixelPtr + (aHeight * iScanLineWords);
288 TUint32 initialMask = 1 << (aX & 0x1f);
292 if (aDrawMode == CGraphicsContext::EDrawModeXOR || aDrawMode == CGraphicsContext::EDrawModeOR)
294 while (pixelPtr < pixelPtrLimit)
296 TUint32 dataMask = 1;
297 TUint32 mask = initialMask;
298 TUint32* tempPixelPtr = pixelPtr;
300 for (TInt count = 0; count < aLength;count++,dataMask <<= 1,mask <<= 1)
308 if (aBuffer[0] & dataMask)
310 if (aDrawMode == CGraphicsContext::EDrawModeXOR)
311 tempPixelPtr[0] ^= mask;
312 else if (aDrawMode == CGraphicsContext::EDrawModeOR)
313 tempPixelPtr[0] |= mask;
318 pixelPtr += iScanLineWords;
324 if (aDrawMode == CGraphicsContext::EDrawModeAND)
326 while (pixelPtr < pixelPtrLimit)
328 TUint32 dataMask = 1;
329 TUint32 mask = initialMask;
330 TUint32* tempPixelPtr = pixelPtr;
332 for (TInt count = 0; count < aLength;count++,dataMask <<= 1,mask <<= 1)
340 if (*aBuffer & dataMask)
341 *tempPixelPtr &= ~mask;
345 pixelPtr += iScanLineWords;
351 void CDrawOneBppBitmap::WriteBinaryLineVertical(TInt aX,TInt aY,TUint32* aBuffer,TInt aHeight,TRgb aColor,TBool aUp)
353 const TBool white = (aColor._Gray2() == 1);
354 const TInt yLimit = aY + ((aUp) ? -aHeight : aHeight);
355 const TInt scanLineWords = (aUp) ? -iScanLineWords : iScanLineWords;
356 const TInt startWord = aX / KPixelsPerWord;
357 TUint32* pixelPtr = ScanLine(aY) + startWord;
358 TUint32* pixelPtrLimit = ScanLine(yLimit) + startWord;
359 TUint32 mask = 1 << (aX & 0x1f);
360 TUint32 dataMask = 1;
364 while (pixelPtr != pixelPtrLimit)
372 if (aBuffer[0] & dataMask)
376 pixelPtr += scanLineWords;
382 while (pixelPtr != pixelPtrLimit)
390 if (aBuffer[0] & dataMask)
394 pixelPtr += scanLineWords;
399 void CDrawOneBppBitmap::WriteLine(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
401 const TInt startLong = (aX + KPixelsPerWord - 1) & (~0x1f);
402 const TInt finishLong = (aX + aLength) & (~0x1f);
403 const TInt startShift = startLong - aX;
404 const TInt startShiftExtra = 32 - startShift;
405 const TInt finishX = aX + aLength;
406 TUint32* base = ScanLine(aY);
407 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
408 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
410 if (finishLong < startLong)
412 TUint32 mask = (0xffffffff << startShiftExtra) & (0xffffffff >> (startLong - finishX));
413 pixelPtrLimit[0] &= ~mask;
414 pixelPtrLimit[0] |= (aBuffer[0] << startShiftExtra) & mask;
420 pixelPtr[-1] &= 0xffffffff >> startShift;
421 pixelPtr[-1] |= aBuffer[0] << startShiftExtra;
423 while (pixelPtr < pixelPtrLimit)
425 pixelPtr[0] = (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
430 if (finishLong < finishX)
432 TUint32 value = (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
433 pixelPtrLimit[0] = PasteInt(value,pixelPtrLimit[0],32 - finishX + finishLong);
438 while (pixelPtr < pixelPtrLimit)
439 *pixelPtr++ = *aBuffer++;
441 if (finishLong < finishX)
442 pixelPtrLimit[0] = PasteInt(aBuffer[0],pixelPtrLimit[0],32 - finishX + finishLong);
446 void CDrawOneBppBitmap::WriteLineXOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
448 const TInt startLong = (aX + KPixelsPerWord - 1) & (~0x1f);
449 const TInt finishLong = (aX + aLength) & (~0x1f);
450 const TInt startShift = startLong - aX;
451 const TInt startShiftExtra = 32 - startShift;
452 const TInt finishX = aX + aLength;
453 TUint32* base = ScanLine(aY);
454 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
455 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
457 if (finishLong < startLong)
459 TUint32 mask = (0xffffffff << startShiftExtra) & (0xffffffff >> (startLong - finishX));
460 pixelPtrLimit[0] ^= (aBuffer[0] << startShiftExtra) & mask;
466 pixelPtr[-1] ^= aBuffer[0] << startShiftExtra;
468 while (pixelPtr < pixelPtrLimit)
470 pixelPtr[0] ^= (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
475 if (finishLong < finishX)
477 TUint32 value = (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
478 pixelPtrLimit[0] ^= PasteInt(value,0,32 - finishX + finishLong);
483 while (pixelPtr < pixelPtrLimit)
484 *pixelPtr++ ^= *aBuffer++;
486 if (finishLong < finishX)
487 pixelPtrLimit[0] ^= PasteInt(aBuffer[0],0,32 - finishX + finishLong);
491 void CDrawOneBppBitmap::WriteLineAND(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
493 const TInt startLong = (aX + KPixelsPerWord - 1) & (~0x1f);
494 const TInt finishLong = (aX + aLength) & (~0x1f);
495 const TInt startShift = startLong - aX;
496 const TInt startShiftExtra = 32 - startShift;
497 const TInt finishX = aX + aLength;
498 TUint32* base = ScanLine(aY);
499 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
500 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
502 if (finishLong < startLong)
504 TUint32 mask = (0xffffffff << startShiftExtra) & (0xffffffff >> (startLong - finishX));
505 pixelPtrLimit[0] &= (aBuffer[0] << startShiftExtra) | ~mask;
511 pixelPtr[-1] &= (aBuffer[0] << startShiftExtra) | (0xffffffff >> startShift);
513 while (pixelPtr < pixelPtrLimit)
515 pixelPtr[0] &= (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
520 if (finishLong < finishX)
522 TUint32 value = (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
523 pixelPtrLimit[0] &= PasteInt(value,0xffffffff,32 - finishX + finishLong);
528 while (pixelPtr < pixelPtrLimit)
529 *pixelPtr++ &= *aBuffer++;
531 if (finishLong < finishX)
532 pixelPtrLimit[0] &= PasteInt(aBuffer[0],0xffffffff,32 - finishX + finishLong);
536 void CDrawOneBppBitmap::WriteLineOR(TInt aX,TInt aY,TInt aLength,TUint32* aBuffer)
538 const TInt startLong = (aX + KPixelsPerWord - 1) & (~0x1f);
539 const TInt finishLong = (aX + aLength) & (~0x1f);
540 const TInt startShift = startLong - aX;
541 const TInt startShiftExtra = 32 - startShift;
542 const TInt finishX = aX + aLength;
543 TUint32* base = ScanLine(aY);
544 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
545 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
547 if (finishLong < startLong)
549 TUint32 mask = (0xffffffff << startShiftExtra) & (0xffffffff >> (startLong - finishX));
550 pixelPtrLimit[0] |= (aBuffer[0] << startShiftExtra) & mask;
556 pixelPtr[-1] |= aBuffer[0] << startShiftExtra;
558 while (pixelPtr < pixelPtrLimit)
560 pixelPtr[0] |= (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
565 if (finishLong < finishX)
567 TUint32 value = (aBuffer[0] >> startShift) | (aBuffer[1] << startShiftExtra);
568 pixelPtrLimit[0] |= PasteInt(value,0,32 - finishX + finishLong);
573 while (pixelPtr < pixelPtrLimit)
574 *pixelPtr++ |= *aBuffer++;
576 if (finishLong < finishX)
577 pixelPtrLimit[0] |= PasteInt(aBuffer[0],0,32 - finishX + finishLong);
582 MAlphaBlend::WriteRgbAlphaLine() implementation.
583 @see MAlphaBlend::WriteRgbAlphaLine()
585 void CDrawOneBppBitmap::WriteRgbAlphaLine(TInt aX, TInt aY, TInt aLength,
586 const TUint8* aRgbBuffer,
587 const TUint8* aMaskBuffer,
588 MAlphaBlend::TShadowing,
589 CGraphicsContext::TDrawMode /*aDrawMode*/)
591 TUint32* pixelPtr = ScanLine(aY) + (aX / KPixelsPerWord);
592 const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
593 TUint32 bitMask = 1 << (aX & 0x1f);
595 while (aMaskBuffer < maskBufferPtrLimit)
597 if (*aMaskBuffer++ & 0x80)
599 if (((aRgbBuffer[2] << 1) + aRgbBuffer[1] + (aRgbBuffer[1] << 2) + aRgbBuffer[0]) > 1016)
600 pixelPtr[0] |= bitMask;
602 pixelPtr[0] &= ~bitMask;
617 void CDrawOneBppBitmap::WriteRgbMulti(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
619 const TUint32 colorWord = (aColor._Gray2() == 1) ? 0xffffffff : 0;
620 const TInt yLimit = aY + aHeight;
621 const TInt startLong = (aX + KPixelsPerWord - 1) & (~0x1f);
622 const TInt finishLong = (aX + aLength) & (~0x1f);
623 const TInt startShift = startLong - aX;
624 const TInt finishShift = 32 - aX - aLength + finishLong;
625 TUint32* base = ScanLine(aY);
626 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
627 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
629 if (finishLong < startLong)
631 TUint32 mask = (0xffffffff << (32 - startShift)) & (0xffffffff >> (startShift - aLength));
632 const TUint32 maskedColorWord = colorWord & mask;
635 for (; aY < yLimit; aY++)
637 pixelPtrLimit[0] &= mask;
638 pixelPtrLimit[0] |= maskedColorWord;
639 pixelPtrLimit += iScanLineWords;
644 const TBool extra = (finishLong < aX + aLength);
646 for (; aY < yLimit; aY++)
648 TUint32* bmpbitstmp = pixelPtr;
651 bmpbitstmp[-1] = PasteInt(bmpbitstmp[-1],colorWord,startShift);
653 while (bmpbitstmp < pixelPtrLimit)
654 *bmpbitstmp++ = colorWord;
657 pixelPtrLimit[0] = PasteInt(colorWord,pixelPtrLimit[0],finishShift);
659 pixelPtr += iScanLineWords;
660 pixelPtrLimit += iScanLineWords;
664 void CDrawOneBppBitmap::WriteRgbMultiXOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
666 const TUint32 colorWord = (aColor._Gray2() == 1) ? 0xffffffff : 0;
667 const TInt yLimit = aY + aHeight;
668 const TInt startLong = (aX + KPixelsPerWord - 1) & (~0x1f);
669 const TInt finishLong = (aX + aLength) & (~0x1f);
670 const TInt startShift = startLong - aX;
671 const TInt finishShift = 32 - aX - aLength + finishLong;
672 TUint32* base = ScanLine(aY);
673 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
674 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
676 if (finishLong < startLong)
678 TUint32 mask = (0xffffffff << (32 - startShift)) & (0xffffffff >> (startShift - aLength));
679 const TUint32 maskedColorWord = colorWord & mask;
681 for (; aY < yLimit; aY++)
683 pixelPtrLimit[0] ^= maskedColorWord;
684 pixelPtrLimit += iScanLineWords;
689 const TBool extra = (finishLong < aX + aLength);
691 for (; aY < yLimit; aY++)
693 TUint32* bmpbitstmp = pixelPtr;
696 bmpbitstmp[-1] ^= PasteInt(0,colorWord,startShift);
698 while (bmpbitstmp < pixelPtrLimit)
699 *bmpbitstmp++ ^= colorWord;
702 pixelPtrLimit[0] ^= PasteInt(colorWord,0,finishShift);
704 pixelPtr += iScanLineWords;
705 pixelPtrLimit += iScanLineWords;
709 void CDrawOneBppBitmap::WriteRgbMultiAND(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
711 const TUint32 colorWord = (aColor._Gray2() == 1) ? 0xffffffff : 0;
712 const TInt yLimit = aY + aHeight;
713 const TInt startLong = (aX + KPixelsPerWord - 1) & (~0x1f);
714 const TInt finishLong = (aX + aLength) & (~0x1f);
715 const TInt startShift = startLong - aX;
716 const TInt finishShift = 32 - aX - aLength + finishLong;
717 TUint32* base = ScanLine(aY);
718 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
719 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
721 if (finishLong < startLong)
723 TUint32 mask = (0xffffffff << (32 - startShift)) & (0xffffffff >> (startShift - aLength));
724 const TUint32 maskedColorWord = colorWord | ~mask;
726 for (; aY < yLimit; aY++)
728 pixelPtrLimit[0] &= maskedColorWord;
729 pixelPtrLimit += iScanLineWords;
734 const TBool extra = (finishLong < aX + aLength);
736 for (; aY < yLimit; aY++)
738 TUint32* bmpbitstmp = pixelPtr;
741 bmpbitstmp[-1] &= PasteInt(0xffffffff,colorWord,startShift);
743 while (bmpbitstmp < pixelPtrLimit)
744 *bmpbitstmp++ &= colorWord;
747 pixelPtrLimit[0] &= PasteInt(colorWord,0xffffffff,finishShift);
749 pixelPtr += iScanLineWords;
750 pixelPtrLimit += iScanLineWords;
754 void CDrawOneBppBitmap::WriteRgbMultiOR(TInt aX,TInt aY,TInt aLength,TInt aHeight,TRgb aColor)
756 const TUint32 colorWord = (aColor._Gray2() == 1) ? 0xffffffff : 0;
757 const TInt yLimit = aY + aHeight;
758 const TInt startLong = (aX + KPixelsPerWord - 1) & (~0x1f);
759 const TInt finishLong = (aX + aLength) & (~0x1f);
760 const TInt startShift = startLong - aX;
761 const TInt finishShift = 32 - aX - aLength + finishLong;
762 TUint32* base = ScanLine(aY);
763 TUint32* pixelPtr = base + (startLong / KPixelsPerWord);
764 TUint32* pixelPtrLimit = base + (finishLong / KPixelsPerWord);
766 if (finishLong < startLong)
768 TUint32 mask = (0xffffffff << (32 - startShift)) & (0xffffffff >> (startShift - aLength));
769 const TUint32 maskedColorWord = colorWord & mask;
771 for (; aY < yLimit; aY++)
773 pixelPtrLimit[0] |= maskedColorWord;
774 pixelPtrLimit += iScanLineWords;
779 const TBool extra = (finishLong < aX + aLength);
781 for (; aY < yLimit; aY++)
783 TUint32* bmpbitstmp = pixelPtr;
786 bmpbitstmp[-1] |= PasteInt(bmpbitstmp[-1],colorWord,startShift);
788 while (bmpbitstmp < pixelPtrLimit)
789 *bmpbitstmp++ |= colorWord;
792 pixelPtrLimit[0] |= PasteInt(colorWord,pixelPtrLimit[0],finishShift);
794 pixelPtr += iScanLineWords;
795 pixelPtrLimit += iScanLineWords;
799 void CDrawOneBppBitmap::WriteRgbAlphaMulti(TInt aX,TInt aY,TInt aLength,TRgb aColor,const TUint8* aMaskBuffer)
802 TUint8* pixelPtr = REINTERPRET_CAST(TUint8*,ScanLine(aY)) + (aX / 8);
803 TInt pixelMask = 1 << (aX & 7);
804 const TUint8* maskBufferPtrLimit = aMaskBuffer + aLength;
809 const TInt gray = aColor._Gray256();
812 while (aMaskBuffer < maskBufferPtrLimit)
814 const TInt pixelGray256Value = (pixelPtr[0] & pixelMask) ? 255 : 0;
815 pixelColor = TRgb::_Gray256(((gray * aMaskBuffer[0]) + ((255 - aMaskBuffer[0]) * pixelGray256Value)) / 255);
816 if (pixelColor._Gray2())
817 pixelPtr[0] |= pixelMask;
819 pixelPtr[0] &= ~pixelMask;
831 TInt CDrawOneBppBitmap::WriteRgbOutlineAndShadow(TInt aX, TInt aY, const TInt aLength,
832 TUint32 aOutlinePenColor, TUint32 aShadowColor,
833 TUint32 aFillColor, const TUint8* aDataBuffer)
835 //This is non-optimised since this screen mode is rarely used and is usually
836 //fast enough without optimisation.
838 TUint8* pixelPtr = REINTERPRET_CAST(TUint8*,ScanLine(aY)) + (aX / 8);
839 TInt pixelMask = 1 << (aX & 7);
840 const TUint8* dataBufferPtrLimit = aDataBuffer + aLength;
842 TInt blendedRedColor;
843 TInt blendedGreenColor;
844 TInt blendedBlueColor;
848 TRgb outlinePenColor;
849 outlinePenColor.SetInternal(aOutlinePenColor);
851 shadowColor.SetInternal(aShadowColor);
853 fillColor.SetInternal(aFillColor);
855 const TInt redOutlinePenColor = outlinePenColor.Red();
856 const TInt redShadowColor = shadowColor.Red();
857 const TInt redFillColor = fillColor.Red();
859 const TInt greenOutlinePenColor = outlinePenColor.Green();
860 const TInt greenShadowColor = shadowColor.Green();
861 const TInt greenFillColor = fillColor.Green();
863 const TInt blueOutlinePenColor = outlinePenColor.Blue();
864 const TInt blueShadowColor = shadowColor.Blue();
865 const TInt blueFillColor = fillColor.Blue();
867 while (aDataBuffer < dataBufferPtrLimit)
869 index = *aDataBuffer++;
870 if (255 == FourColorBlendLookup[index][KBackgroundColorIndex])
873 //No drawing required so move on to next pixel.
875 if (pixelMask > 0x80)
882 else if (255 == FourColorBlendLookup[index][KFillColorIndex])
885 finalColor.SetInternal(aFillColor);
887 else if (255 == FourColorBlendLookup[index][KShadowColorIndex])
890 finalColor.SetInternal(aShadowColor);
892 else if (255 == FourColorBlendLookup[index][KOutlineColorIndex])
895 finalColor.SetInternal(aOutlinePenColor);
899 TRgb backgroundColor = TRgb::_Gray2((pixelPtr[0] & pixelMask) ? 255 : 0);
900 blendedRedColor = (redOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] +
901 redShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
902 redFillColor * FourColorBlendLookup[index][KFillColorIndex] +
903 backgroundColor.Red() * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8;
905 blendedGreenColor = (greenOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] +
906 greenShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
907 greenFillColor * FourColorBlendLookup[index][KFillColorIndex] +
908 backgroundColor.Green() * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8;
910 blendedBlueColor = (blueOutlinePenColor * FourColorBlendLookup[index][KOutlineColorIndex] +
911 blueShadowColor * FourColorBlendLookup[index][KShadowColorIndex] +
912 blueFillColor * FourColorBlendLookup[index][KFillColorIndex] +
913 backgroundColor.Blue() * FourColorBlendLookup[index][KBackgroundColorIndex]) >> 8;
915 finalColor = TRgb(blendedRedColor, blendedGreenColor, blendedBlueColor);
918 if (finalColor._Gray2())
920 pixelPtr[0] |= pixelMask;
924 pixelPtr[0] &= ~pixelMask;
929 if (pixelMask > 0x80)