home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3304 / ppmtoiris.c
Encoding:
C/C++ Source or Header  |  1991-05-09  |  1.8 KB  |  78 lines

  1. /* BASED ON... */
  2. /*
  3.  *    writeimg -
  4.  *        Write out an RGB image file.  This example uses three functions
  5.  *    from the image library: 
  6.  *
  7.  *        iopen, putrow, and iclose.    
  8.  *
  9.  *     The function iopen is called to describe the xsize and ysize of the 
  10.  *    RGB image to be written out.  
  11.  *
  12.  *    The function putrow writes a row of image data to the image file. It is
  13.  *    called with an array of shorts with values in the range [0..255].
  14.  *    
  15.  *    The function iclose is called to close the image file.
  16.  *
  17.  *    Why not modify this program to be a filter that converts from your own
  18.  *    image file format to IRIS images? 
  19.  *
  20.  *                Paul Haeberli - 1987
  21.  *
  22.  */
  23.  
  24. /*
  25.  * ppmtoiris - Garrett A. Wollman - wollman@newton - January 1991
  26.  * also based on ppmcscale.c by Jef Poskanzer (Copyright 1989)
  27.  *
  28.  * Convert a Portable PixelMap to Iris format.
  29.  */
  30.  
  31. #include <stdio.h>
  32. #include "ppm.h"
  33. #include "image.h"
  34.  
  35. unsigned short rbuf[4096];
  36. unsigned short gbuf[4096];
  37. unsigned short bbuf[4096];
  38.  
  39. main(argc,argv)
  40. int argc;
  41. char **argv;
  42. {
  43.     IMAGE *image;
  44.     FILE *ifd;
  45.     register pixel *pixelrow, *pP;
  46.     int rows,cols,format,row;
  47.     register int col;
  48.     pixval maxval;
  49.     int i;
  50.  
  51.     pm_progname = argv[0];
  52.     if(argc<3) {
  53.     fprintf(stderr,"usage ppmtoiris in out\n");
  54.     exit(1);
  55.     }
  56.     
  57.     ifd = pm_openr(argv[1]);
  58.     
  59.     ppm_readppminit(ifd,&cols,&rows,&maxval,&format);
  60.     pixelrow = ppm_allocrow(cols);
  61.  
  62.     image = iopen(argv[2],"w",RLE(1),3,cols,rows,3);
  63.     for (row=0; row<rows; row++) {
  64.       ppm_readppmrow(ifd,pixelrow,cols,maxval,format);
  65.       for(col = 0, pP = pixelrow; col < cols; col++,pP++) {
  66.     rbuf[col] = PPM_GETR(*pP);
  67.     gbuf[col] = PPM_GETG(*pP);
  68.     bbuf[col] = PPM_GETB(*pP);
  69.       }
  70.       putrow(image,rbuf,row,0);        /* red row */
  71.       putrow(image,gbuf,row,1);        /* green row */
  72.       putrow(image,bbuf,row,2);        /* blue row */
  73.     }
  74.     iclose(image);
  75.     pm_close(ifd);
  76.     exit(0);
  77. }
  78.