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