From 3101d7818d0019ef483d73b87d02b1e10ed466b8 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 26 Jan 2013 08:36:20 +0100 Subject: Image (png) to c-header file (struct) converter. tool. --- tools/img2c/Makefile | 205 +++++++++++++++++++++++++++++++++++++++++++++++++++ tools/img2c/img2c.cc | 49 ++++++++++++ 2 files changed, 254 insertions(+) create mode 100644 tools/img2c/Makefile create mode 100644 tools/img2c/img2c.cc diff --git a/tools/img2c/Makefile b/tools/img2c/Makefile new file mode 100644 index 0000000..df9b7a4 --- /dev/null +++ b/tools/img2c/Makefile @@ -0,0 +1,205 @@ +############################################################################# +# Makefile for building: img2c +# Generated by qmake (2.01a) (Qt 4.7.2) on: Sun Nov 13 13:30:04 2011 +# Project: img2c.pro +# Template: app +# Command: /usr/bin/qmake -o Makefile img2c.pro +############################################################################# + +####### Compiler, tools and options + +CC = gcc +CXX = g++ +DEFINES = -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED +CFLAGS = -pipe -Wall -W -D_REENTRANT $(DEFINES) +CXXFLAGS = -pipe -Wall -W -D_REENTRANT $(DEFINES) +INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. +LINK = g++ +LFLAGS = -Wl,-O1 -Wl,-rpath,/usr/lib/qt4 +LIBS = $(SUBLIBS) -L/usr/lib/qt4 -lQtGui -L/usr/lib/qt4 -L/usr/X11R6/lib -lQtCore -lgthread-2.0 -lrt -lglib-2.0 -lpthread +AR = ar cqs +RANLIB = +QMAKE = /usr/bin/qmake +TAR = tar -cf +COMPRESS = gzip -9f +COPY = cp -f +SED = sed +COPY_FILE = $(COPY) +COPY_DIR = $(COPY) -r +STRIP = strip +INSTALL_FILE = install -m 644 -p +INSTALL_DIR = $(COPY_DIR) +INSTALL_PROGRAM = install -m 755 -p +DEL_FILE = rm -f +SYMLINK = ln -f -s +DEL_DIR = rmdir +MOVE = mv -f +CHK_DIR_EXISTS= test -d +MKDIR = mkdir -p + +####### Output directory + +OBJECTS_DIR = ./ + +####### Files + +SOURCES = img2c.cc +OBJECTS = img2c.o +DIST = /usr/share/qt4/mkspecs/common/g++.conf \ + /usr/share/qt4/mkspecs/common/unix.conf \ + /usr/share/qt4/mkspecs/common/linux.conf \ + /usr/share/qt4/mkspecs/qconfig.pri \ + /usr/share/qt4/mkspecs/modules/qt_phonon.pri \ + /usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \ + /usr/share/qt4/mkspecs/features/qt_functions.prf \ + /usr/share/qt4/mkspecs/features/qt_config.prf \ + /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ + /usr/share/qt4/mkspecs/features/default_pre.prf \ + /usr/share/qt4/mkspecs/features/release.prf \ + /usr/share/qt4/mkspecs/features/default_post.prf \ + /usr/share/qt4/mkspecs/features/warn_on.prf \ + /usr/share/qt4/mkspecs/features/qt.prf \ + /usr/share/qt4/mkspecs/features/unix/thread.prf \ + /usr/share/qt4/mkspecs/features/moc.prf \ + /usr/share/qt4/mkspecs/features/resources.prf \ + /usr/share/qt4/mkspecs/features/uic.prf \ + /usr/share/qt4/mkspecs/features/yacc.prf \ + /usr/share/qt4/mkspecs/features/lex.prf \ + /usr/share/qt4/mkspecs/features/include_source_dir.prf \ + img2c.pro +QMAKE_TARGET = img2c +DESTDIR = +TARGET = img2c + +first: all +####### Implicit rules + +.SUFFIXES: .o .c .cpp .cc .cxx .C + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cc.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cxx.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.C.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" + +####### Build rules + +all: Makefile $(TARGET) + +$(TARGET): $(OBJECTS) + $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) + +Makefile: img2c.pro /usr/share/qt4/mkspecs/linux-g++/qmake.conf /usr/share/qt4/mkspecs/common/g++.conf \ + /usr/share/qt4/mkspecs/common/unix.conf \ + /usr/share/qt4/mkspecs/common/linux.conf \ + /usr/share/qt4/mkspecs/qconfig.pri \ + /usr/share/qt4/mkspecs/modules/qt_phonon.pri \ + /usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \ + /usr/share/qt4/mkspecs/features/qt_functions.prf \ + /usr/share/qt4/mkspecs/features/qt_config.prf \ + /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ + /usr/share/qt4/mkspecs/features/default_pre.prf \ + /usr/share/qt4/mkspecs/features/release.prf \ + /usr/share/qt4/mkspecs/features/default_post.prf \ + /usr/share/qt4/mkspecs/features/warn_on.prf \ + /usr/share/qt4/mkspecs/features/qt.prf \ + /usr/share/qt4/mkspecs/features/unix/thread.prf \ + /usr/share/qt4/mkspecs/features/moc.prf \ + /usr/share/qt4/mkspecs/features/resources.prf \ + /usr/share/qt4/mkspecs/features/uic.prf \ + /usr/share/qt4/mkspecs/features/yacc.prf \ + /usr/share/qt4/mkspecs/features/lex.prf \ + /usr/share/qt4/mkspecs/features/include_source_dir.prf \ + /usr/lib/qt4/libQtGui.prl \ + /usr/lib/qt4/libQtCore.prl + $(QMAKE) -o Makefile img2c.pro +/usr/share/qt4/mkspecs/common/g++.conf: +/usr/share/qt4/mkspecs/common/unix.conf: +/usr/share/qt4/mkspecs/common/linux.conf: +/usr/share/qt4/mkspecs/qconfig.pri: +/usr/share/qt4/mkspecs/modules/qt_phonon.pri: +/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri: +/usr/share/qt4/mkspecs/features/qt_functions.prf: +/usr/share/qt4/mkspecs/features/qt_config.prf: +/usr/share/qt4/mkspecs/features/exclusive_builds.prf: +/usr/share/qt4/mkspecs/features/default_pre.prf: +/usr/share/qt4/mkspecs/features/release.prf: +/usr/share/qt4/mkspecs/features/default_post.prf: +/usr/share/qt4/mkspecs/features/warn_on.prf: +/usr/share/qt4/mkspecs/features/qt.prf: +/usr/share/qt4/mkspecs/features/unix/thread.prf: +/usr/share/qt4/mkspecs/features/moc.prf: +/usr/share/qt4/mkspecs/features/resources.prf: +/usr/share/qt4/mkspecs/features/uic.prf: +/usr/share/qt4/mkspecs/features/yacc.prf: +/usr/share/qt4/mkspecs/features/lex.prf: +/usr/share/qt4/mkspecs/features/include_source_dir.prf: +/usr/lib/qt4/libQtGui.prl: +/usr/lib/qt4/libQtCore.prl: +qmake: FORCE + @$(QMAKE) -o Makefile img2c.pro + +dist: + @$(CHK_DIR_EXISTS) .tmp/img2c1.0.0 || $(MKDIR) .tmp/img2c1.0.0 + $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/img2c1.0.0/ && $(COPY_FILE) --parents img2c.cc .tmp/img2c1.0.0/ && (cd `dirname .tmp/img2c1.0.0` && $(TAR) img2c1.0.0.tar img2c1.0.0 && $(COMPRESS) img2c1.0.0.tar) && $(MOVE) `dirname .tmp/img2c1.0.0`/img2c1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/img2c1.0.0 + + +clean:compiler_clean + -$(DEL_FILE) $(OBJECTS) + -$(DEL_FILE) *~ core *.core + + +####### Sub-libraries + +distclean: clean + -$(DEL_FILE) $(TARGET) + -$(DEL_FILE) Makefile + + +check: first + +mocclean: compiler_moc_header_clean compiler_moc_source_clean + +mocables: compiler_moc_header_make_all compiler_moc_source_make_all + +compiler_moc_header_make_all: +compiler_moc_header_clean: +compiler_rcc_make_all: +compiler_rcc_clean: +compiler_image_collection_make_all: qmake_image_collection.cpp +compiler_image_collection_clean: + -$(DEL_FILE) qmake_image_collection.cpp +compiler_moc_source_make_all: +compiler_moc_source_clean: +compiler_uic_make_all: +compiler_uic_clean: +compiler_yacc_decl_make_all: +compiler_yacc_decl_clean: +compiler_yacc_impl_make_all: +compiler_yacc_impl_clean: +compiler_lex_make_all: +compiler_lex_clean: +compiler_clean: + +####### Compile + +img2c.o: img2c.cc + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o img2c.o img2c.cc + +####### Install + +install: FORCE + +uninstall: FORCE + +FORCE: + 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 + +#include + +#include +#include + +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(); +} -- cgit v1.2.3