Commit 5e347ed2 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

plug-ins/file-psd/psd.c plug-ins/file-psd/psd-load.[ch]

2008-08-20  Sven Neumann  <sven@gimp.org>

	* plug-ins/file-psd/psd.c
	* plug-ins/file-psd/psd-load.[ch]
	* plug-ins/file-psd/psd-save.c 
	* plug-ins/file-psd/psd-thumb-load.[ch]: pass error messages 
with
	the return values instead of calling g_message().


svn path=/trunk/; revision=26671
parent 50849396
2008-08-20 Sven Neumann <sven@gimp.org>
* plug-ins/file-psd/psd.c
* plug-ins/file-psd/psd-load.[ch]
* plug-ins/file-psd/psd-save.c
* plug-ins/file-psd/psd-thumb-load.[ch]: pass error messages with
the return values instead of calling g_message().
2008-08-20 Sven Neumann <sven@gimp.org>
* plug-ins/file-jpeg/jpeg.[ch]
......
......@@ -105,7 +105,8 @@ static void convert_1_bit (const gchar *src,
/* Main file load function */
gint32
load_image (const gchar *filename)
load_image (const gchar *filename,
GError **load_error)
{
FILE *f;
struct stat st;
......@@ -122,8 +123,9 @@ load_image (const gchar *filename)
f = g_fopen (filename, "rb");
if (f == NULL)
{
g_message (_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
g_set_error (load_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;
}
......@@ -205,7 +207,8 @@ load_image (const gchar *filename)
load_error:
if (error)
{
g_message (_("Error loading PSD file:\n\n%s"), error->message);
g_set_error (load_error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Error loading PSD file: %s"), error->message);
g_error_free (error);
}
......
......@@ -23,7 +23,8 @@
#define __PSD_LOAD_H__
gint32 load_image (const gchar *filename);
gint32 load_image (const gchar *filename,
GError **error);
#endif /* __PSD_LOAD_H__ */
......@@ -156,7 +156,8 @@ static void save_layer_and_mask (FILE *fd,
static void save_data (FILE *fd,
gint32 image_id);
static gint save_image (const gchar *filename,
gint32 image_id);
gint32 image_id,
GError **error);
static void xfwrite (FILE *fd,
gconstpointer buf,
glong len,
......@@ -237,8 +238,9 @@ run (const gchar *name,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[2];
GimpRunMode run_mode;
static GimpParam values[2];
GimpRunMode run_mode;
GError *error = NULL;
run_mode = param[0].data.d_int32;
......@@ -284,10 +286,21 @@ run (const gchar *name,
break;
}
if (save_image (param[3].data.d_string, image_id))
values[0].data.d_status = GIMP_PDB_SUCCESS;
if (save_image (param[3].data.d_string, image_id, &error))
{
values[0].data.d_status = GIMP_PDB_SUCCESS;
}
else
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
{
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
if (error)
{
*nreturn_vals = 2;
values[1].type = GIMP_PDB_STRING;
values[1].data.d_string = error->message;
}
}
if (export == GIMP_EXPORT_EXPORT)
gimp_image_delete (image_id);
......@@ -395,7 +408,9 @@ write_pascalstring (FILE *fd,
xfwrite (fd, val, len, why);
}
else
write_gint16 (fd, 0, why);
{
write_gint16 (fd, 0, why);
}
/* If total length (length byte + content) is not a multiple of PADDING,
add zeros to pad it. */
......@@ -1518,8 +1533,9 @@ get_image_data (FILE *fd,
static gint
save_image (const gchar *filename,
gint32 image_id)
save_image (const gchar *filename,
gint32 image_id,
GError **error)
{
FILE *fd;
gint32 *layers;
......@@ -1531,9 +1547,12 @@ save_image (const gchar *filename,
if (gimp_image_width (image_id) > 30000 ||
gimp_image_height (image_id) > 30000)
{
g_message (_("Unable to save '%s'. The PSD file format does not support images that are more than 30,000 pixels wide or tall."),
gimp_filename_to_utf8 (filename));
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Unable to save '%s'. The PSD file format does not "
"support images that are more than 30,000 pixels wide "
"or tall."),
gimp_filename_to_utf8 (filename));
return FALSE;
}
......@@ -1544,8 +1563,11 @@ save_image (const gchar *filename,
drawable = gimp_drawable_get (layers[i]);
if (drawable->width > 30000 || drawable->height > 30000)
{
g_message (_("Unable to save '%s'. The PSD file format does not support images with layers that are more than 30,000 pixels wide or tall."),
gimp_filename_to_utf8 (filename));
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Unable to save '%s'. The PSD file format does not "
"support images with layers that are more than 30,000 "
"pixels wide or tall."),
gimp_filename_to_utf8 (filename));
g_free (layers);
return FALSE;
}
......@@ -1556,8 +1578,9 @@ save_image (const gchar *filename,
fd = g_fopen (filename, "wb");
if (fd == 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;
}
......
......@@ -35,37 +35,38 @@
#include "libgimp/stdplugins-intl.h"
/* Local function prototypes */
static gint read_header_block (PSDimage *img_a,
FILE *f,
GError **error);
static gint read_header_block (PSDimage *img_a,
FILE *f,
GError **error);
static gint read_color_mode_block (PSDimage *img_a,
FILE *f,
GError **error);
static gint read_color_mode_block (PSDimage *img_a,
FILE *f,
GError **error);
static gint read_image_resource_block (PSDimage *img_a,
FILE *f,
GError **error);
static gint read_image_resource_block (PSDimage *img_a,
FILE *f,
GError **error);
static gint32 create_gimp_image (PSDimage *img_a,
const gchar *filename);
static gint32 create_gimp_image (PSDimage *img_a,
const gchar *filename);
static gint add_image_resources (const gint32 image_id,
PSDimage *img_a,
FILE *f,
GError **error);
static gint add_image_resources (const gint32 image_id,
PSDimage *img_a,
FILE *f,
GError **error);
/* Main file load function */
gint32
load_thumbnail_image (const gchar *filename,
gint *width,
gint *height)
load_thumbnail_image (const gchar *filename,
gint *width,
gint *height,
GError **load_error)
{
FILE *f;
struct stat st;
PSDimage img_a;
gint32 image_id = -1;
GError *error = NULL;
FILE *f;
struct stat st;
PSDimage img_a;
gint32 image_id = -1;
GError *error = NULL;
/* ----- Open PSD file ----- */
if (g_stat (filename, &st) == -1)
......@@ -75,8 +76,9 @@ load_thumbnail_image (const gchar *filename,
f = g_fopen (filename, "rb");
if (f == NULL)
{
g_message (_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
g_set_error (load_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;
}
......@@ -123,6 +125,13 @@ load_thumbnail_image (const gchar *filename,
/* ----- Process load errors ----- */
load_error:
if (error)
{
g_set_error (load_error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Error loading PSD file: %s"), error->message);
g_error_free (error);
}
/* Delete partially loaded image */
if (image_id > 0)
gimp_image_delete (image_id);
......
......@@ -23,9 +23,10 @@
#define __PSD_THUMB_LOAD_H__
gint32 load_thumbnail_image (const gchar *filename,
gint *width,
gint *height);
gint32 load_thumbnail_image (const gchar *filename,
gint *width,
gint *height,
GError **error);
#endif /* __PSD_THUMB_LOAD_H__ */
......@@ -172,6 +172,7 @@ run (const gchar *name,
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_ID;
GError *error = NULL;
#ifdef PSD_SAVE
gint32 drawable_ID;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
......@@ -190,7 +191,7 @@ run (const gchar *name,
/* File load */
if (strcmp (name, LOAD_PROC) == 0)
{
image_ID = load_image (param[1].data.d_string);
image_ID = load_image (param[1].data.d_string, &error);
if (image_ID != -1)
{
......@@ -217,7 +218,7 @@ run (const gchar *name,
gint width = 0;
gint height = 0;
image_ID = load_thumbnail_image (filename, &width, &height);
image_ID = load_thumbnail_image (filename, &width, &height, &error);
if (image_ID != -1)
{
......@@ -267,7 +268,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))
{
}
else
......@@ -287,5 +289,12 @@ 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment