25 while( ch==
' ' && !feof(fp))
40 if(ch>=
'0' && ch<=
'9')
42 }
while(!feof(fp) && i<maxLen-1 && ch!=
' ');
46 return i<maxLen && !feof(fp);
51 writePPM(
const char *fileName,
unsigned char *data,
int width,
int height )
53 FILE *file = fopen( fileName,
"wb" );
55 printf(
"Could not open file %s for writing\n", fileName );
60 fprintf( file,
"P6\n# generated by patt_to_ppm\n%d %d\n255\n", width, height );
61 fwrite( data, width*height*3, 1, file );
72 FILE* fp = fopen(nFileName,
"r");
77 const int strMax = 256, numPix = nMarkerWidth*nMarkerHeight;
78 unsigned char* pixels24 =
new unsigned char[numPix*3];
82 for(channel=0; channel<3; channel++)
83 for(y=0; y<nMarkerHeight; y++)
85 for(x=0; x<nMarkerWidth; x++)
89 int value = atoi(str);
90 int offset = 3*(x + y*nMarkerWidth) + channel;
91 assert(offset < numPix*3);
92 pixels24[offset] = value;
103 int main(
int argc,
char** argv)
105 unsigned char *patternImage;
106 int width = 16, height = 16;
110 printf(
"ERROR: to few parameters\n");
111 printf(
"Usage: %s infilename outfilename [width=16] [height=16]\n", argv[0] );
112 printf(
"Example: %s patt.hiro patt_hiro.ppm 32 32\n", argv[0] );
116 const char *inName = argv[1],
120 width = atoi( argv[3] );
122 height = atoi( argv[4] );
127 writePPM( outName, patternImage, width, height );
char skipSpaces(FILE *fp)
TFSIMD_FORCE_INLINE const tfScalar & y() const
bool writePPM(const char *fileName, unsigned char *data, int width, int height)
unsigned char * readMarkerFile(const char *nFileName, int nMarkerWidth, int nMarkerHeight)
bool readNumber(FILE *fp, char *buffer, int maxLen)
TFSIMD_FORCE_INLINE const tfScalar & x() const
int main(int argc, char **argv)