home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / PMAPLOAD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-11  |  4.9 KB  |  189 lines

  1. /*
  2.     pmapload.c
  3.  
  4.     % Pixel map loading/saving code.
  5.  
  6.     5/02/89  by Ted.
  7.  
  8.     OWL 1.1
  9.     Copyright (c) 1988, by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      7/05/89 ted    Added pmapioreq, pmap_IoInitFunc and related stuff.
  15. */
  16.  
  17. #include "oakhead.h"
  18. #include "disppriv.h"
  19. #include "pmlsreq.h"
  20.  
  21. #define BFT_PMAP    666
  22.  
  23. /*
  24.     Global pmap I/O function pointer called from DIG pmap_pControl funcs to load
  25.     and save pmaps. This mechanism is used to avoid linking in pmap load and
  26.     save code when it is not ever called.  The programmer must call pmap_IoInit
  27.     in order to engage the load/save DIG code.
  28. */
  29. OGLOBAL pmapioreq_fptr pmapioreq = pmap_IoNullReq;
  30. /* -------------------------------------------------------------------------- */
  31.  
  32. pmap_type pmap_Load(fd, crange)
  33.     FILE *fd;
  34.     ocolmap_type crange;    /* color range to use for the loaded image */
  35. /*
  36.     Load a pmap from a PCX fomat disk file. The colors in the image are
  37.     squeezed into the range represented in the colormap 'crange'.
  38.     Note that a pmap is loaded assuming its configuration
  39.     (nplanes, pixbits, etc.) matches that of the display.
  40. */
  41. {
  42.     pmaplsreq_struct pmlsr;
  43.  
  44.     if (fd == NULL) {
  45.         return(NULL);
  46.     }
  47.     pmlsr.frw.isbfile = FALSE;
  48.     pmlsr.frw.buf = NULL;
  49.     pmlsr.frw.fd = fd;
  50.     pmlsr.crange = crange;
  51.     pmlsr.pmap = NULL;            /* In case of failure */
  52.  
  53.     pmap_Control(PC_LOADPMAP, &pmlsr, NULL);
  54.  
  55.     return(pmlsr.pmap);
  56. }
  57. /* -------------------------------------------------------------------------- */
  58.  
  59. pmap_type pmap_LoadBfile(xbfile, name, crange)
  60.     VOID *xbfile;
  61.     char *name;
  62.     ocolmap_type crange;    /* color range to use for the loaded image */
  63. /*
  64.     Load a pmap from an already open bfile. The colors in the image are
  65.     squeezed into the range represented in the colormap 'crange'. The image
  66.     must start at the beginning of the named block in the bfile.
  67.     Note that a pmap is loaded assuming its configuration
  68.     (nplanes, pixbits, etc.) matches that of the display.
  69.  
  70.     The xbfile parameter is declared void * so that "pmapdecl.h" can be
  71.     included in "disp.h" without requiring "bfdecl.h" to be included as well.
  72. */
  73. {
  74.     bfile_type bfile;
  75.     pmaplsreq_struct pmlsr;
  76.  
  77.     bfile = (bfile_type) xbfile;
  78.  
  79.     /* Find the start of the named bfile block to load from */
  80.     if (!bfile_Find(bfile, name, BFT_PMAP)) {
  81.         return(NULL);
  82.     }
  83.     pmlsr.frw.isbfile = TRUE;
  84.     pmlsr.frw.buf = NULL;
  85.     pmlsr.frw.bfile = bfile;
  86.  
  87.     pmlsr.crange = crange;
  88.     pmlsr.pmap = NULL;            /* In case of failure */
  89.  
  90.     pmap_Control(PC_LOADPMAP, &pmlsr, NULL);
  91.     return(pmlsr.pmap);
  92. }
  93. /* -------------------------------------------------------------------------- */
  94.  
  95. boolean pmap_Save(fd, pmap, cmap)
  96.     FILE *fd;
  97.     pmap_type pmap;
  98.     ocolmap_type cmap;    /* color range to use for the saved image */
  99. /*
  100.     Save a pc format pmap to a file in PCX format.
  101.     A pmap is saved in its own pixel/plane configuration.
  102.  
  103.     Returns TRUE if successful.
  104. */
  105. {
  106.     pmaplsreq_struct pmlsr;
  107.     boolean ret;
  108.  
  109.     if (fd == NULL) {
  110.         return(FALSE);
  111.     }
  112.     pmlsr.frw.isbfile = FALSE;
  113.     pmlsr.frw.buf = NULL;
  114.     pmlsr.frw.fd = fd;
  115.     pmlsr.pmap = pmap;
  116.     pmlsr.crange = cmap;
  117.  
  118.     pmap_Control(PC_SAVEPMAP, &pmlsr, &ret);
  119.  
  120.     return(ret);
  121. }
  122. /*----------------------------------------------------------------------------*/
  123.  
  124. boolean pmap_SaveBfile(xbfile, name, pmap, cmap)
  125.     VOID *xbfile;
  126.     char *name;
  127.     pmap_type pmap;
  128.     ocolmap_type cmap;    /* color range to use for the saved image */
  129. /*
  130.     Save a pc format pmap to a bfile.
  131.     A pmap is saved in its own pixel/plane configuration.
  132.     Returns TRUE if successful.
  133.  
  134.     Note: the xbfile parameter is declared void * so that "pmapdecl.h" can be
  135.     included in "disp.h" without requiring "bfdecl.h" to be included as well.
  136. */
  137. {
  138.     pmaplsreq_struct pmlsr;
  139.     boolean ret;
  140.     bfile_type bfile;
  141.  
  142.     bfile = (bfile_type) xbfile;
  143.  
  144.     /* Create the named bfile block to save to */
  145.     if (!bfile_Find(bfile, name, BFT_PMAP)) {
  146.         return(FALSE);
  147.     }
  148.  
  149.     pmlsr.frw.isbfile = TRUE;
  150.     pmlsr.frw.buf = NULL;
  151.     pmlsr.frw.bfile = bfile;
  152.  
  153.     pmlsr.pmap = pmap;
  154.     pmlsr.crange = cmap;
  155.  
  156.     pmap_Control(PC_SAVEPMAP, &pmlsr, &ret);
  157.     return(ret);
  158. }
  159. /* -------------------------------------------------------------------------- */
  160.  
  161. void pmap_IoInitFunc(iofunc)
  162.     pmapioreq_func ((*iofunc));
  163. /*
  164.     Initialize the global pmap i/o function pointer to point to some function.
  165.     The function is usually def_PmapIoReq as defined in dispmode.h.
  166. */
  167. {
  168.     pmapioreq = iofunc;
  169. }
  170. /* -------------------------------------------------------------------------- */
  171.  
  172. int pmap_IoNullReq(msg, indata, outdata)
  173.     int msg;                /* message */
  174.     VOID *indata;            /* message input data */
  175.     VOID *outdata;            /* message output data */
  176. /*
  177.     Empty pmap io request message handler. Used for initializing function
  178.     pointer so it can point somewhere.
  179. */
  180. {
  181.     oak_notused(msg);
  182.     oak_notused(indata);
  183.     oak_notused(outdata);
  184.  
  185.     return(FALSE);
  186. }
  187. /* -------------------------------------------------------------------------- */
  188.  
  189.