示例#1
0
static GList *
gimp_cursor_view_get_aux_info (GimpDocked *docked)
{
  GimpCursorView     *view = GIMP_CURSOR_VIEW (docked);
  GList              *aux_info;
  const gchar        *nick;
  GimpSessionInfoAux *aux;

  aux_info = parent_docked_iface->get_aux_info (docked);

  if (gimp_enum_get_value (GIMP_TYPE_COLOR_FRAME_MODE,
                           GIMP_COLOR_FRAME (view->color_frame_1)->frame_mode,
                           NULL, &nick, NULL, NULL))
    {
      aux = gimp_session_info_aux_new (AUX_INFO_FRAME_1_MODE, nick);
      aux_info = g_list_append (aux_info, aux);
    }

  if (gimp_enum_get_value (GIMP_TYPE_COLOR_FRAME_MODE,
                           GIMP_COLOR_FRAME (view->color_frame_2)->frame_mode,
                           NULL, &nick, NULL, NULL))
    {
      aux = gimp_session_info_aux_new (AUX_INFO_FRAME_2_MODE, nick);
      aux_info = g_list_append (aux_info, aux);
    }

  return aux_info;
}
void
context_brush_shape_cmd_callback (GtkAction *action,
                                  gint       value,
                                  gpointer   data)
{
  GimpContext *context;
  GimpBrush   *brush;
  return_if_no_context (context, data);

  brush = gimp_context_get_brush (context);

  if (GIMP_IS_BRUSH_GENERATED (brush) &&
      gimp_data_is_writable (GIMP_DATA (brush)))
    {
      GimpBrushGenerated *generated = GIMP_BRUSH_GENERATED (brush);
      GimpDisplay        *display;
      const char         *value_desc;

      gimp_brush_generated_set_shape (generated,
                                      (GimpBrushGeneratedShape) value);

      gimp_enum_get_value (GIMP_TYPE_BRUSH_GENERATED_SHAPE, value,
                           NULL, NULL, &value_desc, NULL);
      display = action_data_get_display (data);

      if (value_desc && display)
        {
          action_message (display, G_OBJECT (brush),
                          _("Brush Shape: %s"), value_desc);
        }
    }
}
示例#3
0
static void
gimp_display_shell_drop_component (GtkWidget       *widget,
                                   gint             x,
                                   gint             y,
                                   GimpImage       *image,
                                   GimpChannelType  component,
                                   gpointer         data)
{
  GimpDisplayShell *shell      = GIMP_DISPLAY_SHELL (data);
  GimpImage        *dest_image = gimp_display_get_image (shell->display);
  GimpChannel      *channel;
  GimpItem         *new_item;
  const gchar      *desc;

  GIMP_LOG (DND, NULL);

  if (shell->display->gimp->busy)
    return;

  if (! dest_image)
    {
      dest_image = gimp_image_new_from_component (image->gimp,
                                                  image, component);
      gimp_create_display (dest_image->gimp, dest_image, GIMP_UNIT_PIXEL, 1.0,
                           G_OBJECT (gtk_widget_get_screen (widget)),
                           gimp_widget_get_monitor (widget));
      g_object_unref (dest_image);

      return;
    }

  channel = gimp_channel_new_from_component (image, component, NULL, NULL);

  new_item = gimp_item_convert (GIMP_ITEM (channel),
                                dest_image, GIMP_TYPE_LAYER);
  g_object_unref (channel);

  if (new_item)
    {
      GimpLayer *new_layer = GIMP_LAYER (new_item);

      gimp_enum_get_value (GIMP_TYPE_CHANNEL_TYPE, component,
                           NULL, NULL, &desc, NULL);
      gimp_object_take_name (GIMP_OBJECT (new_layer),
                             g_strdup_printf (_("%s Channel Copy"), desc));

      gimp_image_undo_group_start (dest_image, GIMP_UNDO_GROUP_EDIT_PASTE,
                                   _("Drop New Layer"));

      gimp_display_shell_dnd_position_item (shell, image, new_item);

      gimp_image_add_layer (dest_image, new_layer,
                            GIMP_IMAGE_ACTIVE_PARENT, -1, TRUE);

      gimp_image_undo_group_end (dest_image);

      gimp_display_shell_dnd_flush (shell, dest_image);
    }
}
static const gchar *
gimp_display_shell_title_image_precision (GimpImage *image)
{
  const gchar *name = "";

  gimp_enum_get_value (GIMP_TYPE_PRECISION,
                       gimp_image_get_precision (image), NULL, NULL, &name, NULL);

  return name;
}
static const gchar *
gimp_display_shell_title_image_type (GimpImage *image)
{
  const gchar *name = "";

  gimp_enum_get_value (GIMP_TYPE_IMAGE_BASE_TYPE,
                       gimp_image_get_base_type (image), NULL, NULL, &name, NULL);

  return name;
}
示例#6
0
文件: gimpundo.c 项目: DevMaggio/gimp
const gchar *
gimp_undo_type_to_name (GimpUndoType type)
{
  const gchar *desc;

  if (gimp_enum_get_value (GIMP_TYPE_UNDO_TYPE, type, NULL, NULL, &desc, NULL))
    return desc;
  else
    return "";
}
示例#7
0
static void
gui_message_console (GimpMessageSeverity  severity,
                     const gchar         *domain,
                     const gchar         *message)
{
  const gchar *desc = "Message";

  gimp_enum_get_value (GIMP_TYPE_MESSAGE_SEVERITY, severity,
                       NULL, NULL, &desc, NULL);
  g_printerr ("%s-%s: %s\n\n", domain, desc, message);
}
示例#8
0
void
gimp_error_console_add (GimpErrorConsole    *console,
                        GimpMessageSeverity  severity,
                        const gchar         *domain,
                        const gchar         *message)
{
  const gchar *desc;
  GtkTextIter  end;
  GtkTextMark *end_mark;
  GdkPixbuf   *pixbuf;
  gchar       *str;

  g_return_if_fail (GIMP_IS_ERROR_CONSOLE (console));
  g_return_if_fail (domain != NULL);
  g_return_if_fail (message != NULL);

  gimp_enum_get_value (GIMP_TYPE_MESSAGE_SEVERITY, severity,
                       NULL, NULL, &desc, NULL);

  gtk_text_buffer_get_end_iter (console->text_buffer, &end);

  pixbuf = gtk_widget_render_icon (console->text_view,
                                   gimp_get_message_stock_id (severity),
                                   GTK_ICON_SIZE_BUTTON, NULL);
  gtk_text_buffer_insert_pixbuf (console->text_buffer, &end, pixbuf);
  g_object_unref (pixbuf);

  gtk_text_buffer_insert (console->text_buffer, &end, "  ", -1);

  str = g_strdup_printf ("%s %s", domain, desc);
  gtk_text_buffer_insert_with_tags_by_name (console->text_buffer, &end,
                                            str, -1,
                                            "title",
                                            NULL);
  g_free (str);

  gtk_text_buffer_insert (console->text_buffer, &end, "\n", -1);

  gtk_text_buffer_insert_with_tags_by_name (console->text_buffer, &end,
                                            message, -1,
                                            "message",
                                            NULL);

  gtk_text_buffer_insert (console->text_buffer, &end, "\n\n", -1);

  end_mark = gtk_text_buffer_create_mark (console->text_buffer,
                                          NULL, &end, TRUE);
  gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (console->text_view), end_mark,
                                FALSE, TRUE, 1.0, 0.0);
  gtk_text_buffer_delete_mark (console->text_buffer, end_mark);
}
示例#9
0
文件: gimp-utils.c 项目: Natella/gimp
/**
 * gimp_enum_get_value_name:
 * @enum_type: Enum type
 * @value:     Enum value
 *
 * Returns the value name for a given value of a given enum
 * type. Useful to have inline in GIMP_LOG() messages for example.
 *
 * Returns: The value name.
 **/
