blob: 515ad37f91e2a84eef6b7d4faaa45c6952ded854 [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/base/base.html">
<script>
'use strict';
/**
* @fileoverview Provides color scheme related functions.
*/
tr.exportTo('tr.ui.b', function() {
function boundChannel(v) {
return Math.min(255, Math.max(0, Math.floor(v)));
}
function brightenColor(c) {
var k;
if (c.r >= 240 && c.g >= 240 && c.b >= 240)
k = 0.80;
else
k = 1.45;
return {
r: boundChannel(c.r * k),
g: boundChannel(c.g * k),
b: boundChannel(c.b * k)
};
}
function desaturateColor(c) {
var value = boundChannel((c.r + c.g + c.b) / 3);
return { r: value, g: value, b: value };
}
function colorToRGBString(c) {
return 'rgb(' + c.r + ',' + c.g + ',' + c.b + ')';
}
function colorToRGBAString(c, a) {
return 'rgba(' + c.r + ',' + c.g + ',' + c.b + ',' + a + ')';
}
return {
brightenColor: brightenColor,
desaturateColor: desaturateColor,
colorToRGBString: colorToRGBString,
colorToRGBAString: colorToRGBAString
};
});
</script>