home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / hpcd06 / tga.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-25  |  2.3 KB  |  73 lines

  1. /* hpcdtoppm (Hadmut's pcdtoppm) v0.6.beta
  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. /***********************************/
  12. /*     Sortie sur fichiers TGA     */
  13. /*   Par Serge Delbono 24/03/94    */
  14. /*                                 */
  15. /***********************************/
  16.  
  17. #include "hpcdtoppm.h"
  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. void write_tga(FILE *fout,      /* fichier sortie */
  30.                dim w,dim h,     /* largeur / hauteur */
  31.                uBYTE *rptr,     /* */
  32.                sdim rzeil,sdim rpix,
  33.                uBYTE *gptr,sdim gzeil,sdim gpix,
  34.                uBYTE *bptr,sdim bzeil,sdim bpix)
  35.  
  36.  {register uBYTE *pr,*pg,*pb;
  37.   dim x,y;
  38.   int i ;
  39.   static uBYTE *BUptr;
  40.   sINT   BUcount;
  41. /* write the header */
  42. /*  fprintf(fout,PPM_Header,w,h); */
  43.   for (i = 0; i < 12; i++)    /* 00, 00, 02, then 7 00's... */
  44.      if (i == 2)
  45.        putc(i, fout);
  46.      else
  47.       putc(0, fout);
  48.  
  49. /*  putc(First_Line % 256, fout); */ /* y origin set to "First_Line" */
  50. /*  putc(First_Line / 256, fout); */
  51.  
  52.     putc(w % 256, fout);  /* write width and height */
  53.     putc(w / 256, fout);
  54.     putc(h % 256, fout);
  55.     putc(h / 256, fout);
  56.     putc(24, fout);  /* 24 bits/pixel (16 million colors!) */
  57.     putc(32, fout);  /* Bitmask, pertinent bit: top-down raster */
  58.   BUinit;
  59.   for(y=0;y<h;y++)
  60.    {
  61.      pr= rptr; rptr+=rzeil;
  62.      pg= gptr; gptr+=gzeil;
  63.      pb= bptr; bptr+=bzeil;
  64.      for(x=0;x<w;x++)
  65.       {BUrgb_write(*pr,*pg,*pb);
  66.        pr+=rpix;  pg+=gpix;  pb+=bpix;
  67.       }
  68.    }
  69.   BUrgb_flush;
  70.  
  71.  }
  72.  
  73.