scaling-helpers-test.c revision 6ba797d6
1#include <config.h>
2#include <stdint.h>
3#include <stdlib.h>
4#include <stdio.h>
5#include <assert.h>
6#include "utils.h"
7#include "pixman-fast-path.h"
8
9/* A trivial reference implementation for
10 * 'bilinear_pad_repeat_get_scanline_bounds'
11 */
12static void
13bilinear_pad_repeat_get_scanline_bounds_ref (int32_t        source_image_width,
14					     pixman_fixed_t vx_,
15					     pixman_fixed_t unit_x,
16					     int32_t *      left_pad,
17					     int32_t *      left_tz,
18					     int32_t *      width,
19					     int32_t *      right_tz,
20					     int32_t *      right_pad)
21{
22    int w = *width;
23    *left_pad = 0;
24    *left_tz = 0;
25    *width = 0;
26    *right_tz = 0;
27    *right_pad = 0;
28    int64_t vx = vx_;
29    while (--w >= 0)
30    {
31	if (vx < 0)
32	{
33	    if (vx + pixman_fixed_1 < 0)
34		*left_pad += 1;
35	    else
36		*left_tz += 1;
37	}
38	else if (vx + pixman_fixed_1 >= pixman_int_to_fixed (source_image_width))
39	{
40	    if (vx >= pixman_int_to_fixed (source_image_width))
41		*right_pad += 1;
42	    else
43		*right_tz += 1;
44	}
45	else
46	{
47	    *width += 1;
48	}
49	vx += unit_x;
50    }
51}
52
53int
54main (void)
55{
56    int i;
57    for (i = 0; i < 10000; i++)
58    {
59	int32_t left_pad1, left_tz1, width1, right_tz1, right_pad1;
60	int32_t left_pad2, left_tz2, width2, right_tz2, right_pad2;
61	pixman_fixed_t vx = lcg_rand_N(10000 << 16) - (3000 << 16);
62	int32_t width = lcg_rand_N(10000);
63	int32_t source_image_width = lcg_rand_N(10000) + 1;
64	pixman_fixed_t unit_x = lcg_rand_N(10 << 16) + 1;
65	width1 = width2 = width;
66
67	bilinear_pad_repeat_get_scanline_bounds_ref (source_image_width,
68						     vx,
69						     unit_x,
70						     &left_pad1,
71						     &left_tz1,
72						     &width1,
73						     &right_tz1,
74						     &right_pad1);
75
76	bilinear_pad_repeat_get_scanline_bounds (source_image_width,
77						 vx,
78						 unit_x,
79						 &left_pad2,
80						 &left_tz2,
81						 &width2,
82						 &right_tz2,
83						 &right_pad2);
84
85	assert (left_pad1 == left_pad2);
86	assert (left_tz1 == left_tz2);
87	assert (width1 == width2);
88	assert (right_tz1 == right_tz2);
89	assert (right_pad1 == right_pad2);
90    }
91
92    return 0;
93}
94