Lomiri
Loading...
Searching...
No Matches
Style.js
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17.pragma library
18
19/*! \brief Calculate average luminance of the passed colors
20
21 \note If not fully opaque, luminance is dependant on blending.
22 */
23function luminance() {
24 var sum = 0;
25 // TODO this was originally
26 // for (var k in arguments) {
27 // but for some unkown reason was causing crashes in testDash/testDashContent
28 // investigate when we have some time
29 for (var k = 0; k < arguments.length; ++k) {
30 // only way to convert string to color
31 var c = Qt.lighter(arguments[k], 1.0);
32
33 sum += 0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b;
34 }
35
36 return sum / arguments.length;
37}