File indexing completed on 2024-05-12 17:04:39
0001 /* 0002 * Copyright 2018 Michail Vourlakos <mvourlakos@gmail.com> 0003 * 0004 * This file is part of Latte-Dock 0005 * 0006 * Latte-Dock is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * Latte-Dock is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 0021 function colorBrightness(color) { 0022 return colorBrightnessFromRGB(color.r * 255, color.g * 255, color.b * 255) 0023 } 0024 0025 // formula for brightness according to: 0026 // https://www.w3.org/TR/AERT/#color-contrast 0027 function colorBrightnessFromRGB(r, g, b) { 0028 return (r * 299 + g * 587 + b * 114) / 1000 0029 } 0030 0031 function colorLuminas(color) { 0032 return colorLuminasFromRGB(color.r, color.g, color.b) 0033 } 0034 0035 // formula for luminance according to: 0036 // https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef 0037 function colorLuminasFromRGB(r, g, b) { 0038 var rS = (r <= 0.03928) ? ( r / 12.92) : Math.pow( ((r + 0.055) / 1.055), 2.4 ); 0039 var gS = (g <= 0.03928) ? ( g / 12.92) : Math.pow( ((g + 0.055) / 1.055), 2.4 ); 0040 var bS = (b <= 0.03928) ? ( b / 12.92) : Math.pow( ((b + 0.055) / 1.055), 2.4 ); 0041 0042 return 0.2126*rS + 0.7152*gS + 0.0722*bS; 0043 } 0044 0045 0046 function normalize(min, max, per) { 0047 return min + ((max-min) * per); 0048 }