Skip to content

Commit

Permalink
Fix pixelate not working well with alpha channel (#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
hipstersmoothie authored Sep 2, 2024
1 parent a425b4c commit 068cd03
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion plugins/plugin-color/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function applyKernel(
x: number,
y: number
) {
const value = [0, 0, 0] as [number, number, number];
const value = [0, 0, 0, 0] as [number, number, number, number];
const size = (kernel.length - 1) / 2;

for (let kx = 0; kx < kernel.length; kx += 1) {
Expand All @@ -74,6 +74,7 @@ function applyKernel(
value[0] += image.bitmap.data[idx]! * kernel[kx]![ky]!;
value[1] += image.bitmap.data[idx + 1]! * kernel[kx]![ky]!;
value[2] += image.bitmap.data[idx + 2]! * kernel[kx]![ky]!;
value[3] += image.bitmap.data[idx + 3]! * kernel[kx]![ky]!;
}
}

Expand Down Expand Up @@ -718,6 +719,7 @@ export const methods = {
image.bitmap.data[idx] = value[0]!;
image.bitmap.data[idx + 1] = value[1]!;
image.bitmap.data[idx + 2] = value[2]!;
image.bitmap.data[idx + 3] = value[3]!;
});

return image;
Expand Down Expand Up @@ -766,6 +768,7 @@ export const methods = {
image.bitmap.data[idx] = limit255(value[0]!);
image.bitmap.data[idx + 1] = limit255(value[1]!);
image.bitmap.data[idx + 2] = limit255(value[2]!);
image.bitmap.data[idx + 3] = limit255(value[3]!);
});

return image;
Expand Down

0 comments on commit 068cd03

Please sign in to comment.