home *** CD-ROM | disk | FTP | other *** search
/ Graphics 16,000 / graphics-16000.iso / amiga / fractal / mak / source.lzh / Source / SaveIT.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-29  |  4.5 KB  |  172 lines

  1. /*
  2.  *  ScreenSave.c --  Carolyn Scheppner  CBM  10/86
  3.  *                   Saves front screen as ILBM file
  4.  *                   Saves a CAMG chunk for HAM, etc.
  5.  *
  6.  *  Renamed to SaveIt-Modifications by Steven Dillon for the M.A.K.
  7.  *
  8.  *     Uses IFF rtns by J.Morrison and S.Shaw of Electronic Arts
  9.  *
  10.  *
  11.  */
  12.  
  13. #include <exec/types.h>
  14. #include <exec/memory.h>
  15. #include <libraries/dos.h>
  16. #include <libraries/dosextens.h>
  17. #include <graphics/gfxbase.h>
  18. #include <graphics/rastport.h>
  19. #include <graphics/gfx.h>
  20. #include <graphics/view.h>
  21.  
  22. #include <intuition/intuition.h>
  23. #include <intuition/intuitionbase.h>
  24. #include <workbench/workbench.h>
  25. #include <workbench/startup.h>
  26.  
  27. #include "iff/ilbm.h"
  28.  
  29. /* CAMG Stuff */
  30. typedef struct {
  31.    ULONG ViewModes;
  32.    } CamgChunk;
  33.  
  34. #define PutCAMG(context, camg)  \
  35.     PutCk(context, ID_CAMG, sizeof(CamgChunk),(BYTE *)camg)
  36.  
  37. #define bufSize 512
  38.  
  39.  
  40. extern struct IntuitionBase *IntuitionBase;
  41. extern struct Screen *FirstScreen;
  42. extern struct Window *NoBorder;
  43.  
  44. struct Screen   *frontScreen;
  45.  
  46. struct ViewPort *picViewPort;
  47. struct BitMap   *picBitMap;
  48. WORD            *picColorTable;
  49. ULONG            picViewModes;
  50.  
  51.  
  52. #define INBUFSZ 40
  53. char sbuf[INBUFSZ];
  54. char nbuf[INBUFSZ];
  55.  
  56.  
  57. SaveIt(File_Name)
  58. char *File_Name;
  59.   {
  60.    LONG file;
  61.    IFFP iffp = NO_FILE;
  62.   
  63.    WindowToFront(NoBorder);
  64.    
  65.    if (!(file = Open(File_Name, MODE_NEWFILE)))
  66.      {
  67.       printf("Can't open file %s",File_Name," for output\n");
  68.       return(FALSE);
  69.      } 
  70.   
  71.      
  72.    Write(file,"x",1);  /* 1.1 so Seek to beginning works ? */
  73.  
  74.   
  75.    frontScreen  = FirstScreen; 
  76.   
  77.    picViewPort = &(frontScreen->ViewPort);
  78.    picBitMap = (struct BitMap*)picViewPort->RasInfo->BitMap;
  79.    picColorTable = (WORD *)picViewPort->ColorMap->ColorTable;
  80.    picViewModes = (ULONG)picViewPort->Modes;
  81.  
  82.   
  83.    iffp = PutPicture(file, picBitMap, picColorTable, picViewModes);
  84.    Close(file);
  85.  
  86.    
  87.   } /* SaveIt */
  88.  
  89.  
  90.  
  91. /** PutPicture() ***********************************************************
  92.  *
  93.  * Put a picture into an IFF file.
  94.  * This procedure calls PutAnILBM, passing in an <x, y> location of <0, 0>,
  95.  * a NULL mask, and a locally-allocated buffer. It also assumes you want to
  96.  * write out all the bitplanes in the BitMap.
  97.  *
  98.  ***************************************************************************/
  99. Point2D nullPoint = {0, 0};
  100.  
  101. IFFP PutPicture(file, bitmap, colorMap, viewmodes)
  102.       LONG file;  struct BitMap *bitmap;
  103.       WORD *colorMap;  ULONG viewmodes;
  104.    {
  105.    BYTE buffer[bufSize];
  106.    return( PutAnILBM(file, bitmap, NULL,
  107.            colorMap, bitmap->Depth, viewmodes,
  108.            &nullPoint, buffer, bufSize) );
  109.    }    
  110.  
  111.    
  112. /** PutAnILBM() ************************************************************
  113.  *
  114.  * Write an entire BitMap as a FORM ILBM in an IFF file.
  115.  * This version works for any display mode (C. Scheppner).
  116.  *
  117.  * Normal return result is IFF_OKAY.
  118.  *
  119.  * The utility program IFFCheck would print the following outline of the
  120.  * resulting file:
  121.  *
  122.  *   FORM ILBM
  123.  *     BMHD
  124.  *     CAMG
  125.  *     CMAP
  126.  *     BODY       (compressed)
  127.  *
  128.  ***************************************************************************/
  129. #define CkErr(expression)  {if (ifferr == IFF_OKAY) ifferr = (expression);}
  130.  
  131. IFFP PutAnILBM(file, bitmap, mask, colorMap, depth,
  132.                                 viewmodes, xy, buffer, bufsize)
  133.       LONG file;
  134.       struct BitMap *bitmap;
  135.       BYTE *mask;  WORD *colorMap; UBYTE depth;
  136.       ULONG viewmodes;
  137.       Point2D *xy; BYTE *buffer;  LONG bufsize;
  138.    {
  139.    BitMapHeader bmHdr;
  140.    CamgChunk    camgChunk;
  141.    GroupContext fileContext, formContext;
  142.    IFFP ifferr;
  143.    WORD pageWidth, pageHeight;
  144.  
  145.    pageWidth  = (bitmap->BytesPerRow) << 3;
  146.    pageHeight = bitmap->Rows;
  147.  
  148.    ifferr = InitBMHdr(&bmHdr, bitmap, mskNone,
  149.                       cmpByteRun1, 0, pageWidth, pageHeight);
  150.    /* You could write an uncompressed image by passing cmpNone instead
  151.     * of cmpByteRun1 to InitBMHdr. */
  152.    bmHdr.nPlanes = depth;   /* This must be  <= bitmap->Depth */
  153.    if (mask != NULL) bmHdr.masking = mskHasMask;
  154.    bmHdr.x = xy->x;   bmHdr.y = xy->y;
  155.  
  156.    camgChunk.ViewModes = viewmodes;
  157.  
  158.    CkErr( OpenWIFF(file, &fileContext, szNotYetKnown) );
  159.    CkErr(StartWGroup(&fileContext, FORM, szNotYetKnown, ID_ILBM, &formContext));
  160.  
  161.    CkErr( PutBMHD(&formContext, &bmHdr) );
  162.    CkErr( PutCAMG(&formContext, &camgChunk) );
  163.    CkErr( PutCMAP(&formContext, colorMap, depth) );
  164.    CkErr( PutBODY(&formContext, bitmap, mask, &bmHdr, buffer, bufsize) );
  165.  
  166.    CkErr( EndWGroup(&formContext) );
  167.    CkErr( CloseWGroup(&fileContext) );
  168.    return( ifferr );
  169.    }
  170.    
  171.  
  172.