2 #include <winpr/string.h>
3 #include <winpr/assert.h>
4 #include <winpr/file.h>
5 #include <winpr/path.h>
6 #include <winpr/image.h>
8 static const char test_src_filename[] = TEST_SOURCE_PATH
"/rgb";
9 static const char test_bin_filename[] = TEST_BINARY_PATH
"/rgb";
11 static BOOL test_image_equal(
const wImage* imageA,
const wImage* imageB)
13 return winpr_image_equal(imageA, imageB,
14 WINPR_IMAGE_CMP_IGNORE_DEPTH | WINPR_IMAGE_CMP_IGNORE_ALPHA |
15 WINPR_IMAGE_CMP_FUZZY);
18 static BOOL test_equal_to(
const wImage* bmp,
const char* name, UINT32 format)
21 wImage* cmp = winpr_image_new();
25 char path[MAX_PATH] = { 0 };
26 (void)_snprintf(path,
sizeof(path),
"%s.%s", name, winpr_image_format_extension(format));
27 const int cmpSize = winpr_image_read(cmp, path);
30 (void)fprintf(stderr,
"[%s] winpr_image_read failed for %s", __func__, path);
34 rc = test_image_equal(bmp, cmp);
36 (void)fprintf(stderr,
"[%s] winpr_image_eqal failed", __func__);
39 winpr_image_free(cmp, TRUE);
43 static BOOL test_equal(
void)
46 wImage* bmp = winpr_image_new();
51 char path[MAX_PATH] = { 0 };
52 (void)_snprintf(path,
sizeof(path),
"%s.bmp", test_src_filename);
53 PathCchConvertStyleA(path,
sizeof(path), PATH_STYLE_NATIVE);
55 const int bmpSize = winpr_image_read(bmp, path);
58 (void)fprintf(stderr,
"[%s] winpr_image_read failed for %s", __func__, path);
62 for (UINT32 x = 0; x < UINT8_MAX; x++)
64 if (!winpr_image_format_is_supported(x))
66 if (!test_equal_to(bmp, test_src_filename, x))
72 winpr_image_free(bmp, TRUE);
77 static BOOL test_read_write_compare(
const char* tname,
const char* tdst, UINT32 format)
80 wImage* bmp1 = winpr_image_new();
81 wImage* bmp2 = winpr_image_new();
82 wImage* bmp3 = winpr_image_new();
83 if (!bmp1 || !bmp2 || !bmp3)
86 char spath[MAX_PATH] = { 0 };
87 char dpath[MAX_PATH] = { 0 };
88 char bpath1[MAX_PATH] = { 0 };
89 char bpath2[MAX_PATH] = { 0 };
90 (void)_snprintf(spath,
sizeof(spath),
"%s.%s", tname, winpr_image_format_extension(format));
91 (void)_snprintf(dpath,
sizeof(dpath),
"%s.%s", tdst, winpr_image_format_extension(format));
92 (void)_snprintf(bpath1,
sizeof(bpath1),
"%s.src.%s", dpath,
93 winpr_image_format_extension(WINPR_IMAGE_BITMAP));
94 (void)_snprintf(bpath2,
sizeof(bpath2),
"%s.bin.%s", dpath,
95 winpr_image_format_extension(WINPR_IMAGE_BITMAP));
96 PathCchConvertStyleA(spath,
sizeof(spath), PATH_STYLE_NATIVE);
97 PathCchConvertStyleA(dpath,
sizeof(dpath), PATH_STYLE_NATIVE);
98 PathCchConvertStyleA(bpath1,
sizeof(bpath1), PATH_STYLE_NATIVE);
99 PathCchConvertStyleA(bpath2,
sizeof(bpath2), PATH_STYLE_NATIVE);
101 const int bmpRSize = winpr_image_read(bmp1, spath);
104 (void)fprintf(stderr,
"[%s] winpr_image_read failed for %s", __func__, spath);
108 const int bmpWSize = winpr_image_write(bmp1, dpath);
111 (void)fprintf(stderr,
"[%s] winpr_image_write failed for %s", __func__, dpath);
115 const int bmp2RSize = winpr_image_read(bmp2, dpath);
118 (void)fprintf(stderr,
"[%s] winpr_image_read failed for %s", __func__, dpath);
122 const int bmpSrcWSize = winpr_image_write_ex(bmp1, WINPR_IMAGE_BITMAP, bpath1);
123 if (bmpSrcWSize <= 0)
125 (void)fprintf(stderr,
"[%s] winpr_image_write_ex failed for %s", __func__, bpath1);
131 const int bmpBinWSize = winpr_image_write_ex(bmp2, WINPR_IMAGE_BITMAP, bpath2);
132 if (bmpBinWSize <= 0)
134 (void)fprintf(stderr,
"[%s] winpr_image_write_ex failed for %s", __func__, bpath2);
138 const int bmp3RSize = winpr_image_read(bmp3, bpath2);
141 (void)fprintf(stderr,
"[%s] winpr_image_read failed for %s", __func__, bpath2);
145 if (!winpr_image_equal(bmp1, bmp2,
146 WINPR_IMAGE_CMP_IGNORE_DEPTH | WINPR_IMAGE_CMP_IGNORE_ALPHA |
147 WINPR_IMAGE_CMP_FUZZY))
149 (void)fprintf(stderr,
"[%s] winpr_image_eqal failed bmp1 bmp2", __func__);
153 rc = winpr_image_equal(bmp3, bmp2,
154 WINPR_IMAGE_CMP_IGNORE_DEPTH | WINPR_IMAGE_CMP_IGNORE_ALPHA |
155 WINPR_IMAGE_CMP_FUZZY);
157 (void)fprintf(stderr,
"[%s] winpr_image_eqal failed bmp3 bmp2", __func__);
159 winpr_image_free(bmp1, TRUE);
160 winpr_image_free(bmp2, TRUE);
161 winpr_image_free(bmp3, TRUE);
165 static BOOL test_read_write(
void)
168 for (UINT32 x = 0; x < UINT8_MAX; x++)
170 if (!winpr_image_format_is_supported(x))
172 if (!test_read_write_compare(test_src_filename, test_bin_filename, x))
178 static BOOL test_load_file(
const char* name)
181 wImage* image = winpr_image_new();
185 const int res = winpr_image_read(image, name);
186 rc = (res > 0) ? TRUE : FALSE;
189 winpr_image_free(image, TRUE);
193 static BOOL test_load(
void)
195 const char* names[] = {
196 "rgb.16a.bmp",
"rgb.16a.nocolor.bmp",
"rgb.16.bmp",
"rgb.16.nocolor.bmp",
197 "rgb.16x.bmp",
"rgb.16x.nocolor.bmp",
"rgb.24.bmp",
"rgb.24.nocolor.bmp",
198 "rgb.32.bmp",
"rgb.32.nocolor.bmp",
"rgb.32x.bmp",
"rgb.32x.nocolor.bmp",
202 for (
size_t x = 0; x < ARRAYSIZE(names); x++)
204 const char* name = names[x];
205 char* fname = GetCombinedPath(TEST_SOURCE_PATH, name);
206 const BOOL res = test_load_file(fname);
215 int TestImage(
int argc,
char* argv[])
225 if (!test_read_write())