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

« back to all changes in this revision

Viewing changes to libgimp/gimpdrawablepreview.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:
32
32
#include "gimpdrawablepreview.h"
33
33
 
34
34
 
35
 
#define SELECTION_BORDER  2
36
 
 
37
 
 
38
 
static void  gimp_drawable_preview_class_init    (GimpDrawablePreviewClass *klass);
39
 
static void  gimp_drawable_preview_init          (GimpDrawablePreview *preview);
40
 
 
41
 
static void  gimp_drawable_preview_style_set     (GtkWidget           *widget,
42
 
                                                  GtkStyle            *prev_style);
43
 
 
44
 
static void  gimp_drawable_preview_draw_original (GimpPreview         *preview);
45
 
static void  gimp_drawable_preview_draw_thumb    (GimpPreview         *preview,
46
 
                                                  GimpPreviewArea     *area,
47
 
                                                  gint                 width,
48
 
                                                  gint                 height);
49
 
static void  gimp_drawable_preview_draw_buffer   (GimpPreview         *preview,
50
 
                                                  const guchar        *buffer,
51
 
                                                  gint                 rowstride);
52
 
static gboolean gimp_drawable_preview_get_bounds (GimpDrawable        *drawable,
53
 
                                                  gint                *xmin,
54
 
                                                  gint                *ymin,
55
 
                                                  gint                *xmax,
56
 
                                                  gint                *ymax);
57
 
 
58
 
 
59
 
static GimpScrolledPreviewClass *parent_class = NULL;
60
 
 
61
 
 
62
 
GType
63
 
gimp_drawable_preview_get_type (void)
64
 
{
65
 
  static GType preview_type = 0;
66
 
 
67
 
  if (!preview_type)
68
 
    {
69
 
      static const GTypeInfo drawable_preview_info =
70
 
      {
71
 
        sizeof (GimpDrawablePreviewClass),
72
 
        (GBaseInitFunc)     NULL,
73
 
        (GBaseFinalizeFunc) NULL,
74
 
        (GClassInitFunc) gimp_drawable_preview_class_init,
75
 
        NULL,           /* class_finalize */
76
 
        NULL,           /* class_data     */
77
 
        sizeof (GimpDrawablePreview),
78
 
        0,              /* n_preallocs    */
79
 
        (GInstanceInitFunc) gimp_drawable_preview_init
80
 
      };
81
 
 
82
 
      preview_type = g_type_register_static (GIMP_TYPE_SCROLLED_PREVIEW,
83
 
                                             "GimpDrawablePreview",
84
 
                                             &drawable_preview_info, 0);
85
 
    }
86
 
 
87
 
  return preview_type;
88
 
}
 
35
#define SELECTION_BORDER  8
 
36
 
 
37
enum
 
38
{
 
39
  PROP_0,
 
40
  PROP_DRAWABLE
 
41
};
 
42
 
 
43
typedef struct
 
44
{
 
45
  gint     x, y;
 
46
  gboolean update;
 
47
} PreviewSettings;
 
48
 
 
49
 
 
50
static GObject * gimp_drawable_preview_constructor (GType                  type,
 
51
                                                    guint                  n_params,
 
52
                                                    GObjectConstructParam *params);
 
53
 
 
54
static void  gimp_drawable_preview_get_property  (GObject         *object,
 
55
                                                  guint            property_id,
 
56
                                                  GValue          *value,
 
57
                                                  GParamSpec      *pspec);
 
58
static void  gimp_drawable_preview_set_property  (GObject         *object,
 
59
                                                  guint            property_id,
 
60
                                                  const GValue    *value,
 
61
                                                  GParamSpec      *pspec);
 
62
static void  gimp_drawable_preview_destroy       (GtkObject       *object);
 
63
 
 
64
static void  gimp_drawable_preview_style_set     (GtkWidget       *widget,
 
65
                                                  GtkStyle        *prev_style);
 
66
 
 
67
static void  gimp_drawable_preview_draw_original (GimpPreview     *preview);
 
68
static void  gimp_drawable_preview_draw_thumb    (GimpPreview     *preview,
 
69
                                                  GimpPreviewArea *area,
 
70
                                                  gint             width,
 
71
                                                  gint             height);
 
72
static void  gimp_drawable_preview_draw_buffer   (GimpPreview     *preview,
 
73
                                                  const guchar    *buffer,
 
74
                                                  gint             rowstride);
 
75
 
 
76
static void  gimp_drawable_preview_set_drawable (GimpDrawablePreview *preview,
 
77
                                                 GimpDrawable        *drawable);
 
