25 if( fscanf(fp,
"%s", word) ){
29 while( fscanf( fp,
"%c", &dummyChar ) && dummyChar !=
'\n' )
40 readPPM(
const char *fileName,
unsigned char **data,
int *width,
int *height )
45 FILE* fp = fopen(fileName,
"rb");
48 printf(
"could not open %s for reading\n", fileName );
56 if( cP !=
'P' || c6 !=
'6'){
57 printf(
"%s is not a ppm P6 file!\n", fileName );
65 sscanf( word,
"%d", width );
66 fscanf( fp,
"%d", height );
72 sscanf( word,
"%d", &dummyInt );
75 int chunkSize = (*width)*(*height)*3*
sizeof(
unsigned char );
77 *data =
new unsigned char[(*width)*(*height)*3];
80 n = fread( *data, 1, chunkSize, fp );
83 printf(
"read %d bytes, expected %d bytes, file truncated?\n", n,
95 rotate(
unsigned char *data,
int width,
int height )
99 unsigned char *tmp =
new unsigned char[width*height*3];
101 for( i = 0; i < width; ++i )
102 for( j = 0; j < height; ++j ){
103 tmp[((width-i-1)*height+j)*3] = data[(j*width+i)*3];
104 tmp[((width-i-1)*height+j)*3+1] = data[(j*width+i)*3+1];
105 tmp[((width-i-1)*height+j)*3+2] = data[(j*width+i)*3+2];
108 memcpy(data, tmp, width*height*3*
sizeof(
unsigned char));
122 fp = fopen( fileName,
"w" );
123 if( fp ==
NULL )
return false;
125 src =
new unsigned char[width*height*3];
126 memcpy( src, data, width*height*3*
sizeof(
unsigned char));
128 for( i = 0; i < 4; i++ ) {
129 for( j = 0; j < 3; j++ ) {
130 for( y = 0; y < height; y++ ) {
131 for( x = 0; x < width; x++ ) {
132 fprintf( fp,
"%4d", src[(y*width+x)*3+j] );
140 rotate( src, width, height );
163 for( i = 0; i < width; ++i )
164 for( j = 0; j < height; ++j ){
165 tmp = data[(j*width+i)*3];
166 data[(j*width+i)*3] = data[(j*width+i)*3+2];
167 data[(j*width+i)*3+2] = tmp;
174 unsigned char *ppmData =
NULL;
175 int width = 0, height = 0;
179 printf(
"ERROR: too few parameters\n");
180 printf(
"Usage: %s ppm_infilename pattern_outfilename\n", argv[0] );
181 printf(
"Example: %s patt_custom.ppm patt.custom\n", argv[0] );
185 const char *inName = argv[1],
189 if( !
readPPM(inName, &ppmData, &width, &height) )
void rotate(unsigned char *data, int width, int height)
TFSIMD_FORCE_INLINE const tfScalar & y() const
void convert2BGR(unsigned char *data, int width, int height)
TFSIMD_FORCE_INLINE const tfScalar & x() const
int main(int argc, char **argv)
bool writeMarkerFile(const char *fileName, unsigned char *data, int width, int height)
void skipComments(FILE *fp, char *word)
bool readPPM(const char *fileName, unsigned char **data, int *width, int *height)