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

« back to all changes in this revision

Viewing changes to libgimp/gimppixbuf.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:
22
22
 
23
23
#include "config.h"
24
24
 
 
25
#include <string.h>
 
26
 
25
27
#include <gdk-pixbuf/gdk-pixbuf.h>
26
28
 
27
29
#include "gimp.h"
39
41
/**
40
42
 * gimp_image_get_thumbnail:
41
43
 * @image_ID: the image ID
42
 
 * @width:    the requested thumbnail width  (<= 512 pixels)
43
 
 * @height:   the requested thumbnail height (<= 512 pixels)
 
44
 * @width:    the requested thumbnail width  (<= 1024 pixels)
 
45
 * @height:   the requested thumbnail height (<= 1024 pixels)
44
46
 * @alpha:    how to handle an alpha channel
45
47
 *
46
48
 * Retrieves a thumbnail pixbuf for the image identified by @image_ID.
61
63
  gint    thumb_bpp;
62
64
  guchar *data;
63
65
 
64
 
  g_return_val_if_fail (width  > 0 && width  <= 512, NULL);
65
 
  g_return_val_if_fail (height > 0 && height <= 512, NULL);
 
66
  g_return_val_if_fail (width  > 0 && width  <= 1024, NULL);
 
67
  g_return_val_if_fail (height > 0 && height <= 1024, NULL);
66
68
 
67
69
  data = gimp_image_get_thumbnail_data (image_ID,
68
70
                                        &thumb_width,
79
81
/**
80
82
 * gimp_drawable_get_thumbnail:
81
83
 * @drawable_ID: the drawable ID
82
 
 * @width:       the requested thumbnail width  (<= 512 pixels)
83
 
 * @height:      the requested thumbnail height (<= 512 pixels)
 
84
 * @width:       the requested thumbnail width  (<= 1024 pixels)
 
85
 * @height:      the requested thumbnail height (<= 1024 pixels)
84
86
 * @alpha:       how to handle an alpha channel
85
87
 *
86
88
 * Retrieves a thumbnail pixbuf for the drawable identified by
102
104
  gint    thumb_bpp;
103
105
  guchar *data;
104
106
 
105
 
  g_return_val_if_fail (width  > 0 && width  <= 512, NULL);
106
 
  g_return_val_if_fail (height > 0 && height <= 512, NULL);
 
107
  g_return_val_if_fail (width  > 0 && width  <= 1024, NULL);
 
108
  g_return_val_if_fail (height > 0 && height <= 1024, NULL);
107
109
 
108
110
  data = gimp_drawable_get_thumbnail_data (drawable_ID,
109
111
                                           &thumb_width,
125
127
 * @src_y:       the y coordinate of the area
126
128
 * @src_width:   the width of the area
127
129
 * @src_height:  the height of the area
128
 
 * @dest_width:  the requested thumbnail width  (<= 512 pixels)
129
 
 * @dest_height: the requested thumbnail height (<= 512 pixels)
 
130
 * @dest_width:  the requested thumbnail width  (<= 1024 pixels)
 
131
 * @dest_height: the requested thumbnail height (<= 1024 pixels)
130
132
 * @alpha:       how to handle an alpha channel
131
133
 *
132
134
 * Retrieves a thumbnail pixbuf for the drawable identified by
156
158
  g_return_val_if_fail (src_y >= 0, NULL);
157
159
  g_return_val_if_fail (src_width  > 0, NULL);
158
160
  g_return_val_if_fail (src_height > 0, NULL);
159
 
  g_return_val_if_fail (dest_width  > 0 && dest_width  <= 512, NULL);
160
 
  g_return_val_if_fail (dest_height > 0 && dest_height <= 512, NULL);
 
161
  g_return_val_if_fail (dest_width  > 0 && dest_width  <= 1024, NULL);
 
162
  g_return_val_if_fail (dest_height > 0 && dest_height <= 1024, NULL);
161
163
 
162
164
  data = gimp_drawable_get_sub_thumbnail_data (drawable_ID,
163
165
                                               src_x, src_y,
174
176
  return NULL;
175
177
}
176
178
 
 
179
/**
 
180
 * gimp_layer_new_from_pixbuf:
 
181
 * @image_ID: The RGB image to which to add the layer.
 
182
 * @name: The layer name.
 
183
 * @pixbuf: A GdkPixbuf.
 
184
 * @opacity: The layer opacity.
 
185
 * @mode: The layer combination mode.
 
186
 * @progress_start: start of progress
 
187
 * @progress_end: end of progress
 
188
 *
 
189
 * Create a new layer from a %GdkPixbuf.
 
190
 *
 
191
 * This procedure creates a new layer from the given %GdkPixbuf.  The
 
192
 * image has to be an RGB image and just like with gimp_layer_new()
 
193
 * you will still need to add the layer to it.
 
194
 *
 
195
 * If you pass @progress_end > @progress_start to this function,
 
196
 * @gimp_progress_update() will be called for. You have to call
 
197
 * @gimp_progress_init() beforehand.
 
198
 *
 
199
 * Returns: The newly created layer.
 
200
 *
 
201
 * Since: GIMP 2.4
 
202
 */
 
203
gint32
 
204
gimp_layer_new_from_pixbuf (gint32                image_ID,
 
205
                            const gchar          *name,
 
206
                            GdkPixbuf            *pixbuf,
 
207
                            gdouble               opacity,
 
208
                            GimpLayerModeEffects  mode,
 
209
                            gdouble               progress_start,
 
210
                            gdouble               progress_end)
 