78
 
 
79
 
 
80
G_DEFINE_TYPE (GimpDrawablePreview, gimp_drawable_preview,
 
81
               GIMP_TYPE_SCROLLED_PREVIEW)
 
82
 
 
83
#define parent_class gimp_drawable_preview_parent_class
 
84
 
89
85
 
90
86
static void
91
87
gimp_drawable_preview_class_init (GimpDrawablePreviewClass *klass)
92
88
{
93
 
  GtkWidgetClass   *widget_class  = GTK_WIDGET_CLASS (klass);
94
 
  GimpPreviewClass *preview_class = GIMP_PREVIEW_CLASS (klass);
95
 
 
96
 
  parent_class = g_type_class_peek_parent (klass);
 
89
  GObjectClass     *object_class     = G_OBJECT_CLASS (klass);
 
90
  GtkObjectClass   *gtk_object_class = GTK_OBJECT_CLASS (klass);
 
91
  GtkWidgetClass   *widget_class     = GTK_WIDGET_CLASS (klass);
 
92
  GimpPreviewClass *preview_class    = GIMP_PREVIEW_CLASS (klass);
 
93
 
 
94
  object_class->constructor  = gimp_drawable_preview_constructor;
 
95
  object_class->get_property = gimp_drawable_preview_get_property;
 
96
  object_class->set_property = gimp_drawable_preview_set_property;
 
97
 
 
98
  gtk_object_class->destroy  = gimp_drawable_preview_destroy;
97
99
 
98
100
  widget_class->style_set    = gimp_drawable_preview_style_set;
99
101
 
100
102
  preview_class->draw        = gimp_drawable_preview_draw_original;
101
103
  preview_class->draw_thumb  = gimp_drawable_preview_draw_thumb;
102
104
  preview_class->draw_buffer = gimp_drawable_preview_draw_buffer;
 
105
 
 
106
  /**
 
107
   * GimpDrawablePreview:drawable:
 
108
   *
 
109
   * Since: GIMP 2.4
 
110
   */
 
111
  g_object_class_install_property (object_class, PROP_DRAWABLE,
 
112
                                   g_param_spec_pointer ("drawable", NULL, NULL,
 
113
                                                         GIMP_PARAM_READWRITE |
 
114
                                                         G_PARAM_CONSTRUCT_ONLY));
103
115
}
104
116
 
105
117
static void
111
123
                NULL);
112
124
}
113
125
 
 
126
static GObject *
 
127
gimp_drawable_preview_constructor (GType                  type,
 
128
                                   guint                  n_params,
 
129
                                   GObjectConstructParam *params)
 
130
{
 
131
  GObject         *object;
 
132
  PreviewSettings  settings;
 
133
  gchar           *data_name = g_strconcat (g_get_prgname (), "-preview", NULL);
 
134
 
 
135
  object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
 
136
 
 
137
  if (gimp_get_data (data_name, &settings))
 
138
    gimp_scrolled_preview_set_position (GIMP_SCROLLED_PREVIEW (object),
 
139
                                        settings.x, settings.y);
 
140
 
 
141
  g_free (data_name);
 
142
 
 
143
  return object;
 
144
}
 
145
 
 
146
static void
 
147
gimp_drawable_preview_get_property (GObject    *object,
 
148
                                    guint       property_id,
 
149
                                    GValue     *value,
 
150
                                    GParamSpec *pspec)
 
151
{
 
152
  GimpDrawablePreview *preview = GIMP_DRAWABLE_PREVIEW (object);
 
153
 
 
154
  switch (property_id)
 
155
    {
 
156
    case PROP_DRAWABLE:
 
157
      g_value_set_pointer (value,
 
158
                           gimp_drawable_preview_get_drawable (preview));
 
159
      break;
 
160
 
 
161
    default:
 
162
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
163
      break;
 
164
    }
 
165
}
 
166
 
 
167
static void
 
168
gimp_drawable_preview_set_property (GObject      *object,
 
169
                                    guint         property_id,
 
170
                                    const GValue *value,
 
171
                                    GParamSpec   *pspec)
 
172
{
 
173
  GimpDrawablePreview *preview = GIMP_DRAWABLE_PREVIEW (object);
 
174
 
 
175
  switch (property_id)
 
176
    {
 
177
    case PROP_DRAWABLE:
 
178
      gimp_drawable_preview_set_drawable (preview,
 
179
                                          g_value_get_pointer (value));
 
180
      break;
 
181
 
 
182
    default:
 
183
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
184
      break;
 
185
    }
 
186
}
 
