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

« back to all changes in this revision

Viewing changes to app/core/gimpprojection.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
43
43
 
44
44
/*  local function prototypes  */
45
45
 
46
 
static void   gimp_projection_class_init          (GimpProjectionClass   *klass);
47
 
static void   gimp_projection_init                (GimpProjection        *proj);
48
 
static void   gimp_projection_pickable_iface_init (GimpPickableInterface *pickable_iface);
 
46
static void   gimp_projection_pickable_iface_init (GimpPickableInterface *iface);
49
47
 
50
48
static void       gimp_projection_finalize              (GObject        *object);
51
49
 
52
50
static gint64     gimp_projection_get_memsize           (GimpObject     *object,
53
51
                                                         gint64         *gui_size);
54
52
 
 
53
static void       gimp_projection_pickable_flush        (GimpPickable   *pickable);
55
54
static guchar   * gimp_projection_get_color_at          (GimpPickable   *pickable,
56
55
                                                         gint            x,
57
56
                                                         gint            y);
 
57
static gint       gimp_projection_get_opacity_at        (GimpPickable   *pickable,
 
58
                                                         gint            x,
 
59
                                                         gint            y);
58
60
 
59
61
static void       gimp_projection_alloc_tiles           (GimpProjection *proj);
60
62
static void       gimp_projection_add_update_area       (GimpProjection *proj,
81
83
static void       gimp_projection_validate_tile         (TileManager    *tm,
82
84
                                                         Tile           *tile);
83
85
 
84
 
static void       gimp_projection_image_update          (GimpImage      *gimage,
 
86
static void       gimp_projection_image_update          (GimpImage      *image,
85
87
                                                         gint            x,
86
88
                                                         gint            y,
87
89
                                                         gint            w,
88
90
                                                         gint            h,
89
91
                                                         GimpProjection *proj);
90
 
static void       gimp_projection_image_size_changed    (GimpImage      *gimage,
91
 
                                                         GimpProjection *proj);
92
 
static void       gimp_projection_image_mode_changed    (GimpImage      *gimage,
93
 
                                                         GimpProjection *proj);
94
 
static void       gimp_projection_image_flush           (GimpImage      *gimage,
95
 
                                                         GimpProjection *proj);
96
 
 
 
92
static void       gimp_projection_image_size_changed    (GimpImage      *image,
 
93
                                                         GimpProjection *proj);
 
94
static void       gimp_projection_image_mode_changed    (GimpImage      *image,
 
95
                                                         GimpProjection *proj);
 
96
static void       gimp_projection_image_flush           (GimpImage      *image,
 
97
                                                         GimpProjection *proj);
 
98
 
 
99
 
 
100
G_DEFINE_TYPE_WITH_CODE (GimpProjection, gimp_projection, GIMP_TYPE_OBJECT,
 
101
                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_PICKABLE,
 
102
                                                gimp_projection_pickable_iface_init))
 
103
 
 
104
#define parent_class gimp_projection_parent_class
97
105
 
98
106
static guint projection_signals[LAST_SIGNAL] = { 0 };
99
107
 
100
 
static GimpObjectClass *parent_class = NULL;
101
 
 
102
 
 
103
 
GType
104
 
gimp_projection_get_type (void)
105
 
{
106
 
  static GType projection_type = 0;
107
 
 
108
 
  if (! projection_type)
109
 
    {
110
 
      static const GTypeInfo projection_info =
111
 
      {
112
 
        sizeof (GimpProjectionClass),
113
 
        (GBaseInitFunc) NULL,
114
 
        (GBaseFinalizeFunc) NULL,
115
 
        (GClassInitFunc) gimp_projection_class_init,
116
 
        NULL,           /* class_finalize */
117
 
        NULL,           /* class_data     */
118
 
        sizeof (GimpProjection),
119
 
        0,              /* n_preallocs    */
120
 
        (GInstanceInitFunc) gimp_projection_init,
121
 
      };
122
 
 
123
 
      static const GInterfaceInfo pickable_iface_info =
124
 
      {
125
 
        (GInterfaceInitFunc) gimp_projection_pickable_iface_init,
126
 
        NULL,           /* iface_finalize */
127
 
        NULL            /* iface_data     */
128
 
      };
129
 
 
130
 
      projection_type = g_type_register_static (GIMP_TYPE_OBJECT,
131
 
                                                "GimpProjection",
132
 
                                                &projection_info, 0);
133
 
 
134
 
      g_type_add_interface_static (projection_type, GIMP_TYPE_PICKABLE,
135
 
                                   &pickable_iface_info);
136
 
    }
137
 
 
138
 
  return projection_type;
139
 
}
140
108
 
141
109
static void
142
110
gimp_projection_class_init (GimpProjectionClass *klass)
144
112
  GObjectClass    *object_class      = G_OBJECT_CLASS (klass);
145
113
  GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
146
114
 
147
 
  parent_class = g_type_class_peek_parent (klass);
148
 
 
149
115
  projection_signals[UPDATE] =
150
116
    g_signal_new ("update",
151
 
                  G_TYPE_FROM_CLASS (klass),
152
 
                  G_SIGNAL_RUN_FIRST,
153
 
                  G_STRUCT_OFFSET (GimpProjectionClass, update),
154
 
                  NULL, NULL,
155
 
                  gimp_marshal_VOID__BOOLEAN_INT_INT_INT_INT,
156
 
                  G_TYPE_NONE, 5,
 
117
                  G_TYPE_FROM_CLASS (klass),
 
118
                  G_SIGNAL_RUN_FIRST,
 
119
                  G_STRUCT_OFFSET (GimpProjectionClass, update),
 
120
                  NULL, NULL,
 
121
                  gimp_marshal_VOID__BOOLEAN_INT_INT_INT_INT,
 
122
                  G_TYPE_NONE, 5,
157
123
                  G_TYPE_BOOLEAN,
158
 
                  G_TYPE_INT,
159
 
                  G_TYPE_INT,
160
 
                  G_TYPE_INT,
161
 
                  G_TYPE_INT);
 
124
                  G_TYPE_INT,
 
125
                  G_TYPE_INT,
 
126
                  G_TYPE_INT,
 
127
                  G_TYPE_INT);
