Skip to content

Commit

Permalink
Apply GBA/DS Phat color mode to remaining srldr files
Browse files Browse the repository at this point in the history
ALSO: Use pre-generated color tables instead of color conversion code
  • Loading branch information
RocketRobz committed Oct 30, 2023
1 parent ba3e5b4 commit 83e2755
Show file tree
Hide file tree
Showing 46 changed files with 455 additions and 670 deletions.
16 changes: 13 additions & 3 deletions 3dssplash/arm9/source/graphics/gif.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include "gif.hpp"
#include "myDSiMode.h"
#include "common/twlmenusettings.h"
#include "common/tonccpy.h"
#include "lzw.hpp"

#include <stdio.h>

extern u16* colorTable;

std::vector<Gif *> Gif::_animating;

void Gif::timerHandler(void) {
Expand Down Expand Up @@ -44,10 +47,17 @@ void Gif::displayFrame(void) {
}
}

std::vector<u16> &colorTable = frame.descriptor.lctFlag ? frame.lct : _gct;
std::vector<u16> &gifColorTable = frame.descriptor.lctFlag ? frame.lct : _gct;
u16* bgPalette = _top ? BG_PALETTE : BG_PALETTE_SUB;

tonccpy(_top ? BG_PALETTE : BG_PALETTE_SUB, colorTable.data(), colorTable.size() * 2);
tonccpy(_top ? BG_PALETTE : BG_PALETTE_SUB, colorTable.data(), colorTable.size() * 2);
tonccpy(bgPalette, gifColorTable.data(), gifColorTable.size() * 2);
tonccpy(bgPalette, gifColorTable.data(), gifColorTable.size() * 2);
if (ms().colorMode > 0) {
for (unsigned int i = 0; i < gifColorTable.size(); i++) {
bgPalette[i] = colorTable[bgPalette[i]];
}
header.bgColor = colorTable[header.bgColor];
}

// Disposal method 2 = fill with bg color
if (frame.gce.disposalMethod == 2)
Expand Down
18 changes: 16 additions & 2 deletions 3dssplash/arm9/source/graphics/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ int fadeDelay = 0;

int screenBrightness = 31;
bool bottomBgLoaded = false;
u16* colorTable = NULL;

int bg3Sub;
int bg3Main;
Expand All @@ -28,7 +29,7 @@ void SetBrightness(u8 screen, s8 bright) {
*(u16*)(0x0400006C + (0x1000 * screen)) = bright + mode;
}

