home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff397.lzh / DKBTrace / DKBSource.LZH / putpict.c < prev    next >
C/C++ Source or Header  |  1990-08-26  |  4KB  |  97 lines

  1. /** putpict.c ***************************************************/
  2. /* PutPict().  Given a BitMap and a color map in RAM on the     */
  3. /* Amiga, outputs as an ILBM.  See /iff/ilbm.h & /iff/ilbmw.c.    */
  4. /*                   23-Jan-86                  */
  5. /*                                                              */
  6. /* By Jerry Morrison and Steve Shaw, Electronic Arts.           */
  7. /* This software is in the public domain.                       */
  8. /*                                                              */
  9. /* This version for the Commodore-Amiga computer.               */
  10. /*                                                              */
  11. /****************************************************************/
  12. #include "iff/intuall.h"
  13. #include "iff/gio.h"
  14. #include "iff/ilbm.h"
  15. #include "iff/putpict.h"
  16.  
  17. #define MaxDepth 5
  18. static IFFP ifferror = 0;
  19.  
  20. #define CkErr(expression)  {if (ifferror == IFF_OKAY) ifferror = (expression);}
  21.     
  22. /*****************************************************************************/
  23. /* IffErr                                                                    */
  24. /*                                                                           */
  25. /* Returns the iff error code and resets it to zero                          */
  26. /*                                                                           */
  27. /*****************************************************************************/
  28. IFFP IffErr()
  29.    {
  30.    IFFP i;
  31.    i = ifferror;
  32.    ifferror = 0;
  33.    return(i);
  34.    }
  35.  
  36. /*****************************************************************************/
  37. /* PutPict()                                                                 */
  38. /*                                                                           */
  39. /* Put a picture into an IFF file                                            */
  40. /* Pass in mask == NULL for no mask.                                         */
  41. /*                                                                           */
  42. /* Buffer should be big enough for one packed scan line                      */
  43. /* Buffer used as temporary storage to speed-up writing.                     */
  44. /* A large buffer, say 8KB, is useful for minimizing Write and Seek calls.   */
  45. /* (See /iff/gio.h & /iff/gio.c).                                            */
  46. /*****************************************************************************/
  47.     
  48. BOOL PutPict(file, vp, buffer, bufsize)
  49.     LONG file;
  50.     struct ViewPort *vp;
  51.     BYTE *buffer;
  52.     LONG bufsize;
  53.     {
  54.     int pageW, pageH;
  55.     BitMapHeader bmHdr;
  56.     GroupContext fileContext, formContext;
  57.  
  58.     pageW = vp->DWidth;
  59.     pageH = vp->DHeight;
  60.  
  61.     ifferror = InitBMHdr(&bmHdr,
  62.     vp->RasInfo->BitMap, 
  63.     mskNone, 
  64.     cmpByteRun1,
  65.     0,
  66.     pageW, 
  67.     pageH );
  68.     
  69. /* use buffered write for speedup, if it is big-enough for both
  70.  * PutBODY's buffer and a gio buffer.*/
  71. #define BODY_BUFSIZE 512
  72.     if (ifferror == IFF_OKAY  &&  bufsize > 2*BODY_BUFSIZE) {
  73.     if (GWriteDeclare(file, buffer+BODY_BUFSIZE, bufsize-BODY_BUFSIZE) < 0)
  74.         ifferror = DOS_ERROR;
  75.     bufsize = BODY_BUFSIZE;
  76.     }
  77.     
  78.     CkErr(OpenWIFF(file, &fileContext, szNotYetKnown) );
  79.     CkErr(StartWGroup(&fileContext, FORM, szNotYetKnown, ID_ILBM, &formContext) );
  80.  
  81.     CkErr(PutCk(&formContext, ID_BMHD, sizeof(BitMapHeader), (BYTE *)&bmHdr));
  82.  
  83.     CkErr(PutCAMG(&formContext, vp->Modes));
  84.  
  85.     if (vp->ColorMap != NULL)
  86.     CkErr( PutCMAP(&formContext, vp));
  87.     CkErr( PutBODY(&formContext, vp->RasInfo->BitMap, NULL, &bmHdr, buffer, bufsize) );
  88.  
  89.     CkErr( EndWGroup(&formContext) );
  90.     CkErr( CloseWGroup(&fileContext) );
  91.     if (GWriteUndeclare(file) < 0  &&  ifferror == IFF_OKAY)
  92.     ifferror = DOS_ERROR;
  93.     return( (BOOL)(ifferror != IFF_OKAY) );
  94.     }    
  95.  
  96.  
  97.