1 /*****************************************************************************
2 * Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU Lesser General Public License as *
6 * published by the Free Software Foundation; either version 2.1 of the *
7 * License, or (at your option) version 3, or any later version accepted *
8 * by the membership of KDE e.V. (or its successor approved by the *
9 * membership of KDE e.V.), which shall act as a proxy defined in *
10 * Section 6 of version 3 of the license. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15 * Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with this library. If not, *
19 * see <http://www.gnu.org/licenses/>. *
20 *****************************************************************************/
21
22 #include "stdio.h"
23
24 int
main(int argc,char ** argv)25 main(int argc, char **argv)
26 {
27 if (argc < 4)
28 return 1;
29 const char *filename = argv[1];
30 const char *varname = argv[2];
31 const char *outputname = argv[3];
32 FILE *outputfile = fopen(outputname, "w");
33 fprintf(outputfile, "#ifndef __QTC_IMAGE_HDR_%s__\n"
34 "#define __QTC_IMAGE_HDR_%s__\n", varname, varname);
35 fprintf(outputfile,
36 "static constexpr unsigned char _%s_data[] = {", varname);
37 int size = 0;
38 unsigned char buff;
39 FILE *inputfile = fopen(filename, "r");
40 while (fread(&buff, 1, 1, inputfile)) {
41 fprintf(outputfile, "%u,", (unsigned)buff);
42 size++;
43 }
44 fclose(inputfile);
45 fprintf(outputfile, "};\n"
46 "static const QImage %s __attribute__((unused)) = "
47 "QImage::fromData(_%s_data, %d);\n"
48 "#endif\n", varname, varname, size);
49 fclose(outputfile);
50 return 0;
51 }
52