Add support for writing a smaller number of tiles

This commit is contained in:
Gary Talent 2017-04-14 23:15:33 -05:00
parent 36124a1738
commit 6b1ccc7ed2
4 changed files with 29 additions and 18 deletions

View File

@ -5,6 +5,6 @@ set -e
padbin 32 build/gba-release/src/player/nostalgia.bin padbin 32 build/gba-release/src/player/nostalgia.bin
echo NOSTALGIA_MEDIA_HEADER_________ > media_header.txt echo NOSTALGIA_MEDIA_HEADER_________ > media_header.txt
oxfs format 32 1m nostalgia_media.oxfs oxfs format 32 1m nostalgia_media.oxfs
./build/current/src/tools/nost-pack -fs nostalgia_media.oxfs -img charset.png -inode 1 -c ./build/current/src/tools/nost-pack -fs nostalgia_media.oxfs -img charset.png -inode 1 -tiles 40 -c
cat build/gba-release/src/player/nostalgia.bin media_header.txt nostalgia_media.oxfs > nostalgia.gba cat build/gba-release/src/player/nostalgia.bin media_header.txt nostalgia_media.oxfs > nostalgia.gba
gbafix nostalgia.gba gbafix nostalgia.gba

View File

@ -23,6 +23,8 @@ typedef Tile8 CharBlock8[256];
struct GbaImageData { struct GbaImageData {
Pallete pal; Pallete pal;
uint16_t tileCount;
uint8_t bpp;
uint8_t tiles[1]; uint8_t tiles[1];
}; };

View File

@ -71,16 +71,16 @@ static char charMap[128] = {
0, 0,
0, 0,
0, 0,
27, 27, // 0
28, 28, // 1
29, 29, // 2
30, 30, // 3
31, 31, // 4
32, 32, // 5
33, 33, // 6
34, 34, // 7
35, 35, // 8
36, 36, // 9
0, 0,
0, 0,
0, 0,
@ -133,7 +133,7 @@ void initConsole() {
REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel REG_BG0CNT |= (1 << 7); // set to use 8 bits per pixel
if (fs) { if (fs) {
FileStore32::FsSize_t readSize = 0; FileStore32::FsSize_t readSize = 0;
fs->read(1, 512, 8 * 64 * 36, &TILE8_ADDR[0][1], nullptr); fs->read(1, 516, 64 * 38, &TILE8_ADDR[0][1], nullptr);
fs->read(1, 0, 512, &MEM_PALLETE_BG[0], &readSize); fs->read(1, 0, 512, &MEM_PALLETE_BG[0], &readSize);
} }
} }

View File

@ -63,26 +63,35 @@ int run(ClArgs args) {
QString argInPath = args.getString("img").c_str(); QString argInPath = args.getString("img").c_str();
QString argFsPath = args.getString("fs").c_str(); QString argFsPath = args.getString("fs").c_str();
auto argCompact = args.getBool("c"); auto argCompact = args.getBool("c");
auto argTiles = args.getInt("tiles");
QImage src(argInPath); QImage src(argInPath);
if (!src.isNull()) { if (!src.isNull()) {
if (argTiles == 0) {
argTiles = (src.width() * src.height()) / 64;
}
QMap<QRgb, int> colors; QMap<QRgb, int> colors;
const auto imgDataBuffSize = sizeof(Pallete) + src.width() * src.height(); const auto imgDataBuffSize = sizeof(Pallete) + argTiles * 64;
uint8_t imgDataBuff[imgDataBuffSize]; uint8_t imgDataBuff[imgDataBuffSize];
GbaImageData *id = (GbaImageData*) imgDataBuff; GbaImageData *id = (GbaImageData*) imgDataBuff;
id->bpp = 8;
id->tileCount = argTiles;
int colorId = 0; int colorId = 0;
// copy pixels as color ids // copy pixels as color ids
for (int x = 0; x < src.colorCount(); x++) { for (int x = 0; x < src.colorCount(); x++) {
for (int y = 0; y < src.colorCount(); y++) { for (int y = 0; y < src.colorCount(); y++) {
auto destI = pointToIdx(src.width(), x, y); auto destI = pointToIdx(src.width(), x, y);
auto c = src.pixel(x, y); if (destI <= argTiles * 64) {
if (!colors.contains(c)) { auto c = src.pixel(x, y);
colors[c] = colorId; if (!colors.contains(c)) {
colorId++; colors[c] = colorId;
colorId++;
}
((uint8_t*) &id->tiles)[destI] = colors[c];
} }
((uint8_t*) &id->tiles)[destI] = colors[c];
} }
} }