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,
@ -120,14 +121,16 @@ run (const gchar *name,
gint *nreturn_vals,
GimpParam **return_vals)
{
static GimpParam values[2];
GimpRunMode run_mode;
gint32 image_ID;
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,19 +138,27 @@ 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,8 +229,9 @@ load_image (const gchar *filename)
if (fd < 0)
{
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;
}
@ -289,7 +303,7 @@ load_image (const gchar *filename)
if ( p == NULL ) /* invalid code */
{
g_printerr ("invalid code, row=%d, col=%d, file offset=%lx, skip to eol\n",
row, col, (unsigned long) lseek( fd, 0, 1 ) - rs + rp );
row, col, (unsigned long) lseek( fd, 0, 1 ) - rs + rp );
while ( ( data & 0x03f ) != 0 )
{
data >>= 1; hibit--;

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,10 +647,11 @@ 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"),
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;
}
@ -704,9 +706,10 @@ ico_load_image (const gchar *filename)
}
gint32
ico_load_thumbnail_image (const gchar *filename,
gint *width,
gint *height)
ico_load_thumbnail_image (const gchar *filename,
gint *width,
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"),
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;
}
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,19 +22,23 @@
#ifndef __ICO_LOAD_H__
#define __ICO_LOAD_H__
gint32 ico_load_image (const gchar *filename);
gint32 ico_load_thumbnail_image (const gchar *filename,
gint *width,
gint *height);
gint ico_get_bit_from_data (const guint8 *data,
gint line_width,
gint bit);
gint ico_get_nibble_from_data (const guint8 *data,
gint line_width,
gint nibble);
gint ico_get_byte_from_data (const guint8 *data,
gint line_width,
gint byte);
gint32 ico_load_image (const gchar *filename,
GError **error);
gint32 ico_load_thumbnail_image (const gchar *filename,
gint *width,
gint *height,
GError **error);
gint ico_get_bit_from_data (const guint8 *data,
gint line_width,
gint bit);
gint ico_get_nibble_from_data (const guint8 *data,
gint line_width,
gint nibble);
gint ico_get_byte_from_data (const guint8 *data,
gint line_width,
gint byte);
#endif /* __ICO_LOAD_H__ */

View File

@ -324,10 +324,10 @@ ico_set_byte_in_data (guint8 *data,
/* Create a colormap from the given buffer data */
static guint32 *
ico_create_palette(guchar *cmap,
gint num_colors,
gint num_colors_used,
gint *black_slot)
ico_create_palette (const guchar *cmap,
gint num_colors,
gint num_colors_used,
gint *black_slot)
{
guchar *palette;
gint i;
@ -374,8 +374,8 @@ ico_create_palette(guchar *cmap,
static GHashTable *
ico_create_color_to_palette_map (guint32 *palette,
gint num_colors)
ico_create_color_to_palette_map (const guint32 *palette,
gint num_colors)
{
GHashTable *hash;
gint i;
@ -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,8 +527,8 @@ ico_get_layer_num_colors (gint32 layer,
}
gboolean
ico_cmap_contains_black (guchar *cmap,
gint num_colors)
ico_cmap_contains_black (const guchar *cmap,
gint num_colors)
{
gint i;
@ -988,9 +989,10 @@ ico_save_info_free (IcoSaveInfo *info)
}
GimpPDBStatusType
ico_save_image (const gchar *filename,
gint32 image,
gint32 run_mode)
ico_save_image (const gchar *filename,
gint32 image,
gint32 run_mode,
GError **error)
{
FILE *fp;
@ -1017,8 +1019,9 @@ ico_save_image (const gchar *filename,
if (! (fp = g_fopen (filename, "wb")))
{
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;
}

View File

@ -23,12 +23,13 @@
#define __ICO_SAVE_H__
GimpPDBStatusType ico_save_image (const gchar *file_name,
gint32 image_ID,
gint32 run_mode);
GimpPDBStatusType ico_save_image (const gchar *file_name,
gint32 image_ID,
gint32 run_mode,
GError **error);
gboolean ico_cmap_contains_black (guchar *cmap,
gint num_colors);
gboolean ico_cmap_contains_black (const guchar *cmap,
gint num_colors);
#endif /* __ICO_SAVE_H__ */

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;
}