home *** CD-ROM | disk | FTP | other *** search
- /* BASED ON... */
- /*
- * writeimg -
- * Write out an RGB image file. This example uses three functions
- * from the image library:
- *
- * iopen, putrow, and iclose.
- *
- * The function iopen is called to describe the xsize and ysize of the
- * RGB image to be written out.
- *
- * The function putrow writes a row of image data to the image file. It is
- * called with an array of shorts with values in the range [0..255].
- *
- * The function iclose is called to close the image file.
- *
- * Why not modify this program to be a filter that converts from your own
- * image file format to IRIS images?
- *
- * Paul Haeberli - 1987
- *
- */
-
- /*
- * ppmtoiris - Garrett A. Wollman - wollman@newton - January 1991
- * also based on ppmcscale.c by Jef Poskanzer (Copyright 1989)
- *
- * Convert a Portable PixelMap to Iris format.
- */
-
- #include <stdio.h>
- #include "ppm.h"
- #include "image.h"
-
- unsigned short rbuf[4096];
- unsigned short gbuf[4096];
- unsigned short bbuf[4096];
-
- main(argc,argv)
- int argc;
- char **argv;
- {
- IMAGE *image;
- FILE *ifd;
- register pixel *pixelrow, *pP;
- int rows,cols,format,row;
- register int col;
- pixval maxval;
- int i;
-
- pm_progname = argv[0];
- if(argc<3) {
- fprintf(stderr,"usage ppmtoiris in out\n");
- exit(1);
- }
-
- ifd = pm_openr(argv[1]);
-
- ppm_readppminit(ifd,&cols,&rows,&maxval,&format);
- pixelrow = ppm_allocrow(cols);
-
- image = iopen(argv[2],"w",RLE(1),3,cols,rows,3);
- for (row=0; row<rows; row++) {
- ppm_readppmrow(ifd,pixelrow,cols,maxval,format);
- for(col = 0, pP = pixelrow; col < cols; col++,pP++) {
- rbuf[col] = PPM_GETR(*pP);
- gbuf[col] = PPM_GETG(*pP);
- bbuf[col] = PPM_GETB(*pP);
- }
- putrow(image,rbuf,row,0); /* red row */
- putrow(image,gbuf,row,1); /* green row */
- putrow(image,bbuf,row,2); /* blue row */
- }
- iclose(image);
- pm_close(ifd);
- exit(0);
- }
-