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

« back to all changes in this revision

Viewing changes to app/base/hue-saturation.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
36
36
 
37
37
  g_return_if_fail (hs != NULL);
38
38
 
 
39
  hs->overlap = 0.0;
39
40
  for (partition = GIMP_ALL_HUES; partition <= GIMP_MAGENTA_HUES; partition++)
40
41
    hue_saturation_partition_reset (hs, partition);
41
42
}
64
65
  for (hue = 0; hue < 6; hue++)
65
66
    for (i = 0; i < 256; i++)
66
67
      {
67
 
        value = (hs->hue[0] + hs->hue[hue + 1]) * 255.0 / 360.0;
68
 
        if ((i + value) < 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;
72
 
        else
73
 
          hs->hue_transfer[hue][i] = i + value;
74
 
 
75
 
        /*  Lightness  */
76
 
        value = (hs->lightness[0] + hs->lightness[hue + 1]) * 127.0 / 100.0;
77
 
        value = CLAMP (value, -255, 255);
78
 
 
79
 
        if (value < 0)
80
 
          hs->lightness_transfer[hue][i] = (guchar) ((i * (255 + value)) / 255);
81
 
        else
82
 
          hs->lightness_transfer[hue][i] = (guchar) (i + ((255 - i) * value) / 255);
83
 
 
84
 
        /*  Saturation  */
85
 
        value = (hs->saturation[0] + hs->saturation[hue + 1]) * 255.0 / 100.0;
86
 
        value = CLAMP (value, -255, 255);
87
 
 
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.
95
 
         */
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;
 
69
        if ((i + value) < 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;
 
73
        else
 
74
          hs->hue_transfer[hue][i] = i + value;
 
75
 
 
76
        /*  Lightness  */
 
77
        value = (hs->lightness[0] + hs->lightness[hue + 1]) * 127.0 / 100.0;
 
78
        value = CLAMP (value, -255, 255);
 
79
 
 
80
        if (value < 0)
 
81
          hs->lightness_transfer[hue][i] = (guchar) ((i * (255 + value)) / 255);
 
82
        else
 
83
          hs->lightness_transfer[hue][i] = (guchar) (i + ((255 - i) * value) / 255);
 
84
 
 
85
        /*  Saturation  */
 
86
        value = (hs->saturation[0] + hs->saturation[hue + 1]) * 255.0 / 100.0;
 
87
        value = CLAMP (value, -255, 255);
 
88
 
 
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.
 
96
         */
 
97
        hs->saturation_transfer[hue][i] = CLAMP ((i * (255 + value)) / 255, 0, 255);
97
98
      }
98
99
}
99
100
 
100
101
void
101
 
hue_saturation (PixelRegion   *srcPR,
102
 
                PixelRegion   *destPR,
103
 
                HueSaturation *hs)
 
102
hue_saturation (HueSaturation *hs,
 
103
                PixelRegion   *srcPR,
 
104
                PixelRegion   *destPR)
104
105
{
105
 
  guchar *src, *s;
106
 
  guchar *dest, *d;
107
 
  gint    alpha;
108
 
  gint    w, h;
109
 
  gint    r, g, b;
110
 
  gint    hue;
 
106
  const guchar *src, *s;
 
107
  guchar       *dest, *d;
 
108
  const gint    hue_thresholds[]    = { 21, 64, 106, 149, 192, 234, 255 };
 
109
  gint          alpha;
 
110
  gint          w, h;
 
111
  gint          r, g, b;
 
112
  gint          hue;
 
113
  gint          hue_counter;
 
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;
111
119
 
112
120
  /*  Set the transfer arrays  (for speed)  */
113
121
  h     = srcPR->h;
122
130
      d = dest;
123
131
 
124
132
      while (w--)
125
 
        {
126
 
          r = s[RED_PIX];
127
 
          g = s[GREEN_PIX];
128
 
          b = s[BLUE_PIX];
 
133
        {
 
134
          r = s[RED_PIX];
 
135
          g = s[GREEN_PIX];
 
136
          b = s[BLUE_PIX];
129
137
 
130
 
          gimp_rgb_to_hsl_int (&r, &g, &b);
 
138
          gimp_rgb_to_hsl_int (&r, &g, &b);
131
139
 
132
140
          hue = (r + (128 / 6)) / 6;
133
141
 
134
 
          if (r < 21)
135
 
            hue = 0;
136
 
          else if (r < 64)
137
 
            hue = 1;
138
 
          else if (r < 106)
139
 
            hue = 2;
140
 
          else if (r < 149)
141
 
            hue = 3;
142
 
          else if (r < 192)
143
 
            hue = 4;
144
 
          else if (r < 234)
145
 
            hue = 5;
 
142
          for (hue_counter = 0; hue_counter < 7; hue_counter++)
 
143
            if (r < hue_thresholds[hue_counter] + overlap_hue)
 
144
              {
 
145
                gint  hue_threshold = hue_thresholds[hue_counter];
 
146
 
 
147
                hue = hue_counter;
 
148
 
 
149
                if (overlap_hue > 1.0 && r > hue_threshold - overlap_hue)
 
150
                  {
 
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;
 
156
                  }
 
157
                else
 
158
                  {
 
159
                    use_secondary_hue = FALSE;
 
160
                  }
 
161
                break;
 
162
              }
 
163
 
 
164
          if (hue >= 6)
 
165
            {
 
166
              hue = 0;
 
167
              use_secondary_hue = FALSE;
 
168
            }
 
169
 
 
170
          if (secondary_hue >= 6)
 
171
            secondary_hue = 0;
 
172
 
 
173
          if (use_secondary_hue)
 
174
            {
 
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;
 
181
            }
146
182
          else
147
 
            hue = 0;
148
 
 
149
 
          r = hs->hue_transfer[hue][r];
150
 
          g = hs->saturation_transfer[hue][g];
151
 
          b = hs->lightness_transfer[hue][b];
152
 
 
153
 
          gimp_hsl_to_rgb_int (&r, &g, &b);
154
 
 
155
 
          d[RED_PIX]   = r;
156
 
          d[GREEN_PIX] = g;
157
 
          d[BLUE_PIX]  = b;
158
 
 
159
 
          if (alpha)
160
 
            d[ALPHA_PIX] = s[ALPHA_PIX];
161
 
 
162
 
          s += srcPR->bytes;
163
 
          d += destPR->bytes;
164
 
        }
 
183
            {
 
184
              r = hs->hue_transfer[hue][r];
 
185
              g = hs->saturation_transfer[hue][g];
 
186
              b = hs->lightness_transfer[hue][b];
 
187
            }
 
188
 
 
189
          gimp_hsl_to_rgb_int (&r, &g, &b);
 
190
 
 
191
          d[RED_PIX]   = r;
 
192
          d[GREEN_PIX] = g;
 
193
          d[BLUE_PIX]  = b;
 
194
 
 
195
          if (alpha)
 
196
            d[ALPHA_PIX] = s[ALPHA_PIX];
 
197
 
 
198
          s += srcPR->bytes;
 
199
          d += destPR->bytes;
 
200
        }
165
201
 
166
202
      src  += srcPR->rowstride;
167
203
      dest += destPR->rowstride;