Xref: utzoo comp.sys.sgi:9985 alt.sources:3715 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!sdd.hp.com!wuarchive!rice!hsdndev!dartvax!mars!nic!kira!emily!wollman From: wollman@emily.uvm.edu (Garrett Wollman) Newsgroups: comp.sys.sgi,alt.sources Subject: ppmtoiris - convert PPM files to Imagelib RGB format Message-ID: <1991May8.145907.13806@uvm.edu> Date: 8 May 91 14:59:07 GMT Sender: news@uvm.edu Organization: University of Vermont - EMBA Computing Facility Lines: 118 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 '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 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