plug-ins: port file-gif-load to new libgimp objects.

This commit is contained in:
Jehan 2019-08-22 23:41:36 +02:00
parent 5e87258067
commit 858ab51f44
3 changed files with 77 additions and 79 deletions

View File

@ -706,8 +706,6 @@ file_gegl_LDADD = \
$(INTLLIBS) \ $(INTLLIBS) \
$(file_gegl_RC) $(file_gegl_RC)
file_gif_load_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API
file_gif_load_SOURCES = \ file_gif_load_SOURCES = \
file-gif-load.c file-gif-load.c

View File

@ -117,7 +117,7 @@ static GimpValueArray * gif_load_thumb (GimpProcedure *procedure,
const GimpValueArray *args, const GimpValueArray *args,
gpointer run_data); gpointer run_data);
static gint32 load_image (const gchar *filename, static GimpImage * load_image (const gchar *filename,
gboolean thumbnail, gboolean thumbnail,
GError **error); GError **error);
@ -224,7 +224,7 @@ gif_load (GimpProcedure *procedure,
{ {
GimpValueArray *return_vals; GimpValueArray *return_vals;
gchar *filename; gchar *filename;
gint32 image_id; GimpImage *image;
GError *error = NULL; GError *error = NULL;
INIT_I18N (); INIT_I18N ();
@ -232,11 +232,11 @@ gif_load (GimpProcedure *procedure,
filename = g_file_get_path (file); filename = g_file_get_path (file);
image_id = load_image (filename, FALSE, &error); image = load_image (filename, FALSE, &error);
g_free (filename); g_free (filename);
if (image_id < 1) if (! image)
return gimp_procedure_new_return_values (procedure, return gimp_procedure_new_return_values (procedure,
GIMP_PDB_EXECUTION_ERROR, GIMP_PDB_EXECUTION_ERROR,
error); error);
@ -256,14 +256,14 @@ gif_load (GimpProcedure *procedure,
#endif #endif
if (! promote_to_rgb) if (! promote_to_rgb)
gimp_image_set_colormap (image_id, gimp_image_set_colormap (image,
gimp_cmap, highest_used_index + 1); gimp_cmap, highest_used_index + 1);
return_vals = gimp_procedure_new_return_values (procedure, return_vals = gimp_procedure_new_return_values (procedure,
GIMP_PDB_SUCCESS, GIMP_PDB_SUCCESS,
NULL); NULL);
GIMP_VALUES_SET_IMAGE (return_vals, 1, image_id); GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
return return_vals; return return_vals;
} }
@ -276,30 +276,29 @@ gif_load_thumb (GimpProcedure *procedure,
gpointer run_data) gpointer run_data)
{ {
GimpValueArray *return_vals; GimpValueArray *return_vals;
gint32 image_id; GimpImage *image;
GError *error = NULL; GError *error = NULL;
INIT_I18N (); INIT_I18N ();
gegl_init (NULL, NULL); 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, return gimp_procedure_new_return_values (procedure,
GIMP_PDB_EXECUTION_ERROR, GIMP_PDB_EXECUTION_ERROR,
error); error);
if (! promote_to_rgb) if (! promote_to_rgb)
gimp_image_set_colormap (image_id, gimp_image_set_colormap (image, gimp_cmap, highest_used_index + 1);
gimp_cmap, highest_used_index + 1);
return_vals = gimp_procedure_new_return_values (procedure, return_vals = gimp_procedure_new_return_values (procedure,
GIMP_PDB_SUCCESS, GIMP_PDB_SUCCESS,
NULL); 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, gimp_image_width (image_id)); GIMP_VALUES_SET_INT (return_vals, 2, gimp_image_width (image));
GIMP_VALUES_SET_INT (return_vals, 3, gimp_image_height (image_id)); GIMP_VALUES_SET_INT (return_vals, 3, gimp_image_height (image));
gimp_value_array_truncate (return_vals, 4); gimp_value_array_truncate (return_vals, 4);
@ -377,25 +376,25 @@ static gboolean ReadImage (FILE *fd,
guint toppos, guint toppos,
guint screenwidth, guint screenwidth,
guint screenheight, guint screenheight,
gint32 *image_ID); GimpImage **image);
static gint32 static GimpImage *
load_image (const gchar *filename, load_image (const gchar *filename,
gboolean thumbnail, gboolean thumbnail,
GError **error) GError **error)
{ {
FILE *fd; FILE *fd;
guchar buf[16]; guchar buf[16];
guchar c; guchar c;
CMap localColorMap; CMap localColorMap;
gint grayScale; gint grayScale;
gboolean useGlobalColormap; gboolean useGlobalColormap;
gint bitPixel; gint bitPixel;
gint imageCount = 0; gint imageCount = 0;
gchar version[4]; gchar version[4];
gint32 image_ID = -1; GimpImage *image = NULL;
gboolean status; gboolean status;
gimp_progress_init_printf (_("Opening '%s'"), gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename)); 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), g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for reading: %s"), _("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno)); gimp_filename_to_utf8 (filename), g_strerror (errno));
return -1; return NULL;
} }
if (! ReadOK (fd, buf, 6)) if (! ReadOK (fd, buf, 6))
{ {
g_message ("Error reading magic number"); g_message ("Error reading magic number");
fclose (fd); fclose (fd);
return -1; return NULL;
} }
if (strncmp ((gchar *) buf, "GIF", 3) != 0) 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, g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
"%s", _("This is not a GIF file")); "%s", _("This is not a GIF file"));
fclose (fd); fclose (fd);
return -1; return NULL;
} }
g_strlcpy (version, (gchar *) buf + 3, 4); 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'"); g_message ("Bad version number, not '87a' or '89a'");
fclose (fd); fclose (fd);
return -1; return NULL;
} }
if (! ReadOK (fd, buf, 7)) if (! ReadOK (fd, buf, 7))
{ {
g_message ("Failed to read screen descriptor"); g_message ("Failed to read screen descriptor");
fclose (fd); fclose (fd);
return -1; return NULL;
} }
GifScreen.Width = LM_to_uint (buf[0], buf[1]); GifScreen.Width = LM_to_uint (buf[0], buf[1]);
@ -456,7 +455,7 @@ load_image (const gchar *filename,
{ {
g_message ("Error reading global colormap"); g_message ("Error reading global colormap");
fclose (fd); fclose (fd);
return -1; return NULL;
} }
} }
@ -474,14 +473,14 @@ load_image (const gchar *filename,
{ {
g_message ("EOF / read error on image data"); g_message ("EOF / read error on image data");
fclose (fd); 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 == ';') if (c == ';')
{ {
/* GIF terminator */ /* GIF terminator */
fclose (fd); fclose (fd);
return image_ID; return image;
} }
if (c == '!') if (c == '!')
@ -491,7 +490,7 @@ load_image (const gchar *filename,
{ {
g_message ("EOF / read error on extension function code"); g_message ("EOF / read error on extension function code");
fclose (fd); 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); DoExtension (fd, c);
@ -511,7 +510,7 @@ load_image (const gchar *filename,
{ {
g_message ("Couldn't read left/top/width/height"); g_message ("Couldn't read left/top/width/height");
fclose (fd); 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); useGlobalColormap = !BitSet (buf[8], LOCALCOLORMAP);
@ -524,7 +523,7 @@ load_image (const gchar *filename,
{ {
g_message ("Error reading local colormap"); g_message ("Error reading local colormap");
fclose (fd); 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]), 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]), (guint) LM_to_uint (buf[2], buf[3]),
GifScreen.Width, GifScreen.Width,
GifScreen.Height, GifScreen.Height,
&image_ID); &image);
} }
else else
{ {
@ -549,7 +548,7 @@ load_image (const gchar *filename,
(guint) LM_to_uint (buf[2], buf[3]), (guint) LM_to_uint (buf[2], buf[3]),
GifScreen.Width, GifScreen.Width,
GifScreen.Height, GifScreen.Height,
&image_ID); &image);
} }
if (!status) if (!status)
@ -560,7 +559,7 @@ load_image (const gchar *filename,
if (comment_parasite != NULL) if (comment_parasite != NULL)
{ {
if (! thumbnail) if (! thumbnail)
gimp_image_attach_parasite (image_ID, comment_parasite); gimp_image_attach_parasite (image, comment_parasite);
gimp_parasite_free (comment_parasite); gimp_parasite_free (comment_parasite);
comment_parasite = NULL; comment_parasite = NULL;
@ -573,7 +572,7 @@ load_image (const gchar *filename,
fclose (fd); fclose (fd);
return image_ID; return image;
} }
static gboolean static gboolean
@ -971,11 +970,11 @@ ReadImage (FILE *fd,
guint toppos, guint toppos,
guint screenwidth, guint screenwidth,
guint screenheight, guint screenheight,
gint32 *image_ID) GimpImage **image)
{ {
static gint frame_number = 1; static gint frame_number = 1;
gint32 layer_ID; GimpLayer *layer;
GeglBuffer *buffer; GeglBuffer *buffer;
guchar *dest, *temp; guchar *dest, *temp;
guchar c; guchar c;
@ -992,7 +991,7 @@ ReadImage (FILE *fd,
if (len < 1 || height < 1) if (len < 1 || height < 1)
{ {
g_message ("Bogus frame dimensions"); g_message ("Bogus frame dimensions");
*image_ID = -1; *image = NULL;
return FALSE; return FALSE;
} }
@ -1002,14 +1001,14 @@ ReadImage (FILE *fd,
if (! ReadOK (fd, &c, 1)) if (! ReadOK (fd, &c, 1))
{ {
g_message ("EOF / read error on image data"); g_message ("EOF / read error on image data");
*image_ID = -1; *image = NULL;
return FALSE; return FALSE;
} }
if (LZWReadByte (fd, TRUE, c) < 0) if (LZWReadByte (fd, TRUE, c) < 0)
{ {
g_message ("Error while reading"); g_message ("Error while reading");
*image_ID = -1; *image = NULL;
return FALSE; return FALSE;
} }
@ -1022,8 +1021,8 @@ ReadImage (FILE *fd,
if (screenheight == 0) if (screenheight == 0)
screenheight = height; screenheight = height;
*image_ID = gimp_image_new (screenwidth, screenheight, GIMP_INDEXED); *image = gimp_image_new (screenwidth, screenheight, GIMP_INDEXED);
gimp_image_set_filename (*image_ID, filename); gimp_image_set_filename (*image, filename);
for (i = 0, j = 0; i < ncols; i++) 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]; 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) if (Gif89.delayTime < 0)
framename = g_strdup (_("Background")); framename = g_strdup (_("Background"));
@ -1044,19 +1043,19 @@ ReadImage (FILE *fd,
if (Gif89.transparent == -1) if (Gif89.transparent == -1)
{ {
layer_ID = gimp_layer_new (*image_ID, framename, layer = gimp_layer_new (*image, framename,
len, height, len, height,
GIMP_INDEXED_IMAGE, GIMP_INDEXED_IMAGE,
100, 100,
gimp_image_get_default_new_layer_mode (*image_ID)); gimp_image_get_default_new_layer_mode (*image));
} }
else else
{ {
layer_ID = gimp_layer_new (*image_ID, framename, layer = gimp_layer_new (*image, framename,
len, height, len, height,
GIMP_INDEXEDA_IMAGE, GIMP_INDEXEDA_IMAGE,
100, 100,
gimp_image_get_default_new_layer_mode (*image_ID)); gimp_image_get_default_new_layer_mode (*image));
alpha_frame=TRUE; alpha_frame=TRUE;
} }
@ -1085,7 +1084,7 @@ ReadImage (FILE *fd,
#ifdef GIFDEBUG #ifdef GIFDEBUG
g_print ("GIF: Promoting image to RGB...\n"); g_print ("GIF: Promoting image to RGB...\n");
#endif #endif
gimp_image_convert_rgb (*image_ID); gimp_image_convert_rgb (*image);
break; break;
} }
@ -1137,31 +1136,32 @@ ReadImage (FILE *fd,
} }
previous_disposal = Gif89.disposal; previous_disposal = Gif89.disposal;
layer_ID = gimp_layer_new (*image_ID, framename, layer = gimp_layer_new (*image, framename,
len, height, len, height,
promote_to_rgb ? promote_to_rgb ?
GIMP_RGBA_IMAGE : GIMP_INDEXEDA_IMAGE, GIMP_RGBA_IMAGE : GIMP_INDEXEDA_IMAGE,
100, 100,
gimp_image_get_default_new_layer_mode (*image_ID)); gimp_image_get_default_new_layer_mode (*image));
alpha_frame = TRUE; alpha_frame = TRUE;
g_free (framename); g_free (framename);
} }
frame_number++; frame_number++;
gimp_image_insert_layer (*image_ID, layer_ID, -1, 0); gimp_image_insert_layer (*image, layer, NULL, 0);
gimp_item_transform_translate (layer_ID, (gint) leftpos, (gint) toppos); gimp_item_transform_translate (GIMP_ITEM (layer), (gint) leftpos, (gint) toppos);
cur_progress = 0; cur_progress = 0;
max_progress = height; max_progress = height;
if (len > (G_MAXSIZE / height / (alpha_frame ? (promote_to_rgb ? 4 : 2) : 1))) 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.", g_message ("'%s' has a larger image size than GIMP can handle.",
gimp_filename_to_utf8 (filename)); gimp_filename_to_utf8 (filename));
*image_ID = -1; gimp_image_delete (*image);
return FALSE; *image = NULL;
} return FALSE;
}
if (alpha_frame) if (alpha_frame)
dest = (guchar *) g_malloc ((gsize)len * (gsize)height * (promote_to_rgb ? 4 : 2)); dest = (guchar *) g_malloc ((gsize)len * (gsize)height * (promote_to_rgb ? 4 : 2));
@ -1277,7 +1277,7 @@ ReadImage (FILE *fd,
} }
fini: 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, gegl_buffer_set (buffer, GEGL_RECTANGLE (0, 0, len, height), 0,
NULL, dest, GEGL_AUTO_ROWSTRIDE); NULL, dest, GEGL_AUTO_ROWSTRIDE);

View File

@ -24,7 +24,7 @@
'file-dicom' => { ui => 1, gegl => 1, cflags => '-fno-strict-aliasing', old_api => 1 }, 'file-dicom' => { ui => 1, gegl => 1, cflags => '-fno-strict-aliasing', old_api => 1 },
'file-gbr' => { ui => 1, gegl => 1 }, 'file-gbr' => { ui => 1, gegl => 1 },
'file-gegl' => { ui => 1, gegl => 1, old_api => 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-gif-save' => { ui => 1, gegl => 1, old_api => 1 },
'file-gih' => { ui => 1, gegl => 1 }, 'file-gih' => { ui => 1, gegl => 1 },
'file-glob' => {}, 'file-glob' => {},