From 38e9af3843c3f890274338c0d73102f201389ce1 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 25 Mar 2023 18:57:09 -0700 Subject: [PATCH] wip --- dither-image.js | 43 +++++++++++++++++++++++++++++-------------- dither4.s | 3 ++- video-cat/combine.sh | 2 +- video-doom/combine.sh | 10 ++++++++++ video-doom/extract.sh | 22 ++++++++++++++++++++++ video-doom/video.sh | 15 +++++++++++++++ 6 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 video-doom/combine.sh create mode 100644 video-doom/extract.sh create mode 100644 video-doom/video.sh diff --git a/dither-image.js b/dither-image.js index 58cb9bf..a481e21 100644 --- a/dither-image.js +++ b/dither-image.js @@ -637,6 +637,10 @@ function decimate(input, palette, n) { let [lo, hi] = medianCut(buckets[index], ranges[index]); buckets.splice(index, 1, lo, hi); } + + if (buckets.length > n) { + throw new Error('xxx too many colors assigned'); + } decimated = buckets.map((bucket) => { // Average the RGB colors in this chunk let rgb = bucket @@ -742,9 +746,17 @@ async function loadImage(src) { let width = image.bitmap.width; let height = image.bitmap.height; - if (width != 160 || height != 160) { + //if (width != 160 || height != 160) { + if (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); } @@ -787,10 +799,12 @@ async function convert(source) { throw new Error(`expected 160px-compatible width, got ${width} pixels`); } + /* if (height !== 160) { // @fixme support up to 240px throw new Error(`expected 160px height, got ${height} pixels`); } + */ if (rgba.length != width * 4 * height) { console.log(` @@ -908,29 +922,30 @@ ${byte2byte(frame.bitmap.slice(0, half))} frame1_palette1_even: ${byte2byte(even(frame.palette1))} -.align 128 -frame1_palette1_odd: -${byte2byte(odd(frame.palette1))} - .align 128 frame1_palette2_even: ${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 frame1_palette2_odd: ${byte2byte(odd(frame.palette2))} -.align 128 -frame1_palette3_even: -${byte2byte(even(frame.palette3))} - .align 128 frame1_palette3_odd: ${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 .byte $f0 ; 8 blank lines - ; 160 lines graphics + ; ${height} lines graphics ; ANTIC mode e (160px 2bpp, 1 scan line per line) .byte $4e .addr frame1_top diff --git a/dither4.s b/dither4.s index 9dfb994..6513a16 100644 --- a/dither4.s +++ b/dither4.s @@ -28,7 +28,8 @@ sample_ptr = sample_ptrl scanline = $86 frame_counter = $89 -height = 160 +;height = 160 +height = 192 bytes_per_line = 40 pages_per_frame = 32 lines_per_frame = 262 diff --git a/video-cat/combine.sh b/video-cat/combine.sh index e6a86bf..e41f542 100644 --- a/video-cat/combine.sh +++ b/video-cat/combine.sh @@ -1,5 +1,5 @@ ffmpeg \ - -r 60000/1001 \ + -r 30000/1001 \ -i 'frames/dither-%04d.png' \ -i 'cats-audio.wav' \ -ac 2 \ diff --git a/video-doom/combine.sh b/video-doom/combine.sh new file mode 100644 index 0000000..9e6b03f --- /dev/null +++ b/video-doom/combine.sh @@ -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 diff --git a/video-doom/extract.sh b/video-doom/extract.sh new file mode 100644 index 0000000..e3b4107 --- /dev/null +++ b/video-doom/extract.sh @@ -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' diff --git a/video-doom/video.sh b/video-doom/video.sh new file mode 100644 index 0000000..3b5730e --- /dev/null +++ b/video-doom/video.sh @@ -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