void gimp_paint_core_cleanup (GimpPaintCore *core) { g_return_if_fail (GIMP_IS_PAINT_CORE (core)); if (core->undo_buffer) { g_object_unref (core->undo_buffer); core->undo_buffer = NULL; } if (core->saved_proj_buffer) { g_object_unref (core->saved_proj_buffer); core->saved_proj_buffer = NULL; } if (core->canvas_buffer) { g_object_unref (core->canvas_buffer); core->canvas_buffer = NULL; } if (core->paint_buffer) { g_object_unref (core->paint_buffer); core->paint_buffer = NULL; } }
void gimp_paint_core_validate_canvas_tiles (GimpPaintCore *core, gint x, gint y, gint w, gint h) { gint i, j; g_return_if_fail (GIMP_IS_PAINT_CORE (core)); g_return_if_fail (core->canvas_tiles != NULL); for (i = y; i < (y + h); i += (TILE_HEIGHT - (i % TILE_HEIGHT))) { for (j = x; j < (x + w); j += (TILE_WIDTH - (j % TILE_WIDTH))) { Tile *tile = tile_manager_get_tile (core->canvas_tiles, j, i, FALSE, FALSE); if (! tile_is_valid (tile)) { tile = tile_manager_get_tile (core->canvas_tiles, j, i, TRUE, TRUE); memset (tile_data_pointer (tile, 0, 0), 0, tile_size (tile)); tile_release (tile, TRUE); } } } }
GeglBuffer * gimp_paint_core_get_paint_buffer (GimpPaintCore *core, GimpDrawable *drawable, GimpPaintOptions *paint_options, const GimpCoords *coords, gint *paint_buffer_x, gint *paint_buffer_y) { GeglBuffer *paint_buffer; g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), NULL); g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL); g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), NULL); g_return_val_if_fail (coords != NULL, NULL); g_return_val_if_fail (paint_buffer_x != NULL, NULL); g_return_val_if_fail (paint_buffer_y != NULL, NULL); paint_buffer = GIMP_PAINT_CORE_GET_CLASS (core)->get_paint_buffer (core, drawable, paint_options, coords, paint_buffer_x, paint_buffer_y); core->paint_buffer_x = *paint_buffer_x; core->paint_buffer_y = *paint_buffer_y; return paint_buffer; }
void gimp_paint_core_validate_saved_proj_tiles (GimpPaintCore *core, GimpPickable *pickable, gint x, gint y, gint w, gint h) { gint i, j; g_return_if_fail (GIMP_IS_PAINT_CORE (core)); g_return_if_fail (GIMP_IS_PICKABLE (pickable)); g_return_if_fail (core->saved_proj_tiles != NULL); for (i = y; i < (y + h); i += (TILE_HEIGHT - (i % TILE_HEIGHT))) { for (j = x; j < (x + w); j += (TILE_WIDTH - (j % TILE_WIDTH))) { Tile *dest_tile = tile_manager_get_tile (core->saved_proj_tiles, j, i, FALSE, FALSE); if (! tile_is_valid (dest_tile)) { Tile *src_tile = tile_manager_get_tile (gimp_pickable_get_tiles (pickable), j, i, TRUE, FALSE); tile_manager_map_tile (core->saved_proj_tiles, j, i, src_tile); tile_release (src_tile, FALSE); } } } }
GeglBuffer * gimp_paint_core_get_orig_proj (GimpPaintCore *core) { g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), NULL); g_return_val_if_fail (core->saved_proj_buffer != NULL, NULL); return core->saved_proj_buffer; }
void gimp_paint_core_set_current_coords (GimpPaintCore *core, const GimpCoords *coords) { g_return_if_fail (GIMP_IS_PAINT_CORE (core)); g_return_if_fail (coords != NULL); core->cur_coords = *coords; }
void gimp_paint_core_get_last_coords (GimpPaintCore *core, GimpCoords *coords) { g_return_if_fail (GIMP_IS_PAINT_CORE (core)); g_return_if_fail (coords != NULL); *coords = core->last_coords; }
void gimp_paint_core_finish (GimpPaintCore *core, GimpDrawable *drawable, gboolean push_undo) { GimpImage *image; g_return_if_fail (GIMP_IS_PAINT_CORE (core)); g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable))); if (core->stroke_buffer) { g_array_free (core->stroke_buffer, TRUE); core->stroke_buffer = NULL; } image = gimp_item_get_image (GIMP_ITEM (drawable)); /* Determine if any part of the image has been altered-- * if nothing has, then just return... */ if ((core->x2 == core->x1) || (core->y2 == core->y1)) { gimp_viewable_preview_thaw (GIMP_VIEWABLE (drawable)); return; } if (push_undo) { gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_PAINT, core->undo_desc); GIMP_PAINT_CORE_GET_CLASS (core)->push_undo (core, image, NULL); gimp_drawable_push_undo (drawable, NULL, core->x1, core->y1, core->x2 - core->x1, core->y2 - core->y1, core->undo_tiles, TRUE); gimp_image_undo_group_end (image); } tile_manager_unref (core->undo_tiles); core->undo_tiles = NULL; if (core->saved_proj_tiles) { tile_manager_unref (core->saved_proj_tiles); core->saved_proj_tiles = NULL; } gimp_viewable_preview_thaw (GIMP_VIEWABLE (drawable)); }
static void gimp_paint_core_undo_constructed (GObject *object) { GimpPaintCoreUndo *paint_core_undo = GIMP_PAINT_CORE_UNDO (object); G_OBJECT_CLASS (parent_class)->constructed (object); g_assert (GIMP_IS_PAINT_CORE (paint_core_undo->paint_core)); paint_core_undo->last_coords = paint_core_undo->paint_core->start_coords; g_object_add_weak_pointer (G_OBJECT (paint_core_undo->paint_core), (gpointer) &paint_core_undo->paint_core); }
void gimp_paint_core_get_current_coords (GimpPaintCore *core, GimpPaintOptions *paint_options, GimpCoords *coords) { g_return_if_fail (GIMP_IS_PAINT_CORE (core)); g_return_if_fail (coords != NULL); *coords = core->cur_coords; gimp_paint_core_smooth_coords (core, paint_options, coords); }
gboolean gimp_paint_core_stroke (GimpPaintCore *core, GimpDrawable *drawable, GimpPaintOptions *paint_options, GimpCoords *strokes, gint n_strokes, gboolean push_undo, GError **error) { g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), FALSE); g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE); g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), FALSE); g_return_val_if_fail (strokes != NULL, FALSE); g_return_val_if_fail (n_strokes > 0, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (gimp_paint_core_start (core, drawable, paint_options, &strokes[0], error)) { gint i; core->last_coords = strokes[0]; gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_INIT, 0); gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_MOTION, 0); for (i = 1; i < n_strokes; i++) { gimp_paint_core_interpolate (core, drawable, paint_options, &strokes[i], 0); } gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_FINISH, 0); gimp_paint_core_finish (core, drawable, push_undo); gimp_paint_core_cleanup (core); return TRUE; } return FALSE; }
TempBuf * gimp_paint_core_get_paint_area (GimpPaintCore *core, GimpDrawable *drawable, GimpPaintOptions *paint_options, const GimpCoords *coords) { g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), NULL); g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), NULL); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), NULL); g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), NULL); g_return_val_if_fail (coords != NULL, NULL); return GIMP_PAINT_CORE_GET_CLASS (core)->get_paint_area (core, drawable, paint_options, coords); }
void gimp_paint_core_interpolate (GimpPaintCore *core, GimpDrawable *drawable, GimpPaintOptions *paint_options, const GimpCoords *coords, guint32 time) { g_return_if_fail (GIMP_IS_PAINT_CORE (core)); g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable))); g_return_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options)); g_return_if_fail (coords != NULL); core->cur_coords = *coords; GIMP_PAINT_CORE_GET_CLASS (core)->interpolate (core, drawable, paint_options, time); }
void gimp_paint_core_cancel (GimpPaintCore *core, GimpDrawable *drawable) { gint x, y; gint width, height; g_return_if_fail (GIMP_IS_PAINT_CORE (core)); g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable))); /* Determine if any part of the image has been altered-- * if nothing has, then just return... */ if ((core->x2 == core->x1) || (core->y2 == core->y1)) return; if (gimp_rectangle_intersect (core->x1, core->y1, core->x2 - core->x1, core->y2 - core->y1, 0, 0, gimp_item_get_width (GIMP_ITEM (drawable)), gimp_item_get_height (GIMP_ITEM (drawable)), &x, &y, &width, &height)) { gegl_buffer_copy (core->undo_buffer, GEGL_RECTANGLE (x, y, width, height), gimp_drawable_get_buffer (drawable), GEGL_RECTANGLE (x, y, width, height)); } g_object_unref (core->undo_buffer); core->undo_buffer = NULL; if (core->saved_proj_buffer) { g_object_unref (core->saved_proj_buffer); core->saved_proj_buffer = NULL; } gimp_drawable_update (drawable, x, y, width, height); gimp_viewable_preview_thaw (GIMP_VIEWABLE (drawable)); }
void gimp_paint_core_cleanup (GimpPaintCore *core) { g_return_if_fail (GIMP_IS_PAINT_CORE (core)); if (core->undo_tiles) { tile_manager_unref (core->undo_tiles); core->undo_tiles = NULL; } if (core->saved_proj_tiles) { tile_manager_unref (core->saved_proj_tiles); core->saved_proj_tiles = NULL; } if (core->canvas_tiles) { tile_manager_unref (core->canvas_tiles); core->canvas_tiles = NULL; } if (core->orig_buf) { temp_buf_free (core->orig_buf); core->orig_buf = NULL; } if (core->orig_proj_buf) { temp_buf_free (core->orig_proj_buf); core->orig_proj_buf = NULL; } if (core->canvas_buf) { temp_buf_free (core->canvas_buf); core->canvas_buf = NULL; } }
/** * gimp_paint_core_round_line: * @core: the #GimpPaintCore * @options: the #GimpPaintOptions to use * @constrain_15_degrees: the modifier state * * Adjusts core->last_coords and core_cur_coords in preparation to * drawing a straight line. If @center_pixels is TRUE the endpoints * get pushed to the center of the pixels. This avoids artefacts * for e.g. the hard mode. The rounding of the slope to 15 degree * steps if ctrl is pressed happens, as does rounding the start and * end coordinates (which may be fractional in high zoom modes) to * the center of pixels. **/ void gimp_paint_core_round_line (GimpPaintCore *core, GimpPaintOptions *paint_options, gboolean constrain_15_degrees) { g_return_if_fail (GIMP_IS_PAINT_CORE (core)); g_return_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options)); if (gimp_paint_options_get_brush_mode (paint_options) == GIMP_BRUSH_HARD) { core->last_coords.x = floor (core->last_coords.x) + 0.5; core->last_coords.y = floor (core->last_coords.y) + 0.5; core->cur_coords.x = floor (core->cur_coords.x ) + 0.5; core->cur_coords.y = floor (core->cur_coords.y ) + 0.5; } if (constrain_15_degrees) gimp_constrain_line (core->last_coords.x, core->last_coords.y, &core->cur_coords.x, &core->cur_coords.y, GIMP_CONSTRAIN_LINE_15_DEGREES); }
static GObject * gimp_paint_core_undo_constructor (GType type, guint n_params, GObjectConstructParam *params) { GObject *object; GimpPaintCoreUndo *paint_core_undo; object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params); paint_core_undo = GIMP_PAINT_CORE_UNDO (object); g_assert (GIMP_IS_PAINT_CORE (paint_core_undo->paint_core)); paint_core_undo->last_coords = paint_core_undo->paint_core->start_coords; g_object_add_weak_pointer (G_OBJECT (paint_core_undo->paint_core), (gpointer) &paint_core_undo->paint_core); return object; }
void gimp_paint_core_paint (GimpPaintCore *core, GimpDrawable *drawable, GimpPaintOptions *paint_options, GimpPaintState paint_state, guint32 time) { GimpPaintCoreClass *core_class; g_return_if_fail (GIMP_IS_PAINT_CORE (core)); g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable))); g_return_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options)); core_class = GIMP_PAINT_CORE_GET_CLASS (core); if (core_class->pre_paint (core, drawable, paint_options, paint_state, time)) { if (paint_state == GIMP_PAINT_STATE_MOTION) { /* Save coordinates for gimp_paint_core_interpolate() */ core->last_paint.x = core->cur_coords.x; core->last_paint.y = core->cur_coords.y; } gimp_paint_core_smooth_coords (core, paint_options, &core->cur_coords); core_class->paint (core, drawable, paint_options, &core->cur_coords, paint_state, time); core_class->post_paint (core, drawable, paint_options, paint_state, time); } }
TempBuf * gimp_paint_core_get_orig_proj (GimpPaintCore *core, GimpPickable *pickable, gint x, gint y, gint width, gint height) { TileManager *src_tiles; PixelRegion srcPR; PixelRegion destPR; Tile *saved_tile; gboolean release_tile; gint h; gint pixelwidth; gint pickable_width; gint pickable_height; const guchar *s; guchar *d; gpointer pr; g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), NULL); g_return_val_if_fail (GIMP_IS_PICKABLE (pickable), NULL); g_return_val_if_fail (core->saved_proj_tiles != NULL, NULL); core->orig_proj_buf = temp_buf_resize (core->orig_proj_buf, gimp_pickable_get_bytes (pickable), x, y, width, height); src_tiles = gimp_pickable_get_tiles (pickable); pickable_width = tile_manager_width (src_tiles); pickable_height = tile_manager_height (src_tiles); gimp_rectangle_intersect (x, y, width, height, 0, 0, pickable_width, pickable_height, &x, &y, &width, &height); /* configure the pixel regions */ pixel_region_init (&srcPR, src_tiles, x, y, width, height, FALSE); pixel_region_init_temp_buf (&destPR, core->orig_proj_buf, x - core->orig_proj_buf->x, y - core->orig_proj_buf->y, width, height); for (pr = pixel_regions_register (2, &srcPR, &destPR); pr != NULL; pr = pixel_regions_process (pr)) { /* If the saved tile corresponding to this location is valid, use it */ saved_tile = tile_manager_get_tile (core->saved_proj_tiles, srcPR.x, srcPR.y, FALSE, FALSE); if (tile_is_valid (saved_tile)) { release_tile = TRUE; saved_tile = tile_manager_get_tile (core->saved_proj_tiles, srcPR.x, srcPR.y, TRUE, FALSE); s = tile_data_pointer (saved_tile, srcPR.x, srcPR.y); } else { release_tile = FALSE; s = srcPR.data; } d = destPR.data; pixelwidth = srcPR.w * srcPR.bytes; h = srcPR.h; while (h --) { memcpy (d, s, pixelwidth); s += srcPR.rowstride; d += destPR.rowstride; } if (release_tile) tile_release (saved_tile, FALSE); } return core->orig_proj_buf; }
gboolean gimp_paint_core_stroke_vectors (GimpPaintCore *core, GimpDrawable *drawable, GimpPaintOptions *paint_options, gboolean emulate_dynamics, GimpVectors *vectors, gboolean push_undo, GError **error) { GList *stroke; gboolean initialized = FALSE; gboolean due_to_lack_of_points = FALSE; gint off_x, off_y; gint vectors_off_x, vectors_off_y; g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), FALSE); g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE); g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), FALSE); g_return_val_if_fail (GIMP_IS_VECTORS (vectors), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); gimp_item_get_offset (GIMP_ITEM (vectors), &vectors_off_x, &vectors_off_y); gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); off_x -= vectors_off_x; off_y -= vectors_off_y; for (stroke = vectors->strokes; stroke; stroke = stroke->next) { GArray *coords; gboolean closed; coords = gimp_stroke_interpolate (GIMP_STROKE (stroke->data), 1.0, &closed); if (coords && coords->len) { gint i; for (i = 0; i < coords->len; i++) { g_array_index (coords, GimpCoords, i).x -= off_x; g_array_index (coords, GimpCoords, i).y -= off_y; } if (emulate_dynamics) gimp_paint_core_stroke_emulate_dynamics ((GimpCoords *) coords->data, coords->len); if (initialized || gimp_paint_core_start (core, drawable, paint_options, &g_array_index (coords, GimpCoords, 0), error)) { initialized = TRUE; core->cur_coords = g_array_index (coords, GimpCoords, 0); core->last_coords = g_array_index (coords, GimpCoords, 0); gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_INIT, 0); gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_MOTION, 0); for (i = 1; i < coords->len; i++) { gimp_paint_core_interpolate (core, drawable, paint_options, &g_array_index (coords, GimpCoords, i), 0); } gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_FINISH, 0); } else { if (coords) g_array_free (coords, TRUE); break; } } else { due_to_lack_of_points = TRUE; } if (coords) g_array_free (coords, TRUE); } if (initialized) { gimp_paint_core_finish (core, drawable, push_undo); gimp_paint_core_cleanup (core); } if (! initialized && due_to_lack_of_points && *error == NULL) { g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, _("Not enough points to stroke")); } return initialized; }
gboolean gimp_paint_core_start (GimpPaintCore *core, GimpDrawable *drawable, GimpPaintOptions *paint_options, const GimpCoords *coords, GError **error) { GimpItem *item; g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), FALSE); g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE); g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), FALSE); g_return_val_if_fail (coords != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); item = GIMP_ITEM (drawable); if (core->stroke_buffer) { g_array_free (core->stroke_buffer, TRUE); core->stroke_buffer = NULL; } core->stroke_buffer = g_array_sized_new (TRUE, TRUE, sizeof (GimpCoords), STROKE_BUFFER_INIT_SIZE); core->cur_coords = *coords; if (! GIMP_PAINT_CORE_GET_CLASS (core)->start (core, drawable, paint_options, coords, error)) { return FALSE; } /* Allocate the undo structure */ if (core->undo_buffer) g_object_unref (core->undo_buffer); core->undo_buffer = gegl_buffer_dup (gimp_drawable_get_buffer (drawable)); /* Allocate the saved proj structure */ if (core->saved_proj_buffer) { g_object_unref (core->saved_proj_buffer); core->saved_proj_buffer = NULL; } if (core->use_saved_proj) { GimpImage *image = gimp_item_get_image (item); GimpPickable *pickable = GIMP_PICKABLE (gimp_image_get_projection (image)); GeglBuffer *buffer = gimp_pickable_get_buffer (pickable); core->saved_proj_buffer = gegl_buffer_dup (buffer); } /* Allocate the canvas blocks structure */ if (core->canvas_buffer) g_object_unref (core->canvas_buffer); core->canvas_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, gimp_item_get_width (item), gimp_item_get_height (item)), babl_format ("Y u8")); /* Get the initial undo extents */ core->x1 = core->x2 = core->cur_coords.x; core->y1 = core->y2 = core->cur_coords.y; core->last_paint.x = -1e6; core->last_paint.y = -1e6; { GimpImage *image; GimpChannel *mask; GeglBuffer *mask_buffer = NULL; gint offset_x = 0; gint offset_y = 0; image = gimp_item_get_image (item); mask = gimp_image_get_mask (image); /* don't apply the mask to itself and don't apply an empty mask */ if (GIMP_DRAWABLE (mask) == drawable || gimp_channel_is_empty (mask)) mask = NULL; if (mask) { mask_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)); gimp_item_get_offset (item, &offset_x, &offset_y); } core->applicator = gimp_applicator_new (gimp_drawable_get_buffer (drawable), gimp_drawable_get_active_mask (drawable), mask_buffer, -offset_x, -offset_y); } /* Freeze the drawable preview so that it isn't constantly updated. */ gimp_viewable_preview_freeze (GIMP_VIEWABLE (drawable)); return TRUE; }
gboolean gimp_paint_core_start (GimpPaintCore *core, GimpDrawable *drawable, GimpPaintOptions *paint_options, const GimpCoords *coords, GError **error) { GimpItem *item; g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), FALSE); g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE); g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), FALSE); g_return_val_if_fail (coords != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); item = GIMP_ITEM (drawable); if (core->stroke_buffer) { g_array_free (core->stroke_buffer, TRUE); core->stroke_buffer = NULL; } core->stroke_buffer = g_array_sized_new (TRUE, TRUE, sizeof (GimpCoords), STROKE_BUFFER_INIT_SIZE); core->cur_coords = *coords; if (! GIMP_PAINT_CORE_GET_CLASS (core)->start (core, drawable, paint_options, coords, error)) { return FALSE; } /* Allocate the undo structure */ if (core->undo_tiles) tile_manager_unref (core->undo_tiles); core->undo_tiles = tile_manager_new (gimp_item_get_width (item), gimp_item_get_height (item), gimp_drawable_bytes (drawable)); /* Allocate the saved proj structure */ if (core->saved_proj_tiles) tile_manager_unref (core->saved_proj_tiles); core->saved_proj_tiles = NULL; if (core->use_saved_proj) { GimpImage *image = gimp_item_get_image (item); GimpPickable *pickable = GIMP_PICKABLE (gimp_image_get_projection (image)); TileManager *tiles = gimp_pickable_get_tiles (pickable); core->saved_proj_tiles = tile_manager_new (tile_manager_width (tiles), tile_manager_height (tiles), tile_manager_bpp (tiles)); } /* Allocate the canvas blocks structure */ if (core->canvas_tiles) tile_manager_unref (core->canvas_tiles); core->canvas_tiles = tile_manager_new (gimp_item_get_width (item), gimp_item_get_height (item), 1); /* Get the initial undo extents */ core->x1 = core->x2 = core->cur_coords.x; core->y1 = core->y2 = core->cur_coords.y; core->last_paint.x = -1e6; core->last_paint.y = -1e6; /* Freeze the drawable preview so that it isn't constantly updated. */ gimp_viewable_preview_freeze (GIMP_VIEWABLE (drawable)); return TRUE; }
void gimp_paint_core_finish (GimpPaintCore *core, GimpDrawable *drawable, gboolean push_undo) { GimpImage *image; g_return_if_fail (GIMP_IS_PAINT_CORE (core)); g_return_if_fail (GIMP_IS_DRAWABLE (drawable)); g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable))); if (core->applicator) { g_object_unref (core->applicator); core->applicator = NULL; } if (core->stroke_buffer) { g_array_free (core->stroke_buffer, TRUE); core->stroke_buffer = NULL; } if (core->mask_buffer) { g_object_unref (core->mask_buffer); core->mask_buffer = NULL; } if (core->comp_buffer) { g_object_unref (core->comp_buffer); core->comp_buffer = NULL; } image = gimp_item_get_image (GIMP_ITEM (drawable)); /* Determine if any part of the image has been altered-- * if nothing has, then just return... */ if ((core->x2 == core->x1) || (core->y2 == core->y1)) { gimp_viewable_preview_thaw (GIMP_VIEWABLE (drawable)); return; } if (push_undo) { GeglBuffer *buffer; gint x, y, width, height; gimp_rectangle_intersect (core->x1, core->y1, core->x2 - core->x1, core->y2 - core->y1, 0, 0, gimp_item_get_width (GIMP_ITEM (drawable)), gimp_item_get_height (GIMP_ITEM (drawable)), &x, &y, &width, &height); gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_PAINT, core->undo_desc); GIMP_PAINT_CORE_GET_CLASS (core)->push_undo (core, image, NULL); buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, width, height), gimp_drawable_get_format (drawable)); gegl_buffer_copy (core->undo_buffer, GEGL_RECTANGLE (x, y, width, height), buffer, GEGL_RECTANGLE (0, 0, 0, 0)); gimp_drawable_push_undo (drawable, NULL, buffer, x, y, width, height); g_object_unref (buffer); gimp_image_undo_group_end (image); } g_object_unref (core->undo_buffer); core->undo_buffer = NULL; if (core->saved_proj_buffer) { g_object_unref (core->saved_proj_buffer); core->saved_proj_buffer = NULL; } gimp_viewable_preview_thaw (GIMP_VIEWABLE (drawable)); }
gboolean gimp_paint_core_stroke_boundary (GimpPaintCore *core, GimpDrawable *drawable, GimpPaintOptions *paint_options, gboolean emulate_dynamics, const GimpBoundSeg *bound_segs, gint n_bound_segs, gint offset_x, gint offset_y, gboolean push_undo, GError **error) { GimpBoundSeg *stroke_segs; gint n_stroke_segs; gint off_x; gint off_y; GimpCoords *coords; gboolean initialized = FALSE; gint n_coords; gint seg; gint s; g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), FALSE); g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE); g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), FALSE); g_return_val_if_fail (bound_segs != NULL && n_bound_segs > 0, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); stroke_segs = gimp_boundary_sort (bound_segs, n_bound_segs, &n_stroke_segs); if (n_stroke_segs == 0) return TRUE; gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); off_x -= offset_x; off_y -= offset_y; coords = g_new0 (GimpCoords, n_bound_segs + 4); seg = 0; n_coords = 0; /* we offset all coordinates by 0.5 to align the brush with the path */ coords[n_coords] = default_coords; coords[n_coords].x = (gdouble) (stroke_segs[0].x1 - off_x + 0.5); coords[n_coords].y = (gdouble) (stroke_segs[0].y1 - off_y + 0.5); n_coords++; for (s = 0; s < n_stroke_segs; s++) { while (stroke_segs[seg].x1 != -1 || stroke_segs[seg].x2 != -1 || stroke_segs[seg].y1 != -1 || stroke_segs[seg].y2 != -1) { coords[n_coords] = default_coords; coords[n_coords].x = (gdouble) (stroke_segs[seg].x1 - off_x + 0.5); coords[n_coords].y = (gdouble) (stroke_segs[seg].y1 - off_y + 0.5); n_coords++; seg++; } /* Close the stroke points up */ coords[n_coords] = coords[0]; n_coords++; if (emulate_dynamics) gimp_paint_core_stroke_emulate_dynamics (coords, n_coords); if (initialized || gimp_paint_core_start (core, drawable, paint_options, &coords[0], error)) { gint i; initialized = TRUE; core->cur_coords = coords[0]; core->last_coords = coords[0]; gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_INIT, 0); gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_MOTION, 0); for (i = 1; i < n_coords; i++) { gimp_paint_core_interpolate (core, drawable, paint_options, &coords[i], 0); } gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_FINISH, 0); } else { break; } n_coords = 0; seg++; coords[n_coords] = default_coords; coords[n_coords].x = (gdouble) (stroke_segs[seg].x1 - off_x + 0.5); coords[n_coords].y = (gdouble) (stroke_segs[seg].y1 - off_y + 0.5); n_coords++; } if (initialized) { gimp_paint_core_finish (core, drawable, push_undo); gimp_paint_core_cleanup (core); } g_free (coords); g_free (stroke_segs); return initialized; }
gboolean gimp_paint_core_start (GimpPaintCore *core, GimpDrawable *drawable, GimpPaintOptions *paint_options, const GimpCoords *coords, GError **error) { GimpImage *image; GimpItem *item; GimpChannel *mask; g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), FALSE); g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE); g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), FALSE); g_return_val_if_fail (coords != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); item = GIMP_ITEM (drawable); image = gimp_item_get_image (item); if (core->stroke_buffer) { g_array_free (core->stroke_buffer, TRUE); core->stroke_buffer = NULL; } core->stroke_buffer = g_array_sized_new (TRUE, TRUE, sizeof (GimpCoords), STROKE_BUFFER_INIT_SIZE); /* remember the last stroke's endpoint for later undo */ core->start_coords = core->last_coords; core->cur_coords = *coords; if (! GIMP_PAINT_CORE_GET_CLASS (core)->start (core, drawable, paint_options, coords, error)) { return FALSE; } /* Allocate the undo structure */ if (core->undo_buffer) g_object_unref (core->undo_buffer); core->undo_buffer = gegl_buffer_dup (gimp_drawable_get_buffer (drawable)); /* Allocate the saved proj structure */ if (core->saved_proj_buffer) { g_object_unref (core->saved_proj_buffer); core->saved_proj_buffer = NULL; } if (core->use_saved_proj) { GeglBuffer *buffer = gimp_pickable_get_buffer (GIMP_PICKABLE (image)); core->saved_proj_buffer = gegl_buffer_dup (buffer); } /* Allocate the canvas blocks structure */ if (core->canvas_buffer) g_object_unref (core->canvas_buffer); core->canvas_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, gimp_item_get_width (item), gimp_item_get_height (item)), babl_format ("Y float")); /* Get the initial undo extents */ core->x1 = core->x2 = core->cur_coords.x; core->y1 = core->y2 = core->cur_coords.y; core->last_paint.x = -1e6; core->last_paint.y = -1e6; mask = gimp_image_get_mask (image); /* don't apply the mask to itself and don't apply an empty mask */ if (GIMP_DRAWABLE (mask) != drawable && ! gimp_channel_is_empty (mask)) { GeglBuffer *mask_buffer; gint offset_x; gint offset_y; mask_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)); gimp_item_get_offset (item, &offset_x, &offset_y); core->mask_buffer = g_object_ref (mask_buffer); core->mask_x_offset = -offset_x; core->mask_y_offset = -offset_y; } else { core->mask_buffer = NULL; } core->linear_mode = gimp_drawable_get_linear (drawable); if (paint_options->use_applicator) { core->applicator = gimp_applicator_new (NULL, core->linear_mode); if (core->mask_buffer) { gimp_applicator_set_mask_buffer (core->applicator, core->mask_buffer); gimp_applicator_set_mask_offset (core->applicator, core->mask_x_offset, core->mask_y_offset); } gimp_applicator_set_affect (core->applicator, gimp_drawable_get_active_mask (drawable)); gimp_applicator_set_dest_buffer (core->applicator, gimp_drawable_get_buffer (drawable)); } else { if (core->comp_buffer) { g_object_unref (core->comp_buffer); core->comp_buffer = NULL; } /* Allocate the scratch buffer if there's a component mask */ if (gimp_drawable_get_active_mask (drawable) != GIMP_COMPONENT_ALL) { const Babl *format; if (core->linear_mode) format = babl_format ("RGBA float"); else format = babl_format ("R'G'B'A float"); core->comp_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, gimp_item_get_width (item), gimp_item_get_height (item)), format); } } /* Freeze the drawable preview so that it isn't constantly updated. */ gimp_viewable_preview_freeze (GIMP_VIEWABLE (drawable)); return TRUE; }