/* * readimage - Read an image file and print its pixel values. * * To compile: cc readimage.c -o readimage -limage * * Paul Haeberli - 1991 */ #include main(argc,argv) int argc; char **argv; { IMAGE *image; int x, y, z; short *rbuf, *gbuf, *bbuf; /* print usage message */ if( argc<2 ) { fprintf(stderr,"usage: readimage infile\n"); exit(1); } /* open the image file */ if( (image=iopen(argv[1],"r")) == NULL ) { fprintf(stderr,"readimage: can't open input file %s",argv[1]); exit(1); } /* print a little info about the image */ printf("Image x and y size in pixels: %d %d", image->xsize,image->ysize); printf("Image zsize in channels: %d",image->zsize); printf("Image pixel min and max: %d %d",image->min,image->max); /* allocate buffers for image data */ rbuf = (short *)malloc(image->xsize*sizeof(short)); gbuf = (short *)malloc(image->xsize*sizeof(short)); bbuf = (short *)malloc(image->xsize*sizeof(short)); /* check to see if the image is B/W or RGB */ if(image->zsize == 1) { printf("This is a black and write image"); for(y=0; yysize; y++) { getrow(image,rbuf,y,0); printf("row %d: ",y); for(x=0; xxsize; x++) printf("%d |",rbuf[x]); printf(""); } } else if(image->zsize >= 3) { /* if the image has alpha zsize is 4 */ printf("This is a rgb image"); for(y=0; yysize; y++) { getrow(image,rbuf,y,0); getrow(image,gbuf,y,1); getrow(image,bbuf,y,2); printf("row %d: ",y); for(x=0; xxsize; x++) printf("%d %d %d |",rbuf[x],gbuf[x],bbuf[x]); printf(""); } } }