~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/base/levels.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
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;
81
81
           channel++)
82
 
        levels_channel_stretch (levels, hist, channel);
 
82
        levels_channel_stretch (levels, hist, channel);
83
83
    }
84
84
  else
85
85
    {
115
115
      new_count = 0.0;
116
116
 
117
117
      for (i = 0; i < 255; i++)
118
 
        {
119
 
          new_count += gimp_histogram_get_value (hist, channel, i);
120
 
          percentage = new_count / count;
121
 
          next_percentage =
122
 
            (new_count + gimp_histogram_get_value (hist,
123
 
                                                   channel,
124
 
                                                   i + 1)) / count;
125
 
          if (fabs (percentage - 0.006) < fabs (next_percentage - 0.006))
126
 
            {
127
 
              levels->low_input[channel] = i + 1;
128
 
              break;
129
 
            }
130
 
        }
 
118
        {
 
119
          new_count += gimp_histogram_get_value (hist, channel, i);
 
120
          percentage = new_count / count;
 
121
          next_percentage =
 
122
            (new_count + gimp_histogram_get_value (hist,
 
123
                                                   channel,
 
124
                                                   i + 1)) / count;
 
125
          if (fabs (percentage - 0.006) < fabs (next_percentage - 0.006))
 
126
            {
 
127
              levels->low_input[channel] = i + 1;
 
128
              break;
 
129
            }
 
130
        }
131
131
      /*  Set the high input  */
132
132
      new_count = 0.0;
133
133
      for (i = 255; i > 0; i--)
134
 
        {
135
 
          new_count += gimp_histogram_get_value (hist, channel, i);
136
 
          percentage = new_count / count;
137
 
          next_percentage =
138
 
            (new_count + gimp_histogram_get_value (hist,
139
 
                                                   channel,
140
 
                                                   i - 1)) / count;
141
 
          if (fabs (percentage - 0.006) < fabs (next_percentage - 0.006))
142
 
            {
143
 
              levels->high_input[channel] = i - 1;
144
 
              break;
145
 
            }
146
 
        }
 
134
        {
 
135
          new_count += gimp_histogram_get_value (hist, channel, i);
 
136
          percentage = new_count / count;
 
137
          next_percentage =
 
138
            (new_count + gimp_histogram_get_value (hist,
 
139
                                                   channel,
 
140
                                                   i - 1)) / count;
 
141
          if (fabs (percentage - 0.006) < fabs (next_percentage - 0.006))
 
142
            {
 
143
              levels->high_input[channel] = i - 1;
 
144
              break;
 
145
            }
 
146
        }
147
147
    }
148
148
}
149
149
 
150
150
static gint
151
151
levels_input_from_color (GimpHistogramChannel  channel,
152
 
                         guchar               *color)
 
152
                         guchar               *color)
153
153
{
154
154
  switch (channel)
155
155
    {
194
194
      guchar lightness;
195
195
 
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]);
198
198
 
199
199
      input = levels_input_from_color (channel, gray);
200
200
 
201
201
      range = levels->high_input[channel] - levels->low_input[channel];
202
202
      if (range <= 0)
203
 
        return;
 
203
        return;
204
204
 
205
205
      input -= levels->low_input[channel];
206
206
      if (input < 0)
207
 
        return;
 
207
        return;
208
208
 
209
209
      /* Normalize input and lightness */
210
210
      inten = (gdouble) input / (gdouble) range;
230
230
  for (j = 0; j < 5; j++)
231
231
    {
232
232
      for (i = 0; i < 256; i++)
233
 
        {
234
 
          /*  determine input intensity  */
235
 
          if (levels->high_input[j] != levels->low_input[j])
 
233
        {
 
234
          /*  determine input intensity  */
 
235
          if (levels->high_input[j] != levels->low_input[j])
236
236
            {
237
237
              inten = ((gdouble) (i - levels->low_input[j]) /
238
238
                       (double) (levels->high_input[j] - levels->low_input[j]));
239
239
            }
240
 
          else
 
240
          else
241
241
            {
242
242
              inten = (gdouble) (i - levels->low_input[j]);
243
243
            }
244
244
 
245
 
          inten = CLAMP (inten, 0.0, 1.0);
246
 
 
247
 
          if (levels->gamma[j] != 0.0)
248
 
            inten = pow (inten, (1.0 / levels->gamma[j]));
249
 
 
250
 
          levels->input[j][i] = (guchar) (inten * 255.0 + 0.5);
251
 
        }
 
245
          inten = CLAMP (inten, 0.0, 1.0);
 
246
 
 
247
          if (levels->gamma[j] != 0.0)
 
248
            inten = pow (inten, (1.0 / levels->gamma[j]));
 
249
 
 
250
          levels->input[j][i] = (guchar) (inten * 255.0 + 0.5);
 
251
        }
252
252
    }
253
253
}
254
254
 
255
255
gfloat
256
256
levels_lut_func (Levels *levels,
257
 
                 gint    n_channels,
258
 
                 gint    channel,
259
 
                 gfloat  value)
 
257
                 gint    n_channels,
 
258
                 gint    channel,
 
259
                 gfloat  value)
260
260
{
261
261
  gdouble inten;
262
262
  gint    j;
278
278
    {
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)
282
 
        return inten;
 
281
          channel == n_channels - 1)
 
282
        return inten;
283
283
 
284
284
      /*  determine input intensity  */
285
285
      if (levels->high_input[j] != levels->low_input[j])
293
293
        }
294
294
 
295
295
      if (levels->gamma[j] != 0.0)
296
 
        {
297
 
          if (inten >= 0.0)
298
 
            inten =  pow ( inten, (1.0 / levels->gamma[j]));
299
 
          else
300
 
            inten = -pow (-inten, (1.0 / levels->gamma[j]));
301
 
        }
 
296
        {
 
297
          if (inten >= 0.0)
 
298
            inten =  pow ( inten, (1.0 / levels->gamma[j]));
 
299
          else
 
300
            inten = -pow (-inten, (1.0 / levels->gamma[j]));
 
301
        }
302
302
 
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]));
311
311
 
312
312
      inten /= 255.0;
313
313
    }