home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1354 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  2.1 KB

  1. From: paul@manray.asd.sgi.com (Paul Haeberli)
  2. Newsgroups: alt.sources
  3. Subject: [comp.sys.sgi] convert ALIAS image files to IRIS image files
  4. Message-ID: <12135@stag.math.lsa.umich.edu>
  5. Date: 21 May 90 04:39:04 GMT
  6.  
  7. Archive-name: aliastoiris/15-May-90
  8. Original-posting-by: paul@manray.asd.sgi.com (Paul Haeberli)
  9. Original-subject: convert ALIAS image files to IRIS image files
  10. Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)
  11.  
  12. [This is an experimental alt.sources re-posting from the newsgroup(s)
  13. comp.sys.sgi. Comments on this service to emv@math.lsa.umich.edu 
  14. (Edward Vielmetti).]
  15.  
  16.  
  17. /*
  18.  *    fromalias -
  19.  *        Convert an Alias image to an Iris image.
  20.  *
  21.  *    To compile:
  22.  *        cc fromalias.c -o fromalias -limage -I/usr/include/gl
  23.  *
  24.  *                Paul Haeberli - 1986
  25.  */
  26. #include "image.h"
  27.  
  28. short rbuf[4096];
  29. short gbuf[4096];
  30. short bbuf[4096];
  31.  
  32. typedef struct hdr {
  33.      short xsize;
  34.      short ysize;
  35.      short xorg;
  36.      short yorg;
  37.      short bitsdeep;
  38. } hdr;
  39.  
  40. hdr ihdr;
  41.  
  42. main(argc,argv)
  43. int argc;
  44. char **argv;
  45. {
  46.     IMAGE *image;
  47.     FILE *infile;
  48.     int xsize, ysize;
  49.     int y, z;
  50.  
  51.     if(argc<3) {
  52.     fprintf(stderr,"usage: fromalias aliasimage outimage.rgb\n");
  53.     exit(1);
  54.     }
  55.     if ((infile = fopen(argv[1],"r")) == NULL ) {
  56.     fprintf(stderr,"fromalias: can't open %s\n",argv[1]);
  57.     exit(1);
  58.     }
  59.     fread(&ihdr,sizeof(ihdr),1,infile);
  60.     xsize = ihdr.xsize;
  61.     ysize = ihdr.ysize;
  62.     image = iopen(argv[2],"w",RLE(1),3,xsize,ysize,3);
  63.     for(y=0; y<ysize; y++) {
  64.     getalias(infile,rbuf,gbuf,bbuf,xsize);
  65.     putrow(image,rbuf,ysize-1-y,0);
  66.     putrow(image,gbuf,ysize-1-y,1);
  67.     putrow(image,bbuf,ysize-1-y,2);
  68.     }
  69.     iclose(image);
  70.     exit(0);
  71. }
  72.  
  73. getalias(infile,rbuf,gbuf,bbuf,xsize)
  74. FILE *infile;
  75. register unsigned short *rbuf, *gbuf, *bbuf;
  76. int xsize;
  77. {
  78.     register int n, count;
  79.     register int r, g, b;
  80.     unsigned long val;
  81.  
  82.     for(n=0; n<xsize;) {
  83.     fread(&val,sizeof(long),1,infile);
  84.     r =  val&0xff;
  85.     val >>= 8;
  86.     g =  val&0xff;
  87.     val >>= 8;
  88.     b =  val&0xff;
  89.     val >>= 8;
  90.     count =  val&0xff;
  91.     n += count;
  92.     while(count--) {
  93.         *rbuf++ = r;
  94.         *gbuf++ = g;
  95.         *bbuf++ = b;
  96.     }
  97.     }
  98. }
  99.