diff options
author | David Schleef <ds@schleef.org> | 2009-11-23 13:42:23 -0800 |
---|---|---|
committer | David Schleef <ds@schleef.org> | 2011-05-17 10:22:05 -0700 |
commit | 835582b6dc5087feb7ea58532825bfd5704ca989 (patch) | |
tree | 4df382116591cc89edd76331620cb3205427a237 /test | |
parent | 222c3452d9dde875a21779a5ccf14e952d3ee206 (diff) |
orc: test program to check orc generated code
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 11 | ||||
-rw-r--r-- | test/ds.c | 163 |
2 files changed, 173 insertions, 1 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 9dc7219..3fa6965 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -21,12 +21,21 @@ TESTPROGRAMS = \ blitters-test \ scaling-test \ affine-test \ - composite + composite \ + ds pdf_op_test_SOURCES = pdf-op-test.c utils.c utils.h region_test_SOURCES = region-test.c utils.c utils.h blitters_test_SOURCES = blitters-test.c utils.c utils.h +<<<<<<< HEAD composite_traps_test_SOURCES = composite-traps-test.c utils.c utils.h +======= + +ds_LDADD = $(TEST_LDADD) +ds_SOURCES = ds.c ../pixman/pixman-orccode.c + +scaling_test_LDADD = $(TEST_LDADD) +>>>>>>> orc: test program to check orc generated code scaling_test_SOURCES = scaling-test.c utils.c utils.h affine_test_SOURCES = affine-test.c utils.c utils.h alphamap_SOURCES = alphamap.c utils.c utils.h diff --git a/test/ds.c b/test/ds.c new file mode 100644 index 0000000..fb574f0 --- /dev/null +++ b/test/ds.c @@ -0,0 +1,163 @@ + +#include "config.h" + +//#include <pixman/pixman.h> +#include "pixman/pixman-private.h" +#include "pixman/pixman-combine32.h" +#include "pixman/pixman-orccode.h" + +#include <orc/orc.h> + +#include <stdint.h> +#include <stdlib.h> +#include <stdio.h> + +#define ORC_CLAMP(x,a,b) ((x)<(a) ? (a) : ((x)>(b) ? (b) : (x))) + +#define COMPOSITE_OVER(d,s,m) (ORC_MULDIV_255((d),(255-m)) + (s)) +#define COMPOSITE_ADD(d,s) ORC_CLAMP((d) + (s), 0, 255) +#define COMPOSITE_IN(s,m) ORC_MULDIV_255((s),(m)) + +#define ORC_DIVIDE_255(x) ((((x)+128) + (((x)+128)>>8))>>8) +#define ORC_MULDIV_255(a,b) ORC_DIVIDE_255((a)*(b)) + +#define ORC_ARGB_A(x) (((x)>>24)&0xff) +#define ORC_ARGB_R(x) (((x)>>16)&0xff) +#define ORC_ARGB_G(x) (((x)>>8)&0xff) +#define ORC_ARGB_B(x) (((x)>>0)&0xff) +#define ORC_ARGB(a,r,g,b) \ + ((ORC_CLAMP((b),0,255)<<0)| \ + (ORC_CLAMP((g),0,255)<<8)| \ + (ORC_CLAMP((r),0,255)<<16)| \ + (ORC_CLAMP((a),0,255)<<24)) + + //((((b)&0xff)<<0)|(((g)&0xff)<<8)|(((r)&0xff)<<16)|(((a)&0xff)<<24)) + +#define randu8() (random()&0xff) + +static uint32_t +combine_mask (const uint32_t *src, const uint32_t *mask, int i) +{ + uint32_t s, m; + + if (mask) + { + m = *(mask + i) >> A_SHIFT; + + if (!m) + return 0; + } + + s = *(src + i); + + if (mask) + UN8x4_MUL_UN8 (s, m); + + return s; +} + +void +combine_over_u (pixman_implementation_t *imp, + pixman_op_t op, + uint32_t * dest, + const uint32_t * src, + const uint32_t * mask, + int width) +{ + int i; + + for (i = 0; i < width; ++i) + { + uint32_t s = combine_mask (src, mask, i); + uint32_t d = *(dest + i); + uint32_t ia = ALPHA_8 (~s); + + UN8x4_MUL_UN8_ADD_UN8x4 (d, ia, s); + *(dest + i) = d; + } +} + + +uint32_t dest_orig[256]; +uint32_t dest[256]; +uint32_t dest_ref[256]; +uint32_t src[256]; +uint32_t mask[256]; + +uint32_t rand_argb(void) +{ + int a = randu8(); + +#if 0 + return ORC_ARGB(a, + ORC_MULDIV_255(randu8(),a), + ORC_MULDIV_255(randu8(),a), + ORC_MULDIV_255(randu8(),a)); +#endif + return ORC_ARGB(a, + randu8(), + randu8(), + randu8()); +} + +int main (int argc, char *argv[]) +{ + int i; + + orc_init(); + + for(i=0;i<256;i++){ + //dest_orig[i]=ORC_ARGB(255,0,0,255); + dest_orig[i]=rand_argb(); + dest[i]=dest_orig[i]; + dest_ref[i]=dest_orig[i]; + } + + for(i=0;i<256;i++){ + //src[i]=ORC_ARGB(i,i,0,0); + src[i]=rand_argb(); + } + + for(i=0;i<256;i++){ + mask[i]=ORC_ARGB(255,0,0,0); + } + + //combine_over_u (NULL, 0, dest, src, mask, 256); + combine_over_u (NULL, 0, dest_ref, src, NULL, 256); + //orc_code_combine_over_u_n (dest, src, 256); + + for(i=0;i<256;i++){ + int a = ORC_ARGB_A(src[i]); + dest[i] = ORC_ARGB( + COMPOSITE_OVER(ORC_ARGB_A(dest[i]), ORC_ARGB_A(src[i]), a), + COMPOSITE_OVER(ORC_ARGB_R(dest[i]), ORC_ARGB_R(src[i]), a), + COMPOSITE_OVER(ORC_ARGB_G(dest[i]), ORC_ARGB_G(src[i]), a), + COMPOSITE_OVER(ORC_ARGB_B(dest[i]), ORC_ARGB_B(src[i]), a)); + + } + + for(i=0;i<256;i++){ + printf("%02x %02x %02x %02x %02x %02x %02x %02x -> " + "%02x %02x %02x %02x %02x %02x %02x %02x %s\n", + ORC_ARGB_A(dest_orig[i]), + ORC_ARGB_R(dest_orig[i]), + ORC_ARGB_G(dest_orig[i]), + ORC_ARGB_B(dest_orig[i]), + ORC_ARGB_A(src[i]), + ORC_ARGB_R(src[i]), + ORC_ARGB_G(src[i]), + ORC_ARGB_B(src[i]), + ORC_ARGB_A(dest_ref[i]), + ORC_ARGB_R(dest_ref[i]), + ORC_ARGB_G(dest_ref[i]), + ORC_ARGB_B(dest_ref[i]), + ORC_ARGB_A(dest[i]), + ORC_ARGB_R(dest[i]), + ORC_ARGB_G(dest[i]), + ORC_ARGB_B(dest[i]), + (dest[i] == dest_ref[i]) ? "":"*"); + } + + return 0; +} + |