Skip to content

Commit 068cd03

Browse files
Fix pixelate not working well with alpha channel (#1314)
1 parent a425b4c commit 068cd03

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

plugins/plugin-color/src/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function applyKernel(
6464
x: number,
6565
y: number
6666
) {
67-
const value = [0, 0, 0] as [number, number, number];
67+
const value = [0, 0, 0, 0] as [number, number, number, number];
6868
const size = (kernel.length - 1) / 2;
6969

7070
for (let kx = 0; kx < kernel.length; kx += 1) {
@@ -74,6 +74,7 @@ function applyKernel(
7474
value[0] += image.bitmap.data[idx]! * kernel[kx]![ky]!;
7575
value[1] += image.bitmap.data[idx + 1]! * kernel[kx]![ky]!;
7676
value[2] += image.bitmap.data[idx + 2]! * kernel[kx]![ky]!;
77+
value[3] += image.bitmap.data[idx + 3]! * kernel[kx]![ky]!;
7778
}
7879
}
7980

@@ -718,6 +719,7 @@ export const methods = {
718719
image.bitmap.data[idx] = value[0]!;
719720
image.bitmap.data[idx + 1] = value[1]!;
720721
image.bitmap.data[idx + 2] = value[2]!;
722+
image.bitmap.data[idx + 3] = value[3]!;
721723
});
722724

723725
return image;
@@ -766,6 +768,7 @@ export const methods = {
766768
image.bitmap.data[idx] = limit255(value[0]!);
767769
image.bitmap.data[idx + 1] = limit255(value[1]!);
768770
image.bitmap.data[idx + 2] = limit255(value[2]!);
771+
image.bitmap.data[idx + 3] = limit255(value[3]!);
769772
});
770773

771774
return image;

0 commit comments

Comments
 (0)