const gchar *
gimp_enum_get_value_name (GType enum_type,
                          gint  value)
{
  const gchar *value_name = NULL;
  
  gimp_enum_get_value (enum_type,
                       value,
                       &value_name,
                       NULL /*value_nick*/,
                       NULL /*value_desc*/,
                       NULL /*value_help*/);

  return value_name;
}
static void
convert_precision_dialog_response (GtkWidget     *widget,
                                   gint           response_id,
                                   ConvertDialog *dialog)
{
  if (response_id == GTK_RESPONSE_OK)
    {
      GimpProgress  *progress;
      GimpPrecision  precision;
      const gchar   *enum_desc;

      precision = gimp_babl_precision (dialog->component_type,
                                       dialog->linear);

      gimp_enum_get_value (GIMP_TYPE_PRECISION, precision,
                           NULL, NULL, &enum_desc, NULL);

      progress = gimp_progress_start (dialog->progress, FALSE,
                                      _("Converting image to %s"),
                                      enum_desc);

      gimp_image_convert_precision (dialog->image,
                                    precision,
                                    dialog->layer_dither_type,
                                    dialog->text_layer_dither_type,
                                    dialog->mask_dither_type,
                                    progress);

      if (progress)
        gimp_progress_end (progress);

      gimp_image_flush (dialog->image);

       /* gegl:color-reduction only does 16 bits */
      if (dialog->bits <= 16)
        {
          /* Save defaults for next time */
          saved_layer_dither_type      = dialog->layer_dither_type;
          saved_text_layer_dither_type = dialog->text_layer_dither_type;
          saved_mask_dither_type       = dialog->mask_dither_type;
        }
    }

  gtk_widget_destroy (dialog->dialog);
}
示例#11
0
void
gimp_channel_select_component (GimpChannel     *channel,
                               GimpChannelType  component,
                               GimpChannelOps   op,
                               gboolean         feather,
                               gdouble          feather_radius_x,
                               gdouble          feather_radius_y)
{
  GimpItem    *item;
  GimpChannel *add_on;
  const gchar *desc;
  gchar       *undo_desc;

  g_return_if_fail (GIMP_IS_CHANNEL (channel));
  g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (channel)));

  item = GIMP_ITEM (channel);

  add_on = gimp_channel_new_from_component (gimp_item_get_image (item),
                                            component, NULL, NULL);

  if (feather)
    gimp_channel_feather (add_on,
                          feather_radius_x,
                          feather_radius_y,
                          FALSE /* no undo */);

  gimp_enum_get_value (GIMP_TYPE_CHANNEL_TYPE, component,
                       NULL, NULL, &desc, NULL);

  undo_desc = g_strdup_printf (C_("undo-type", "%s Channel to Selection"), desc);

  gimp_channel_select_channel (channel, undo_desc, add_on,
                               0, 0, op,
                               FALSE, 0.0, 0.0);

  g_free (undo_desc);
  g_object_unref (add_on);
}
void
context_paint_mode_cmd_callback (GtkAction *action,
                                 gint       value,
                                 gpointer   data)
{
  GimpContext          *context;
  GimpToolInfo         *tool_info;
  GimpLayerModeEffects  paint_mode;
  gint                  index;
  return_if_no_context (context, data);

  paint_mode = gimp_context_get_paint_mode (context);

  index = action_select_value ((GimpActionSelectType) value,
                               context_paint_mode_index (paint_mode),
                               0, G_N_ELEMENTS (paint_modes) - 1, 0,
                               0.0, 1.0, 1.0, 0.0, FALSE);
  gimp_context_set_paint_mode (context, paint_modes[index]);

  tool_info = gimp_context_get_tool (context);

  if (tool_info && GIMP_IS_TOOL_OPTIONS (tool_info->tool_options))
    {
      GimpDisplay *display;
      const char  *value_desc;

      gimp_enum_get_value (GIMP_TYPE_LAYER_MODE_EFFECTS, index,
                           NULL, NULL, &value_desc, NULL);

      display = action_data_get_display (data);

      if (value_desc && display)
        {
          action_message (display, G_OBJECT (tool_info->tool_options),
                          _("Paint Mode: %s"), value_desc);
        }
    }
}
示例#13
0
文件: gimp-gui.c 项目: alfanak/gimp
void
gimp_show_message (Gimp                *gimp,
                   GObject             *handler,
                   GimpMessageSeverity  severity,
                   const gchar         *domain,
                   const gchar         *message)
{
  const gchar *desc = "Message";

  g_return_if_fail (GIMP_IS_GIMP (gimp));
  g_return_if_fail (handler == NULL || G_IS_OBJECT (handler));
  g_return_if_fail (message != NULL);

  if (! domain)
    domain = GIMP_ACRONYM;

  if (! gimp->console_messages)
    {
      if (gimp->gui.show_message)
        {
          gimp->gui.show_message (gimp, handler,
                                  severity, domain, message);
          return;
        }
      else if (GIMP_IS_PROGRESS (handler) &&
               gimp_progress_message (GIMP_PROGRESS (handler), gimp,
                                      severity, domain, message))
        {
          /* message has been handled by GimpProgress */
          return;
        }
    }

  gimp_enum_get_value (GIMP_TYPE_MESSAGE_SEVERITY, severity,
                       NULL, NULL, &desc, NULL);
  g_printerr ("%s-%s: %s\n\n", domain, desc, message);
}
示例#14
0
void
gimp_export_dialog_set_image (GimpExportDialog *dialog,
                              GimpImage        *image)
{
  GimpFileDialog *file_dialog;
  GFile          *dir_file  = NULL;
  GFile          *name_file = NULL;
  GFile          *ext_file  = NULL;
  gchar          *basename;

  g_return_if_fail (GIMP_IS_EXPORT_DIALOG (dialog));
  g_return_if_fail (GIMP_IS_IMAGE (image));

  file_dialog = GIMP_FILE_DIALOG (dialog);

  file_dialog->image = image;

  gimp_file_dialog_set_file_proc (file_dialog, NULL);

  /* Priority of default paths for Export:
   *
   *   1. Last Export path
   *   2. Path of import source
   *   3. Path of XCF source
   *   4. Last path of any save to XCF
   *   5. Last Export path of any document
   *   6. The default path (usually the OS 'Documents' path)
   */

  dir_file = gimp_image_get_exported_file (image);

  if (! dir_file)
    dir_file = g_object_get_data (G_OBJECT (image),
                                  "gimp-image-source-file");

  if (! dir_file)
    dir_file = gimp_image_get_imported_file (image);

  if (! dir_file)
    dir_file = gimp_image_get_file (image);

  if (! dir_file)
    dir_file = g_object_get_data (G_OBJECT (file_dialog->gimp),
                                  GIMP_FILE_SAVE_LAST_FILE_KEY);

  if (! dir_file)
    dir_file = g_object_get_data (G_OBJECT (file_dialog->gimp),
                                  GIMP_FILE_EXPORT_LAST_FILE_KEY);

  if (! dir_file)
    dir_file = gimp_file_dialog_get_default_folder (file_dialog);

  /* Priority of default basenames for Export:
   *
   *   1. Last Export name
   *   3. Save URI
   *   2. Source file name
   *   3. 'Untitled'
   */

  name_file = gimp_image_get_exported_file (image);

  if (! name_file)
    name_file = gimp_image_get_file (image);

  if (! name_file)
    name_file = gimp_image_get_imported_file (image);

  if (! name_file)
    name_file = gimp_image_get_untitled_file (image);


  /* Priority of default type/extension for Export:
   *
   *   1. Type of last Export
   *   2. Type of the image Import
   *   3. Type of latest Export of any document
   *   4. Default file type set in Preferences
   */

  ext_file = gimp_image_get_exported_file (image);

  if (! ext_file)
    ext_file = gimp_image_get_imported_file (image);

  if (! ext_file)
    ext_file = g_object_get_data (G_OBJECT (file_dialog->gimp),
                                  GIMP_FILE_EXPORT_LAST_FILE_KEY);

  if (ext_file)
    {
      g_object_ref (ext_file);
    }
  else
    {
      const gchar *extension;
      gchar       *uri;

      gimp_enum_get_value (GIMP_TYPE_EXPORT_FILE_TYPE,
                           image->gimp->config->export_file_type,
                           NULL, &extension, NULL, NULL);

      uri = g_strconcat ("file:///we/only/care/about/extension.",
                         extension, NULL);
      ext_file = g_file_new_for_uri (uri);
      g_free (uri);
    }

  if (ext_file)
    {
      GFile *tmp_file = gimp_file_with_new_extension (name_file, ext_file);
      basename = g_path_get_basename (gimp_file_get_utf8_name (tmp_file));
      g_object_unref (tmp_file);
      g_object_unref (ext_file);
    }
  else
    {
      basename = g_path_get_basename (gimp_file_get_utf8_name (name_file));
    }

  if (g_file_query_file_type (dir_file, G_FILE_QUERY_INFO_NONE, NULL) ==
      G_FILE_TYPE_DIRECTORY)
    {
      gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog),
                                                dir_file, NULL);
    }
  else
    {
      GFile *parent_file = g_file_get_parent (dir_file);
      gtk_file_chooser_set_current_folder_file (GTK_FILE_CHOOSER (dialog),
                                                parent_file, NULL);
      g_object_unref (parent_file);
    }

  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), basename);
}
示例#15
0
GtkWidget *
gimp_proc_view_new (const gchar     *name,
                    const gchar     *menu_path,
                    const gchar     *blurb,
                    const gchar     *help,
                    const gchar     *author,
                    const gchar     *copyright,
                    const gchar     *date,
                    GimpPDBProcType  type,
                    gint             n_params,
                    gint             n_return_vals,
                    GimpParamDef    *params,
                    GimpParamDef    *return_vals)
{
  GtkWidget    *main_vbox;
  GtkWidget    *frame;
  GtkWidget    *vbox;
  GtkWidget    *table;
  GtkWidget    *label;
  GtkSizeGroup *name_group;
  GtkSizeGroup *type_group;
  GtkSizeGroup *desc_group;
  const gchar  *type_str;
  gint          row;

  if (blurb     && strlen (blurb) < 2)     blurb     = NULL;
  if (help      && strlen (help) < 2)      help      = NULL;
  if (author    && strlen (author) < 2)    author    = NULL;
  if (date      && strlen (date) < 2)      date      = NULL;
  if (copyright && strlen (copyright) < 2) copyright = NULL;

  if (blurb && help && ! strcmp (blurb, help))
    help = NULL;

  main_vbox = gtk_vbox_new (FALSE, 12);

  /* show the name */

  frame = gimp_frame_new (name);
  label = gtk_frame_get_label_widget (GTK_FRAME (frame));
  gtk_label_set_selectable (GTK_LABEL (label), TRUE);
  gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);

  vbox = gtk_vbox_new (FALSE, 8);
  gtk_container_add (GTK_CONTAINER (frame), vbox);
  gtk_widget_show (vbox);

  if (! gimp_enum_get_value (GIMP_TYPE_PDB_PROC_TYPE, type,
                             NULL, NULL, &type_str, NULL))
    type_str = "UNKNOWN";

  label = gtk_label_new (type_str);
  gimp_label_set_attributes (GTK_LABEL (label),
                             PANGO_ATTR_STYLE, PANGO_STYLE_ITALIC,
                             -1);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
  gtk_widget_show (label);

  if (menu_path)
    {
      label = gtk_label_new_with_mnemonic (menu_path);
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
      gtk_widget_show (label);
    }

  if (blurb)
    {
      label = gtk_label_new (blurb);
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
      gtk_widget_show (label);
    }

  name_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
  type_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
  desc_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);

  /* in parameters */
  if (n_params)
    {
      frame = gimp_frame_new (_("Parameters"));
      gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
      gtk_widget_show (frame);

      table = gimp_proc_view_create_params (params, n_params,
                                            name_group, type_group, desc_group);
      gtk_container_add (GTK_CONTAINER (frame), table);
      gtk_widget_show (table);
    }

  /* out parameters */
  if (n_return_vals)
    {
      frame = gimp_frame_new (_("Return Values"));
      gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
      gtk_widget_show (frame);

      table = gimp_proc_view_create_params (return_vals, n_return_vals,
                                            name_group, type_group, desc_group);
      gtk_container_add (GTK_CONTAINER (frame), table);
      gtk_widget_show (table);
    }

  if (! help && ! author && ! date && ! copyright)
    return main_vbox;

  frame = gimp_frame_new (_("Additional Information"));
  gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);

  vbox = gtk_vbox_new (FALSE, 8);
  gtk_container_add (GTK_CONTAINER (frame), vbox);
  gtk_widget_show (vbox);

  /* show the help */
  if (help)
    {
      label = gtk_label_new (help);
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
      gtk_widget_show (label);
    }

  /* show the author & the copyright */

  if (! author && ! date && ! copyright)
    return main_vbox;

  table = gtk_table_new ((author != 0) + (date != 0) + (copyright != 0), 2,
                         FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
  gtk_table_set_row_spacings (GTK_TABLE (table), 4);
  gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
  gtk_widget_show (table);

  row = 0;

  if (author)
    {
      label = gtk_label_new (author);
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);

      gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
                                 _("Author:"), 0.0, 0.0,
                                 label, 3, FALSE);
    }

  if (date)
    {
      label = gtk_label_new (date);
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);

      gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
                                 _("Date:"), 0.0, 0.0,
                                 label, 3, FALSE);
    }

  if (copyright)
    {
      label = gtk_label_new (copyright);
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);

      gimp_table_attach_aligned (GTK_TABLE (table), 0, row++,
                                 _("Copyright:"), 0.0, 0.0,
                                 label, 3, FALSE);
    }

  return main_vbox;
}
示例#16
0
static void
gimp_image_prop_view_update (GimpImagePropView *view)
{
  GimpImage         *image = view->image;
  GimpImageBaseType  type;
  GimpPrecision      precision;
  GimpUnit           unit;
  gdouble            unit_factor;
  gint               unit_digits;
  const gchar       *desc;
  gchar              format_buf[32];
  gchar              buf[256];
  gdouble            xres;
  gdouble            yres;

  gimp_image_get_resolution (image, &xres, &yres);

  /*  pixel size  */
  g_snprintf (buf, sizeof (buf), ngettext ("%d × %d pixel",
                                           "%d × %d pixels",
                                           gimp_image_get_height (image)),
              gimp_image_get_width  (image),
              gimp_image_get_height (image));
  gtk_label_set_text (GTK_LABEL (view->pixel_size_label), buf);

  /*  print size  */
  unit = gimp_get_default_unit ();

  unit_digits = gimp_unit_get_digits (unit);

  g_snprintf (format_buf, sizeof (format_buf), "%%.%df × %%.%df %s",
              unit_digits + 1, unit_digits + 1,
              gimp_unit_get_plural (unit));
  g_snprintf (buf, sizeof (buf), format_buf,
              gimp_pixels_to_units (gimp_image_get_width  (image), unit, xres),
              gimp_pixels_to_units (gimp_image_get_height (image), unit, yres));
  gtk_label_set_text (GTK_LABEL (view->print_size_label), buf);

  /*  resolution  */
  unit        = gimp_image_get_unit (image);
  unit_factor = gimp_unit_get_factor (unit);

  g_snprintf (format_buf, sizeof (format_buf), _("pixels/%s"),
              gimp_unit_get_abbreviation (unit));
  g_snprintf (buf, sizeof (buf), _("%g × %g %s"),
              xres / unit_factor,
              yres / unit_factor,
              unit == GIMP_UNIT_INCH ? _("ppi") : format_buf);
  gtk_label_set_text (GTK_LABEL (view->resolution_label), buf);

  /*  color type  */
  type = gimp_image_get_base_type (image);

  gimp_enum_get_value (GIMP_TYPE_IMAGE_BASE_TYPE, type,
                       NULL, NULL, &desc, NULL);

  switch (type)
    {
    case GIMP_RGB:
    case GIMP_GRAY:
      g_snprintf (buf, sizeof (buf), "%s", desc);
      break;
    case GIMP_INDEXED:
      g_snprintf (buf, sizeof (buf),
                  "%s (%d %s)", desc, gimp_image_get_colormap_size (image),
                  _("colors"));
      break;
    }

  gtk_label_set_text (GTK_LABEL (view->colorspace_label), buf);

  /*  precision  */
  precision = gimp_image_get_precision (image);

  gimp_enum_get_value (GIMP_TYPE_PRECISION, precision,
                       NULL, NULL, &desc, NULL);

  gtk_label_set_text (GTK_LABEL (view->precision_label), desc);

  /*  size in memory  */
  gimp_image_prop_view_label_set_memsize (view->memsize_label,
                                          GIMP_OBJECT (image));

  /*  undo / redo  */
  gimp_image_prop_view_label_set_undo (view->undo_label,
                                       gimp_image_get_undo_stack (image));
  gimp_image_prop_view_label_set_undo (view->redo_label,
                                       gimp_image_get_redo_stack (image));

  /*  number of layers  */
  g_snprintf (buf, sizeof (buf), "%d",
              gimp_image_get_width  (image) *
              gimp_image_get_height (image));
  gtk_label_set_text (GTK_LABEL (view->pixels_label), buf);

  /*  number of layers  */
  g_snprintf (buf, sizeof (buf), "%d",
              gimp_image_get_n_layers (image));
  gtk_label_set_text (GTK_LABEL (view->layers_label), buf);

  /*  number of channels  */
  g_snprintf (buf, sizeof (buf), "%d",
              gimp_image_get_n_channels (image));
  gtk_label_set_text (GTK_LABEL (view->channels_label), buf);

  /*  number of vectors  */
  g_snprintf (buf, sizeof (buf), "%d",
              gimp_image_get_n_vectors (image));
  gtk_label_set_text (GTK_LABEL (view->vectors_label), buf);
}
示例#17
0
/**
 * file_open_thumbnail:
 * @gimp:
 * @context:
 * @progress:
 * @uri:          the URI of the image file
 * @size:         requested size of the thumbnail
 * @mime_type:    return location for image MIME type
 * @image_width:  return location for image width
 * @image_height: return location for image height
 * @type:         return location for image type (set to -1 if unknown)
 * @num_layers:   return location for number of layers
 *                (set to -1 if the number of layers is not known)
 * @error:
 *
 * Attempts to load a thumbnail by using a registered thumbnail loader.
 *
 * Return value: the thumbnail image
 */
