1
/* The GIMP -- an image manipulation program
1
/* GIMP - The GNU Image Manipulation Program
2
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
4
* This program is free software; you can redistribute it and/or modify
79
79
for (channel = GIMP_HISTOGRAM_RED;
80
80
channel <= GIMP_HISTOGRAM_BLUE;
82
levels_channel_stretch (levels, hist, channel);
82
levels_channel_stretch (levels, hist, channel);
117
117
for (i = 0; i < 255; i++)
119
new_count += gimp_histogram_get_value (hist, channel, i);
120
percentage = new_count / count;
122
(new_count + gimp_histogram_get_value (hist,
125
if (fabs (percentage - 0.006) < fabs (next_percentage - 0.006))
127
levels->low_input[channel] = i + 1;
119
new_count += gimp_histogram_get_value (hist, channel, i);
120
percentage = new_count / count;
122
(new_count + gimp_histogram_get_value (hist,
125
if (fabs (percentage - 0.006) < fabs (next_percentage - 0.006))
127
levels->low_input[channel] = i + 1;
131
131
/* Set the high input */
133
133
for (i = 255; i > 0; i--)
135
new_count += gimp_histogram_get_value (hist, channel, i);
136
percentage = new_count / count;
138
(new_count + gimp_histogram_get_value (hist,
141
if (fabs (percentage - 0.006) < fabs (next_percentage - 0.006))
143
levels->high_input[channel] = i - 1;
135
new_count += gimp_histogram_get_value (hist, channel, i);
136
percentage = new_count / count;
138
(new_count + gimp_histogram_get_value (hist,
141
if (fabs (percentage - 0.006) < fabs (next_percentage - 0.006))
143
levels->high_input[channel] = i - 1;
151
151
levels_input_from_color (GimpHistogramChannel channel,
194
194
guchar lightness;
196
196
/* Calculate lightness value */
197
lightness = GIMP_RGB_INTENSITY (gray[0], gray[1], gray[2]);
197
lightness = GIMP_RGB_LUMINANCE (gray[0], gray[1], gray[2]);
199
199
input = levels_input_from_color (channel, gray);
201
201
range = levels->high_input[channel] - levels->low_input[channel];
205
205
input -= levels->low_input[channel];
209
209
/* Normalize input and lightness */
210
210
inten = (gdouble) input / (gdouble) range;
230
230
for (j = 0; j < 5; j++)
232
232
for (i = 0; i < 256; i++)
234
/* determine input intensity */
235
if (levels->high_input[j] != levels->low_input[j])
234
/* determine input intensity */
235
if (levels->high_input[j] != levels->low_input[j])
237
237
inten = ((gdouble) (i - levels->low_input[j]) /
238
238
(double) (levels->high_input[j] - levels->low_input[j]));
242
242
inten = (gdouble) (i - levels->low_input[j]);
245
inten = CLAMP (inten, 0.0, 1.0);
247
if (levels->gamma[j] != 0.0)
248
inten = pow (inten, (1.0 / levels->gamma[j]));
250
levels->input[j][i] = (guchar) (inten * 255.0 + 0.5);
245
inten = CLAMP (inten, 0.0, 1.0);
247
if (levels->gamma[j] != 0.0)
248
inten = pow (inten, (1.0 / levels->gamma[j]));
250
levels->input[j][i] = (guchar) (inten * 255.0 + 0.5);
256
256
levels_lut_func (Levels *levels,
279
279
/* don't apply the overall curve to the alpha channel */
280
280
if (j == 0 && (n_channels == 2 || n_channels == 4) &&
281
channel == n_channels - 1)
281
channel == n_channels - 1)
284
284
/* determine input intensity */
285
285
if (levels->high_input[j] != levels->low_input[j])
295
295
if (levels->gamma[j] != 0.0)
298
inten = pow ( inten, (1.0 / levels->gamma[j]));
300
inten = -pow (-inten, (1.0 / levels->gamma[j]));
298
inten = pow ( inten, (1.0 / levels->gamma[j]));
300
inten = -pow (-inten, (1.0 / levels->gamma[j]));
303
303
/* determine the output intensity */
304
304
if (levels->high_output[j] >= levels->low_output[j])
305
inten = (gdouble) (inten * (levels->high_output[j] -
305
inten = (gdouble) (inten * (levels->high_output[j] -
306
306
levels->low_output[j]) +
307
levels->low_output[j]);
307
levels->low_output[j]);
308
308
else if (levels->high_output[j] < levels->low_output[j])
309
inten = (gdouble) (levels->low_output[j] - inten *
310
(levels->low_output[j] - levels->high_output[j]));
309
inten = (gdouble) (levels->low_output[j] - inten *
310
(levels->low_output[j] - levels->high_output[j]));