WIP 4-frame output
This commit is contained in:
parent
7d7a5bd064
commit
ece161d6d6
3 changed files with 29 additions and 10 deletions
4
Makefile
4
Makefile
|
@ -6,7 +6,7 @@ all : sample0.xex sample1.xex sample2.xex sample3.xex sample4.xex sample5.xex sa
|
||||||
# $@ is output
|
# $@ is output
|
||||||
|
|
||||||
%.s : %.jpg dither-image.js
|
%.s : %.jpg dither-image.js
|
||||||
node dither-image.js $< $@ $@.png
|
node dither-image.js $< $@
|
||||||
|
|
||||||
chickens.s : chickens.wav pack-wav.js
|
chickens.s : chickens.wav pack-wav.js
|
||||||
node pack-wav.js $< $@
|
node pack-wav.js $< $@
|
||||||
|
@ -24,6 +24,8 @@ clean :
|
||||||
rm -f sample[0-6].o
|
rm -f sample[0-6].o
|
||||||
rm -f sample[0-6].xex
|
rm -f sample[0-6].xex
|
||||||
rm -f sample[0-6].s.png
|
rm -f sample[0-6].s.png
|
||||||
|
rm -f sample[0-6].s.0.png
|
||||||
|
rm -f sample[0-6].s.1.png
|
||||||
rm -f chickens.s
|
rm -f chickens.s
|
||||||
rm -f chickens.o
|
rm -f chickens.o
|
||||||
|
|
||||||
|
|
|
@ -383,8 +383,8 @@ let atariRGB = [
|
||||||
* @param {RGB[]} input source scanline data, in linear RGB
|
* @param {RGB[]} input source scanline data, in linear RGB
|
||||||
* @param {number[]} palette - current working palette, as Atari 8-bit color values (low nybble luminance, high nybble hue)
|
* @param {number[]} palette - current working palette, as Atari 8-bit color values (low nybble luminance, high nybble hue)
|
||||||
* @param {number} n - target color count
|
* @param {number} n - target color count
|
||||||
* @param {Object} inputError
|
* @param {RGB[]} inputError
|
||||||
* @returns {{output: Uint8Array, palette: number[], error: {red: Float64Array, green: Float64Array, blue: Float64Array}}}
|
* @returns {{output: Uint8Array, palette: number[], error: RGB[]}}
|
||||||
*/
|
*/
|
||||||
function decimate(input, palette, n, inputError) {
|
function decimate(input, palette, n, inputError) {
|
||||||
// to brute-force, the possible palettes are:
|
// to brute-force, the possible palettes are:
|
||||||
|
@ -446,9 +446,10 @@ function decimate(input, palette, n, inputError) {
|
||||||
popularity[pick]++;
|
popularity[pick]++;
|
||||||
|
|
||||||
if (x == width - 1) {
|
if (x == width - 1) {
|
||||||
let half = nextError.divide(2);
|
let half = nextError.divide(4);
|
||||||
error.next[x - 1].inc(half);
|
error.next[x - 1].inc(half);
|
||||||
error.next[x].inc(half);
|
error.next[x].inc(half);
|
||||||
|
// drop half the error on the floor at the edge ;_;
|
||||||
} else {
|
} else {
|
||||||
let quarter = nextError.divide(4);
|
let quarter = nextError.divide(4);
|
||||||
error.right = quarter;
|
error.right = quarter;
|
||||||
|
@ -565,7 +566,7 @@ function imageToLinearRGB(rgba) {
|
||||||
* @param {string} source path to source image file
|
* @param {string} source path to source image file
|
||||||
* @returns {{width: number, height: number, lines: {palette: Array, output: Uint8Array}[]}}
|
* @returns {{width: number, height: number, lines: {palette: Array, output: Uint8Array}[]}}
|
||||||
*/
|
*/
|
||||||
async function convert(source, nbits) {
|
async function convert(source, nbits, reps) {
|
||||||
|
|
||||||
let {
|
let {
|
||||||
width,
|
width,
|
||||||
|
@ -590,6 +591,15 @@ async function convert(source, nbits) {
|
||||||
throw new Error('inconsistent data size');
|
throw new Error('inconsistent data size');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (reps > 1) {
|
||||||
|
height *= reps;
|
||||||
|
let rgba2 = new Uint8Array(rgba.length * reps);
|
||||||
|
for (let i = 0; i < reps; i++) {
|
||||||
|
rgba2.set(rgba, rgba.length * i);
|
||||||
|
}
|
||||||
|
rgba = rgba2;
|
||||||
|
}
|
||||||
|
|
||||||
let input = imageToLinearRGB(rgba);
|
let input = imageToLinearRGB(rgba);
|
||||||
|
|
||||||
if (input.length != width * height) {
|
if (input.length != width * height) {
|
||||||
|
@ -649,7 +659,7 @@ function genAssembly(width, height, nbits, lines) {
|
||||||
let palette2 = new Uint8Array(height);
|
let palette2 = new Uint8Array(height);
|
||||||
let palette3 = new Uint8Array(height);
|
let palette3 = new Uint8Array(height);
|
||||||
let bitmap = new Uint8Array(stride * height);
|
let bitmap = new Uint8Array(stride * height);
|
||||||
for (let y = 0; y < height; y++) {
|
for (let y = 0; y < lines.length; y++) {
|
||||||
palette1[y] = lines[y].palette[1];
|
palette1[y] = lines[y].palette[1];
|
||||||
palette2[y] = lines[y].palette[2];
|
palette2[y] = lines[y].palette[2];
|
||||||
palette3[y] = lines[y].palette[3];
|
palette3[y] = lines[y].palette[3];
|
||||||
|
@ -723,19 +733,24 @@ async function saveImage(width, height, lines, dest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (process.argv.length < 5) {
|
if (process.argv.length < 3) {
|
||||||
console.error("Usage: node dither-image.js source-image.jpg dest-asm.s dest-preview.png");
|
console.error("Usage: node dither-image.js source-image.jpg dest-asm.s");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let nbits = 2;
|
let nbits = 2;
|
||||||
|
let reps = 4;
|
||||||
|
|
||||||
let {width, height, lines} = await convert(process.argv[2], nbits);
|
let {width, height, lines} = await convert(process.argv[2], nbits, reps);
|
||||||
|
|
||||||
let asm = genAssembly(width, height, nbits, lines);
|
let asm = genAssembly(width, height, nbits, lines);
|
||||||
writeFileSync(process.argv[3], asm, "utf-8");
|
writeFileSync(process.argv[3], asm, "utf-8");
|
||||||
|
|
||||||
await saveImage(width, height, lines, process.argv[4]);
|
let heightPerFrame = height / reps;
|
||||||
|
for (let i = 0; i < reps; i++) {
|
||||||
|
let slice = lines.slice(i * heightPerFrame, (i + 1) * heightPerFrame);
|
||||||
|
await saveImage(width, heightPerFrame, slice, `${process.argv[3]}.${i}.png`);
|
||||||
|
}
|
||||||
|
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,8 @@ let infile = process.argv[2];
|
||||||
let outfile = process.argv[3];
|
let outfile = process.argv[3];
|
||||||
|
|
||||||
let buffer = readFileSync(infile);
|
let buffer = readFileSync(infile);
|
||||||
|
// @FIXME fix
|
||||||
|
buffer = buffer.slice(0, 262);
|
||||||
let asm = wav2assembly(buffer);
|
let asm = wav2assembly(buffer);
|
||||||
writeFileSync(outfile, asm, 'utf-8');
|
writeFileSync(outfile, asm, 'utf-8');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue