1
/* The GIMP -- an image manipulation program
1
/* GIMP - The GNU Image Manipulation Program
2
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
4
* This program is free software; you can redistribute it and/or modify
50
GimpImage *gimage = GIMP_IMAGE (viewable);
52
GimpImage *image = GIMP_IMAGE (viewable);
52
if (! gimage->gimp->config->layer_previews && ! is_popup)
54
if (! image->gimp->config->layer_previews && ! is_popup)
59
gimp_viewable_calc_preview_size (gimage->width,
61
gimp_viewable_calc_preview_size (image->width,
77
79
gint *popup_height)
79
GimpImage *gimage = GIMP_IMAGE (viewable);
81
GimpImage *image = GIMP_IMAGE (viewable);
81
if (! gimage->gimp->config->layer_previews)
83
if (! image->gimp->config->layer_previews)
84
if (gimage->width > width || gimage->height > height)
86
if (image->width > width || image->height > height)
86
88
gboolean scaling_up;
88
gimp_viewable_calc_preview_size (gimage->width,
90
gimp_viewable_calc_preview_size (image->width,
92
94
dot_for_dot, 1.0, 1.0,
110
112
gimp_image_get_preview (GimpViewable *viewable,
113
GimpContext *context,
114
GimpImage *gimage = GIMP_IMAGE (viewable);
117
GimpImage *image = GIMP_IMAGE (viewable);
116
if (! gimage->gimp->config->layer_previews)
119
if (! image->gimp->config->layer_previews)
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)
123
126
/* The easy way */
124
return gimage->comp_preview;
127
return image->comp_preview;
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);
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.
136
gimage->comp_preview = gimp_image_get_new_preview (viewable,
139
gimage->comp_preview_valid = TRUE;
141
return gimage->comp_preview;
139
image->comp_preview = gimp_image_get_new_preview (viewable, context,
142
image->comp_preview_valid = TRUE;
144
return image->comp_preview;
146
149
gimp_image_get_new_preview (GimpViewable *viewable,
150
GimpContext *context,
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;
168
gimage = GIMP_IMAGE (viewable);
172
image = GIMP_IMAGE (viewable);
170
if (! gimage->gimp->config->layer_previews)
174
if (! image->gimp->config->layer_previews)
173
ratio = (gdouble) width / (gdouble) gimage->width;
177
ratio = (gdouble) width / (gdouble) image->width;
175
switch (gimp_image_base_type (gimage))
179
switch (gimp_image_base_type (image))
178
182
case GIMP_INDEXED:
202
206
/* only add layers that are visible to the list */
203
207
if (gimp_item_get_visible (GIMP_ITEM (layer)))
205
/* floating selections are added right above the layer
206
* they are attached to
208
if (gimp_layer_is_floating_sel (layer))
210
floating_sel = layer;
215
floating_sel->fs.drawable == GIMP_DRAWABLE (layer))
217
reverse_list = g_slist_prepend (reverse_list, floating_sel);
209
/* floating selections are added right above the layer
210
* they are attached to
212
if (gimp_layer_is_floating_sel (layer))
214
floating_sel = layer;
219
floating_sel->fs.drawable == GIMP_DRAWABLE (layer))
221
reverse_list = g_slist_prepend (reverse_list, floating_sel);
220
reverse_list = g_slist_prepend (reverse_list, layer);
224
reverse_list = g_slist_prepend (reverse_list, layer);
225
229
construct_flag = FALSE;
238
242
gimp_item_width (GIMP_ITEM (layer)),
239
243
gimp_item_height (GIMP_ITEM (layer)),
241
gimage->width, gimage->height,
245
image->width, image->height,
243
247
&src_width, &src_height))
262
266
y2 = CLAMP (y + h, 0, height);
264
268
if (x2 == x1 || y2 == y1)
267
src1PR.bytes = comp->bytes;
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);
276
274
if (use_sub_preview)
284
282
g_assert (layer_buf);
285
283
g_assert (layer_buf->bytes <= comp->bytes);
287
src2PR.bytes = layer_buf->bytes;
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);
297
layer_buf = gimp_viewable_get_preview (GIMP_VIEWABLE (layer), w, h);
290
layer_buf = gimp_viewable_get_preview (GIMP_VIEWABLE (layer),
299
293
g_assert (layer_buf);
300
294
g_assert (layer_buf->bytes <= comp->bytes);
302
src2PR.bytes = layer_buf->bytes;
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);
313
300
if (layer->mask && layer->mask->apply_mask)
315
302
if (use_sub_preview)
324
maskPR.bytes = mask_buf->bytes;
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);
334
316
mask_buf = gimp_viewable_get_preview (GIMP_VIEWABLE (layer->mask),
337
maskPR.bytes = mask_buf->bytes;
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);
356
331
/* Based on the type of the layer, project the layer onto the
357
332
* composite preview...
363
338
if (gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))
365
if (! construct_flag)
366
initial_region (&src2PR, &src1PR,
340
if (! construct_flag)
341
initial_region (&src2PR, &src1PR,
368
343
layer->opacity * 255.999,
370
345
visible_components,
371
346
INITIAL_INTENSITY_ALPHA);
373
combine_regions (&src1PR, &src2PR, &src1PR,
348
combine_regions (&src1PR, &src2PR, &src1PR,
375
350
layer->opacity * 255.999,
377
352
visible_components,
378
353
COMBINE_INTEN_A_INTEN_A);
382
if (! construct_flag)
383
initial_region (&src2PR, &src1PR,
357
if (! construct_flag)
358
initial_region (&src2PR, &src1PR,
385
360
layer->opacity * 255.999,
387
362
visible_components,
388
363
INITIAL_INTENSITY);
390
combine_regions (&src1PR, &src2PR, &src1PR,
365
combine_regions (&src1PR, &src2PR, &src1PR,
392
367
layer->opacity * 255.999,
394
369
visible_components,
395
370
COMBINE_INTEN_A_INTEN);