[cairo-commit] src/cairo-png.c

Chris Wilson ickle at kemper.freedesktop.org
Mon Apr 23 05:10:15 PDT 2007


 src/cairo-png.c |   31 +++++++++++++++++++++++++------
 1 files changed, 25 insertions(+), 6 deletions(-)

New commits:
diff-tree 0fce7e85a1c853216866ddf6a40725e7ce57fe93 (from 59670dd5d3854af1f7cbdef984df7802c338330b)
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Apr 23 13:00:40 2007 +0100

    Do not print out libpng error messages to stderr.
    
    We wish to avoid writing to file descriptors (and streams) that are
    outside cairo's control. In this case, the messages are superfluous as
    the errors are propagated via the cairo_status_t returns.

diff --git a/src/cairo-png.c b/src/cairo-png.c
index 7422622..442fec5 100644
--- a/src/cairo-png.c
+++ b/src/cairo-png.c
@@ -83,6 +83,24 @@ convert_data_to_bytes (png_structp png, 
     }
 }
 
+/* Use a couple of simple error callbacks that do not print anything to
+ * stderr and rely on the user to check for errors via the cairo_status_t
+ * return.
+ */
+static void
+png_simple_error_callback (png_structp png_save_ptr,
+	                   png_const_charp error_msg)
+{
+    longjmp (png_save_ptr->jmpbuf, CAIRO_STATUS_NO_MEMORY);
+}
+
+static void
+png_simple_warning_callback (png_structp png_save_ptr,
+	                     png_const_charp error_msg)
+{
+}
+
+
 static cairo_status_t
 write_png (cairo_surface_t	*surface,
 	   png_rw_ptr		write_func,
@@ -118,7 +136,9 @@ write_png (cairo_surface_t	*surface,
     for (i = 0; i < image->height; i++)
 	rows[i] = (png_byte *) image->data + i * image->stride;
 
-    png = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+    png = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL,
+	                           png_simple_error_callback,
+	                           png_simple_warning_callback);
     if (png == NULL) {
 	status = CAIRO_STATUS_NO_MEMORY;
 	goto BAIL2;
@@ -130,10 +150,9 @@ write_png (cairo_surface_t	*surface,
 	goto BAIL3;
     }
 
-    if (setjmp (png_jmpbuf (png))) {
-	status = CAIRO_STATUS_NO_MEMORY;
+    status = setjmp (png_jmpbuf (png));
+    if (status)
 	goto BAIL3;
-    }
 
     png_set_write_fn (png, closure, write_func, NULL);
 
@@ -350,8 +369,8 @@ read_png (png_rw_ptr	read_func,
     /* XXX: Perhaps we'll want some other error handlers? */
     png = png_create_read_struct (PNG_LIBPNG_VER_STRING,
                                   NULL,
-                                  NULL,
-                                  NULL);
+	                          png_simple_error_callback,
+	                          png_simple_warning_callback);
     if (png == NULL)
 	goto BAIL;
 


More information about the cairo-commit mailing list