Nov 15, 2020
Some advice, learn binary math. If nothing else these values are 0..255 for a reason.
Where you have:
(pixel[0] + Math.floor((left[0] + up[0]) / 2)) % 256
You should probably have:
(pixel[0] + ((left[0] + up[0]) >> 1)) & 0xFF
Binary math is always faster than floating point, and lets you skip the Math.floor