diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2008-04-21 19:44:11 +0100 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-04-21 19:44:11 +0100 |
commit | a313547f6d0ed060de7fc27dc2886ef09b8598d4 (patch) | |
tree | af4bff15a291b12db910aadecbaeed121ef0d3f4 /test/create-from-png.c | |
parent | f2f91db131e7c7df1e87bcd41ae17c07429bbcb8 (diff) | |
download | cairo-a313547f6d0ed060de7fc27dc2886ef09b8598d4.tar.gz |
[test/create-from-png] Check loading of various colour types.
Check that when loading from index/gray/rgb PNGs, with and without
alpha/transparency, that the correct surface is generated by read_png(),
i.e. if the PNG contains an alpha channel then the image must be an
ARGB32 surface.
Diffstat (limited to 'test/create-from-png.c')
-rw-r--r-- | test/create-from-png.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/test/create-from-png.c b/test/create-from-png.c index fe08b308d..0707680cb 100644 --- a/test/create-from-png.c +++ b/test/create-from-png.c @@ -145,5 +145,126 @@ main (void) } cairo_surface_destroy (surface); + /* check that loading alpha/opaque PNGs generate the correct surfaces */ + xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".", + "create-from-png-alpha-ref.png"); + surface = cairo_image_surface_create_from_png (filename); + if (cairo_surface_status (surface)) { + cairo_test_log ("Error reading PNG image %s: %s\n", + filename, + cairo_status_to_string (cairo_surface_status (surface))); + free (filename); + return CAIRO_TEST_FAILURE; + } + if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_ARGB32) { + cairo_test_log ("Error reading PNG image %s: did not create an ARGB32 image\n", + filename); + cairo_surface_destroy (surface); + return CAIRO_TEST_FAILURE; + } + free (filename); + cairo_surface_destroy (surface); + + xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".", + "create-from-png-ref.png"); + surface = cairo_image_surface_create_from_png (filename); + if (cairo_surface_status (surface)) { + cairo_test_log ("Error reading PNG image %s: %s\n", + filename, + cairo_status_to_string (cairo_surface_status (surface))); + free (filename); + return CAIRO_TEST_FAILURE; + } + if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_RGB24) { + cairo_test_log ("Error reading PNG image %s: did not create an RGB24 image\n", + filename); + cairo_surface_destroy (surface); + return CAIRO_TEST_FAILURE; + } + free (filename); + cairo_surface_destroy (surface); + + /* check paletted PNGs */ + xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".", + "create-from-png-indexed-alpha-ref.png"); + surface = cairo_image_surface_create_from_png (filename); + if (cairo_surface_status (surface)) { + cairo_test_log ("Error reading PNG image %s: %s\n", + filename, + cairo_status_to_string (cairo_surface_status (surface))); + free (filename); + return CAIRO_TEST_FAILURE; + } + if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_ARGB32) { + cairo_test_log ("Error reading PNG image %s: did not create an ARGB32 image\n", + filename); + free (filename); + cairo_surface_destroy (surface); + return CAIRO_TEST_FAILURE; + } + free (filename); + cairo_surface_destroy (surface); + + xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".", + "create-from-png-indexed-ref.png"); + surface = cairo_image_surface_create_from_png (filename); + if (cairo_surface_status (surface)) { + cairo_test_log ("Error reading PNG image %s: %s\n", + filename, + cairo_status_to_string (cairo_surface_status (surface))); + free (filename); + return CAIRO_TEST_FAILURE; + } + if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_RGB24) { + cairo_test_log ("Error reading PNG image %s: did not create an RGB24 image\n", + filename); + free (filename); + cairo_surface_destroy (surface); + return CAIRO_TEST_FAILURE; + } + free (filename); + cairo_surface_destroy (surface); + + /* check grayscale PNGs */ + xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".", + "create-from-png-gray-alpha-ref.png"); + surface = cairo_image_surface_create_from_png (filename); + if (cairo_surface_status (surface)) { + cairo_test_log ("Error reading PNG image %s: %s\n", + filename, + cairo_status_to_string (cairo_surface_status (surface))); + free (filename); + return CAIRO_TEST_FAILURE; + } + if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_ARGB32) { + cairo_test_log ("Error reading PNG image %s: did not create an ARGB32 image\n", + filename); + free (filename); + cairo_surface_destroy (surface); + return CAIRO_TEST_FAILURE; + } + free (filename); + cairo_surface_destroy (surface); + + xasprintf (&filename, "%s/%s", srcdir ? srcdir : ".", + "create-from-png-gray-ref.png"); + surface = cairo_image_surface_create_from_png (filename); + if (cairo_surface_status (surface)) { + cairo_test_log ("Error reading PNG image %s: %s\n", + filename, + cairo_status_to_string (cairo_surface_status (surface))); + free (filename); + return CAIRO_TEST_FAILURE; + } + if (cairo_image_surface_get_format (surface) != CAIRO_FORMAT_RGB24) { + cairo_test_log ("Error reading PNG image %s: did not create an RGB24 image\n", + filename); + free (filename); + cairo_surface_destroy (surface); + return CAIRO_TEST_FAILURE; + } + free (filename); + cairo_surface_destroy (surface); + return cairo_test (&test); } |