Created
December 11, 2017 15:55
-
-
Save ramsaylanier/d4af90d38d093400e32e864d4fa4903b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| onmessage = function (e) { | |
| const data = e.data | |
| const length = data.data.length | |
| const BLOCKSIZE = 5 | |
| const STEPS = 4 | |
| let i = -4 | |
| let count = 0 | |
| let rgb = {r: 0, g: 0, b: 0} | |
| while ((i += BLOCKSIZE * STEPS) < length) { | |
| ++count | |
| rgb.r += data.data[i] | |
| rgb.g += data.data[i + 1] | |
| rgb.b += data.data[i + 2] | |
| } | |
| // ~~ used to floor values | |
| rgb.r = ~~(rgb.r / count) | |
| rgb.g = ~~(rgb.g / count) | |
| rgb.b = ~~(rgb.b / count) | |
| postMessage(rgb) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment