summaryrefslogtreecommitdiff
path: root/test/create-from-png.c
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2005-04-25 20:42:54 +0000
committerKristian Høgsberg <krh@redhat.com>2005-04-25 20:42:54 +0000
commit87009d692b5a37fc91db19819c46216ed6b3c4e3 (patch)
treec18f745e369ddc891512d5c79d123970496fb455 /test/create-from-png.c
parente55161d2b2ea27d5174c2674544b3aaf6748134d (diff)
downloadcairo-87009d692b5a37fc91db19819c46216ed6b3c4e3.tar.gz
Factor out bulk of the code into a new callback based function, write_png(). Call it with a stdio write callback. (cairo_surface_write_png_to_stream): New function to write a surface to a PNG stream. (cairo_image_surface_create_from_png): Likewise, move most of the code to read_png(), clean up error handling and reduce this function to calling read_png() with a stdio based read function. (cairo_image_surface_create_from_png_stream): New function to create an image surface from a PNG stream.
New functions to get widht and height of an image surface. Add new prototype and error codes. Adjust to new PNG API.
Diffstat (limited to 'test/create-from-png.c')
-rw-r--r--test/create-from-png.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/test/create-from-png.c b/test/create-from-png.c
index 41223f728..4a93905ef 100644
--- a/test/create-from-png.c
+++ b/test/create-from-png.c
@@ -44,23 +44,22 @@ draw (cairo_t *cr, int width, int height)
char *filename;
FILE *file;
cairo_surface_t *surface;
- int surface_width, surface_height;
+ int png_width, png_height;
xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".",
"create-for-png-ref.png");
- file = fopen (filename, "r");
- if (file == NULL) {
+
+ surface = cairo_image_surface_create_from_png (filename);
+ free (filename);
+
+ if (surface == NULL) {
fprintf (stderr, "Error: failed to open file %s\n", filename);
- free (filename);
return CAIRO_TEST_FAILURE;
}
- free (filename);
-
- surface = cairo_image_surface_create_for_png (file,
- &surface_width,
- &surface_height);
- cairo_show_surface (cr, surface, surface_width, surface_height);
+ png_width = cairo_image_surface_get_width (surface);
+ png_height = cairo_image_surface_get_height (surface);
+ cairo_show_surface (cr, surface, png_width, png_height);
cairo_surface_destroy (surface);