void gimp_drawable_stroke_vectors (GimpDrawable *drawable, GimpStrokeOptions *options, GimpVectors *vectors) { GimpScanConvert *scan_convert; GimpStroke *stroke; gint num_coords = 0; 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_STROKE_OPTIONS (options)); g_return_if_fail (GIMP_IS_VECTORS (vectors)); scan_convert = gimp_scan_convert_new (); /* For each Stroke in the vector, interpolate it, and add it to the * ScanConvert */ for (stroke = gimp_vectors_stroke_get_next (vectors, NULL); stroke; stroke = gimp_vectors_stroke_get_next (vectors, stroke)) { GArray *coords; gboolean closed; /* Get the interpolated version of this stroke, and add it to our * scanconvert. */ coords = gimp_stroke_interpolate (stroke, 0.2, &closed); if (coords && coords->len) { GimpVector2 *points = g_new0 (GimpVector2, coords->len); gint i; for (i = 0; i < coords->len; i++) { points[i].x = g_array_index (coords, GimpCoords, i).x; points[i].y = g_array_index (coords, GimpCoords, i).y; num_coords++; } gimp_scan_convert_add_polyline (scan_convert, coords->len, points, closed); g_free (points); } if (coords) g_array_free (coords, TRUE); } if (num_coords > 0) gimp_drawable_stroke_scan_convert (drawable, options, scan_convert); gimp_scan_convert_free (scan_convert); }
TempBuf * gimp_vectors_get_new_preview (GimpViewable *viewable, GimpContext *context, gint width, gint height) { GimpVectors *vectors; GimpItem *item; GimpStroke *cur_stroke; gdouble xscale, yscale; guchar *data; TempBuf *temp_buf; guchar white[1] = { 255 }; vectors = GIMP_VECTORS (viewable); item = GIMP_ITEM (viewable); xscale = ((gdouble) width) / gimp_image_get_width (item->image); yscale = ((gdouble) height) / gimp_image_get_height (item->image); temp_buf = temp_buf_new (width, height, 1, 0, 0, white); data = temp_buf_data (temp_buf); for (cur_stroke = gimp_vectors_stroke_get_next (vectors, NULL); cur_stroke; cur_stroke = gimp_vectors_stroke_get_next (vectors, cur_stroke)) { GArray *coords; gboolean closed; gint i; coords = gimp_stroke_interpolate (cur_stroke, 0.5, &closed); if (coords) { for (i = 0; i < coords->len; i++) { GimpCoords point; gint x, y; point = g_array_index (coords, GimpCoords, i); x = ROUND (point.x * xscale); y = ROUND (point.y * yscale); if (x >= 0 && y >= 0 && x < width && y < height) data[y * width + x] = 0; } g_array_free (coords, TRUE); } } return temp_buf; }
void gimp_channel_select_vectors (GimpChannel *channel, const gchar *undo_desc, GimpVectors *vectors, GimpChannelOps op, gboolean antialias, gboolean feather, gdouble feather_radius_x, gdouble feather_radius_y, gboolean push_undo) { GimpScanConvert *scan_convert; GList *stroke; gboolean coords_added = FALSE; g_return_if_fail (GIMP_IS_CHANNEL (channel)); g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (channel))); g_return_if_fail (undo_desc != NULL); g_return_if_fail (GIMP_IS_VECTORS (vectors)); scan_convert = gimp_scan_convert_new (); 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) { GimpVector2 *points; gint i; points = g_new0 (GimpVector2, coords->len); for (i = 0; i < coords->len; i++) { points[i].x = g_array_index (coords, GimpCoords, i).x; points[i].y = g_array_index (coords, GimpCoords, i).y; } gimp_scan_convert_add_polyline (scan_convert, coords->len, points, TRUE); coords_added = TRUE; g_free (points); } if (coords) g_array_free (coords, TRUE); } if (coords_added) gimp_channel_select_scan_convert (channel, undo_desc, scan_convert, 0, 0, op, antialias, feather, feather_radius_x, feather_radius_y, push_undo); gimp_scan_convert_free (scan_convert); }
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; }
static gboolean gimp_vectors_bounds (GimpItem *item, gdouble *x, gdouble *y, gdouble *width, gdouble *height) { GimpVectors *vectors = GIMP_VECTORS (item); if (! vectors->bounds_valid) { GimpStroke *stroke; vectors->bounds_empty = TRUE; vectors->bounds_x1 = vectors->bounds_x2 = 0.0; vectors->bounds_y1 = vectors->bounds_y2 = 0.0; for (stroke = gimp_vectors_stroke_get_next (vectors, NULL); stroke; stroke = gimp_vectors_stroke_get_next (vectors, stroke)) { GArray *stroke_coords; gboolean closed; stroke_coords = gimp_stroke_interpolate (stroke, 1.0, &closed); if (stroke_coords) { GimpCoords point; gint i; if (vectors->bounds_empty && stroke_coords->len > 0) { point = g_array_index (stroke_coords, GimpCoords, 0); vectors->bounds_x1 = vectors->bounds_x2 = point.x; vectors->bounds_y1 = vectors->bounds_y2 = point.y; vectors->bounds_empty = FALSE; } for (i = 0; i < stroke_coords->len; i++) { point = g_array_index (stroke_coords, GimpCoords, i); vectors->bounds_x1 = MIN (vectors->bounds_x1, point.x); vectors->bounds_y1 = MIN (vectors->bounds_y1, point.y); vectors->bounds_x2 = MAX (vectors->bounds_x2, point.x); vectors->bounds_y2 = MAX (vectors->bounds_y2, point.y); } g_array_free (stroke_coords, TRUE); } } vectors->bounds_valid = TRUE; } *x = vectors->bounds_x1; *y = vectors->bounds_y1; *width = vectors->bounds_x2 - vectors->bounds_x1; *height = vectors->bounds_y2 - vectors->bounds_y1; return ! vectors->bounds_empty; }