4 * Copyright (C) 2009-2014 Cyril Hrubis <metan@ucw.cz>
11 #include <core/GP_WritePixel.h>
15 static void dump_buffer(const char *name, char *buf, unsigned int buf_len)
19 printf("%s:\n{", name);
21 for (i = 0; i < buf_len; i++) {
22 printf("%i", !!buf[i]);
35 * Compares two statically defined buffers
37 #define COMPARE_BUFFERS(id, buf1, buf2) do { \
38 unsigned int buf_len = sizeof(buf2)/sizeof(*buf2); \
42 for (i = 0; i < buf_len; i++) \
43 if(buf1[i] != buf2[i]) { \
45 dump_buffer("wrote", buf1, buf_len); \
46 dump_buffer("gen", buf2, buf_len); \
47 tst_msg("Buffers are different"); \
54 @ for pixelsize in [8, 16, 24, 32]:
55 @ for offset in range(0, 4):
56 @ for len in range(0, 6):
57 @ for aligment in [0, 4]:
58 @ if (pixelsize != 16 and pixelsize != 32) or aligment == 0:
59 static int WritePixel{{ "_%i_%i_%i_%i" % (pixelsize, offset, len, aligment) }}(void)
61 char write_buf[{{ 25 * pixelsize//8 }}] = {};
62 char gen_buf[{{ 25 * pixelsize//8 }}] = {};
65 * Fill the compare buffer
67 @ for i in range(0, len):
68 @ for j in range(0, pixelsize//8):
69 gen_buf[{{aligment + offset * pixelsize//8 + i * pixelsize//8 + j}}] = 0xff;
72 GP_WritePixels_{{ pixelsize }}BPP(write_buf + {{aligment + offset * pixelsize//8}}, {{ len }}, 0xffffffff>>{{32 - pixelsize}});
74 COMPARE_BUFFERS({{'"p=%i o=%i l=%i a=%i"' % (pixelsize, offset, len, aligment)}}, write_buf, gen_buf);
77 static int WritePixel{{ "_%i_%i_%i_%i_alloc" % (pixelsize, offset, len, aligment) }}(void)
79 char gen_buf[{{ 25 * pixelsize//8 }}] = {};
80 char *write_buf = malloc({{ 25 * pixelsize//8 }});
83 * Fill the compare buffer
85 @ for i in range(0, len):
86 @ for j in range(0, pixelsize//8):
87 gen_buf[{{aligment + offset * pixelsize//8 + i * pixelsize//8 + j}}] = 0xff;
90 if (gen_buf == NULL) {
91 tst_msg("Malloc failed :(");
95 memset(write_buf, 0, {{ 25 * pixelsize//8 }});
97 GP_WritePixels_{{ pixelsize }}BPP(write_buf + {{aligment + offset * pixelsize//8}}, {{ len }}, 0xffffffff>>{{32 - pixelsize}});
99 COMPARE_BUFFERS({{'"p=%i o=%i l=%i a=%i"' % (pixelsize, offset, len, aligment)}}, write_buf, gen_buf);
103 const struct tst_suite tst_suite = {
104 .suite_name = "WritePixel Testsuite",
106 @ for pixelsize in [8, 16, 24, 32]:
107 @ for offset in range(0, 4):
108 @ for len in range(0, 6):
109 @ for aligment in [0, 4]:
110 @ if (pixelsize != 16 and pixelsize != 32) or aligment == 0:
111 {.name = "WritePixel {{ pixelsize }} {{ offset }} {{ len }} {{ aligment }} stack",
112 .tst_fn = WritePixel{{ "_%i_%i_%i_%i" % (pixelsize, offset, len, aligment) }}},
113 {.name = "WritePixel {{ pixelsize }} {{ offset }} {{ len }} {{ aligment }} alloc",
114 .tst_fn = WritePixel{{ "_%i_%i_%i_%i_alloc" % (pixelsize, offset, len, aligment) }}},