211
{
 
212
  GimpDrawable *drawable;
 
213
  GimpPixelRgn  rgn;
 
214
  const guchar *pixels;
 
215
  gpointer      pr;
 
216
  gint32        layer;
 
217
  gint          width;
 
218
  gint          height;
 
219
  gint          rowstride;
 
220
  gint          bpp;
 
221
  gdouble       range = progress_end - progress_start;
 
222
  guint         count = 0;
 
223
  guint         done  = 0;
 
224
 
 
225
  g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), -1);
 
226
 
 
227
  if (gimp_image_base_type (image_ID) != GIMP_RGB)
 
228
    {
 
229
      g_warning ("gimp_layer_new_from_pixbuf() needs an RGB image");
 
230
      return -1;
 
231
    }
 
232
 
 
233
  if (gdk_pixbuf_get_colorspace (pixbuf) != GDK_COLORSPACE_RGB)
 
234
    {
 
235
      g_warning ("gimp_layer_new_from_pixbuf() assumes that GdkPixbuf is RGB");
 
236
      return -1;
 
237
    }
 
238
 
 
239
  width  = gdk_pixbuf_get_width (pixbuf);
 
240
  height = gdk_pixbuf_get_height (pixbuf);
 
241
  bpp    = gdk_pixbuf_get_n_channels (pixbuf);
 
242
 
 
243
  layer = gimp_layer_new (image_ID, name, width, height,
 
244
                          bpp == 3 ? GIMP_RGB_IMAGE : GIMP_RGBA_IMAGE,
 
245
                          opacity, mode);
 
246
 
 
247
  if (layer == -1)
 
248
    return -1;
 
249
 
 
250
  drawable = gimp_drawable_get (layer);
 
251
 
 
252
  gimp_pixel_rgn_init (&rgn, drawable, 0, 0, width, height, TRUE, FALSE);
 
253
 
 
254
  g_assert (bpp == rgn.bpp);
 
255
 
 
256
  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
 
257
  pixels    = gdk_pixbuf_get_pixels (pixbuf);
 
258
 
 
259
  for (pr = gimp_pixel_rgns_register (1, &rgn);
 
260
       pr != NULL;
 
261
       pr = gimp_pixel_rgns_process (pr))
 
262
    {
 
263
      const guchar *src  = pixels + rgn.y * rowstride + rgn.x * bpp;
 
264
      guchar       *dest = rgn.data;
 
265
      gint          y;
 
266
 
 
267
      for (y = 0; y < rgn.h; y++)
 
268
        {
 
269
          memcpy (dest, src, rgn.w * rgn.bpp);
 
270
 
 
271
          src  += rowstride;
 
272
          dest += rgn.rowstride;
 
273
        }
 
274
 
 
275
      if (range > 0.0)
 
276
        {
 
277
          done += rgn.h * rgn.w;
 
278
 
 
279
          if (count++ % 16 == 0)
 
280
            gimp_progress_update (progress_start +
 
281
                                  (gdouble) done / (width * height) * range);
 
282
        }
 
283
    }
 
284
 
 
285
  if (range > 0.0)
 
286
    gimp_progress_update (progress_end);
 
287
 
 
288
  gimp_drawable_detach (drawable);
 
289
 
 
290
  return layer;
 
291
}
 
292
 
 
293
 
 
294
/*
 
295
 * The data that is passed to this function is either freed here or
 
296
 * owned by the returned pixbuf.
 
297
 */
177
298
static GdkPixbuf *
178
299
gimp_pixbuf_from_data (guchar                 *data,
179
300
                       gint                    width,
188
309
    case 1:
189
310
      pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
190
311
      {
 
312
        guchar *src       = data;
191
313
        guchar *pixels    = gdk_pixbuf_get_pixels (pixbuf);
192
314
        gint    rowstride = gdk_pixbuf_get_rowstride (pixbuf);
193
315
        gint    y;
197
319
            guchar *dest = pixels;
198
320
            gint    x;
199
321
 
200
 
            for (x = 0; x < width; x++, data += 1, dest += 3)
 
322
            for (x = 0; x < width; x++, src += 1, dest += 3)
201
323
              {
202
 
                dest[0] = dest[1] = dest[2] = data[0];
 
324
                dest[0] = dest[1] = dest[2] = src[0];
203
325
              }
204
326
 
205
327
            pixels += rowstride;
206
328
          }
 
329
 
 
330
        g_free (data);
207
331
      }
208
332
      bpp = 3;
209
333
      break;
211
335
    case 2:
212
336
      pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
213
337
      {
 
338
        guchar *src       = data;
214
339
        guchar *pixels    = gdk_pixbuf_get_pixels (pixbuf);
215
340
        gint    rowstride = gdk_pixbuf_get_rowstride (pixbuf);
216
341
        gint    y;
220
345
            guchar *dest = pixels;
221
346
            gint    x;
222
347
 
223
 
            for (x = 0; x < width; x++, data += 2, dest += 4)
 
348
            for (x = 0; x < width; x++, src += 2, dest += 4)
224
349
              {
225
 
                dest[0] = dest[1] = dest[2] = data[0];
226
 
                dest[3] = data[1];
 
350
                dest[0] = dest[1] = dest[2] = src[0];
 
351
                dest[3] = src[1];
227
352
              }
228
353
 
229
354
            pixels += rowstride;
230
355
          }
 
356
 
 
357
        g_free (data);
231
358
      }
232
359
      bpp = 4;
233
360
      break;