~ubuntu-branches/ubuntu/saucy/gimp/saucy-security

« back to all changes in this revision

Viewing changes to app/base/lut-funcs.c

  • Committer: Package Import Robot
  • Author(s): Micah Gersten
  • Date: 2012-05-20 19:21:01 UTC
  • mfrom: (1.1.26) (0.4.16 sid)
  • Revision ID: package-import@ubuntu.com-20120520192101-bs7zetx8ffoq2nfv
Tags: 2.8.0-2ubuntu1
* Merge from Debian unstable (LP: #908472). Remaining Changes:
  - debian/patches/02_help-message.patch,
    debian/patches/03_gimp.desktop.in.in.patch:
    + Update some strings for Ubuntu
  - debian/control:
    + Update description
  - debian/rules:
    + Set gettext domain and update translation templates
* Drop the following patches that were applied upstream:
  - debian/patches/ghost-cursor.patch: fix Wacom tablet cursor events
  - debian/patches/embed-page-setup-dialog.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
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.
8
8
 *
9
9
 * This program is distributed in the hope that it will be useful,
12
12
 * GNU General Public License for more details.
13
13
 *
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/>.
17
16
 */
18
17
 
19
18
#include "config.h"
288
287
typedef struct
289
288
{
290
289
  GimpHistogram *histogram;
291
 
  gint           part[5][257];
 
290
  gint           part[5][256];
292
291
} hist_lut_struct;
293
292
 
294
293
static gfloat
297
296
                   gint             channel,
298
297
                   gfloat           value)
299
298
{
300
 
  gint i = 0;
301
299
  gint j;
302
300
 
303
301
  /* don't equalize the alpha channel */
304
302
  if ((nchannels == 2 || nchannels == 4) && channel == nchannels - 1)
305
303
    return value;
306
304
 
307
 
  j = (gint) (value * 255.0 + 0.5);
308
 
 
309
 
  while (hlut->part[channel][i + 1] <= j)
310
 
    i++;
311
 
 
312
 
  return i / 255.0;
 
305
  j = RINT (CLAMP (value * 255.0, 0, 255));
 
306
 
 
307
  return hlut->part[channel][j] / 255.;
313
308
}
314
309
 
315
310
static void
317
312
                    GimpHistogram *hist,
318
313
                    gint           n_channels)
319
314
{
320
 
  gint            i, k, j;
 
315
  gint            i, k;
321
316
  hist_lut_struct hlut;
322
 
  gdouble         pixels_per_value;
323
 
  gdouble         desired;
324
 
  gdouble         sum, dif;
 
317
  gdouble         pixels;
325
318
 
326
319
  g_return_if_fail (lut != NULL);
327
320
  g_return_if_fail (hist != NULL);
328
321
 
329
322
  /* Find partition points */
330
 
  pixels_per_value = gimp_histogram_get_count (hist,
331
 
                                               GIMP_HISTOGRAM_VALUE,
332
 
                                               0, 255) / 256.0;
 
323
  pixels = gimp_histogram_get_count (hist, GIMP_HISTOGRAM_VALUE, 0, 255);
333
324
 
334
325
  for (k = 0; k < n_channels; k++)
335
326
    {
336
 
      /* First and last points in partition */
337
 
      hlut.part[k][0]   = 0;
338
 
      hlut.part[k][256] = 256;
339
 
 
340
 
      /* Find intermediate points */
341
 
      j   = 0;
342
 
      sum = (gimp_histogram_get_channel (hist, k, 0) +
343
 
             gimp_histogram_get_channel (hist, k, 1));
344
 
 
345
 
      for (i = 1; i < 256; i++)
 
327
      gdouble sum = 0;
 
328
 
 
329
      for (i = 0; i < 256; i++)
346
330
        {
347
 
          desired = i * pixels_per_value;
348
 
 
349
 
          while (sum < desired && j < 256)
350
 
            {
351
 
              j++;
352
 
              sum += gimp_histogram_get_channel (hist, k, j + 1);
353
 
            }
354
 
 
355
 
          /* Nearest sum */
356
 
          dif = sum - gimp_histogram_get_channel (hist, k, j);
357
 
 
358
 
          if ((sum - desired) > (dif / 2.0))
359
 
            hlut.part[k][i] = j;
360
 
          else
361
 
            hlut.part[k][i] = j + 1;
 
331
          gdouble histi = gimp_histogram_get_channel (hist, k, i);
 
332
 
 
333
          sum += histi;
 
334
 
 
335
          hlut.part[k][i] = RINT (sum * 255. / pixels);
362
336
        }
363
337
    }
364
338