u16 convertVramColorToGrayscale(u16 val) {
/* u16 convertVramColorToGrayscale(u16 val) {
u8 b,g,r,max,min;
b = ((val)>>10)&31;
g = ((val)>>5)&31;
Expand All @@ -43,7 +44,7 @@ u16 convertVramColorToGrayscale(u16 val) {
max = (max + min) / 2;
return BIT(15)|(max<<10)|(max<<5)|(max);
}
} */

void vBlankHandler() {
if (fadeType == true) {
Expand Down Expand Up @@ -73,6 +74,19 @@ void graphicsInit() {
SetBrightness(0, 31);
SetBrightness(1, 31);

if (ms().colorMode > 0) {
colorTable = new u16[0x20000/sizeof(u16)];

const char* colorTablePath = "nitro:/graphics/colorTables/grayscale.bin";
if (ms().colorMode == 2) {
colorTablePath = "nitro:/graphics/colorTables/agb001.bin";
}

FILE* file = fopen(colorTablePath, "rb");
fread(colorTable, 1, 0x20000, file);
fclose(file);
}

////////////////////////////////////////////////////////////
videoSetMode(MODE_5_2D);
videoSetModeSub(MODE_5_2D);
Expand Down
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions imageview/arm9/source/errorScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#include "sound.h"

extern u16* colorTable;

extern bool sdRemoveDetect;
extern const char *unlaunchAutoLoadID;
extern char unlaunchDevicePath[256];
Expand Down Expand Up @@ -67,6 +69,11 @@ void checkSdEject(void) {
0xD6B5,
0xFFFF,
};
if (ms().colorMode > 0) {
for (int i = 0; i < 4; i++) {
palette[i] = colorTable[palette[i]];
}
}
//tonccpy(BG_PALETTE + 0xF8, palette, sizeof(palette));
toncset16(BG_PALETTE, 0, 256);
toncset16(BG_PALETTE_SUB, 0, 256);
Expand Down
16 changes: 13 additions & 3 deletions imageview/arm9/source/graphics/gif.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include "gif.hpp"
#include "myDSiMode.h"
#include "common/twlmenusettings.h"
#include "common/tonccpy.h"
#include "lzw.hpp"

#include <stdio.h>

extern u16* colorTable;

std::vector<Gif *> Gif::_animating;

void Gif::timerHandler(void) {
Expand Down Expand Up @@ -44,10 +47,17 @@ void Gif::displayFrame(void) {
}
}

std::vector<u16> &colorTable = frame.descriptor.lctFlag ? frame.lct : _gct;
std::vector<u16> &gifColorTable = frame.descriptor.lctFlag ? frame.lct : _gct;
u16* bgPalette = _top ? BG_PALETTE : BG_PALETTE_SUB;

tonccpy(_top ? BG_PALETTE : BG_PALETTE_SUB, colorTable.data(), colorTable.size() * 2);
tonccpy(_top ? BG_PALETTE : BG_PALETTE_SUB, colorTable.data(), colorTable.size() * 2);
tonccpy(bgPalette, gifColorTable.data(), gifColorTable.size() * 2);
tonccpy(bgPalette, gifColorTable.data(), gifColorTable.size() * 2);
if (ms().colorMode > 0) {
for (unsigned int i = 0; i < gifColorTable.size(); i++) {
bgPalette[i] = colorTable[bgPalette[i]];
}
header.bgColor = colorTable[header.bgColor];
}

// Disposal method 2 = fill with bg color
if (frame.gce.disposalMethod == 2)
Expand Down
50 changes: 32 additions & 18 deletions imageview/arm9/source/graphics/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ bool doubleBuffer = false;

u8* dsImageBuffer8;
u16* dsImageBuffer[2];
u16* colorTable = NULL;

int bg3Sub;
int bg2Main;
Expand Down Expand Up @@ -170,8 +171,8 @@ void imageLoad(const char* filename) {
}
if (image[(i*4)+3] > 0) {
u16 color = image[i*4]>>3 | (image[(i*4)+1]>>3)<<5 | (image[(i*4)+2]>>3)<<10 | BIT(15);
if (ms().colorMode == 1) {
color = convertVramColorToGrayscale(color);
if (ms().colorMode > 0) {
color = colorTable[color];
}
dsImageBuffer[0][(xPos+x+(y*256))+(yPos*256)] = alphablend(color, 0, image[(i*4)+3]);
} else {
Expand Down Expand Up @@ -200,8 +201,8 @@ void imageLoad(const char* filename) {
}
if (image[(i*4)+3] > 0) {
u16 color = image[i*4]>>3 | (image[(i*4)+1]>>3)<<5 | (image[(i*4)+2]>>3)<<10 | BIT(15);
if (ms().colorMode == 1) {
color = convertVramColorToGrayscale(color);
if (ms().colorMode > 0) {
color = colorTable[color];
}
dsImageBuffer[1][(xPos+x+(y*256))+(yPos*256)] = alphablend(color, 0, image[(i*4)+3]);
} else {
Expand Down Expand Up @@ -294,8 +295,8 @@ void imageLoad(const char* filename) {
}
}
u16 color = bmpImageBuffer[(i*bits)+2]>>3 | (bmpImageBuffer[(i*bits)+1]>>3)<<5 | (bmpImageBuffer[i*bits]>>3)<<10 | BIT(15);
if (ms().colorMode == 1) {
color = convertVramColorToGrayscale(color);
if (ms().colorMode > 0) {
color = colorTable[color];
}
dsImageBuffer[0][(xPos+x+(y*256))+(yPos*256)] = color;
if (alternatePixel) {
Expand All @@ -320,8 +321,8 @@ void imageLoad(const char* filename) {
}
}
color = bmpImageBuffer[(i*bits)+2]>>3 | (bmpImageBuffer[(i*bits)+1]>>3)<<5 | (bmpImageBuffer[i*bits]>>3)<<10 | BIT(15);
if (ms().colorMode == 1) {
color = convertVramColorToGrayscale(color);
if (ms().colorMode > 0) {
color = colorTable[color];
}
dsImageBuffer[1][(xPos+x+(y*256))+(yPos*256)] = color;
x++;
Expand All @@ -343,8 +344,8 @@ void imageLoad(const char* filename) {
for (uint x = 0; x < width; x++) {
u16 val = *(src++);
u16 color = ((val >> (rgb565 ? 11 : 10)) & 0x1F) | ((val >> (rgb565 ? 1 : 0)) & (0x1F << 5)) | (val & 0x1F) << 10 | BIT(15);
if (ms().colorMode == 1) {
color = convertVramColorToGrayscale(color);
if (ms().colorMode > 0) {
color = colorTable[color];
}
*(dst + x) = color;
}
Expand All @@ -363,8 +364,8 @@ void imageLoad(const char* filename) {
fread(&pixelR, 1, 1, file);
fread(&unk, 1, 1, file);
pixelBuffer[i] = pixelR>>3 | (pixelG>>3)<<5 | (pixelB>>3)<<10 | BIT(15);
if (ms().colorMode == 1) {
pixelBuffer[i] = convertVramColorToGrayscale(pixelBuffer[i]);
if (ms().colorMode > 0) {
pixelBuffer[i] = colorTable[pixelBuffer[i]];
}
}
u8 *bmpImageBuffer = new u8[width * height];
Expand Down Expand Up @@ -394,8 +395,8 @@ void imageLoad(const char* filename) {
fread(&pixelR, 1, 1, file);
fread(&unk, 1, 1, file);
monoPixel[i] = pixelR>>3 | (pixelG>>3)<<5 | (pixelB>>3)<<10 | BIT(15);
if (ms().colorMode == 1) {
monoPixel[i] = convertVramColorToGrayscale(monoPixel[i]);
if (ms().colorMode > 0) {
monoPixel[i] = colorTable[monoPixel[i]];
}
}
u8 *bmpImageBuffer = new u8[(width * height)/8];
Expand Down Expand Up @@ -442,9 +443,9 @@ void imageLoad(const char* filename) {
}

tonccpy(BG_PALETTE, gif.gct().data(), gif.gct().size() * 2);
if (ms().colorMode == 1) {
if (ms().colorMode > 0) {
for (int i = 0; i < (int)gif.gct().size(); i++) {
BG_PALETTE[i] = convertVramColorToGrayscale(BG_PALETTE[i]);
BG_PALETTE[i] = colorTable[BG_PALETTE[i]];
}
}

Expand All @@ -471,9 +472,9 @@ void bgLoad(void) {
u16 *dst = bgGetGfxPtr(bg3Sub);

tonccpy(BG_PALETTE_SUB, gif.gct().data(), gif.gct().size() * 2);
if (ms().colorMode == 1) {
if (ms().colorMode > 0) {
for (int i = 0; i < (int)gif.gct().size(); i++) {
BG_PALETTE_SUB[i] = convertVramColorToGrayscale(BG_PALETTE_SUB[i]);
BG_PALETTE_SUB[i] = colorTable[BG_PALETTE_SUB[i]];
}
}

Expand All @@ -488,6 +489,19 @@ void graphicsInit() {
SetBrightness(0, 31);
SetBrightness(1, 31);

if (ms().colorMode > 0) {
colorTable = new u16[0x20000/sizeof(u16)];

const char* colorTablePath = "nitro:/graphics/colorTables/grayscale.bin";
if (ms().colorMode == 2) {
colorTablePath = "nitro:/graphics/colorTables/agb001.bin";
}

FILE* file = fopen(colorTablePath, "rb");
fread(colorTable, 1, 0x20000, file);
fclose(file);
}

////////////////////////////////////////////////////////////
videoSetMode(MODE_5_2D);
videoSetModeSub(MODE_5_2D);
Expand Down
Binary file not shown.
Binary file not shown.
9 changes: 8 additions & 1 deletion manual/arm9/source/errorScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
#include <maxmod9.h>

// #include "autoboot.h"
// #include "common/twlmenusettings.h"
#include "common/twlmenusettings.h"
#include "common/systemdetails.h"
#include "common/flashcard.h"
#include "graphics/fontHandler.h"
#include "common/tonccpy.h"
#include "language.h"

extern u16* colorTable;

extern bool sdRemoveDetect;
extern const char *unlaunchAutoLoadID;
extern char unlaunchDevicePath[256];
Expand Down Expand Up @@ -51,6 +53,11 @@ void checkSdEject(void) {
0xD6B5,
0xFFFF,
};
if (ms().colorMode > 0) {
for (int i = 0; i < 4; i++) {
palette[i] = colorTable[palette[i]];
}
}
tonccpy(BG_PALETTE + 0xF8, palette, sizeof(palette));
tonccpy(BG_PALETTE_SUB + 0xF8, palette, sizeof(palette));

Expand Down
7 changes: 7 additions & 0 deletions manual/arm9/source/graphics/fontHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "myDSiMode.h"
#include "TextEntry.h"

extern u16* colorTable;

FontGraphic *smallFont;
FontGraphic *largeFont;

Expand Down Expand Up @@ -54,6 +56,11 @@ void fontInit() {
0xC631,
0xA108,
};
if (ms().colorMode > 0) {
for (int i = 0; i < 4; i++) {
palette[i] = colorTable[palette[i]];
}
}
tonccpy(BG_PALETTE + 0xF8, palette, sizeof(palette));
tonccpy(BG_PALETTE_SUB + 0xF8, palette, sizeof(palette));
}
Expand Down
16 changes: 13 additions & 3 deletions manual/arm9/source/graphics/gif.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include "gif.hpp"
#include "myDSiMode.h"
#include "common/twlmenusettings.h"
#include "common/tonccpy.h"
#include "lzw.hpp"

#include <stdio.h>

extern u16* colorTable;

std::vector<Gif *> Gif::_animating;

void Gif::timerHandler(void) {
Expand Down Expand Up @@ -44,10 +47,17 @@ void Gif::displayFrame(void) {
}
}

std::vector<u16> &colorTable = frame.descriptor.lctFlag ? frame.lct : _gct;
std::vector<u16> &gifColorTable = frame.descriptor.lctFlag ? frame.lct : _gct;
u16* bgPalette = _top ? BG_PALETTE : BG_PALETTE_SUB;

tonccpy(_top ? BG_PALETTE : BG_PALETTE_SUB, colorTable.data(), colorTable.size() * 2);
tonccpy(_top ? BG_PALETTE : BG_PALETTE_SUB, colorTable.data(), colorTable.size() * 2);
tonccpy(bgPalette, gifColorTable.data(), gifColorTable.size() * 2);
tonccpy(bgPalette, gifColorTable.data(), gifColorTable.size() * 2);
if (ms().colorMode > 0) {
for (unsigned int i = 0; i < gifColorTable.size(); i++) {
bgPalette[i] = colorTable[bgPalette[i]];
}
header.bgColor = colorTable[header.bgColor];
}

// Disposal method 2 = fill with bg color
if (frame.gce.disposalMethod == 2)
Expand Down
Loading

0 comments on commit 83e2755

Please sign in to comment.