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

« back to all changes in this revision

Viewing changes to app/core/gimpbuffer.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
29
29
#include "base/temp-buf.h"
30
30
 
31
31
#include "paint-funcs/paint-funcs.h"
 
32
#include "paint-funcs/scale-funcs.h"
32
33
 
33
34
#include "gimpbuffer.h"
34
35
 
35
36
 
36
 
static void      gimp_buffer_class_init       (GimpBufferClass *klass);
37
 
static void      gimp_buffer_init             (GimpBuffer      *buffer);
38
 
 
39
 
static void      gimp_buffer_finalize         (GObject         *object);
40
 
 
41
 
static gint64    gimp_buffer_get_memsize      (GimpObject      *object,
42
 
                                               gint64          *gui_size);
43
 
 
44
 
static void      gimp_buffer_get_preview_size (GimpViewable    *viewable,
45
 
                                               gint             size,
46
 
                                               gboolean         is_popup,
47
 
                                               gboolean         dot_for_dot,
48
 
                                               gint            *popup_width,
49
 
                                               gint            *popup_height);
50
 
static gboolean  gimp_buffer_get_popup_size   (GimpViewable    *viewable,
51
 
                                               gint             width,
52
 
                                               gint             height,
53
 
                                               gboolean         dot_for_dot,
54
 
                                               gint            *popup_width,
55
 
                                               gint            *popup_height);
56
 
static TempBuf * gimp_buffer_get_new_preview  (GimpViewable    *viewable,
57
 
                                               gint             width,
58
 
                                               gint             height);
59
 
static gchar   * gimp_buffer_get_description  (GimpViewable    *viewable,
60
 
                                               gchar          **tooltip);
61
 
 
62
 
 
63
 
static GimpViewableClass *parent_class = NULL;
64
 
 
65
 
 
66
 
GType
67
 
gimp_buffer_get_type (void)
68
 
{
69
 
  static GType buffer_type = 0;
70
 
 
71
 
  if (! buffer_type)
72
 
    {
73
 
      static const GTypeInfo buffer_info =
74
 
      {
75
 
        sizeof (GimpBufferClass),
76
 
        (GBaseInitFunc) NULL,
77
 
        (GBaseFinalizeFunc) NULL,
78
 
        (GClassInitFunc) gimp_buffer_class_init,
79
 
        NULL,           /* class_finalize */
80
 
        NULL,           /* class_data     */
81
 
        sizeof (GimpBuffer),
82
 
        0,              /* n_preallocs    */
83
 
        (GInstanceInitFunc) gimp_buffer_init,
84
 
      };
85
 
 
86
 
      buffer_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
87
 
                                            "GimpBuffer",
88
 
                                            &buffer_info, 0);
89
 
  }
90
 
 
91
 
  return buffer_type;
92
 
}
 
37
static void      gimp_buffer_finalize         (GObject       *object);
 
38
 
 
39
static gint64    gimp_buffer_get_memsize      (GimpObject    *object,
 
40
                                               gint64        *gui_size);
 
41
 
 
42
static gboolean  gimp_buffer_get_size         (GimpViewable  *viewable,
 
43
                                               gint          *width,
 
44
                                               gint          *height);
 
45
static void      gimp_buffer_get_preview_size (GimpViewable  *viewable,
 
46
                                               gint           size,
 
47
                                               gboolean       is_popup,
 
48
                                               gboolean       dot_for_dot,
 
49
                                               gint          *popup_width,
 
50
                                               gint          *popup_height);
 
51
static gboolean  gimp_buffer_get_popup_size   (GimpViewable  *viewable,
 
52
                                               gint           width,
 
53
                                               gint           height,
 
54
                                               gboolean       dot_for_dot,
 
55
                                               gint          *popup_width,
 
56
                                               gint          *popup_height);
 
57
static TempBuf * gimp_buffer_get_new_preview  (GimpViewable  *viewable,
 
58
                                               GimpContext   *context,
 
59
                                               gint           width,
 
60
                                               gint           height);
 
61
static gchar   * gimp_buffer_get_description  (GimpViewable  *viewable,
 
62
                                               gchar        **tooltip);
 
63
 
 
64
 
 
65
G_DEFINE_TYPE (GimpBuffer, gimp_buffer, GIMP_TYPE_VIEWABLE)
 
66
 
 
67
#define parent_class gimp_buffer_parent_class
 
68
 
93
69
 
