20#include <winpr/image.h>
23static void usage(
const char* name)
25 (void)printf(
"%s <source file> <destination file>\n\n", name);
26 (void)printf(
"\tRead any image format supported by WinPR::wImage\n");
27 (void)printf(
"\tand convert it to raw BGRA data.\n\n");
28 (void)printf(
"\toutput format is a C header with an array ready to be included\n");
31static int dump_data_hex(FILE* fp,
const uint8_t* data,
size_t size)
35 const int rc = fprintf(fp,
"0x%02" PRIx8, data[0]);
40 for (
size_t x = 1; x < size; x++)
44 const int rc = fprintf(fp,
",\n");
50 const int rc = fprintf(fp,
",");
55 const int rc = fprintf(fp,
"0x%02" PRIx8, data[x]);
62static int dump_data(
const wImage* img,
const char* file)
64 FILE* fp = fopen(file,
"w");
67 (void)fprintf(stderr,
"Failed to open file '%s'\n", file);
72 int count = fprintf(fp,
"#pragma once\n");
75 count = fprintf(fp,
"\n");
78 count = fprintf(fp,
"#include <stdint.h>\n");
81 count = fprintf(fp,
"\n");
84 count = fprintf(fp,
"static const uint8_t img_data[] ={\n");
87 count = dump_data_hex(fp, img->data, 1ULL * img->height * img->scanline);
90 count = fprintf(fp,
"};\n");
99int main(
int argc,
char* argv[])
108 const char* src = argv[1];
109 const char* dst = argv[2];
110 wImage* img = winpr_image_new();
114 const int res = winpr_image_read(img, src);
117 (void)fprintf(stderr,
"Failed to read image file '%s'\n", src);
121 rc = dump_data(img, dst);
124 (void)printf(
"Converted '%s' to header '%s'\n", src, dst);
128 winpr_image_free(img, TRUE);