home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / Devices / modules / screendump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  2.5 KB  |  95 lines

  1. /*
  2.  * screendump.c    - routine to dump rastport (iffparse not required)
  3.  *
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <intuition/screens.h>
  8. #include <devices/printer.h>
  9.  
  10. #ifndef NO_PROTOS
  11. #include <clib/exec_protos.h>
  12. #include <clib/alib_protos.h>
  13. #endif
  14.  
  15.  
  16. /* screendump
  17.  * 
  18.  * Passed a screen pointer, source x, source y, width, height,
  19.  *   destcols and io_Special flags, will print part or all of a screen.
  20.  *
  21.  * If 0 is passed for BOTH destcols and special, screendump()
  22.  *   assumes you want IT to compute suitable values.
  23.  * In this case:
  24.  *   1. If srcx and srcy are 0, and srcw and srch are same as
  25.  *      screen width and height, screendump will set destcols=0,
  26.  *      and special = SPECIAL_FULLCOLS|SPECIAL_ASPECT
  27.  *    for a full width aspected dump.
  28.  *
  29.  *   2. If srcx or srcy are nonzero, or srcw or srch are different
  30.  *      from screen width or height, screendump will print a
  31.  *      fractional size dump relative to the size whole screendump
  32.  *      would have been.
  33.  *
  34.  * Returns 0 for success or printer io_Error (devices/printer.h)
  35.  */
  36.  
  37. int screendump(struct Screen *scr,
  38.         UWORD srcx, UWORD srcy, UWORD srcw, UWORD srch,
  39.         LONG destcols, UWORD iospecial)
  40.     {
  41.     struct IODRPReq *iodrp;
  42.     struct MsgPort  *printerPort;
  43.     struct ViewPort *vp;
  44.     ULONG tmpl;
  45.     int error = PDERR_BADDIMENSION;
  46.  
  47.     if(!scr)    return(error);
  48.  
  49.     if((!destcols)&&(!iospecial))
  50.     {
  51.     /* Then we compute what they should be */
  52.     if((!srcx)&&(!srcy)&&(srcw==scr->Width)&&(srch==scr->Height))
  53.         {
  54.         iospecial = SPECIAL_FULLCOLS|SPECIAL_ASPECT;
  55.         }
  56.     else
  57.         {
  58.         iospecial = SPECIAL_FRACCOLS|SPECIAL_ASPECT;
  59.         tmpl = srcw;
  60.         tmpl = tmpl << 16;
  61.         destcols = (tmpl / scr->Width) << 16;
  62.         }
  63.     }
  64.  
  65.     if(printerPort = CreatePort(0,0))
  66.     {
  67.     if(iodrp=
  68.        (struct IODRPReq *)CreateExtIO(printerPort,sizeof(struct IODRPReq)))
  69.         {
  70.         if(!(error=OpenDevice("printer.device",0,iodrp,0)))
  71.         {
  72.                 vp = &scr->ViewPort;
  73.                 iodrp->io_Command = PRD_DUMPRPORT;
  74.                 iodrp->io_RastPort = &scr->RastPort;
  75.                 iodrp->io_ColorMap = vp->ColorMap;
  76.                 iodrp->io_Modes = (ULONG)vp->Modes;
  77.              iodrp->io_SrcX = srcx;
  78.             iodrp->io_SrcY = srcy;
  79.                 iodrp->io_SrcWidth = srcw;
  80.                 iodrp->io_SrcHeight = srch;
  81.             iodrp->io_DestCols = destcols;
  82.     /*      iodrp->io_DestRows = 0; cleared by allocation */
  83.                 iodrp->io_Special = iospecial;
  84.  
  85.                 error = DoIO(iodrp);
  86.  
  87.                 CloseDevice(iodrp);
  88.                 }
  89.         DeleteExtIO(iodrp);
  90.           }
  91.           DeletePort(printerPort);
  92.           }
  93.     return(error);
  94.     }
  95.