187
 
 
188
static void
 
189
gimp_drawable_preview_destroy (GtkObject *object)
 
190
{
 
191
  GimpPreview     *preview = GIMP_PREVIEW (object);
 
192
  PreviewSettings  settings;
 
193
  gchar           *data_name;
 
194
 
 
195
  settings.x      = preview->xoff + preview->xmin;
 
196
  settings.y      = preview->yoff + preview->ymin;
 
197
  settings.update = TRUE;
 
198
 
 
199
  data_name = g_strconcat (g_get_prgname (), "-preview", NULL);
 
200
  gimp_set_data (data_name, &settings, sizeof (PreviewSettings));
 
201
  g_free (data_name);
 
202
 
 
203
  GTK_OBJECT_CLASS (parent_class)->destroy (object);
 
204
}
 
205
 
114
206
static void
115
207
gimp_drawable_preview_style_set (GtkWidget *widget,
116
208
                                 GtkStyle  *prev_style)
178
270
{
179
271
  GimpDrawablePreview *drawable_preview = GIMP_DRAWABLE_PREVIEW (preview);
180
272
  GimpDrawable        *drawable         = drawable_preview->drawable;
181
 
  guchar              *buffer;
182
 
  gint                 x1, y1, x2, y2;
183
 
  gint                 bpp;
184
 
 
185
 
  if (! drawable)
186
 
    return;
187
 
 
188
 
  if (gimp_drawable_preview_get_bounds (drawable, &x1, &y1, &x2, &y2))
 
273
 
 
274
  if (drawable)
 
275
    _gimp_drawable_preview_area_draw_thumb (area, drawable, width, height);
 
276
}
 
277
 
 
278
void
 
279
_gimp_drawable_preview_area_draw_thumb (GimpPreviewArea *area,
 
280
                                        GimpDrawable    *drawable,
 
281
                                        gint             width,
 
282
                                        gint             height)
 
283
{
 
284
  guchar *buffer;
 
285
  gint    x1, y1, x2, y2;
 
286
  gint    bpp;
 
287
  gint    size = 100;
 
288
  gint    nav_width, nav_height;
 
289
 
 
290
  g_return_if_fail (GIMP_IS_PREVIEW_AREA (area));
 
291
  g_return_if_fail (drawable != NULL);
 
292
 
 
293
  if (_gimp_drawable_preview_get_bounds (drawable, &x1, &y1, &x2, &y2))
 
294
    {
 
295
      width  = x2 - x1;
 
296
      height = y2 - y1;
 
297
    }
 
298
  else
 
299
    {
 
300
      width  = gimp_drawable_width  (drawable->drawable_id);
 
301
      height = gimp_drawable_height (drawable->drawable_id);
 
302
    }
 
303
 
 
304
  if (width > height)
 
305
    {
 
306
      nav_width  = MIN (width, size);
 
307
      nav_height = (height * nav_width) / width;
 
308
    }
 
309
  else
 
310
    {
 
311
      nav_height = MIN (height, size);
 
312
      nav_width  = (width * nav_height) / height;
 
313
    }
 
314
 
 
315
  if (_gimp_drawable_preview_get_bounds (drawable, &x1, &y1, &x2, &y2))
189
316
    {
190
317
      buffer = gimp_drawable_get_sub_thumbnail_data (drawable->drawable_id,
191
318
                                                     x1, y1, x2 - x1, y2 - y1,
192
 
                                                     &width, &height, &bpp);
 
319
                                                     &nav_width, &nav_height,
 
320
                                                     &bpp);
193
321
    }
194
322
  else
195
323
    {
196
324
      buffer = gimp_drawable_get_thumbnail_data (drawable->drawable_id,
197
 
                                                 &width, &height, &bpp);
 
325
                                                 &nav_width, &nav_height,
 
326
                                                 &bpp);
198
327
    }
199
328
 
200
329
  if (buffer)
201
330
    {
202
331
      GimpImageType  type;
203
332
 
204
 
      gtk_widget_set_size_request (GTK_WIDGET (area), width, height);
 
333
      gtk_widget_set_size_request (GTK_WIDGET (area), nav_width, nav_height);
205
334
      gtk_widget_show (GTK_WIDGET (area));
206
335
      gtk_widget_realize (GTK_WIDGET (area));
207
336
 
217
346
        }
218
347
 
219
348
      gimp_preview_area_draw (area,
220
 
                              0, 0, width, height,
221
 
                              type, buffer, bpp * width);
 
