1 | // [Blend2D] |
2 | // 2D Vector Graphics Powered by a JIT Compiler. |
3 | // |
4 | // [License] |
5 | // Zlib - See LICENSE.md file in the package. |
6 | |
7 | #include "./blapi-build_p.h" |
8 | #include "./blpixelops_p.h" |
9 | #include "./blsupport_p.h" |
10 | |
11 | // ============================================================================ |
12 | // [BLPixelUtils - Unit Test] |
13 | // ============================================================================ |
14 | |
15 | #ifdef BL_TEST |
16 | UNIT(blend2d_pixelops_xrgb32_0888_from_xrgb16_0555) { |
17 | uint32_t c = 0; |
18 | |
19 | for (;;) { |
20 | uint32_t r = ((c >> 10) & 0x1F) << 3; |
21 | uint32_t g = ((c >> 5) & 0x1F) << 3; |
22 | uint32_t b = ((c ) & 0x1F) << 3; |
23 | |
24 | uint32_t result = bl_xrgb32_0888_from_xrgb16_0555(c); |
25 | uint32_t expected = blRgba32Pack(r + (r >> 5), g + (g >> 5), b + (b >> 5), 0xFF); |
26 | |
27 | EXPECT(result == expected, |
28 | "xrgb32_0888_from_xrgb16_0555() - %08X -> %08X (Expected %08X)" , c, result, expected); |
29 | |
30 | if (c == 0xFFFF) |
31 | break; |
32 | c++; |
33 | } |
34 | } |
35 | |
36 | UNIT(blend2d_pixelops_xrgb32_0888_from_xrgb16_0565) { |
37 | uint32_t c = 0; |
38 | |
39 | for (;;) { |
40 | uint32_t r = ((c >> 11) & 0x1F) << 3; |
41 | uint32_t g = ((c >> 5) & 0x3F) << 2; |
42 | uint32_t b = ((c ) & 0x1F) << 3; |
43 | |
44 | uint32_t result = bl_xrgb32_0888_from_xrgb16_0565(c); |
45 | uint32_t expected = blRgba32Pack(r + (r >> 5), g + (g >> 6), b + (b >> 5), 0xFF); |
46 | |
47 | EXPECT(result == expected, |
48 | "xrgb32_0888_from_xrgb16_0555() - %08X -> %08X (Expected %08X)" , c, result, expected); |
49 | |
50 | if (c == 0xFFFF) |
51 | break; |
52 | c++; |
53 | } |
54 | } |
55 | |
56 | UNIT(blend2d_pixelops_argb32_8888_from_argb16_4444) { |
57 | uint32_t c = 0; |
58 | |
59 | for (;;) { |
60 | uint32_t a = ((c >> 12) & 0xF) * 0x11; |
61 | uint32_t r = ((c >> 8) & 0xF) * 0x11; |
62 | uint32_t g = ((c >> 4) & 0xF) * 0x11; |
63 | uint32_t b = ((c ) & 0xF) * 0x11; |
64 | |
65 | uint32_t result = bl_argb32_8888_from_argb16_4444(c); |
66 | uint32_t expected = blRgba32Pack(r, g, b, a); |
67 | |
68 | EXPECT(result == expected, |
69 | "argb32_8888_from_argb16_4444() - %08X -> %08X (Expected %08X)" , c, result, expected); |
70 | |
71 | if (c == 0xFFFF) |
72 | break; |
73 | c++; |
74 | } |
75 | } |
76 | |
77 | UNIT(blend2d_pixelops_prgb32_8888_from_argb32_8888) { |
78 | uint32_t i; |
79 | uint32_t c = 0; |
80 | |
81 | for (i = 0; i < 10000000; i++) { |
82 | uint32_t a = (c >> 24) & 0xFF; |
83 | uint32_t r = (c >> 16) & 0xFF; |
84 | uint32_t g = (c >> 8) & 0xFF; |
85 | uint32_t b = (c ) & 0xFF; |
86 | |
87 | uint32_t result = bl_prgb32_8888_from_argb32_8888(c); |
88 | uint32_t expected = blRgba32Pack(blUdiv255(r * a), blUdiv255(g * a), blUdiv255(b * a), a); |
89 | |
90 | EXPECT(result == expected, |
91 | "prgb32_8888_from_argb32_8888() - %08X -> %08X (Expected %08X)" , c, result, expected); |
92 | |
93 | c += 7919; |
94 | } |
95 | } |
96 | #endif |
97 | |