From 69b30283f572122aba2a3d32745db68c2fcb03b5 Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Tue, 2 Nov 2021 17:30:27 +0100 Subject: [PATCH] refactor(pixel-dither): minor update --- packages/pixel-dither/src/dither.ts | 12 ++++++------ packages/pixel-dither/src/ordered.ts | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/pixel-dither/src/dither.ts b/packages/pixel-dither/src/dither.ts index b56d95b4a3..9df6f04bc9 100644 --- a/packages/pixel-dither/src/dither.ts +++ b/packages/pixel-dither/src/dither.ts @@ -30,23 +30,23 @@ export const ditherWith = ( const chan = format.channels[cid]; const $thresh = chan.num * threshold; const $max = chan.mask0; - const pixels = new Int32Array(cimg.pixels); + const data = new Int32Array(cimg.data); for (let y = 0; y < height; y++) { for (let x = 0, i = x + y * width; x < width; x++, i++) { - p = pixels[i] < $thresh ? 0 : $max; - err = (pixels[i] - p) * bleed; - pixels[i] = p; + p = data[i] < $thresh ? 0 : $max; + err = (data[i] - p) * bleed; + data[i] = p; if (!err) continue; for (let j = ox.length; j-- > 0; ) { const xx = x + ox[j]; const yy = y + oy[j]; if (yy >= 0 && yy < height && xx >= 0 && xx < width) { - pixels[yy * width + xx] += (err * weights[j]) >> shift; + data[yy * width + xx] += (err * weights[j]) >> shift; } } } } - cimg.pixels.set(pixels); + cimg.data.set(data); img.setChannel(cid, cimg); } return img; diff --git a/packages/pixel-dither/src/ordered.ts b/packages/pixel-dither/src/ordered.ts index 722973063b..1b0e573007 100644 --- a/packages/pixel-dither/src/ordered.ts +++ b/packages/pixel-dither/src/ordered.ts @@ -92,17 +92,17 @@ export const orderedDither = ( size: BayerSize | BayerMatrix, numColors: number | number[] ) => { - const { pixels, format, width } = img; + const { data, format, width } = img; const steps = isNumber(numColors) ? new Array(format.channels.length).fill(numColors) : numColors; const mat = isNumber(size) ? defBayer(size) : size; for ( - let i = 0, n = pixels.length, nc = format.channels.length, x = 0, y = 0; + let i = 0, n = data.length, nc = format.channels.length, x = 0, y = 0; i < n; i++ ) { - let col = pixels[i]; + let col = data[i]; for (let j = 0; j < nc; j++) { const ch = format.channels[j]; const num = ch.num; @@ -113,7 +113,7 @@ export const orderedDither = ( orderedDither1(mat, cs, num, num, x, y, ch.int(col)) )); } - pixels[i] = col; + data[i] = col; if (++x === width) { x = 0; y++;