162
128
 
163
129
  object_class->finalize         = gimp_projection_finalize;
164
130
 
168
134
static void
169
135
gimp_projection_init (GimpProjection *proj)
170
136
{
171
 
  proj->gimage                   = NULL;
 
137
  proj->image                    = NULL;
172
138
 
173
139
  proj->type                     = -1;
174
140
  proj->bytes                    = 0;
182
148
  proj->construct_flag           = FALSE;
183
149
}
184
150
 
 
151
/* sorry for the evil casts */
 
152
 
185
153
static void
186
 
gimp_projection_pickable_iface_init (GimpPickableInterface *pickable_iface)
 
154
gimp_projection_pickable_iface_init (GimpPickableInterface *iface)
187
155
{
188
 
  pickable_iface->get_image      = gimp_projection_get_image;
189
 
  pickable_iface->get_image_type = gimp_projection_get_image_type;
190
 
  pickable_iface->get_tiles      = gimp_projection_get_tiles;
191
 
  pickable_iface->get_color_at   = gimp_projection_get_color_at;
 
156
  iface->flush          = gimp_projection_pickable_flush;
 
157
  iface->get_image      = (GimpImage     * (*) (GimpPickable *pickable)) gimp_projection_get_image;
 
158
  iface->get_image_type = (GimpImageType   (*) (GimpPickable *pickable)) gimp_projection_get_image_type;
 
159
  iface->get_bytes      = (gint            (*) (GimpPickable *pickable)) gimp_projection_get_bytes;
 
160
  iface->get_tiles      = (TileManager   * (*) (GimpPickable *pickable)) gimp_projection_get_tiles;
 
161
  iface->get_color_at   = gimp_projection_get_color_at;
 
162
  iface->get_opacity_at = gimp_projection_get_opacity_at;
192
163
}
193
164
 
194
165
static void
231
202
                                                                  gui_size);
232
203
}
233
204
 
 
205
static void
 
206
gimp_projection_pickable_flush (GimpPickable *pickable)
 
207
{
 
208
  GimpProjection *proj = GIMP_PROJECTION (pickable);
 
209
 
 
210
  gimp_projection_finish_draw (proj);
 
211
  gimp_projection_flush_now (proj);
 
212
}
 
213
 
234
214
static guchar *
235
215
gimp_projection_get_color_at (GimpPickable *pickable,
236
216
                              gint          x,
241
221
  guchar         *src;
242
222
  guchar         *dest;
243
223
 
244
 
  if (x < 0 || y < 0 || x >= proj->gimage->width || y >= proj->gimage->height)
 
224
  if (x < 0 || y < 0 || x >= proj->image->width || y >= proj->image->height)
245
225
    return NULL;
246
226
 
247
227
  dest = g_new (guchar, 5);
248
228
  tile = tile_manager_get_tile (gimp_projection_get_tiles (proj),
249
229
                                x, y, TRUE, FALSE);
250
230
  src = tile_data_pointer (tile, x % TILE_WIDTH, y % TILE_HEIGHT);
251
 
  gimp_image_get_color (proj->gimage, gimp_projection_get_image_type (proj),
 
231
  gimp_image_get_color (proj->image, gimp_projection_get_image_type (proj),
252
232
                        src, dest);
253
233
 
254
234
  dest[4] = 0;
257
237
  return dest;
258
238
}
259
239
 
 
240
static gint
 
241
gimp_projection_get_opacity_at (GimpPickable *pickable,
 
242
                                gint          x,
 
243
                                gint          y)
 
244
{
 
245
  return OPAQUE_OPACITY;
 
246
}
 
247
 
260
248
GimpProjection *
261
 
gimp_projection_new (GimpImage *gimage)
 
249
gimp_projection_new (GimpImage *image)
262
250
{
263
251
  GimpProjection *proj;
264
252
 
265
 
  g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
 
253
  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
266
254
 
267
255
  proj = g_object_new (GIMP_TYPE_PROJECTION, NULL);
268
256
 
269
 
  proj->gimage = gimage;
 
257
  proj->image = image;
270
258
 
271
 
  g_signal_connect_object (gimage, "update",
 
259
  g_signal_connect_object (image, "update",
272
260
                           G_CALLBACK (gimp_projection_image_update),
273
261
                           proj, 0);
274
 
  g_signal_connect_object (gimage, "size_changed",
 
262
  g_signal_connect_object (image, "size-changed",
275
263
                           G_CALLBACK (gimp_projection_image_size_changed),
276
264
                           proj, 0);
277
 
  g_signal_connect_object (gimage, "mode_changed",
 
265
  g_signal_connect_object (image, "mode-changed",
278
266
                           G_CALLBACK (gimp_projection_image_mode_changed),
279
267
                           proj, 0);
280
 
  g_signal_connect_object (gimage, "flush",
 
268
  g_signal_connect_object (image, "flush",
281
269
                           G_CALLBACK (gimp_projection_image_flush),
282
270
                           proj, 0);
283
271
 
290
278
  g_return_val_if_fail (GIMP_IS_PROJECTION (proj), NULL);
291
279
 
292
280
  if (proj->tiles == NULL                                      ||
293
 
      tile_manager_width  (proj->tiles) != proj->gimage->width ||
294
 
      tile_manager_height (proj->tiles) != proj->gimage->height)
 
281
      tile_manager_width  (proj->tiles) != proj->image->width ||
 
282
      tile_manager_height (proj->tiles) != proj->image->height)
295
283
    {
296
284
      gimp_projection_alloc_tiles (proj);
297
285
    }
304
292
{
305
293
  g_return_val_if_fail (GIMP_IS_PROJECTION (proj), NULL);
306
294
 
307
 
  return proj->gimage;
 
295
  return proj->image;
308
296
}
309
297
 
310
298
GimpImageType
356
344
 
357
345
  if (proj->idle_render.idle_id)
358
346
    {
 
347
#if 0
 
348
      g_printerr ("%s: flushing idle render queue\n", G_STRFUNC);
 
349
#endif
 
350
 
359
351
      g_source_remove (proj->idle_render.idle_id);
360
352
      proj->idle_render.idle_id = 0;
361
353
 
378
370
   *  This includes the intensity channels and an alpha channel
379
371
   *  if one doesn't exist.
380
372
   */
381
 
  switch (gimp_image_base_type (proj->gimage))
 
373
  switch (gimp_image_base_type (proj->image))
382
374
    {
383
375
    case GIMP_RGB:
384
376
    case GIMP_INDEXED:
397
389
 
398
390
  if (proj->tiles)
399
391
    {
400
 
      if (proj_type            != proj->type                       ||
401
 
          proj_bytes           != proj->bytes                      ||
402
 
          proj->gimage->width  != tile_manager_width (proj->tiles) ||
403
 
          proj->gimage->height != tile_manager_height (proj->tiles))
 
392
      if (proj_type           != proj->type                       ||
 
393
          proj_bytes          != proj->bytes                      ||
 
394
          proj->image->width  != tile_manager_width (proj->tiles) ||
 
395
          proj->image->height != tile_manager_height (proj->tiles))
404
396
        {
405
397
          tile_manager_unref (proj->tiles);
406
398
          proj->tiles = NULL;
412
404
      proj->type  = proj_type;
413
405
      proj->bytes = proj_bytes;
414
406
 
415
 
      proj->tiles = tile_manager_new (proj->gimage->width,
416
 
                                      proj->gimage->height,
 
407
      proj->tiles = tile_manager_new (proj->image->width,
 
408
                                      proj->image->height,
417
409
                                      proj->bytes);
418
410
      tile_manager_set_user_data (proj->tiles, proj);
419
411
      tile_manager_set_validate_proc (proj->tiles,
432
424
 
433
425
  g_return_if_fail (GIMP_IS_PROJECTION (proj));
434
426
 
435
 
  area = gimp_area_new (CLAMP (x, 0, proj->gimage->width),
436
 
                        CLAMP (y, 0, proj->gimage->height),
437
 
                        CLAMP (x + w, 0, proj->gimage->width),
438
 
                        CLAMP (y + h, 0, proj->gimage->height));
 
427
  area = gimp_area_new (CLAMP (x, 0, proj->image->width),
 
428
                        CLAMP (y, 0, proj->image->height),
 
429
                        CLAMP (x + w, 0, proj->image->width),
 
430
                        CLAMP (y + h, 0, proj->image->height));
439
431
 
440
432
  proj->update_areas = gimp_area_list_process (proj->update_areas, area);
441
433
}
624
616
  gint x1, y1, x2, y2;
625
617
 
626
618
  /*  Bounds check  */
627
 
  x1 = CLAMP (x,     0, proj->gimage->width);
628
 
  y1 = CLAMP (y,     0, proj->gimage->height);
629
 
  x2 = CLAMP (x + w, 0, proj->gimage->width);
630
 
  y2 = CLAMP (y + h, 0, proj->gimage->height);
 
619
  x1 = CLAMP (x,     0, proj->image->width);
 
620
  y1 = CLAMP (y,     0, proj->image->height);
 
621
  x2 = CLAMP (x + w, 0, proj->image->width);
 
622
  y2 = CLAMP (y + h, 0, proj->image->height);
631
623
  x = x1;
632
624
  y = y1;
633
625
  w = (x2 - x1);
655
647
  for (i = y; i < (y + h); i += (TILE_HEIGHT - (i % TILE_HEIGHT)))
656
648
    for (j = x; j < (x + w); j += (TILE_WIDTH - (j % TILE_WIDTH)))
657
649
      {
658
 
        tile = tile_manager_get_tile (tm, j, i, FALSE, FALSE);
 
650
        tile = tile_manager_get_tile (tm, j, i, FALSE, FALSE);
659
651
 
660
652
        tile_invalidate_tile (&tile, tm, j, i);
661
653
      }
681
673
/*  image callbacks  */
682
674
 
683
675
static void
684
 
gimp_projection_image_update (GimpImage      *gimage,
 
676
gimp_projection_image_update (GimpImage      *image,
685
677
                              gint            x,
686
678
                              gint            y,
687
679
                              gint            w,
692
684
}
693
685
 
694
686
static void
695
 
gimp_projection_image_size_changed (GimpImage      *gimage,
696
 
                                    GimpProjection *proj)
697
 
{
698
 
  gimp_projection_alloc_tiles (proj);
699
 
  gimp_projection_add_update_area (proj, 0, 0, gimage->width, gimage->height);
700
 
}
701
 
 
702
 
static void
703
 
gimp_projection_image_mode_changed (GimpImage      *gimage,
704
 
                                    GimpProjection *proj)
705
 
{
706
 
  gimp_projection_alloc_tiles (proj);
707
 
  gimp_projection_add_update_area (proj, 0, 0, gimage->width, gimage->height);
708
 
}
709
 
 
710
 
static void
711
 
gimp_projection_image_flush (GimpImage      *gimage,
 
687
gimp_projection_image_size_changed (GimpImage      *image,
 
688
                                    GimpProjection *proj)
 
689
{
 
690
  gimp_projection_alloc_tiles (proj);
 
691
  gimp_projection_add_update_area (proj, 0, 0, image->width, image->height);
 
692
}
 
693
 
 
694
static void
 
695
gimp_projection_image_mode_changed (GimpImage      *image,
 
696
                                    GimpProjection *proj)
 
697
{
 
698
  gimp_projection_alloc_tiles (proj);
 
699
  gimp_projection_add_update_area (proj, 0, 0, image->width, image->height);
 
700
}
 
701
 
 
702
static void
 
703
gimp_projection_image_flush (GimpImage      *image,
712
704
                             GimpProjection *proj)
713
705
{
714
706
  gimp_projection_flush (proj);