diff options
author | Søren Sandmann Pedersen <ssp@redhat.com> | 2014-06-01 17:58:35 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <soren.sandmann@gmail.com> | 2016-09-06 15:41:36 -0400 |
commit | 9a51d191232e47fc164fb666a441207dbe98823f (patch) | |
tree | b24779082bb93e84fd406d36eac339061c4f83b8 | |
parent | 85467ec308f8621a5410c007491797b7b1847601 (diff) |
Beginning of downscale test
FIXME: needs a better name (possibly box-filter-test or something like that).
This branch is supposed to be changing the sample points so that they are
positioned at locations
(2i + 1 - k) / 2^k
For subsample_bits = k. This positions them at
0.5 for k = 0
0, 0.5 for k = 1
0, 0.25, 0.5, 0.75 for k = 2
and so on, which is better than currently, where they are located at
(i + 0.5) / 2^k
which gives
0.5 for k = 0
0.25, 0.75 for k = 1
0.125, 0.375, 0.5, 0.625 for k = 2
and so on, which results in artefacts for downscalings that are an
exact multiple of the original size.
-rw-r--r-- | test/Makefile.sources | 2 | ||||
-rw-r--r-- | test/downscale-test.c | 95 |
2 files changed, 97 insertions, 0 deletions
diff --git a/test/Makefile.sources b/test/Makefile.sources index 0a562316..8d1f65ab 100644 --- a/test/Makefile.sources +++ b/test/Makefile.sources @@ -1,4 +1,5 @@ # Tests (sorted by expected completion time) + TESTPROGRAMS = \ oob-test \ infinite-loop \ @@ -17,6 +18,7 @@ TESTPROGRAMS = \ scaling-helpers-test \ thread-test \ rotate-test \ + downscale-test \ alphamap \ gradient-crash-test \ pixel-test \ diff --git a/test/downscale-test.c b/test/downscale-test.c new file mode 100644 index 00000000..be479b6b --- /dev/null +++ b/test/downscale-test.c @@ -0,0 +1,95 @@ +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "utils.h" + +#define WIDTH 256 +#define HEIGHT 256 + +#define SCALED_WIDTH 8 +#define SCALED_HEIGHT 8 + +/* This test scales down a bit 2x2 checkerboard using a box filter. The + * resulting image is supposed to be perfectly black and white with no + * gray pixels. + */ +int +main () +{ + pixman_image_t *src, *dest; + pixman_color_t black = { 0x0000, 0x0000, 0x0000, 0xffff }; + pixman_color_t white = { 0xffff, 0xffff, 0xffff, 0xffff }; + pixman_box32_t full = { 0, 0, WIDTH, HEIGHT }; + pixman_box32_t boxes[] = { + { 0, 0, WIDTH / 2, HEIGHT / 2 }, + { WIDTH / 2, HEIGHT / 2, WIDTH, HEIGHT } + }; + pixman_transform_t transform = { + { { (WIDTH / SCALED_WIDTH) * 65536, 0, 0 }, + { 0, (HEIGHT / SCALED_HEIGHT) * 65536, 0 }, + { 0, 0, 65536 } + } + }; + int bits; + pixman_bool_t failed; + + src = pixman_image_create_bits (PIXMAN_a8r8g8b8, WIDTH, HEIGHT, NULL, -1); + + pixman_image_fill_boxes (PIXMAN_OP_SRC, src, &white, 1, &full); + pixman_image_fill_boxes (PIXMAN_OP_SRC, src, &black, 2, boxes); + + write_png (src, "check.png"); + + dest = pixman_image_create_bits (PIXMAN_a8r8g8b8, SCALED_WIDTH, SCALED_HEIGHT, NULL, -1); + pixman_image_set_repeat (src, PIXMAN_REPEAT_PAD); + pixman_image_set_transform (src, &transform); + + for (bits = 0; bits < 12; ++bits) + { + pixman_fixed_t *params; + int n_params; + uint32_t *dst_data; + int i; + int j; + + params = pixman_filter_create_separable_convolution ( + &n_params, + (WIDTH / SCALED_WIDTH) * 65536, + (HEIGHT / SCALED_HEIGHT) * 65536, + PIXMAN_KERNEL_BOX, + PIXMAN_KERNEL_BOX, + PIXMAN_KERNEL_BOX, + PIXMAN_KERNEL_BOX, + bits, bits); + + pixman_image_set_filter (src, PIXMAN_FILTER_SEPARABLE_CONVOLUTION, params, n_params); + + free (params); + + pixman_image_composite32 (PIXMAN_OP_SRC, src, NULL, dest, + 0, 0, 0, 0, 0, 0, SCALED_WIDTH, SCALED_HEIGHT); + + dst_data = pixman_image_get_data (dest); + + for (j = 0; j < SCALED_HEIGHT; ++j) + { + for (i = 0; i < SCALED_WIDTH; ++i) + { + uint32_t *p = dst_data + j * SCALED_WIDTH + i; + int xb = i < SCALED_WIDTH / 2; + int yb = j < SCALED_HEIGHT / 2; + uint32_t ref = (xb ^ yb)? 0xffffffff : 0xff000000; + + if (*p != ref) + { + printf ("bits: %d: Wrong pixel at (%d %d) -- got %x, expected %x\n", + bits, i, j, *p, ref); + failed = TRUE; + } + } + } + } + + return failed; +} |