gimp r26667 - in trunk: . plug-ins/file-faxg3 plug-ins/file-ico
- From: neo svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r26667 - in trunk: . plug-ins/file-faxg3 plug-ins/file-ico
- Date: Wed, 20 Aug 2008 06:15:36 +0000 (UTC)
Author: neo
Date: Wed Aug 20 06:15:35 2008
New Revision: 26667
URL: http://svn.gnome.org/viewvc/gimp?rev=26667&view=rev
Log:
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().
Modified:
trunk/ChangeLog
trunk/plug-ins/file-faxg3/faxg3.c
trunk/plug-ins/file-ico/ico-load.c
trunk/plug-ins/file-ico/ico-load.h
trunk/plug-ins/file-ico/ico-save.c
trunk/plug-ins/file-ico/ico-save.h
trunk/plug-ins/file-ico/ico.c
Modified: trunk/plug-ins/file-faxg3/faxg3.c
==============================================================================
--- trunk/plug-ins/file-faxg3/faxg3.c (original)
+++ trunk/plug-ins/file-faxg3/faxg3.c Wed Aug 20 06:15:35 2008
@@ -61,7 +61,8 @@
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 @@
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 @@
{
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 @@
#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 @@
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 @@
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--;
Modified: trunk/plug-ins/file-ico/ico-load.c
==============================================================================
--- trunk/plug-ins/file-ico/ico-load.c (original)
+++ trunk/plug-ins/file-ico/ico-load.c Wed Aug 20 06:15:35 2008
@@ -157,10 +157,10 @@
{
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 @@
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 @@
gint32
-ico_load_image (const gchar *filename)
+ico_load_image (const gchar *filename,
+ GError **error)
{
FILE *fp;
IcoLoadInfo *info;
@@ -646,10 +647,11 @@
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 @@
}
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 @@
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 @@
filename, icon_count));
info = ico_read_info (fp, icon_count);
- if ( !info )
+ if (! info )
{
fclose (fp);
return -1;
Modified: trunk/plug-ins/file-ico/ico-load.h
==============================================================================
--- trunk/plug-ins/file-ico/ico-load.h (original)
+++ trunk/plug-ins/file-ico/ico-load.h Wed Aug 20 06:15:35 2008
@@ -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__ */
Modified: trunk/plug-ins/file-ico/ico-save.c
==============================================================================
--- trunk/plug-ins/file-ico/ico-save.c (original)
+++ trunk/plug-ins/file-ico/ico-save.c Wed Aug 20 06:15:35 2008
@@ -324,10 +324,10 @@
/* 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 @@
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 @@
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 @@
}
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 @@
}
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 @@
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;
}
Modified: trunk/plug-ins/file-ico/ico-save.h
==============================================================================
--- trunk/plug-ins/file-ico/ico-save.h (original)
+++ trunk/plug-ins/file-ico/ico-save.h Wed Aug 20 06:15:35 2008
@@ -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__ */
Modified: trunk/plug-ins/file-ico/ico.c
==============================================================================
--- trunk/plug-ins/file-ico/ico.c (original)
+++ trunk/plug-ins/file-ico/ico.c Wed Aug 20 06:15:35 2008
@@ -157,6 +157,7 @@
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
+ GError *error = NULL;
INIT_I18N ();
@@ -185,7 +186,7 @@
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 @@
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 @@
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 @@
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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]