This commit is contained in:
Brooke Vibber 2023-03-25 18:57:09 -07:00
parent e5adb72851
commit 38e9af3843
6 changed files with 79 additions and 16 deletions

View file

@ -637,6 +637,10 @@ function decimate(input, palette, n) {
let [lo, hi] = medianCut(buckets[index], ranges[index]); let [lo, hi] = medianCut(buckets[index], ranges[index]);
buckets.splice(index, 1, lo, hi); buckets.splice(index, 1, lo, hi);
} }
if (buckets.length > n) {
throw new Error('xxx too many colors assigned');
}
decimated = buckets.map((bucket) => { decimated = buckets.map((bucket) => {
// Average the RGB colors in this chunk // Average the RGB colors in this chunk
let rgb = bucket let rgb = bucket
@ -742,9 +746,17 @@ async function loadImage(src) {
let width = image.bitmap.width; let width = image.bitmap.width;
let height = image.bitmap.height; let height = image.bitmap.height;
if (width != 160 || height != 160) { //if (width != 160 || height != 160) {
if (width != 160) {
width = 160; width = 160;
height = 160; //height = 160;
//height = 192;
let dar = 1.2 / 2;
height = (width * image.bitmap.width / image.bitmap.height) * dar;
height = Math.round(height);
if (height & 1) {
height++;
}
image = image.resize(width, height); image = image.resize(width, height);
} }
@ -787,10 +799,12 @@ async function convert(source) {
throw new Error(`expected 160px-compatible width, got ${width} pixels`); throw new Error(`expected 160px-compatible width, got ${width} pixels`);
} }
/*
if (height !== 160) { if (height !== 160) {
// @fixme support up to 240px // @fixme support up to 240px
throw new Error(`expected 160px height, got ${height} pixels`); throw new Error(`expected 160px height, got ${height} pixels`);
} }
*/
if (rgba.length != width * 4 * height) { if (rgba.length != width * 4 * height) {
console.log(` console.log(`
@ -908,29 +922,30 @@ ${byte2byte(frame.bitmap.slice(0, half))}
frame1_palette1_even: frame1_palette1_even:
${byte2byte(even(frame.palette1))} ${byte2byte(even(frame.palette1))}
.align 128
frame1_palette1_odd:
${byte2byte(odd(frame.palette1))}
.align 128 .align 128
frame1_palette2_even: frame1_palette2_even:
${byte2byte(even(frame.palette2))} ${byte2byte(even(frame.palette2))}
.align 128
frame1_palette3_even:
${byte2byte(even(frame.palette3))}
.align 4096
frame1_bottom:
${byte2byte(frame.bitmap.slice(half))}
.align 128
frame1_palette1_odd:
${byte2byte(odd(frame.palette1))}
.align 128 .align 128
frame1_palette2_odd: frame1_palette2_odd:
${byte2byte(odd(frame.palette2))} ${byte2byte(odd(frame.palette2))}
.align 128
frame1_palette3_even:
${byte2byte(even(frame.palette3))}
.align 128 .align 128
frame1_palette3_odd: frame1_palette3_odd:
${byte2byte(odd(frame.palette3))} ${byte2byte(odd(frame.palette3))}
.align 4096
frame1_bottom:
${byte2byte(frame.bitmap.slice(half))}
@ -943,7 +958,7 @@ displaylist:
; include a DLI to mark us as frame 0 ; include a DLI to mark us as frame 0
.byte $f0 ; 8 blank lines .byte $f0 ; 8 blank lines
; 160 lines graphics ; ${height} lines graphics
; 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

View file

@ -28,7 +28,8 @@ sample_ptr = sample_ptrl
scanline = $86 scanline = $86
frame_counter = $89 frame_counter = $89
height = 160 ;height = 160
height = 192
bytes_per_line = 40 bytes_per_line = 40
pages_per_frame = 32 pages_per_frame = 32
lines_per_frame = 262 lines_per_frame = 262

View file

@ -1,5 +1,5 @@
ffmpeg \ ffmpeg \
-r 60000/1001 \ -r 30000/1001 \
-i 'frames/dither-%04d.png' \ -i 'frames/dither-%04d.png' \
-i 'cats-audio.wav' \ -i 'cats-audio.wav' \
-ac 2 \ -ac 2 \

10
video-doom/combine.sh Normal file
View file

@ -0,0 +1,10 @@
ffmpeg \
-r 60000/1001 \
-i 'frames/dither-%04d.png' \
-i 'doom-audio.wav' \
-ac 2 \
-ar 48000 \
-vf 'pad=w=640:h=360:x=52:y=20' \
-pix_fmt yuv420p \
-movflags +faststart \
-y doom-dither.mp4

22
video-doom/extract.sh Normal file
View file

@ -0,0 +1,22 @@
set -a
mkdir -p frames
TIME=37
ffmpeg \
-i 'doom-speedrun.webm' \
-t $TIME \
-r 60000/1001 \
-vf 'scale=160:192' \
-an \
-y 'frames/doom-%04d.png'
ffmpeg \
-i 'doom-speedrun.webm' \
-t $TIME \
-vn \
-ac 1 \
-ar 15734 \
-acodec pcm_u8 \
-y 'doom-audio.wav'

15
video-doom/video.sh Normal file
View file

@ -0,0 +1,15 @@
set -e
for frame in frames/doom-[0-9][0-9][0-9][0-9].png
do
n="${frame#frames/doom-}"
n="${n%.png}"
out="frames/dither-${n}"
last="${n:0-1}"
node ../dither-image.js "$frame" "$out" &
if (( last == 9 ))
then
wait
fi
done
wait