home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / CDRom / PHOTOC12.LZX / src / photocdaga / ppm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  1.8 KB  |  87 lines

  1. /* hpcdtoppm (Hadmut's pcdtoppm) v0.6
  2. *  Copyright (c) 1992, 1993, 1994 by Hadmut Danisch (danisch@ira.uka.de).
  3. *  Permission to use and distribute this software and its
  4. *  documentation for noncommercial use and without fee is hereby granted,
  5. *  provided that the above copyright notice appear in all copies and that
  6. *  both that copyright notice and this permission notice appear in
  7. *  supporting documentation. It is not allowed to sell this software in 
  8. *  any way. This software is not public domain.
  9. */
  10.  
  11. #define OWN_WRITE
  12.  
  13. #include "hpcdtoppm.h"
  14.  
  15.  
  16.  
  17.  
  18.  
  19. static uBYTE BUF[own_BUsize];
  20. #define BUinit {BUcount=0;BUptr=BUF;}
  21.  
  22. #define BUrgb_flush        {fwrite(BUF,BUcount*3,1,fout);BUinit; }
  23. #define BUrgb_write(r,g,b) {if(BUcount>=own_BUsize/3) BUrgb_flush; *BUptr++ = r ; *BUptr++ = g ; *BUptr++ = b ; BUcount++;}
  24.  
  25. #define BUgreyflush        {fwrite(BUF,BUcount,1,fout);BUinit; }
  26. #define BUgreywrite(g)     {if(BUcount>=own_BUsize) BUgreyflush;  *BUptr++ = g ;  BUcount++;}
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. void write_ppm(FILE *fout,dim w,dim h, 
  35.                uBYTE *rptr,sdim rzeil,sdim rpix,  
  36.                uBYTE *gptr,sdim gzeil,sdim gpix,  
  37.                uBYTE *bptr,sdim bzeil,sdim bpix) 
  38.  {register uBYTE *pr,*pg,*pb;
  39.   dim x,y;
  40.   static uBYTE *BUptr;
  41.   sINT   BUcount;
  42.  
  43.   fprintf(fout,PPM_Header,w,h);
  44.   BUinit;
  45.   for(y=0;y<h;y++)
  46.    {
  47.      pr= rptr; rptr+=rzeil;
  48.      pg= gptr; gptr+=gzeil;
  49.      pb= bptr; bptr+=bzeil;
  50.      for(x=0;x<w;x++) 
  51.       {BUrgb_write(*pr,*pg,*pb);
  52.        pr+=rpix;  pg+=gpix;  pb+=bpix;
  53.       }
  54.    }
  55.   BUrgb_flush;
  56.  
  57.  }
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. void write_pgm(FILE *fout,dim w,dim h, uBYTE *ptr,sdim zeil,sdim pix) 
  65.  {register uBYTE *p;
  66.   dim x,y;
  67.   static uBYTE *BUptr;
  68.   sINT   BUcount;
  69.  
  70.  
  71.   fprintf(fout,PGM_Header,w,h);
  72.   BUinit;
  73.   for(y=0;y<h;y++)
  74.    {
  75.     p= ptr; ptr+=zeil;
  76.  
  77.     for(x=0;x<w;x++) 
  78.      {BUgreywrite(*p);
  79.       p+=pix;
  80.      }
  81.    }
  82.   BUgreyflush;
  83.  }
  84.  
  85.  
  86.  
  87.