[PATCH 1/3] test: Add test for image downscaling
"Bryce W. Harrington" <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <5A5FB412583EA944A1D0228D52A9C57263B970@sisaex02sj> |
This adds pixman-downscale.c, which tests correctness of PNG images scaled down using pixman routines. Signed-off-by: Bryce Harrington <[email protected]> --- test/Makefile.sources | 1 + test/pixman-downscale.c | 68 +++++++++++++++++++++++++++++++ test/quad-color.png | Bin 0 -> 301 bytes test/reference/pixman-downscale.ref.png | Bin 0 -> 191 bytes 4 files changed, 69 insertions(+) create mode 100644 test/pixman-downscale.c create mode 100644 test/quad-color.png create mode 100644 test/reference/pixman-downscale.ref.png diff --git a/test/Makefile.sources b/test/Makefile.sources index d44edb4..4c16c55 100644 --- a/test/Makefile.sources +++ b/test/Makefile.sources @@ -248,6 +248,7 @@ test_sources = \ pattern-get-type.c \ pattern-getters.c \ pdf-isolated-group.c \ + pixman-downscale.c \ pixman-rotate.c \ png.c \ push-group.c \ diff --git a/test/pixman-downscale.c b/test/pixman-downscale.c new file mode 100644 index 0000000..0562015 --- /dev/null +++ b/test/pixman-downscale.c @@ -0,0 +1,68 @@ +/* + * Copyright © 2013 Samsung Electronics + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Author: Bryce Harrington <[email protected]> + */ + +#include <stdio.h> +#include <stdlib.h> +#include <math.h> + +#include <cairo.h> + +#include "cairo-test.h" + +static const char *png_filename = "quad-color.png"; + +/* Draw an image scaled down, with antialiasing disabled */ +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + const cairo_test_context_t *ctx = cairo_test_get_context (cr); + cairo_surface_t *image; + double x_scale, y_scale, scale; + + cairo_set_source_rgb (cr, 1, 1, 1); + image = cairo_test_create_surface_from_png (ctx, png_filename); + x_scale = WIDTH * 1.0 / cairo_image_surface_get_width (image); + y_scale = HEIGHT * 1.0 / cairo_image_surface_get_height (image); + scale = fmin(x_scale, y_scale); + + cairo_save (cr); + cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); + cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); + cairo_scale (cr, scale, scale); + cairo_set_source_surface (cr, image, 0, 0); + cairo_paint (cr); + cairo_restore (cr); + cairo_surface_destroy (image); + + return CAIRO_TEST_SUCCESS; +} + +CAIRO_TEST (pixman_downscale, + "Exposes errors when downscaling", + "image, transform, raster", /* keywords */ + NULL, /* requirements */ + 96, 96, + NULL, draw) diff --git a/test/quad-color.png b/test/quad-color.png new file mode 100644 index 0000000000000000000000000000000000000000..0d68a82cc27532aa78fc12af7646f6821a730a2b GIT binary patch literal 301 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1SE5RJ;(=AY)RhkE)4%caKYZ?lYt_SJY5_^ zD(1Ysy^*iUK*S+1>rej2(}h=B@0d(;Js;WVUVNE%S1wQ;!=K59zYi43gs*v=>!Y8U z_vgvq?cQM@omse;SR0!h92Y1A>{u^la;*65g4(k)k}t|wYjB7lNebZM8vKpTne!)c zbN%i~M<*ZqX0g}kFdxELd^!~Z1T@ab2krlH<ByqM{lP1D%YXuKdqK|r@Q}6kF=t0) R<@7`l*VEO{Wt~$(698O(XEy)< literal 0 HcmV?d00001 diff --git a/test/reference/pixman-downscale.ref.png b/test/reference/pixman-downscale.ref.png new file mode 100644 index 0000000000000000000000000000000000000000..df0f9c0d84f3f48d00fdb0f3f08ae587754a269d GIT binary patch literal 191 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1SIoCSFHz9jKx9jP7LeL$-D$|I14-?iy0WW zg+Z8+Vb&awa`qBWUsv|K>|BC!7IA*pm4QNmo-U3d7N_3^pXOpv;3&RWA0EGNU1}T4 zrIUAMg4_8gwy>{ZJlV~aSJYV)vi6&EaICP+3<LMb7lqjZ5!yx;9>LS69R3%PQJ;M; gq~!8p8PysezC2Ei17|)i02<EV>FVdQ&MBb@0ICT&&j0`b literal 0 HcmV?d00001 -- 1.7.9.5 -- Bryce Harrington Senior Open Source Developer - [email protected] Open Source Group - Samsung Research America -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo