[gimp/wip/Jehan/classy-GIMP: 29/58] plug-ins: port file-ico to the new GimpImage/GimpDrawable objects.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/Jehan/classy-GIMP: 29/58] plug-ins: port file-ico to the new GimpImage/GimpDrawable objects.
- Date: Tue, 20 Aug 2019 08:46:05 +0000 (UTC)
commit 5f588d15dff83bec87e8cad651ef2b0254bde088
Author: Jehan <jehan girinstud io>
Date: Wed Aug 14 15:11:25 2019 +0200
plug-ins: port file-ico to the new GimpImage/GimpDrawable objects.
plug-ins/file-ico/Makefile.am | 1 -
plug-ins/file-ico/ico-dialog.c | 87 +++++++++++++++---------------
plug-ins/file-ico/ico-dialog.h | 8 +--
plug-ins/file-ico/ico-load.c | 42 +++++++--------
plug-ins/file-ico/ico-load.h | 30 +++++------
plug-ins/file-ico/ico-save.c | 118 ++++++++++++++++++++++-------------------
plug-ins/file-ico/ico-save.h | 2 +-
plug-ins/file-ico/ico.c | 28 +++++-----
plug-ins/file-ico/ico.h | 2 +-
9 files changed, 163 insertions(+), 155 deletions(-)
---
diff --git a/plug-ins/file-ico/Makefile.am b/plug-ins/file-ico/Makefile.am
index 44bf64dbf0..0bc5bbfd2d 100644
--- a/plug-ins/file-ico/Makefile.am
+++ b/plug-ins/file-ico/Makefile.am
@@ -36,7 +36,6 @@ file_ico_SOURCES = \
ico-save.h
AM_CPPFLAGS = \
- -DGIMP_DEPRECATED_REPLACE_NEW_API \
-I$(top_srcdir) \
$(GTK_CFLAGS) \
$(GEGL_CFLAGS) \
diff --git a/plug-ins/file-ico/ico-dialog.c b/plug-ins/file-ico/ico-dialog.c
index b6938663bb..f1bca792c6 100644
--- a/plug-ins/file-ico/ico-dialog.c
+++ b/plug-ins/file-ico/ico-dialog.c
@@ -107,7 +107,7 @@ ico_dialog_new (IcoSaveInfo *info)
}
static GtkWidget *
-ico_preview_new (gint32 layer)
+ico_preview_new (GimpDrawable *layer)
{
GtkWidget *image;
GdkPixbuf *pixbuf;
@@ -126,10 +126,10 @@ ico_preview_new (gint32 layer)
/* This function creates and returns an hbox for an icon,
which then gets added to the dialog's main vbox. */
static GtkWidget *
-ico_create_icon_hbox (GtkWidget *icon_preview,
- gint32 layer,
- gint layer_num,
- IcoSaveInfo *info)
+ico_create_icon_hbox (GtkWidget *icon_preview,
+ GimpDrawable *layer,
+ gint layer_num,
+ IcoSaveInfo *info)
{
static GtkSizeGroup *size = NULL;
@@ -144,7 +144,7 @@ ico_create_icon_hbox (GtkWidget *icon_preview,
layer's ID and stacking number with the hbox. */
g_object_set_data (G_OBJECT (hbox),
- "icon_layer", GINT_TO_POINTER (layer));
+ "icon_layer", layer);
g_object_set_data (G_OBJECT (hbox),
"icon_layer_num", GINT_TO_POINTER (layer_num));
@@ -193,14 +193,15 @@ ico_create_icon_hbox (GtkWidget *icon_preview,
}
static GtkWidget *
-ico_dialog_get_layer_preview (GtkWidget *dialog,
- gint32 layer)
+ico_dialog_get_layer_preview (GtkWidget *dialog,
+ GimpDrawable *layer)
{
GtkWidget *preview;
GtkWidget *icon_hbox;
gchar key[ICO_MAXBUF];
- g_snprintf (key, sizeof (key), "layer_%i_hbox", layer);
+ g_snprintf (key, sizeof (key), "layer_%i_hbox",
+ gimp_item_get_id (GIMP_ITEM (layer)));
icon_hbox = g_object_get_data (G_OBJECT (dialog), key);
if (!icon_hbox)
@@ -221,9 +222,9 @@ ico_dialog_get_layer_preview (GtkWidget *dialog,
}
static void
-ico_dialog_update_icon_preview (GtkWidget *dialog,
- gint32 layer,
- gint bpp)
+ico_dialog_update_icon_preview (GtkWidget *dialog,
+ GimpDrawable *layer,
+ gint bpp)
{
GtkWidget *preview = ico_dialog_get_layer_preview (dialog, layer);
GdkPixbuf *pixbuf;
@@ -265,14 +266,14 @@ ico_dialog_update_icon_preview (GtkWidget *dialog,
{
GeglBuffer *buffer;
GeglBuffer *tmp;
- gint32 image;
- gint32 tmp_image;
- gint32 tmp_layer;
+ GimpImage *image;
+ GimpImage *tmp_image;
+ GimpLayer *tmp_layer;
guchar *buf;
guchar *cmap;
gint num_colors;
- image = gimp_item_get_image (layer);
+ image = gimp_item_get_image (GIMP_ITEM (layer));
tmp_image = gimp_image_new (w, h, gimp_image_base_type (image));
gimp_image_undo_disable (tmp_image);
@@ -288,10 +289,10 @@ ico_dialog_update_icon_preview (GtkWidget *dialog,
gimp_drawable_type (layer),
100,
gimp_image_get_default_new_layer_mode (tmp_image));
- gimp_image_insert_layer (tmp_image, tmp_layer, -1, 0);
+ gimp_image_insert_layer (tmp_image, tmp_layer, NULL, 0);
buffer = gimp_drawable_get_buffer (layer);
- tmp = gimp_drawable_get_buffer (tmp_layer);
+ tmp = gimp_drawable_get_buffer (GIMP_DRAWABLE (tmp_layer));
buf = g_malloc (w * h * 4);
@@ -335,7 +336,7 @@ ico_dialog_update_icon_preview (GtkWidget *dialog,
gimp_image_convert_rgb (tmp_image);
}
- tmp = gimp_drawable_get_buffer (tmp_layer);
+ tmp = gimp_drawable_get_buffer (GIMP_DRAWABLE (tmp_layer));
gegl_buffer_set (tmp, GEGL_RECTANGLE (0, 0, w, h), 0,
format, buf, GEGL_AUTO_ROWSTRIDE);
@@ -354,7 +355,7 @@ ico_dialog_update_icon_preview (GtkWidget *dialog,
g_free (cmap);
g_free (buf);
- pixbuf = gimp_drawable_get_thumbnail (tmp_layer,
+ pixbuf = gimp_drawable_get_thumbnail (GIMP_DRAWABLE (tmp_layer),
MIN (w, 128), MIN (h, 128),
GIMP_PIXBUF_SMALL_CHECKS);
@@ -364,12 +365,12 @@ ico_dialog_update_icon_preview (GtkWidget *dialog,
{
GeglBuffer *buffer;
GeglBuffer *tmp;
- gint32 image;
- gint32 tmp_image;
- gint32 tmp_layer;
+ GimpImage *image;
+ GimpImage *tmp_image;
+ GimpLayer *tmp_layer;
GimpValueArray *return_vals;
- image = gimp_item_get_image (layer);
+ image = gimp_item_get_image (GIMP_ITEM (layer));
tmp_image = gimp_image_new (w, h, gimp_image_base_type (image));
gimp_image_undo_disable (tmp_image);
@@ -388,10 +389,10 @@ ico_dialog_update_icon_preview (GtkWidget *dialog,
gimp_drawable_type (layer),
100,
gimp_image_get_default_new_layer_mode (tmp_image));
- gimp_image_insert_layer (tmp_image, tmp_layer, -1, 0);
+ gimp_image_insert_layer (tmp_image, tmp_layer, NULL, 0);
buffer = gimp_drawable_get_buffer (layer);
- tmp = gimp_drawable_get_buffer (tmp_layer);
+ tmp = gimp_drawable_get_buffer (GIMP_DRAWABLE (tmp_layer));
gegl_buffer_copy (buffer, NULL, GEGL_ABYSS_NONE, tmp, NULL);
@@ -405,14 +406,14 @@ ico_dialog_update_icon_preview (GtkWidget *dialog,
gimp_pdb_run_procedure (gimp_get_pdb (),
"plug-in-threshold-alpha",
GIMP_TYPE_RUN_MODE, GIMP_RUN_NONINTERACTIVE,
- GIMP_TYPE_IMAGE_ID, tmp_image,
- GIMP_TYPE_DRAWABLE_ID, tmp_layer,
+ GIMP_TYPE_IMAGE_ID, gimp_image_get_id (tmp_image),
+ GIMP_TYPE_DRAWABLE_ID, gimp_item_get_id (GIMP_ITEM (tmp_layer)),
G_TYPE_INT, ICO_ALPHA_THRESHOLD,
G_TYPE_NONE);
gimp_value_array_unref (return_vals);
- pixbuf = gimp_drawable_get_thumbnail (tmp_layer,
+ pixbuf = gimp_drawable_get_thumbnail (GIMP_DRAWABLE (tmp_layer),
MIN (w, 128), MIN (h, 128),
GIMP_PIXBUF_SMALL_CHECKS);
@@ -430,9 +431,9 @@ ico_dialog_update_icon_preview (GtkWidget *dialog,
}
void
-ico_dialog_add_icon (GtkWidget *dialog,
- gint32 layer,
- gint layer_num)
+ico_dialog_add_icon (GtkWidget *dialog,
+ GimpDrawable *layer,
+ gint layer_num)
{
GtkWidget *vbox;
GtkWidget *hbox;
@@ -449,7 +450,8 @@ ico_dialog_add_icon (GtkWidget *dialog,
gtk_widget_show (hbox);
/* Let's make the hbox accessible through the layer ID */
- g_snprintf (key, sizeof (key), "layer_%i_hbox", layer);
+ g_snprintf (key, sizeof (key), "layer_%i_hbox",
+ gimp_item_get_id (GIMP_ITEM (layer)));
g_object_set_data (G_OBJECT (dialog), key, hbox);
ico_dialog_update_icon_preview (dialog, layer, info->depths[layer_num]);
@@ -461,11 +463,11 @@ static void
ico_dialog_bpp_changed (GtkWidget *combo,
GObject *hbox)
{
- GtkWidget *dialog;
- gint32 layer;
- gint layer_num;
- gint bpp;
- IcoSaveInfo *info;
+ GtkWidget *dialog;
+ GimpDrawable *layer;
+ gint layer_num;
+ gint bpp;
+ IcoSaveInfo *info;
dialog = gtk_widget_get_toplevel (combo);
@@ -474,7 +476,7 @@ ico_dialog_bpp_changed (GtkWidget *combo,
info = g_object_get_data (G_OBJECT (dialog), "save_info");
g_assert (info);
- layer = GPOINTER_TO_INT (g_object_get_data (hbox, "icon_layer"));
+ layer = g_object_get_data (hbox, "icon_layer");
layer_num = GPOINTER_TO_INT (g_object_get_data (hbox, "icon_layer_num"));
/* Update vector entry for later when we're actually saving,
@@ -509,13 +511,14 @@ ico_dialog_check_compat (GtkWidget *dialog,
IcoSaveInfo *info)
{
GtkWidget *warning;
+ GList *iter;
gboolean warn = FALSE;
gint i;
- for (i = 0; i < info->num_icons; i++)
+ for (iter = info->layers, i = 0; iter; iter = iter->next, i++)
{
- if (gimp_drawable_width (info->layers[i]) > 255 ||
- gimp_drawable_height (info->layers[i]) > 255 ||
+ if (gimp_drawable_width (iter->data) > 255 ||
+ gimp_drawable_height (iter->data) > 255 ||
info->compress[i])
{
warn = TRUE;
diff --git a/plug-ins/file-ico/ico-dialog.h b/plug-ins/file-ico/ico-dialog.h
index 19ddee446a..f39315d80c 100644
--- a/plug-ins/file-ico/ico-dialog.h
+++ b/plug-ins/file-ico/ico-dialog.h
@@ -22,9 +22,9 @@
#define __ICO_DIALOG_H__
-GtkWidget * ico_dialog_new (IcoSaveInfo *info);
-void ico_dialog_add_icon (GtkWidget *dialog,
- gint32 layer,
- gint layer_num);
+GtkWidget * ico_dialog_new (IcoSaveInfo *info);
+void ico_dialog_add_icon (GtkWidget *dialog,
+ GimpDrawable *layer,
+ gint layer_num);
#endif /* __ICO_DIALOG_H__ */
diff --git a/plug-ins/file-ico/ico-load.c b/plug-ins/file-ico/ico-load.c
index f44b805905..075590cc34 100644
--- a/plug-ins/file-ico/ico-load.c
+++ b/plug-ins/file-ico/ico-load.c
@@ -597,37 +597,37 @@ ico_read_icon (FILE *fp,
return TRUE;
}
-static gint32
+static GimpLayer *
ico_load_layer (FILE *fp,
- gint32 image,
+ GimpImage *image,
gint32 icon_num,
guchar *buf,
gint maxsize,
IcoLoadInfo *info)
{
gint width, height;
- gint32 layer;
+ GimpLayer *layer;
guint32 first_bytes;
GeglBuffer *buffer;
gchar name[ICO_MAXBUF];
if (fseek (fp, info->offset, SEEK_SET) < 0 ||
! ico_read_int32 (fp, &first_bytes, 1))
- return -1;
+ return NULL;
if (first_bytes == ICO_PNG_MAGIC)
{
if (!ico_read_png (fp, first_bytes, buf, maxsize, &width, &height))
- return -1;
+ return NULL;
}
else if (first_bytes == 40)
{
if (!ico_read_icon (fp, first_bytes, buf, maxsize, &width, &height))
- return -1;
+ return NULL;
}
else
{
- return -1;
+ return NULL;
}
/* read successfully. add to image */
@@ -636,9 +636,9 @@ ico_load_layer (FILE *fp,
GIMP_RGBA_IMAGE,
100,
gimp_image_get_default_new_layer_mode (image));
- gimp_image_insert_layer (image, layer, -1, icon_num);
+ gimp_image_insert_layer (image, layer, NULL, icon_num);
- buffer = gimp_drawable_get_buffer (layer);
+ buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
gegl_buffer_set (buffer, GEGL_RECTANGLE (0, 0, width, height), 0,
NULL, buf, GEGL_AUTO_ROWSTRIDE);
@@ -649,7 +649,7 @@ ico_load_layer (FILE *fp,
}
-gint32
+GimpImage *
ico_load_image (const gchar *filename,
GError **error)
{
@@ -657,7 +657,7 @@ ico_load_image (const gchar *filename,
IcoLoadInfo *info;
gint max_width, max_height;
gint i;
- gint32 image;
+ GimpImage *image;
guchar *buf;
guint icon_count;
gint maxsize;
@@ -671,21 +671,21 @@ ico_load_image (const gchar *filename,
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
- return -1;
+ return NULL;
}
icon_count = ico_read_init (fp);
if (!icon_count)
{
fclose (fp);
- return -1;
+ return NULL;
}
info = ico_read_info (fp, icon_count, error);
if (! info)
{
fclose (fp);
- return -1;
+ return NULL;
}
/* find width and height of image */
@@ -702,7 +702,7 @@ ico_load_image (const gchar *filename,
{
g_free (info);
fclose (fp);
- return -1;
+ return NULL;
}
D(("image size: %ix%i\n", max_width, max_height));
@@ -724,7 +724,7 @@ ico_load_image (const gchar *filename,
return image;
}
-gint32
+GimpImage *
ico_load_thumbnail_image (const gchar *filename,
gint *width,
gint *height,
@@ -732,7 +732,7 @@ ico_load_thumbnail_image (const gchar *filename,
{
FILE *fp;
IcoLoadInfo *info;
- gint32 image;
+ GimpImage *image;
gint w = 0;
gint h = 0;
gint bpp = 0;
@@ -749,14 +749,14 @@ ico_load_thumbnail_image (const gchar *filename,
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
- return -1;
+ return NULL;
}
icon_count = ico_read_init (fp);
if (! icon_count)
{
fclose (fp);
- return -1;
+ return NULL;
}
D(("*** %s: Microsoft icon file, containing %i icon(s)\n",
@@ -766,7 +766,7 @@ ico_load_thumbnail_image (const gchar *filename,
if (! info)
{
fclose (fp);
- return -1;
+ return NULL;
}
/* Do a quick scan of the icons in the file to find the best match */
@@ -792,7 +792,7 @@ ico_load_thumbnail_image (const gchar *filename,
}
if (w <= 0 || h <= 0)
- return -1;
+ return NULL;
image = gimp_image_new (w, h, GIMP_RGB);
buf = g_new (guchar, w*h*4);
diff --git a/plug-ins/file-ico/ico-load.h b/plug-ins/file-ico/ico-load.h
index 8749fd986c..92205f0edc 100644
--- a/plug-ins/file-ico/ico-load.h
+++ b/plug-ins/file-ico/ico-load.h
@@ -22,22 +22,22 @@
#define __ICO_LOAD_H__
-gint32 ico_load_image (const gchar *filename,
- GError **error);
-gint32 ico_load_thumbnail_image (const gchar *filename,
- gint *width,
- gint *height,
- GError **error);
+GimpImage * ico_load_image (const gchar *filename,
+ GError **error);
+GimpImage * ico_load_thumbnail_image (const gchar *filename,
+ gint *width,
+ gint *height,
+ GError **error);
-gint ico_get_bit_from_data (const guint8 *data,
- gint line_width,
- gint bit);
-gint ico_get_nibble_from_data (const guint8 *data,
- gint line_width,
- gint nibble);
-gint ico_get_byte_from_data (const guint8 *data,
- gint line_width,
- gint byte);
+gint ico_get_bit_from_data (const guint8 *data,
+ gint line_width,
+ gint bit);
+gint ico_get_nibble_from_data (const guint8 *data,
+ gint line_width,
+ gint nibble);
+gint ico_get_byte_from_data (const guint8 *data,
+ gint line_width,
+ gint byte);
#endif /* __ICO_LOAD_H__ */
diff --git a/plug-ins/file-ico/ico-save.c b/plug-ins/file-ico/ico-save.c
index e669660f4e..aedb069002 100644
--- a/plug-ins/file-ico/ico-save.c
+++ b/plug-ins/file-ico/ico-save.c
@@ -64,13 +64,13 @@ static void ico_set_byte_in_data (guint8 *data,
gint byte_num,
gint byte_val);
-static gint ico_get_layer_num_colors (gint32 layer,
- gboolean *uses_alpha_levels);
-static void ico_image_get_reduced_buf (guint32 layer,
- gint bpp,
- gint *num_colors,
- guchar **cmap_out,
- guchar **buf_out);
+static gint ico_get_layer_num_colors (GimpLayer *layer,
+ gboolean *uses_alpha_levels);
+static void ico_image_get_reduced_buf (GimpDrawable *layer,
+ gint bpp,
+ gint *num_colors,
+ guchar **cmap_out,
+ guchar **buf_out);
static gint
@@ -156,14 +156,17 @@ ico_write_int8 (FILE *fp,
static void
-ico_save_init (gint32 image_ID,
+ico_save_init (GimpImage *image,
IcoSaveInfo *info)
{
- gint *layers;
- gint i, num_colors;
+ GList *layers;
+ GList *iter;
+ gint num_colors;
+ gint i;
gboolean uses_alpha_values = FALSE;
- layers = gimp_image_get_layers (image_ID, &info->num_icons);
+ layers = gimp_image_get_layers (image);
+ info->num_icons = g_list_length (layers);
info->layers = layers;
info->depths = g_new (gint, info->num_icons);
info->default_depths = g_new (gint, info->num_icons);
@@ -173,9 +176,9 @@ ico_save_init (gint32 image_ID,
the user should pick these anyway, so we can save her some time.
If the user wants to lose some colors, the settings can always be changed
in the dialog: */
- for (i = 0; i < info->num_icons; i++)
+ for (iter = layers, i = 0; iter; iter = iter->next, i++)
{
- num_colors = ico_get_layer_num_colors (layers[i], &uses_alpha_values);
+ num_colors = ico_get_layer_num_colors (iter->data, &uses_alpha_values);
if (!uses_alpha_values)
{
@@ -207,8 +210,8 @@ ico_save_init (gint32 image_ID,
}
/* vista icons */
- if (gimp_drawable_width (layers[i]) > 255
- || gimp_drawable_height (layers[i]) > 255 )
+ if (gimp_drawable_width (iter->data) > 255
+ || gimp_drawable_height (iter->data) > 255 )
{
info->compress[i] = TRUE;
}
@@ -226,20 +229,21 @@ ico_save_init (gint32 image_ID,
static gboolean
-ico_save_dialog (gint32 image_ID,
+ico_save_dialog (GimpImage *image,
IcoSaveInfo *info)
{
GtkWidget *dialog;
+ GList *iter;
gint i;
gint response;
gimp_ui_init (PLUG_IN_BINARY, TRUE);
dialog = ico_dialog_new (info);
- for (i = 0; i < info->num_icons; i++)
+ for (iter = info->layers, i = 0; iter; iter = iter->next, i++)
{
/* if (gimp_layer_get_visible(layers[i])) */
- ico_dialog_add_icon (dialog, info->layers[i], i);
+ ico_dialog_add_icon (dialog, iter->data, i);
}
/* Scale the thing to approximately fit its content, but not too large ... */
@@ -423,8 +427,8 @@ ico_get_palette_index (GHashTable *hash,
}
static gint
-ico_get_layer_num_colors (gint32 layer,
- gboolean *uses_alpha_levels)
+ico_get_layer_num_colors (GimpLayer *layer,
+ gboolean *uses_alpha_levels)
{
gint w, h;
gint bpp;
@@ -435,7 +439,7 @@ ico_get_layer_num_colors (gint32 layer,
guint32 *colors;
guint32 *c;
GHashTable *hash;
- GeglBuffer *buffer = gimp_drawable_get_buffer (layer);
+ GeglBuffer *buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
const Babl *format;
w = gegl_buffer_get_width (buffer);
@@ -443,7 +447,7 @@ ico_get_layer_num_colors (gint32 layer,
num_pixels = w * h;
- switch (gimp_drawable_type (layer))
+ switch (gimp_drawable_type (GIMP_DRAWABLE (layer)))
{
case GIMP_RGB_IMAGE:
format = babl_format ("R'G'B' u8");
@@ -565,14 +569,14 @@ ico_cmap_contains_black (const guchar *cmap,
}
static void
-ico_image_get_reduced_buf (guint32 layer,
- gint bpp,
- gint *num_colors,
- guchar **cmap_out,
- guchar **buf_out)
+ico_image_get_reduced_buf (GimpDrawable *layer,
+ gint bpp,
+ gint *num_colors,
+ guchar **cmap_out,
+ guchar **buf_out)
{
- gint32 tmp_image;
- gint32 tmp_layer;
+ GimpImage *tmp_image;
+ GimpLayer *tmp_layer;
gint w, h;
guchar *buf;
guchar *cmap = NULL;
@@ -615,7 +619,7 @@ ico_image_get_reduced_buf (guint32 layer,
if (bpp <= 8 || bpp == 24 || babl_format_get_bytes_per_pixel (format) != 4)
{
- gint32 image = gimp_item_get_image (layer);
+ GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
GeglBuffer *tmp;
tmp_image = gimp_image_new (w, h, gimp_image_base_type (image));
@@ -635,9 +639,9 @@ ico_image_get_reduced_buf (guint32 layer,
gimp_drawable_type (layer),
100,
gimp_image_get_default_new_layer_mode (tmp_image));
- gimp_image_insert_layer (tmp_image, tmp_layer, -1, 0);
+ gimp_image_insert_layer (tmp_image, tmp_layer, NULL, 0);
- tmp = gimp_drawable_get_buffer (tmp_layer);
+ tmp = gimp_drawable_get_buffer (GIMP_DRAWABLE (tmp_layer));
gegl_buffer_get (buffer, GEGL_RECTANGLE (0, 0, w, h), 1.0,
format, buf,
@@ -647,7 +651,7 @@ ico_image_get_reduced_buf (guint32 layer,
g_object_unref (tmp);
- if (! gimp_drawable_is_rgb (tmp_layer))
+ if (! gimp_drawable_is_rgb (GIMP_DRAWABLE (tmp_layer)))
gimp_image_convert_rgb (tmp_image);
if (bpp <= 8)
@@ -681,7 +685,7 @@ ico_image_get_reduced_buf (guint32 layer,
gimp_image_convert_rgb (tmp_image);
}
- tmp = gimp_drawable_get_buffer (tmp_layer);
+ tmp = gimp_drawable_get_buffer (GIMP_DRAWABLE (tmp_layer));
gegl_buffer_set (tmp, GEGL_RECTANGLE (0, 0, w, h), 0,
format, buf, GEGL_AUTO_ROWSTRIDE);
@@ -709,8 +713,8 @@ ico_image_get_reduced_buf (guint32 layer,
gimp_pdb_run_procedure (gimp_get_pdb (),
"plug-in-threshold-alpha",
GIMP_TYPE_RUN_MODE, GIMP_RUN_NONINTERACTIVE,
- GIMP_TYPE_IMAGE_ID, tmp_image,
- GIMP_TYPE_DRAWABLE_ID, tmp_layer,
+ GIMP_TYPE_IMAGE_ID, gimp_image_get_id (tmp_image),
+ GIMP_TYPE_DRAWABLE_ID, gimp_item_get_id (GIMP_ITEM (tmp_layer)),
G_TYPE_INT, ICO_ALPHA_THRESHOLD,
G_TYPE_NONE);
@@ -719,7 +723,7 @@ ico_image_get_reduced_buf (guint32 layer,
gimp_layer_add_alpha (tmp_layer);
- tmp = gimp_drawable_get_buffer (tmp_layer);
+ tmp = gimp_drawable_get_buffer (GIMP_DRAWABLE (tmp_layer));
gegl_buffer_get (tmp, GEGL_RECTANGLE (0, 0, w, h), 1.0,
NULL, buf,
@@ -743,9 +747,9 @@ ico_image_get_reduced_buf (guint32 layer,
}
static gboolean
-ico_write_png (FILE *fp,
- gint32 layer,
- gint32 depth)
+ico_write_png (FILE *fp,
+ GimpDrawable *layer,
+ gint32 depth)
{
png_structp png_ptr;
png_infop info_ptr;
@@ -818,9 +822,9 @@ ico_write_png (FILE *fp,
}
static gboolean
-ico_write_icon (FILE *fp,
- gint32 layer,
- gint32 depth)
+ico_write_icon (FILE *fp,
+ GimpDrawable *layer,
+ gint32 depth)
{
IcoFileDataHeader header;
gint and_len, xor_len, palette_index, x, y;
@@ -1049,24 +1053,26 @@ ico_save_info_free (IcoSaveInfo *info)
g_free (info->depths);
g_free (info->default_depths);
g_free (info->compress);
- g_free (info->layers);
+ g_list_free_full (info->layers, g_object_unref);
memset (info, 0, sizeof (IcoSaveInfo));
}
GimpPDBStatusType
ico_save_image (const gchar *filename,
- gint32 image,
+ GimpImage *image,
gint32 run_mode,
GError **error)
{
FILE *fp;
- gint i;
- gint width, height;
- IcoSaveInfo info;
- IcoFileHeader header;
- IcoFileEntry *entries;
- gboolean saved;
+ GList *iter;
+ gint width;
+ gint height;
+ IcoSaveInfo info;
+ IcoFileHeader header;
+ IcoFileEntry *entries;
+ gboolean saved;
+ gint i;
D(("*** Exporting Microsoft icon file %s\n", filename));
@@ -1111,12 +1117,12 @@ ico_save_image (const gchar *filename,
return GIMP_PDB_EXECUTION_ERROR;
}
- for (i = 0; i < info.num_icons; i++)
+ for (iter = info.layers, i = 0; iter; iter = iter->next, i++)
{
gimp_progress_update ((gdouble)i / (gdouble)info.num_icons);
- width = gimp_drawable_width (info.layers[i]);
- height = gimp_drawable_height (info.layers[i]);
+ width = gimp_drawable_width (iter->data);
+ height = gimp_drawable_height (iter->data);
if (width <= 255 && height <= 255)
{
entries[i].width = width;
@@ -1137,9 +1143,9 @@ ico_save_image (const gchar *filename,
entries[i].offset = ftell (fp);
if (info.compress[i])
- saved = ico_write_png (fp, info.layers[i], info.depths[i]);
+ saved = ico_write_png (fp, iter->data, info.depths[i]);
else
- saved = ico_write_icon (fp, info.layers[i], info.depths[i]);
+ saved = ico_write_icon (fp, iter->data, info.depths[i]);
if (!saved)
{
diff --git a/plug-ins/file-ico/ico-save.h b/plug-ins/file-ico/ico-save.h
index 46d6ff5e5c..471c2a61a2 100644
--- a/plug-ins/file-ico/ico-save.h
+++ b/plug-ins/file-ico/ico-save.h
@@ -23,7 +23,7 @@
GimpPDBStatusType ico_save_image (const gchar *file_name,
- gint32 image_ID,
+ GimpImage *image,
gint32 run_mode,
GError **error);
diff --git a/plug-ins/file-ico/ico.c b/plug-ins/file-ico/ico.c
index a6a5e7e18b..87b7e3796a 100644
--- a/plug-ins/file-ico/ico.c
+++ b/plug-ins/file-ico/ico.c
@@ -73,8 +73,8 @@ static GimpValueArray * ico_load_thumb (GimpProcedure *procedure,
gpointer run_data);
static GimpValueArray * ico_save (GimpProcedure *procedure,
GimpRunMode run_mode,
- gint32 image_id,
- gint32 drawable_id,
+ GimpImage *image,
+ GimpDrawable *drawable,
GFile *file,
const GimpValueArray *args,
gpointer run_data);
@@ -195,7 +195,7 @@ ico_load (GimpProcedure *procedure,
{
GimpValueArray *return_vals;
gchar *filename;
- gint32 image_id;
+ GimpImage *image;
GError *error = NULL;
INIT_I18N ();
@@ -203,11 +203,11 @@ ico_load (GimpProcedure *procedure,
filename = g_file_get_path (file);
- image_id = ico_load_image (filename, &error);
+ image = ico_load_image (filename, &error);
g_free (filename);
- if (image_id < 1)
+ if (! image)
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_EXECUTION_ERROR,
error);
@@ -216,7 +216,7 @@ ico_load (GimpProcedure *procedure,
GIMP_PDB_SUCCESS,
NULL);
- GIMP_VALUES_SET_IMAGE (return_vals, 1, image_id);
+ GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
return return_vals;
}
@@ -232,7 +232,7 @@ ico_load_thumb (GimpProcedure *procedure,
gchar *filename;
gint width;
gint height;
- gint32 image_id;
+ GimpImage *image;
GError *error = NULL;
INIT_I18N ();
@@ -242,10 +242,10 @@ ico_load_thumb (GimpProcedure *procedure,
width = size;
height = size;
- image_id = ico_load_thumbnail_image (filename,
- &width, &height, &error);
+ image = ico_load_thumbnail_image (filename,
+ &width, &height, &error);
- if (image_id < 1)
+ if (image)
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_EXECUTION_ERROR,
error);
@@ -254,7 +254,7 @@ ico_load_thumb (GimpProcedure *procedure,
GIMP_PDB_SUCCESS,
NULL);
- GIMP_VALUES_SET_IMAGE (return_vals, 1, image_id);
+ GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
GIMP_VALUES_SET_INT (return_vals, 2, width);
GIMP_VALUES_SET_INT (return_vals, 3, height);
@@ -266,8 +266,8 @@ ico_load_thumb (GimpProcedure *procedure,
static GimpValueArray *
ico_save (GimpProcedure *procedure,
GimpRunMode run_mode,
- gint32 image_id,
- gint32 drawable_id,
+ GimpImage *image,
+ GimpDrawable *drawable,
GFile *file,
const GimpValueArray *args,
gpointer run_data)
@@ -281,7 +281,7 @@ ico_save (GimpProcedure *procedure,
filename = g_file_get_path (file);
- status = ico_save_image (filename, image_id, run_mode, &error);
+ status = ico_save_image (filename, image, run_mode, &error);
g_free (filename);
diff --git a/plug-ins/file-ico/ico.h b/plug-ins/file-ico/ico.h
index 65a217cd46..39374a059c 100644
--- a/plug-ins/file-ico/ico.h
+++ b/plug-ins/file-ico/ico.h
@@ -89,7 +89,7 @@ typedef struct _IcoSaveInfo
gint *depths;
gint *default_depths;
gboolean *compress;
- gint *layers;
+ GList *layers;
gint num_icons;
} IcoSaveInfo;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]