clean up undoing the frames dup

This commit is contained in:
Brooke Vibber 2023-03-18 19:09:00 -07:00
parent dfc3cfaacf
commit 0cf5b06f73
2 changed files with 35 additions and 58 deletions

View file

@ -7,8 +7,6 @@ all : sample0.xex sample1.xex sample2.xex sample3.xex sample4.xex sample5.xex sa
%.s : %.jpg dither-image.js gif.sh mp4.sh %.s : %.jpg dither-image.js gif.sh mp4.sh
node dither-image.js $< $@ node dither-image.js $< $@
./gif.sh $@
./mp4.sh $@
chickens.s : chickens.wav pack-wav.js chickens.s : chickens.wav pack-wav.js
node pack-wav.js $< $@ node pack-wav.js $< $@
@ -37,9 +35,6 @@ 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-9].png
rm -f sample[0-6].s.palette.png
rm -f sample[0-6].s.gif
rm -f *.xex rm -f *.xex
rm -f chickens.s rm -f chickens.s
rm -f chickens.o rm -f chickens.o

View file

@ -504,7 +504,8 @@ function decimate(input, palette, n, inputError) {
} }
} }
decimated = decimated.filter((color, i) => { decimated = decimated.filter((color, i) => {
if (i == 0) { if (palette[i] == 0) {
// solid black
return true; return true;
} }
if (i == pick) { if (i == pick) {
@ -567,7 +568,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, reps) { async function convert(source, nbits) {
let { let {
width, width,
@ -592,15 +593,6 @@ async function convert(source, nbits, reps) {
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) {
@ -662,21 +654,17 @@ function odd(arr) {
return arr.filter((_item, index) => (index & 1)); return arr.filter((_item, index) => (index & 1));
} }
function genAssembly(width, height, nbits, lines, reps) { function genAssembly(width, height, nbits, lines) {
let linesEach = height / reps;
let stride = width * nbits / 8; let stride = width * nbits / 8;
let half = stride * linesEach / 2; let half = stride * height / 2;
let frames = []; let frame = {
palette1: new Uint8Array(height),
for (let i = 0; i < reps; i ++) { palette2: new Uint8Array(height),
let frame = frames[i] = { palette3: new Uint8Array(height),
palette1: new Uint8Array(linesEach), bitmap: new Uint8Array(stride * height),
palette2: new Uint8Array(linesEach),
palette3: new Uint8Array(linesEach),
bitmap: new Uint8Array(stride * linesEach),
}; };
for (let y = 0; y < linesEach; y++) { for (let y = 0; y < height; y++) {
let base = linesEach * i; let base = 0;
frame.palette1[y] = lines[y + base].palette[1]; frame.palette1[y] = lines[y + base].palette[1];
frame.palette2[y] = lines[y + base].palette[2]; frame.palette2[y] = lines[y + base].palette[2];
frame.palette3[y] = lines[y + base].palette[3]; frame.palette3[y] = lines[y + base].palette[3];
@ -687,7 +675,6 @@ function genAssembly(width, height, nbits, lines, reps) {
frame.bitmap.subarray(y * stride, (y + 1) * stride) frame.bitmap.subarray(y * stride, (y + 1) * stride)
); );
} }
}
return `.data return `.data
.export frame1_top .export frame1_top
@ -704,35 +691,35 @@ function genAssembly(width, height, nbits, lines, reps) {
.align 4096 .align 4096
frame1_top: frame1_top:
${byte2byte(frames[0].bitmap.slice(0, half))} ${byte2byte(frame.bitmap.slice(0, half))}
.align 128 .align 128
frame1_palette1_even: frame1_palette1_even:
${byte2byte(even(frames[0].palette1))} ${byte2byte(even(frame.palette1))}
.align 128 .align 128
frame1_palette1_odd: frame1_palette1_odd:
${byte2byte(odd(frames[0].palette1))} ${byte2byte(odd(frame.palette1))}
.align 128 .align 128
frame1_palette2_even: frame1_palette2_even:
${byte2byte(even(frames[0].palette2))} ${byte2byte(even(frame.palette2))}
.align 128 .align 128
frame1_palette2_odd: frame1_palette2_odd:
${byte2byte(odd(frames[0].palette2))} ${byte2byte(odd(frame.palette2))}
.align 128 .align 128
frame1_palette3_even: frame1_palette3_even:
${byte2byte(even(frames[0].palette3))} ${byte2byte(even(frame.palette3))}
.align 128 .align 128
frame1_palette3_odd: frame1_palette3_odd:
${byte2byte(odd(frames[0].palette3))} ${byte2byte(odd(frame.palette3))}
.align 4096 .align 4096
frame1_bottom: frame1_bottom:
${byte2byte(frames[0].bitmap.slice(half))} ${byte2byte(frame.bitmap.slice(half))}
@ -749,12 +736,12 @@ displaylist:
; ANTIC mode e (160px 2bpp, 1 scan line per line) ; ANTIC mode e (160px 2bpp, 1 scan line per line)
.byte $4e .byte $4e
.addr frame1_top .addr frame1_top
.repeat ${linesEach / 2 - 1} .repeat ${height / 2 - 1}
.byte $0e .byte $0e
.endrep .endrep
.byte $4e .byte $4e
.addr frame1_bottom .addr frame1_bottom
.repeat ${linesEach / 2 - 1} .repeat ${height / 2 - 1}
.byte $0e .byte $0e
.endrep .endrep
@ -811,18 +798,13 @@ async function main() {
} }
let nbits = 2; let nbits = 2;
let reps = 1;
let {width, height, lines} = await convert(process.argv[2], nbits, reps); let {width, height, lines} = await convert(process.argv[2], nbits);
let asm = genAssembly(width, height, nbits, lines, reps); let asm = genAssembly(width, height, nbits, lines);
writeFileSync(process.argv[3], asm, "utf-8"); writeFileSync(process.argv[3], asm, "utf-8");
let heightPerFrame = height / reps; await saveImage(width, height, lines, `${process.argv[3]}.png`);
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);
} }