summaryrefslogtreecommitdiff
path: root/tools/img2c/img2c.cc
blob: e24d2b3ad200fb36eee745d4c10e19a1750ceedc (plain)
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
#include <QApplication>

#include <QImage>

#include <stdio.h>
#include <arpa/inet.h>

int main(int argc, char *argv[])
{
	//  QApplication app(argc, argv);

	

	if(argc < 3) {
		printf("Missing parameter [inputfile] [imgname]\n");
		return 1;
	}

	QString file = argv[1];
	QString name = argv[2];

	QImage img;
	if(!img.load(file)) {
		printf("Could not open file %s\n", file.toStdString().c_str());
		return 1;
	}

	printf("struct __img_%s {\n  size_t width;\n  size_t height;\n  unsigned int pixels[%d];\n  unsigned int order;\n}", name.toStdString().c_str(), img.width() * img.height());
	printf(" img_%s = {\n", name.toStdString().c_str());
	printf("  %d,\n", img.width());
	printf("  %d,\n", img.height());
	printf("  {\n");
	
	for(int y = 0; y < img.height(); y++) {
		for(int x = 0; x < img.width(); x++) {
			printf("    0x%08x", htonl(img.pixel(x, y)));
			if(x != img.width() - 1 || y != img.height() - 1) {
 				printf(",");
			}
			printf("\n");
		}
	}
	printf("  },\n");
	printf("  0x%08x", htonl(0x00010203));
	printf("};\n");

	return 0;
	//	return app.exec();
}