mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 10:48:38 -05:00
Simplify getAverageColor() loop.
This commit is contained in:
parent
8c96d91400
commit
98de3cbb2a
1 changed files with 5 additions and 6 deletions
|
@ -204,13 +204,12 @@ Raster = Item.extend({
|
|||
function getAverageColor(pixels) {
|
||||
var channels = [0, 0, 0];
|
||||
var total = 0;
|
||||
for (var i = 0, l = pixels.length / 4; i < l; i++) {
|
||||
var offset = i * 4;
|
||||
var alpha = pixels[offset + 3] / 255;
|
||||
for (var i = 0, l = pixels.length; i < l; i += 4) {
|
||||
var alpha = pixels[i + 3] / 255;
|
||||
total += alpha;
|
||||
channels[0] += pixels[offset] * alpha;
|
||||
channels[1] += pixels[offset + 1] * alpha;
|
||||
channels[2] += pixels[offset + 2] * alpha;
|
||||
channels[0] += pixels[i] * alpha;
|
||||
channels[1] += pixels[i + 1] * alpha;
|
||||
channels[2] += pixels[i + 2] * alpha;
|
||||
}
|
||||
for (var i = 0; i < 3; i++)
|
||||
channels[i] /= total * 255;
|
||||
|
|
Loading…
Reference in a new issue