11#include " BBitmap.h"
2+ #include < Display/Display.h>
23#include < cstring>
34#include " Panic.h"
45#include " BFont.h"
1314
1415#define RLE
1516
17+ TUint32 (BBitmap::*ReadPixelByDepth)(TInt, TInt) = ENull;
18+
1619BBitmap::BBitmap (
1720 TUint aWidth, TUint aHeight, TUint aDepth, TUint16 aMemoryType) {
1821 mROM = EFalse;
@@ -22,7 +25,6 @@ BBitmap::BBitmap(
2225 mPitch = mWidth ;
2326 mColors = 256 ;
2427 mPalette = new TRGB [mColors ];
25- // mPixels = (TUint32 *) AllocMem(mWidth * mHeight, aMemoryType);
2628 mPixels = (TUint32 *) AllocMem ((mWidth * mHeight ) * sizeof (TUint32), aMemoryType);
2729 mTransparentColor = -1 ;
2830
@@ -33,6 +35,10 @@ BBitmap::BBitmap(
3335 for (TInt i = 0 ; i < 256 ; i++) {
3436 mColorsUsed [i] = ENull;
3537 }
38+
39+ ReadPixelByDepth = gDisplay .renderBitmap && gDisplay .renderBitmap ->Depth () != mDepth
40+ ? &BBitmap::ReadPixelColor
41+ : &BBitmap::ReadPixel;
3642}
3743
3844/* *
@@ -138,6 +144,10 @@ BBitmap::BBitmap(TAny *aROM, TUint16 aMemoryType) {
138144 *dst++ = color;
139145 }
140146#endif
147+
148+ ReadPixelByDepth = gDisplay .renderBitmap && gDisplay .renderBitmap ->Depth () != mDepth
149+ ? &BBitmap::ReadPixelColor
150+ : &BBitmap::ReadPixel;
141151}
142152
143153BBitmap::~BBitmap () {
@@ -184,6 +194,10 @@ TInt BBitmap::FindColor(TRGB &aColor) {
184194// add aStartColor (it's an offset) to each pixel
185195// copy palette from 0 to aStartColor (index) for the number of colors
186196void BBitmap::Remap (BBitmap *aOther) {
197+ if (gDisplay .renderBitmap ->Depth () != mDepth ) {
198+ return ;
199+ }
200+
187201 TRGB transparent (255 , 0 , 255 );
188202 mTransparentColor = -1 ;
189203
@@ -358,8 +372,7 @@ TBool BBitmap::DrawBitmap(BViewPort *aViewPort, BBitmap *aSrcBitmap,
358372
359373 for (TInt y = spriteRect.y1 ; y < spriteRect.y2 ; y++, pixels += nextRow) {
360374 for (TInt x = spriteRect.x1 ; x < spriteRect.x2 ; x++, pixels += incX) {
361- // *pixels = aSrcBitmap->ReadPixel(y, x);
362- *pixels = aSrcBitmap->ReadColor (x, y).rgb888 ();
375+ *pixels = (aSrcBitmap->*ReadPixelByDepth)(y, x);
363376 }
364377 }
365378 } else {
@@ -417,8 +430,7 @@ TBool BBitmap::DrawBitmap(BViewPort *aViewPort, BBitmap *aSrcBitmap,
417430
418431 for (TInt y = spriteRect.y1 ; y < spriteRect.y2 ; y++, pixels += nextRow) {
419432 for (TInt x = spriteRect.x1 ; x < spriteRect.x2 ; x++, pixels += incX) {
420- // *pixels = aSrcBitmap->ReadPixel(x, y);
421- *pixels = aSrcBitmap->ReadColor (x, y).rgb888 ();
433+ *pixels = (aSrcBitmap->*ReadPixelByDepth)(x, y);
422434 }
423435 }
424436 }
@@ -437,7 +449,7 @@ void BBitmap::CopyPixels(BBitmap *aOther) {
437449 }
438450
439451 if (mDepth == aOther->mDepth ) {
440- memcpy (mPixels , aOther->mPixels , mWidth * mHeight );
452+ memcpy (mPixels , aOther->mPixels , mWidth * mHeight * sizeof (TUint32) );
441453 return ;
442454 }
443455
@@ -454,7 +466,9 @@ void BBitmap::CopyPixels(BBitmap *aOther) {
454466
455467TBool BBitmap::DrawBitmapTransparent (BViewPort *aViewPort, BBitmap *aSrcBitmap, TRect aSrcRect, TInt aX, TInt aY, TUint32 aFlags) {
456468 const TUint32 pitch = this ->mPitch ;
457- const TInt t = aSrcBitmap->mTransparentColor ;
469+ const TInt t = gDisplay .renderBitmap ->Depth () != aSrcBitmap->mDepth
470+ ? aSrcBitmap->mPalette [aSrcBitmap->mTransparentColor ].rgb888 ()
471+ : aSrcBitmap->mTransparentColor ;
458472
459473 TUint32 *pixels;
460474 TRect clipRect, spriteRect;
@@ -550,10 +564,8 @@ TBool BBitmap::DrawBitmapTransparent(BViewPort *aViewPort, BBitmap *aSrcBitmap,
550564
551565 for (TInt y = spriteRect.y1 ; y < spriteRect.y2 ; y++, pixels += nextRow) {
552566 for (TInt x = spriteRect.x1 ; x < spriteRect.x2 ; x++, pixels += incX) {
553- // TUint8 pix = aSrcBitmap->ReadPixel(y, x);
554- // if (pix != t) {
555- TUint32 pix = aSrcBitmap->ReadColor (x, y).rgb888 ();
556- if (pix != 16711935 ) {
567+ TUint32 pix = (aSrcBitmap->*ReadPixelByDepth)(y, x);
568+ if (pix != t) {
557569 *pixels = pix;
558570 }
559571 }
@@ -613,11 +625,8 @@ TBool BBitmap::DrawBitmapTransparent(BViewPort *aViewPort, BBitmap *aSrcBitmap,
613625
614626 for (TInt y = spriteRect.y1 ; y < spriteRect.y2 ; y++, pixels += nextRow) {
615627 for (TInt x = spriteRect.x1 ; x < spriteRect.x2 ; x++, pixels += incX) {
616- // TUint8 pix = aSrcBitmap->ReadPixel(x, y);
617- // if (pix != t) {
618- // *pixels = pix;
619- TUint32 pix = aSrcBitmap->ReadColor (x, y).rgb888 ();
620- if (pix != 16711935 ) {
628+ TUint32 pix = (aSrcBitmap->*ReadPixelByDepth)(x, y);
629+ if (pix != t) {
621630 *pixels = pix;
622631 }
623632 }
@@ -628,15 +637,15 @@ TBool BBitmap::DrawBitmapTransparent(BViewPort *aViewPort, BBitmap *aSrcBitmap,
628637}
629638
630639TBool BBitmap::DrawStringShadow (BViewPort *aViewPort, const char *aStr,
631- const BFont *aFont, TInt aX, TInt aY, TInt32 aFgColor, TInt32 aShadowColor,
640+ const BFont *aFont, TInt aX, TInt aY, TUint32 aFgColor, TUint32 aShadowColor,
632641 TInt32 aBgColor, TInt aLetterSpacing) {
633642 return DrawString (aViewPort, aStr, aFont, aX, aY, aShadowColor, aBgColor, aLetterSpacing)
634643 ? DrawString (aViewPort, aStr, aFont, aX - 1 , aY - 1 , aFgColor, aBgColor, aLetterSpacing)
635644 : EFalse;
636645}
637646
638647TBool BBitmap::DrawString (BViewPort *aViewPort, const char *aStr,
639- const BFont *aFont, TInt aX, TInt aY, TInt32 aFgColor, TInt32 aBgColor,
648+ const BFont *aFont, TInt aX, TInt aY, TUint32 aFgColor, TInt32 aBgColor,
640649 TInt aLetterSpacing) {
641650 const TUint32 pitch = this ->mPitch ;
642651 const TInt fontWidth = aFont->mWidth ,
@@ -692,15 +701,14 @@ TBool BBitmap::DrawString(BViewPort *aViewPort, const char *aStr,
692701 for (TInt y = charRect.y1 ; y < charRect.y2 ; y++, pixels += nextRow) {
693702 for (TInt x = charRect.x1 ; x < charRect.x2 ; x++, pixels++) {
694703 // TUint32 pix = fontBitmap->ReadPixel(x, y);
695- TUint32 pix = fontBitmap->ReadColor (x, y). rgb888 ( );
704+ TUint32 pix = ( fontBitmap->*ReadPixelByDepth) (x, y);
696705 // Write background and foreground pixels
697706 if (pix == 0 ) {
698707 if (drawBg) {
699- // *pixels = TUint8(aBgColor);
700708 *pixels = TUint32 (aBgColor);
701709 }
702710 } else {
703- *pixels = TUint32 ( aFgColor) ;
711+ *pixels = aFgColor;
704712 }
705713 }
706714 }
@@ -713,11 +721,10 @@ TBool BBitmap::DrawString(BViewPort *aViewPort, const char *aStr,
713721}
714722
715723void BBitmap::Clear (TUint32 aColor) {
716- memset (mPixels , aColor, mPitch * mHeight * sizeof (TUint32));
717- }
718-
719- void BBitmap::Clear (TUint8 aColor) {
720- memset (mPixels , aColor, mPitch * mHeight * sizeof (TUint8));
724+ const TInt len = mPitch * mHeight ;
725+ for (TInt i = 0 ; i < len; i++) {
726+ WritePixel (i, 0 , aColor);
727+ }
721728}
722729
723730void BBitmap::DrawFastHLine (
0 commit comments