~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to pixman/test/scaling-helpers-test.c

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
    prng_srand (0);
 
56
    for (i = 0; i < 10000; i++)
 
57
    {
 
58
        int32_t left_pad1, left_tz1, width1, right_tz1, right_pad1;
 
59
        int32_t left_pad2, left_tz2, width2, right_tz2, right_pad2;
 
60
        pixman_fixed_t vx = prng_rand_n(10000 << 16) - (3000 << 16);
 
61
        int32_t width = prng_rand_n(10000);
 
62
        int32_t source_image_width = prng_rand_n(10000) + 1;
 
63
        pixman_fixed_t unit_x = prng_rand_n(10 << 16) + 1;
 
64
        width1 = width2 = width;
 
65
 
 
66
        bilinear_pad_repeat_get_scanline_bounds_ref (source_image_width,
 
67
                                                     vx,
 
68
                                                     unit_x,
 
69
                                                     &left_pad1,
 
70
                                                     &left_tz1,
 
71
                                                     &width1,
 
72
                                                     &right_tz1,
 
73
                                                     &right_pad1);
 
74
 
 
75
        bilinear_pad_repeat_get_scanline_bounds (source_image_width,
 
76
                                                 vx,
 
77
                                                 unit_x,
 
78
                                                 &left_pad2,
 
79
                                                 &left_tz2,
 
80
                                                 &width2,
 
81
                                                 &right_tz2,
 
82
                                                 &right_pad2);
 
83
 
 
84
        assert (left_pad1 == left_pad2);
 
85
        assert (left_tz1 == left_tz2);
 
86
        assert (width1 == width2);
 
87
        assert (right_tz1 == right_tz2);
 
88
        assert (right_pad1 == right_pad2);
 
89
    }
 
90
 
 
91
    return 0;
 
92
}