Skip to content

Commit 505c071

Browse files
authored
Tweak default texture conversion settings
1 parent 3e3481c commit 505c071

File tree

12 files changed

+151
-153
lines changed

12 files changed

+151
-153
lines changed

src/bggen.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void bgAddTileToTotal(REDUCTION *reduction, int *pxBlock, BGTILE *tile) {
8686
for (int y = 0; y < 8; y++) {
8787
for (int x = 0; x < 8; x++) {
8888
COLOR32 col = tile->px[x + y * 8];
89-
89+
9090
int x2 = (tile->flipMode & TILE_FLIPX) ? (7 - x) : x;
9191
int y2 = (tile->flipMode & TILE_FLIPY) ? (7 - y) : y;
9292
int *dest = pxBlock + 4 * (x2 + y2 * 8);
@@ -199,7 +199,7 @@ void tdlReset(TILE_DIFF_LIST *list) {
199199
}
200200

201201
int performCharacterCompression(BGTILE *tiles, int nTiles, int nBits, int nMaxChars, COLOR32 *palette, int paletteSize, int nPalettes,
202-
int paletteBase, int paletteOffset, int balance, int colorBalance, int *progress) {
202+
int paletteBase, int paletteOffset, int balance, int colorBalance, int *progress) {
203203
int nChars = nTiles;
204204
float *diffBuff = (float *) calloc(nTiles * nTiles, sizeof(float));
205205
unsigned char *flips = (unsigned char *) calloc(nTiles * nTiles, 1); //how must each tile be manipulated to best match its partner
@@ -239,7 +239,7 @@ int performCharacterCompression(BGTILE *tiles, int nTiles, int nBits, int nMaxCh
239239
}
240240
}
241241
nChars--;
242-
if(nTiles > nMaxChars) *progress = 500 + (int) (500 * sqrt((float) (nTiles - nChars) / (nTiles - nMaxChars)));
242+
if (nTiles > nMaxChars) *progress = 500 + (int) (500 * sqrt((float) (nTiles - nChars) / (nTiles - nMaxChars)));
243243
}
244244
}
245245
}
@@ -275,7 +275,7 @@ int performCharacterCompression(BGTILE *tiles, int nTiles, int nBits, int nMaxCh
275275
tdlAdd(&tdl, j, i, thisError);
276276
}
277277
}
278-
278+
279279
//now merge tiles while we can
280280
int tile1, tile2;
281281
while (tdl.diffBuffLength > 0 && nChars > nMaxChars) {
@@ -375,7 +375,7 @@ int performCharacterCompression(BGTILE *tiles, int nTiles, int nBits, int nMaxCh
375375

376376
//now, match colors to indices.
377377
COLOR32 *pal = palette + (bestPalette << nBits);
378-
ditherImagePaletteEx(tile->px, NULL, 8, 8, pal + paletteOffset + !paletteOffset,
378+
ditherImagePaletteEx(tile->px, NULL, 8, 8, pal + paletteOffset + !paletteOffset,
379379
paletteSize - !paletteOffset, 0, 1, 0, 0.0f, balance, colorBalance, 0);
380380
for (int j = 0; j < 64; j++) {
381381
COLOR32 col = tile->px[j];
@@ -384,7 +384,7 @@ int performCharacterCompression(BGTILE *tiles, int nTiles, int nBits, int nMaxCh
384384
index = closestPalette(col, pal + paletteOffset + !paletteOffset, paletteSize - !paletteOffset)
385385
+ !paletteOffset + paletteOffset;
386386
}
387-
387+
388388
tile->indices[j] = index;
389389
tile->px[j] = index ? (pal[index] | 0xFF000000) : 0;
390390
}
@@ -444,10 +444,10 @@ void setupBgTilesEx(BGTILE *tiles, int nTiles, int nBits, COLOR32 *palette, int
444444
COLOR32 col = tile->px[j];
445445
int index = 0;
446446
if (((col >> 24) & 0xFF) > 127) {
447-
index = closestPalette(col, pal + paletteOffset + !paletteOffset, paletteSize - !paletteOffset)
447+
index = closestPalette(col, pal + paletteOffset + !paletteOffset, paletteSize - !paletteOffset)
448448
+ !paletteOffset + paletteOffset;
449449
}
450-
450+
451451
tile->indices[j] = index;
452452
tile->px[j] = index ? (pal[index] | 0xFF000000) : 0;
453453

@@ -464,12 +464,12 @@ void setupBgTilesEx(BGTILE *tiles, int nTiles, int nBits, COLOR32 *palette, int
464464
}
465465

466466
void bgGenerate(COLOR32 *imgBits, int width, int height, int nBits, int dither, float diffuse,
467-
COLOR **pOutPalette, unsigned char **pOutChars, unsigned short **pOutScreen,
468-
int *outPalSize, int *outCharSize, int *outScreenSize,
469-
int paletteBase, int nPalettes, int fmt, int tileBase, int mergeTiles,
470-
int paletteSize, int paletteOffset, int rowLimit, int nMaxChars,
471-
int balance, int colorBalance, int enhanceColors,
472-
int *progress1, int *progress1Max, int *progress2, int *progress2Max) {
467+
COLOR **pOutPalette, unsigned char **pOutChars, unsigned short **pOutScreen,
468+
int *outPalSize, int *outCharSize, int *outScreenSize,
469+
int paletteBase, int nPalettes, int fmt, int tileBase, int mergeTiles,
470+
int paletteSize, int paletteOffset, int rowLimit, int nMaxChars,
471+
int balance, int colorBalance, int enhanceColors,
472+
int *progress1, int *progress1Max, int *progress2, int *progress2Max) {
473473

474474
//cursory sanity checks
475475
if (nBits == 4) {
@@ -502,7 +502,7 @@ void bgGenerate(COLOR32 *imgBits, int width, int height, int nBits, int dither,
502502
//initialize progress
503503
*progress1Max = nTiles * 2; //2 passes
504504
*progress2Max = 1000;
505-
505+
506506
COLOR32 *palette = (COLOR32 *) calloc(256, 4);
507507
if (nBits < 5) nBits = 4;
508508
else nBits = 8;
@@ -520,7 +520,7 @@ void bgGenerate(COLOR32 *imgBits, int width, int height, int nBits, int dither,
520520
}
521521
}
522522
*progress1 = nTiles * 2; //make sure it's done
523-
523+
524524
//split image into 8x8 tiles.
525525
for (int y = 0; y < tilesY; y++) {
526526
for (int x = 0; x < tilesX; x++) {
@@ -543,7 +543,7 @@ void bgGenerate(COLOR32 *imgBits, int width, int height, int nBits, int dither,
543543
//match tiles to each other
544544
int nChars = nTiles;
545545
if (mergeTiles) {
546-
nChars = performCharacterCompression(tiles, nTiles, nBits, nMaxChars, palette, paletteSize, nPalettes, paletteBase,
546+
nChars = performCharacterCompression(tiles, nTiles, nBits, nMaxChars, palette, paletteSize, nPalettes, paletteBase,
547547
paletteOffset, balance, colorBalance, progress2);
548548
}
549549

src/bggen.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ void setupBgTilesEx(BGTILE *tiles, int nTiles, int nBits, COLOR32 *palette, int
5050
int performCharacterCompression(BGTILE *tiles, int nTiles, int nBits, int nMaxChars, COLOR32 *palette, int paletteSize, int nPalettes,
5151
int paletteBase, int paletteOffset, int balance, int colorBalance, int *progress);
5252

53-
void bgGenerate(COLOR32 *imgBits, int width, int height, int nBits, int dither, float diffuse,
54-
COLOR **pOutPalette, unsigned char **pOutChars, unsigned short **pOutScreen,
55-
int *outPalSize, int *outCharSize, int *outScreenSize,
56-
int palette, int nPalettes, int bin, int tileBase, int mergeTiles,
57-
int paletteSize, int paletteOffsetm, int rowLimit, int nMaxChars,
58-
int balance, int colorBalance, int enhanceColors,
59-
int *progress1, int *progress1Max, int *progress2, int *progress2Max);
53+
void bgGenerate(COLOR32 *imgBits, int width, int height, int nBits, int dither, float diffuse,
54+
COLOR **pOutPalette, unsigned char **pOutChars, unsigned short **pOutScreen,
55+
int *outPalSize, int *outCharSize, int *outScreenSize,
56+
int palette, int nPalettes, int bin, int tileBase, int mergeTiles,
57+
int paletteSize, int paletteOffsetm, int rowLimit, int nMaxChars,
58+
int balance, int colorBalance, int enhanceColors,
59+
int *progress1, int *progress1Max, int *progress2, int *progress2Max);

src/color.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "color.h"
22

3-
static uint8_t colorConversionLookupReverse[] = {
3+
static const uint8_t colorConversionLookupReverse[] = {
44
0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
55
2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4,
66
4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6,
@@ -26,14 +26,14 @@ COLOR ColorConvertToDS(COLOR32 c) {
2626
return r | (g << 5) | (b << 10);
2727
}
2828

29-
static uint8_t colorConversionLookup[] = {
29+
static const uint8_t colorConversionLookup[] = {
3030
0, 8, 16, 25, 33, 41, 49, 58,
3131
66, 74, 82, 90, 99, 107, 115, 123,
3232
132, 140, 148, 156, 165, 173, 181, 189,
3333
197, 206, 214, 222, 230, 239, 247, 255
3434
};
3535

36-
static uint8_t colorRound6Lookup[] = {
36+
static const uint8_t colorRound6Lookup[] = {
3737
0, 0, 0, 4, 4, 4, 4, 8, 8, 8, 8, 12, 12, 12, 12, 16,
3838
16, 16, 16, 20, 20, 20, 20, 24, 24, 24, 24, 28, 28, 28, 28, 32,
3939
32, 32, 32, 36, 36, 36, 36, 40, 40, 40, 40, 45, 45, 45, 45, 49,
@@ -85,4 +85,3 @@ COLOR ColorInterpolate(COLOR c1, COLOR c2, float amt) {
8585
int b = (int) (GetB(c1) * (1.0f - amt) + GetB(c2) * amt);
8686
return r | (g << 5) | (b << 10);
8787
}
88-

src/color.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,3 @@ COLOR32 ColorRoundToDS18(COLOR32 c);
4545
// Interpolate between two 15-bit colors
4646
//
4747
COLOR ColorInterpolate(COLOR c1, COLOR c2, float amt);
48-

0 commit comments

Comments
 (0)