mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Simplify calculation of total in getAverageColor().
This commit is contained in:
parent
98de3cbb2a
commit
8cb3efb28e
1 changed files with 3 additions and 2 deletions
|
@ -205,14 +205,15 @@ Raster = Item.extend({
|
|||
var channels = [0, 0, 0];
|
||||
var total = 0;
|
||||
for (var i = 0, l = pixels.length; i < l; i += 4) {
|
||||
var alpha = pixels[i + 3] / 255;
|
||||
var alpha = pixels[i + 3];
|
||||
total += alpha;
|
||||
alpha /= 255;
|
||||
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;
|
||||
channels[i] /= total;
|
||||
return total ? Color.read(channels) : null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue