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

  1. From: paul@manray.asd.sgi.com (Paul Haeberli)
  2. Newsgroups: alt.sources
  3. Subject: [comp.sys.sgi] convert IRIS image files into ALIAS image format
  4. Message-ID: <12136@stag.math.lsa.umich.edu>
  5. Date: 21 May 90 04:39:23 GMT
  6.  
  7. Archive-name: iristoalias/15-May-90
  8. Original-posting-by: paul@manray.asd.sgi.com (Paul Haeberli)
  9. Original-subject: convert IRIS image files into ALIAS image format
  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.  *    toalias -
  19.  *        Convert an Iris image to an Alias image.
  20.  *
  21.  *    To compile:
  22.  *        cc toalias.c -o toalias -limage -I/usr/include/gl
  23.  *
  24.  *                Paul Haeberli - 1986
  25.  */
  26. #include "image.h"
  27.  
  28. char rbuf[4096];
  29. char gbuf[4096];
  30. char bbuf[4096];
  31. unsigned long lbuf[4096];
  32.  
  33. typedef struct hdr {
  34.      short xsize;
  35.      short ysize;
  36.      short xorg;
  37.      short yorg;
  38.      short bitsdeep;
  39. } hdr;
  40.  
  41. hdr ihdr;
  42.  
  43. main(argc,argv)
  44. int argc;
  45. char **argv;
  46. {
  47.     IMAGE *image;
  48.     int xsize, ysize;
  49.     int y, z;
  50.     char dname[128];
  51.     FILE *outfile;
  52.  
  53.     if(argc<3) {
  54.     fprintf(stderr,"usage: toalias inimage.rgb aliasimage\n");
  55.     exit(1);
  56.     }
  57.     if ((image = iopen(argv[1],"r")) == NULL ) {
  58.     fprintf(stderr,"toalias: can't open %s\n",argv[1]);
  59.     exit(1);
  60.     }
  61.     if ((outfile = fopen(argv[2],"w")) == NULL ) {
  62.     fprintf(stderr,"toalias: can't open %s\n",argv[2]);
  63.     exit(1);
  64.     }
  65.     xsize = image->xsize;
  66.     ysize = image->ysize;
  67.     ihdr.xsize = xsize;
  68.     ihdr.ysize = ysize;
  69.     ihdr.xorg = 0;
  70.     ihdr.yorg = ysize-1;
  71.     ihdr.bitsdeep = 24;
  72.     fwrite(&ihdr,sizeof(ihdr),1,outfile);
  73.     for(y=0; y<ysize; y++) {
  74.     getrow(image,rbuf,ysize-1-y,0);
  75.     getrow(image,gbuf,ysize-1-y,1);
  76.     getrow(image,bbuf,ysize-1-y,2);
  77.     putalias(outfile,rbuf,gbuf,bbuf,xsize);
  78.     }
  79.     fclose(outfile);
  80.     exit(0);
  81. }
  82.  
  83. putalias(outfile,rbuf,gbuf,bbuf,xsize)
  84. FILE *outfile;
  85. register unsigned short *rbuf, *gbuf, *bbuf;
  86. int xsize;
  87. {
  88.     register int n, count;
  89.     unsigned long val;
  90.  
  91.     for(n=0; n<xsize; n++) {
  92.     val = *bbuf++;
  93.     val = (val<<8)+ *gbuf++;
  94.     val = (val<<8)+ *rbuf++;
  95.     lbuf[n] = val;
  96.     }
  97.     val = lbuf[0];
  98.     count = 0;
  99.     for(n=0; n<xsize; n++) {
  100.     if(lbuf[n] == val) {
  101.         count++;
  102.         if(count==255) {
  103.         val |= count<<24;
  104.         fwrite(&val,sizeof(long),1,outfile);
  105.         val &= 0xffffff;
  106.         count = 0;
  107.         }
  108.     } else {
  109.         if(count) {
  110.         val |= count<<24;
  111.         fwrite(&val,sizeof(long),1,outfile);
  112.         }
  113.         val = lbuf[n];
  114.         count = 1;
  115.     }
  116.     lbuf[n] = val;
  117.     }
  118.     if(count) {
  119.     val |= count<<24;
  120.     fwrite(&val,sizeof(long),1,outfile);
  121.     }
  122. }
  123.