From ee7304700b2f058864d6ef588531399eb9104ea9 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 3 May 2013 14:38:52 +0200 Subject: PNG error handling, extreme --- tools/img2c/img2c.cc | 69 ++++++++++++++++++++++----------------------------- tools/img2c/img2c.pro | 11 ++++++++ 2 files changed, 41 insertions(+), 39 deletions(-) create mode 100644 tools/img2c/img2c.pro (limited to 'tools') diff --git a/tools/img2c/img2c.cc b/tools/img2c/img2c.cc index e24d2b3..ebff6d7 100644 --- a/tools/img2c/img2c.cc +++ b/tools/img2c/img2c.cc @@ -7,43 +7,34 @@ 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(); + if(argc < 3) { + printf("Missing parameter [inputfile] [outputfile]\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; + } + + FILE *fp = fopen(name.toStdString().c_str(), "w"); + + unsigned int w = img.width(); + unsigned int h = img.height(); + (void)fwrite(&w, sizeof(unsigned int), 1, fp); + (void)fwrite(&h, sizeof(unsigned int), 1, fp); + + for(int y = 0; y < img.height(); y++) { + for(int x = 0; x < img.width(); x++) { + unsigned int px = img.pixel(x, y); + (void)fwrite(&px, 1, sizeof(unsigned int), fp); + } + } + + fclose(fp); + return 0; } diff --git a/tools/img2c/img2c.pro b/tools/img2c/img2c.pro new file mode 100644 index 0000000..08907d5 --- /dev/null +++ b/tools/img2c/img2c.pro @@ -0,0 +1,11 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Fri May 3 14:05:24 2013 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . + +# Input +SOURCES += img2c.cc -- cgit v1.2.3