94
70
static void
95
71
gimp_buffer_class_init (GimpBufferClass *klass)
98
74
  GimpObjectClass   *gimp_object_class = GIMP_OBJECT_CLASS (klass);
99
75
  GimpViewableClass *viewable_class    = GIMP_VIEWABLE_CLASS (klass);
100
76
 
101
 
  parent_class = g_type_class_peek_parent (klass);
102
 
 
103
77
  object_class->finalize           = gimp_buffer_finalize;
104
78
 
105
79
  gimp_object_class->get_memsize   = gimp_buffer_get_memsize;
106
80
 
107
81
  viewable_class->default_stock_id = "gtk-paste";
 
82
  viewable_class->get_size         = gimp_buffer_get_size;
108
83
  viewable_class->get_preview_size = gimp_buffer_get_preview_size;
109
84
  viewable_class->get_popup_size   = gimp_buffer_get_popup_size;
110
85
  viewable_class->get_new_preview  = gimp_buffer_get_new_preview;
135
110
gimp_buffer_get_memsize (GimpObject *object,
136
111
                         gint64     *gui_size)
137
112
{
138
 
  GimpBuffer *buffer;
 
113
  GimpBuffer *buffer  = GIMP_BUFFER (object);
139
114
  gint64      memsize = 0;
140
115
 
141
 
  buffer = GIMP_BUFFER (object);
142
 
 
143
116
  if (buffer->tiles)
144
117
    memsize += tile_manager_get_memsize (buffer->tiles, FALSE);
145
118
 
147
120
                                                                  gui_size);
148
121
}
149
122
 
 
123
static gboolean
 
124
gimp_buffer_get_size (GimpViewable *viewable,
 
125
                      gint         *width,
 
126
                      gint         *height)
 
127
{
 
128
  GimpBuffer *buffer = GIMP_BUFFER (viewable);
 
129
 
 
130
  *width  = gimp_buffer_get_width (buffer);
 
131
  *height = gimp_buffer_get_height (buffer);
 
132
 
 
133
  return TRUE;
 
134
}
 
135
 
150
136
static void
151
137
gimp_buffer_get_preview_size (GimpViewable *viewable,
152
 
                              gint          size,
 
138
                              gint          size,
153
139
                              gboolean      is_popup,
154
140
                              gboolean      dot_for_dot,
155
 
                              gint         *width,
156
 
                              gint         *height)
 
141
                              gint         *width,
 
142
                              gint         *height)
157
143
{
158
144
  GimpBuffer *buffer = GIMP_BUFFER (viewable);
159
145
 
210
196
 
211
197
static TempBuf *
212
198
gimp_buffer_get_new_preview (GimpViewable *viewable,
213
 
                             gint          width,
214
 
                             gint          height)
 
199
                             GimpContext  *context,
 
200
                             gint          width,
 
201
                             gint          height)
215
202
{
216
203
  GimpBuffer  *buffer = GIMP_BUFFER (viewable);
217
204
  TempBuf     *temp_buf;
227
214
  bytes = tile_manager_bpp (buffer->tiles);
228
215
 
229
216
  pixel_region_init (&srcPR, buffer->tiles,
230
 
                     0, 0,
231
 
                     buffer_width,
232
 
                     buffer_height,
233
 
                     FALSE);
 
217
                     0, 0,
 
218
                     buffer_width,
 
219
                     buffer_height,
 
220
                     FALSE);
234
221
 
235
222
  if (buffer_height > height || buffer_width > width)
236
223
    temp_buf = temp_buf_new (width, height, bytes, 0, 0, NULL);
237
224
  else
238
225
    temp_buf = temp_buf_new (buffer_width, buffer_height, bytes, 0, 0, NULL);
239
226
 
240
 
  destPR.bytes     = temp_buf->bytes;
241
 
  destPR.x         = 0;
242
 
  destPR.y         = 0;
243
 
  destPR.w         = temp_buf->width;
244
 
  destPR.h         = temp_buf->height;
245
 
  destPR.rowstride = temp_buf->width * destPR.bytes;
246
 
  destPR.data      = temp_buf_data (temp_buf);
 
227
  pixel_region_init_temp_buf (&destPR, temp_buf,
 
228
                              0, 0, temp_buf->width, temp_buf->height);
247
229
 
248
230
  if (buffer_height > height || buffer_width > width)
