From 3278068e691d2a177aa374a2e6936f079e130017 Mon Sep 17 00:00:00 2001 From: Yegor Pelykh Date: Sun, 12 May 2024 16:20:37 +0300 Subject: [PATCH] fix: Minor ditherImage update --- src/filter/filter.ts | 7 ++----- test/filter/filter.quantize.test.ts | 6 ++++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/filter/filter.ts b/src/filter/filter.ts index 03ef783..3760a82 100644 --- a/src/filter/filter.ts +++ b/src/filter/filter.ts @@ -1107,9 +1107,6 @@ export abstract class Filter { }); const imageCopy = opt.image.clone(); - - const pIter = opt.image[Symbol.iterator](); - let itRes = pIter.next(); for (let y = 0; y < height; y++) { if (serpentine) { direction *= -1; @@ -1117,9 +1114,9 @@ export abstract class Filter { const x0 = direction === 1 ? 0 : width - 1; const x1 = direction === 1 ? width : 0; - for (let x = x0; x !== x1; x += direction, itRes = pIter.next()) { + for (let x = x0; x !== x1; x += direction) { // Get original color - const pc = itRes.value; + const pc = imageCopy.getPixel(x, y); const r1 = Math.trunc(pc.getChannel(0)); const g1 = Math.trunc(pc.getChannel(1)); const b1 = Math.trunc(pc.getChannel(2)); diff --git a/test/filter/filter.quantize.test.ts b/test/filter/filter.quantize.test.ts index cf8751a..69e324e 100644 --- a/test/filter/filter.quantize.test.ts +++ b/test/filter/filter.quantize.test.ts @@ -83,8 +83,10 @@ describe('Filter', () => { data: input, })!; const q1_ = Filter.quantize({ - image: i1_, - numberOfColors: 32, + image: Filter.grayscale({ + image: i1_, + }), + numberOfColors: 2, dither: DitherKernel.floydSteinberg, }); output = encodePng({