86
96
(* callback) (gimp,
88
98
GIMP_TYPE_CLONE_OPTIONS,
93
gimp_clone_get_type (void)
95
static GType type = 0;
99
static const GTypeInfo info =
101
sizeof (GimpCloneClass),
102
(GBaseInitFunc) NULL,
103
(GBaseFinalizeFunc) NULL,
104
(GClassInitFunc) gimp_clone_class_init,
105
NULL, /* class_finalize */
106
NULL, /* class_data */
109
(GInstanceInitFunc) gimp_clone_init,
112
type = g_type_register_static (GIMP_TYPE_BRUSH_CORE,
121
105
gimp_clone_class_init (GimpCloneClass *klass)
123
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
124
GimpBrushCoreClass *brush_core_class = GIMP_BRUSH_CORE_CLASS (klass);
126
parent_class = g_type_class_peek_parent (klass);
128
paint_core_class->paint = gimp_clone_paint;
130
brush_core_class->handles_changing_brush = TRUE;
107
GimpPaintCoreClass *paint_core_class = GIMP_PAINT_CORE_CLASS (klass);
108
GimpSourceCoreClass *source_core_class = GIMP_SOURCE_CORE_CLASS (klass);
110
paint_core_class->start = gimp_clone_start;
112
source_core_class->motion = gimp_clone_motion;
134
116
gimp_clone_init (GimpClone *clone)
136
clone->set_source = FALSE;
138
clone->src_drawable = NULL;
142
clone->orig_src_x = 0;
143
clone->orig_src_y = 0;
147
clone->first_stroke = TRUE;
151
gimp_clone_paint (GimpPaintCore *paint_core,
152
GimpDrawable *drawable,
153
GimpPaintOptions *paint_options,
154
GimpPaintState paint_state,
121
gimp_clone_start (GimpPaintCore *paint_core,
122
GimpDrawable *drawable,
123
GimpPaintOptions *paint_options,
157
GimpClone *clone = GIMP_CLONE (paint_core);
158
127
GimpCloneOptions *options = GIMP_CLONE_OPTIONS (paint_options);
159
GimpContext *context = GIMP_CONTEXT (paint_options);
163
case GIMP_PAINT_STATE_INIT:
164
if (clone->set_source)
166
gimp_clone_set_src_drawable (clone, drawable);
168
clone->src_x = paint_core->cur_coords.x;
169
clone->src_y = paint_core->cur_coords.y;
171
clone->first_stroke = TRUE;
173
else if (options->align_mode == GIMP_CLONE_ALIGN_NO)
175
clone->orig_src_x = clone->src_x;
176
clone->orig_src_y = clone->src_y;
178
clone->first_stroke = TRUE;
181
if (options->clone_type == GIMP_PATTERN_CLONE)
182
if (! gimp_context_get_pattern (context))
183
g_message (_("No patterns available for this operation."));
186
case GIMP_PAINT_STATE_MOTION:
187
if (clone->set_source)
189
/* If the control key is down, move the src target and return */
191
clone->src_x = paint_core->cur_coords.x;
192
clone->src_y = paint_core->cur_coords.y;
194
clone->first_stroke = TRUE;
198
/* otherwise, update the target */
203
dest_x = paint_core->cur_coords.x;
204
dest_y = paint_core->cur_coords.y;
206
if (options->align_mode == GIMP_CLONE_ALIGN_REGISTERED)
211
else if (clone->first_stroke)
213
clone->offset_x = clone->src_x - dest_x;
214
clone->offset_y = clone->src_y - dest_y;
216
clone->first_stroke = FALSE;
219
clone->src_x = dest_x + clone->offset_x;
220
clone->src_y = dest_y + clone->offset_y;
222
gimp_clone_motion (paint_core, drawable, paint_options);
226
case GIMP_PAINT_STATE_FINISH:
227
if (options->align_mode == GIMP_CLONE_ALIGN_NO && ! clone->first_stroke)
229
clone->src_x = clone->orig_src_x;
230
clone->src_y = clone->orig_src_y;
129
if (! GIMP_PAINT_CORE_CLASS (parent_class)->start (paint_core, drawable,
130
paint_options, coords,
136
if (options->clone_type == GIMP_PATTERN_CLONE)
138
if (! gimp_context_get_pattern (GIMP_CONTEXT (options)))
140
g_set_error (error, 0, 0,
141
_("No patterns available for use with this tool."));
240
gimp_clone_motion (GimpPaintCore *paint_core,
150
gimp_clone_motion (GimpSourceCore *source_core,
241
151
GimpDrawable *drawable,
242
GimpPaintOptions *paint_options)
152
GimpPaintOptions *paint_options,
154
GimpPickable *src_pickable,
159
gint paint_area_offset_x,
160
gint paint_area_offset_y,
161
gint paint_area_width,
162
gint paint_area_height)
244
GimpClone *clone = GIMP_CLONE (paint_core);
245
GimpCloneOptions *options = GIMP_CLONE_OPTIONS (paint_options);
246
GimpContext *context = GIMP_CONTEXT (paint_options);
247
GimpPressureOptions *pressure_options = paint_options->pressure_options;
249
GimpImage *src_gimage = NULL;
257
PixelRegion srcPR, destPR;
258
GimpPattern *pattern = NULL;
263
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
265
opacity = gimp_paint_options_get_fade (paint_options, gimage,
266
paint_core->pixel_dist);
270
/* make local copies because we change them */
271
offset_x = clone->offset_x;
272
offset_y = clone->offset_y;
274
/* Make sure we still have a source if we are doing image cloning */
275
if (options->clone_type == GIMP_IMAGE_CLONE)
277
if (! clone->src_drawable)
280
if (! (src_gimage = gimp_item_get_image (GIMP_ITEM (clone->src_drawable))))
283
/* Determine whether the source image has an alpha channel */
284
has_alpha = gimp_drawable_has_alpha (clone->src_drawable);
287
area = gimp_paint_core_get_paint_area (paint_core, drawable, paint_options);
164
GimpPaintCore *paint_core = GIMP_PAINT_CORE (source_core);
165
GimpCloneOptions *options = GIMP_CLONE_OPTIONS (paint_options);
166
GimpSourceOptions *source_options = GIMP_SOURCE_OPTIONS (paint_options);
167
GimpContext *context = GIMP_CONTEXT (paint_options);
168
GimpImage *src_image = NULL;
169
GimpImageType src_type = 0;
170
GimpImageType dest_type;
175
GimpPattern *pattern = NULL;
177
image = gimp_item_get_image (GIMP_ITEM (drawable));
291
179
switch (options->clone_type)
293
181
case GIMP_IMAGE_CLONE:
294
/* Set the paint area to transparent */
295
temp_buf_data_clear (area);
297
x1 = CLAMP (area->x + offset_x,
298
0, gimp_item_width (GIMP_ITEM (clone->src_drawable)));
299
y1 = CLAMP (area->y + offset_y,
300
0, gimp_item_height (GIMP_ITEM (clone->src_drawable)));
301
x2 = CLAMP (area->x + offset_x + area->width,
302
0, gimp_item_width (GIMP_ITEM (clone->src_drawable)));
303
y2 = CLAMP (area->y + offset_y + area->height,
304
0, gimp_item_height (GIMP_ITEM (clone->src_drawable)));
306
if (!(x2 - x1) || !(y2 - y1))
309
/* If the source gimage is different from the destination,
310
* then we should copy straight from the destination image
312
* Otherwise, we need a call to get_orig_image to make sure
313
* we get a copy of the unblemished (offset) image
315
if (clone->src_drawable != drawable)
317
pixel_region_init (&srcPR, gimp_drawable_data (clone->src_drawable),
318
x1, y1, (x2 - x1), (y2 - y1), FALSE);
324
/* get the original image */
325
orig = gimp_paint_core_get_orig_image (paint_core, clone->src_drawable,
328
srcPR.bytes = orig->bytes;
333
srcPR.rowstride = srcPR.bytes * orig->width;
334
srcPR.data = temp_buf_data (orig);
337
offset_x = x1 - (area->x + offset_x);
338
offset_y = y1 - (area->y + offset_y);
340
/* configure the destination */
341
destPR.bytes = area->bytes;
346
destPR.rowstride = destPR.bytes * area->width;
347
destPR.data = (temp_buf_data (area) +
348
offset_y * destPR.rowstride +
349
offset_x * destPR.bytes);
351
pr = pixel_regions_register (2, &srcPR, &destPR);
182
src_image = gimp_pickable_get_image (src_pickable);
184
src_type = gimp_pickable_get_image_type (src_pickable);
186
if (gimp_pickable_get_bytes (src_pickable) < srcPR->bytes)
187
src_type = GIMP_IMAGE_TYPE_WITH_ALPHA (src_type);
189
pixel_region_init_temp_buf (&destPR, paint_area,
190
paint_area_offset_x, paint_area_offset_y,
191
paint_area_width, paint_area_height);
193
pr = pixel_regions_register (2, srcPR, &destPR);
354
196
case GIMP_PATTERN_CLONE:
355
197
pattern = gimp_context_get_pattern (context);
360
/* configure the destination */
361
destPR.bytes = area->bytes;
364
destPR.w = area->width;
365
destPR.h = area->height;
366
destPR.rowstride = destPR.bytes * area->width;
367
destPR.data = temp_buf_data (area);
199
pixel_region_init_temp_buf (&destPR, paint_area,
201
paint_area->width, paint_area->height);
369
203
pr = pixel_regions_register (1, &destPR);
207
dest_type = gimp_drawable_type (drawable);
373
209
for (; pr != NULL; pr = pixel_regions_process (pr))
211
guchar *s = srcPR->data;
212
guchar *d = destPR.data;
378
214
for (y = 0; y < destPR.h; y++)
380
216
switch (options->clone_type)
382
218
case GIMP_IMAGE_CLONE:
383
gimp_clone_line_image (gimage, src_gimage,
384
drawable, clone->src_drawable,
386
srcPR.bytes, destPR.bytes, destPR.w);
387
s += srcPR.rowstride;
219
gimp_clone_line_image (image, dest_type,
222
srcPR->bytes, destPR.bytes, destPR.w);
223
s += srcPR->rowstride;
390
226
case GIMP_PATTERN_CLONE:
391
gimp_clone_line_pattern (gimage, drawable,
227
gimp_clone_line_pattern (image, dest_type,
394
area->y + y + offset_y,
229
paint_area->x + src_offset_x,
230
paint_area->y + y + src_offset_y,
395
231
destPR.bytes, destPR.w);