wip · ModusCreateOrg/creative-engine@0614424 · GitHub
Skip to content

Commit 0614424

Browse files
wip
1 parent 131fb1b commit 0614424

4 files changed

Lines changed: 59 additions & 66 deletions

File tree

‎src/BBitmap.cpp‎

Lines changed: 33 additions & 26 deletions

‎src/BBitmap.h‎

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -165,27 +165,18 @@ class BBitmap : public BBase {
165165
// void SetPalette(TUint8 index, TUint32 *aPalette, TInt aCount);
166166
public:
167167
TRGB &ReadColor(TInt aX, TInt aY) {
168-
TUint8 pixel = mPixels[aY * mPitch + aX];
168+
TUint32 pixel = mPixels[aY * mPitch + aX];
169169
return mPalette[pixel];
170170
}
171171

172-
TUint8 ReadPixel(TInt aX, TInt aY) { return mPixels[aY * mPitch + aX]; }
172+
TUint32 ReadPixelColor(TInt aX, TInt aY) { return ReadColor(aX, aY).rgb888(); }
173173

174-
public:
175-
void WritePixel(TInt aX, TInt aY, TUint8 aColor) {
176-
mPixels[aY * mPitch + aX] = aColor;
177-
}
174+
TUint32 ReadPixel(TInt aX, TInt aY) { return mPixels[aY * mPitch + aX]; }
178175

179176
void WritePixel(TInt aX, TInt aY, TUint32 aColor) {
180177
mPixels[aY * mPitch + aX] = aColor;
181178
}
182179

183-
void SafeWritePixel(TInt aX, TInt aY, TUint8 aColor) {
184-
if (mDimensions.PointInRect(aX, aY)) {
185-
WritePixel(aX, aY, aColor);
186-
}
187-
}
188-
189180
void SafeWritePixel(TInt aX, TInt aY, TUint32 aColor) {
190181
if (mDimensions.PointInRect(aX, aY)) {
191182
WritePixel(aX, aY, aColor);
@@ -195,9 +186,8 @@ class BBitmap : public BBase {
195186
public:
196187
// DRAWING PRIMITIVES
197188
/**
198-
* Erase bitmap to specified color (palette index)
189+
* Erase bitmap to specified color
199190
*/
200-
void Clear(TUint8 aColor = 0);
201191
void Clear(TUint32 aColor = 0);
202192

203193
/**
@@ -286,12 +276,12 @@ class BBitmap : public BBase {
286276
* @return
287277
*/
288278
TBool DrawString(BViewPort *aViewPort, const char *aStr, const BFont *aFont,
289-
TInt aDstX, TInt aDstY, TInt32 aFgColor, TInt32 aBgColor = -1,
279+
TInt aDstX, TInt aDstY, TUint32 aFgColor, TInt32 aBgColor = -1,
290280
TInt aLetterSpacing = 0);
291281

292282
TBool DrawStringShadow(BViewPort *aViewPort, const char *aStr,
293-
const BFont *aFont, TInt aDstX, TInt aDstY, TInt32 aFgColor,
294-
TInt32 aShadowColor, TInt32 aBgColor = -1, TInt aLetterSpacing = 0);
283+
const BFont *aFont, TInt aDstX, TInt aDstY, TUint32 aFgColor,
284+
TUint32 aShadowColor, TInt32 aBgColor = -1, TInt aLetterSpacing = 0);
295285

296286
TUint GetPitch() { return mPitch; }
297287

‎src/Display/DesktopDisplay/DesktopDisplay.cpp‎

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,27 +97,23 @@ void DesktopDisplay::Update() {
9797

9898
if (0 == SDL_LockTexture(texture, ENull, &screenBuf, &pitch)) {
9999
auto *screenBits = (TUint32 *) screenBuf;
100-
// TRGB *palette = displayBitmap->GetPalette();
101-
// printf("%lu\n", sizeof(*ptr));
102-
// renderBitmap->Dump();
103-
// printf("\n\n");
104-
TUint32 *ptr = displayBitmap->mPixels;
105-
memcpy(screenBits, ptr, SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(TUint32));
106-
107-
// for (TInt16 y = 0; y < SCREEN_HEIGHT; y++) {
108-
// TUint8 *ptr = &displayBitmap->mPixels[y * displayBitmap->GetPitch()];
109-
//
110-
// for (TInt x = 0; x < SCREEN_WIDTH; x++) {
111-
// TUint8 pixel = *ptr++;
112-
// TUint32 color = palette[pixel].rgb888();
113-
// *screenBits++ = color;
114-
// }
115-
// }
116-
117-
// (TUint32 *) screenBuf;
118-
// screenBits = (TUint32 *) screenBuf;
119-
// Dump(screenBits, renderBitmap->mWidth);
120-
// Dump(displayBitmap->mPixels, displayBitmap->mWidth, displayBitmap->mHeight);
100+
101+
if (displayBitmap->Depth() == 32) {
102+
TUint32 *ptr = displayBitmap->mPixels;
103+
memcpy(screenBits, ptr, SCREEN_WIDTH * SCREEN_HEIGHT * sizeof(TUint32));
104+
} else {
105+
TRGB *palette = displayBitmap->GetPalette();
106+
for (TInt y = 0; y < SCREEN_HEIGHT; y++) {
107+
TUint32 *ptr = &displayBitmap->mPixels[y * displayBitmap->GetPitch()];
108+
109+
for (TInt x = 0; x < SCREEN_WIDTH; x++) {
110+
TUint32 pixel = *ptr++;
111+
TUint32 color = palette[pixel].rgb888();
112+
*screenBits++ = color;
113+
}
114+
}
115+
}
116+
121117
SDL_UnlockTexture(texture);
122118
}
123119
else {

‎src/Display/DisplayBase.h‎

Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)