wollman@emily.uvm.edu (Garrett Wollman) (05/08/91)
Here is a program I wrote (based in the skeleton in 4dgifts) which reads in a PPM file and writes out an Imagelib file. Note that this is somewhat bad form in that it doesn't read from the standard input like most PBMPLUS utilities. Possibly other people have written similar utilities; the reason I wrote this one is because the fromtarga program doesn't understand TARGA-16 files generated by older versions of Fractint. Use it as you will; I've found that it works nicely for both PPMs and PGMs. In particular, I have used it to convert Targa, Gif, and FITS (astronomical) images for display. Some of the Magellan pictures at NASA Ames make nice roots! -GAWollman #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of shell archive." # Contents: ppmtoiris.c # Wrapped by wollman@emily on Wed May 8 09:18:05 1991 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'ppmtoiris.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'ppmtoiris.c'\" else echo shar: Extracting \"'ppmtoiris.c'\" \(1887 characters\) sed "s/^X//" >'ppmtoiris.c' <<'END_OF_FILE' X/* BASED ON... */ X/* X * writeimg - X * Write out an RGB image file. This example uses three functions X * from the image library: X * X * iopen, putrow, and iclose. X * X * The function iopen is called to describe the xsize and ysize of the X * RGB image to be written out. X * X * The function putrow writes a row of image data to the image file. It is X * called with an array of shorts with values in the range [0..255]. X * X * The function iclose is called to close the image file. X * X * Why not modify this program to be a filter that converts from your own X * image file format to IRIS images? X * X * Paul Haeberli - 1987 X * X */ X X/* X * ppmtoiris - Garrett A. Wollman - wollman@newton - January 1991 X * also based on ppmcscale.c by Jef Poskanzer (Copyright 1989) X * X * Convert a Portable PixelMap to Iris format. X */ X X#include <stdio.h> X#include "ppm.h" X#include "image.h" X unsigned short rbuf[4096]; unsigned short gbuf[4096]; unsigned short bbuf[4096]; X main(argc,argv) int argc; char **argv; X{ X IMAGE *image; X FILE *ifd; X register pixel *pixelrow, *pP; X int rows,cols,format,row; X register int col; X pixval maxval; X int i; X X pm_progname = argv[0]; X if(argc<3) { X fprintf(stderr,"usage ppmtoiris in out\n"); X exit(1); X } X X ifd = pm_openr(argv[1]); X X ppm_readppminit(ifd,&cols,&rows,&maxval,&format); X pixelrow = ppm_allocrow(cols); X X image = iopen(argv[2],"w",RLE(1),3,cols,rows,3); X for (row=0; row<rows; row++) { X ppm_readppmrow(ifd,pixelrow,cols,maxval,format); X for(col = 0, pP = pixelrow; col < cols; col++,pP++) { X rbuf[col] = PPM_GETR(*pP); X gbuf[col] = PPM_GETG(*pP); X bbuf[col] = PPM_GETB(*pP); X } X putrow(image,rbuf,row,0); /* red row */ X putrow(image,gbuf,row,1); /* green row */ X putrow(image,bbuf,row,2); /* blue row */ X } X iclose(image); X pm_close(ifd); X exit(0); X} END_OF_FILE if test 1887 -ne `wc -c <'ppmtoiris.c'`; then echo shar: \"'ppmtoiris.c'\" unpacked with wrong size! fi # end of 'ppmtoiris.c' fi echo shar: End of shell archive. exit 0 Garrett A. Wollman - wollman@emily.uvm.edu Disclaimer: I'm not even sure this represents *my* opinion, never mind UVM's, EMBA's, EMBA-CF's, or indeed anyone else's.