From 7d7a5bd064afc13e24ce1eaeaa9f697b2ce8d4ae Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 30 Nov 2022 08:53:47 -0800 Subject: [PATCH] wip 160px height --- dither-image.js | 33 +++++++++------------------------ dither4.s | 11 ++++++----- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/dither-image.js b/dither-image.js index 88bbcbb..e502cfe 100644 --- a/dither-image.js +++ b/dither-image.js @@ -529,8 +529,15 @@ function decimate(input, palette, n, inputError) { */ async function loadImage(src) { let image = await Jimp.read(src); + let width = image.bitmap.width; let height = image.bitmap.height; + if (width != 160 || height != 160) { + width = 160; + height = 160; + image = image.resize(width, height); + } + let rgba = image.bitmap.data.slice(); return { width, @@ -539,23 +546,6 @@ async function loadImage(src) { }; } -/** - * Halve the horizontal resolution, interpolating input. - * @param {Uint8Array} rgba - * @returns {Uint8Array} - **/ -function halveImage(rgba) { - let out = new Uint8Array(rgba.length >> 1); - for (let i = 0; i < rgba.length; i += 8) { - let j = i >> 1; - out[j + 0] = (rgba[i + 0] + rgba[i + 4] + 1) >> 1; - out[j + 1] = (rgba[i + 1] + rgba[i + 5] + 1) >> 1; - out[j + 2] = (rgba[i + 2] + rgba[i + 6] + 1) >> 1; - out[j + 3] = (rgba[i + 3] + rgba[i + 7] + 1) >> 1; - } - return out; -} - function imageToLinearRGB(rgba) { let input = []; for (let i = 0; i < rgba.length; i += 4) { @@ -583,18 +573,13 @@ async function convert(source, nbits) { rgba } = await loadImage(source); - if (width == 320) { - width = 160; - rgba = halveImage(rgba); - } - if (width !== 160) { throw new Error(`expected 160px-compatible width, got ${width} pixels`); } - if (height !== 192) { + if (height !== 160) { // @fixme support up to 240px - throw new Error(`expected 192px height, got ${height} pixels`); + throw new Error(`expected 160px height, got ${height} pixels`); } if (rgba.length != width * 4 * height) { diff --git a/dither4.s b/dither4.s index eba84eb..3f1e314 100644 --- a/dither4.s +++ b/dither4.s @@ -27,11 +27,12 @@ sample_ptrh = $85 sample_ptr = sample_ptrl scanline = $86 -height = 192 +height = 160 bytes_per_line = 40 pages_per_frame = 32 lines_per_frame = 262 -scanline_offset = 31 +;scanline_offset = 31 + (40 - 24) / 2 +scanline_offset = 47 scanline_max = (lines_per_frame - scanline_offset) / 2 .data @@ -44,12 +45,12 @@ scanline_max = (lines_per_frame - scanline_offset) / 2 .import audio_samples_end displaylist: - ; 24 lines overscan - .repeat 3 + ; 40 lines overscan + .repeat 5 .byte $70 ; 8 blank lines .endrep - ; 192 lines graphics + ; 160 lines graphics ; ANTIC mode e (160px 2bpp, 1 scan line per line) .byte $4e .addr framebuffer