Skip to content

Commit

Permalink
fix: Minor ditherImage update
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor-pelykh committed May 12, 2024
1 parent 90578df commit 3278068
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/filter/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1107,19 +1107,16 @@ 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;
}

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));
Expand Down
6 changes: 4 additions & 2 deletions test/filter/filter.quantize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 3278068

Please sign in to comment.