Cleanup nost-pack

This commit is contained in:
Gary Talent 2017-04-13 05:32:56 -05:00
parent aaa870a2e9
commit 7ddfc0639b

@ -59,17 +59,18 @@ int pointToIdx(int w, int x, int y) {
int run(ClArgs args) { int run(ClArgs args) {
Error err = 0; Error err = 0;
QString inPath = args.getString("img").c_str(); QString argInPath = args.getString("img").c_str();
QString fsPath = args.getString("fs").c_str(); QString argFsPath = args.getString("fs").c_str();
auto compact = args.getBool("c"); auto argCompact = args.getBool("c");
QMap<QRgb, int> colors;
QImage src(inPath); QImage src(argInPath);
const auto imgDataBuffSize = sizeof(Pallete) - 1 + src.width() * src.height();
uint8_t imgDataBuff[imgDataBuffSize];
GbaImageData *id = (GbaImageData*) imgDataBuff;
int colorId = 0;
if (!src.isNull()) { if (!src.isNull()) {
QMap<QRgb, int> colors;
const auto imgDataBuffSize = sizeof(Pallete) - 1 + src.width() * src.height();
uint8_t imgDataBuff[imgDataBuffSize];
GbaImageData *id = (GbaImageData*) imgDataBuff;
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++) {
@ -92,7 +93,7 @@ int run(ClArgs args) {
size_t fsBuffSize; size_t fsBuffSize;
auto fsBuff = loadFileBuff(fsPath, &fsBuffSize); auto fsBuff = loadFileBuff(argFsPath, &fsBuffSize);
if (fsBuff && !err) { if (fsBuff && !err) {
auto fs = createFileSystem(fsBuff, fsBuffSize); auto fs = createFileSystem(fsBuff, fsBuffSize);
@ -101,11 +102,11 @@ int run(ClArgs args) {
fsBuff = fs->buff(); // update fsBuff pointer in case there is a new buff fsBuff = fs->buff(); // update fsBuff pointer in case there is a new buff
err |= fs->write(1, imgDataBuff, imgDataBuffSize); err |= fs->write(1, imgDataBuff, imgDataBuffSize);
if (compact) { if (argCompact) {
fs->resize(); fs->resize();
} }
auto fsFile = fopen(fsPath.toUtf8(), "wb"); auto fsFile = fopen(argFsPath.toUtf8(), "wb");
if (fsFile) { if (fsFile) {
err = fwrite(fsBuff, fs->size(), 1, fsFile) != 1; err = fwrite(fsBuff, fs->size(), 1, fsFile) != 1;
err |= fclose(fsFile); err |= fclose(fsFile);