Jason Knight
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

--

--

Jason Knight
Jason Knight

Written by Jason Knight

Accessibility and Efficiency Consultant, Web Developer, Musician, and just general pain in the arse

Responses (1)