Skip to content

Commit a6115c9

Browse files
committed
DSi-based UIs: Allocate/Free bmpImageBuffer when needed
1 parent 5872fef commit a6115c9

File tree

4 files changed

+33
-23
lines changed

4 files changed

+33
-23
lines changed

romsel_dsimenutheme/arm9/source/esrbSplash.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ void createEsrbSplash(void) {
6767
lodepng::decode(image, imageWidth, imageHeight, esrbImagePath);
6868
if (imageWidth > 256 || imageHeight > 192) return;
6969

70+
u16* bmpImageBuffer = new u16[256 * 192];
71+
7072
for (uint i=0;i<image.size()/4;i++) {
71-
tex().bmpImageBuffer()[i] = image[i*4]>>3 | (image[(i*4)+1]>>3)<<5 | (image[(i*4)+2]>>3)<<10 | BIT(15);
73+
bmpImageBuffer[i] = image[i*4]>>3 | (image[(i*4)+1]>>3)<<5 | (image[(i*4)+2]>>3)<<10 | BIT(15);
7274
}
7375

7476
if (descriptors != "") {
@@ -110,7 +112,7 @@ void createEsrbSplash(void) {
110112
printSmall(false, 100, descriptorYpos, descriptorList[i]);
111113
descriptorYpos += (descriptorLines > 4) ? 12 : 16;
112114
}
113-
updateTextImg(tex().bmpImageBuffer(), false);
115+
updateTextImg(bmpImageBuffer, false);
114116
clearText();
115117

116118
esrbDescFontDeinit();
@@ -119,6 +121,8 @@ void createEsrbSplash(void) {
119121
mkdir(sys().isRunFromSD() ? "sd:/_nds/nds-bootstrap" : "fat:/_nds/nds-bootstrap", 0777);
120122

121123
FILE *file = fopen(sys().isRunFromSD() ? "sd:/_nds/nds-bootstrap/esrb.bin" : "fat:/_nds/nds-bootstrap/esrb.bin", "wb");
122-
fwrite(tex().bmpImageBuffer(), sizeof(u16), 256*192, file);
124+
fwrite(bmpImageBuffer, sizeof(u16), 256*192, file);
123125
fclose(file);
126+
127+
delete[] bmpImageBuffer;
124128
}

romsel_dsimenutheme/arm9/source/gbaswitch.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ void loadGbaBorder(const char* filename) {
1111
lodepng::decode(image, imageWidth, imageHeight, filename);
1212
bool alternatePixel = false;
1313

14+
u16* bmpImageBuffer = new u16[256 * 192];
15+
1416
for (uint i = 0; i < image.size()/4; i++) {
1517
image[(i*4)+3] = 0;
1618
if (alternatePixel) {
@@ -27,12 +29,12 @@ void loadGbaBorder(const char* filename) {
2729
image[(i*4)+3] |= BIT(2);
2830
}
2931
}
30-
tex().bmpImageBuffer()[i] = image[i*4]>>3 | (image[(i*4)+1]>>3)<<5 | (image[(i*4)+2]>>3)<<10 | BIT(15);
32+
bmpImageBuffer[i] = image[i*4]>>3 | (image[(i*4)+1]>>3)<<5 | (image[(i*4)+2]>>3)<<10 | BIT(15);
3133
if ((i % 256) == 255) alternatePixel = !alternatePixel;
3234
alternatePixel = !alternatePixel;
3335
}
34-
DC_FlushRange(tex().bmpImageBuffer(),SCREEN_WIDTH*SCREEN_HEIGHT*2);
35-
dmaCopy(tex().bmpImageBuffer(),(void*)BG_BMP_RAM(0),SCREEN_WIDTH*SCREEN_HEIGHT*2);
36+
DC_FlushRange(bmpImageBuffer,SCREEN_WIDTH*SCREEN_HEIGHT*2);
37+
dmaCopy(bmpImageBuffer,(void*)BG_BMP_RAM(0),SCREEN_WIDTH*SCREEN_HEIGHT*2);
3638

3739
alternatePixel = false;
3840
for (uint i = 0; i < image.size()/4; i++) {
@@ -57,12 +59,14 @@ void loadGbaBorder(const char* filename) {
5759
image[(i*4)+2] -= 0x4;
5860
}
5961
}
60-
tex().bmpImageBuffer()[i] = image[i*4]>>3 | (image[(i*4)+1]>>3)<<5 | (image[(i*4)+2]>>3)<<10 | BIT(15);
62+
bmpImageBuffer[i] = image[i*4]>>3 | (image[(i*4)+1]>>3)<<5 | (image[(i*4)+2]>>3)<<10 | BIT(15);
6163
if ((i % 256) == 255) alternatePixel = !alternatePixel;
6264
alternatePixel = !alternatePixel;
6365
}
64-
DC_FlushRange(tex().bmpImageBuffer(),SCREEN_WIDTH*SCREEN_HEIGHT*2);
65-
dmaCopy(tex().bmpImageBuffer(),(void*)BG_BMP_RAM(8),SCREEN_WIDTH*SCREEN_HEIGHT*2);
66+
DC_FlushRange(bmpImageBuffer,SCREEN_WIDTH*SCREEN_HEIGHT*2);
67+
dmaCopy(bmpImageBuffer,(void*)BG_BMP_RAM(8),SCREEN_WIDTH*SCREEN_HEIGHT*2);
68+
69+
delete[] bmpImageBuffer;
6670
}
6771

6872
void gbaSwitch(void) {

romsel_dsimenutheme/arm9/source/graphics/ThemeTextures.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@ extern bool rocketVideo_playVideo;
3737
extern u8 *rotatingCubesLocation;
3838

3939
// #include <nds/arm9/decompress.h>
40-
// extern u16 bmpImageBuffer[256*192];
4140
extern bool showColon;
4241

43-
static u16 _bmpImageBuffer[256 * 192] = {0};
44-
static u16* _bmpImageBuffer2 = (u16*)_bmpImageBuffer;
4542
static u16 _bgMainBuffer[256 * 192] = {0};
4643
static u16 _bgSubBuffer[256 * 192] = {0};
4744
static u16 _photoBuffer[208 * 156] = {0};
@@ -50,12 +47,12 @@ static u16* _bgSubBuffer2 = (u16*)_bgSubBuffer;
5047
static u16* _photoBuffer2 = (u16*)_photoBuffer;
5148
// DSi mode double-frame buffers
5249
//static u16* _frameBuffer[2] = {(u16*)0x02F80000, (u16*)0x02F98000};
53-
static u16* _frameBufferBot[2] = {(u16*)_bmpImageBuffer, (u16*)_bmpImageBuffer};
50+
static u16* _frameBufferBot[2] = {NULL};
5451

5552
static bool topBorderBufferLoaded = false;
5653
bool boxArtColorDeband = false;
5754

58-
static u8* boxArtCache = (u8*)NULL; // Size: 0x1B8000
55+
static u8* boxArtCache = NULL; // Size: 0x1B8000
5956
static bool boxArtFound[40] = {false};
6057
uint boxArtWidth = 0, boxArtHeight = 0;
6158

@@ -993,6 +990,9 @@ void ThemeTextures::drawBoxArt(const char *filename, bool inMem) {
993990
bool alternatePixel = false;
994991
if (boxArtWidth > 256 || boxArtHeight > 192) return;
995992

993+
u16* bmpImageBuffer = new u16[256 * 192];
994+
u16* bmpImageBuffer2 = boxArtColorDeband ? new u16[256 * 192] : NULL;
995+
996996
imageXpos = (256-boxArtWidth)/2;
997997
imageYpos = (192-boxArtHeight)/2;
998998

@@ -1025,9 +1025,9 @@ void ThemeTextures::drawBoxArt(const char *filename, bool inMem) {
10251025
color = colorTable[color % 0x8000];
10261026
}
10271027
if (alpha == 255) {
1028-
_bmpImageBuffer[i] = color;
1028+
bmpImageBuffer[i] = color;
10291029
} else {
1030-
_bmpImageBuffer[i] = alphablend(color, _bgSubBuffer[(photoY*256)+photoX], alpha);
1030+
bmpImageBuffer[i] = alphablend(color, _bgSubBuffer[(photoY*256)+photoX], alpha);
10311031
}
10321032
if (boxArtColorDeband) {
10331033
if (alternatePixel) {
@@ -1056,9 +1056,9 @@ void ThemeTextures::drawBoxArt(const char *filename, bool inMem) {
10561056
color = colorTable[color % 0x8000];
10571057
}
10581058
if (alpha == 255) {
1059-
_bmpImageBuffer2[i] = color;
1059+
bmpImageBuffer2[i] = color;
10601060
} else {
1061-
_bmpImageBuffer2[i] = alphablend(color, _bgSubBuffer2[(photoY*256)+photoX], alpha);
1061+
bmpImageBuffer2[i] = alphablend(color, _bgSubBuffer2[(photoY*256)+photoX], alpha);
10621062
}
10631063
if ((i % boxArtWidth) == boxArtWidth-1) alternatePixel = !alternatePixel;
10641064
alternatePixel = !alternatePixel;
@@ -1070,8 +1070,8 @@ void ThemeTextures::drawBoxArt(const char *filename, bool inMem) {
10701070
}
10711071
}
10721072

1073-
u16 *src = _bmpImageBuffer;
1074-
u16 *src2 = _bmpImageBuffer2;
1073+
u16 *src = bmpImageBuffer;
1074+
u16 *src2 = bmpImageBuffer2;
10751075
for (uint y = 0; y < boxArtHeight; y++) {
10761076
for (uint x = 0; x < boxArtWidth; x++) {
10771077
_bgSubBuffer[(y+imageYpos) * 256 + imageXpos + x] = *(src++);
@@ -1081,6 +1081,11 @@ void ThemeTextures::drawBoxArt(const char *filename, bool inMem) {
10811081
}
10821082
}
10831083
commitBgSubModify();
1084+
1085+
delete[] bmpImageBuffer;
1086+
if (boxArtColorDeband) {
1087+
delete[] bmpImageBuffer2;
1088+
}
10841089
}
10851090

10861091
#define MAX_PHOTO_WIDTH 208
@@ -1456,7 +1461,6 @@ void ThemeTextures::applyUserPaletteToAllGrfTextures() {
14561461
_settingsIconTexture->applyUserPaletteFile(TFN_PALETTE_ICON_SETTINGS, effectDSiArrowButtonPalettes);
14571462
}
14581463

1459-
u16 *ThemeTextures::bmpImageBuffer() { return _bmpImageBuffer; }
14601464
u16 *ThemeTextures::bgSubBuffer2() { return _bgSubBuffer2; }
14611465
u16 *ThemeTextures::photoBuffer() { return _photoBuffer; }
14621466
u16 *ThemeTextures::photoBuffer2() { return _photoBuffer2; }
@@ -1627,7 +1631,6 @@ void ThemeTextures::videoSetup() {
16271631
boxArtColorDeband = (ms().boxArtColorDeband && !ms().macroMode && (sys().isRegularDS() ? sys().dsDebugRam() : ndmaEnabled()) && !rotatingCubesLoaded && ms().theme != TWLSettings::EThemeHBL);
16281632

16291633
if (boxArtColorDeband) {
1630-
_bmpImageBuffer2 = new u16[256 * 192];
16311634
_bgSubBuffer2 = new u16[256 * 192];
16321635
_photoBuffer2 = new u16[208 * 156];
16331636
_frameBufferBot[0] = new u16[256 * 192];

romsel_dsimenutheme/arm9/source/graphics/ThemeTextures.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ class ThemeTextures
197197
FontGraphic *dateTimeFont() { return _dateTimeFont.get(); }
198198
FontGraphic *usernameFont() { extern FontGraphic *smallFont; return _usernameFont ? _usernameFont.get() : smallFont; }
199199

200-
static u16* bmpImageBuffer();
201200
static u16* bgSubBuffer2();
202201
static u16* photoBuffer();
203202
static u16* photoBuffer2();

0 commit comments

Comments
 (0)