diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-01-26 08:36:20 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2013-01-26 08:36:20 +0100 |
commit | 3101d7818d0019ef483d73b87d02b1e10ed466b8 (patch) | |
tree | 70806510add1dca1b0f3fb06a9b49659042f76cc /tools/img2c/img2c.cc | |
parent | 5b777203e3c1f3d8be6ada417acefc21488028e1 (diff) |
Image (png) to c-header file (struct) converter. tool.
Diffstat (limited to 'tools/img2c/img2c.cc')
-rw-r--r-- | tools/img2c/img2c.cc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tools/img2c/img2c.cc b/tools/img2c/img2c.cc new file mode 100644 index 0000000..e24d2b3 --- /dev/null +++ b/tools/img2c/img2c.cc @@ -0,0 +1,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(); +} |