#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!=2) 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::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()); }