2
// Copyright (C) 2009 Jason Smith, Robert Dyer
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, either version 3 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
22
namespace Docky.CairoHelper
24
public static class Util
27
/// Set a color to use a maximum value
29
/// <param name="gdk_color">
30
/// A <see cref="Gdk.Color"/>
32
/// <param name="max_value">
33
/// A <see cref="System.Double"/>
36
/// A <see cref="Gdk.Color"/>
38
public static Gdk.Color SetMinimumValue (this Gdk.Color gdk_color, double min_value)
43
r = (byte) ((gdk_color.Red) >> 8);
44
g = (byte) ((gdk_color.Green) >> 8);
45
b = (byte) ((gdk_color.Blue) >> 8);
47
RGBToHSV (r, g, b, out h, out s, out v);
48
v = Math.Max (v, min_value);
49
HSVToRGB (h, s, v, out r, out g, out b);
51
return new Gdk.Color (r, g, b);
54
public static void RGBToHSV (byte r, byte g, byte b,
55
out double hue, out double sat, out double val)
57
// Ported from Murrine Engine.
58
double red, green, blue;
68
max = Math.Max (red, Math.Max (blue, green));
69
min = Math.Min (red, Math.Min (blue, green));
71
val = max / 255.0 * 100.0;
73
if (Math.Abs (delta) < 0.0001) {
76
sat = (delta / max) * 100;
78
if (red == max) hue = (green - blue) / delta;
79
if (green == max) hue = 2 + (blue - red) / delta;
80
if (blue == max) hue = 4 + (red - green) / delta;
83
if (hue < 0) hue += 360;
87
public static void HSVToRGB (double hue, double sat, double val,
88
out byte red, out byte green, out byte blue)
91
double r = 0, g = 0, b = 0;
106
secNum = (int) Math.Floor(h / 60);
107
fracSec = h/60 - secNum;
110
q = v * (1 - s*fracSec);
111
t = v * (1 - s*(1 - fracSec));
146
red = Convert.ToByte(r*255);
147
green = Convert.ToByte(g*255);
148
blue = Convert.ToByte(b*255);