static GdkSegment * gimp_region_select_tool_calculate (GimpRegionSelectTool *region_sel, GimpDisplay *display, gint *num_segs) { GimpTool *tool = GIMP_TOOL (region_sel); GimpRegionSelectOptions *options = GIMP_REGION_SELECT_TOOL_GET_OPTIONS (tool); GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (display->shell); GimpDrawable *drawable; GdkSegment *segs; BoundSeg *bsegs; PixelRegion maskPR; drawable = gimp_image_get_active_drawable (display->image); gimp_display_shell_set_override_cursor (shell, GDK_WATCH); if (region_sel->region_mask) g_object_unref (region_sel->region_mask); region_sel->region_mask = GIMP_REGION_SELECT_TOOL_GET_CLASS (region_sel)->get_mask (region_sel, display); if (! region_sel->region_mask) { gimp_display_shell_unset_override_cursor (shell); *num_segs = 0; return NULL; } /* calculate and allocate a new segment array which represents the * boundary of the contiguous region */ pixel_region_init (&maskPR, gimp_drawable_get_tiles (GIMP_DRAWABLE (region_sel->region_mask)), 0, 0, gimp_item_width (GIMP_ITEM (region_sel->region_mask)), gimp_item_height (GIMP_ITEM (region_sel->region_mask)), FALSE); bsegs = boundary_find (&maskPR, BOUNDARY_WITHIN_BOUNDS, 0, 0, gimp_item_width (GIMP_ITEM (region_sel->region_mask)), gimp_item_height (GIMP_ITEM (region_sel->region_mask)), BOUNDARY_HALF_WAY, num_segs); segs = g_new (GdkSegment, *num_segs); gimp_display_shell_transform_segments (shell, bsegs, segs, *num_segs, ! options->sample_merged); g_free (bsegs); gimp_display_shell_unset_override_cursor (shell); return segs; }
static BoundSeg * gimp_region_select_tool_calculate (GimpRegionSelectTool *region_sel, GimpDisplay *display, gint *n_segs) { GimpDisplayShell *shell = gimp_display_get_shell (display); BoundSeg *segs; PixelRegion maskPR; gimp_display_shell_set_override_cursor (shell, GDK_WATCH); if (region_sel->region_mask) g_object_unref (region_sel->region_mask); region_sel->region_mask = GIMP_REGION_SELECT_TOOL_GET_CLASS (region_sel)->get_mask (region_sel, display); if (! region_sel->region_mask) { gimp_display_shell_unset_override_cursor (shell); *n_segs = 0; return NULL; } /* calculate and allocate a new segment array which represents the * boundary of the contiguous region */ pixel_region_init (&maskPR, gimp_drawable_get_tiles (GIMP_DRAWABLE (region_sel->region_mask)), 0, 0, gimp_item_get_width (GIMP_ITEM (region_sel->region_mask)), gimp_item_get_height (GIMP_ITEM (region_sel->region_mask)), FALSE); segs = boundary_find (&maskPR, BOUNDARY_WITHIN_BOUNDS, 0, 0, gimp_item_get_width (GIMP_ITEM (region_sel->region_mask)), gimp_item_get_height (GIMP_ITEM (region_sel->region_mask)), BOUNDARY_HALF_WAY, n_segs); gimp_display_shell_unset_override_cursor (shell); return segs; }
static void gimp_region_select_tool_button_release (GimpTool *tool, GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonReleaseType release_type, GimpDisplay *display) { GimpRegionSelectTool *region_sel = GIMP_REGION_SELECT_TOOL (tool); GimpSelectionOptions *sel_options = GIMP_SELECTION_TOOL_GET_OPTIONS (tool); GimpRegionSelectOptions *options = GIMP_REGION_SELECT_TOOL_GET_OPTIONS (tool); gimp_tool_pop_status (tool, display); gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool)); gimp_tool_control_halt (tool->control); if (release_type != GIMP_BUTTON_RELEASE_CANCEL) { gint off_x, off_y; if (GIMP_SELECTION_TOOL (tool)->function == SELECTION_ANCHOR) { if (gimp_image_floating_sel (display->image)) { /* If there is a floating selection, anchor it */ floating_sel_anchor (gimp_image_floating_sel (display->image)); } else { /* Otherwise, clear the selection mask */ gimp_channel_clear (gimp_image_get_mask (display->image), NULL, TRUE); } gimp_image_flush (display->image); } else if (region_sel->region_mask) { if (options->sample_merged) { off_x = 0; off_y = 0; } else { GimpDrawable *drawable; drawable = gimp_image_get_active_drawable (display->image); gimp_item_offsets (GIMP_ITEM (drawable), &off_x, &off_y); } gimp_channel_select_channel (gimp_image_get_mask (display->image), GIMP_REGION_SELECT_TOOL_GET_CLASS (tool)->undo_desc, region_sel->region_mask, off_x, off_y, sel_options->operation, sel_options->feather, sel_options->feather_radius, sel_options->feather_radius); gimp_image_flush (display->image); } } if (region_sel->region_mask) { g_object_unref (region_sel->region_mask); region_sel->region_mask = NULL; } if (region_sel->segs) { g_free (region_sel->segs); region_sel->segs = NULL; region_sel->num_segs = 0; } /* Restore the original threshold */ g_object_set (options, "threshold", region_sel->saved_threshold, NULL); }