1
1
/* GIMP - The GNU Image Manipulation Program
2
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
4
* This program is free software: you can redistribute it and/or modify
5
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
6
* the Free Software Foundation; either version 3 of the License, or
7
7
* (at your option) any later version.
9
9
* This program is distributed in the hope that it will be useful,
12
12
* GNU General Public License for more details.
14
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
18
#include "config.h"
303
301
/* don't equalize the alpha channel */
304
302
if ((nchannels == 2 || nchannels == 4) && channel == nchannels - 1)
307
j = (gint) (value * 255.0 + 0.5);
309
while (hlut->part[channel][i + 1] <= j)
305
j = RINT (CLAMP (value * 255.0, 0, 255));
307
return hlut->part[channel][j] / 255.;
317
312
GimpHistogram *hist,
321
316
hist_lut_struct hlut;
322
gdouble pixels_per_value;
326
319
g_return_if_fail (lut != NULL);
327
320
g_return_if_fail (hist != NULL);
329
322
/* Find partition points */
330
pixels_per_value = gimp_histogram_get_count (hist,
331
GIMP_HISTOGRAM_VALUE,
323
pixels = gimp_histogram_get_count (hist, GIMP_HISTOGRAM_VALUE, 0, 255);
334
325
for (k = 0; k < n_channels; k++)
336
/* First and last points in partition */
338
hlut.part[k][256] = 256;
340
/* Find intermediate points */
342
sum = (gimp_histogram_get_channel (hist, k, 0) +
343
gimp_histogram_get_channel (hist, k, 1));
345
for (i = 1; i < 256; i++)
329
for (i = 0; i < 256; i++)
347
desired = i * pixels_per_value;
349
while (sum < desired && j < 256)
352
sum += gimp_histogram_get_channel (hist, k, j + 1);
356
dif = sum - gimp_histogram_get_channel (hist, k, j);
358
if ((sum - desired) > (dif / 2.0))
361
hlut.part[k][i] = j + 1;
331
gdouble histi = gimp_histogram_get_channel (hist, k, i);
335
hlut.part[k][i] = RINT (sum * 255. / pixels);