16ba797d6Smrg#include <stdlib.h>
26ba797d6Smrg#include <stdio.h>
36ba797d6Smrg#include <assert.h>
46ba797d6Smrg#include "utils.h"
59ad247e8Sjmcneill#include "pixman-inlines.h"
66ba797d6Smrg
76ba797d6Smrg/* A trivial reference implementation for
86ba797d6Smrg * 'bilinear_pad_repeat_get_scanline_bounds'
96ba797d6Smrg */
106ba797d6Smrgstatic void
116ba797d6Smrgbilinear_pad_repeat_get_scanline_bounds_ref (int32_t        source_image_width,
126ba797d6Smrg					     pixman_fixed_t vx_,
136ba797d6Smrg					     pixman_fixed_t unit_x,
146ba797d6Smrg					     int32_t *      left_pad,
156ba797d6Smrg					     int32_t *      left_tz,
166ba797d6Smrg					     int32_t *      width,
176ba797d6Smrg					     int32_t *      right_tz,
186ba797d6Smrg					     int32_t *      right_pad)
196ba797d6Smrg{
206ba797d6Smrg    int w = *width;
219ad247e8Sjmcneill    int64_t vx = vx_;
226ba797d6Smrg    *left_pad = 0;
236ba797d6Smrg    *left_tz = 0;
246ba797d6Smrg    *width = 0;
256ba797d6Smrg    *right_tz = 0;
266ba797d6Smrg    *right_pad = 0;
276ba797d6Smrg    while (--w >= 0)
286ba797d6Smrg    {
296ba797d6Smrg	if (vx < 0)
306ba797d6Smrg	{
316ba797d6Smrg	    if (vx + pixman_fixed_1 < 0)
326ba797d6Smrg		*left_pad += 1;
336ba797d6Smrg	    else
346ba797d6Smrg		*left_tz += 1;
356ba797d6Smrg	}
366ba797d6Smrg	else if (vx + pixman_fixed_1 >= pixman_int_to_fixed (source_image_width))
376ba797d6Smrg	{
386ba797d6Smrg	    if (vx >= pixman_int_to_fixed (source_image_width))
396ba797d6Smrg		*right_pad += 1;
406ba797d6Smrg	    else
416ba797d6Smrg		*right_tz += 1;
426ba797d6Smrg	}
436ba797d6Smrg	else
446ba797d6Smrg	{
456ba797d6Smrg	    *width += 1;
466ba797d6Smrg	}
476ba797d6Smrg	vx += unit_x;
486ba797d6Smrg    }
496ba797d6Smrg}
506ba797d6Smrg
516ba797d6Smrgint
526ba797d6Smrgmain (void)
536ba797d6Smrg{
546ba797d6Smrg    int i;
55f4f78bb6Smrg    prng_srand (0);
566ba797d6Smrg    for (i = 0; i < 10000; i++)
576ba797d6Smrg    {
586ba797d6Smrg	int32_t left_pad1, left_tz1, width1, right_tz1, right_pad1;
596ba797d6Smrg	int32_t left_pad2, left_tz2, width2, right_tz2, right_pad2;
60f4f78bb6Smrg	pixman_fixed_t vx = prng_rand_n(10000 << 16) - (3000 << 16);
61f4f78bb6Smrg	int32_t width = prng_rand_n(10000);
62f4f78bb6Smrg	int32_t source_image_width = prng_rand_n(10000) + 1;
63f4f78bb6Smrg	pixman_fixed_t unit_x = prng_rand_n(10 << 16) + 1;
646ba797d6Smrg	width1 = width2 = width;
656ba797d6Smrg
666ba797d6Smrg	bilinear_pad_repeat_get_scanline_bounds_ref (source_image_width,
676ba797d6Smrg						     vx,
686ba797d6Smrg						     unit_x,
696ba797d6Smrg						     &left_pad1,
706ba797d6Smrg						     &left_tz1,
716ba797d6Smrg						     &width1,
726ba797d6Smrg						     &right_tz1,
736ba797d6Smrg						     &right_pad1);
746ba797d6Smrg
756ba797d6Smrg	bilinear_pad_repeat_get_scanline_bounds (source_image_width,
766ba797d6Smrg						 vx,
776ba797d6Smrg						 unit_x,
786ba797d6Smrg						 &left_pad2,
796ba797d6Smrg						 &left_tz2,
806ba797d6Smrg						 &width2,
816ba797d6Smrg						 &right_tz2,
826ba797d6Smrg						 &right_pad2);
836ba797d6Smrg
846ba797d6Smrg	assert (left_pad1 == left_pad2);
856ba797d6Smrg	assert (left_tz1 == left_tz2);
866ba797d6Smrg	assert (width1 == width2);
876ba797d6Smrg	assert (right_tz1 == right_tz2);
886ba797d6Smrg	assert (right_pad1 == right_pad2);
896ba797d6Smrg    }
906ba797d6Smrg
916ba797d6Smrg    return 0;
926ba797d6Smrg}
93