1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
6
* Copyright (C) 2012 The Free Software Foundation, Inc.
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include "color-utils.h"
24
#include "glib-utils.h"
31
gimp_rgb_to_hsv (guchar red,
40
min = MIN3 (red, green, blue);
41
max = MAX3 (red, green, blue);
49
*sat = 255 * (long)(max - min) / *val;
58
*hue = 0 + 43 * (green - blue) / (max - min);
59
else if (max == green)
60
*hue = 85 + 43 * (blue - red) / (max - min);
62
*hue = 171 + 43 * (red - green) / (max - min);
67
gimp_hsv_to_rgb (guchar hue,
74
guchar region, remainder, p, q, t;
77
*red = *green = *blue = val;
82
remainder = (hue - (region * 43)) * 6;
84
p = (val * (255 - sat)) >> 8;
85
q = (val * (255 - ((sat * remainder) >> 8))) >> 8;
86
t = (val * (255 - ((sat * (255 - remainder)) >> 8))) >> 8;
127
gimp_rgb_to_hsl (guchar red,
136
min = MIN3 (red, green, blue);
137
max = MAX3 (red, green, blue);
139
*lum = (max + min) / 2;
147
*sat = 255 * (long) (max - min) / (max + min);
149
*sat = 255 * (long) (max - min) / (512 - max - min);
154
*hue = 0 + 43 * (green - blue) / (max - min);
155
else if (max == green)
156
*hue = 85 + 43 * (blue - red) / (max - min);
157
else if (max == blue)
158
*hue = 171 + 43 * (red - green) / (max - min);
163
gimp_hsl_value (gdouble n1,
175
value = n1 + (n2 - n1) * (hue / 42.5);
176
else if (hue < 127.5)
179
value = n1 + (n2 - n1) * ((170 - hue) / 42.5);
183
return value * 255.0;
188
gimp_hsl_to_rgb (guchar hue,
201
gdouble h, s, l, m1, m2;
208
m2 = (l * (255 + s)) / 65025.0;
210
m2 = (l + s - (l * s) / 255.0) / 255.0;
212
m1 = (l / 127.5) - m2;
214
*red = gimp_hsl_value (m1, m2, h + 85);
215
*green = gimp_hsl_value (m1, m2, h);
216
*blue = gimp_hsl_value (m1, m2, h - 85);