349
                              0, 0, nav_width, nav_height,
 
350
                              type, buffer, bpp * nav_width);
222
351
 
223
352
      g_free (buffer);
224
353
    }
225
354
}
226
355
 
227
 
static gboolean
228
 
gimp_rectangle_intersect (gint  x1,
229
 
                          gint  y1,
230
 
                          gint  width1,
231
 
                          gint  height1,
232
 
                          gint  x2,
233
 
                          gint  y2,
234
 
                          gint  width2,
235
 
                          gint  height2,
236
 
                          gint *dest_x,
237
 
                          gint *dest_y,
238
 
                          gint *dest_width,
239
 
                          gint *dest_height)
240
 
{
241
 
  gint d_x, d_y;
242
 
  gint d_w, d_h;
243
 
 
244
 
  d_x = MAX (x1, x2);
245
 
  d_y = MAX (y1, y2);
246
 
  d_w = MIN (x1 + width1,  x2 + width2)  - d_x;
247
 
  d_h = MIN (y1 + height1, y2 + height2) - d_y;
248
 
 
249
 
  if (dest_x)      *dest_x      = d_x;
250
 
  if (dest_y)      *dest_y      = d_y;
251
 
  if (dest_width)  *dest_width  = d_w;
252
 
  if (dest_height) *dest_height = d_h;
253
 
 
254
 
  return (d_w > 0 && d_h > 0);
255
 
}
256
 
 
257
356
static void
258
357
gimp_drawable_preview_draw_area (GimpDrawablePreview *preview,
259
358
                                 gint                 x,
331
430
                                  draw_height,
332
431
                                  gimp_drawable_type (drawable->drawable_id),
333
432
                                  src, draw_width * drawable->bpp,
334
 
                                  buf + (draw_x - x) + (draw_y - y) * rowstride,
 
433
                                  (buf +
 
434
                                   (draw_x - x) * drawable->bpp +
 
435
                                   (draw_y - y) * rowstride),
335
436
                                  rowstride,
336
437
                                  sel, draw_width);
337
438
 
365
466
 
366
467
  drawable_preview->drawable = drawable;
367
468
 
368
 
  gimp_drawable_preview_get_bounds (drawable, &x1, &y1, &x2, &y2);
 
469
  _gimp_drawable_preview_get_bounds (drawable, &x1, &y1, &x2, &y2);
369
470
 
370
471
  gimp_preview_set_bounds (preview, x1, y1, x2, y2);
371
472
 
386
487
#define MAX3(a, b, c)  (MAX (MAX ((a), (b)), (c)))
387
488
#define MIN3(a, b, c)  (MIN (MIN ((a), (b)), (c)))
388
489
 
389
 
static gboolean
390
 
gimp_drawable_preview_get_bounds (GimpDrawable *drawable,
391
 
                                  gint         *xmin,
392
 
                                  gint         *ymin,
393
 
                                  gint         *xmax,
394
 
                                  gint         *ymax)
 
490
gboolean
 
491
_gimp_drawable_preview_get_bounds (GimpDrawable *drawable,
 
492
                                   gint         *xmin,
 
493
                                   gint         *ymin,
 
494
                                   gint         *xmax,
 
495
                                   gint         *ymax)
395
496
{
396
497
  gint     width;
397
498
  gint     height;
401
502
  gint     x2, y2;
402
503
  gboolean retval;
403
504
 
 
505
  g_return_val_if_fail (drawable != NULL, FALSE);
 
506
 
404
507
  width  = gimp_drawable_width (drawable->drawable_id);
405
508
  height = gimp_drawable_height (drawable->drawable_id);
406
509
 
447
550
gimp_drawable_preview_new (GimpDrawable *drawable,
448
551
                           gboolean     *toggle)
449
552
{
450
 
  GimpDrawablePreview *preview;
 
553
  GtkWidget *preview;
451
554
 
452
555
  g_return_val_if_fail (drawable != NULL, NULL);
453
556
 
454
 
  preview = g_object_new (GIMP_TYPE_DRAWABLE_PREVIEW, NULL);
 
557
  preview = g_object_new (GIMP_TYPE_DRAWABLE_PREVIEW,
 
558
                          "drawable", drawable,
 
559
                          NULL);
455
560
 
456
561
  if (toggle)
457
562
    {
462
567
                        toggle);
463
568
    }
464
569
 
465
 
  gimp_drawable_preview_set_drawable (preview, drawable);
466
570
 
467
 
  return GTK_WIDGET (preview);
 
571
  return preview;
468
572
}
469
573
 
470
574
/**