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

« back to all changes in this revision

Viewing changes to app/core/gimpimage-preview.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
20
20
 
21
21
#include <glib-object.h>
22
22
 
 
23
#include "libgimpbase/gimpbase.h"
 
24
#include "libgimpmath/gimpmath.h"
 
25
 
23
26
#include "core-types.h"
24
27
 
25
28
#include "base/pixel-region.h"
30
33
#include "config/gimpcoreconfig.h"
31
34
 
32
35
#include "gimp.h"
33
 
#include "gimp-utils.h"
34
36
#include "gimpdrawable-preview.h"
35
37
#include "gimpimage.h"
36
38
#include "gimpimage-preview.h"
47
49
                             gint         *width,
48
50
                             gint         *height)
49
51
{
50
 
  GimpImage *gimage = GIMP_IMAGE (viewable);
 
52
  GimpImage *image = GIMP_IMAGE (viewable);
51
53
 
52
 
  if (! gimage->gimp->config->layer_previews && ! is_popup)
 
54
  if (! image->gimp->config->layer_previews && ! is_popup)
53
55
    {
54
56
      *width  = size;
55
57
      *height = size;
56
58
      return;
57
59
    }
58
60
 
59
 
  gimp_viewable_calc_preview_size (gimage->width,
60
 
                                   gimage->height,
 
61
  gimp_viewable_calc_preview_size (image->width,
 
62
                                   image->height,
61
63
                                   size,
62
64
                                   size,
63
65
                                   dot_for_dot,
64
 
                                   gimage->xresolution,
65
 
                                   gimage->yresolution,
 
66
                                   image->xresolution,
 
67
                                   image->yresolution,
66
68
                                   width,
67
69
                                   height,
68
70
                                   NULL);
76
78
                           gint         *popup_width,
77
79
                           gint         *popup_height)
78
80
{
79
 
  GimpImage *gimage = GIMP_IMAGE (viewable);
 
81
  GimpImage *image = GIMP_IMAGE (viewable);
80
82
 
81
 
  if (! gimage->gimp->config->layer_previews)
 
83
  if (! image->gimp->config->layer_previews)
82
84
    return FALSE;
83
85
 
84
 
  if (gimage->width > width || gimage->height > height)
 
86
  if (image->width > width || image->height > height)
85
87
    {
86
88
      gboolean scaling_up;
87
89
 
88
 
      gimp_viewable_calc_preview_size (gimage->width,
89
 
                                       gimage->height,
 
90
      gimp_viewable_calc_preview_size (image->width,
 
91
                                       image->height,
90
92
                                       width  * 2,
91
93
                                       height * 2,
92
94
                                       dot_for_dot, 1.0, 1.0,
96
98
 
97
99
      if (scaling_up)
98
100
        {
99
 
          *popup_width  = gimage->width;
100
 
          *popup_height = gimage->height;
 
101
          *popup_width  = image->width;
 
102
          *popup_height = image->height;
101
103
        }
102
104
 
103
105
      return TRUE;
108
110
 
109
111
TempBuf *
110
112
gimp_image_get_preview (GimpViewable *viewable,
111
 
                        gint          width,
112
 
                        gint          height)
 
113
                        GimpContext  *context,
 
114
                        gint          width,
 
115
                        gint          height)
113
116
{
114
 
  GimpImage *gimage = GIMP_IMAGE (viewable);
 
117
  GimpImage *image = GIMP_IMAGE (viewable);
115
118
 
116
 
  if (! gimage->gimp->config->layer_previews)
 
119
  if (! image->gimp->config->layer_previews)
117
120
    return NULL;
118
121
 
119
 
  if (gimage->comp_preview_valid            &&
120
 
      gimage->comp_preview->width  == width &&
121
 
      gimage->comp_preview->height == height)
 
122
  if (image->comp_preview_valid            &&
 
123
      image->comp_preview->width  == width &&
 
124
      image->comp_preview->height == height)
122
125
    {
123
126
      /*  The easy way  */
124
 
      return gimage->comp_preview;
 
127
      return image->comp_preview;
125
128
    }
126
129
  else
127
130
    {
128
131
      /*  The hard way  */
129
 
      if (gimage->comp_preview)
130
 
        temp_buf_free (gimage->comp_preview);
 
132
      if (image->comp_preview)
 
133
        temp_buf_free (image->comp_preview);
131
134
 
132
135
      /*  Actually construct the composite preview from the layer previews!
133
136
       *  This might seem ridiculous, but it's actually the best way, given
134
137
       *  a number of unsavory alternatives.
135
138
       */
136
 
      gimage->comp_preview = gimp_image_get_new_preview (viewable,
137
 
                                                         width, height);
138
 
 
139
 
      gimage->comp_preview_valid = TRUE;
140
 
 
141
 
      return gimage->comp_preview;
 
139
      image->comp_preview = gimp_image_get_new_preview (viewable, context,
 
140
                                                        width, height);
 
141
 
 
142
      image->comp_preview_valid = TRUE;
 
143
 
 
144
      return image->comp_preview;
142
145
    }
143
146
}
144
147
 
145
148
TempBuf *
146
149
gimp_image_get_new_preview (GimpViewable *viewable,
147
 
                            gint          width,
148
 
                            gint          height)
 
150
                            GimpContext  *context,
 
151
                            gint          width,
 
152
                            gint          height)
149
153
{
150
 
  GimpImage   *gimage;
 
154
  GimpImage   *image;
151
155
  GimpLayer   *layer;
152
156
  GimpLayer   *floating_sel;
153
157
  PixelRegion  src1PR, src2PR, maskPR;
165
169
  gboolean     visible_components[MAX_CHANNELS] = { TRUE, TRUE, TRUE, TRUE };
166
170
  gint         off_x, off_y;
167
171
 
168
 
  gimage = GIMP_IMAGE (viewable);
 
172
  image = GIMP_IMAGE (viewable);
169
173
 
170
 
  if (! gimage->gimp->config->layer_previews)
 
174
  if (! image->gimp->config->layer_previews)
171
175
    return NULL;
172
176
 
173
 
  ratio = (gdouble) width / (gdouble) gimage->width;
 
177
  ratio = (gdouble) width / (gdouble) image->width;
174
178
 
175
 
  switch (gimp_image_base_type (gimage))
 
179
  switch (gimp_image_base_type (image))
176
180
    {
177
181
    case GIMP_RGB:
178
182
    case GIMP_INDEXED:
193
197
 
194
198
  floating_sel = NULL;
195
199
 
196
 
  for (list = GIMP_LIST (gimage->layers)->list;
 
200
  for (list = GIMP_LIST (image->layers)->list;
197
201
       list;
198
202
       list = g_list_next (list))
199
203
    {
201
205
 
202
206
      /*  only add layers that are visible to the list  */
203
207
      if (gimp_item_get_visible (GIMP_ITEM (layer)))
204
 
        {
205
 
          /*  floating selections are added right above the layer
206
 
           *  they are attached to
207
 
           */
208
 
          if (gimp_layer_is_floating_sel (layer))
209
 
            {
210
 
              floating_sel = layer;
211
 
            }
212
 
          else
213
 
            {
214
 
              if (floating_sel &&
215
 
                  floating_sel->fs.drawable == GIMP_DRAWABLE (layer))
216
 
                {
217
 
                  reverse_list = g_slist_prepend (reverse_list, floating_sel);
218
 
                }
 
208
        {
 
209
          /*  floating selections are added right above the layer
 
210
           *  they are attached to
 
211
           */
 
212
          if (gimp_layer_is_floating_sel (layer))
 
213
            {
 
214
              floating_sel = layer;
 
215
            }
 
216
          else
 
217
            {
 
218
              if (floating_sel &&
 
219
                  floating_sel->fs.drawable == GIMP_DRAWABLE (layer))
 
220
                {
 
221
                  reverse_list = g_slist_prepend (reverse_list, floating_sel);
 
222
                }
219
223
 
220
 
              reverse_list = g_slist_prepend (reverse_list, layer);
221
 
            }
222
 
        }
 
224
              reverse_list = g_slist_prepend (reverse_list, layer);
 
225
            }
 
226
        }
223
227
    }
224
228
 
225
229
  construct_flag = FALSE;
238
242
                                      gimp_item_width  (GIMP_ITEM (layer)),
239
243
                                      gimp_item_height (GIMP_ITEM (layer)),
240
244
                                      -off_x, -off_y,
241
 
                                      gimage->width, gimage->height,
 
245
                                      image->width, image->height,
242
246
                                      &src_x, &src_y,
243
247
                                      &src_width, &src_height))
244
248
        {
251
255
      h = (gint) RINT (ratio * gimp_item_height (GIMP_ITEM (layer)));
252
256
 
253
257
      if (w < 1 || h < 1)
254
 
        continue;
 
258
        continue;
255
259
 
256
260
      if ((w * h) > (width * height * 4))
257
261
        use_sub_preview = TRUE;
262
266
      y2 = CLAMP (y + h, 0, height);
263
267
 
264
268
      if (x2 == x1 || y2 == y1)
265
 
        continue;
 
269
        continue;
266
270
 
267
 
      src1PR.bytes     = comp->bytes;
268
 
      src1PR.x         = x1;
269
 
      src1PR.y         = y1;
270
 
      src1PR.w         = (x2 - x1);
271
 
      src1PR.h         = (y2 - y1);
272
 
      src1PR.rowstride = comp->width * src1PR.bytes;
273
 
      src1PR.data      = (temp_buf_data (comp) +
274
 
                          y1 * src1PR.rowstride + x1 * src1PR.bytes);
 
271
      pixel_region_init_temp_buf (&src1PR, comp,
 
272
                                  x1, y1, x2 - x1, y2 - y1);
275
273
 
276
274
      if (use_sub_preview)
277
275
        {
284
282
          g_assert (layer_buf);
285
283
          g_assert (layer_buf->bytes <= comp->bytes);
286
284
 
287
 
          src2PR.bytes     = layer_buf->bytes;
288
 
          src2PR.x         = 0;
289
 
          src2PR.y         = 0;
290
 
          src2PR.w         = src1PR.w;
291
 
          src2PR.h         = src1PR.h;
292
 
          src2PR.rowstride = layer_buf->width * src2PR.bytes;
293
 
          src2PR.data      = temp_buf_data (layer_buf);
 
285
          pixel_region_init_temp_buf (&src2PR, layer_buf,
 
286
                                      0, 0, src1PR.w, src1PR.h);
294
287
        }
295
288
      else
296
289
        {
297
 
          layer_buf = gimp_viewable_get_preview (GIMP_VIEWABLE (layer), w, h);
 
290
          layer_buf = gimp_viewable_get_preview (GIMP_VIEWABLE (layer),
 
291
                                                 context, w, h);
298
292
 
299
293
          g_assert (layer_buf);
300
294
          g_assert (layer_buf->bytes <= comp->bytes);
301
295
 
302
 
          src2PR.bytes     = layer_buf->bytes;
303
 
          src2PR.x         = src1PR.x;
304
 
          src2PR.y         = src1PR.y;
305
 
          src2PR.w         = src1PR.w;
306
 
          src2PR.h         = src1PR.h;
307
 
          src2PR.rowstride = layer_buf->width * src2PR.bytes;
308
 
          src2PR.data      = (temp_buf_data (layer_buf) +
309
 
                              (y1 - y) * src2PR.rowstride +
310
 
                              (x1 - x) * src2PR.bytes);
 
296
          pixel_region_init_temp_buf (&src2PR, layer_buf,
 
297
                                      x1 - x, y1 - y, src1PR.w, src1PR.h);
311
298
        }
312
299
 
313
300
      if (layer->mask && layer->mask->apply_mask)
314
 
        {
 
301
        {
315
302
          if (use_sub_preview)
316
303
            {
317
304
              mask_buf =
321
308
                                               x2 - x1,
322
309
                                               y2 - y1);
323
310
 
324
 
              maskPR.bytes     = mask_buf->bytes;
325
 
              maskPR.x         = 0;
326
 
              maskPR.y         = 0;
327
 
              maskPR.w         = src1PR.w;
328
 
              maskPR.h         = src1PR.h;
329
 
              maskPR.rowstride = mask_buf->width * mask_buf->bytes;
330
 
              maskPR.data      = mask_buf_data (mask_buf);
 
311
              pixel_region_init_temp_buf (&maskPR, mask_buf,
 
312
                                          0, 0, src1PR.w, maskPR.h);
331
313
            }
332
314
          else
333
315
            {
334
316
              mask_buf = gimp_viewable_get_preview (GIMP_VIEWABLE (layer->mask),
335
 
                                                    w, h);
 
317
                                                    context, w, h);
336
318
 
337
 
              maskPR.bytes     = mask_buf->bytes;
338
 
              maskPR.x         = src1PR.x;
339
 
              maskPR.y         = src1PR.y;
340
 
              maskPR.w         = src1PR.w;
341
 
              maskPR.h         = src1PR.h;
342
 
              maskPR.rowstride = mask_buf->width * mask_buf->bytes;
343
 
              maskPR.data      = (mask_buf_data (mask_buf) +
344
 
                                  (y1 - y) * maskPR.rowstride +
345
 
                                  (x1 - x) * maskPR.bytes);
 
319
              pixel_region_init_temp_buf (&maskPR, mask_buf,
 
320
                                          x1 - x, y1 - y, src1PR.w, maskPR.h);
346
321
            }
347
322
 
348
323
          mask = &maskPR;
349
 
        }
 
324
        }
350
325
      else
351
 
        {
 
326
        {
352
327
          mask_buf = NULL;
353
 
          mask     = NULL;
354
 
        }
 
328
          mask     = NULL;
 
329
        }
355
330
 
356
331
      /*  Based on the type of the layer, project the layer onto the
357
332
       *   composite preview...
361
336
       *   for previews
362
337
       */
363
338
      if (gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))
364
 
        {
365
 
          if (! construct_flag)
366
 
            initial_region (&src2PR, &src1PR,
367
 
                            mask, NULL,
 
339
        {
 
340
          if (! construct_flag)
 
341
            initial_region (&src2PR, &src1PR,
 
342
                            mask, NULL,
368
343
                            layer->opacity * 255.999,
369
 
                            layer->mode,
 
344
                            layer->mode,
370
345
                            visible_components,
371
346
                            INITIAL_INTENSITY_ALPHA);
372
 
          else
373
 
            combine_regions (&src1PR, &src2PR, &src1PR,
374
 
                             mask, NULL,
 
347
          else
 
348
            combine_regions (&src1PR, &src2PR, &src1PR,
 
349
                             mask, NULL,
375
350
                             layer->opacity * 255.999,
376
 
                             layer->mode,
 
351
                             layer->mode,
377
352
                             visible_components,
378
353
                             COMBINE_INTEN_A_INTEN_A);
379
354
        }
380
355
      else
381
356
        {
382
 
          if (! construct_flag)
383
 
            initial_region (&src2PR, &src1PR,
384
 
                            mask, NULL,
 
357
          if (! construct_flag)
 
358
            initial_region (&src2PR, &src1PR,
 
359
                            mask, NULL,
385
360
                            layer->opacity * 255.999,
386
 
                            layer->mode,
 
361
                            layer->mode,
387
362
                            visible_components,
388
363
                            INITIAL_INTENSITY);
389
 
          else
390
 
            combine_regions (&src1PR, &src2PR, &src1PR,
391
 
                             mask, NULL,
 
364
          else
 
365
            combine_regions (&src1PR, &src2PR, &src1PR,
 
366
                             mask, NULL,
392
367
                             layer->opacity * 255.999,
393
 
                             layer->mode,
 
368
                             layer->mode,
394
369
                             visible_components,
395
370
                             COMBINE_INTEN_A_INTEN);
396
371
        }