/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLIO/apps/jpg2cpp/jpg2cpp.cpp ** ** Module : ICLIO ** ** Authors: Christof Elbrechter ** ** ** ** ** ** GNU LESSER GENERAL PUBLIC LICENSE ** ** This file may be used under the terms of the GNU Lesser General ** ** Public License version 3.0 as published by the ** ** ** ** Free Software Foundation and appearing in the file LICENSE.LGPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the license requirements will ** ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** ** ** ** The development of this software was supported by the ** ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** ** Forschungsgemeinschaft (DFG) in the context of the German ** ** Excellence Initiative. ** ** ** ********************************************************************/ #include "stdio.h" #include #include #include using namespace std; int usage(){ printf("jpg2cpp converts jpeg images into a c++ compatible data format.\n" "usage: jpg2cpp > \n" " must be something like myImage.jpg without any \"./foo\"-\n " " or \"../../foo/bar/\"-prefix.\n" " is something like \"ICL/ICLIO/src/demoImageMyImage.cpp\"\n" " The destination file is created in 4 blocks:\n" " - main data block containing most of the binary data of the image\n" " - extra data block containing some additional bytes for the image\n" " - the createImage_xxx() -function block. This is the implementation of\n" " a function, that converts the data- and the extraData-block into an\n" " appropriate ImgBase object. The image is created by using a temporary\n" " jpg file on the hard-disk, which is read using a FileReader object.\n" " - the header information block containing the function declaration for\n" " the according header file\n\n" ); return 1; } int fileNotFound(char *pc){ printf("file %s not found\n",pc); return 1; } void writeLine(vector::iterator &it, int len, bool isLastRow){ printf(" {"); vector::iterator end = it+len-1; while(it != end){ printf("%3d,",*it++); } if(!isLastRow){ printf("%3d},\n",*it++); }else{ printf("%3d}\n};\n",*it++); } } int main(int n, char **ppc){ if(n!=3) return usage(); FILE *f = fopen(ppc[1],"rb"); if(!f) return fileNotFound(ppc[1]); char buf[10000]; vector dataVec; int nBytesRead = 0; while(!feof(f)){ int read = fread(buf,1,10000,f); nBytesRead += read; for(int i=0;i\n"); printf("#include \n"); //------------------------------------------- printf("using namespace icl;\n"); printf("using namespace std;\n"); printf("namespace icl{\n"); printf("namespace{\n"); const int COLS = 30; const int ROWS = nBytesRead/COLS; const int NEXTRA = nBytesRead - COLS*ROWS; printf("const int NROWS = %d;\n",ROWS); printf("const int NCOLS = %d;\n",COLS); printf("const int NEXTRA = %d;\n",NEXTRA); printf("unsigned char %s[NROWS][NCOLS] = {\n",arrayName.c_str()); printf(" // {{{ open\n"); vector::iterator it=dataVec.begin(); for(int l=0;ldeepCopy();\n" " FILE *f = fopen(\"./.tmp_image_buffer.jpg\",\"wb\");\n" " const int DIM = NROWS*NCOLS+NEXTRA;\n" " char *buf= new char[DIM];\n" " int j=0;\n" " for(int i=0;ideepCopy();\n" " remove(\"./.tmp_image_buffer.jpg\");\n" " return image->deepCopy();\n" "}\n// }}}\n\n",arrayName.c_str(),extraArrayName.c_str()); printf("} // end namespace icl\n\n\n"); printf("!!! put this into the header file:\n" "namespace icl{\n" " /// Create the image named %s\n" " ImgBase *createImage_%s();\n" "}\n\n",imageName.c_str(),imageName.c_str()); }