static gboolean
gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
{
  GimpImageEditor *image_editor = GIMP_IMAGE_EDITOR (editor);
  GList           *sample_points;
  gint             n_points     = 0;
  GList           *list;
  gint             i;

  editor->dirty_idle_id = 0;

  if (! image_editor->image)
    return FALSE;

  sample_points = gimp_image_get_sample_points (image_editor->image);

  n_points = MIN (4, g_list_length (sample_points));

  for (i = 0, list = sample_points;
       i < n_points;
       i++, list = g_list_next (list))
    {
      if (editor->dirty[i])
        {
          GimpSamplePoint *sample_point = list->data;
          GimpColorFrame  *color_frame;
          const Babl      *format;
          guchar           pixel[32];
          GimpRGB          color;
          gint             x;
          gint             y;

          editor->dirty[i] = FALSE;

          color_frame = GIMP_COLOR_FRAME (editor->color_frames[i]);

          gimp_sample_point_get_position (sample_point, &x, &y);

          if (gimp_image_pick_color (image_editor->image, NULL,
                                     x, y,
                                     editor->sample_merged,
                                     FALSE, 0.0,
                                     &format,
                                     pixel,
                                     &color))
            {
              gimp_color_frame_set_color (color_frame, FALSE,
                                          format, pixel, &color);
            }
          else
            {
              gimp_color_frame_set_invalid (color_frame);
            }
        }
    }

  return FALSE;
}
示例#2
0
static gboolean
gimp_color_tool_real_pick (GimpColorTool *color_tool,
                           gint           x,
                           gint           y,
                           GimpImageType *sample_type,
                           GimpRGB       *color,
                           gint          *color_index)
{
  GimpTool *tool = GIMP_TOOL (color_tool);

  g_return_val_if_fail (tool->display != NULL, FALSE);
  g_return_val_if_fail (tool->drawable != NULL, FALSE);

  return gimp_image_pick_color (tool->display->image, tool->drawable, x, y,
                                color_tool->options->sample_merged,
                                color_tool->options->sample_average,
                                color_tool->options->average_radius,
                                sample_type,
                                color,
                                color_index);
}
示例#3
0
static gboolean
gimp_color_tool_real_pick (GimpColorTool  *color_tool,
                           gint            x,
                           gint            y,
                           const Babl    **sample_format,
                           GimpRGB        *color,
                           gint           *color_index)
{
  GimpTool  *tool  = GIMP_TOOL (color_tool);
  GimpImage *image = gimp_display_get_image (tool->display);

  g_return_val_if_fail (tool->display != NULL, FALSE);
  g_return_val_if_fail (tool->drawable != NULL, FALSE);

  return gimp_image_pick_color (image, tool->drawable, x, y,
                                color_tool->options->sample_merged,
                                color_tool->options->sample_average,
                                color_tool->options->average_radius,
                                sample_format,
                                color,
                                color_index);
}
示例#4
0
static gboolean
gimp_selection_view_button_press (GtkWidget           *widget,
                                  GdkEventButton      *bevent,
                                  GimpSelectionEditor *editor)
{
  GimpImageEditor      *image_editor = GIMP_IMAGE_EDITOR (editor);
  GimpViewRenderer     *renderer;
  GimpToolInfo         *tool_info;
  GimpSelectionOptions *options;
  GimpDrawable         *drawable;
  GimpChannelOps        operation = GIMP_CHANNEL_OP_REPLACE;
  gint                  x, y;
  GimpRGB               color;

  if (! image_editor->image)
    return TRUE;

  renderer = GIMP_VIEW (editor->view)->renderer;

  tool_info = gimp_get_tool_info (image_editor->image->gimp,
                                  "gimp-by-color-select-tool");

  if (! tool_info)
    return TRUE;

  options = GIMP_SELECTION_OPTIONS (tool_info->tool_options);

  drawable = gimp_image_get_active_drawable (image_editor->image);

  if (! drawable)
    return TRUE;

  if (bevent->state & GDK_SHIFT_MASK)
    {
      if (bevent->state & GDK_CONTROL_MASK)
        {
          operation = GIMP_CHANNEL_OP_INTERSECT;
        }
      else
        {
          operation = GIMP_CHANNEL_OP_ADD;
        }
    }
  else if (bevent->state & GDK_CONTROL_MASK)
    {
      operation = GIMP_CHANNEL_OP_SUBTRACT;
    }

  x = image_editor->image->width  * bevent->x / renderer->width;
  y = image_editor->image->height * bevent->y / renderer->height;

  if (gimp_image_pick_color (image_editor->image, drawable, x, y,
                             options->sample_merged,
                             FALSE, 0.0,
                             NULL,
                             &color, NULL))
    {
      gimp_channel_select_by_color (gimp_image_get_mask (image_editor->image),
                                    drawable,
                                    options->sample_merged,
                                    &color,
                                    options->threshold,
                                    options->select_transparent,
                                    options->select_criterion,
                                    operation,
                                    options->antialias,
                                    options->feather,
                                    options->feather_radius,
                                    options->feather_radius);
      gimp_image_flush (image_editor->image);
    }

  return TRUE;
}
示例#5
0
static gboolean
gimp_selection_view_button_press (GtkWidget           *widget,
                                  GdkEventButton      *bevent,
                                  GimpSelectionEditor *editor)
{
  GimpImageEditor         *image_editor = GIMP_IMAGE_EDITOR (editor);
  GimpViewRenderer        *renderer;
  GimpToolInfo            *tool_info;
  GimpSelectionOptions    *sel_options;
  GimpRegionSelectOptions *options;
  GimpDrawable            *drawable;
  GimpChannelOps           operation;
  gint                     x, y;
  GimpRGB                  color;

  if (! image_editor->image)
    return TRUE;

  renderer = GIMP_VIEW (editor->view)->renderer;

  tool_info = gimp_get_tool_info (image_editor->image->gimp,
                                  "gimp-by-color-select-tool");

  if (! tool_info)
    return TRUE;

  sel_options = GIMP_SELECTION_OPTIONS (tool_info->tool_options);
  options     = GIMP_REGION_SELECT_OPTIONS (tool_info->tool_options);

  drawable = gimp_image_get_active_drawable (image_editor->image);

  if (! drawable)
    return TRUE;

  operation = gimp_modifiers_to_channel_op (bevent->state);

  x = gimp_image_get_width  (image_editor->image) * bevent->x / renderer->width;
  y = gimp_image_get_height (image_editor->image) * bevent->y / renderer->height;

  if (gimp_image_pick_color (image_editor->image, drawable, x, y,
                             options->sample_merged,
                             FALSE, 0.0,
                             NULL,
                             &color, NULL))
    {
      gimp_channel_select_by_color (gimp_image_get_mask (image_editor->image),
                                    drawable,
                                    options->sample_merged,
                                    &color,
                                    options->threshold,
                                    options->select_transparent,
                                    options->select_criterion,
                                    operation,
                                    sel_options->antialias,
                                    sel_options->feather,
                                    sel_options->feather_radius,
                                    sel_options->feather_radius);
      gimp_image_flush (image_editor->image);
    }

  return TRUE;
}
示例#6
0
void
gimp_cursor_view_update_cursor (GimpCursorView   *view,
                                GimpImage        *image,
                                GimpUnit          unit,
                                gdouble           x,
                                gdouble           y)
{
  gboolean      in_image;
  gdouble       unit_factor;
  gint          unit_digits;
  const gchar  *unit_str;
  gchar         format_buf[32];
  gchar         buf[32];
  GimpImageType sample_type;
  GimpRGB       color;
  gint          color_index;

  g_return_if_fail (GIMP_IS_CURSOR_VIEW (view));
  g_return_if_fail (GIMP_IS_IMAGE (image));

  if (unit == GIMP_UNIT_PIXEL)
    unit = gimp_image_get_unit (image);

  in_image = (x >= 0.0 && x < gimp_image_get_width  (image) &&
              y >= 0.0 && y < gimp_image_get_height (image));

  unit_factor = _gimp_unit_get_factor (image->gimp, unit);
  unit_digits = _gimp_unit_get_digits (image->gimp, unit);
  unit_str    = _gimp_unit_get_abbreviation (image->gimp, unit);

#define FORMAT_STRING(s) (in_image ? (s) : "("s")")

  g_snprintf (buf, sizeof (buf), FORMAT_STRING ("%d"), (gint) floor (x));
  gtk_label_set_text (GTK_LABEL (view->pixel_x_label), buf);

  g_snprintf (buf, sizeof (buf), FORMAT_STRING ("%d"), (gint) floor (y));
  gtk_label_set_text (GTK_LABEL (view->pixel_y_label), buf);

  g_snprintf (format_buf, sizeof (format_buf),
              FORMAT_STRING ("%%.%df %s"), unit_digits, unit_str);

  g_snprintf (buf, sizeof (buf), format_buf,
              x * unit_factor / image->xresolution);
  gtk_label_set_text (GTK_LABEL (view->unit_x_label), buf);

  g_snprintf (buf, sizeof (buf), format_buf,
              y * unit_factor / image->yresolution);
  gtk_label_set_text (GTK_LABEL (view->unit_y_label), buf);

  if (gimp_image_pick_color (image, NULL,
                             (gint) floor (x),
                             (gint) floor (y),
                             view->sample_merged,
                             FALSE, 0.0,
                             &sample_type, &color, &color_index))
    {
      gimp_color_frame_set_color (GIMP_COLOR_FRAME (view->color_frame_1),
                                  sample_type, &color, color_index);
      gimp_color_frame_set_color (GIMP_COLOR_FRAME (view->color_frame_2),
                                  sample_type, &color, color_index);
    }
  else
    {
      gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (view->color_frame_1));
      gimp_color_frame_set_invalid (GIMP_COLOR_FRAME (view->color_frame_2));
    }
}