home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d536 / chemesthetics.lha / Chemesthetics / Source / Source.LZH / saveiff.c < prev    next >
C/C++ Source or Header  |  1991-06-17  |  3KB  |  109 lines

  1. #include "saveiff.h"
  2. #include <iff/ilbm.h>
  3. #include "chem_defs.h"
  4. #include "messages.h"
  5.  
  6. /* ------------------------------- external references ------------------ */
  7.  
  8. extern struct ChemPrefs ChemPrefs;
  9.  
  10. extern void SimpleRequest();
  11.  
  12. /* ------------------------------- routines ----------------------------- */
  13.  
  14. LONG      save(filename, screen, wwidth, sheight)       /* saves displayed map as IFF FORM */
  15. UBYTE     *filename;
  16. struct Screen *screen;
  17. int      wwidth, sheight;
  18. {
  19.   IFFP        PutAnILBM();
  20.   ULONG     IconBase;
  21.   LONG        file;
  22.   struct BitMap *picBitMap;
  23.   struct ViewPort *vp;
  24.   ULONG     picViewModes;
  25.   WORD       *picColorTable;
  26.   extern struct Screen *s;
  27.   IFFP        iffp = NO_FILE;
  28.   LONG        returncode = NOT_OK;
  29.  
  30.   vp = &(screen->ViewPort);
  31.   if (!(file = Open(filename, MODE_NEWFILE)))
  32.     return (returncode);
  33.  
  34.   Write(file, "x", 1);                 /* 1.1 so Seek to beginning works ? (?!?!???)*/
  35.  
  36.   picBitMap = (struct BitMap *) vp->RasInfo->BitMap;
  37.   picColorTable = (WORD *) vp->ColorMap->ColorTable;
  38.   picViewModes = (ULONG) vp->Modes;
  39.  
  40.   iffp = PutAnILBM(file, picBitMap, picColorTable, picBitMap->Depth,
  41.            picViewModes, wwidth, sheight);
  42.  
  43.   Close(file);
  44.  
  45.   if (iffp == IFF_OKAY)
  46.   {
  47.     if(ChemPrefs.IconCreaIFF==TRUE)
  48.     {
  49.       IconBase = (ULONG) OpenLibrary("icon.library", 0);
  50.       if (IconBase != NULL)
  51.       {
  52.     if (NULL != PutDiskObject(filename, &ILBMobject))
  53.     {
  54.       returncode = OK;
  55.     }
  56.     else
  57.     {
  58.       DisplayBeep(screen);
  59.       SimpleRequest(ERROR_PUT_ICON);
  60.     }
  61.     CloseLibrary((struct Library *) IconBase);
  62.       }
  63.       else
  64.     SimpleRequest(NO_ICON_LIB);
  65.     }
  66.     else
  67.       returncode=OK;
  68.   }
  69.   return (returncode);
  70. }
  71.  
  72.  
  73. #define CkErr(expression)  {if (ifferr == IFF_OKAY) ifferr = (expression);}
  74.  
  75. IFFP      PutAnILBM(file, bitmap, colorMap, depth,
  76.                   viewmodes, wwidth, sheight)
  77. LONG      file;
  78. struct BitMap *bitmap;
  79. WORD     *colorMap;
  80. UBYTE      depth;
  81. ULONG      viewmodes;
  82. int      wwidth, sheight;
  83. {
  84.   BYTE        buffer[bufsize];
  85.   BitMapHeader bmHdr;
  86.   CamgChunk camgChunk;
  87.   GroupContext fileContext, formContext;
  88.   IFFP        ifferr;
  89.  
  90.   ifferr = InitBMHdr(&bmHdr, bitmap, mskNone,
  91.              cmpByteRun1, 0, wwidth, sheight);
  92.   bmHdr.y = 0;
  93.   bmHdr.h = sheight;
  94.  
  95.   camgChunk.ViewModes = viewmodes & CAMGMASK;
  96.  
  97.   CkErr(OpenWIFF(file, &fileContext, szNotYetKnown));
  98.   CkErr(StartWGroup(&fileContext, FORM, szNotYetKnown, ID_ILBM, &formContext));
  99.  
  100.   CkErr(PutBMHD(&formContext, &bmHdr));
  101.   CkErr(PutCAMG(&formContext, &camgChunk));
  102.   CkErr(PutCMAP(&formContext, colorMap, depth));
  103.   CkErr(PutBODY(&formContext, bitmap, mskNone, &bmHdr, buffer, bufsize));
  104.  
  105.   CkErr(EndWGroup(&formContext));
  106.   CkErr(CloseWGroup(&fileContext));
  107.   return (ifferr);
  108. }
  109.