static GeglBuffer * gimp_source_core_real_get_source (GimpSourceCore *source_core, GimpDrawable *drawable, GimpPaintOptions *paint_options, GimpPickable *src_pickable, gint src_offset_x, gint src_offset_y, GeglBuffer *paint_buffer, gint paint_buffer_x, gint paint_buffer_y, gint *paint_area_offset_x, gint *paint_area_offset_y, gint *paint_area_width, gint *paint_area_height, GeglRectangle *src_rect) { GimpSourceOptions *options = GIMP_SOURCE_OPTIONS (paint_options); GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable)); GimpImage *src_image = gimp_pickable_get_image (src_pickable); GeglBuffer *src_buffer = gimp_pickable_get_buffer (src_pickable); GeglBuffer *dest_buffer; gint x, y; gint width, height; if (! gimp_rectangle_intersect (paint_buffer_x + src_offset_x, paint_buffer_y + src_offset_y, gegl_buffer_get_width (paint_buffer), gegl_buffer_get_height (paint_buffer), 0, 0, gegl_buffer_get_width (src_buffer), gegl_buffer_get_height (src_buffer), &x, &y, &width, &height)) { return FALSE; } /* If the source image is different from the destination, * then we should copy straight from the source image * to the canvas. * Otherwise, we need a call to get_orig_image to make sure * we get a copy of the unblemished (offset) image */ if (( options->sample_merged && (src_image != image)) || (! options->sample_merged && (source_core->src_drawable != drawable))) { dest_buffer = src_buffer; } else { /* get the original image */ if (options->sample_merged) dest_buffer = gimp_paint_core_get_orig_proj (GIMP_PAINT_CORE (source_core)); else dest_buffer = gimp_paint_core_get_orig_image (GIMP_PAINT_CORE (source_core)); } *paint_area_offset_x = x - (paint_buffer_x + src_offset_x); *paint_area_offset_y = y - (paint_buffer_y + src_offset_y); *paint_area_width = width; *paint_area_height = height; *src_rect = *GEGL_RECTANGLE (x, y, width, height); return g_object_ref (dest_buffer); }
static gboolean gimp_source_core_real_get_source (GimpSourceCore *source_core, GimpDrawable *drawable, GimpPaintOptions *paint_options, GimpPickable *src_pickable, gint src_offset_x, gint src_offset_y, TempBuf *paint_area, gint *paint_area_offset_x, gint *paint_area_offset_y, gint *paint_area_width, gint *paint_area_height, PixelRegion *srcPR) { GimpSourceOptions *options = GIMP_SOURCE_OPTIONS (paint_options); GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable)); GimpImage *src_image = gimp_pickable_get_image (src_pickable); TileManager *src_tiles = gimp_pickable_get_tiles (src_pickable); gint x1, y1; gint x2, y2; x1 = CLAMP (paint_area->x + src_offset_x, 0, tile_manager_width (src_tiles)); y1 = CLAMP (paint_area->y + src_offset_y, 0, tile_manager_height (src_tiles)); x2 = CLAMP (paint_area->x + src_offset_x + paint_area->width, 0, tile_manager_width (src_tiles)); y2 = CLAMP (paint_area->y + src_offset_y + paint_area->height, 0, tile_manager_height (src_tiles)); if (!(x2 - x1) || !(y2 - y1)) return FALSE; /* If the source image is different from the destination, * then we should copy straight from the source image * to the canvas. * Otherwise, we need a call to get_orig_image to make sure * we get a copy of the unblemished (offset) image */ if (( options->sample_merged && (src_image != image)) || (! options->sample_merged && (source_core->src_drawable != drawable))) { pixel_region_init (srcPR, src_tiles, x1, y1, x2 - x1, y2 - y1, FALSE); } else { TempBuf *orig; /* get the original image */ if (options->sample_merged) orig = gimp_paint_core_get_orig_proj (GIMP_PAINT_CORE (source_core), src_pickable, x1, y1, x2, y2); else orig = gimp_paint_core_get_orig_image (GIMP_PAINT_CORE (source_core), GIMP_DRAWABLE (src_pickable), x1, y1, x2, y2); pixel_region_init_temp_buf (srcPR, orig, 0, 0, x2 - x1, y2 - y1); } *paint_area_offset_x = x1 - (paint_area->x + src_offset_x); *paint_area_offset_y = y1 - (paint_area->y + src_offset_y); *paint_area_width = x2 - x1; *paint_area_height = y2 - y1; return TRUE; }
static void gimp_perspective_clone_paint (GimpPaintCore *paint_core, GimpDrawable *drawable, GimpPaintOptions *paint_options, const GimpCoords *coords, GimpPaintState paint_state, guint32 time) { GimpSourceCore *source_core = GIMP_SOURCE_CORE (paint_core); GimpPerspectiveClone *clone = GIMP_PERSPECTIVE_CLONE (paint_core); GimpContext *context = GIMP_CONTEXT (paint_options); GimpCloneOptions *clone_options = GIMP_CLONE_OPTIONS (paint_options); GimpSourceOptions *options = GIMP_SOURCE_OPTIONS (paint_options); switch (paint_state) { case GIMP_PAINT_STATE_INIT: if (source_core->set_source) { g_object_set (source_core, "src-drawable", drawable, NULL); source_core->src_x = coords->x; source_core->src_y = coords->y; /* get source coordinates in front view perspective */ gimp_matrix3_transform_point (&clone->transform_inv, source_core->src_x, source_core->src_y, &clone->src_x_fv, &clone->src_y_fv); source_core->first_stroke = TRUE; } else { GeglBuffer *orig_buffer = NULL; GeglNode *tile = NULL; GeglNode *src_node; if (options->align_mode == GIMP_SOURCE_ALIGN_NO) { source_core->orig_src_x = source_core->src_x; source_core->orig_src_y = source_core->src_y; source_core->first_stroke = TRUE; } clone->node = gegl_node_new (); g_object_set (clone->node, "dont-cache", TRUE, NULL); switch (clone_options->clone_type) { case GIMP_IMAGE_CLONE: { GimpPickable *src_pickable; GimpImage *src_image; GimpImage *dest_image; /* If the source image is different from the * destination, then we should copy straight from the * source image to the canvas. * Otherwise, we need a call to get_orig_image to make sure * we get a copy of the unblemished (offset) image */ src_pickable = GIMP_PICKABLE (source_core->src_drawable); src_image = gimp_pickable_get_image (src_pickable); if (options->sample_merged) src_pickable = GIMP_PICKABLE (gimp_image_get_projection (src_image)); dest_image = gimp_item_get_image (GIMP_ITEM (drawable)); if ((options->sample_merged && (src_image != dest_image)) || (! options->sample_merged && (source_core->src_drawable != drawable))) { orig_buffer = gimp_pickable_get_buffer (src_pickable); } else { if (options->sample_merged) orig_buffer = gimp_paint_core_get_orig_proj (paint_core); else orig_buffer = gimp_paint_core_get_orig_image (paint_core); } } break; case GIMP_PATTERN_CLONE: { GimpPattern *pattern = gimp_context_get_pattern (context); orig_buffer = gimp_pattern_create_buffer (pattern); tile = gegl_node_new_child (clone->node, "operation", "gegl:tile", NULL); clone->crop = gegl_node_new_child (clone->node, "operation", "gegl:crop", NULL); } break; } src_node = gegl_node_new_child (clone->node, "operation", "gegl:buffer-source", "buffer", orig_buffer, NULL); clone->transform_node = gegl_node_new_child (clone->node, "operation", "gegl:transform", "sampler", GIMP_INTERPOLATION_LINEAR, NULL); clone->dest_node = gegl_node_new_child (clone->node, "operation", "gegl:write-buffer", NULL); if (tile) { gegl_node_link_many (src_node, tile, clone->crop, clone->transform_node, clone->dest_node, NULL); g_object_unref (orig_buffer); } else { gegl_node_link_many (src_node, clone->transform_node, clone->dest_node, NULL); } } break; case GIMP_PAINT_STATE_MOTION: if (source_core->set_source) { /* If the control key is down, move the src target and return */ source_core->src_x = coords->x; source_core->src_y = coords->y; /* get source coordinates in front view perspective */ gimp_matrix3_transform_point (&clone->transform_inv, source_core->src_x, source_core->src_y, &clone->src_x_fv, &clone->src_y_fv); source_core->first_stroke = TRUE; } else { /* otherwise, update the target */ gint dest_x; gint dest_y; dest_x = coords->x; dest_y = coords->y; if (options->align_mode == GIMP_SOURCE_ALIGN_REGISTERED) { source_core->offset_x = 0; source_core->offset_y = 0; } else if (options->align_mode == GIMP_SOURCE_ALIGN_FIXED) { source_core->offset_x = source_core->src_x - dest_x; source_core->offset_y = source_core->src_y - dest_y; } else if (source_core->first_stroke) { source_core->offset_x = source_core->src_x - dest_x; source_core->offset_y = source_core->src_y - dest_y; /* get destination coordinates in front view perspective */ gimp_matrix3_transform_point (&clone->transform_inv, dest_x, dest_y, &clone->dest_x_fv, &clone->dest_y_fv); source_core->first_stroke = FALSE; } gimp_source_core_motion (source_core, drawable, paint_options, coords); } break; case GIMP_PAINT_STATE_FINISH: if (clone->node) { g_object_unref (clone->node); clone->node = NULL; clone->crop = NULL; clone->transform_node = NULL; clone->dest_node = NULL; } break; default: break; } g_object_notify (G_OBJECT (clone), "src-x"); g_object_notify (G_OBJECT (clone), "src-y"); }
static gboolean gimp_perspective_clone_get_source (GimpSourceCore *source_core, GimpDrawable *drawable, GimpPaintOptions *paint_options, GimpPickable *src_pickable, gint src_offset_x, gint src_offset_y, TempBuf *paint_area, gint *paint_area_offset_x, gint *paint_area_offset_y, gint *paint_area_width, gint *paint_area_height, PixelRegion *srcPR) { GimpPerspectiveClone *clone = GIMP_PERSPECTIVE_CLONE (source_core); GimpPaintCore *paint_core = GIMP_PAINT_CORE (source_core); GimpSourceOptions *options = GIMP_SOURCE_OPTIONS (paint_options); GimpImage *src_image; GimpImage *image; GimpImageType src_type; gint x1d, y1d, x2d, y2d; gdouble x1s, y1s, x2s, y2s, x3s, y3s, x4s, y4s; gint xmin, ymin, xmax, ymax; TileManager *src_tiles; TileManager *orig_tiles; PixelRegion origPR; PixelRegion destPR; GimpMatrix3 matrix; gint bytes; src_image = gimp_pickable_get_image (src_pickable); image = gimp_item_get_image (GIMP_ITEM (drawable)); src_type = gimp_pickable_get_image_type (src_pickable); src_tiles = gimp_pickable_get_tiles (src_pickable); /* Destination coordinates that will be painted */ x1d = paint_area->x; y1d = paint_area->y; x2d = paint_area->x + paint_area->width; y2d = paint_area->y + paint_area->height; /* Boundary box for source pixels to copy: Convert all the vertex of * the box to paint in destination area to its correspondent in * source area bearing in mind perspective */ gimp_perspective_clone_get_source_point (clone, x1d, y1d, &x1s, &y1s); gimp_perspective_clone_get_source_point (clone, x1d, y2d, &x2s, &y2s); gimp_perspective_clone_get_source_point (clone, x2d, y1d, &x3s, &y3s); gimp_perspective_clone_get_source_point (clone, x2d, y2d, &x4s, &y4s); xmin = floor (MIN4 (x1s, x2s, x3s, x4s)); ymin = floor (MIN4 (y1s, y2s, y3s, y4s)); xmax = ceil (MAX4 (x1s, x2s, x3s, x4s)); ymax = ceil (MAX4 (y1s, y2s, y3s, y4s)); xmin = CLAMP (xmin - 1, 0, tile_manager_width (src_tiles)); ymin = CLAMP (ymin - 1, 0, tile_manager_height (src_tiles)); xmax = CLAMP (xmax + 1, 0, tile_manager_width (src_tiles)); ymax = CLAMP (ymax + 1, 0, tile_manager_height (src_tiles)); /* if the source area is completely out of the image */ if (!(xmax - xmin) || !(ymax - ymin)) return FALSE; /* If the source image is different from the destination, * then we should copy straight from the source image * to the canvas. * Otherwise, we need a call to get_orig_image to make sure * we get a copy of the unblemished (offset) image */ if (( options->sample_merged && (src_image != image)) || (! options->sample_merged && (source_core->src_drawable != drawable))) { pixel_region_init (&origPR, src_tiles, xmin, ymin, xmax - xmin, ymax - ymin, FALSE); } else { TempBuf *orig; /* get the original image */ if (options->sample_merged) orig = gimp_paint_core_get_orig_proj (paint_core, src_pickable, xmin, ymin, xmax, ymax); else orig = gimp_paint_core_get_orig_image (paint_core, GIMP_DRAWABLE (src_pickable), xmin, ymin, xmax, ymax); pixel_region_init_temp_buf (&origPR, orig, 0, 0, xmax - xmin, ymax - ymin); } /* copy the original image to a tile manager, adding alpha if needed */ bytes = GIMP_IMAGE_TYPE_BYTES (GIMP_IMAGE_TYPE_WITH_ALPHA (src_type)); orig_tiles = tile_manager_new (xmax - xmin, ymax - ymin, bytes); tile_manager_set_offsets (orig_tiles, xmin, ymin); pixel_region_init (&destPR, orig_tiles, 0, 0, xmax - xmin, ymax - ymin, TRUE); if (bytes > origPR.bytes) add_alpha_region (&origPR, &destPR); else copy_region (&origPR, &destPR); clone->src_area = temp_buf_resize (clone->src_area, tile_manager_bpp (orig_tiles), 0, 0, x2d - x1d, y2d - y1d); pixel_region_init_temp_buf (&destPR, clone->src_area, 0, 0, x2d - x1d, y2d - y1d); gimp_perspective_clone_get_matrix (clone, &matrix); gimp_transform_region (src_pickable, GIMP_CONTEXT (paint_options), orig_tiles, &destPR, x1d, y1d, x2d, y2d, &matrix, GIMP_INTERPOLATION_LINEAR, 0, NULL); tile_manager_unref (orig_tiles); pixel_region_init_temp_buf (srcPR, clone->src_area, 0, 0, x2d - x1d, y2d - y1d); return TRUE; }