Skip to content

Commit e615abf

Browse files
gyngclaude
andcommitted
fix: restore column-major loop order in error diffusion
The perf optimisation changed x-outer/y-inner to y-outer/x-inner. With the Floyd-Steinberg kernel this changes which neighbouring pixels have already received error when the current pixel is processed. Row-major scan causes error to accumulate horizontally, producing large buildup along vertical edges that pushes pixels to wrong bright palette colours (visible as coloured halos). Restoring column-major (x-outer, y-inner) matches the original processing order. Bounds check and Float32Array optimisations kept. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c5b0440 commit e615abf

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/filters/errorDiffusingFilterFactory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export const errorDiffusingFilter = (
5353
// Scratch buffer — avoids per-pixel array allocations in palette calls
5454
const _pix = new Float32Array(4);
5555

56-
for (let y = 0; y < H; y += 1) {
57-
for (let x = 0; x < W; x += 1) {
56+
for (let x = 0; x < W; x += 1) {
57+
for (let y = 0; y < H; y += 1) {
5858
const i = (x + W * y) * 4;
5959

6060
if (useLinear) {

0 commit comments

Comments
 (0)