home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 329.lha / MultiPlot / source / screensave.c < prev    next >
C/C++ Source or Header  |  1990-01-05  |  8KB  |  262 lines

  1. /*
  2.  *  ScreenSave.c --  v1.06 Carolyn Scheppner  CBM
  3.  *                   Saves front screen as ILBM file
  4.  *                   Saves a CAMG chunk for HAM, etc.
  5.  *                   Creates icon for ILBM file
  6.  *  Original 10/86
  7.  *  Modified 9/88 - To mask out unwanted ViewMode bits in CAMG
  8.  *                  and use CAMG defs in new ilbm.h
  9.  *
  10.  *     Uses IFF rtns by J.Morrison and S.Shaw of Electronic Arts
  11.  *
  12.  *       (all C code including IFF modules compiled with -v on LC2)
  13.  * Linkage information:
  14.  * FROM     AStartup.obj, ScreenSave.o, iffw.o, ilbmw.o, packer.o
  15.  * TO       ScreenSave
  16.  * LIBRARY  Amiga.lib, LC.lib
  17.  *
  18.  */
  19.  
  20. #include <exec/types.h>
  21. #include <exec/memory.h>
  22. #include <libraries/dos.h>
  23. #include <libraries/dosextens.h>
  24. #include <graphics/gfxbase.h>
  25. #include <graphics/rastport.h>
  26. #include <graphics/gfx.h>
  27. #include <graphics/view.h>
  28.  
  29. #include <intuition/intuition.h>
  30. #include <intuition/intuitionbase.h>
  31. #include <workbench/workbench.h>
  32. #include <workbench/startup.h>
  33.  
  34. #include "ilbm.h"
  35.  
  36. extern struct IntuitionBase *IntuitionBase; /* Pointer aus exec */
  37.  
  38. /* For masking unwanted Viewmodes bits */
  39. #define BADFLAGS  (SPRITES|VP_HIDE|GENLOCK_AUDIO|GENLOCK_VIDEO)
  40. #define FLAGMASK  (~BADFLAGS)
  41. #define CAMGMASK  (FLAGMASK & 0x0000FFFFL)
  42.  
  43. /* Other Stuff */
  44.  
  45. #define bufSize 512
  46. struct Screen   *frontScreen;
  47.  
  48. struct ViewPort *picViewPort;
  49. struct BitMap   *picBitMap;
  50. WORD            *picColorTable;
  51. ULONG            picViewModes;
  52.  
  53. #define INBUFSZ 40
  54. char sbuf[INBUFSZ];
  55. char nbuf[INBUFSZ];
  56.  
  57. /* Definitions for ILBM Icon */
  58. USHORT  ILBMimagedata[] = {
  59.  0xFFFF, 0xFFFC,
  60.  0xC000, 0x000C,
  61.  0xC000, 0x000C,
  62.  0xC1E7, 0x9E0C,
  63.  0xC1F8, 0x7E0C,
  64.  0xC078, 0x780C,
  65.  0xC187, 0x860C,
  66.  0xC078, 0x780C,
  67.  0xC1F8, 0x7E0C,
  68.  0xC1E7, 0x9E0C,
  69.  0xC000, 0x000C,
  70.  0xC000, 0x000C,
  71.  0xFFFF, 0xFFFC,
  72.  0x0000, 0x0000,
  73.  0x0000, 0x0000,
  74. /**/
  75.  0xFFFF, 0xFFFC,
  76.  0xFFFF, 0xFFFC,
  77.  0xF800, 0x007C,
  78.  0xF9E0, 0x1E7C,
  79.  0xF980, 0x067C,
  80.  0xF807, 0x807C,
  81.  0xF81F, 0xE07C,
  82.  0xF807, 0x807C,
  83.  0xF980, 0x067C,
  84.  0xF9E0, 0x1E7C,
  85.  0xF800, 0x007C,
  86.  0xFFFF, 0xFFFC,
  87.  0xFFFF, 0xFFFC,
  88.  0x0000, 0x0000,
  89.  0x0000, 0x0000,
  90. /**/
  91.  };
  92.  
  93. struct Image ILBMimage = {
  94.    0,0,                     /* Leftedge, Topedge */
  95.    30,15,                   /* Width Height */
  96.    2,                       /* Depth */
  97.    &ILBMimagedata[0],       /* Data for image */
  98.    3,0                      /* PlanePick, PlaneOnOff */
  99.    };
  100.  
  101. struct DiskObject ILBMobject = {
  102.    WB_DISKMAGIC,
  103.    WB_DISKVERSION,
  104.  
  105.    /* Gadget Structure */
  106.    NULL,                    /* Ptr to next gadget */
  107.    0,0,                     /* Leftedge, Topedge */
  108.    30,15,                   /* Width, Height */
  109.    GADGHBOX|GADGIMAGE,      /* Flags */
  110.    RELVERIFY|GADGIMMEDIATE, /* Activation */
  111.    BOOLGADGET,              /* Type */
  112.    (APTR)&ILBMimage,        /* Render */
  113.    NULL,                    /* Select Render */
  114.    NULL,                    /* Text */
  115.    NULL,NULL,NULL,NULL,     /* Exclude, Special, ID, UserData */
  116.  
  117.    4,                       /* WBObject type */
  118.    ":Display",              /* Default tool */
  119.    NULL,                    /* Tool Types */
  120.    NO_ICON_POSITION,        /* Current X */
  121.    NO_ICON_POSITION,        /* Current Y */
  122.    NULL,NULL,NULL,          /* Drawer, ToolWindow, Stack */
  123.    };
  124.  
  125. extern char filename[150];
  126. extern struct Screen *screen;
  127. extern struct Window *window;
  128.  
  129.  
  130. screensave()
  131.    {
  132.    IFFP            iffp = NO_FILE;
  133.    struct Process  *OurTask;
  134.    struct Window   *old_pr_WindowPtr;
  135.    LONG fp;
  136.    static char plotname[150], def_drive[150], def_path[100], def_node[30],def_extn[20];
  137.  
  138.      strcpy(plotname,filename);
  139.      strsfn(plotname,def_drive,def_path,def_node,def_extn);
  140.      strcat(def_drive,def_path);
  141.      strcat(def_node,".pic");
  142.  
  143.      OurTask = (struct Process *)FindTask(0L);
  144.      old_pr_WindowPtr = (struct Window *)OurTask->pr_WindowPtr;
  145.      OurTask->pr_WindowPtr = (APTR)window;
  146.      if (get_fname(window,screen,"Save File As...",def_node,def_drive)==NULL)
  147.           {
  148.              OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
  149.              return(TRUE);
  150.            }
  151.  
  152.       OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
  153.       strmfp(plotname,def_drive,def_node);
  154.  
  155.    if (!(fp = Open(plotname,MODE_NEWFILE) ))
  156.       {Message("     Can't open file        "); return(FALSE);}
  157.  
  158.    Write(fp,"x",1);  /* 1.1 so Seek to beginning works ? */
  159.  
  160.    Forbid();
  161.    frontScreen  = IntuitionBase->FirstScreen;
  162.    Permit();
  163.  
  164.    picViewPort = &( frontScreen->ViewPort );
  165.    picBitMap = (struct BitMap*)picViewPort->RasInfo->BitMap;
  166.    picColorTable = (WORD *)picViewPort->ColorMap->ColorTable;
  167.    picViewModes = (ULONG)picViewPort->Modes;
  168.  
  169.    iffp = PutPicture(fp, picBitMap, picColorTable, picViewModes);
  170.    Close(fp);
  171.  
  172.    if (iffp == IFF_OKAY)
  173.       {
  174.       if(!(PutDiskObject(plotname,&ILBMobject)))
  175.           {Message("   Can't open .info file     "); return(FALSE);}
  176.       }
  177.    return(1);
  178.    }
  179.  
  180.  
  181.  
  182. /** PutPicture() ***********************************************************
  183.  *
  184.  * Put a picture into an IFF file.
  185.  * This procedure calls PutAnILBM, passing in an <x, y> location of <0, 0>,
  186.  * a NULL mask, and a locally-allocated buffer. It also assumes you want to
  187.  * write out all the bitplanes in the BitMap.
  188.  *
  189.  ***************************************************************************/
  190. Point2D nullPoint = {0, 0};
  191.  
  192. IFFP PutPicture(file, bitmap, colorMap, viewmodes)
  193.       LONG file;  struct BitMap *bitmap;
  194.       WORD *colorMap;  ULONG viewmodes;
  195.    {
  196.    BYTE buffer[bufSize];
  197.    return( PutAnILBM(file, bitmap, NULL,
  198.            colorMap, bitmap->Depth, viewmodes,
  199.            &nullPoint, buffer, bufSize) );
  200.    }
  201.  
  202.  
  203. /** PutAnILBM() ************************************************************
  204.  *
  205.  * Write an entire BitMap as a FORM ILBM in an IFF file.
  206.  * This version works for any display mode (C. Scheppner).
  207.  *
  208.  * Normal return result is IFF_OKAY.
  209.  *
  210.  * The utility program IFFCheck would print the following outline of the
  211.  * resulting file:
  212.  *
  213.  *   FORM ILBM
  214.  *     BMHD
  215.  *     CAMG
  216.  *     CMAP
  217.  *     BODY       (compressed)
  218.  *
  219.  ***************************************************************************/
  220. #define CkErr(expression)  {if (ifferr == IFF_OKAY) ifferr = (expression);}
  221.  
  222. IFFP PutAnILBM(file, bitmap, mask, colorMap, depth,
  223.                                 viewmodes, xy, buffer, bufsize)
  224.       LONG file;
  225.       struct BitMap *bitmap;
  226.       BYTE *mask;  WORD *colorMap; UBYTE depth;
  227.       ULONG viewmodes;
  228.       Point2D *xy; BYTE *buffer;  LONG bufsize;
  229.    {
  230.    BitMapHeader bmHdr;
  231.    CamgChunk    camgChunk;
  232.    GroupContext fileContext, formContext;
  233.    IFFP ifferr;
  234.    WORD pageWidth, pageHeight;
  235.  
  236.    pageWidth  = (bitmap->BytesPerRow) << 3;
  237.    pageHeight = bitmap->Rows;
  238.  
  239.    ifferr = InitBMHdr(&bmHdr, bitmap, mskNone,
  240.                       cmpByteRun1, 0, pageWidth, pageHeight);
  241.    /* You could write an uncompressed image by passing cmpNone instead
  242.     * of cmpByteRun1 to InitBMHdr. */
  243.    bmHdr.nPlanes = depth;   /* This must be  <= bitmap->Depth */
  244.    if (mask != NULL) bmHdr.masking = mskHasMask;
  245.    bmHdr.x = xy->x;   bmHdr.y = xy->y;
  246.  
  247.    camgChunk.ViewModes = viewmodes & CAMGMASK; /* Mask out unwanted bits! */
  248.  
  249.    CkErr( OpenWIFF(file, &fileContext, szNotYetKnown) );
  250.    CkErr(StartWGroup(&fileContext, FORM, szNotYetKnown, ID_ILBM, &formContext));
  251.  
  252.    CkErr( PutBMHD(&formContext, &bmHdr) );
  253.    CkErr( PutCAMG(&formContext, &camgChunk) );
  254.    CkErr( PutCMAP(&formContext, colorMap, depth) );
  255.    CkErr( PutBODY(&formContext, bitmap, mask, &bmHdr, buffer, bufsize) );
  256.  
  257.    CkErr( EndWGroup(&formContext) );
  258.    CkErr( CloseWGroup(&fileContext) );
  259.    return( ifferr );
  260.    }
  261.  
  262.