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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
#include <stdio.h>
#include <winpr/string.h>
#include <winpr/assert.h>
#include <winpr/file.h>
#include <winpr/path.h>
#include <winpr/image.h>
static const char test_src_filename[] = TEST_SOURCE_PATH "/rgb";
static const char test_bin_filename[] = TEST_BINARY_PATH "/rgb";
static BOOL test_image_equal(const wImage* imageA, const wImage* imageB)
{
return winpr_image_equal(imageA, imageB,
WINPR_IMAGE_CMP_IGNORE_DEPTH | WINPR_IMAGE_CMP_IGNORE_ALPHA |
WINPR_IMAGE_CMP_FUZZY);
}
static BOOL test_equal_to(const wImage* bmp, const char* name, UINT32 format)
{
BOOL rc = FALSE;
wImage* cmp = winpr_image_new();
if (!cmp)
goto fail;
char path[MAX_PATH] = { 0 };
_snprintf(path, sizeof(path), "%s.%s", name, winpr_image_format_extension(format));
const int cmpSize = winpr_image_read(cmp, path);
if (cmpSize <= 0)
{
fprintf(stderr, "[%s] winpr_image_read failed for %s", __func__, path);
goto fail;
}
rc = test_image_equal(bmp, cmp);
if (!rc)
fprintf(stderr, "[%s] winpr_image_eqal failed", __func__);
fail:
winpr_image_free(cmp, TRUE);
return rc;
}
static BOOL test_equal(void)
{
BOOL rc = FALSE;
wImage* bmp = winpr_image_new();
if (!bmp)
goto fail;
char path[MAX_PATH] = { 0 };
_snprintf(path, sizeof(path), "%s.bmp", test_src_filename);
PathCchConvertStyleA(path, sizeof(path), PATH_STYLE_NATIVE);
const int bmpSize = winpr_image_read(bmp, path);
if (bmpSize <= 0)
{
fprintf(stderr, "[%s] winpr_image_read failed for %s", __func__, path);
goto fail;
}
for (UINT32 x = 0; x < UINT8_MAX; x++)
{
if (!winpr_image_format_is_supported(x))
continue;
if (!test_equal_to(bmp, test_src_filename, x))
goto fail;
}
rc = TRUE;
fail:
winpr_image_free(bmp, TRUE);
return rc;
}
static BOOL test_read_write_compare(const char* tname, const char* tdst, UINT32 format)
{
BOOL rc = FALSE;
wImage* bmp1 = winpr_image_new();
wImage* bmp2 = winpr_image_new();
wImage* bmp3 = winpr_image_new();
if (!bmp1 || !bmp2 || !bmp3)
goto fail;
char spath[MAX_PATH] = { 0 };
char dpath[MAX_PATH] = { 0 };
char bpath1[MAX_PATH] = { 0 };
char bpath2[MAX_PATH] = { 0 };
_snprintf(spath, sizeof(spath), "%s.%s", tname, winpr_image_format_extension(format));
_snprintf(dpath, sizeof(dpath), "%s.%s", tdst, winpr_image_format_extension(format));
_snprintf(bpath1, sizeof(bpath1), "%s.src.%s", dpath,
winpr_image_format_extension(WINPR_IMAGE_BITMAP));
_snprintf(bpath2, sizeof(bpath2), "%s.bin.%s", dpath,
winpr_image_format_extension(WINPR_IMAGE_BITMAP));
PathCchConvertStyleA(spath, sizeof(spath), PATH_STYLE_NATIVE);
PathCchConvertStyleA(dpath, sizeof(dpath), PATH_STYLE_NATIVE);
PathCchConvertStyleA(bpath1, sizeof(bpath1), PATH_STYLE_NATIVE);
PathCchConvertStyleA(bpath2, sizeof(bpath2), PATH_STYLE_NATIVE);
const int bmpRSize = winpr_image_read(bmp1, spath);
if (bmpRSize <= 0)
{
fprintf(stderr, "[%s] winpr_image_read failed for %s", __func__, spath);
goto fail;
}
const int bmpWSize = winpr_image_write(bmp1, dpath);
if (bmpWSize <= 0)
{
fprintf(stderr, "[%s] winpr_image_write failed for %s", __func__, dpath);
goto fail;
}
const int bmp2RSize = winpr_image_read(bmp2, dpath);
if (bmp2RSize <= 0)
{
fprintf(stderr, "[%s] winpr_image_read failed for %s", __func__, dpath);
goto fail;
}
const int bmpSrcWSize = winpr_image_write_ex(bmp1, WINPR_IMAGE_BITMAP, bpath1);
if (bmpSrcWSize <= 0)
{
fprintf(stderr, "[%s] winpr_image_write_ex failed for %s", __func__, bpath1);
goto fail;
}
/* write a bitmap and read it back.
* this tests if we have the proper internal format */
const int bmpBinWSize = winpr_image_write_ex(bmp2, WINPR_IMAGE_BITMAP, bpath2);
if (bmpBinWSize <= 0)
{
fprintf(stderr, "[%s] winpr_image_write_ex failed for %s", __func__, bpath2);
goto fail;
}
const int bmp3RSize = winpr_image_read(bmp3, bpath2);
if (bmp3RSize <= 0)
{
fprintf(stderr, "[%s] winpr_image_read failed for %s", __func__, bpath2);
goto fail;
}
if (!winpr_image_equal(bmp1, bmp2,
WINPR_IMAGE_CMP_IGNORE_DEPTH | WINPR_IMAGE_CMP_IGNORE_ALPHA |
WINPR_IMAGE_CMP_FUZZY))
{
fprintf(stderr, "[%s] winpr_image_eqal failed bmp1 bmp2", __func__);
goto fail;
}
rc = winpr_image_equal(bmp3, bmp2,
WINPR_IMAGE_CMP_IGNORE_DEPTH | WINPR_IMAGE_CMP_IGNORE_ALPHA |
WINPR_IMAGE_CMP_FUZZY);
if (!rc)
fprintf(stderr, "[%s] winpr_image_eqal failed bmp3 bmp2", __func__);
fail:
winpr_image_free(bmp1, TRUE);
winpr_image_free(bmp2, TRUE);
winpr_image_free(bmp3, TRUE);
return rc;
}
static BOOL test_read_write(void)
{
BOOL rc = TRUE;
for (UINT32 x = 0; x < UINT8_MAX; x++)
{
if (!winpr_image_format_is_supported(x))
continue;
if (!test_read_write_compare(test_src_filename, test_bin_filename, x))
rc = FALSE;
}
return rc;
}
static BOOL test_load_file(const char* name)
{
BOOL rc = FALSE;
wImage* image = winpr_image_new();
if (!image || !name)
goto fail;
const int res = winpr_image_read(image, name);
rc = (res > 0) ? TRUE : FALSE;
fail:
winpr_image_free(image, TRUE);
return rc;
}
static BOOL test_load(void)
{
const char* names[] = {
"rgb.16a.bmp", "rgb.16a.nocolor.bmp", "rgb.16.bmp", "rgb.16.nocolor.bmp",
"rgb.16x.bmp", "rgb.16x.nocolor.bmp", "rgb.24.bmp", "rgb.24.nocolor.bmp",
"rgb.32.bmp", "rgb.32.nocolor.bmp", "rgb.32x.bmp", "rgb.32x.nocolor.bmp",
"rgb.bmp"
};
for (size_t x = 0; x < ARRAYSIZE(names); x++)
{
const char* name = names[x];
char* fname = GetCombinedPath(TEST_SOURCE_PATH, name);
const BOOL res = test_load_file(fname);
free(fname);
if (!res)
return FALSE;
}
return TRUE;
}
int TestImage(int argc, char* argv[])
{
int rc = 0;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
if (!test_equal())
rc -= 1;
if (!test_read_write())
rc -= 2;
if (!test_load())
rc -= 4;
return rc;
}
|