clean up undoing the frames dup
This commit is contained in:
parent
dfc3cfaacf
commit
0cf5b06f73
2 changed files with 35 additions and 58 deletions
5
Makefile
5
Makefile
|
@ -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
|
||||
node dither-image.js $< $@
|
||||
./gif.sh $@
|
||||
./mp4.sh $@
|
||||
|
||||
chickens.s : chickens.wav pack-wav.js
|
||||
node pack-wav.js $< $@
|
||||
|
@ -37,9 +35,6 @@ clean :
|
|||
rm -f sample[0-6].o
|
||||
rm -f sample[0-6].xex
|
||||
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 chickens.s
|
||||
rm -f chickens.o
|
||||
|
|
|
@ -504,7 +504,8 @@ function decimate(input, palette, n, inputError) {
|
|||
}
|
||||
}
|
||||
decimated = decimated.filter((color, i) => {
|
||||
if (i == 0) {
|
||||
if (palette[i] == 0) {
|
||||
// solid black
|
||||
return true;
|
||||
}
|
||||
if (i == pick) {
|
||||
|
@ -567,7 +568,7 @@ function imageToLinearRGB(rgba) {
|
|||
* @param {string} source path to source image file
|
||||
* @returns {{width: number, height: number, lines: {palette: Array, output: Uint8Array}[]}}
|
||||
*/
|
||||
async function convert(source, nbits, reps) {
|
||||
async function convert(source, nbits) {
|
||||
|
||||
let {
|
||||
width,
|
||||
|
@ -592,15 +593,6 @@ async function convert(source, nbits, reps) {
|
|||
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);
|
||||
|
||||
if (input.length != width * height) {
|
||||
|
@ -662,31 +654,26 @@ function odd(arr) {
|
|||
return arr.filter((_item, index) => (index & 1));
|
||||
}
|
||||
|
||||
function genAssembly(width, height, nbits, lines, reps) {
|
||||
let linesEach = height / reps;
|
||||
function genAssembly(width, height, nbits, lines) {
|
||||
let stride = width * nbits / 8;
|
||||
let half = stride * linesEach / 2;
|
||||
let frames = [];
|
||||
|
||||
for (let i = 0; i < reps; i ++) {
|
||||
let frame = frames[i] = {
|
||||
palette1: new Uint8Array(linesEach),
|
||||
palette2: new Uint8Array(linesEach),
|
||||
palette3: new Uint8Array(linesEach),
|
||||
bitmap: new Uint8Array(stride * linesEach),
|
||||
};
|
||||
for (let y = 0; y < linesEach; y++) {
|
||||
let base = linesEach * i;
|
||||
frame.palette1[y] = lines[y + base].palette[1];
|
||||
frame.palette2[y] = lines[y + base].palette[2];
|
||||
frame.palette3[y] = lines[y + base].palette[3];
|
||||
indexedToBitmap(
|
||||
width,
|
||||
nbits,
|
||||
lines[y + base].output,
|
||||
frame.bitmap.subarray(y * stride, (y + 1) * stride)
|
||||
);
|
||||
}
|
||||
let half = stride * height / 2;
|
||||
let frame = {
|
||||
palette1: new Uint8Array(height),
|
||||
palette2: new Uint8Array(height),
|
||||
palette3: new Uint8Array(height),
|
||||
bitmap: new Uint8Array(stride * height),
|
||||
};
|
||||
for (let y = 0; y < height; y++) {
|
||||
let base = 0;
|
||||
frame.palette1[y] = lines[y + base].palette[1];
|
||||
frame.palette2[y] = lines[y + base].palette[2];
|
||||
frame.palette3[y] = lines[y + base].palette[3];
|
||||
indexedToBitmap(
|
||||
width,
|
||||
nbits,
|
||||
lines[y + base].output,
|
||||
frame.bitmap.subarray(y * stride, (y + 1) * stride)
|
||||
);
|
||||
}
|
||||
|
||||
return `.data
|
||||
|
@ -704,35 +691,35 @@ function genAssembly(width, height, nbits, lines, reps) {
|
|||
|
||||
.align 4096
|
||||
frame1_top:
|
||||
${byte2byte(frames[0].bitmap.slice(0, half))}
|
||||
${byte2byte(frame.bitmap.slice(0, half))}
|
||||
|
||||
.align 128
|
||||
frame1_palette1_even:
|
||||
${byte2byte(even(frames[0].palette1))}
|
||||
${byte2byte(even(frame.palette1))}
|
||||
|
||||
.align 128
|
||||
frame1_palette1_odd:
|
||||
${byte2byte(odd(frames[0].palette1))}
|
||||
${byte2byte(odd(frame.palette1))}
|
||||
|
||||
.align 128
|
||||
frame1_palette2_even:
|
||||
${byte2byte(even(frames[0].palette2))}
|
||||
${byte2byte(even(frame.palette2))}
|
||||
|
||||
.align 128
|
||||
frame1_palette2_odd:
|
||||
${byte2byte(odd(frames[0].palette2))}
|
||||
${byte2byte(odd(frame.palette2))}
|
||||
|
||||
.align 128
|
||||
frame1_palette3_even:
|
||||
${byte2byte(even(frames[0].palette3))}
|
||||
${byte2byte(even(frame.palette3))}
|
||||
|
||||
.align 128
|
||||
frame1_palette3_odd:
|
||||
${byte2byte(odd(frames[0].palette3))}
|
||||
${byte2byte(odd(frame.palette3))}
|
||||
|
||||
.align 4096
|
||||
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)
|
||||
.byte $4e
|
||||
.addr frame1_top
|
||||
.repeat ${linesEach / 2 - 1}
|
||||
.repeat ${height / 2 - 1}
|
||||
.byte $0e
|
||||
.endrep
|
||||
.byte $4e
|
||||
.addr frame1_bottom
|
||||
.repeat ${linesEach / 2 - 1}
|
||||
.repeat ${height / 2 - 1}
|
||||
.byte $0e
|
||||
.endrep
|
||||
|
||||
|
@ -811,18 +798,13 @@ async function main() {
|
|||
}
|
||||
|
||||
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");
|
||||
|
||||
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`);
|
||||
}
|
||||
await saveImage(width, height, lines, `${process.argv[3]}.png`);
|
||||
|
||||
process.exit(0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue