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

« back to all changes in this revision

Viewing changes to app/core/gimpdrawable-convert.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
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 * Copyright (C) 1997-2004 Adam D. Moss <adam@gimp.org>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
#include "config.h"
 
21
 
 
22
#include <glib-object.h>
 
23
 
 
24
#include "libgimpcolor/gimpcolor.h"
 
25
 
 
26
#include "core-types.h"
 
27
 
 
28
#include "base/pixel-region.h"
 
29
#include "base/tile-manager.h"
 
30
 
 
31
#include "gimpdrawable.h"
 
32
#include "gimpdrawable-convert.h"
 
33
 
 
34
 
 
35
void
 
36
gimp_drawable_convert_rgb (GimpDrawable      *drawable,
 
37
                           TileManager       *new_tiles,
 
38
                           GimpImageBaseType  old_base_type)
 
39
{
 
40
  PixelRegion   srcPR, destPR;
 
41
  gint          row, col;
 
42
  gint          offset;
 
43
  gint          has_alpha;
 
44
  const guchar *src, *s;
 
45
  guchar       *dest, *d;
 
46
  const guchar *cmap;
 
47
  gpointer      pr;
 
48
 
 
49
  g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
 
50
  g_return_if_fail (new_tiles != NULL);
 
51
 
 
52
  has_alpha = gimp_drawable_has_alpha (drawable);
 
53
 
 
54
  g_return_if_fail (tile_manager_bpp (new_tiles) == (has_alpha ? 4 : 3));
 
55
 
 
56
  cmap = gimp_drawable_get_colormap (drawable);
 
57
 
 
58
  pixel_region_init (&srcPR, drawable->tiles,
 
59
                     0, 0,
 
60
                     GIMP_ITEM (drawable)->width,
 
61
                     GIMP_ITEM (drawable)->height,
 
62
                     FALSE);
 
63
  pixel_region_init (&destPR, new_tiles,
 
64
                     0, 0,
 
65
                     GIMP_ITEM (drawable)->width,
 
66
                     GIMP_ITEM (drawable)->height,
 
67
                     TRUE);
 
68
 
 
69
 
 
70
  switch (old_base_type)
 
71
    {
 
72
    case GIMP_GRAY:
 
73
      for (pr = pixel_regions_register (2, &srcPR, &destPR);
 
74
           pr != NULL;
 
75
           pr = pixel_regions_process (pr))
 
76
        {
 
77
          src  = srcPR.data;
 
78
          dest = destPR.data;
 
79
 
 
80
          for (row = 0; row < srcPR.h; row++)
 
81
            {
 
82
              s = src;
 
83
              d = dest;
 
84
 
 
85
              for (col = 0; col < srcPR.w; col++)
 
86
                {
 
87
                  d[RED_PIX] = *s;
 
88
                  d[GREEN_PIX] = *s;
 
89
                  d[BLUE_PIX] = *s;
 
90
 
 
91
                  d += 3;
 
92
                  s++;
 
93
                  if (has_alpha)
 
94
                    *d++ = *s++;
 
95
                }
 
96
 
 
97
              src += srcPR.rowstride;
 
98
              dest += destPR.rowstride;
 
99
            }
 
100
        }
 
101
      break;
 
102
 
 
103
    case GIMP_INDEXED:
 
104
      for (pr = pixel_regions_register (2, &srcPR, &destPR);
 
105
           pr != NULL;
 
106
           pr = pixel_regions_process (pr))
 
107
        {
 
108
          src  = srcPR.data;
 
109
          dest = destPR.data;
 
110
 
 
111
          for (row = 0; row < srcPR.h; row++)
 
112
            {
 
113
              s = src;
 
114
              d = dest;
 
115
 
 
116
              for (col = 0; col < srcPR.w; col++)
 
117
                {
 
118
                  offset = *s++ * 3;
 
119
                  d[RED_PIX] = cmap[offset + 0];
 
120
                  d[GREEN_PIX] = cmap[offset + 1];
 
121
                  d[BLUE_PIX] = cmap[offset + 2];
 
122
 
 
123
                  d += 3;
 
124
                  if (has_alpha)
 
125
                    *d++ = *s++;
 
126
                }
 
127
 
 
128
              src += srcPR.rowstride;
 
129
              dest += destPR.rowstride;
 
130
            }
 
131
        }
 
132
      break;
 
133
 
 
134
    default:
 
135
      break;
 
136
    }
 
137
}
 
138
 
 
139
void
 
140
gimp_drawable_convert_grayscale (GimpDrawable      *drawable,
 
141
                                 TileManager       *new_tiles,
 
142
                                 GimpImageBaseType  old_base_type)
 
143
{
 
144
  PixelRegion   srcPR, destPR;
 
145
  gint          row, col;
 
146
  gint          offset, val;
 
147
  gboolean      has_alpha;
 
148
  const guchar *src, *s;
 
149
  guchar       *dest, *d;
 
150
  const guchar *cmap;
 
151
  gpointer      pr;
 
152
 
 
153
  g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
 
154
  g_return_if_fail (new_tiles != NULL);
 
155
 
 
156
  has_alpha = gimp_drawable_has_alpha (drawable);
 
157
 
 
158
  g_return_if_fail (tile_manager_bpp (new_tiles) == (has_alpha ? 2 : 1));
 
159
 
 
160
  cmap = gimp_drawable_get_colormap (drawable);
 
161
 
 
162
  pixel_region_init (&srcPR, drawable->tiles,
 
163
                     0, 0,
 
164
                     GIMP_ITEM (drawable)->width,
 
165
                     GIMP_ITEM (drawable)->height,
 
166
                     FALSE);
 
167
  pixel_region_init (&destPR, new_tiles,
 
168
                     0, 0,
 
169
                     GIMP_ITEM (drawable)->width,
 
170
                     GIMP_ITEM (drawable)->height,
 
171
                     TRUE);
 
172
 
 
173
  switch (old_base_type)
 
174
    {
 
175
    case GIMP_RGB:
 
176
      for (pr = pixel_regions_register (2, &srcPR, &destPR);
 
177
           pr != NULL;
 
178
           pr = pixel_regions_process (pr))
 
179
        {
 
180
          src = srcPR.data;
 
181
          dest = destPR.data;
 
182
 
 
183
          for (row = 0; row < srcPR.h; row++)
 
184
            {
 
185
              s = src;
 
186
              d = dest;
 
187
              for (col = 0; col < srcPR.w; col++)
 
188
                {
 
189
                  val = GIMP_RGB_LUMINANCE (s[RED_PIX],
 
190
                                            s[GREEN_PIX],
 
191
                                            s[BLUE_PIX]) + 0.5;
 
192
                  *d++ = (guchar) val;
 
193
                  s += 3;
 
194
                  if (has_alpha)
 
195
                    *d++ = *s++;
 
196
                }
 
197
 
 
198
              src += srcPR.rowstride;
 
199
              dest += destPR.rowstride;
 
200
            }
 
201
        }
 
202
      break;
 
203
 
 
204
    case GIMP_INDEXED:
 
205
      for (pr = pixel_regions_register (2, &srcPR, &destPR);
 
206
           pr != NULL;
 
207
           pr = pixel_regions_process (pr))
 
208
        {
 
209
          src = srcPR.data;
 
210
          dest = destPR.data;
 
211
 
 
212
          for (row = 0; row < srcPR.h; row++)
 
213
            {
 
214
              s = src;
 
215
              d = dest;
 
216
 
 
217
              for (col = 0; col < srcPR.w; col++)
 
218
                {
 
219
                  offset = *s++ * 3;
 
220
                  val = GIMP_RGB_LUMINANCE (cmap[offset+0],
 
221
                                            cmap[offset+1],
 
222
                                            cmap[offset+2]) + 0.5;
 
223
                  *d++ = (guchar) val;
 
224
                  if (has_alpha)
 
225
                    *d++ = *s++;
 
226
                }
 
227
 
 
228
              src += srcPR.rowstride;
 
229
              dest += destPR.rowstride;
 
230
            }
 
231
        }
 
232
      break;
 
233
 
 
234
    default:
 
235
      break;
 
236
    }
 
237
}