-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
test-zrle.c
168 lines (134 loc) · 3.44 KB
/
test-zrle.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include "zrle.h"
#include "rfb-proto.h"
#include <endian.h>
#include <stdio.h>
int test_pixel32_to_cpixel_3(void)
{
static uint32_t src[64] = { 0 };
static uint8_t dst[64 * 3] = { 0 };
struct rfb_pixel_format srcfmt = { 0 }, dstfmt = { 0 };
srcfmt.depth = 24;
srcfmt.bits_per_pixel = 32;
srcfmt.true_colour_flag = 1;
srcfmt.red_max = 255;
srcfmt.green_max = 255;
srcfmt.blue_max = 255;
srcfmt.red_shift = 24;
srcfmt.green_shift = 16;
srcfmt.blue_shift = 8;
dstfmt.depth = 24;
dstfmt.bits_per_pixel = 32;
dstfmt.true_colour_flag = 1;
dstfmt.red_max = 255;
dstfmt.green_max = 255;
dstfmt.blue_max = 255;
dstfmt.red_shift = 8;
dstfmt.green_shift = 16;
dstfmt.blue_shift = 24;
for (int i = 0; i < 64; ++i)
src[i] = 0x12345678;
pixel32_to_cpixel(dst, &dstfmt, src, &srcfmt, 3, 64);
for (int i = 0; i < 64; ++i) {
uint8_t r, g, b;
r = dst[i * 3 + 0];
g = dst[i * 3 + 1];
b = dst[i * 3 + 2];
if (r != 0x12 || g != 0x34 || b != 0x56) {
printf("pixel32_to_cpixel_3 failed\n");
return 1;
}
}
printf("pixel32_to_cpixel_3 ran OK\n");
return 0;
}
int test_pixel32_to_cpixel_2(void)
{
static uint32_t src[64] = { 0 };
static uint16_t dst[64] = { 0 };
struct rfb_pixel_format srcfmt = { 0 }, dstfmt = { 0 };
srcfmt.depth = 24;
srcfmt.bits_per_pixel = 32;
srcfmt.true_colour_flag = 1;
srcfmt.red_max = 255;
srcfmt.green_max = 255;
srcfmt.blue_max = 255;
srcfmt.red_shift = 24;
srcfmt.green_shift = 16;
srcfmt.blue_shift = 8;
dstfmt.depth = 16;
dstfmt.bits_per_pixel = 16;
dstfmt.true_colour_flag = 1;
dstfmt.red_max = 31;
dstfmt.green_max = 63;
dstfmt.blue_max = 31;
dstfmt.red_shift = 11;
dstfmt.green_shift = 5;
dstfmt.blue_shift = 0;
#if __BYTE_ORDER__ == __BIG_ENDIAN__
dstfmt.big_endian_flag = 1;
#endif
for (int i = 0; i < 64; ++i)
src[i] = 0x12345678;
pixel32_to_cpixel((uint8_t*)dst, &dstfmt, src, &srcfmt, 2, 64);
for (int i = 0; i < 64; ++i) {
uint8_t r, g, b;
r = (dst[i] >> 11) & 31;
g = (dst[i] >> 5) & 63;
b = (dst[i] >> 0) & 31;
if (r != (0x12 >> 3) || g != (0x34 >> 2) || b != (0x56 >> 3)) {
printf("pixel32_to_cpixel_2 failed: %x %x %x\n", r, g, b);
return 1;
}
}
printf("pixel32_to_cpixel_2 ran OK\n");
return 0;
}
int test_pixel32_to_cpixel_1(void)
{
static uint32_t src[64] = { 0 };
static uint8_t dst[64] = { 0 };
struct rfb_pixel_format srcfmt = { 0 }, dstfmt = { 0 };
srcfmt.depth = 24;
srcfmt.bits_per_pixel = 32;
srcfmt.true_colour_flag = 1;
srcfmt.red_max = 255;
srcfmt.green_max = 255;
srcfmt.blue_max = 255;
srcfmt.red_shift = 24;
srcfmt.green_shift = 16;
srcfmt.blue_shift = 8;
dstfmt.depth = 8;
dstfmt.bits_per_pixel = 8;
dstfmt.true_colour_flag = 1;
dstfmt.red_max = 7;
dstfmt.green_max = 7;
dstfmt.blue_max = 3;
dstfmt.red_shift = 5;
dstfmt.green_shift = 2;
dstfmt.blue_shift = 0;
#if __BYTE_ORDER__ == __BIG_ENDIAN__
dstfmt.big_endian_flag = 1;
#endif
for (int i = 0; i < 64; ++i)
src[i] = 0x98765432;
pixel32_to_cpixel((uint8_t*)dst, &dstfmt, src, &srcfmt, 1, 64);
for (int i = 0; i < 64; ++i) {
uint8_t r, g, b;
r = (dst[i] >> 5) & 7;
g = (dst[i] >> 2) & 7;
b = (dst[i] >> 0) & 3;
if (r != (0x98 >> 5) || g != (0x76 >> 5) || b != (0x54 >> 6)) {
printf("pixel32_to_cpixel_1 failed: %x %x %x\n", r, g, b);
return 1;
}
}
printf("pixel32_to_cpixel_1 ran OK\n");
return 0;
}
int main()
{
if (test_pixel32_to_cpixel_3()) return 1;
if (test_pixel32_to_cpixel_2()) return 1;
if (test_pixel32_to_cpixel_1()) return 1;
return 0;
}