GimpImage *
file_open_thumbnail (Gimp           *gimp,
                     GimpContext    *context,
                     GimpProgress   *progress,
                     const gchar    *uri,
                     gint            size,
                     const gchar   **mime_type,
                     gint           *image_width,
                     gint           *image_height,
                     GimpImageType  *type,
                     gint           *num_layers,
                     GError        **error)
{
    GimpPlugInProcedure *file_proc;
    GimpProcedure       *procedure;

    g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
    g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
    g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
    g_return_val_if_fail (mime_type != NULL, NULL);
    g_return_val_if_fail (image_width != NULL, NULL);
    g_return_val_if_fail (image_height != NULL, NULL);
    g_return_val_if_fail (type != NULL, NULL);
    g_return_val_if_fail (num_layers != NULL, NULL);
    g_return_val_if_fail (error == NULL || *error == NULL, NULL);

    *image_width  = 0;
    *image_height = 0;
    *type         = -1;
    *num_layers   = -1;

    file_proc = file_procedure_find (gimp->plug_in_manager->load_procs, uri,
                                     NULL);

    if (! file_proc || ! file_proc->thumb_loader)
        return NULL;

    procedure = gimp_pdb_lookup_procedure (gimp->pdb, file_proc->thumb_loader);

    if (procedure && procedure->num_args >= 2 && procedure->num_values >= 1)
    {
        GimpPDBStatusType  status;
        GValueArray       *return_vals;
        gchar             *filename;
        GimpImage         *image = NULL;

        filename = file_utils_filename_from_uri (uri);

        if (! filename)
            filename = g_strdup (uri);

        return_vals =
            gimp_pdb_execute_procedure_by_name (gimp->pdb,
                                                context, progress, error,
                                                gimp_object_get_name (procedure),
                                                G_TYPE_STRING,   filename,
                                                GIMP_TYPE_INT32, size,
                                                G_TYPE_NONE);

        g_free (filename);

        status = g_value_get_enum (&return_vals->values[0]);

        if (status == GIMP_PDB_SUCCESS &&
                GIMP_VALUE_HOLDS_IMAGE_ID (&return_vals->values[1]))
        {
            image = gimp_value_get_image (&return_vals->values[1], gimp);

            if (return_vals->n_values >= 3 &&
                    G_VALUE_HOLDS_INT (&return_vals->values[2]) &&
                    G_VALUE_HOLDS_INT (&return_vals->values[3]))
            {
                *image_width  = MAX (0,
                                     g_value_get_int (&return_vals->values[2]));
                *image_height = MAX (0,
                                     g_value_get_int (&return_vals->values[3]));

                if (return_vals->n_values >= 5 &&
                        G_VALUE_HOLDS_INT (&return_vals->values[4]))
                {
                    gint value = g_value_get_int (&return_vals->values[4]);

                    if (gimp_enum_get_value (GIMP_TYPE_IMAGE_TYPE, value,
                                             NULL, NULL, NULL, NULL))
                    {
                        *type = value;
                    }
                }

                if (return_vals->n_values >= 6 &&
                        G_VALUE_HOLDS_INT (&return_vals->values[5]))
                {
                    *num_layers = MAX (0,
                                       g_value_get_int (&return_vals->values[5]));
                }
            }

            if (image)
            {
                file_open_sanitize_image (image, FALSE);

                *mime_type = file_proc->mime_type;

#ifdef GIMP_UNSTABLE
                g_printerr ("opened thumbnail at %d x %d\n",
                            gimp_image_get_width  (image),
                            gimp_image_get_height (image));
#endif
            }
        }

        g_value_array_free (return_vals);

        return image;
    }

    return NULL;
}
示例#18
0
GtkWidget *
convert_precision_dialog_new (GimpImage     *image,
                              GimpContext   *context,
                              GtkWidget     *parent,
                              GimpPrecision  precision,
                              GimpProgress  *progress)
{
  ConvertDialog *dialog;
  GtkWidget     *button;
  GtkWidget     *main_vbox;
  GtkWidget     *vbox;
  GtkWidget     *hbox;
  GtkWidget     *label;
  GtkWidget     *frame;
  GtkWidget     *combo;
  GtkSizeGroup  *size_group;
  const gchar   *enum_desc;
  gchar         *blurb;
  GType          dither_type;
  const Babl    *format;
  gint           bits;

  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
  g_return_val_if_fail (GTK_IS_WIDGET (parent), NULL);
  g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);

  dialog = g_slice_new0 (ConvertDialog);

  /* a random format with precision */
  format = gimp_babl_format (GIMP_RGB, precision, FALSE);
  bits   = (babl_format_get_bytes_per_pixel (format) * 8 /
            babl_format_get_n_components (format));

  dialog->image     = image;
  dialog->progress  = progress;
  dialog->precision = precision;
  dialog->bits      = bits;

  /* gegl:color-reduction only does 16 bits */
  if (bits <= 16)
    {
      dialog->layer_dither_type      = saved_layer_dither_type;
      dialog->text_layer_dither_type = saved_text_layer_dither_type;
      dialog->mask_dither_type       = saved_mask_dither_type;
    }

  gimp_enum_get_value (GIMP_TYPE_PRECISION, precision,
                       NULL, NULL, &enum_desc, NULL);

  blurb = g_strdup_printf (_("Convert Image to %s"), enum_desc);

  dialog->dialog =
    gimp_viewable_dialog_new (GIMP_VIEWABLE (image), context,
                              _("Precision Conversion"),
                              "gimp-image-convert-precision",
                              GIMP_STOCK_CONVERT_PRECISION,
                              blurb,
                              parent,
                              gimp_standard_help_func,
                              GIMP_HELP_IMAGE_CONVERT_PRECISION,

                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,

                              NULL);

  g_free (blurb);

  button = gtk_dialog_add_button (GTK_DIALOG (dialog->dialog),
                                  _("C_onvert"), GTK_RESPONSE_OK);
  gtk_button_set_image (GTK_BUTTON (button),
                        gtk_image_new_from_icon_name (GIMP_STOCK_CONVERT_PRECISION,
                                                      GTK_ICON_SIZE_BUTTON));

  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog->dialog),
                                           GTK_RESPONSE_OK,
                                           GTK_RESPONSE_CANCEL,
                                           -1);

  gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);

  g_object_weak_ref (G_OBJECT (dialog->dialog),
                     (GWeakNotify) convert_precision_dialog_free, dialog);

  g_signal_connect (dialog->dialog, "response",
                    G_CALLBACK (convert_precision_dialog_response),
                    dialog);

  main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))),
                      main_vbox, TRUE, TRUE, 0);
  gtk_widget_show (main_vbox);


  /*  dithering  */

  dither_type = gimp_gegl_get_op_enum_type ("gegl:color-reduction",
                                            "dither-strategy");

  frame = gimp_frame_new (_("Dithering"));
  gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  gtk_container_add (GTK_CONTAINER (frame), vbox);
  gtk_widget_show (vbox);

  /* gegl:color-reduction only does 16 bits */
  gtk_widget_set_sensitive (vbox, bits <= 16);

  size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);

  /*  layers  */

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  label = gtk_label_new_with_mnemonic (_("_Layers:"));
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  gtk_size_group_add_widget (size_group, label);
  gtk_widget_show (label);

  combo = gimp_enum_combo_box_new (dither_type);
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
  gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
  gtk_widget_show (combo);

  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
                              dialog->layer_dither_type,
                              G_CALLBACK (gimp_int_combo_box_get_active),
                              &dialog->layer_dither_type);

  /*  text layers  */

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  label = gtk_label_new_with_mnemonic (_("_Text Layers:"));
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  gtk_size_group_add_widget (size_group, label);
  gtk_widget_show (label);

  combo = gimp_enum_combo_box_new (dither_type);
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
  gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
  gtk_widget_show (combo);

  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
                              dialog->text_layer_dither_type,
                              G_CALLBACK (gimp_int_combo_box_get_active),
                              &dialog->text_layer_dither_type);

  gimp_help_set_help_data (combo,
                           _("Dithering text layers will make them uneditable"),
                           NULL);

  /*  channels  */

  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  label = gtk_label_new_with_mnemonic (_("_Channels and Masks:"));
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  gtk_size_group_add_widget (size_group, label);
  gtk_widget_show (label);

  combo = gimp_enum_combo_box_new (dither_type);
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
  gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
  gtk_widget_show (combo);

  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
                              dialog->mask_dither_type,
                              G_CALLBACK (gimp_int_combo_box_get_active),
                              &dialog->mask_dither_type);

  g_object_unref (size_group);

  return dialog->dialog;
}
示例#19
0
static GtkWidget *
gimp_proc_view_create_params (GimpParamDef *params,
                              gint          n_params,
                              GtkSizeGroup *name_group,
                              GtkSizeGroup *type_group,
                              GtkSizeGroup *desc_group)
{
  GtkWidget *table;
  gint       i;

  table = gtk_table_new (n_params, 3, FALSE);
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
  gtk_table_set_row_spacings (GTK_TABLE (table), 4);

  for (i = 0; i < n_params; i++)
    {
      GtkWidget   *label;
      const gchar *type;
      gchar       *upper;

      /* name */
      label = gtk_label_new (params[i].name);
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_size_group_add_widget (name_group, label);
      gtk_table_attach (GTK_TABLE (table), label,
                        0, 1, i, i + 1, GTK_FILL, GTK_FILL, 0, 0);
      gtk_widget_show (label);

      /* type */
      if (! gimp_enum_get_value (GIMP_TYPE_PDB_ARG_TYPE, params[i].type,
                                 NULL, &type, NULL, NULL))
        upper = g_strdup ("UNKNOWN");
      else
        upper = g_ascii_strup (type, -1);

      label = gtk_label_new (upper);
      g_free (upper);

      gimp_label_set_attributes (GTK_LABEL (label),
                                 PANGO_ATTR_FAMILY, "monospace",
                                 PANGO_ATTR_STYLE,  PANGO_STYLE_ITALIC,
                                 -1);
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_size_group_add_widget (type_group, label);
      gtk_table_attach (GTK_TABLE (table), label,
                        1, 2, i, i + 1, GTK_FILL, GTK_FILL, 0, 0);
      gtk_widget_show (label);

      /* description */
      label = gtk_label_new (params[i].description);
      gtk_label_set_selectable (GTK_LABEL (label), TRUE);
      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
      gtk_size_group_add_widget (desc_group, label);
      gtk_table_attach (GTK_TABLE (table), label,
                        2, 3, i, i + 1, GTK_SHRINK | GTK_FILL, GTK_FILL, 0, 0);
      gtk_widget_show (label);
    }

  return table;
}