Exemplo n.º 1
0
static void
gimp_foreground_select_tool_cursor_update (GimpTool         *tool,
                                           const GimpCoords *coords,
                                           GdkModifierType   state,
                                           GimpDisplay      *display)
{
  GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);

  if (fg_select->mask)
    {
      GimpForegroundSelectOptions *options;

      options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (tool);

      gimp_tool_control_set_toggled (tool->control, options->background);

      switch (GIMP_SELECTION_TOOL (tool)->function)
        {
        case SELECTION_MOVE_MASK:
        case SELECTION_MOVE:
        case SELECTION_MOVE_COPY:
        case SELECTION_ANCHOR:
          return;
        default:
          break;
        }
    }

  GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
}
Exemplo n.º 2
0
static void
gimp_foreground_select_tool_button_release (GimpTool              *tool,
                                            const GimpCoords      *coords,
                                            guint32                time,
                                            GdkModifierType        state,
                                            GimpButtonReleaseType  release_type,
                                            GimpDisplay           *display)
{
  GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);

  if (fg_select->mask)
    {
      GimpForegroundSelectOptions *options;

      options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (tool);

      gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));

      gimp_tool_control_halt (tool->control);

      gimp_foreground_select_tool_push_stroke (fg_select, display, options);

      gimp_free_select_tool_select (GIMP_FREE_SELECT_TOOL (tool), display);

      gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
    }
  else
    {
      GIMP_TOOL_CLASS (parent_class)->button_release (tool,
                                                      coords, time, state,
                                                      release_type,
                                                      display);
    }
}
static void
gimp_foreground_select_tool_set_preview (GimpForegroundSelectTool *fg_select,
                                         GimpDisplay              *display)
{

  GimpTool                    *tool = GIMP_TOOL (fg_select);
  GimpForegroundSelectOptions *options;
  GimpRGB                      color;

  g_return_if_fail (fg_select->mask != NULL);

  options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (tool);

  gimp_foreground_select_options_get_mask_color (options, &color);
  gimp_display_shell_set_mask (gimp_display_get_shell (display),
                               fg_select->mask, &color);

  gimp_tool_control_set_tool_cursor        (tool->control,
                                            GIMP_TOOL_CURSOR_PAINTBRUSH);
  gimp_tool_control_set_toggle_tool_cursor (tool->control,
                                            GIMP_TOOL_CURSOR_PAINTBRUSH);

  gimp_tool_control_set_toggled (tool->control, FALSE);

  fg_select->state = MATTING_STATE_PREVIEW_MASK;
}
Exemplo n.º 4
0
static void
gimp_foreground_select_tool_draw (GimpDrawTool *draw_tool)
{
  GimpForegroundSelectTool    *fg_select = GIMP_FOREGROUND_SELECT_TOOL (draw_tool);
  GimpTool                    *tool      = GIMP_TOOL (draw_tool);
  GimpForegroundSelectOptions *options;

  options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (tool);

  if (fg_select->stroke)
    {
      gimp_draw_tool_add_pen (draw_tool,
                              (const GimpVector2 *) fg_select->stroke->data,
                              fg_select->stroke->len,
                              GIMP_CONTEXT (options),
                              (options->background ?
                               GIMP_ACTIVE_COLOR_BACKGROUND :
                               GIMP_ACTIVE_COLOR_FOREGROUND),
                              options->stroke_width);
    }

  if (fg_select->mask)
    {
      GimpDisplayShell   *shell = gimp_display_get_shell (draw_tool->display);
      gint                x     = fg_select->last_coords.x;
      gint                y     = fg_select->last_coords.y;
      gdouble             radius;

      radius = (options->stroke_width / shell->scale_y) / 2;

      /*  warn if the user is drawing outside of the working area  */
      if (FALSE)
        {
          gint x1, y1;
          gint x2, y2;

          gimp_foreground_select_tool_get_area (fg_select->mask,
                                                &x1, &y1, &x2, &y2);

          if (x < x1 + radius || x > x2 - radius ||
              y < y1 + radius || y > y2 - radius)
            {
              gimp_draw_tool_add_rectangle (draw_tool, FALSE,
                                            x1, y1,
                                            x2 - x1, y2 - y1);
            }
        }

      gimp_draw_tool_add_arc (draw_tool, FALSE,
                              x - radius, y - radius,
                              2 * radius, 2 * radius,
                              0.0, 2.0 * G_PI);
    }
  else
    {
      GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
    }
}
Exemplo n.º 5
0
static void
gimp_foreground_select_tool_set_mask (GimpForegroundSelectTool *fg_select,
                                      GimpDisplay              *display,
                                      GimpChannel              *mask)
{
  GimpTool                    *tool = GIMP_TOOL (fg_select);
  GimpForegroundSelectOptions *options;

  options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (tool);

  if (fg_select->mask == mask)
    return;

  if (fg_select->mask)
    {
      g_object_unref (fg_select->mask);
      fg_select->mask = NULL;
    }

  if (mask)
    {
      GimpRGB color;

      fg_select->mask = g_object_ref (mask);

      gimp_foreground_select_options_get_mask_color (options, &color);
      gimp_display_shell_set_mask (gimp_display_get_shell (display),
                                   GIMP_DRAWABLE (mask), &color);
    }
  else
    {
      gimp_display_shell_set_mask (gimp_display_get_shell (display),
                                   NULL, NULL);
    }

  if (mask)
    {
      gimp_tool_control_set_tool_cursor        (tool->control,
                                                GIMP_TOOL_CURSOR_PAINTBRUSH);
      gimp_tool_control_set_toggle_tool_cursor (tool->control,
                                                GIMP_TOOL_CURSOR_ERASER);

      gimp_tool_control_set_toggled (tool->control, options->background);
    }
  else
    {
      gimp_tool_control_set_tool_cursor        (tool->control,
                                                GIMP_TOOL_CURSOR_FREE_SELECT);
      gimp_tool_control_set_toggle_tool_cursor (tool->control,
                                                GIMP_TOOL_CURSOR_FREE_SELECT);

      gimp_tool_control_set_toggled (tool->control, FALSE);
    }
}
Exemplo n.º 6
0
static void
gimp_foreground_select_tool_modifier_key (GimpTool        *tool,
                                          GdkModifierType  key,
                                          gboolean         press,
                                          GdkModifierType  state,
                                          GimpDisplay     *display)
{
  if (key == gimp_get_toggle_behavior_mask ())
    {
      GimpForegroundSelectOptions *options;

      options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (tool);

      g_object_set (options,
                    "background", ! options->background,
                    NULL);
    }
}
static void
gimp_foreground_select_tool_button_release (GimpTool              *tool,
                                            const GimpCoords      *coords,
                                            guint32                time,
                                            GdkModifierType        state,
                                            GimpButtonReleaseType  release_type,
                                            GimpDisplay           *display)
{
  GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool);

  if ((fg_select->state == MATTING_STATE_PAINT_TRIMAP) ||
      (fg_select->state == MATTING_STATE_PREVIEW_MASK))
    {
      GimpForegroundSelectOptions *options;

      options = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (tool);

      gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));

      gimp_tool_control_halt (tool->control);

      gimp_foreground_select_tool_stroke_paint (fg_select, display, options);

      if (fg_select->state == MATTING_STATE_PREVIEW_MASK)
        gimp_foreground_select_tool_preview (fg_select, display);
      else
        gimp_foreground_select_tool_set_trimap (fg_select, display);

      gimp_free_select_tool_select (GIMP_FREE_SELECT_TOOL (tool), display);

      gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
    }
  else if (fg_select->state == MATTING_STATE_FREE_SELECT)
    {
      GIMP_TOOL_CLASS (parent_class)->button_release (tool,
                                                      coords, time, state,
                                                      release_type,
                                                      display);
    }
}
Exemplo n.º 8
0
static void
gimp_foreground_select_tool_select (GimpFreeSelectTool *free_sel,
                                    GimpDisplay        *display)
{
  GimpForegroundSelectTool    *fg_select;
  GimpForegroundSelectOptions *options;
  GimpImage                   *image = gimp_display_get_image (display);
  GimpDrawable                *drawable;
  GimpScanConvert             *scan_convert;
  GimpChannel                 *mask;
  const GimpVector2           *points;
  gint                         n_points;

  drawable  = gimp_image_get_active_drawable (image);
  fg_select = GIMP_FOREGROUND_SELECT_TOOL (free_sel);
  options   = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (free_sel);

  if (fg_select->idle_id)
    {
      g_source_remove (fg_select->idle_id);
      fg_select->idle_id = 0;
    }

  if (! drawable)
    return;

  scan_convert = gimp_scan_convert_new ();

  gimp_free_select_tool_get_points (free_sel,
                                    &points,
                                    &n_points);

  gimp_scan_convert_add_polyline (scan_convert,
                                  n_points,
                                  points,
                                  TRUE);

  mask = gimp_channel_new (image,
                           gimp_image_get_width (image),
                           gimp_image_get_height (image),
                           "foreground-extraction", NULL);

  gimp_scan_convert_render_value (scan_convert,
                                  gimp_drawable_get_tiles (GIMP_DRAWABLE (mask)),
                                  0, 0, 128);
  gimp_scan_convert_free (scan_convert);

  if (fg_select->strokes)
    {
      GList *list;

      gimp_set_busy (image->gimp);

      /*  apply foreground and background markers  */
      for (list = fg_select->strokes; list; list = list->next)
        gimp_foreground_select_tool_stroke (mask, list->data);

      if (fg_select->state)
        gimp_drawable_foreground_extract_siox (GIMP_DRAWABLE (mask),
                                               fg_select->state,
                                               fg_select->refinement,
                                               options->smoothness,
                                               options->sensitivity,
                                               ! options->contiguous,
                                               GIMP_PROGRESS (fg_select));

      fg_select->refinement = SIOX_REFINEMENT_NO_CHANGE;

      gimp_unset_busy (image->gimp);
    }
  else
    {
      gint x1, y1;
      gint x2, y2;

      g_object_set (options, "background", FALSE, NULL);

      gimp_foreground_select_tool_get_area (mask, &x1, &y1, &x2, &y2);

      if (fg_select->state)
        g_warning ("state should be NULL here");

      fg_select->state =
        gimp_drawable_foreground_extract_siox_init (drawable,
                                                    x1, y1, x2 - x1, y2 - y1);
    }

  gimp_foreground_select_tool_set_mask (fg_select, display, mask);

  g_object_unref (mask);
}
static void
gimp_foreground_select_tool_preview (GimpForegroundSelectTool *fg_select,
                                     GimpDisplay              *display)
{
  GimpTool                    *tool     = GIMP_TOOL (fg_select);
  GimpForegroundSelectOptions *options  = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (tool);
  GimpImage                   *image    = gimp_display_get_image (display);
  GimpDrawable                *drawable = gimp_image_get_active_drawable (image);
  GeglBuffer                  *trimap_buffer;
  GeglBuffer                  *drawable_buffer;
  GeglNode                    *gegl;
  GeglNode                    *matting_node;
  GeglNode                    *input_image;
  GeglNode                    *input_trimap;
  GeglNode                    *output_mask;
  GeglBuffer                  *buffer;
  GimpProgress                *progress;
  GeglProcessor               *processor;
  gdouble                     value;

  if (fg_select->mask)
    {
      g_object_unref (fg_select->mask);
      fg_select->mask = NULL;
    }

  progress = gimp_progress_start (GIMP_PROGRESS (fg_select),
                                  _("Computing alpha of unknown pixels"),
                                  FALSE);

  trimap_buffer   = fg_select->trimap;
  drawable_buffer = gimp_drawable_get_buffer (drawable);

  gegl = gegl_node_new ();

  input_trimap = gegl_node_new_child (gegl,
                                      "operation", "gegl:buffer-source",
                                      "buffer",    trimap_buffer,
                                      NULL);
  input_image = gegl_node_new_child (gegl,
                                     "operation", "gegl:buffer-source",
                                     "buffer",    drawable_buffer,
                                     NULL);
  output_mask = gegl_node_new_child (gegl,
                                     "operation", "gegl:buffer-sink",
                                     "buffer",    &buffer,
                                     "format",    NULL,
                                     NULL);

  if (options->engine == GIMP_MATTING_ENGINE_GLOBAL)
    {
      matting_node = gegl_node_new_child (gegl,
                                          "operation",  "gegl:matting-global",
                                          "iterations", options->iterations,
                                          NULL);
    }
  else
    {
      matting_node = gegl_node_new_child (gegl,
                                          "operation",     "gegl:matting-levin",
                                          "levels",        options->levels,
                                          "active_levels", options->active_levels,
                                          NULL);
    }

  gegl_node_connect_to (input_image,  "output",
                        matting_node, "input");
  gegl_node_connect_to (input_trimap, "output",
                        matting_node, "aux");
  gegl_node_connect_to (matting_node, "output",
                        output_mask,  "input");

  processor = gegl_node_new_processor (output_mask, NULL);

  while (gegl_processor_work (processor, &value))
    {
      if (progress)
        gimp_progress_set_value (progress, value);
    }

  if (progress)
    gimp_progress_end (progress);

  g_object_unref (processor);

  fg_select->mask = buffer;

  gimp_foreground_select_tool_set_preview (fg_select, display);

  g_object_unref (gegl);
}
Exemplo n.º 10
0
static void
gimp_foreground_select_tool_oper_update (GimpTool         *tool,
                                         const GimpCoords *coords,
                                         GdkModifierType   state,
                                         gboolean          proximity,
                                         GimpDisplay      *display)
{
  GimpForegroundSelectTool    *fg_select    = GIMP_FOREGROUND_SELECT_TOOL (tool);
  GimpForegroundSelectOptions *options      = GIMP_FOREGROUND_SELECT_TOOL_GET_OPTIONS (fg_select);
  const gchar                 *status_stage = NULL;
  const gchar                 *status_mode  = NULL;

  GimpDisplayShell   *shell   = gimp_display_get_shell (display);
  GimpImage          *image   = gimp_display_get_image (display);

  GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity,
                                               display);

  if (fg_select->state == MATTING_STATE_FREE_SELECT)
    {
      if (GIMP_SELECTION_TOOL (tool)->function == SELECTION_SELECT)
        status_stage = _("Roughly outline the object to extract");
    }
  else
    {
      GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);

      gimp_draw_tool_pause (draw_tool);

      fg_select->last_coords = *coords;

      gimp_draw_tool_resume (draw_tool);

      if (options->draw_mode == GIMP_MATTING_DRAW_MODE_FOREGROUND)
        status_mode = _("Selecting foreground, ");
      else if (options->draw_mode == GIMP_MATTING_DRAW_MODE_BACKGROUND)
        status_mode = _("Selecting background, ");
      else
        status_mode = _("Selecting unknown, ");

      if (fg_select->state == MATTING_STATE_PAINT_TRIMAP)
        status_stage = _("press Enter to preview.");
      else
        status_stage = _("press Escape to exit preview or Enter to apply.");
    }

  if (proximity && status_stage)
    {
      if (status_mode)
        gimp_tool_replace_status (tool, display, "%s%s", status_mode, status_stage);
      else
        gimp_tool_replace_status (tool, display, "%s", status_stage);
    }

  gimp_foreground_select_tool_update_gui (fg_select);

  gimp_tool_gui_set_shell (fg_select->gui, shell);
  gimp_tool_gui_set_viewable (fg_select->gui, GIMP_VIEWABLE (image));

  gimp_tool_gui_show (fg_select->gui);
}