plug-ins: port file-sgi to GimpImage/GimpDrawable.

This commit is contained in:
Jehan 2019-08-16 00:31:10 +02:00
parent 08849a584c
commit 3d4bf19bae
2 changed files with 31 additions and 32 deletions

View File

@ -29,7 +29,6 @@ file_sgi_SOURCES = \
sgi-lib.h sgi-lib.h
AM_CPPFLAGS = \ AM_CPPFLAGS = \
-DGIMP_DEPRECATED_REPLACE_NEW_API \
-I$(top_srcdir) \ -I$(top_srcdir) \
$(GTK_CFLAGS) \ $(GTK_CFLAGS) \
$(GEGL_CFLAGS) \ $(GEGL_CFLAGS) \

View File

@ -77,17 +77,17 @@ static GimpValueArray * sgi_load (GimpProcedure *procedure,
gpointer run_data); gpointer run_data);
static GimpValueArray * sgi_save (GimpProcedure *procedure, static GimpValueArray * sgi_save (GimpProcedure *procedure,
GimpRunMode run_mode, GimpRunMode run_mode,
gint32 image_id, GimpImage *image,
gint32 drawable_id, GimpDrawable *drawable,
GFile *file, GFile *file,
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,
GError **error); GError **error);
static gint save_image (const gchar *filename, static gint save_image (const gchar *filename,
gint32 image_ID, GimpImage *image,
gint32 drawable_ID, GimpDrawable *drawable,
GError **error); GError **error);
static gboolean save_dialog (void); static gboolean save_dialog (void);
@ -200,7 +200,7 @@ sgi_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 ();
@ -208,11 +208,11 @@ sgi_load (GimpProcedure *procedure,
filename = g_file_get_path (file); filename = g_file_get_path (file);
image_id = load_image (filename, &error); image = load_image (filename, &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);
@ -221,7 +221,7 @@ sgi_load (GimpProcedure *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;
} }
@ -229,8 +229,8 @@ sgi_load (GimpProcedure *procedure,
static GimpValueArray * static GimpValueArray *
sgi_save (GimpProcedure *procedure, sgi_save (GimpProcedure *procedure,
GimpRunMode run_mode, GimpRunMode run_mode,
gint32 image_id, GimpImage *image,
gint32 drawable_id, GimpDrawable *drawable,
GFile *file, GFile *file,
const GimpValueArray *args, const GimpValueArray *args,
gpointer run_data) gpointer run_data)
@ -248,7 +248,7 @@ sgi_save (GimpProcedure *procedure,
case GIMP_RUN_WITH_LAST_VALS: case GIMP_RUN_WITH_LAST_VALS:
gimp_ui_init (PLUG_IN_BINARY, FALSE); gimp_ui_init (PLUG_IN_BINARY, FALSE);
export = gimp_export_image (&image_id, &drawable_id, "SGI", export = gimp_export_image (&image, &drawable, "SGI",
GIMP_EXPORT_CAN_HANDLE_RGB | GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_GRAY | GIMP_EXPORT_CAN_HANDLE_GRAY |
GIMP_EXPORT_CAN_HANDLE_INDEXED | GIMP_EXPORT_CAN_HANDLE_INDEXED |
@ -289,7 +289,7 @@ sgi_save (GimpProcedure *procedure,
{ {
gchar *filename = g_file_get_path (file); gchar *filename = g_file_get_path (file);
if (save_image (filename, image_id, drawable_id, if (save_image (filename, image, drawable,
&error)) &error))
{ {
gimp_set_data (SAVE_PROC, &compression, sizeof (compression)); gimp_set_data (SAVE_PROC, &compression, sizeof (compression));
@ -303,12 +303,12 @@ sgi_save (GimpProcedure *procedure,
} }
if (export == GIMP_EXPORT_EXPORT) if (export == GIMP_EXPORT_EXPORT)
gimp_image_delete (image_id); gimp_image_delete (image);
return gimp_procedure_new_return_values (procedure, status, error); return gimp_procedure_new_return_values (procedure, status, error);
} }
static gint32 static GimpImage *
load_image (const gchar *filename, load_image (const gchar *filename,
GError **error) GError **error)
{ {
@ -321,8 +321,8 @@ load_image (const gchar *filename,
count, /* Count of rows to put in image */ count, /* Count of rows to put in image */
bytes; /* Number of channels to use */ bytes; /* Number of channels to use */
sgi_t *sgip; /* File pointer */ sgi_t *sgip; /* File pointer */
gint32 image, /* Image */ GimpImage *image; /* Image */
layer; /* Layer */ GimpLayer *layer; /* Layer */
GeglBuffer *buffer; /* Buffer for layer */ GeglBuffer *buffer; /* Buffer for layer */
guchar **pixels, /* Pixel rows */ guchar **pixels, /* Pixel rows */
*pptr; /* Current pixel */ *pptr; /* Current pixel */
@ -341,7 +341,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,
_("Could not open '%s' for reading."), _("Could not open '%s' for reading."),
gimp_filename_to_utf8 (filename)); gimp_filename_to_utf8 (filename));
return -1; return NULL;
}; };
/* /*
@ -355,21 +355,21 @@ 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,
_("Invalid width: %hu"), sgip->xsize); _("Invalid width: %hu"), sgip->xsize);
return -1; return NULL;
} }
if (sgip->ysize == 0 /*|| sgip->ysize > GIMP_MAX_IMAGE_SIZE*/) if (sgip->ysize == 0 /*|| sgip->ysize > GIMP_MAX_IMAGE_SIZE*/)
{ {
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Invalid height: %hu"), sgip->ysize); _("Invalid height: %hu"), sgip->ysize);
return -1; return NULL;
} }
if (sgip->zsize == 0 /*|| sgip->zsize > GIMP_MAX_IMAGE_SIZE*/) if (sgip->zsize == 0 /*|| sgip->zsize > GIMP_MAX_IMAGE_SIZE*/)
{ {
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Invalid number of channels: %hu"), sgip->zsize); _("Invalid number of channels: %hu"), sgip->zsize);
return -1; return NULL;
} }
bytes = sgip->zsize; bytes = sgip->zsize;
@ -404,12 +404,12 @@ load_image (const gchar *filename,
} }
image = gimp_image_new (sgip->xsize, sgip->ysize, image_type); image = gimp_image_new (sgip->xsize, sgip->ysize, image_type);
if (image == -1) if (! image)
{ {
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
"Could not allocate new image: %s", "Could not allocate new image: %s",
gimp_pdb_get_last_error (gimp_get_pdb ())); gimp_pdb_get_last_error (gimp_get_pdb ()));
return -1; return NULL;
} }
gimp_image_set_filename (image, filename); gimp_image_set_filename (image, filename);
@ -422,13 +422,13 @@ load_image (const gchar *filename,
layer_type, layer_type,
100, 100,
gimp_image_get_default_new_layer_mode (image)); gimp_image_get_default_new_layer_mode (image));
gimp_image_insert_layer (image, layer, -1, 0); gimp_image_insert_layer (image, layer, NULL, 0);
/* /*
* Get the drawable and set the pixel region for our load... * Get the drawable and set the pixel region for our load...
*/ */
buffer = gimp_drawable_get_buffer (layer); buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
/* /*
* Temporary buffers... * Temporary buffers...
@ -521,8 +521,8 @@ load_image (const gchar *filename,
static gint static gint
save_image (const gchar *filename, save_image (const gchar *filename,
gint32 image_ID, GimpImage *image,
gint32 drawable_ID, GimpDrawable *drawable,
GError **error) GError **error)
{ {
gint i, j, /* Looping var */ gint i, j, /* Looping var */
@ -544,12 +544,12 @@ save_image (const gchar *filename,
* Get the drawable for the current image... * Get the drawable for the current image...
*/ */
width = gimp_drawable_width (drawable_ID); width = gimp_drawable_width (drawable);
height = gimp_drawable_height (drawable_ID); height = gimp_drawable_height (drawable);
buffer = gimp_drawable_get_buffer (drawable_ID); buffer = gimp_drawable_get_buffer (drawable);
switch (gimp_drawable_type (drawable_ID)) switch (gimp_drawable_type (drawable))
{ {
case GIMP_GRAY_IMAGE: case GIMP_GRAY_IMAGE:
zsize = 1; zsize = 1;