64
65
for (hue = 0; hue < 6; hue++)
65
66
for (i = 0; i < 256; i++)
67
value = (hs->hue[0] + hs->hue[hue + 1]) * 255.0 / 360.0;
69
hs->hue_transfer[hue][i] = 255 + (i + value);
70
else if ((i + value) > 255)
71
hs->hue_transfer[hue][i] = i + value - 255;
73
hs->hue_transfer[hue][i] = i + value;
76
value = (hs->lightness[0] + hs->lightness[hue + 1]) * 127.0 / 100.0;
77
value = CLAMP (value, -255, 255);
80
hs->lightness_transfer[hue][i] = (guchar) ((i * (255 + value)) / 255);
82
hs->lightness_transfer[hue][i] = (guchar) (i + ((255 - i) * value) / 255);
85
value = (hs->saturation[0] + hs->saturation[hue + 1]) * 255.0 / 100.0;
86
value = CLAMP (value, -255, 255);
88
/* This change affects the way saturation is computed. With the
89
old code (different code for value < 0), increasing the
90
saturation affected muted colors very much, and bright colors
91
less. With the new code, it affects muted colors and bright
92
colors more or less evenly. For enhancing the color in photos,
93
the new behavior is exactly what you want. It's hard for me
94
to imagine a case in which the old behavior is better.
96
hs->saturation_transfer[hue][i] = CLAMP ((i * (255 + value)) / 255, 0, 255);
68
value = (hs->hue[0] + hs->hue[hue + 1]) * 255.0 / 360.0;
70
hs->hue_transfer[hue][i] = 255 + (i + value);
71
else if ((i + value) > 255)
72
hs->hue_transfer[hue][i] = i + value - 255;
74
hs->hue_transfer[hue][i] = i + value;
77
value = (hs->lightness[0] + hs->lightness[hue + 1]) * 127.0 / 100.0;
78
value = CLAMP (value, -255, 255);
81
hs->lightness_transfer[hue][i] = (guchar) ((i * (255 + value)) / 255);
83
hs->lightness_transfer[hue][i] = (guchar) (i + ((255 - i) * value) / 255);
86
value = (hs->saturation[0] + hs->saturation[hue + 1]) * 255.0 / 100.0;
87
value = CLAMP (value, -255, 255);
89
/* This change affects the way saturation is computed. With the
90
old code (different code for value < 0), increasing the
91
saturation affected muted colors very much, and bright colors
92
less. With the new code, it affects muted colors and bright
93
colors more or less evenly. For enhancing the color in photos,
94
the new behavior is exactly what you want. It's hard for me
95
to imagine a case in which the old behavior is better.
97
hs->saturation_transfer[hue][i] = CLAMP ((i * (255 + value)) / 255, 0, 255);
101
hue_saturation (PixelRegion *srcPR,
102
hue_saturation (HueSaturation *hs,
106
const guchar *src, *s;
108
const gint hue_thresholds[] = { 21, 64, 106, 149, 192, 234, 255 };
114
gint secondary_hue = 0;
115
gboolean use_secondary_hue = FALSE;
116
gfloat primary_intensity = 0.0;
117
gfloat secondary_intensity = 0.0;
118
gfloat overlap_hue = (hs->overlap / 100.0) * 21;
112
120
/* Set the transfer arrays (for speed) */
130
gimp_rgb_to_hsl_int (&r, &g, &b);
138
gimp_rgb_to_hsl_int (&r, &g, &b);
132
140
hue = (r + (128 / 6)) / 6;
142
for (hue_counter = 0; hue_counter < 7; hue_counter++)
143
if (r < hue_thresholds[hue_counter] + overlap_hue)
145
gint hue_threshold = hue_thresholds[hue_counter];
149
if (overlap_hue > 1.0 && r > hue_threshold - overlap_hue)
151
secondary_hue = hue_counter + 1;
152
use_secondary_hue = TRUE;
153
secondary_intensity =
154
(r - hue_threshold + overlap_hue) / (2.0 * overlap_hue);
155
primary_intensity = 1.0 - secondary_intensity;
159
use_secondary_hue = FALSE;
167
use_secondary_hue = FALSE;
170
if (secondary_hue >= 6)
173
if (use_secondary_hue)
175
r = hs->hue_transfer[hue][r] * primary_intensity +
176
hs->hue_transfer[secondary_hue][r] * secondary_intensity;
177
g = hs->saturation_transfer[hue][g] * primary_intensity +
178
hs->saturation_transfer[secondary_hue][g] * secondary_intensity;
179
b = hs->lightness_transfer[hue][b] * primary_intensity +
180
hs->lightness_transfer[secondary_hue][b] * secondary_intensity;
149
r = hs->hue_transfer[hue][r];
150
g = hs->saturation_transfer[hue][g];
151
b = hs->lightness_transfer[hue][b];
153
gimp_hsl_to_rgb_int (&r, &g, &b);
160
d[ALPHA_PIX] = s[ALPHA_PIX];
184
r = hs->hue_transfer[hue][r];
185
g = hs->saturation_transfer[hue][g];
186
b = hs->lightness_transfer[hue][b];
189
gimp_hsl_to_rgb_int (&r, &g, &b);
196
d[ALPHA_PIX] = s[ALPHA_PIX];
166
202
src += srcPR->rowstride;
167
203
dest += destPR->rowstride;