Committing progres

This commit is contained in:
2022-01-06 09:22:49 -08:00
parent f339ce0713
commit 4ad29e981e
15 changed files with 74 additions and 320 deletions

View File

@@ -1,4 +1,5 @@
const PNG = require('pngjs').PNG;
const path = require('path');
const fs = require('fs');
const { arrayToString } = require('./util');
const {
@@ -15,8 +16,7 @@ const getPixelValue = (pixel) => {
throw new Error();
}
const png2gb = (fileIn, fileOut, name) => {
const png2gb = (fileIn, dirOut, name) => {
const data = fs.readFileSync(fileIn);
const png = PNG.sync.read(data);
@@ -66,16 +66,24 @@ const png2gb = (fileIn, fileOut, name) => {
bits.push(lowBits, highBits);
}
let out = '';
out += `#include "libs.h"\n\n`
out += `#define ${name}_IMAGE_WIDTH ${png.width}\n`;
out += `#define ${name}_IMAGE_HEIGHT ${png.height}\n`;
out += `#define ${name}_IMAGE_COLUMNS ${png.width / TILE_WIDTH}\n`;
out += `#define ${name}_IMAGE_ROWS ${png.height / TILE_HEIGHT}\n`;
out += `#define ${name}_IMAGE_TILES ${columns * rows}\n`;
out += `\nconst uint8_t ${name}_IMAGE[] = {\n${arrayToSTring(bits)}};`;
let outH = '';
outH += `#include "libs.h"\n\n`
outH += `#define ${name}_IMAGE_WIDTH ${png.width}\n`;
outH += `#define ${name}_IMAGE_HEIGHT ${png.height}\n`;
outH += `#define ${name}_IMAGE_COLUMNS ${png.width / TILE_WIDTH}\n`;
outH += `#define ${name}_IMAGE_ROWS ${png.height / TILE_HEIGHT}\n`;
outH += `#define ${name}_IMAGE_TILES ${columns * rows}\n`;
outH += `extern const uint8_t ${name}_IMAGE[];`;
fs.writeFileSync(fileOut, out);
let outC = `#include "${name}.h"\n`;
outC += `\nconst uint8_t ${name}_IMAGE[] = {\n${arrayToString(bits)}};`;
const fileH = path.join(dirOut, name + '.h');
const fileC = path.join(dirOut, name + '.c');
fs.writeFileSync(fileH, outH);
fs.writeFileSync(fileC, outC);
return { fileH, fileC };
}
module.exports = {