249
231
    {
272
254
{
273
255
  GimpBuffer *buffer = GIMP_BUFFER (viewable);
274
256
 
275
 
  if (tooltip)
276
 
    *tooltip = NULL;
277
 
 
278
 
  return g_strdup_printf ("%s (%d x %d)",
 
257
  return g_strdup_printf ("%s (%d × %d)",
279
258
                          GIMP_OBJECT (buffer)->name,
280
259
                          gimp_buffer_get_width (buffer),
281
260
                          gimp_buffer_get_height (buffer));
283
262
 
284
263
GimpBuffer *
285
264
gimp_buffer_new (TileManager *tiles,
286
 
                 const gchar *name,
 
265
                 const gchar *name,
287
266
                 gboolean     copy_pixels)
288
267
{
289
 
  GimpBuffer  *buffer;
290
 
  PixelRegion  srcPR, destPR;
291
 
  gint         width, height;
 
268
  GimpBuffer *buffer;
 
269
  gint        width, height;
292
270
 
293
271
  g_return_val_if_fail (tiles != NULL, NULL);
294
272
  g_return_val_if_fail (name != NULL, NULL);
296
274
  width  = tile_manager_width (tiles);
297
275
  height = tile_manager_height (tiles);
298
276
 
299
 
  buffer = g_object_new (GIMP_TYPE_BUFFER, NULL);
300
 
 
301
 
  gimp_object_set_name (GIMP_OBJECT (buffer), name);
 
277
  buffer = g_object_new (GIMP_TYPE_BUFFER,
 
278
                         "name", name,
 
279
                         NULL);
302
280
 
303
281
  if (copy_pixels)
304
282
    {
 
283
      PixelRegion srcPR, destPR;
 
284
 
305
285
      buffer->tiles = tile_manager_new (width, height,
306
286
                                        tile_manager_bpp (tiles));
307
287
 
317
297
  return buffer;
318
298
}
319
299
 
 
300
GimpBuffer *
 
301
gimp_buffer_new_from_pixbuf (GdkPixbuf   *pixbuf,
 
302
                             const gchar *name)
 
303
{
 
304
  TileManager *tiles;
 
305
  guchar      *pixels;
 
306
  PixelRegion  destPR;
 
307
  gint         width;
 
308
  gint         height;
 
309
  gint         rowstride;
 
310
  gint         channels;
 
311
  gint         y;
 
312
 
 
313
  g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
 
314
  g_return_val_if_fail (name != NULL, NULL);
 
315
 
 
316
  width     = gdk_pixbuf_get_width (pixbuf);
 
317
  height    = gdk_pixbuf_get_height (pixbuf);
 
318
  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
 
319
  channels  = gdk_pixbuf_get_n_channels (pixbuf);
 
320
 
 
321
  tiles = tile_manager_new (width, height, channels);
 
322
 
 
323
  pixel_region_init (&destPR, tiles, 0, 0, width, height, TRUE);
 
324
 
 
325
  for (y = 0, pixels = gdk_pixbuf_get_pixels (pixbuf);
 
326
       y < height;
 
327
       y++, pixels += rowstride)
 
328
    {
 
329
      pixel_region_set_row (&destPR, 0, y, width, pixels);
 
330
   }
 
331
 
 
332
  return gimp_buffer_new (tiles, name, FALSE);
 
333
}
 
334
 
320
335
gint
321
336
gimp_buffer_get_width (const GimpBuffer *buffer)
322
337
{
332
347
 
333
348
  return tile_manager_height (buffer->tiles);
334
349
}
 
350
 
 
351
gint
 
352
gimp_buffer_get_bytes (const GimpBuffer *buffer)
 
353
{
 
354
  g_return_val_if_fail (GIMP_IS_BUFFER (buffer), 0);
 
355
 
 
356
  return tile_manager_bpp (buffer->tiles);
 
357
}
 
358
 
 
359
GimpImageType
 
360
gimp_buffer_get_image_type (const GimpBuffer *buffer)
 
361
{
 
362
  g_return_val_if_fail (GIMP_IS_BUFFER (buffer), 0);
 
363
 
 
364
  switch (tile_manager_bpp (buffer->tiles))
 
365
    {
 
366
    case 1: return GIMP_GRAY_IMAGE;
 
367
    case 2: return GIMP_GRAYA_IMAGE;
 
368
    case 3: return GIMP_RGB_IMAGE;
 
369
    case 4: return GIMP_RGBA_IMAGE;
 
370
    }
 
371
 
 
372
  return 0;
 
373
}