plug-ins/common/file-raw.c plug-ins/common/file-tga.c
2008-08-18 Sven Neumann <sven@gimp.org> * plug-ins/common/file-raw.c * plug-ins/common/file-tga.c * plug-ins/common/file-tiff-load.c * plug-ins/common/file-tiff-save.c: pass error messages with the return values instead of calling gimp_message(). svn path=/trunk/; revision=26640
This commit is contained in:

committed by
Sven Neumann

parent
edabd739d4
commit
fc059e310d
@ -1,3 +1,11 @@
|
||||
2008-08-18 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* plug-ins/common/file-raw.c
|
||||
* plug-ins/common/file-tga.c
|
||||
* plug-ins/common/file-tiff-load.c
|
||||
* plug-ins/common/file-tiff-save.c: pass error messages with the
|
||||
return values instead of calling gimp_message().
|
||||
|
||||
2008-08-18 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* plug-ins/common/file-pnm.c
|
||||
|
@ -113,10 +113,13 @@ static int mmap_read (gint fd,
|
||||
gint32 len,
|
||||
gint32 pos,
|
||||
gint rowstride);
|
||||
static gint32 load_image (const gchar *filename);
|
||||
|
||||
static gint32 load_image (const gchar *filename,
|
||||
GError **error);
|
||||
static GimpPDBStatusType save_image (const gchar *filename,
|
||||
gint32 image_id,
|
||||
gint32 drawable_id);
|
||||
gint32 drawable_id,
|
||||
GError **error);
|
||||
|
||||
/* gui functions */
|
||||
static void preview_update (GimpPreviewArea *preview);
|
||||
@ -207,11 +210,12 @@ run (const gchar *name,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals)
|
||||
{
|
||||
static GimpParam values[2];
|
||||
GimpRunMode run_mode;
|
||||
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
||||
gint32 image_id;
|
||||
gint32 drawable_id;
|
||||
static GimpParam values[2];
|
||||
GimpRunMode run_mode;
|
||||
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
||||
GError *error = NULL;
|
||||
gint32 image_id;
|
||||
gint32 drawable_id;
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
|
||||
@ -240,9 +244,12 @@ run (const gchar *name,
|
||||
|
||||
if (preview_fd < 0)
|
||||
{
|
||||
g_message (_("Could not open '%s' for reading: %s"),
|
||||
gimp_filename_to_utf8 (param[1].data.d_string),
|
||||
g_strerror (errno));
|
||||
g_set_error (&error,
|
||||
G_FILE_ERROR, g_file_error_from_errno (errno),
|
||||
_("Could not open '%s' for reading: %s"),
|
||||
gimp_filename_to_utf8 (param[1].data.d_string),
|
||||
g_strerror (errno));
|
||||
|
||||
status = GIMP_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
else
|
||||
@ -265,7 +272,7 @@ run (const gchar *name,
|
||||
/* we are okay, and the user clicked OK in the load dialog */
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
image_id = load_image (param[1].data.d_string);
|
||||
image_id = load_image (param[1].data.d_string, &error);
|
||||
|
||||
if (image_id != -1)
|
||||
{
|
||||
@ -310,12 +317,21 @@ run (const gchar *name,
|
||||
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
status = save_image (param[3].data.d_string, image_id, drawable_id);
|
||||
status = save_image (param[3].data.d_string, image_id, drawable_id,
|
||||
&error);
|
||||
}
|
||||
}
|
||||
|
||||
values[0].data.d_status = status;
|
||||
g_free (runtime);
|
||||
|
||||
if (status != GIMP_PDB_SUCCESS && error)
|
||||
{
|
||||
*nreturn_vals = 2;
|
||||
values[1].type = GIMP_PDB_STRING;
|
||||
values[1].data.d_string = error->message;
|
||||
}
|
||||
|
||||
values[0].data.d_status = status;
|
||||
}
|
||||
|
||||
|
||||
@ -487,7 +503,8 @@ raw_load_palette (RawGimpData *data,
|
||||
static GimpPDBStatusType
|
||||
save_image (const gchar *filename,
|
||||
gint32 image_id,
|
||||
gint32 drawable_id)
|
||||
gint32 drawable_id,
|
||||
GError **error)
|
||||
{
|
||||
GimpDrawable *drawable;
|
||||
GimpPixelRgn pixel_rgn;
|
||||
@ -525,8 +542,9 @@ save_image (const gchar *filename,
|
||||
|
||||
if (! fp)
|
||||
{
|
||||
g_message (_("Could not open '%s' for writing: %s"),
|
||||
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
||||
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
||||
_("Could not open '%s' for writing: %s"),
|
||||
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
||||
return GIMP_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
|
||||
@ -552,8 +570,9 @@ save_image (const gchar *filename,
|
||||
|
||||
if (! fp)
|
||||
{
|
||||
g_message (_("Could not open '%s' for writing: %s"),
|
||||
gimp_filename_to_utf8 (newfile), g_strerror (errno));
|
||||
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
||||
_("Could not open '%s' for writing: %s"),
|
||||
gimp_filename_to_utf8 (newfile), g_strerror (errno));
|
||||
return GIMP_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
|
||||
@ -628,7 +647,8 @@ save_image (const gchar *filename,
|
||||
}
|
||||
|
||||
static gint32
|
||||
load_image (const gchar *filename)
|
||||
load_image (const gchar *filename,
|
||||
GError **error)
|
||||
{
|
||||
RawGimpData *data;
|
||||
gint32 layer_id = -1;
|
||||
@ -642,8 +662,9 @@ load_image (const gchar *filename)
|
||||
data->fp = g_fopen (filename, "rb");
|
||||
if (! data->fp)
|
||||
{
|
||||
g_message (_("Could not open '%s' for reading: %s"),
|
||||
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -185,10 +185,12 @@ static void run (const gchar *name,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
|
||||
static gint32 load_image (const gchar *filename);
|
||||
static gint32 load_image (const gchar *filename,
|
||||
GError **error);
|
||||
static gint save_image (const gchar *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID);
|
||||
gint32 drawable_ID,
|
||||
GError **error);
|
||||
|
||||
static gboolean save_dialog (void);
|
||||
|
||||
@ -276,12 +278,13 @@ run (const gchar *name,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals)
|
||||
{
|
||||
static GimpParam values[2];
|
||||
GimpRunMode run_mode;
|
||||
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
||||
gint32 image_ID;
|
||||
gint32 drawable_ID;
|
||||
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
||||
static GimpParam values[2];
|
||||
GimpRunMode run_mode;
|
||||
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
||||
gint32 image_ID;
|
||||
gint32 drawable_ID;
|
||||
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
||||
GError *error = NULL;
|
||||
|
||||
#ifdef PROFILE
|
||||
struct tms tbuf1, tbuf2;
|
||||
@ -303,7 +306,7 @@ run (const gchar *name,
|
||||
times (&tbuf1);
|
||||
#endif
|
||||
|
||||
image_ID = load_image (param[1].data.d_string);
|
||||
image_ID = load_image (param[1].data.d_string, &error);
|
||||
|
||||
if (image_ID != -1)
|
||||
{
|
||||
@ -381,7 +384,8 @@ run (const gchar *name,
|
||||
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
if (save_image (param[3].data.d_string, image_ID, drawable_ID))
|
||||
if (save_image (param[3].data.d_string, image_ID, drawable_ID,
|
||||
&error))
|
||||
{
|
||||
/* Store psvals data */
|
||||
gimp_set_data (SAVE_PROC, &tsvals, sizeof (tsvals));
|
||||
@ -400,6 +404,13 @@ run (const gchar *name,
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
}
|
||||
|
||||
if (status != GIMP_PDB_SUCCESS && error)
|
||||
{
|
||||
*nreturn_vals = 2;
|
||||
values[1].type = GIMP_PDB_STRING;
|
||||
values[1].data.d_string = error->message;
|
||||
}
|
||||
|
||||
values[0].data.d_status = status;
|
||||
|
||||
#ifdef PROFILE
|
||||
@ -411,7 +422,8 @@ run (const gchar *name,
|
||||
}
|
||||
|
||||
static gint32
|
||||
load_image (const gchar *filename)
|
||||
load_image (const gchar *filename,
|
||||
GError **error)
|
||||
{
|
||||
FILE *fp;
|
||||
tga_info info;
|
||||
@ -423,10 +435,12 @@ load_image (const gchar *filename)
|
||||
gint32 image_ID = -1;
|
||||
|
||||
fp = g_fopen (filename, "rb");
|
||||
if (!fp)
|
||||
|
||||
if (! fp)
|
||||
{
|
||||
g_message (_("Could not open '%s' for reading: %s"),
|
||||
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1120,9 +1134,10 @@ ReadImage (FILE *fp,
|
||||
|
||||
|
||||
static gint
|
||||
save_image (const gchar *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID)
|
||||
save_image (const gchar *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID,
|
||||
GError **error)
|
||||
{
|
||||
GimpPixelRgn pixel_rgn;
|
||||
GimpDrawable *drawable;
|
||||
@ -1151,8 +1166,9 @@ save_image (const gchar *filename,
|
||||
|
||||
if ((fp = g_fopen (filename, "wb")) == NULL)
|
||||
{
|
||||
g_message (_("Could not open '%s' for writing: %s"),
|
||||
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
||||
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
||||
_("Could not open '%s' for writing: %s"),
|
||||
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -107,12 +107,13 @@ static void run (const gchar *name,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
|
||||
static gboolean load_dialog (TIFF *tif,
|
||||
TiffSelectedPages *pages);
|
||||
static gboolean load_dialog (TIFF *tif,
|
||||
TiffSelectedPages *pages);
|
||||
|
||||
static gint32 load_image (const gchar *filename,
|
||||
TIFF *tif,
|
||||
TiffSelectedPages *pages);
|
||||
static gint32 load_image (const gchar *filename,
|
||||
TIFF *tif,
|
||||
TiffSelectedPages *pages,
|
||||
GError **error);
|
||||
|
||||
static void load_rgba (TIFF *tif,
|
||||
channel_data *channel);
|
||||
@ -259,6 +260,7 @@ run (const gchar *name,
|
||||
{
|
||||
static GimpParam values[2];
|
||||
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
||||
GError *error = NULL;
|
||||
gint32 image;
|
||||
TiffSelectedPages pages;
|
||||
|
||||
@ -285,8 +287,9 @@ run (const gchar *name,
|
||||
|
||||
if (fd == -1)
|
||||
{
|
||||
g_message (_("Could not open '%s' for reading: %s"),
|
||||
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
||||
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));
|
||||
status = GIMP_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
else
|
||||
@ -337,7 +340,8 @@ run (const gchar *name,
|
||||
{
|
||||
gimp_set_data (LOAD_PROC, &target, sizeof (target));
|
||||
|
||||
image = load_image (param[1].data.d_string, tif, &pages);
|
||||
image = load_image (param[1].data.d_string, tif, &pages,
|
||||
&error);
|
||||
|
||||
g_free (pages.pages);
|
||||
|
||||
@ -372,6 +376,13 @@ run (const gchar *name,
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
}
|
||||
|
||||
if (status != GIMP_PDB_SUCCESS && error)
|
||||
{
|
||||
*nreturn_vals = 2;
|
||||
values[1].type = GIMP_PDB_STRING;
|
||||
values[1].data.d_string = error->message;
|
||||
}
|
||||
|
||||
values[0].data.d_status = status;
|
||||
}
|
||||
|
||||
@ -535,9 +546,10 @@ load_dialog (TIFF *tif,
|
||||
}
|
||||
|
||||
static gint32
|
||||
load_image (const gchar *filename,
|
||||
TIFF *tif,
|
||||
TiffSelectedPages *pages)
|
||||
load_image (const gchar *filename,
|
||||
TIFF *tif,
|
||||
TiffSelectedPages *pages,
|
||||
GError **error)
|
||||
{
|
||||
gushort bps, spp, photomet;
|
||||
guint16 orientation;
|
||||
@ -744,7 +756,8 @@ load_image (const gchar *filename,
|
||||
{
|
||||
if ((image = gimp_image_new (cols, rows, image_type)) == -1)
|
||||
{
|
||||
g_message ("Could not create a new image");
|
||||
g_message ("Could not create a new image: %s",
|
||||
gimp_get_pdb_error ());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,8 @@ static gboolean save_paths (TIFF *tif,
|
||||
static gboolean save_image (const gchar *filename,
|
||||
gint32 image,
|
||||
gint32 drawable,
|
||||
gint32 orig_image);
|
||||
gint32 orig_image,
|
||||
GError **error);
|
||||
|
||||
static gboolean save_dialog (gboolean has_alpha,
|
||||
gboolean is_monochrome);
|
||||
@ -218,6 +219,7 @@ run (const gchar *name,
|
||||
gint32 drawable;
|
||||
gint32 orig_image;
|
||||
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
||||
GError *error = NULL;
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
|
||||
@ -341,7 +343,8 @@ run (const gchar *name,
|
||||
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
if (save_image (param[3].data.d_string, image, drawable, orig_image))
|
||||
if (save_image (param[3].data.d_string, image, drawable, orig_image,
|
||||
&error))
|
||||
{
|
||||
/* Store mvals data */
|
||||
gimp_set_data (SAVE_PROC, &tsvals, sizeof (TiffSaveVals));
|
||||
@ -360,6 +363,13 @@ run (const gchar *name,
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
}
|
||||
|
||||
if (status != GIMP_PDB_SUCCESS && error)
|
||||
{
|
||||
*nreturn_vals = 2;
|
||||
values[1].type = GIMP_PDB_STRING;
|
||||
values[1].data.d_string = error->message;
|
||||
}
|
||||
|
||||
values[0].data.d_status = status;
|
||||
}
|
||||
|
||||
@ -617,10 +627,11 @@ save_paths (TIFF *tif,
|
||||
*/
|
||||
|
||||
static gboolean
|
||||
save_image (const gchar *filename,
|
||||
gint32 image,
|
||||
gint32 layer,
|
||||
gint32 orig_image) /* the export function might have created a duplicate */
|
||||
save_image (const gchar *filename,
|
||||
gint32 image,
|
||||
gint32 layer,
|
||||
gint32 orig_image, /* the export function might have */
|
||||
GError **error) /* created a duplicate */
|
||||
{
|
||||
TIFF *tif;
|
||||
gushort red[256];
|
||||
@ -668,8 +679,9 @@ save_image (const gchar *filename,
|
||||
|
||||
if (fd == -1)
|
||||
{
|
||||
g_message (_("Could not open '%s' for writing: %s"),
|
||||
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
||||
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
||||
_("Could not open '%s' for writing: %s"),
|
||||
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -769,7 +781,9 @@ save_image (const gchar *filename,
|
||||
break;
|
||||
|
||||
case GIMP_INDEXEDA_IMAGE:
|
||||
g_message ("TIFF save cannot handle indexed images with alpha channel.");
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||
"%s",
|
||||
"TIFF save cannot handle indexed images with alpha channel.");
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user