pgm.c

00001 #include <stdio.h>
00002 
00003 main(int argc, char **argv)
00004 {
00005   int width, height, shift, x, y, i;
00006   unsigned short row[7000];
00007   unsigned char out[7000];
00008   char str[64];
00009   int min[4], max[4], count[4];
00010   long long total[4];
00011 
00012   if (argc < 4) {
00013     fprintf(stderr,"Usage:  %s <width> <height> <shift>\n",argv[0]);
00014     exit(1);
00015   }
00016   width =atoi(argv[1]);
00017   height=atoi(argv[2]);
00018   shift =atoi(argv[3]);
00019 
00020   printf("P5 %d %d 255\n", width, height);
00021 
00022   for (i=0; i < 4; i++) {
00023     max[i]=count[i]=total[i]=0;
00024     min[i]=0xfffffff;
00025   }
00026 
00027   for (y=0; y < height; y++) {
00028     fread (row, 2, width, stdin);
00029     for (x=0; x < width; x++) {
00030       i = ((y << 1) & 2) + (x & 1);
00031       if (max[i] < row[x]) max[i] = row[x];
00032       if (min[i] > row[x]) min[i] = row[x];
00033       count[i]++;
00034       total[i] += row[x];
00035       out[x] = row[x] >> shift;
00036     }
00037     fwrite (out, 1, width, stdout);
00038   }
00039 
00040   for (i=0; i < 4; i++) {
00041     fprintf (stderr,"min=%d  max=%d  avg=%f\n",
00042     min[i],max[i],(float) total[i]/count[i]);
00043   }
00044 }

Generated on Sat Jan 27 11:36:13 2007 for libopenraw by  doxygen 1.4.7