plug-ins/file-faxg3/faxg3.c plug-ins/file-ico/ico.c

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

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


svn path=/trunk/; revision=26667
This commit is contained in:
Sven Neumann
2008-08-20 06:15:35 +00:00
committed by Sven Neumann
parent 0b804f4d50
commit 3f26d82b62
7 changed files with 108 additions and 66 deletions

View File

@ -1,3 +1,11 @@
2008-08-20 Sven Neumann <sven@gimp.org>
* plug-ins/file-faxg3/faxg3.c
* plug-ins/file-ico/ico.c
* plug-ins/file-ico/ico-load.[ch]
* plug-ins/file-ico/ico-save.[ch]: pass error messages with the
return values instead of calling g_message().
2008-08-19 Sven Neumann <sven@gimp.org>
* app/core/gimpimage-guides.c (gimp_image_find_guide): find guides

View File

@ -61,7 +61,8 @@ 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 gint32 emitgimp (gint hcol,
gint row,
@ -123,11 +124,13 @@ run (const gchar *name,
static GimpParam values[2];
GimpRunMode run_mode;
gint32 image_ID;
GError *error = NULL;
run_mode = param[0].data.d_int32;
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = GIMP_PDB_CALLING_ERROR;
@ -135,18 +138,26 @@ run (const gchar *name,
{
INIT_I18N();
*nreturn_vals = 2;
image_ID = load_image (param[1].data.d_string);
values[1].type = GIMP_PDB_IMAGE;
values[1].data.d_image = image_ID;
image_ID = load_image (param[1].data.d_string, &error);
if (image_ID != -1)
{
*nreturn_vals = 2;
values[0].data.d_status = GIMP_PDB_SUCCESS;
values[1].type = GIMP_PDB_IMAGE;
values[1].data.d_image = image_ID;
}
else
{
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;
}
}
}
}
@ -181,8 +192,10 @@ static int rs; /* read buffer size */
#define MAX_ROWS 4300
#define MAX_COLS 1728 /* !! FIXME - command line parameter */
static gint32
load_image (const gchar *filename)
load_image (const gchar *filename,
GError **error)
{
int data;
int hibit;
@ -216,7 +229,8 @@ load_image (const gchar *filename)
if (fd < 0)
{
g_message (_("Could not open '%s' for reading: %s"),
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;
}

View File

@ -157,10 +157,10 @@ ico_read_size (FILE *fp,
{
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL,
NULL);
if ( !png_ptr )
if (! png_ptr )
return FALSE;
info_ptr = png_create_info_struct (png_ptr);
if ( !info_ptr )
if (! info_ptr )
{
png_destroy_read_struct (&png_ptr, NULL, NULL);
return FALSE;
@ -257,10 +257,10 @@ ico_read_png (FILE *fp,
gint i;
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if ( !png_ptr )
if (! png_ptr )
return FALSE;
info = png_create_info_struct (png_ptr);
if ( !info )
if (! info )
{
png_destroy_read_struct (&png_ptr, NULL, NULL);
return FALSE;
@ -630,7 +630,8 @@ ico_load_layer (FILE *fp,
gint32
ico_load_image (const gchar *filename)
ico_load_image (const gchar *filename,
GError **error)
{
FILE *fp;
IcoLoadInfo *info;
@ -646,9 +647,10 @@ ico_load_image (const gchar *filename)
gimp_filename_to_utf8 (filename));
fp = g_fopen (filename, "rb");
if ( !fp )
if (! fp )
{
g_message (_("Could not open '%s' for reading: %s"),
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;
}
@ -706,7 +708,8 @@ ico_load_image (const gchar *filename)
gint32
ico_load_thumbnail_image (const gchar *filename,
gint *width,
gint *height)
gint *height,
GError **error)
{
FILE *fp;
IcoLoadInfo *info;
@ -723,15 +726,16 @@ ico_load_thumbnail_image (const gchar *filename,
gimp_filename_to_utf8 (filename));
fp = g_fopen (filename, "rb");
if ( !fp )
if (! fp )
{
g_message (_("Could not open '%s' for reading: %s"),
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;
}
icon_count = ico_read_init (fp);
if ( !icon_count )
if (! icon_count )
{
fclose (fp);
return -1;
@ -741,7 +745,7 @@ ico_load_thumbnail_image (const gchar *filename,
filename, icon_count));
info = ico_read_info (fp, icon_count);
if ( !info )
if (! info )
{
fclose (fp);
return -1;

View File

@ -22,10 +22,14 @@
#ifndef __ICO_LOAD_H__
#define __ICO_LOAD_H__
gint32 ico_load_image (const gchar *filename);
gint32 ico_load_image (const gchar *filename,
GError **error);
gint32 ico_load_thumbnail_image (const gchar *filename,
gint *width,
gint *height);
gint *height,
GError **error);
gint ico_get_bit_from_data (const guint8 *data,
gint line_width,
gint bit);

View File

@ -324,7 +324,7 @@ ico_set_byte_in_data (guint8 *data,
/* Create a colormap from the given buffer data */
static guint32 *
ico_create_palette(guchar *cmap,
ico_create_palette (const guchar *cmap,
gint num_colors,
gint num_colors_used,
gint *black_slot)
@ -374,7 +374,7 @@ ico_create_palette(guchar *cmap,
static GHashTable *
ico_create_color_to_palette_map (guint32 *palette,
ico_create_color_to_palette_map (const guint32 *palette,
gint num_colors)
{
GHashTable *hash;
@ -384,8 +384,9 @@ ico_create_color_to_palette_map (guint32 *palette,
for (i = 0; i < num_colors; i++)
{
gint *color, *slot;
guint8 *pixel = (guint8 *) &palette[i];
const guint8 *pixel = (const guint8 *) &palette[i];
gint *color;
gint *slot;
color = g_new (gint, 1);
slot = g_new (gint, 1);
@ -526,7 +527,7 @@ ico_get_layer_num_colors (gint32 layer,
}
gboolean
ico_cmap_contains_black (guchar *cmap,
ico_cmap_contains_black (const guchar *cmap,
gint num_colors)
{
gint i;
@ -990,7 +991,8 @@ ico_save_info_free (IcoSaveInfo *info)
GimpPDBStatusType
ico_save_image (const gchar *filename,
gint32 image,
gint32 run_mode)
gint32 run_mode,
GError **error)
{
FILE *fp;
@ -1017,7 +1019,8 @@ ico_save_image (const gchar *filename,
if (! (fp = g_fopen (filename, "wb")))
{
g_message (_("Could not open '%s' for writing: %s"),
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;
}

View File

@ -25,9 +25,10 @@
GimpPDBStatusType ico_save_image (const gchar *file_name,
gint32 image_ID,
gint32 run_mode);
gint32 run_mode,
GError **error);
gboolean ico_cmap_contains_black (guchar *cmap,
gboolean ico_cmap_contains_black (const guchar *cmap,
gint num_colors);

View File

@ -157,6 +157,7 @@ run (const gchar *name,
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GError *error = NULL;
INIT_I18N ();
@ -185,7 +186,7 @@ run (const gchar *name,
if (status == GIMP_PDB_SUCCESS)
{
image_ID = ico_load_image (param[1].data.d_string);
image_ID = ico_load_image (param[1].data.d_string, &error);
if (image_ID != -1)
{
@ -212,7 +213,8 @@ run (const gchar *name,
gint height = param[1].data.d_int32;
gint32 image_ID;
image_ID = ico_load_thumbnail_image (filename, &width, &height);
image_ID = ico_load_thumbnail_image (filename,
&width, &height, &error);
if (image_ID != -1)
{
@ -259,7 +261,7 @@ run (const gchar *name,
if (status == GIMP_PDB_SUCCESS)
{
status = ico_save_image (file_name, image_ID, run_mode);
status = ico_save_image (file_name, image_ID, run_mode, &error);
}
if (export == GIMP_EXPORT_EXPORT)
@ -270,7 +272,13 @@ run (const gchar *name,
status = GIMP_PDB_CALLING_ERROR;
}
values[0].type = GIMP_PDB_STATUS;
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;
}