home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / CSCAP323.ZIP / OWLSRC.EXE / PMAPLOAD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-06  |  4.8 KB  |  176 lines

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