void gimp_text_layer_rotate (GimpItem *item, GimpContext *context, GimpRotationType rotate_type, gdouble center_x, gdouble center_y, gboolean clip_result) { GimpTextLayer *layer = GIMP_TEXT_LAYER (item); if (! gimp_text_layer_transform_rotate (layer, rotate_type, center_x, center_y)) { GimpLayerMask *mask = gimp_layer_get_mask (GIMP_LAYER (layer)); if (mask) gimp_item_rotate (GIMP_ITEM (mask), context, rotate_type, center_x, center_y, clip_result); } else { gimp_text_layer_parent_class ()->rotate (item, context, rotate_type, center_x, center_y, clip_result); } }
/** * gimp_projection_initialize: * @proj: A #GimpProjection. * @x: * @y: * @w: * @h: * * This function determines whether a visible layer with combine mode * Normal provides complete coverage over the specified area. If not, * the projection is initialized to transparent black. */ static void gimp_projection_initialize (GimpProjection *proj, gint x, gint y, gint w, gint h) { GList *list; gint proj_off_x; gint proj_off_y; gboolean coverage = FALSE; gimp_projectable_get_offset (proj->projectable, &proj_off_x, &proj_off_y); for (list = gimp_projectable_get_layers (proj->projectable); list; list = g_list_next (list)) { GimpLayer *layer = list->data; GimpDrawable *drawable = GIMP_DRAWABLE (layer); GimpItem *item = GIMP_ITEM (layer); gint off_x, off_y; gimp_item_get_offset (item, &off_x, &off_y); /* subtract the projectable's offsets because the list of * update areas is in tile-pyramid coordinates, but our * external API is always in terms of image coordinates. */ off_x -= proj_off_x; off_y -= proj_off_y; if (gimp_item_get_visible (item) && ! gimp_drawable_has_alpha (drawable) && ! gimp_layer_get_mask (layer) && gimp_layer_get_mode (layer) == GIMP_NORMAL_MODE && gimp_layer_get_opacity (layer) == GIMP_OPACITY_OPAQUE && off_x <= x && off_y <= y && (off_x + gimp_item_get_width (item)) >= (x + w) && (off_y + gimp_item_get_height (item)) >= (y + h)) { coverage = TRUE; break; } } if (! coverage) { PixelRegion region; pixel_region_init (®ion, gimp_pickable_get_tiles (GIMP_PICKABLE (proj)), x, y, w, h, TRUE); clear_region (®ion); } }
/* ----------------------- * p_tri_map_preprocessing * ----------------------- * prepare the tri mask for processing * - have bpp == 1 * - have same size and offset as the input drawable (that is a layer) * - pixel values >= 240 are set to value 240 (MATTING_USER_FOREGROUND) * - in case the input layer already has an alpha channel * all fully transparent (alpha == 0) pixels are also set 0 (MATTING_USER_BACKGROUND) * in the tri map to keep pixels fully transparent. (such pixels typicall do not * have a useful color information in the RGB channels) * * * in case the user provided the tri map as layer or channel that is NOT the layermask of the input layer * we create a new dummy layer with same size and offset as the input layer * and add a layermask to this dummy layer. * The layermask of the dummy layer is then filled with the intersecting grayscale copy * of the user-provided triMap drawable and will be used as tri map in the alpha matting processing. * * returns the dawable Id of the relevant TRI MAP that fulfills the conditons listed above. */ static gint32 p_tri_map_preprocessing (GimpDrawable *drawable, GapFgExtractValues *fgValPtr, gint32 *dummyLayerId) { gint32 prepocessedTriMapLayerId; gint32 inputLayerMaskId; gint32 imageId; *dummyLayerId = -1; imageId = gimp_drawable_get_image(drawable->drawable_id); inputLayerMaskId = gimp_layer_get_mask(drawable->drawable_id); if (fgValPtr->tri_map_drawable_id == inputLayerMaskId) { prepocessedTriMapLayerId = inputLayerMaskId; } else { gint offset_x; gint offset_y; gint32 dummyLayerMaskId; gint32 l_fsel_layer_id; *dummyLayerId = gimp_layer_new(imageId , "DUMMY" , drawable->width , drawable->height , GIMP_RGBA_IMAGE , 100.0 /* full opacity */ , GIMP_NORMAL_MODE /* normal mode */ ); /* get offsets of the input drawable (layer) within the image */ gimp_drawable_offsets (drawable->drawable_id, &offset_x, &offset_y); /* add dummy layer (of same size at same offsets) to the same image */ gimp_image_add_layer(imageId, *dummyLayerId, -1 /* stackposition */ ); gimp_layer_set_offsets(*dummyLayerId, offset_x, offset_y); /* create a new layermask (black is full transparent */ dummyLayerMaskId = gimp_layer_create_mask(*dummyLayerId, GIMP_ADD_BLACK_MASK); gimp_layer_add_mask(*dummyLayerId, dummyLayerMaskId); gimp_edit_copy(fgValPtr->tri_map_drawable_id); l_fsel_layer_id = gimp_edit_paste(dummyLayerMaskId, FALSE); gimp_floating_sel_anchor(l_fsel_layer_id); prepocessedTriMapLayerId = dummyLayerMaskId; } gap_fg_rgn_tri_map_normalize(drawable, prepocessedTriMapLayerId); return(prepocessedTriMapLayerId); } /* end p_tri_map_preprocessing */
static gboolean gimp_layer_mask_is_attached (const GimpItem *item) { GimpLayerMask *mask = GIMP_LAYER_MASK (item); GimpLayer *layer = gimp_layer_mask_get_layer (mask); return (GIMP_IS_IMAGE (gimp_item_get_image (item)) && GIMP_IS_LAYER (layer) && gimp_layer_get_mask (layer) == mask && gimp_item_is_attached (GIMP_ITEM (layer))); }
void gimp_display_shell_set_layer_style (GimpDisplayShell *shell, cairo_t *cr, GimpLayer *layer) { cairo_pattern_t *pattern; g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); g_return_if_fail (cr != NULL); g_return_if_fail (GIMP_IS_LAYER (layer)); cairo_set_line_width (cr, 1.0); cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); if (gimp_layer_get_mask (layer) && gimp_layer_mask_get_edit (gimp_layer_get_mask (layer))) { pattern = gimp_cairo_stipple_pattern_create (&layer_mask_fg, &layer_mask_bg, 0); } else if (gimp_viewable_get_children (GIMP_VIEWABLE (layer))) { pattern = gimp_cairo_stipple_pattern_create (&layer_group_fg, &layer_group_bg, 0); } else { pattern = gimp_cairo_stipple_pattern_create (&layer_fg, &layer_bg, 0); } cairo_set_source (cr, pattern); cairo_pattern_destroy (pattern); }
static gint64 gimp_layer_mask_undo_get_memsize (GimpObject *object, gint64 *gui_size) { GimpLayerMaskUndo *layer_mask_undo = GIMP_LAYER_MASK_UNDO (object); GimpLayer *layer = GIMP_LAYER (GIMP_ITEM_UNDO (object)->item); gint64 memsize = 0; /* don't use !gimp_item_is_attached() here */ if (gimp_layer_get_mask (layer) != layer_mask_undo->layer_mask) memsize += gimp_object_get_memsize (GIMP_OBJECT (layer_mask_undo->layer_mask), gui_size); return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object, gui_size); }
static void export_apply_masks (gint32 image_ID, gint *drawable_ID) { gint32 n_layers; gint32 *layers; gint i; layers = gimp_image_get_layers (image_ID, &n_layers); for (i = 0; i < n_layers; i++) { if (gimp_layer_get_mask (layers[i]) != -1) gimp_layer_remove_mask (layers[i], GIMP_MASK_APPLY); } g_free (layers); }
GimpUndo * gimp_image_undo_push_layer_mask_remove (GimpImage *image, const gchar *undo_desc, GimpLayer *layer, GimpLayerMask *mask) { g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (GIMP_IS_LAYER (layer), NULL); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (layer)), NULL); g_return_val_if_fail (GIMP_IS_LAYER_MASK (mask), NULL); g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (mask)), NULL); g_return_val_if_fail (gimp_layer_mask_get_layer (mask) == layer, NULL); g_return_val_if_fail (gimp_layer_get_mask (layer) == mask, NULL); return gimp_image_undo_push (image, GIMP_TYPE_LAYER_MASK_UNDO, GIMP_UNDO_LAYER_MASK_REMOVE, undo_desc, GIMP_DIRTY_IMAGE_STRUCTURE, "item", layer, "layer-mask", mask, NULL); }
void gimp_text_layer_flip (GimpItem *item, GimpContext *context, GimpOrientationType flip_type, gdouble axis, gboolean clip_result) { GimpTextLayer *layer = GIMP_TEXT_LAYER (item); if (gimp_text_layer_transform_flip (layer, flip_type, axis)) { GimpLayerMask *mask = gimp_layer_get_mask (GIMP_LAYER (layer)); if (mask) gimp_item_flip (GIMP_ITEM (mask), context, flip_type, axis, clip_result); } else { gimp_text_layer_parent_class ()->flip (item, context, flip_type, axis, clip_result); } }
GimpDrawable * gimp_drawable_transform_rotate (GimpDrawable *drawable, GimpContext *context, GimpRotationType rotate_type, gdouble center_x, gdouble center_y, gboolean clip_result) { GimpImage *image; GeglBuffer *orig_buffer; gint orig_offset_x; gint orig_offset_y; gboolean new_layer; GimpDrawable *result = 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_CONTEXT (context), NULL); image = gimp_item_get_image (GIMP_ITEM (drawable)); /* Start a transform undo group */ gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_TRANSFORM, C_("undo-type", "Rotate")); /* Cut/Copy from the specified drawable */ orig_buffer = gimp_drawable_transform_cut (drawable, context, &orig_offset_x, &orig_offset_y, &new_layer); if (orig_buffer) { GeglBuffer *new_buffer; gint new_offset_x; gint new_offset_y; /* always clip unfloated buffers so they keep their size */ if (GIMP_IS_CHANNEL (drawable) && ! babl_format_has_alpha (gegl_buffer_get_format (orig_buffer))) clip_result = TRUE; /* also transform the mask if we are transforming an entire layer */ if (GIMP_IS_LAYER (drawable) && gimp_layer_get_mask (GIMP_LAYER (drawable)) && gimp_channel_is_empty (gimp_image_get_mask (image))) { GimpLayerMask *mask = gimp_layer_get_mask (GIMP_LAYER (drawable)); gimp_item_rotate (GIMP_ITEM (mask), context, rotate_type, center_x, center_y, clip_result); } /* transform the buffer */ new_buffer = gimp_drawable_transform_buffer_rotate (drawable, context, orig_buffer, orig_offset_x, orig_offset_y, rotate_type, center_x, center_y, clip_result, &new_offset_x, &new_offset_y); /* Free the cut/copied buffer */ g_object_unref (orig_buffer); if (new_buffer) { result = gimp_drawable_transform_paste (drawable, new_buffer, new_offset_x, new_offset_y, new_layer); g_object_unref (new_buffer); } } /* push the undo group end */ gimp_image_undo_group_end (image); return result; }
GimpDrawable * gimp_drawable_transform_affine (GimpDrawable *drawable, GimpContext *context, const GimpMatrix3 *matrix, GimpTransformDirection direction, GimpInterpolationType interpolation_type, gint recursion_level, GimpTransformResize clip_result, GimpProgress *progress) { GimpImage *image; GeglBuffer *orig_buffer; gint orig_offset_x; gint orig_offset_y; gboolean new_layer; GimpDrawable *result = 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_CONTEXT (context), NULL); g_return_val_if_fail (matrix != NULL, NULL); g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL); image = gimp_item_get_image (GIMP_ITEM (drawable)); /* Start a transform undo group */ gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_TRANSFORM, C_("undo-type", "Transform")); /* Cut/Copy from the specified drawable */ orig_buffer = gimp_drawable_transform_cut (drawable, context, &orig_offset_x, &orig_offset_y, &new_layer); if (orig_buffer) { GeglBuffer *new_buffer; gint new_offset_x; gint new_offset_y; /* always clip unfloated buffers so they keep their size */ if (GIMP_IS_CHANNEL (drawable) && ! babl_format_has_alpha (gegl_buffer_get_format (orig_buffer))) clip_result = GIMP_TRANSFORM_RESIZE_CLIP; /* also transform the mask if we are transforming an entire layer */ if (GIMP_IS_LAYER (drawable) && gimp_layer_get_mask (GIMP_LAYER (drawable)) && gimp_channel_is_empty (gimp_image_get_mask (image))) { GimpLayerMask *mask = gimp_layer_get_mask (GIMP_LAYER (drawable)); gimp_item_transform (GIMP_ITEM (mask), context, matrix, direction, interpolation_type, recursion_level, clip_result, progress); } /* transform the buffer */ new_buffer = gimp_drawable_transform_buffer_affine (drawable, context, orig_buffer, orig_offset_x, orig_offset_y, matrix, direction, interpolation_type, recursion_level, clip_result, &new_offset_x, &new_offset_y, progress); /* Free the cut/copied buffer */ g_object_unref (orig_buffer); if (new_buffer) { result = gimp_drawable_transform_paste (drawable, new_buffer, new_offset_x, new_offset_y, new_layer); g_object_unref (new_buffer); } } /* push the undo group end */ gimp_image_undo_group_end (image); return result; }
static GimpLayer * gimp_image_merge_layers (GimpImage *image, GSList *merge_list, GimpContext *context, GimpMergeType merge_type, const gchar *undo_desc) { GList *list; GSList *reverse_list = NULL; PixelRegion src1PR, src2PR, maskPR; PixelRegion *mask; GimpLayer *merge_layer; GimpLayer *layer; GimpLayer *bottom_layer; GimpImageType type; gint count; gint x1, y1, x2, y2; gint x3, y3, x4, y4; CombinationMode operation; gint position; gboolean active[MAX_CHANNELS] = { TRUE, TRUE, TRUE, TRUE }; gint off_x, off_y; gchar *name; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); layer = NULL; type = GIMP_RGBA_IMAGE; x1 = y1 = 0; x2 = y2 = 0; bottom_layer = NULL; /* Get the layer extents */ count = 0; while (merge_list) { layer = merge_list->data; gimp_item_offsets (GIMP_ITEM (layer), &off_x, &off_y); switch (merge_type) { case GIMP_EXPAND_AS_NECESSARY: case GIMP_CLIP_TO_IMAGE: if (! count) { x1 = off_x; y1 = off_y; x2 = off_x + gimp_item_width (GIMP_ITEM (layer)); y2 = off_y + gimp_item_height (GIMP_ITEM (layer)); } else { if (off_x < x1) x1 = off_x; if (off_y < y1) y1 = off_y; if ((off_x + gimp_item_width (GIMP_ITEM (layer))) > x2) x2 = (off_x + gimp_item_width (GIMP_ITEM (layer))); if ((off_y + gimp_item_height (GIMP_ITEM (layer))) > y2) y2 = (off_y + gimp_item_height (GIMP_ITEM (layer))); } if (merge_type == GIMP_CLIP_TO_IMAGE) { x1 = CLAMP (x1, 0, gimp_image_get_width (image)); y1 = CLAMP (y1, 0, gimp_image_get_height (image)); x2 = CLAMP (x2, 0, gimp_image_get_width (image)); y2 = CLAMP (y2, 0, gimp_image_get_height (image)); } break; case GIMP_CLIP_TO_BOTTOM_LAYER: if (merge_list->next == NULL) { x1 = off_x; y1 = off_y; x2 = off_x + gimp_item_width (GIMP_ITEM (layer)); y2 = off_y + gimp_item_height (GIMP_ITEM (layer)); } break; case GIMP_FLATTEN_IMAGE: if (merge_list->next == NULL) { x1 = 0; y1 = 0; x2 = gimp_image_get_width (image); y2 = gimp_image_get_height (image); } break; } count ++; reverse_list = g_slist_prepend (reverse_list, layer); merge_list = g_slist_next (merge_list); } if ((x2 - x1) == 0 || (y2 - y1) == 0) return NULL; /* Start a merge undo group. */ gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_LAYERS_MERGE, undo_desc); name = g_strdup (gimp_object_get_name (GIMP_OBJECT (layer))); if (merge_type == GIMP_FLATTEN_IMAGE || gimp_drawable_type (GIMP_DRAWABLE (layer)) == GIMP_INDEXED_IMAGE) { guchar bg[4] = { 0, 0, 0, 0 }; type = GIMP_IMAGE_TYPE_FROM_BASE_TYPE (gimp_image_base_type (image)); merge_layer = gimp_layer_new (image, (x2 - x1), (y2 - y1), type, gimp_object_get_name (GIMP_OBJECT (layer)), GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE); if (! merge_layer) { g_warning ("%s: could not allocate merge layer.", G_STRFUNC); return NULL; } GIMP_ITEM (merge_layer)->offset_x = x1; GIMP_ITEM (merge_layer)->offset_y = y1; /* get the background for compositing */ gimp_image_get_background (image, context, gimp_drawable_type (GIMP_DRAWABLE (merge_layer)), bg); /* init the pixel region */ pixel_region_init (&src1PR, gimp_drawable_get_tiles (GIMP_DRAWABLE (merge_layer)), 0, 0, (x2 - x1), (y2 - y1), TRUE); /* set the region to the background color */ color_region (&src1PR, bg); position = 0; } else { /* The final merged layer inherits the name of the bottom most layer * and the resulting layer has an alpha channel whether or not the * original did. Opacity is set to 100% and the MODE is set to normal. */ merge_layer = gimp_layer_new (image, (x2 - x1), (y2 - y1), gimp_drawable_type_with_alpha (GIMP_DRAWABLE (layer)), "merged layer", GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE); if (!merge_layer) { g_warning ("%s: could not allocate merge layer", G_STRFUNC); return NULL; } GIMP_ITEM (merge_layer)->offset_x = x1; GIMP_ITEM (merge_layer)->offset_y = y1; /* clear the layer */ pixel_region_init (&src1PR, gimp_drawable_get_tiles (GIMP_DRAWABLE (merge_layer)), 0, 0, (x2 - x1), (y2 - y1), TRUE); clear_region (&src1PR); /* Find the index in the layer list of the bottom layer--we need this * in order to add the final, merged layer to the layer list correctly */ layer = reverse_list->data; position = gimp_container_num_children (image->layers) - gimp_container_get_child_index (image->layers, GIMP_OBJECT (layer)); } bottom_layer = layer; /* Copy the tattoo and parasites of the bottom layer to the new layer */ gimp_item_set_tattoo (GIMP_ITEM (merge_layer), gimp_item_get_tattoo (GIMP_ITEM (bottom_layer))); g_object_unref (GIMP_ITEM (merge_layer)->parasites); GIMP_ITEM (merge_layer)->parasites = gimp_parasite_list_copy (GIMP_ITEM (bottom_layer)->parasites); while (reverse_list) { GimpLayerModeEffects mode; layer = reverse_list->data; /* determine what sort of operation is being attempted and * if it's actually legal... */ operation = gimp_image_merge_layers_get_operation (merge_layer, layer); if (operation == -1) { gimp_layer_add_alpha (layer); /* try again ... */ operation = gimp_image_merge_layers_get_operation (merge_layer, layer); } if (operation == -1) { g_warning ("%s: attempting to merge incompatible layers.", G_STRFUNC); return NULL; } gimp_item_offsets (GIMP_ITEM (layer), &off_x, &off_y); x3 = CLAMP (off_x, x1, x2); y3 = CLAMP (off_y, y1, y2); x4 = CLAMP (off_x + gimp_item_width (GIMP_ITEM (layer)), x1, x2); y4 = CLAMP (off_y + gimp_item_height (GIMP_ITEM (layer)), y1, y2); /* configure the pixel regions */ pixel_region_init (&src1PR, gimp_drawable_get_tiles (GIMP_DRAWABLE (merge_layer)), (x3 - x1), (y3 - y1), (x4 - x3), (y4 - y3), TRUE); pixel_region_init (&src2PR, gimp_drawable_get_tiles (GIMP_DRAWABLE (layer)), (x3 - off_x), (y3 - off_y), (x4 - x3), (y4 - y3), FALSE); if (gimp_layer_get_mask (layer) && gimp_layer_mask_get_apply (layer->mask)) { TileManager *tiles; tiles = gimp_drawable_get_tiles (GIMP_DRAWABLE (layer->mask)); pixel_region_init (&maskPR, tiles, (x3 - off_x), (y3 - off_y), (x4 - x3), (y4 - y3), FALSE); mask = &maskPR; } else { mask = NULL; } /* DISSOLVE_MODE is special since it is the only mode that does not * work on the projection with the lower layer, but only locally on * the layers alpha channel. */ mode = gimp_layer_get_mode (layer); if (layer == bottom_layer && mode != GIMP_DISSOLVE_MODE) mode = GIMP_NORMAL_MODE; combine_regions (&src1PR, &src2PR, &src1PR, mask, NULL, gimp_layer_get_opacity (layer) * 255.999, mode, active, operation); gimp_image_remove_layer (image, layer); reverse_list = g_slist_next (reverse_list); } g_slist_free (reverse_list); /* if the type is flatten, remove all the remaining layers */ if (merge_type == GIMP_FLATTEN_IMAGE) { list = GIMP_LIST (image->layers)->list; while (list) { layer = list->data; list = g_list_next (list); gimp_image_remove_layer (image, layer); } gimp_image_add_layer (image, merge_layer, position); } else { /* Add the layer to the image */ gimp_image_add_layer (image, merge_layer, gimp_container_num_children (image->layers) - position + 1); } /* set the name after the original layers have been removed so we * don't end up with #2 appended to the name */ gimp_object_take_name (GIMP_OBJECT (merge_layer), name); gimp_item_set_visible (GIMP_ITEM (merge_layer), TRUE, TRUE); /* End the merge undo group */ gimp_image_undo_group_end (image); gimp_drawable_update (GIMP_DRAWABLE (merge_layer), 0, 0, gimp_item_width (GIMP_ITEM (merge_layer)), gimp_item_height (GIMP_ITEM (merge_layer))); return merge_layer; }
static GimpLayer * gimp_image_merge_layers (GimpImage *image, GimpContainer *container, GSList *merge_list, GimpContext *context, GimpMergeType merge_type) { GList *list; GSList *reverse_list = NULL; GSList *layers; GimpLayer *merge_layer; GimpLayer *layer; GimpLayer *bottom_layer; GimpParasiteList *parasites; gint count; gint x1, y1, x2, y2; gint off_x, off_y; gint position; gchar *name; GimpLayer *parent; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); layer = NULL; x1 = y1 = 0; x2 = y2 = 0; bottom_layer = NULL; parent = gimp_layer_get_parent (merge_list->data); /* Get the layer extents */ count = 0; while (merge_list) { layer = merge_list->data; gimp_item_get_offset (GIMP_ITEM (layer), &off_x, &off_y); switch (merge_type) { case GIMP_EXPAND_AS_NECESSARY: case GIMP_CLIP_TO_IMAGE: if (! count) { x1 = off_x; y1 = off_y; x2 = off_x + gimp_item_get_width (GIMP_ITEM (layer)); y2 = off_y + gimp_item_get_height (GIMP_ITEM (layer)); } else { if (off_x < x1) x1 = off_x; if (off_y < y1) y1 = off_y; if ((off_x + gimp_item_get_width (GIMP_ITEM (layer))) > x2) x2 = (off_x + gimp_item_get_width (GIMP_ITEM (layer))); if ((off_y + gimp_item_get_height (GIMP_ITEM (layer))) > y2) y2 = (off_y + gimp_item_get_height (GIMP_ITEM (layer))); } if (merge_type == GIMP_CLIP_TO_IMAGE) { x1 = CLAMP (x1, 0, gimp_image_get_width (image)); y1 = CLAMP (y1, 0, gimp_image_get_height (image)); x2 = CLAMP (x2, 0, gimp_image_get_width (image)); y2 = CLAMP (y2, 0, gimp_image_get_height (image)); } break; case GIMP_CLIP_TO_BOTTOM_LAYER: if (merge_list->next == NULL) { x1 = off_x; y1 = off_y; x2 = off_x + gimp_item_get_width (GIMP_ITEM (layer)); y2 = off_y + gimp_item_get_height (GIMP_ITEM (layer)); } break; case GIMP_FLATTEN_IMAGE: if (merge_list->next == NULL) { x1 = 0; y1 = 0; x2 = gimp_image_get_width (image); y2 = gimp_image_get_height (image); } break; } count ++; reverse_list = g_slist_prepend (reverse_list, layer); merge_list = g_slist_next (merge_list); } if ((x2 - x1) == 0 || (y2 - y1) == 0) return NULL; /* Start a merge undo group. */ name = g_strdup (gimp_object_get_name (layer)); if (merge_type == GIMP_FLATTEN_IMAGE || (gimp_drawable_is_indexed (GIMP_DRAWABLE (layer)) && ! gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))) { GeglColor *color; GimpRGB bg; merge_layer = gimp_layer_new (image, (x2 - x1), (y2 - y1), gimp_image_get_layer_format (image, FALSE), gimp_object_get_name (layer), GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE); if (! merge_layer) { g_warning ("%s: could not allocate merge layer.", G_STRFUNC); return NULL; } gimp_item_set_offset (GIMP_ITEM (merge_layer), x1, y1); /* get the background for compositing */ gimp_context_get_background (context, &bg); color = gimp_gegl_color_new (&bg); gegl_buffer_set_color (gimp_drawable_get_buffer (GIMP_DRAWABLE (merge_layer)), GEGL_RECTANGLE(0,0,x2-x1,y2-y1), color); g_object_unref (color); position = 0; } else { /* The final merged layer inherits the name of the bottom most layer * and the resulting layer has an alpha channel whether or not the * original did. Opacity is set to 100% and the MODE is set to normal. */ merge_layer = gimp_layer_new (image, (x2 - x1), (y2 - y1), gimp_drawable_get_format_with_alpha (GIMP_DRAWABLE (layer)), "merged layer", GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE); if (!merge_layer) { g_warning ("%s: could not allocate merge layer", G_STRFUNC); return NULL; } gimp_item_set_offset (GIMP_ITEM (merge_layer), x1, y1); /* clear the layer */ gegl_buffer_clear (gimp_drawable_get_buffer (GIMP_DRAWABLE (merge_layer)), NULL); /* Find the index in the layer list of the bottom layer--we need this * in order to add the final, merged layer to the layer list correctly */ layer = reverse_list->data; position = gimp_container_get_n_children (container) - gimp_container_get_child_index (container, GIMP_OBJECT (layer)); } bottom_layer = layer; /* Copy the tattoo and parasites of the bottom layer to the new layer */ gimp_item_set_tattoo (GIMP_ITEM (merge_layer), gimp_item_get_tattoo (GIMP_ITEM (bottom_layer))); parasites = gimp_item_get_parasites (GIMP_ITEM (bottom_layer)); parasites = gimp_parasite_list_copy (parasites); gimp_item_set_parasites (GIMP_ITEM (merge_layer), parasites); g_object_unref (parasites); for (layers = reverse_list; layers; layers = g_slist_next (layers)) { GeglBuffer *merge_buffer; GeglBuffer *layer_buffer; GimpApplicator *applicator; GimpLayerModeEffects mode; layer = layers->data; gimp_item_get_offset (GIMP_ITEM (layer), &off_x, &off_y); /* DISSOLVE_MODE is special since it is the only mode that does not * work on the projection with the lower layer, but only locally on * the layers alpha channel. */ mode = gimp_layer_get_mode (layer); if (layer == bottom_layer && mode != GIMP_DISSOLVE_MODE) mode = GIMP_NORMAL_MODE; merge_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (merge_layer)); layer_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer)); applicator = gimp_applicator_new (NULL, gimp_drawable_get_linear (GIMP_DRAWABLE (layer)), FALSE, FALSE); if (gimp_layer_get_mask (layer) && gimp_layer_get_apply_mask (layer)) { GeglBuffer *mask_buffer; mask_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer->mask)); gimp_applicator_set_mask_buffer (applicator, mask_buffer); gimp_applicator_set_mask_offset (applicator, - (x1 - off_x), - (y1 - off_y)); } gimp_applicator_set_src_buffer (applicator, merge_buffer); gimp_applicator_set_dest_buffer (applicator, merge_buffer); gimp_applicator_set_apply_buffer (applicator, layer_buffer); gimp_applicator_set_apply_offset (applicator, - (x1 - off_x), - (y1 - off_y)); gimp_applicator_set_mode (applicator, gimp_layer_get_opacity (layer), mode); gimp_applicator_blit (applicator, GEGL_RECTANGLE (0, 0, gegl_buffer_get_width (merge_buffer), gegl_buffer_get_height (merge_buffer))); g_object_unref (applicator); gimp_image_remove_layer (image, layer, TRUE, NULL); } g_slist_free (reverse_list); gimp_object_take_name (GIMP_OBJECT (merge_layer), name); gimp_item_set_visible (GIMP_ITEM (merge_layer), TRUE, FALSE); /* if the type is flatten, remove all the remaining layers */ if (merge_type == GIMP_FLATTEN_IMAGE) { list = gimp_image_get_layer_iter (image); while (list) { layer = list->data; list = g_list_next (list); gimp_image_remove_layer (image, layer, TRUE, NULL); } gimp_image_add_layer (image, merge_layer, parent, position, TRUE); } else { /* Add the layer to the image */ gimp_image_add_layer (image, merge_layer, parent, gimp_container_get_n_children (container) - position + 1, TRUE); } gimp_drawable_update (GIMP_DRAWABLE (merge_layer), 0, 0, gimp_item_get_width (GIMP_ITEM (merge_layer)), gimp_item_get_height (GIMP_ITEM (merge_layer))); return merge_layer; }
static TileManager * gimp_flip_tool_transform (GimpTransformTool *trans_tool, GimpItem *active_item, gboolean mask_empty, GimpDisplay *display) { GimpFlipOptions *options = GIMP_FLIP_TOOL_GET_OPTIONS (trans_tool); GimpTransformOptions *tr_options = GIMP_TRANSFORM_OPTIONS (options); GimpContext *context = GIMP_CONTEXT (options); gdouble axis = 0.0; TileManager *ret = NULL; switch (options->flip_type) { case GIMP_ORIENTATION_HORIZONTAL: axis = ((gdouble) trans_tool->x1 + (gdouble) (trans_tool->x2 - trans_tool->x1) / 2.0); break; case GIMP_ORIENTATION_VERTICAL: axis = ((gdouble) trans_tool->y1 + (gdouble) (trans_tool->y2 - trans_tool->y1) / 2.0); break; default: break; } if (gimp_item_get_linked (active_item)) gimp_item_linked_flip (active_item, context, options->flip_type, axis, FALSE); if (GIMP_IS_LAYER (active_item) && gimp_layer_get_mask (GIMP_LAYER (active_item)) && mask_empty) { GimpLayerMask *mask = gimp_layer_get_mask (GIMP_LAYER (active_item)); gimp_item_flip (GIMP_ITEM (mask), context, options->flip_type, axis, FALSE); } switch (tr_options->type) { case GIMP_TRANSFORM_TYPE_LAYER: case GIMP_TRANSFORM_TYPE_SELECTION: if (trans_tool->original) ret = gimp_drawable_transform_tiles_flip (GIMP_DRAWABLE (active_item), context, trans_tool->original, options->flip_type, axis, FALSE); break; case GIMP_TRANSFORM_TYPE_PATH: gimp_item_flip (active_item, context, options->flip_type, axis, FALSE); break; } return ret; }
/** * gimp_export_image: * @image_ID: Pointer to the image_ID. * @drawable_ID: Pointer to the drawable_ID. * @format_name: The (short) name of the image_format (e.g. JPEG or GIF). * @capabilities: What can the image_format do? * * Takes an image and a drawable to be saved together with a * description of the capabilities of the image_format. If the * type of image doesn't match the capabilities of the format * a dialog is opened that informs the user that the image has * to be exported and offers to do the necessary conversions. * * If the user chooses to export the image, a copy is created. * This copy is then converted, the image_ID and drawable_ID * are changed to point to the new image and the procedure returns * GIMP_EXPORT_EXPORT. The save_plugin has to take care of deleting the * created image using gimp_image_delete() when it has saved it. * * If the user chooses to Ignore the export problem, the image_ID * and drawable_ID is not altered, GIMP_EXPORT_IGNORE is returned and * the save_plugin should try to save the original image. If the * user chooses Cancel, GIMP_EXPORT_CANCEL is returned and the * save_plugin should quit itself with status %GIMP_PDB_CANCEL. * * If @format_name is NULL, no dialogs will be shown and this function * will behave as if the user clicked on the 'Export' button, if a * dialog would have been shown. * * Returns: An enum of #GimpExportReturn describing the user_action. **/ GimpExportReturn gimp_export_image (gint32 *image_ID, gint32 *drawable_ID, const gchar *format_name, GimpExportCapabilities capabilities) { GSList *actions = NULL; GimpImageBaseType type; gint32 i; gint32 n_layers; gint32 *layers; gboolean interactive = FALSE; gboolean added_flatten = FALSE; gboolean has_layer_masks = FALSE; gboolean background_has_alpha = TRUE; GimpExportReturn retval = GIMP_EXPORT_CANCEL; g_return_val_if_fail (*image_ID > -1 && *drawable_ID > -1, FALSE); /* do some sanity checks */ if (capabilities & GIMP_EXPORT_NEEDS_ALPHA) capabilities |= GIMP_EXPORT_CAN_HANDLE_ALPHA; if (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS_AS_ANIMATION) capabilities |= GIMP_EXPORT_CAN_HANDLE_LAYERS; if (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYER_MASKS) capabilities |= GIMP_EXPORT_CAN_HANDLE_LAYERS; if (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS) capabilities |= GIMP_EXPORT_CAN_HANDLE_ALPHA; if (format_name && g_getenv ("GIMP_INTERACTIVE_EXPORT")) interactive = TRUE; /* ask for confirmation if the user is not saving a layer (see bug #51114) */ if (interactive && ! gimp_item_is_layer (*drawable_ID) && ! (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS)) { if (gimp_item_is_layer_mask (*drawable_ID)) { retval = confirm_save_dialog (_("You are about to save a layer mask as %s.\n" "This will not save the visible layers."), format_name); } else if (gimp_item_is_channel (*drawable_ID)) { retval = confirm_save_dialog (_("You are about to save a channel (saved selection) as %s.\n" "This will not save the visible layers."), format_name); } else { /* this should not happen */ g_warning ("%s: unknown drawable type!", G_STRFUNC); } /* cancel - the user can then select an appropriate layer to save */ if (retval == GIMP_EXPORT_CANCEL) return GIMP_EXPORT_CANCEL; } /* check alpha and layer masks */ layers = gimp_image_get_layers (*image_ID, &n_layers); for (i = 0; i < n_layers; i++) { if (gimp_drawable_has_alpha (layers[i])) { if (! (capabilities & GIMP_EXPORT_CAN_HANDLE_ALPHA)) { actions = g_slist_prepend (actions, &export_action_flatten); added_flatten = TRUE; break; } } else { /* If this is the last layer, it's visible and has no alpha * channel, then the image has a "flat" background */ if (i == n_layers - 1 && gimp_item_get_visible (layers[i])) background_has_alpha = FALSE; if (capabilities & GIMP_EXPORT_NEEDS_ALPHA) { actions = g_slist_prepend (actions, &export_action_add_alpha); break; } } } if (! added_flatten) { for (i = 0; i < n_layers; i++) { if (gimp_layer_get_mask (layers[i]) != -1) has_layer_masks = TRUE; } } if (! added_flatten) { gint32 n_children; gint32 *children; children = gimp_item_get_children (layers[0], &n_children); /* check if layer size != canvas size, opacity != 100%, or offsets != 0 */ if (n_layers == 1 && ! children && gimp_item_is_layer (*drawable_ID) && ! (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS)) { gint offset_x; gint offset_y; gimp_drawable_offsets (*drawable_ID, &offset_x, &offset_y); if ((gimp_layer_get_opacity (*drawable_ID) < 100.0) || (gimp_image_width (*image_ID) != gimp_drawable_width (*drawable_ID)) || (gimp_image_height (*image_ID) != gimp_drawable_height (*drawable_ID)) || offset_x || offset_y) { if (capabilities & GIMP_EXPORT_CAN_HANDLE_ALPHA) { actions = g_slist_prepend (actions, &export_action_merge_single); } else { actions = g_slist_prepend (actions, &export_action_flatten); } } } /* check multiple layers */ else if (n_layers > 1) { if (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS_AS_ANIMATION) { if (background_has_alpha || capabilities & GIMP_EXPORT_NEEDS_ALPHA) actions = g_slist_prepend (actions, &export_action_animate_or_merge); else actions = g_slist_prepend (actions, &export_action_animate_or_flatten); } else if (! (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS)) { if (capabilities & GIMP_EXPORT_NEEDS_ALPHA) actions = g_slist_prepend (actions, &export_action_merge); else actions = g_slist_prepend (actions, &export_action_merge_or_flatten); } } /* check for a single toplevel layer group */ else if (children) { if (! (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS)) { if (capabilities & GIMP_EXPORT_NEEDS_ALPHA) actions = g_slist_prepend (actions, &export_action_merge); else actions = g_slist_prepend (actions, &export_action_merge_or_flatten); } } g_free (children); /* check layer masks */ if (has_layer_masks && ! (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYER_MASKS)) actions = g_slist_prepend (actions, &export_action_apply_masks); } g_free (layers); /* check the image type */ type = gimp_image_base_type (*image_ID); switch (type) { case GIMP_RGB: if (! (capabilities & GIMP_EXPORT_CAN_HANDLE_RGB)) { if ((capabilities & GIMP_EXPORT_CAN_HANDLE_INDEXED) && (capabilities & GIMP_EXPORT_CAN_HANDLE_GRAY)) actions = g_slist_prepend (actions, &export_action_convert_indexed_or_grayscale); else if (capabilities & GIMP_EXPORT_CAN_HANDLE_INDEXED) actions = g_slist_prepend (actions, &export_action_convert_indexed); else if (capabilities & GIMP_EXPORT_CAN_HANDLE_GRAY) actions = g_slist_prepend (actions, &export_action_convert_grayscale); else if (capabilities & GIMP_EXPORT_CAN_HANDLE_BITMAP) actions = g_slist_prepend (actions, &export_action_convert_bitmap); } break; case GIMP_GRAY: if (! (capabilities & GIMP_EXPORT_CAN_HANDLE_GRAY)) { if ((capabilities & GIMP_EXPORT_CAN_HANDLE_RGB) && (capabilities & GIMP_EXPORT_CAN_HANDLE_INDEXED)) actions = g_slist_prepend (actions, &export_action_convert_rgb_or_indexed); else if (capabilities & GIMP_EXPORT_CAN_HANDLE_RGB) actions = g_slist_prepend (actions, &export_action_convert_rgb); else if (capabilities & GIMP_EXPORT_CAN_HANDLE_INDEXED) actions = g_slist_prepend (actions, &export_action_convert_indexed); else if (capabilities & GIMP_EXPORT_CAN_HANDLE_BITMAP) actions = g_slist_prepend (actions, &export_action_convert_bitmap); } break; case GIMP_INDEXED: if (! (capabilities & GIMP_EXPORT_CAN_HANDLE_INDEXED)) { if ((capabilities & GIMP_EXPORT_CAN_HANDLE_RGB) && (capabilities & GIMP_EXPORT_CAN_HANDLE_GRAY)) actions = g_slist_prepend (actions, &export_action_convert_rgb_or_grayscale); else if (capabilities & GIMP_EXPORT_CAN_HANDLE_RGB) actions = g_slist_prepend (actions, &export_action_convert_rgb); else if (capabilities & GIMP_EXPORT_CAN_HANDLE_GRAY) actions = g_slist_prepend (actions, &export_action_convert_grayscale); else if (capabilities & GIMP_EXPORT_CAN_HANDLE_BITMAP) { gint n_colors; g_free (gimp_image_get_colormap (*image_ID, &n_colors)); if (n_colors > 2) actions = g_slist_prepend (actions, &export_action_convert_bitmap); } } break; } if (actions) { actions = g_slist_reverse (actions); if (interactive) retval = export_dialog (actions, format_name); else retval = GIMP_EXPORT_EXPORT; } else { retval = GIMP_EXPORT_IGNORE; } if (retval == GIMP_EXPORT_EXPORT) { GSList *list; *image_ID = gimp_image_duplicate (*image_ID); *drawable_ID = gimp_image_get_active_layer (*image_ID); gimp_image_undo_disable (*image_ID); for (list = actions; list; list = list->next) { export_action_perform (list->data, *image_ID, drawable_ID); } } g_slist_free (actions); return retval; }
void layers_actions_update (GimpActionGroup *group, gpointer data) { GimpImage *image = action_data_get_image (data); GimpLayer *layer = NULL; GimpLayerMask *mask = NULL; /* layer mask */ gboolean fs = FALSE; /* floating sel */ gboolean ac = FALSE; /* active channel */ gboolean sel = FALSE; gboolean alpha = FALSE; /* alpha channel present */ gboolean indexed = FALSE; /* is indexed */ gboolean lock_alpha = FALSE; gboolean can_lock_alpha = FALSE; gboolean text_layer = FALSE; gboolean writable = FALSE; gboolean children = FALSE; GList *next = NULL; GList *next_visible = NULL; GList *prev = NULL; if (image) { fs = (gimp_image_get_floating_selection (image) != NULL); ac = (gimp_image_get_active_channel (image) != NULL); sel = ! gimp_channel_is_empty (gimp_image_get_mask (image)); indexed = (gimp_image_base_type (image) == GIMP_INDEXED); layer = gimp_image_get_active_layer (image); if (layer) { GList *layer_list; GList *list; mask = gimp_layer_get_mask (layer); lock_alpha = gimp_layer_get_lock_alpha (layer); can_lock_alpha = gimp_layer_can_lock_alpha (layer); alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)); writable = ! gimp_item_is_content_locked (GIMP_ITEM (layer)); if (gimp_viewable_get_children (GIMP_VIEWABLE (layer))) children = TRUE; layer_list = gimp_item_get_container_iter (GIMP_ITEM (layer)); list = g_list_find (layer_list, layer); if (list) { prev = g_list_previous (list); next = g_list_next (list); for (next_visible = next; next_visible; next_visible = g_list_next (next_visible)) { if (gimp_item_get_visible (next_visible->data)) { /* "next_visible" is actually "next_visible" and * "writable" and "not group" */ if (gimp_item_is_content_locked (next_visible->data) || gimp_viewable_get_children (next_visible->data)) next_visible = NULL; break; } } } text_layer = gimp_item_is_text_layer (GIMP_ITEM (layer)); } } #define SET_VISIBLE(action,condition) \ gimp_action_group_set_action_visible (group, action, (condition) != 0) #define SET_SENSITIVE(action,condition) \ gimp_action_group_set_action_sensitive (group, action, (condition) != 0) #define SET_ACTIVE(action,condition) \ gimp_action_group_set_action_active (group, action, (condition) != 0) #define SET_LABEL(action,label) \ gimp_action_group_set_action_label (group, action, label) SET_VISIBLE ("layers-text-tool", text_layer && !ac); SET_SENSITIVE ("layers-edit-attributes", layer && !fs && !ac); if (layer && gimp_layer_is_floating_sel (layer)) { SET_LABEL ("layers-new", C_("layers-action", "To _New Layer")); SET_LABEL ("layers-new-last-values", C_("layers-action", "To _New Layer")); } else { SET_LABEL ("layers-new", C_("layers-action", "_New Layer...")); SET_LABEL ("layers-new-last-values", C_("layers-action", "_New Layer")); } SET_SENSITIVE ("layers-new", image); SET_SENSITIVE ("layers-new-last-values", image); SET_SENSITIVE ("layers-new-from-visible", image); SET_SENSITIVE ("layers-new-group", image && !indexed); SET_SENSITIVE ("layers-duplicate", layer && !fs && !ac); SET_SENSITIVE ("layers-delete", layer && !ac); SET_SENSITIVE ("layers-select-top", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-select-bottom", layer && !fs && !ac && next); SET_SENSITIVE ("layers-select-previous", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-select-next", layer && !fs && !ac && next); SET_SENSITIVE ("layers-raise", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-raise-to-top", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-lower", layer && !fs && !ac && next); SET_SENSITIVE ("layers-lower-to-bottom", layer && !fs && !ac && next); SET_SENSITIVE ("layers-anchor", layer && fs && !ac); SET_SENSITIVE ("layers-merge-down", layer && !fs && !ac && next_visible); SET_VISIBLE ("layers-merge-group", children); SET_SENSITIVE ("layers-merge-group", layer && !fs && !ac && children); SET_SENSITIVE ("layers-merge-layers", layer && !fs && !ac); SET_SENSITIVE ("layers-flatten-image", layer && !fs && !ac); SET_VISIBLE ("layers-text-discard", text_layer && !ac); SET_VISIBLE ("layers-text-to-vectors", text_layer && !ac); SET_VISIBLE ("layers-text-along-vectors", text_layer && !ac); SET_SENSITIVE ("layers-resize", writable && !ac); SET_SENSITIVE ("layers-resize-to-image", writable && !ac); SET_SENSITIVE ("layers-scale", writable && !ac); SET_SENSITIVE ("layers-crop", writable && sel); SET_SENSITIVE ("layers-alpha-add", writable && !children && !fs && !alpha); SET_SENSITIVE ("layers-alpha-remove", writable && !children && !fs && alpha); SET_SENSITIVE ("layers-lock-alpha", can_lock_alpha); SET_ACTIVE ("layers-lock-alpha", lock_alpha); SET_SENSITIVE ("layers-mask-add", layer && !fs && !ac && !mask && !children); SET_SENSITIVE ("layers-mask-apply", writable && !fs && !ac && mask && !children); SET_SENSITIVE ("layers-mask-delete", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-edit", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-show", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-disable", layer && !fs && !ac && mask); SET_ACTIVE ("layers-mask-edit", mask && gimp_layer_mask_get_edit (mask)); SET_ACTIVE ("layers-mask-show", mask && gimp_layer_mask_get_show (mask)); SET_ACTIVE ("layers-mask-disable", mask && !gimp_layer_mask_get_apply (mask)); SET_SENSITIVE ("layers-mask-selection-replace", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-selection-add", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-selection-subtract", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-selection-intersect", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-alpha-selection-replace", layer && !fs && !ac); SET_SENSITIVE ("layers-alpha-selection-add", layer && !fs && !ac); SET_SENSITIVE ("layers-alpha-selection-subtract", layer && !fs && !ac); SET_SENSITIVE ("layers-alpha-selection-intersect", layer && !fs && !ac); #undef SET_VISIBLE #undef SET_SENSITIVE #undef SET_ACTIVE #undef SET_LABEL }
static gboolean gimp_text_layer_render (GimpTextLayer *layer) { GimpDrawable *drawable; GimpItem *item; GimpImage *image; GimpTextLayout *layout; gdouble xres; gdouble yres; gint width; gint height; if (! layer->text) return FALSE; drawable = GIMP_DRAWABLE (layer); item = GIMP_ITEM (layer); image = gimp_item_get_image (item); if (gimp_container_is_empty (image->gimp->fonts)) { gimp_message_literal (image->gimp, NULL, GIMP_MESSAGE_ERROR, _("Due to lack of any fonts, " "text functionality is not available.")); return FALSE; } gimp_image_get_resolution (image, &xres, &yres); layout = gimp_text_layout_new (layer->text, xres, yres); g_object_freeze_notify (G_OBJECT (drawable)); if (gimp_text_layout_get_size (layout, &width, &height) && (width != gimp_item_get_width (item) || height != gimp_item_get_height (item))) { GeglBuffer *new_buffer; new_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0, width, height), gimp_drawable_get_format (drawable)); gimp_drawable_set_buffer (drawable, FALSE, NULL, new_buffer); g_object_unref (new_buffer); if (gimp_layer_get_mask (GIMP_LAYER (layer))) { GimpLayerMask *mask = gimp_layer_get_mask (GIMP_LAYER (layer)); static GimpContext *unused_eek = NULL; if (! unused_eek) unused_eek = gimp_context_new (image->gimp, "eek", NULL); gimp_item_resize (GIMP_ITEM (mask), unused_eek, width, height, 0, 0); } } if (layer->auto_rename) { GimpItem *item = GIMP_ITEM (layer); gchar *name = NULL; if (layer->text->text) { name = gimp_utf8_strtrim (layer->text->text, 30); } else if (layer->text->markup) { gchar *tmp = gimp_markup_extract_text (layer->text->markup); name = gimp_utf8_strtrim (tmp, 30); g_free (tmp); } if (! name) name = g_strdup (_("Empty Text Layer")); if (gimp_item_is_attached (item)) { gimp_item_tree_rename_item (gimp_item_get_tree (item), item, name, FALSE, NULL); g_free (name); } else { gimp_object_take_name (GIMP_OBJECT (layer), name); } } gimp_text_layer_render_layout (layer, layout); g_object_unref (layout); g_object_thaw_notify (G_OBJECT (drawable)); return (width > 0 && height > 0); }
/* -------------------------------------------- * gap_fg_from_selection_exec_apply_run * -------------------------------------------- * generate a tri map from the current selection by filling the shrinked * shape with white, the expanded shape with black and the borderline * between shrinked and expanded selection with medium gray. * the trimap is attached as layermask to the input drawable, * and used as input for the foreground selection via alpha matting algorithm, * that creates a resulting layer with trimmed selection. * */ gint gap_fg_from_selection_exec_apply_run (gint32 image_id, gint32 drawable_id , gboolean doProgress, gboolean doFlush , GapFgSelectValues *fsValPtr) { GimpRGB color; gint32 activeSelection; gint32 shrinkedSelection; gint32 trimap; gboolean hadSelection; gint rc; rc = 0; trimap = -1; activeSelection = -1; shrinkedSelection = -1; hadSelection = FALSE; gimp_context_push(); gimp_image_undo_group_start(image_id); if (gimp_selection_is_empty(image_id) == TRUE) { if (gimp_drawable_has_alpha(drawable_id) == FALSE) { /* if the layer has no alpha select all */ gimp_selection_all(image_id); } else { gimp_selection_layer_alpha(drawable_id); } activeSelection = gimp_selection_save(image_id); } else { activeSelection = gimp_selection_save(image_id); hadSelection = TRUE; } trimap = gimp_layer_get_mask(drawable_id); if (trimap < 0) { /* create trimap as new layermask */ trimap = gimp_layer_create_mask(drawable_id, GIMP_ADD_BLACK_MASK); gimp_layer_add_mask(drawable_id, trimap); } else { /* use BLACK color to fill the already existing layermask * (note that gimp_drawable_fill is used to fill the entire mask * regardless to the current selection) */ color.r = 0.0; color.g = 0.0; color.b = 0.0; color.a = 1.0; gimp_context_set_background (&color); gimp_drawable_fill(trimap, GIMP_BACKGROUND_FILL); } gimp_selection_sharpen(image_id); if (fsValPtr->innerRadius > 0) { gimp_selection_shrink(image_id, fsValPtr->innerRadius); } shrinkedSelection = gimp_selection_save(image_id); /* use WHITE color to mark foreground regions */ color.r = 1.0; color.g = 1.0; color.b = 1.0; color.a = 1.0; gimp_context_set_background (&color); gimp_edit_fill(trimap, GIMP_BACKGROUND_FILL); gimp_selection_load(activeSelection); gimp_selection_sharpen(image_id); if (fsValPtr->outerRadius > 0) { gimp_selection_grow(image_id, fsValPtr->outerRadius); } gimp_selection_combine(shrinkedSelection, GIMP_CHANNEL_OP_SUBTRACT); /* use medium GRAY to mark undefined regions */ color.r = 0.5; color.g = 0.5; color.b = 0.5; color.a = 1.0; gimp_context_set_background (&color); gimp_edit_fill(trimap, GIMP_BACKGROUND_FILL); gimp_selection_none(image_id); /* perform the foreground selection (that creates the resulting layer) */ { GapFgExtractValues fgExtractValues; GapFgExtractValues *fgValPtr; fgValPtr = &fgExtractValues; fgValPtr->input_drawable_id = drawable_id; fgValPtr->tri_map_drawable_id = trimap; fgValPtr->create_result = TRUE; fgValPtr->create_layermask = fsValPtr->create_layermask; fgValPtr->lock_color = fsValPtr->lock_color; fgValPtr->colordiff_threshold = fsValPtr->colordiff_threshold; rc = gap_fg_matting_exec_apply_run (image_id, drawable_id , doProgress, doFlush , fgValPtr ); } /* restore original selection */ if (hadSelection == TRUE) { gimp_selection_load(activeSelection); } gimp_image_undo_group_end(image_id); gimp_context_pop(); return (rc); } /* end gap_fg_from_selection_exec_apply_run */
/* ----------------------------- * gap_fg_matting_exec_apply_run * ----------------------------- * handle undo, progress init and * apply the processing functions */ gint32 gap_fg_matting_exec_apply_run (gint32 image_id, gint32 drawable_id , gboolean doProgress, gboolean doFlush , GapFgExtractValues *fgValPtr) { gint32 retLayerId; gint32 oldLayerMaskId; gint32 triMapOrig; gint32 triMapRelevant; gint32 dummyLayerId; GimpDrawable *maskDrawable; GimpDrawable *activeDrawable; /* dont operate on other drawables than layers */ g_return_val_if_fail (gimp_drawable_is_layer(drawable_id), -1); globalDoProgress = doProgress; triMapOrig = fgValPtr->tri_map_drawable_id; /* try to use layermask as tri-mask * in case negative id was specified by the caller */ oldLayerMaskId = gimp_layer_get_mask(drawable_id); if (fgValPtr->tri_map_drawable_id < 0) { fgValPtr->tri_map_drawable_id = oldLayerMaskId; } gimp_image_undo_group_start (image_id); if (doProgress) { gimp_progress_init (_("Foreground Extract")); } activeDrawable = gimp_drawable_get (drawable_id); triMapRelevant = p_tri_map_preprocessing (activeDrawable, fgValPtr, &dummyLayerId); maskDrawable = gimp_drawable_get(triMapRelevant); if (maskDrawable == NULL) { gimp_image_undo_group_end (image_id); gimp_drawable_detach (activeDrawable); printf("ERROR: no valid tri-mask was specified\n"); return (-1); } if(gap_debug) { printf("gap_fg_matting_exec_apply_run START: drawableID:%d triMapOrig:%d tri_map_drawable_id:%d triMapRelevant:%d\n" " create_layermask:%d lock_color:%d " " create_result:%d colordiff_threshold:%.5f" "\n" , (int)drawable_id , (int)triMapOrig , (int)fgValPtr->tri_map_drawable_id , (int)triMapRelevant , (int)fgValPtr->create_layermask , (int)fgValPtr->lock_color , (int)fgValPtr->create_result , (float)fgValPtr->colordiff_threshold ); } retLayerId = gap_drawable_foreground_extract (activeDrawable, maskDrawable, fgValPtr); gimp_drawable_detach (maskDrawable); if(dummyLayerId >= 0) { if(gap_debug) { printf("removing dummy layer:%d\n" ,(int) dummyLayerId ); } gimp_image_remove_layer(image_id, dummyLayerId); } if (doProgress) { gimp_progress_update(1.0); } gimp_image_undo_group_end (image_id); if(gap_debug) { printf("gap_fg_matting_exec_apply_run DONE: retLayerId:%d\n" , (int)retLayerId ); } if (doFlush != FALSE) { gimp_drawable_flush (activeDrawable); } gimp_drawable_detach (activeDrawable); return (retLayerId); } /* end gap_fg_matting_exec_apply_run */
GimpLayer * gimp_edit_paste (GimpImage *image, GimpDrawable *drawable, GimpObject *paste, GimpPasteType paste_type, gint viewport_x, gint viewport_y, gint viewport_width, gint viewport_height) { GimpLayer *layer = NULL; const Babl *floating_format; gint offset_x; gint offset_y; g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL); g_return_val_if_fail (drawable == NULL || GIMP_IS_DRAWABLE (drawable), NULL); g_return_val_if_fail (drawable == NULL || gimp_item_is_attached (GIMP_ITEM (drawable)), NULL); g_return_val_if_fail (GIMP_IS_IMAGE (paste) || GIMP_IS_BUFFER (paste), NULL); /* change paste type to NEW_LAYER for cases where we can't attach a * floating selection */ if (! drawable || gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) || gimp_item_is_content_locked (GIMP_ITEM (drawable))) { paste_type = GIMP_PASTE_TYPE_NEW_LAYER; } /* floating pastes always have the pasted-to drawable's format with * alpha; if drawable == NULL, user is pasting into an empty image */ if (drawable) floating_format = gimp_drawable_get_format_with_alpha (drawable); else floating_format = gimp_image_get_layer_format (image, TRUE); if (GIMP_IS_IMAGE (paste)) { GType layer_type; layer = gimp_image_get_layer_iter (GIMP_IMAGE (paste))->data; switch (paste_type) { case GIMP_PASTE_TYPE_FLOATING: case GIMP_PASTE_TYPE_FLOATING_INTO: /* when pasting as floating selection, force creation of a * plain layer, so gimp_item_convert() will collapse a * group layer */ layer_type = GIMP_TYPE_LAYER; break; case GIMP_PASTE_TYPE_NEW_LAYER: layer_type = G_TYPE_FROM_INSTANCE (layer); break; default: g_return_val_if_reached (NULL); } layer = GIMP_LAYER (gimp_item_convert (GIMP_ITEM (layer), image, layer_type)); switch (paste_type) { case GIMP_PASTE_TYPE_FLOATING: case GIMP_PASTE_TYPE_FLOATING_INTO: /* when pasting as floating selection, get rid of the layer mask, * and make sure the layer has the right format */ if (gimp_layer_get_mask (layer)) gimp_layer_apply_mask (layer, GIMP_MASK_DISCARD, FALSE); if (gimp_drawable_get_format (GIMP_DRAWABLE (layer)) != floating_format) { gimp_drawable_convert_type (GIMP_DRAWABLE (layer), image, gimp_drawable_get_base_type (drawable), gimp_drawable_get_precision (drawable), TRUE, NULL, GEGL_DITHER_NONE, GEGL_DITHER_NONE, FALSE, NULL); } break; default: break; } } else if (GIMP_IS_BUFFER (paste)) { layer = gimp_layer_new_from_buffer (GIMP_BUFFER (paste), image, floating_format, _("Pasted Layer"), GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE); } if (! layer) return NULL; gimp_edit_get_paste_offset (image, drawable, GIMP_OBJECT (layer), viewport_x, viewport_y, viewport_width, viewport_height, &offset_x, &offset_y); gimp_item_set_offset (GIMP_ITEM (layer), offset_x, offset_y); gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_EDIT_PASTE, C_("undo-type", "Paste")); switch (paste_type) { case GIMP_PASTE_TYPE_FLOATING: /* if there is a selection mask clear it - this might not * always be desired, but in general, it seems like the correct * behavior */ if (! gimp_channel_is_empty (gimp_image_get_mask (image))) gimp_channel_clear (gimp_image_get_mask (image), NULL, TRUE); /* fall thru */ case GIMP_PASTE_TYPE_FLOATING_INTO: floating_sel_attach (layer, drawable); break; case GIMP_PASTE_TYPE_NEW_LAYER: { GimpLayer *parent = NULL; gint position = 0; /* always add on top of the passed layer, where we would * attach a floating selection */ if (GIMP_IS_LAYER (drawable)) { parent = gimp_layer_get_parent (GIMP_LAYER (drawable)); position = gimp_item_get_index (GIMP_ITEM (drawable)); } gimp_image_add_layer (image, layer, parent, position, TRUE); } break; } gimp_image_undo_group_end (image); return layer; }
gint dialog_I (PlugInImageVals * image_vals, PlugInDrawableVals * drawable_vals, PlugInVals * vals, PlugInUIVals * ui_vals, PlugInColVals * col_vals, PlugInDialogVals * dialog_vals) { gint32 image_ID; gint32 layer_ID; gint orig_width, orig_height; GtkWidget *main_hbox; GtkWidget *vbox; GtkWidget *vbox2; GtkWidget *vbox3; GtkWidget *hbox; GtkWidget *hbox2; GtkWidget *frame; GtkWidget *filler; GtkWidget *pres_use_image; GtkWidget *disc_use_image; GtkWidget *rigmask_use_image; //GtkWidget *noninter_button; GtkWidget *resetvalues_event_box; GtkWidget *resetvalues_button; GtkWidget *resetvalues_icon; GtkWidget *flatten_event_box; GtkWidget *flatten_button; GtkWidget *flatten_icon; GtkWidget *show_info_event_box; GtkWidget *show_info_button; GtkWidget *show_info_icon; GtkWidget *dump_event_box; GtkWidget *dump_button; GtkWidget *dump_icon; //GtkWidget *lastvalues_event_box; //GtkWidget *lastvalues_button; //GtkWidget *lastvalues_icon; gboolean has_mask = FALSE; GimpUnit unit; gdouble xres, yres; GtkWidget * v_separator; GtkWidget *info_title_label; GtkWidget * info_label; CarverData * carver_data; image_ID = image_vals->image_ID; layer_ID = drawable_vals->layer_ID; state = g_new (PlugInVals, 1); memcpy (state, vals, sizeof (PlugInVals)); ui_state = g_new (PlugInUIVals, 1); memcpy (ui_state, ui_vals, sizeof (PlugInUIVals)); dialog_state = dialog_vals; orig_width = gimp_drawable_width (layer_ID); orig_height = gimp_drawable_height (layer_ID); g_assert (gimp_drawable_is_layer (layer_ID) == TRUE); interface_I_data.orig_width = orig_width; interface_I_data.orig_height = orig_height; interface_I_data.col_vals = col_vals; interface_I_data.vmap_layer_ID = -1; reader_go = TRUE; if (gimp_layer_get_mask (layer_ID) != -1) { has_mask = TRUE; } dlg = gtk_dialog_new_with_buttons (_("GIMP LiquidRescale Plug-In"), NULL, 0, //GIMP_STOCK_RESET, RESPONSE_RESET, //GTK_STOCK_REFRESH, RESPONSE_REFRESH, GTK_STOCK_GO_BACK, RESPONSE_NONINTERACTIVE, GTK_STOCK_CLOSE, GTK_RESPONSE_OK, NULL); gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE); gtk_window_set_keep_above(GTK_WINDOW (dlg), TRUE); if (dialog_state->has_pos) { //printf("move window, x,y=%i,%i\n", dialog_state->x, dialog_state->y); fflush(stdout); gtk_window_move (GTK_WINDOW(dlg), dialog_state->x, dialog_state->y); dialog_state->has_pos = FALSE; } g_signal_connect (dlg, "response", G_CALLBACK (callback_dialog_I_response), (gpointer) (NULL)); /* dlg_tips = gtk_tooltips_new (); */ main_hbox = gtk_hbox_new (FALSE, 12); gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 12); gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area(GTK_DIALOG (dlg))), main_hbox); vbox = gtk_vbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (main_hbox), vbox, TRUE, TRUE, 0); gtk_widget_show (vbox); /* New size */ frame = gimp_frame_new (_("Set width and height")); gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0); gtk_widget_show (frame); hbox = gtk_hbox_new (FALSE, 4); gtk_container_add (GTK_CONTAINER (frame), hbox); gtk_widget_show (hbox); vbox3 = gtk_vbox_new (FALSE, 4); gtk_box_pack_start (GTK_BOX (hbox), vbox3, FALSE, FALSE, 0); gtk_widget_show (vbox3); unit = gimp_image_get_unit (image_ID); gimp_image_get_resolution (image_ID, &xres, &yres); coordinates = alt_coordinates_new (unit, "%p", TRUE, TRUE, SPIN_BUTTON_WIDTH, ALT_SIZE_ENTRY_UPDATE_SIZE, ui_state->chain_active, TRUE, _("Width:"), state->new_width, xres, 2, GIMP_MAX_IMAGE_SIZE, 0, orig_width, _("Height:"), state->new_height, yres, 2, GIMP_MAX_IMAGE_SIZE, 0, orig_height); interface_I_data.coordinates = coordinates; g_signal_connect (ALT_SIZE_ENTRY (coordinates), "value-changed", G_CALLBACK (callback_size_changed), (gpointer) & interface_I_data); g_signal_connect (ALT_SIZE_ENTRY (coordinates), "refval-changed", G_CALLBACK (callback_size_changed), (gpointer) & interface_I_data); g_signal_connect (ALT_SIZE_ENTRY (coordinates), "coordinates-alarm", G_CALLBACK (callback_alarm_triggered), (gpointer) & interface_I_data); gtk_box_pack_start (GTK_BOX (vbox3), coordinates, FALSE, FALSE, 0); gtk_widget_show (coordinates); /* Aux layer usage icons */ hbox2 = gtk_hbox_new (FALSE, 10); gtk_container_set_border_width (GTK_CONTAINER (hbox2), 4); gtk_box_pack_start (GTK_BOX (vbox3), hbox2, FALSE, FALSE, 0); gtk_widget_show (hbox2); filler = gtk_image_new (); gtk_box_pack_start (GTK_BOX (hbox2), filler, TRUE, TRUE, 0); gtk_widget_show (filler); filler = gtk_image_new (); gtk_box_pack_end (GTK_BOX (hbox2), filler, TRUE, TRUE, 0); gtk_widget_show (filler); pres_use_image = gtk_image_new_from_stock (GIMP_STOCK_CHANNEL_GREEN, GTK_ICON_SIZE_MENU); gtk_box_pack_start (GTK_BOX (hbox2), pres_use_image, FALSE, FALSE, 0); gtk_widget_show (pres_use_image); disc_use_image = gtk_image_new_from_stock (GIMP_STOCK_CHANNEL_RED, GTK_ICON_SIZE_MENU); gtk_box_pack_start (GTK_BOX (hbox2), disc_use_image, FALSE, FALSE, 0); gtk_widget_show (disc_use_image); rigmask_use_image = gtk_image_new_from_stock (GIMP_STOCK_CHANNEL_BLUE, GTK_ICON_SIZE_MENU); gtk_widget_show (rigmask_use_image); gtk_box_pack_start (GTK_BOX (hbox2), rigmask_use_image, FALSE, FALSE, 0); update_info_aux_use_icons(vals, ui_vals, pres_use_image, disc_use_image, rigmask_use_image); /* Reset size button */ vbox2 = gtk_vbox_new (FALSE, 4); gtk_box_pack_end (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0); gtk_widget_show (vbox2); resetvalues_event_box = gtk_event_box_new (); gtk_box_pack_start (GTK_BOX (vbox2), resetvalues_event_box, FALSE, FALSE, 0); gtk_widget_show (resetvalues_event_box); gimp_help_set_help_data (resetvalues_event_box, _ ("Reset width and height to their original values"), NULL); resetvalues_button = gtk_button_new (); resetvalues_icon = gtk_image_new_from_stock (GIMP_STOCK_RESET, GTK_ICON_SIZE_MENU); gtk_container_add (GTK_CONTAINER (resetvalues_button), resetvalues_icon); gtk_widget_show (resetvalues_icon); gtk_container_add (GTK_CONTAINER (resetvalues_event_box), resetvalues_button); gtk_widget_show (resetvalues_button); g_signal_connect (resetvalues_button, "clicked", G_CALLBACK (callback_resetvalues_button), (gpointer) & interface_I_data); /* Map info */ v_separator = gtk_vseparator_new(); gtk_box_pack_start (GTK_BOX (main_hbox), v_separator, TRUE, TRUE, 0); gtk_widget_show(v_separator); vbox = gtk_vbox_new (FALSE, 4); gtk_box_pack_start (GTK_BOX (main_hbox), vbox, FALSE, FALSE, 0); gtk_widget_show (vbox); hbox2 = gtk_hbox_new (FALSE, 4); gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0); gtk_widget_show (hbox2); info_title_label = gtk_label_new (""); /* Please keep the <b> and </b> tags in translations */ gtk_label_set_markup(GTK_LABEL(info_title_label), _("<b>Map</b>")); gtk_box_pack_start (GTK_BOX (hbox2), info_title_label, FALSE, FALSE, 0); gtk_widget_show (info_title_label); hbox = gtk_hbox_new (FALSE, 12); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); gtk_widget_show (hbox); vbox2 = gtk_vbox_new (FALSE, 4); gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0); gtk_widget_show (vbox2); show_info_event_box = gtk_event_box_new (); gtk_box_pack_start (GTK_BOX (vbox2), show_info_event_box, FALSE, FALSE, 0); gtk_widget_show (show_info_event_box); gimp_help_set_help_data (show_info_event_box, _ ("Show/hide internal map information"), NULL); show_info_button = gtk_toggle_button_new (); show_info_icon = gtk_image_new_from_stock (GTK_STOCK_INFO, GTK_ICON_SIZE_MENU); gtk_container_add (GTK_CONTAINER (show_info_button), show_info_icon); gtk_widget_show (show_info_icon); gtk_container_add (GTK_CONTAINER (show_info_event_box), show_info_button); gtk_widget_show (show_info_button); g_signal_connect (show_info_button, "toggled", G_CALLBACK (callback_show_info_button), (gpointer) & interface_I_data); flatten_event_box = gtk_event_box_new (); gtk_box_pack_start (GTK_BOX (vbox2), flatten_event_box, FALSE, FALSE, 0); gtk_widget_show (flatten_event_box); gimp_help_set_help_data (flatten_event_box, _ ("Reset the internal map"), NULL); flatten_button = gtk_button_new (); flatten_icon = gtk_image_new_from_stock (GIMP_STOCK_RESET, GTK_ICON_SIZE_MENU); gtk_container_add (GTK_CONTAINER (flatten_button), flatten_icon); gtk_widget_show (flatten_icon); gtk_container_add (GTK_CONTAINER (flatten_event_box), flatten_button); gtk_widget_show (flatten_button); g_signal_connect (flatten_button, "clicked", G_CALLBACK (callback_flatten_button), (gpointer) & interface_I_data); dump_event_box = gtk_event_box_new (); gtk_box_pack_start (GTK_BOX (vbox2), dump_event_box, FALSE, FALSE, 0); gtk_widget_show (dump_event_box); gimp_help_set_help_data (dump_event_box, _ ("Dump the internal map on a new layer (RGB images only)"), NULL); dump_button = gtk_button_new (); dump_icon = gtk_image_new_from_stock (GIMP_STOCK_VISIBLE, GTK_ICON_SIZE_MENU); gtk_container_add (GTK_CONTAINER (dump_button), dump_icon); gtk_widget_show (dump_icon); gtk_container_add (GTK_CONTAINER (dump_event_box), dump_button); gtk_widget_show (dump_button); g_signal_connect (dump_button, "clicked", G_CALLBACK (callback_dump_button), (gpointer) & interface_I_data); gtk_widget_set_sensitive(dump_button, FALSE); interface_I_data.dump_button = dump_button; info_label = gtk_label_new(""); //set_info_label_text (info_label, orig_width, orig_height, 0, 0, state->enl_step / 100); gtk_label_set_selectable(GTK_LABEL(info_label), TRUE); //gtk_container_add (GTK_CONTAINER (info_frame), info_label); gtk_box_pack_start (GTK_BOX (hbox), info_label, TRUE, TRUE, 0); gtk_label_set_justify(GTK_LABEL (info_label), GTK_JUSTIFY_LEFT); gtk_widget_show (info_label); //interface_I_data.info_frame = info_frame; interface_I_data.info_label = info_label; callback_show_info_button(show_info_button, (gpointer) &interface_I_data); /* noninter_button = gtk_button_new_with_mnemonic ("_Non-interactive"); g_signal_connect (GTK_BUTTON (noninter_button), "clicked", G_CALLBACK (callback_noninter_button), (gpointer) dlg); gtk_box_pack_start (GTK_BOX (vbox2), noninter_button, FALSE, FALSE, 0); gtk_widget_show (noninter_button); */ /* Initialize the carver */ AUX_LAYER_STATUS(state->pres_layer_ID, ui_state->pres_status); AUX_LAYER_STATUS(state->disc_layer_ID, ui_state->disc_status); AUX_LAYER_STATUS(state->rigmask_layer_ID, ui_state->rigmask_status); gimp_image_undo_group_start(image_ID); carver_data = render_init_carver(image_vals, drawable_vals, state, TRUE); gimp_image_undo_group_end(image_ID); if (carver_data == NULL) { return RESPONSE_FATAL; } interface_I_data.carver_data = carver_data; image_vals->image_ID = carver_data->image_ID; drawable_vals->layer_ID = carver_data->layer_ID; set_info_label_text (&interface_I_data); //set_alarm (ALARM_DELAY); size_changed = 1; /* register size reader */ g_timeout_add (READER_INTERVAL, check_size_changes, NULL); /* Show the main containers */ gtk_widget_show (main_hbox); gtk_widget_show (dlg); gtk_main (); lqr_carver_destroy (carver_data->carver); switch (dialog_I_response) { case RESPONSE_NONINTERACTIVE: switch (state->output_target) { case OUTPUT_TARGET_NEW_LAYER: case OUTPUT_TARGET_NEW_IMAGE: state->output_target = OUTPUT_TARGET_SAME_LAYER; break; case OUTPUT_TARGET_SAME_LAYER: default: break; } case GTK_RESPONSE_OK: /* Save ui values */ ui_state->chain_active = gimp_chain_button_get_active (GIMP_COORDINATES_CHAINBUTTON (coordinates)); /* save all */ memcpy (vals, state, sizeof (PlugInVals)); memcpy (ui_vals, ui_state, sizeof (PlugInUIVals)); break; default: break; } gtk_widget_destroy (dlg); reader_go = FALSE; return dialog_I_response; }
static void gimp_image_duplicate_floating_sel (GimpImage *image, GimpImage *new_image) { GimpLayer *floating_sel; GimpDrawable *floating_sel_drawable; GList *floating_sel_path; GimpItemStack *new_item_stack; GimpLayer *new_floating_sel; GimpDrawable *new_floating_sel_drawable; floating_sel = gimp_image_get_floating_selection (image); if (! floating_sel) return; floating_sel_drawable = gimp_layer_get_floating_sel_drawable (floating_sel); if (GIMP_IS_LAYER_MASK (floating_sel_drawable)) { GimpLayer *layer; layer = gimp_layer_mask_get_layer (GIMP_LAYER_MASK (floating_sel_drawable)); floating_sel_path = gimp_item_get_path (GIMP_ITEM (layer)); new_item_stack = GIMP_ITEM_STACK (gimp_image_get_layers (new_image)); } else { floating_sel_path = gimp_item_get_path (GIMP_ITEM (floating_sel_drawable)); if (GIMP_IS_LAYER (floating_sel_drawable)) new_item_stack = GIMP_ITEM_STACK (gimp_image_get_layers (new_image)); else new_item_stack = GIMP_ITEM_STACK (gimp_image_get_channels (new_image)); } /* adjust path[0] for the floating layer missing in new_image */ floating_sel_path->data = GUINT_TO_POINTER (GPOINTER_TO_UINT (floating_sel_path->data) - 1); if (GIMP_IS_LAYER (floating_sel_drawable)) { new_floating_sel = GIMP_LAYER (gimp_image_duplicate_item (GIMP_ITEM (floating_sel), new_image)); } else { /* can't use gimp_item_convert() for floating selections of channels * or layer masks because they maybe don't have a normal layer's type */ new_floating_sel = GIMP_LAYER (gimp_item_duplicate (GIMP_ITEM (floating_sel), G_TYPE_FROM_INSTANCE (floating_sel))); gimp_item_set_image (GIMP_ITEM (new_floating_sel), new_image); gimp_object_set_name (GIMP_OBJECT (new_floating_sel), gimp_object_get_name (floating_sel)); } /* Make sure the copied layer doesn't say: "<old layer> copy" */ gimp_object_set_name (GIMP_OBJECT (new_floating_sel), gimp_object_get_name (floating_sel)); new_floating_sel_drawable = GIMP_DRAWABLE (gimp_item_stack_get_item_by_path (new_item_stack, floating_sel_path)); if (GIMP_IS_LAYER_MASK (floating_sel_drawable)) new_floating_sel_drawable = GIMP_DRAWABLE (gimp_layer_get_mask (GIMP_LAYER (new_floating_sel_drawable))); floating_sel_attach (new_floating_sel, new_floating_sel_drawable); g_list_free (floating_sel_path); }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { static GimpParam values[1]; GimpPDBStatusType status = GIMP_PDB_SUCCESS; GimpRunMode run_mode; /* Plug-in variables */ gboolean single_image; gboolean defaults_proc; /* Plug-In variables */ cairo_surface_t *pdf_file; cairo_t *cr; GimpExportCapabilities capabilities; guint32 i = 0; gint32 j = 0; gdouble x_res, y_res; gdouble x_scale, y_scale; gint32 image_id; gboolean exported; GimpImageBaseType type; gint32 temp; gint *layers; gint32 num_of_layers; GimpDrawable *layer; cairo_surface_t *layer_image; gdouble opacity; gint x, y; GimpRGB layer_color; gboolean single_color; gint32 mask_id = -1; GimpDrawable *mask = NULL; cairo_surface_t *mask_image = NULL; FILE *fp; INIT_I18N (); /* Setting mandatory output values */ *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; /* Initializing all the settings */ multi_page.image_count = 0; if (! init_vals (name, nparams, param, &single_image, &defaults_proc, &run_mode)) { values[0].data.d_status = GIMP_PDB_CALLING_ERROR; return; } /* Starting the executions */ if (run_mode == GIMP_RUN_INTERACTIVE) { if (single_image) { if (! gui_single ()) { values[0].data.d_status = GIMP_PDB_CANCEL; return; } } else if (! gui_multi ()) { values[0].data.d_status = GIMP_PDB_CANCEL; return; } if (file_name == NULL) { values[0].data.d_status = GIMP_PDB_CALLING_ERROR; gimp_message (_("You must select a file to save!")); return; } } fp = g_fopen (file_name, "wb"); pdf_file = cairo_pdf_surface_create_for_stream (write_func, fp, 1, 1); if (cairo_surface_status (pdf_file) != CAIRO_STATUS_SUCCESS) { char *str = g_strdup_printf (_("An error occured while creating the PDF file:\n" "%s\n" "Make sure you entered a valid filename and that the selected location isn't read only!"), cairo_status_to_string (cairo_surface_status (pdf_file))); gimp_message (str); g_free (str); values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; return; } cr = cairo_create (pdf_file); capabilities = GIMP_EXPORT_CAN_HANDLE_RGB | GIMP_EXPORT_CAN_HANDLE_ALPHA | GIMP_EXPORT_CAN_HANDLE_GRAY | GIMP_EXPORT_CAN_HANDLE_LAYERS | GIMP_EXPORT_CAN_HANDLE_INDEXED; if (optimize.apply_masks) capabilities |= GIMP_EXPORT_CAN_HANDLE_LAYER_MASKS; for (i = 0; i < multi_page.image_count; i++) { /* Save the state of the surface before any changes, so that settings * from one page won't affect all the others */ cairo_save (cr); image_id = multi_page.images[i]; /* We need the active layer in order to use gimp_image_export */ temp = gimp_image_get_active_drawable (image_id); if (temp == -1) exported = gimp_export_image (&image_id, &temp, NULL, capabilities) == GIMP_EXPORT_EXPORT; else exported = FALSE; type = gimp_image_base_type (image_id); gimp_image_get_resolution (image_id, &x_res, &y_res); x_scale = 72.0 / x_res; y_scale = 72.0 / y_res; cairo_pdf_surface_set_size (pdf_file, gimp_image_width (image_id) * x_scale, gimp_image_height (image_id) * y_scale); /* This way we set how many pixels are there in every inch. * It's very important for PangoCairo */ cairo_surface_set_fallback_resolution (pdf_file, x_res, y_res); /* PDF is usually 72 points per inch. If we have a different resolution, * we will need this to fit our drawings */ cairo_scale (cr, x_scale, y_scale); /* Now, we should loop over the layers of each image */ layers = gimp_image_get_layers (image_id, &num_of_layers); for (j = 0; j < num_of_layers; j++) { layer = gimp_drawable_get (layers [num_of_layers-j-1]); opacity = gimp_layer_get_opacity (layer->drawable_id)/100.0; /* Gimp doesn't display indexed layers with opacity below 50% * And if it's above 50%, it will be rounded to 100% */ if (type == GIMP_INDEXED) { if (opacity <= 0.5) opacity = 0.0; else opacity = 1.0; } if (gimp_item_get_visible (layer->drawable_id) && (! optimize.ignore_hidden || (optimize.ignore_hidden && opacity > 0.0))) { mask_id = gimp_layer_get_mask (layer->drawable_id); if (mask_id != -1) { mask = gimp_drawable_get (mask_id); mask_image = get_drawable_image (mask); } gimp_drawable_offsets (layer->drawable_id, &x, &y); /* For raster layers */ if (!gimp_item_is_text_layer (layer->drawable_id)) { layer_color = get_layer_color (layer, &single_color); cairo_rectangle (cr, x, y, layer->width, layer->height); if (optimize.vectorize && single_color) { cairo_set_source_rgba (cr, layer_color.r, layer_color.g, layer_color.b, layer_color.a * opacity); if (mask_id != -1) cairo_mask_surface (cr, mask_image, x, y); else cairo_fill (cr); } else { cairo_clip (cr); layer_image = get_drawable_image (layer); cairo_set_source_surface (cr, layer_image, x, y); cairo_push_group (cr); cairo_paint_with_alpha (cr, opacity); cairo_pop_group_to_source (cr); if (mask_id != -1) cairo_mask_surface (cr, mask_image, x, y); else cairo_paint (cr); cairo_reset_clip (cr); cairo_surface_destroy (layer_image); } } /* For text layers */ else { drawText (layer, opacity, cr, x_res, y_res); } } /* We are done with the layer - time to free some resources */ gimp_drawable_detach (layer); if (mask_id != -1) { gimp_drawable_detach (mask); cairo_surface_destroy (mask_image); } } /* We are done with this image - Show it! */ cairo_show_page (cr); cairo_restore (cr); if (exported) gimp_image_delete (image_id); } /* We are done with all the images - time to free the resources */ cairo_surface_destroy (pdf_file); cairo_destroy (cr); fclose (fp); /* Finally done, let's save the parameters */ gimp_set_data (DATA_OPTIMIZE, &optimize, sizeof (optimize)); if (!single_image) { g_strlcpy (multi_page.file_name, file_name, MAX_FILE_NAME_LENGTH); gimp_set_data (DATA_IMAGE_LIST, &multi_page, sizeof (multi_page)); } }
void layers_actions_update (GimpActionGroup *group, gpointer data) { GimpImage *image = action_data_get_image (data); GimpLayer *layer = NULL; GimpLayerMask *mask = NULL; /* layer mask */ gboolean fs = FALSE; /* floating sel */ gboolean ac = FALSE; /* active channel */ gboolean sel = FALSE; gboolean alpha = FALSE; /* alpha channel present */ gboolean indexed = FALSE; /* is indexed */ gboolean lock_alpha = FALSE; gboolean text_layer = FALSE; GList *next = NULL; GList *prev = NULL; if (image) { fs = (gimp_image_floating_sel (image) != NULL); ac = (gimp_image_get_active_channel (image) != NULL); sel = ! gimp_channel_is_empty (gimp_image_get_mask (image)); indexed = (gimp_image_base_type (image) == GIMP_INDEXED); layer = gimp_image_get_active_layer (image); if (layer) { GList *list; mask = gimp_layer_get_mask (layer); lock_alpha = gimp_layer_get_lock_alpha (layer); alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)); list = g_list_find (GIMP_LIST (image->layers)->list, layer); if (list) { prev = g_list_previous (list); next = g_list_next (list); } if (layer) text_layer = gimp_drawable_is_text_layer (GIMP_DRAWABLE (layer)); } } #define SET_VISIBLE(action,condition) \ gimp_action_group_set_action_visible (group, action, (condition) != 0) #define SET_SENSITIVE(action,condition) \ gimp_action_group_set_action_sensitive (group, action, (condition) != 0) #define SET_ACTIVE(action,condition) \ gimp_action_group_set_action_active (group, action, (condition) != 0) SET_VISIBLE ("layers-text-tool", text_layer && !ac); SET_SENSITIVE ("layers-edit-attributes", layer && !fs && !ac); SET_SENSITIVE ("layers-new", image); SET_SENSITIVE ("layers-new-last-values", image); SET_SENSITIVE ("layers-duplicate", layer && !fs && !ac); SET_SENSITIVE ("layers-delete", layer && !ac); SET_SENSITIVE ("layers-select-top", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-select-bottom", layer && !fs && !ac && next); SET_SENSITIVE ("layers-select-previous", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-select-next", layer && !fs && !ac && next); SET_SENSITIVE ("layers-raise", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-raise-to-top", layer && !fs && !ac && prev); SET_SENSITIVE ("layers-lower", layer && !fs && !ac && next); SET_SENSITIVE ("layers-lower-to-bottom", layer && !fs && !ac && next); SET_SENSITIVE ("layers-anchor", layer && fs && !ac); SET_SENSITIVE ("layers-merge-down", layer && !fs && !ac && next); SET_SENSITIVE ("layers-merge-layers", layer && !fs && !ac); SET_SENSITIVE ("layers-flatten-image", layer && !fs && !ac); SET_VISIBLE ("layers-text-discard", text_layer && !ac); SET_VISIBLE ("layers-text-to-vectors", text_layer && !ac); SET_VISIBLE ("layers-text-along-vectors", text_layer && !ac); SET_VISIBLE ("layers-text-selection-replace", text_layer && !ac); SET_VISIBLE ("layers-text-selection-add", text_layer && !ac); SET_VISIBLE ("layers-text-selection-subtract", text_layer && !ac); SET_VISIBLE ("layers-text-selection-intersect", text_layer && !ac); SET_SENSITIVE ("layers-resize", layer && !ac); SET_SENSITIVE ("layers-resize-to-image", layer && !ac); SET_SENSITIVE ("layers-scale", layer && !ac); SET_SENSITIVE ("layers-crop", layer && sel); SET_SENSITIVE ("layers-alpha-add", layer && !fs && !alpha); SET_SENSITIVE ("layers-alpha-remove", layer && !fs && alpha); SET_SENSITIVE ("layers-lock-alpha", layer); SET_ACTIVE ("layers-lock-alpha", lock_alpha); SET_SENSITIVE ("layers-mask-add", layer && !fs && !ac && !mask); SET_SENSITIVE ("layers-mask-apply", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-delete", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-edit", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-show", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-disable", layer && !fs && !ac && mask); SET_ACTIVE ("layers-mask-edit", mask && gimp_layer_mask_get_edit (mask)); SET_ACTIVE ("layers-mask-show", mask && gimp_layer_mask_get_show (mask)); SET_ACTIVE ("layers-mask-disable", mask && !gimp_layer_mask_get_apply (mask)); SET_SENSITIVE ("layers-mask-selection-replace", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-selection-add", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-selection-subtract", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-mask-selection-intersect", layer && !fs && !ac && mask); SET_SENSITIVE ("layers-alpha-selection-replace", layer && !fs && !ac); SET_SENSITIVE ("layers-alpha-selection-add", layer && !fs && !ac); SET_SENSITIVE ("layers-alpha-selection-subtract", layer && !fs && !ac); SET_SENSITIVE ("layers-alpha-selection-intersect", layer && !fs && !ac); #undef SET_VISIBLE #undef SET_SENSITIVE #undef SET_ACTIVE }