[gimp] plug-ins: port file-gif-load to new libgimp objects.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: port file-gif-load to new libgimp objects.
- Date: Thu, 22 Aug 2019 21:42:48 +0000 (UTC)
commit 858ab51f44162fe2fc2beb653bdf1c81486c9b12
Author: Jehan <jehan girinstud io>
Date: Thu Aug 22 23:41:36 2019 +0200
plug-ins: port file-gif-load to new libgimp objects.
plug-ins/common/Makefile.am | 2 -
plug-ins/common/file-gif-load.c | 152 ++++++++++++++++++++--------------------
plug-ins/common/plugin-defs.pl | 2 +-
3 files changed, 77 insertions(+), 79 deletions(-)
---
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index f3c8cc6fcc..39d6db759e 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -706,8 +706,6 @@ file_gegl_LDADD = \
$(INTLLIBS) \
$(file_gegl_RC)
-file_gif_load_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
-
file_gif_load_SOURCES = \
file-gif-load.c
diff --git a/plug-ins/common/file-gif-load.c b/plug-ins/common/file-gif-load.c
index a1e29f3c81..3f3c1ce74c 100644
--- a/plug-ins/common/file-gif-load.c
+++ b/plug-ins/common/file-gif-load.c
@@ -117,7 +117,7 @@ static GimpValueArray * gif_load_thumb (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer run_data);
-static gint32 load_image (const gchar *filename,
+static GimpImage * load_image (const gchar *filename,
gboolean thumbnail,
GError **error);
@@ -224,7 +224,7 @@ gif_load (GimpProcedure *procedure,
{
GimpValueArray *return_vals;
gchar *filename;
- gint32 image_id;
+ GimpImage *image;
GError *error = NULL;
INIT_I18N ();
@@ -232,11 +232,11 @@ gif_load (GimpProcedure *procedure,
filename = g_file_get_path (file);
- image_id = load_image (filename, FALSE, &error);
+ image = load_image (filename, FALSE, &error);
g_free (filename);
- if (image_id < 1)
+ if (! image)
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_EXECUTION_ERROR,
error);
@@ -256,14 +256,14 @@ gif_load (GimpProcedure *procedure,
#endif
if (! promote_to_rgb)
- gimp_image_set_colormap (image_id,
+ gimp_image_set_colormap (image,
gimp_cmap, highest_used_index + 1);
return_vals = gimp_procedure_new_return_values (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;
}
@@ -276,30 +276,29 @@ gif_load_thumb (GimpProcedure *procedure,
gpointer run_data)
{
GimpValueArray *return_vals;
- gint32 image_id;
+ GimpImage *image;
GError *error = NULL;
INIT_I18N ();
gegl_init (NULL, NULL);
- image_id = load_image (g_file_get_path (file), TRUE, &error);
+ image = load_image (g_file_get_path (file), TRUE, &error);
- if (image_id < 1)
+ if (! image)
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_EXECUTION_ERROR,
error);
if (! promote_to_rgb)
- gimp_image_set_colormap (image_id,
- gimp_cmap, highest_used_index + 1);
+ gimp_image_set_colormap (image, gimp_cmap, highest_used_index + 1);
return_vals = gimp_procedure_new_return_values (procedure,
GIMP_PDB_SUCCESS,
NULL);
- GIMP_VALUES_SET_IMAGE (return_vals, 1, image_id);
- GIMP_VALUES_SET_INT (return_vals, 2, gimp_image_width (image_id));
- GIMP_VALUES_SET_INT (return_vals, 3, gimp_image_height (image_id));
+ GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
+ GIMP_VALUES_SET_INT (return_vals, 2, gimp_image_width (image));
+ GIMP_VALUES_SET_INT (return_vals, 3, gimp_image_height (image));
gimp_value_array_truncate (return_vals, 4);
@@ -377,25 +376,25 @@ static gboolean ReadImage (FILE *fd,
guint toppos,
guint screenwidth,
guint screenheight,
- gint32 *image_ID);
+ GimpImage **image);
-static gint32
+static GimpImage *
load_image (const gchar *filename,
gboolean thumbnail,
GError **error)
{
- FILE *fd;
- guchar buf[16];
- guchar c;
- CMap localColorMap;
- gint grayScale;
- gboolean useGlobalColormap;
- gint bitPixel;
- gint imageCount = 0;
- gchar version[4];
- gint32 image_ID = -1;
- gboolean status;
+ FILE *fd;
+ guchar buf[16];
+ guchar c;
+ CMap localColorMap;
+ gint grayScale;
+ gboolean useGlobalColormap;
+ gint bitPixel;
+ gint imageCount = 0;
+ gchar version[4];
+ GimpImage *image = NULL;
+ gboolean status;
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
@@ -407,14 +406,14 @@ 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;
}
if (! ReadOK (fd, buf, 6))
{
g_message ("Error reading magic number");
fclose (fd);
- return -1;
+ return NULL;
}
if (strncmp ((gchar *) buf, "GIF", 3) != 0)
@@ -422,7 +421,7 @@ load_image (const gchar *filename,
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
"%s", _("This is not a GIF file"));
fclose (fd);
- return -1;
+ return NULL;
}
g_strlcpy (version, (gchar *) buf + 3, 4);
@@ -431,14 +430,14 @@ load_image (const gchar *filename,
{
g_message ("Bad version number, not '87a' or '89a'");
fclose (fd);
- return -1;
+ return NULL;
}
if (! ReadOK (fd, buf, 7))
{
g_message ("Failed to read screen descriptor");
fclose (fd);
- return -1;
+ return NULL;
}
GifScreen.Width = LM_to_uint (buf[0], buf[1]);
@@ -456,7 +455,7 @@ load_image (const gchar *filename,
{
g_message ("Error reading global colormap");
fclose (fd);
- return -1;
+ return NULL;
}
}
@@ -474,14 +473,14 @@ load_image (const gchar *filename,
{
g_message ("EOF / read error on image data");
fclose (fd);
- return image_ID; /* will be -1 if failed on first image! */
+ return image; /* will be NULL if failed on first image! */
}
if (c == ';')
{
/* GIF terminator */
fclose (fd);
- return image_ID;
+ return image;
}
if (c == '!')
@@ -491,7 +490,7 @@ load_image (const gchar *filename,
{
g_message ("EOF / read error on extension function code");
fclose (fd);
- return image_ID; /* will be -1 if failed on first image! */
+ return image; /* will be NULL if failed on first image! */
}
DoExtension (fd, c);
@@ -511,7 +510,7 @@ load_image (const gchar *filename,
{
g_message ("Couldn't read left/top/width/height");
fclose (fd);
- return image_ID; /* will be -1 if failed on first image! */
+ return image; /* will be NULL if failed on first image! */
}
useGlobalColormap = !BitSet (buf[8], LOCALCOLORMAP);
@@ -524,7 +523,7 @@ load_image (const gchar *filename,
{
g_message ("Error reading local colormap");
fclose (fd);
- return image_ID; /* will be -1 if failed on first image! */
+ return image; /* will be NULL if failed on first image! */
}
status = ReadImage (fd, filename, LM_to_uint (buf[4], buf[5]),
@@ -536,7 +535,7 @@ load_image (const gchar *filename,
(guint) LM_to_uint (buf[2], buf[3]),
GifScreen.Width,
GifScreen.Height,
- &image_ID);
+ &image);
}
else
{
@@ -549,7 +548,7 @@ load_image (const gchar *filename,
(guint) LM_to_uint (buf[2], buf[3]),
GifScreen.Width,
GifScreen.Height,
- &image_ID);
+ &image);
}
if (!status)
@@ -560,7 +559,7 @@ load_image (const gchar *filename,
if (comment_parasite != NULL)
{
if (! thumbnail)
- gimp_image_attach_parasite (image_ID, comment_parasite);
+ gimp_image_attach_parasite (image, comment_parasite);
gimp_parasite_free (comment_parasite);
comment_parasite = NULL;
@@ -573,7 +572,7 @@ load_image (const gchar *filename,
fclose (fd);
- return image_ID;
+ return image;
}
static gboolean
@@ -971,11 +970,11 @@ ReadImage (FILE *fd,
guint toppos,
guint screenwidth,
guint screenheight,
- gint32 *image_ID)
+ GimpImage **image)
{
static gint frame_number = 1;
- gint32 layer_ID;
+ GimpLayer *layer;
GeglBuffer *buffer;
guchar *dest, *temp;
guchar c;
@@ -992,7 +991,7 @@ ReadImage (FILE *fd,
if (len < 1 || height < 1)
{
g_message ("Bogus frame dimensions");
- *image_ID = -1;
+ *image = NULL;
return FALSE;
}
@@ -1002,14 +1001,14 @@ ReadImage (FILE *fd,
if (! ReadOK (fd, &c, 1))
{
g_message ("EOF / read error on image data");
- *image_ID = -1;
+ *image = NULL;
return FALSE;
}
if (LZWReadByte (fd, TRUE, c) < 0)
{
g_message ("Error while reading");
- *image_ID = -1;
+ *image = NULL;
return FALSE;
}
@@ -1022,8 +1021,8 @@ ReadImage (FILE *fd,
if (screenheight == 0)
screenheight = height;
- *image_ID = gimp_image_new (screenwidth, screenheight, GIMP_INDEXED);
- gimp_image_set_filename (*image_ID, filename);
+ *image = gimp_image_new (screenwidth, screenheight, GIMP_INDEXED);
+ gimp_image_set_filename (*image, filename);
for (i = 0, j = 0; i < ncols; i++)
{
@@ -1032,7 +1031,7 @@ ReadImage (FILE *fd,
used_cmap[2][i] = gimp_cmap[j++] = cmap[2][i];
}
- gimp_image_set_colormap (*image_ID, gimp_cmap, ncols);
+ gimp_image_set_colormap (*image, gimp_cmap, ncols);
if (Gif89.delayTime < 0)
framename = g_strdup (_("Background"));
@@ -1044,19 +1043,19 @@ ReadImage (FILE *fd,
if (Gif89.transparent == -1)
{
- layer_ID = gimp_layer_new (*image_ID, framename,
- len, height,
- GIMP_INDEXED_IMAGE,
- 100,
- gimp_image_get_default_new_layer_mode (*image_ID));
+ layer = gimp_layer_new (*image, framename,
+ len, height,
+ GIMP_INDEXED_IMAGE,
+ 100,
+ gimp_image_get_default_new_layer_mode (*image));
}
else
{
- layer_ID = gimp_layer_new (*image_ID, framename,
- len, height,
- GIMP_INDEXEDA_IMAGE,
- 100,
- gimp_image_get_default_new_layer_mode (*image_ID));
+ layer = gimp_layer_new (*image, framename,
+ len, height,
+ GIMP_INDEXEDA_IMAGE,
+ 100,
+ gimp_image_get_default_new_layer_mode (*image));
alpha_frame=TRUE;
}
@@ -1085,7 +1084,7 @@ ReadImage (FILE *fd,
#ifdef GIFDEBUG
g_print ("GIF: Promoting image to RGB...\n");
#endif
- gimp_image_convert_rgb (*image_ID);
+ gimp_image_convert_rgb (*image);
break;
}
@@ -1137,31 +1136,32 @@ ReadImage (FILE *fd,
}
previous_disposal = Gif89.disposal;
- layer_ID = gimp_layer_new (*image_ID, framename,
- len, height,
- promote_to_rgb ?
- GIMP_RGBA_IMAGE : GIMP_INDEXEDA_IMAGE,
- 100,
- gimp_image_get_default_new_layer_mode (*image_ID));
+ layer = gimp_layer_new (*image, framename,
+ len, height,
+ promote_to_rgb ?
+ GIMP_RGBA_IMAGE : GIMP_INDEXEDA_IMAGE,
+ 100,
+ gimp_image_get_default_new_layer_mode (*image));
alpha_frame = TRUE;
g_free (framename);
}
frame_number++;
- gimp_image_insert_layer (*image_ID, layer_ID, -1, 0);
- gimp_item_transform_translate (layer_ID, (gint) leftpos, (gint) toppos);
+ gimp_image_insert_layer (*image, layer, NULL, 0);
+ gimp_item_transform_translate (GIMP_ITEM (layer), (gint) leftpos, (gint) toppos);
cur_progress = 0;
max_progress = height;
if (len > (G_MAXSIZE / height / (alpha_frame ? (promote_to_rgb ? 4 : 2) : 1)))
- {
- g_message ("'%s' has a larger image size than GIMP can handle.",
- gimp_filename_to_utf8 (filename));
- *image_ID = -1;
- return FALSE;
- }
+ {
+ g_message ("'%s' has a larger image size than GIMP can handle.",
+ gimp_filename_to_utf8 (filename));
+ gimp_image_delete (*image);
+ *image = NULL;
+ return FALSE;
+ }
if (alpha_frame)
dest = (guchar *) g_malloc ((gsize)len * (gsize)height * (promote_to_rgb ? 4 : 2));
@@ -1277,7 +1277,7 @@ ReadImage (FILE *fd,
}
fini:
- buffer = gimp_drawable_get_buffer (layer_ID);
+ buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
gegl_buffer_set (buffer, GEGL_RECTANGLE (0, 0, len, height), 0,
NULL, dest, GEGL_AUTO_ROWSTRIDE);
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index 71a9341425..314ddc5e6f 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -24,7 +24,7 @@
'file-dicom' => { ui => 1, gegl => 1, cflags => '-fno-strict-aliasing', old_api => 1 },
'file-gbr' => { ui => 1, gegl => 1 },
'file-gegl' => { ui => 1, gegl => 1, old_api => 1 },
- 'file-gif-load' => { gegl => 1, old_api => 1 },
+ 'file-gif-load' => { gegl => 1 },
'file-gif-save' => { ui => 1, gegl => 1, old_api => 1 },
'file-gih' => { ui => 1, gegl => 1 },
'file-glob' => {},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]