93
95
g_return_if_fail (GIMP_IS_PROJECTION (proj));
99
/* set the construct flag, used to determine if anything
100
* has been written to the gimage raw image yet.
102
gimage->construct_flag = FALSE;
106
gimp_item_offsets (GIMP_ITEM (gimage->layers->data), &xoff, &yoff);
109
if ((gimage->layers) && /* There's a layer. */
110
(! g_slist_next (gimage->layers)) && /* It's the only layer. */
111
(gimp_drawable_has_alpha (GIMP_DRAWABLE (gimage->layers->data))) &&
113
(gimp_item_get_visible (GIMP_ITEM (gimage->layers->data))) &&
115
(gimp_item_width (GIMP_ITEM (gimage->layers->data)) ==
117
(gimp_item_height (GIMP_ITEM (gimage->layers->data)) ==
118
gimage->height) && /* Covers all. */
119
(!gimp_drawable_is_indexed (GIMP_DRAWABLE (gimage->layers->data))) &&
121
(((GimpLayer *)(gimage->layers->data))->opacity == GIMP_OPACITY_OPAQUE)
128
gimp_item_offsets (GIMP_ITEM (gimage->layers->data), &xoff, &yoff);
130
if ((xoff==0) && (yoff==0)) /* Starts at 0,0 */
132
PixelRegion srcPR, destPR;
135
g_warning("Can use cow-projection hack. Yay!");
137
pixel_region_init (&srcPR, gimp_drawable_data
138
(GIMP_DRAWABLE (gimage->layers->data)),
140
pixel_region_init (&destPR,
141
gimp_image_projection (gimage),
144
for (pr = pixel_regions_register (2, &srcPR, &destPR);
146
pr = pixel_regions_process (pr))
148
tile_manager_map_over_tile (destPR.tiles,
149
destPR.curtile, srcPR.curtile);
152
gimage->construct_flag = TRUE;
153
gimp_image_construct_channels (gimage, x, y, w, h);
98
GimpImage *image = proj->image;
100
if ((gimp_container_num_children (image->layers) == 1)) /* a single layer */
104
layer = GIMP_DRAWABLE (gimp_container_get_child_by_index (image->layers,
107
if (gimp_drawable_has_alpha (layer) &&
108
(gimp_item_get_visible (GIMP_ITEM (layer))) &&
109
(gimp_item_width (GIMP_ITEM (layer)) == image->width) &&
110
(gimp_item_height (GIMP_ITEM (layer)) == image->height) &&
111
(! gimp_drawable_is_indexed (layer)) &&
112
(gimp_layer_get_opacity (GIMP_LAYER (layer)) == GIMP_OPACITY_OPAQUE))
117
gimp_item_offsets (GIMP_ITEM (layer), &xoff, &yoff);
119
if (xoff == 0 && yoff == 0)
121
PixelRegion srcPR, destPR;
123
g_printerr ("cow-projection!");
125
pixel_region_init (&srcPR, gimp_drawable_get_tiles (layer),
127
pixel_region_init (&destPR, gimp_projection_get_tiles (proj),
130
copy_region (&srcPR, &destPR);
132
proj->construct_flag = TRUE;
134
gimp_projection_construct_channels (proj, x, y, w, h);
159
142
proj->construct_flag = FALSE;
162
144
/* First, determine if the projection image needs to be
163
145
* initialized--this is the case when there are no visible
188
PixelRegion src1PR, src2PR, maskPR;
195
175
/* composite the floating selection if it exists */
196
if ((layer = gimp_image_floating_sel (proj->gimage)))
176
if ((layer = gimp_image_floating_sel (proj->image)))
197
177
floating_sel_composite (layer, x, y, w, h, FALSE);
199
179
reverse_list = NULL;
201
for (list = GIMP_LIST (proj->gimage->layers)->list;
181
for (list = GIMP_LIST (proj->image->layers)->list;
203
183
list = g_list_next (list))
205
layer = (GimpLayer *) list->data;
207
187
/* only add layers that are visible and not floating selections
210
190
if (! gimp_layer_is_floating_sel (layer) &&
211
gimp_item_get_visible (GIMP_ITEM (layer)))
213
reverse_list = g_list_prepend (reverse_list, layer);
191
gimp_item_get_visible (GIMP_ITEM (layer)))
193
reverse_list = g_list_prepend (reverse_list, layer);
217
197
for (list = reverse_list; list; list = g_list_next (list))
219
layer = (GimpLayer *) list->data;
221
205
gimp_item_offsets (GIMP_ITEM (layer), &off_x, &off_y);
228
212
/* configure the pixel regions */
229
213
pixel_region_init (&src1PR, gimp_projection_get_tiles (proj),
230
x1, y1, (x2 - x1), (y2 - y1),
214
x1, y1, (x2 - x1), (y2 - y1),
233
217
/* If we're showing the layer mask instead of the layer... */
234
218
if (layer->mask && layer->mask->show_mask)
236
pixel_region_init (&src2PR,
237
gimp_drawable_data (GIMP_DRAWABLE (layer->mask)),
238
(x1 - off_x), (y1 - off_y),
239
(x2 - x1), (y2 - y1), FALSE);
220
pixel_region_init (&src2PR,
221
gimp_drawable_get_tiles (GIMP_DRAWABLE (layer->mask)),
222
(x1 - off_x), (y1 - off_y),
223
(x2 - x1), (y2 - y1), FALSE);
241
copy_gray_to_region (&src2PR, &src1PR);
225
copy_gray_to_region (&src2PR, &src1PR);
243
227
/* Otherwise, normal */
246
pixel_region_init (&src2PR,
247
gimp_drawable_data (GIMP_DRAWABLE (layer)),
248
(x1 - off_x), (y1 - off_y),
249
(x2 - x1), (y2 - y1), FALSE);
251
if (layer->mask && layer->mask->apply_mask)
253
pixel_region_init (&maskPR,
254
gimp_drawable_data (GIMP_DRAWABLE (layer->mask)),
255
(x1 - off_x), (y1 - off_y),
256
(x2 - x1), (y2 - y1), FALSE);
262
/* Based on the type of the layer, project the layer onto the
263
* projection image...
265
switch (gimp_drawable_type (GIMP_DRAWABLE (layer)))
267
case GIMP_RGB_IMAGE: case GIMP_GRAY_IMAGE:
268
/* no mask possible */
269
project_intensity (proj, layer, &src2PR, &src1PR, mask);
272
case GIMP_RGBA_IMAGE: case GIMP_GRAYA_IMAGE:
273
project_intensity_alpha (proj, layer, &src2PR, &src1PR, mask);
276
case GIMP_INDEXED_IMAGE:
277
/* no mask possible */
278
project_indexed (proj, layer, &src2PR, &src1PR);
281
case GIMP_INDEXEDA_IMAGE:
282
project_indexed_alpha (proj, layer, &src2PR, &src1PR, mask);
230
PixelRegion *mask = NULL;
232
pixel_region_init (&src2PR,
233
gimp_drawable_get_tiles (GIMP_DRAWABLE (layer)),
234
(x1 - off_x), (y1 - off_y),
235
(x2 - x1), (y2 - y1), FALSE);
237
if (layer->mask && layer->mask->apply_mask)
239
pixel_region_init (&maskPR,
240
gimp_drawable_get_tiles (GIMP_DRAWABLE (layer->mask)),
241
(x1 - off_x), (y1 - off_y),
242
(x2 - x1), (y2 - y1), FALSE);
246
/* Based on the type of the layer, project the layer onto the
247
* projection image...
249
switch (gimp_drawable_type (GIMP_DRAWABLE (layer)))
252
case GIMP_GRAY_IMAGE:
253
project_intensity (proj, layer, &src2PR, &src1PR, mask);
256
case GIMP_RGBA_IMAGE:
257
case GIMP_GRAYA_IMAGE:
258
project_intensity_alpha (proj, layer, &src2PR, &src1PR, mask);
261
case GIMP_INDEXED_IMAGE:
262
project_indexed (proj, layer, &src2PR, &src1PR, mask);
265
case GIMP_INDEXEDA_IMAGE:
266
project_indexed_alpha (proj, layer, &src2PR, &src1PR, mask);
290
274
proj->construct_flag = TRUE; /* something was projected */
317
298
for (list = reverse_list; list; list = g_list_next (list))
319
channel = (GimpChannel *) list->data;
300
GimpChannel *channel = list->data;
321
302
if (gimp_item_get_visible (GIMP_ITEM (channel)))
323
/* configure the pixel regions */
324
pixel_region_init (&src1PR,
325
gimp_projection_get_tiles (proj),
328
pixel_region_init (&src2PR,
329
gimp_drawable_data (GIMP_DRAWABLE (channel)),
333
project_channel (proj, channel, &src1PR, &src2PR);
335
proj->construct_flag = TRUE;
307
/* configure the pixel regions */
308
pixel_region_init (&src1PR,
309
gimp_projection_get_tiles (proj),
312
pixel_region_init (&src2PR,
313
gimp_drawable_get_tiles (GIMP_DRAWABLE (channel)),
317
project_channel (proj, channel, &src1PR, &src2PR);
319
proj->construct_flag = TRUE;
339
323
g_list_free (reverse_list);
382
366
guchar clear[4] = { 0, 0, 0, 0 };
384
368
pixel_region_init (&PR, gimp_projection_get_tiles (proj),
386
370
color_region (&PR, clear);
391
375
project_intensity (GimpProjection *proj,
397
381
if (! proj->construct_flag)
398
382
initial_region (src, dest, mask, NULL,
399
383
layer->opacity * 255.999,
401
proj->gimage->visible,
385
proj->image->visible,
402
386
INITIAL_INTENSITY);
404
388
combine_regions (dest, src, dest, mask, NULL,
405
389
layer->opacity * 255.999,
407
proj->gimage->visible,
391
proj->image->visible,
408
392
COMBINE_INTEN_A_INTEN);
412
396
project_intensity_alpha (GimpProjection *proj,
418
402
if (! proj->construct_flag)
419
403
initial_region (src, dest, mask, NULL,
420
404
layer->opacity * 255.999,
422
proj->gimage->visible,
406
proj->image->visible,
423
407
INITIAL_INTENSITY_ALPHA);
425
409
combine_regions (dest, src, dest, mask, NULL,
426
410
layer->opacity * 255.999,
428
proj->gimage->visible,
412
proj->image->visible,
429
413
COMBINE_INTEN_A_INTEN_A);
433
417
project_indexed (GimpProjection *proj,
438
g_return_if_fail (proj->gimage->cmap != NULL);
423
g_return_if_fail (proj->image->cmap != NULL);
440
425
if (! proj->construct_flag)
441
initial_region (src, dest, NULL, proj->gimage->cmap,
426
initial_region (src, dest, mask, proj->image->cmap,
442
427
layer->opacity * 255.999,
444
proj->gimage->visible,
429
proj->image->visible,
445
430
INITIAL_INDEXED);
447
g_warning ("%s: unable to project indexed image.", G_STRFUNC);
432
combine_regions (dest, src, dest, mask, proj->image->cmap,
433
layer->opacity * 255.999,
435
proj->image->visible,
436
COMBINE_INTEN_A_INDEXED);
451
440
project_indexed_alpha (GimpProjection *proj,
457
g_return_if_fail (proj->gimage->cmap != NULL);
446
g_return_if_fail (proj->image->cmap != NULL);
459
448
if (! proj->construct_flag)
460
initial_region (src, dest, mask, proj->gimage->cmap,
449
initial_region (src, dest, mask, proj->image->cmap,
461
450
layer->opacity * 255.999,
463
proj->gimage->visible,
452
proj->image->visible,
464
453
INITIAL_INDEXED_ALPHA);
466
combine_regions (dest, src, dest, mask, proj->gimage->cmap,
455
combine_regions (dest, src, dest, mask, proj->image->cmap,
467
456
layer->opacity * 255.999,
469
proj->gimage->visible,
458
proj->image->visible,
470
459
COMBINE_INTEN_A_INDEXED_A);
474
463
project_channel (GimpProjection *proj,
475
GimpChannel *channel,
464
GimpChannel *channel,
483
472
gimp_rgba_get_uchar (&channel->color,
484
&col[0], &col[1], &col[2], &opacity);
473
&col[0], &col[1], &col[2], &opacity);
486
475
if (! proj->construct_flag)
488
477
type = (channel->show_masked) ?
489
INITIAL_CHANNEL_MASK : INITIAL_CHANNEL_SELECTION;
478
INITIAL_CHANNEL_MASK : INITIAL_CHANNEL_SELECTION;
491
480
initial_region (src2, src, NULL, col,