4#include <winpr/image.h>
6static const int formats[] = { WINPR_IMAGE_BITMAP, WINPR_IMAGE_PNG, WINPR_IMAGE_JPEG,
9static void usage(
int argc,
char* argv[])
11 const char* prg =
"INVALID";
15 (void)fprintf(stdout,
"%s <src> <dst>\n", prg);
16 (void)fprintf(stdout,
"\tConvert image <src> to <dst>\n");
17 (void)fprintf(stdout,
"\tSupported formats (for this build):\n");
19 for (
size_t x = 0; x < ARRAYSIZE(formats); x++)
21 const int format = formats[x];
22 const char* ext = winpr_image_format_extension(format);
23 const char* mime = winpr_image_format_mime(format);
24 const BOOL supported = winpr_image_format_is_supported(format);
27 (void)fprintf(stdout,
"\t\t%s [.%s]\n", mime, ext);
32static int detect_format(
const char* name)
34 const char* dot = strrchr(name,
'.');
37 (void)fprintf(stderr,
"'%s' does not have a file extension\n", name);
41 for (
size_t x = 0; x < ARRAYSIZE(formats); x++)
43 const int format = formats[x];
44 const char* ext = winpr_image_format_extension(format);
45 const char* mime = winpr_image_format_mime(format);
46 const BOOL supported = winpr_image_format_is_supported(format);
47 if (strcmp(&dot[1], ext) == 0)
49 (void)fprintf(stdout,
"'%s' is of format %s [supported:%s]\n", name, mime,
50 supported ?
"true" :
"false");
57 (void)fprintf(stderr,
"'%s' is a unsupported format\n", name);
61int main(
int argc,
char* argv[])
70 const char* src = argv[1];
71 const char* dst = argv[2];
73 const int sfmt = detect_format(src);
74 const int dfmt = detect_format(dst);
75 if ((sfmt < 0) || (dfmt < 0))
81 wImage* img = winpr_image_new();
87 const int rrc = winpr_image_read(img, src);
90 (void)fprintf(stderr,
"Failed to read image '%s': %d\n", src, rrc);
93 const int wrc = winpr_image_write(img, dst);
96 (void)fprintf(stderr,
"Failed to write image '%s': %d\n", dst, wrc);
100 (void)fprintf(stdout,
"Successfully converted '%s' to '%s'\n", src, dst);
103 winpr_image_free(img, TRUE);