This commit is contained in:
Brooke Vibber 2022-11-25 17:54:58 -08:00
parent da3a6d69c6
commit da00cf317f
2 changed files with 29 additions and 27 deletions

View file

@ -1,22 +1,27 @@
.PHONY : all clean all : sample0.xex sample1.xex sample2.xex sample3.xex sample4.xex sample5.xex sample6.xex
all : dither4.xex
# sample5.s from sample5.jpg # sample5.s from sample5.jpg
# reminder: $< is input # reminder: $< is input
# $@ is output # $@ is output
%.o : %.s
ca65 -v -t atari -o $@ $<
%.s : %.jpg %.s : %.jpg
node dither-image.js $< $@ $@.png node dither-image.js $< $@ $@.png
%.o : %.s
ca65 -v -t atari -o $@ $<
%.xex : %.o dither4.o
ld65 -v -C atari-asm-xex.cfg -o $@ $<
dither4.xex : dither4.o sample6.o dither4.xex : dither4.o sample6.o
ld65 -v -C atari-asm-xex.cfg -o $@ $< ld65 -v -C atari-asm-xex.cfg -o $@ $<
clean :
rm -f sample5.s #clean :
rm -f sample5.o # rm -f dither4.o
rm -f dither4.o # rm -f dither4.xex
rm -f dither4.xex # rm -f sample[0-6].o
# rm -f sample[0-6].s
# rm -f sample[0-6].xex
# rm -f sample[0-6].png

View file

@ -626,10 +626,8 @@ async function convert(source, nbits) {
for (let y = 0; y < height; y++) { for (let y = 0; y < height; y++) {
let error = lines[y - 1]?.error; let error = lines[y - 1]?.error;
let inputLine = input.slice(y * width, (y + 1) * width); let inputLine = input.slice(y * width, (y + 1) * width);
console.log(`DOING LINE ${y}; have ${inputLine.length} pixels`);
let line = decimate(inputLine, allColors, 4, error); let line = decimate(inputLine, allColors, 4, error);
lines.push(line); lines.push(line);
console.log(`DID LINE ${y}; have ${line.output.length} pixels`);
} }
return { return {
width, width,
@ -640,12 +638,13 @@ async function convert(source, nbits) {
function indexedToBitmap(width, nbits, src, dest) { function indexedToBitmap(width, nbits, src, dest) {
let nbytes = width >> nbits; let nbytes = width * nbits / 8;
let x = 0;
for (let i = 0; i < nbytes; i++) { for (let i = 0; i < nbytes; i++) {
let a = 0; let a = 0;
for (let b = 0; b < 8; b += nbits) { for (let b = 0; b < 8; b += nbits) {
a <<= nbits; a <<= nbits;
a |= src[i]; a |= src[x++];
} }
dest[i] = a; dest[i] = a;
} }
@ -654,7 +653,7 @@ function indexedToBitmap(width, nbits, src, dest) {
function byte2byte(arr) { function byte2byte(arr) {
let lines = []; let lines = [];
for (let i=0; i < arr.length; i++) { for (let i=0; i < arr.length; i++) {
lines.push(`.byte ${lines[i]}`); lines.push(`.byte ${arr[i]}`);
} }
return lines.join('\n'); return lines.join('\n');
} }
@ -669,24 +668,22 @@ function genAssembly(width, height, nbits, lines) {
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];
indexedToBitmap(width, nbits, lines[y].output, framebuffer.slice(y * stride)); indexedToBitmap(width, nbits, lines[y].output, framebuffer.slice(y * stride, (y + 1) * stride));
} }
return ` return `.data
.data
.export palette1: .export far palette1:
${byte2byte(palette1)} ${byte2byte(palette1)}
.export palette2: .export far palette2:
${byte2byte(palette2)} ${byte2byte(palette2)}
.export palette3: .export far palette3:
${byte2byte(palette3)} ${byte2byte(palette3)}
.export framebuffer: .export far framebuffer:
${byte2byte(framebuffer)} ${byte2byte(framebuffer)}
`; `;
} }