home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d7xx / d777 / chemesthetics.lha / Chemesthetics / Source.LHA / saveiff.c < prev    next >
C/C++ Source or Header  |  1992-04-29  |  3KB  |  128 lines

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