home *** CD-ROM | disk | FTP | other *** search
- /*
- pmapload.c
-
- % Pixel map loading/saving code.
-
- 5/02/89 by Ted.
-
- OWL 1.1
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 7/05/89 ted Added pmapioreq, pmap_IoInitFunc and related stuff.
- */
-
- #include "oakhead.h"
- #include "disppriv.h"
- #include "pmlsreq.h"
-
- #define BFT_PMAP 666
-
- /*
- Global pmap I/O function pointer called from DIG pmap_pControl funcs to load
- and save pmaps. This mechanism is used to avoid linking in pmap load and
- save code when it is not ever called. The programmer must call pmap_IoInit
- in order to engage the load/save DIG code.
- */
- OGLOBAL pmapioreq_fptr pmapioreq = pmap_IoNullReq;
- /* -------------------------------------------------------------------------- */
-
- pmap_type pmap_Load(fd, crange)
- FILE *fd;
- ocolmap_type crange; /* color range to use for the loaded image */
- /*
- Load a pmap from a PCX fomat disk file. The colors in the image are
- squeezed into the range represented in the colormap 'crange'.
- Note that a pmap is loaded assuming its configuration
- (nplanes, pixbits, etc.) matches that of the display.
- */
- {
- pmaplsreq_struct pmlsr;
-
- if (fd == NULL) {
- return(NULL);
- }
- pmlsr.frw.isbfile = FALSE;
- pmlsr.frw.buf = NULL;
- pmlsr.frw.fd = fd;
- pmlsr.crange = crange;
- pmlsr.pmap = NULL; /* In case of failure */
-
- pmap_Control(PC_LOADPMAP, &pmlsr, NULL);
-
- return(pmlsr.pmap);
- }
- /* -------------------------------------------------------------------------- */
-
- pmap_type pmap_LoadBfile(xbfile, name, crange)
- VOID *xbfile;
- char *name;
- ocolmap_type crange; /* color range to use for the loaded image */
- /*
- Load a pmap from an already open bfile. The colors in the image are
- squeezed into the range represented in the colormap 'crange'. The image
- must start at the beginning of the named block in the bfile.
- Note that a pmap is loaded assuming its configuration
- (nplanes, pixbits, etc.) matches that of the display.
-
- The xbfile parameter is declared void * so that "pmapdecl.h" can be
- included in "disp.h" without requiring "bfdecl.h" to be included as well.
- */
- {
- bfile_type bfile;
- pmaplsreq_struct pmlsr;
-
- bfile = (bfile_type) xbfile;
-
- /* Find the start of the named bfile block to load from */
- if (!bfile_Find(bfile, name, BFT_PMAP)) {
- return(NULL);
- }
- pmlsr.frw.isbfile = TRUE;
- pmlsr.frw.buf = NULL;
- pmlsr.frw.bfile = bfile;
-
- pmlsr.crange = crange;
- pmlsr.pmap = NULL; /* In case of failure */
-
- pmap_Control(PC_LOADPMAP, &pmlsr, NULL);
- return(pmlsr.pmap);
- }
- /* -------------------------------------------------------------------------- */
-
- boolean pmap_Save(fd, pmap, cmap)
- FILE *fd;
- pmap_type pmap;
- ocolmap_type cmap; /* color range to use for the saved image */
- /*
- Save a pc format pmap to a file in PCX format.
- A pmap is saved in its own pixel/plane configuration.
-
- Returns TRUE if successful.
- */
- {
- pmaplsreq_struct pmlsr;
- boolean ret;
-
- if (fd == NULL) {
- return(FALSE);
- }
- pmlsr.frw.isbfile = FALSE;
- pmlsr.frw.buf = NULL;
- pmlsr.frw.fd = fd;
- pmlsr.pmap = pmap;
- pmlsr.crange = cmap;
-
- pmap_Control(PC_SAVEPMAP, &pmlsr, &ret);
-
- return(ret);
- }
- /*----------------------------------------------------------------------------*/
-
- boolean pmap_SaveBfile(xbfile, name, pmap, cmap)
- VOID *xbfile;
- char *name;
- pmap_type pmap;
- ocolmap_type cmap; /* color range to use for the saved image */
- /*
- Save a pc format pmap to a bfile.
- A pmap is saved in its own pixel/plane configuration.
- Returns TRUE if successful.
-
- Note: the xbfile parameter is declared void * so that "pmapdecl.h" can be
- included in "disp.h" without requiring "bfdecl.h" to be included as well.
- */
- {
- pmaplsreq_struct pmlsr;
- boolean ret;
- bfile_type bfile;
-
- bfile = (bfile_type) xbfile;
-
- /* Create the named bfile block to save to */
- if (!bfile_Find(bfile, name, BFT_PMAP)) {
- return(FALSE);
- }
-
- pmlsr.frw.isbfile = TRUE;
- pmlsr.frw.buf = NULL;
- pmlsr.frw.bfile = bfile;
-
- pmlsr.pmap = pmap;
- pmlsr.crange = cmap;
-
- pmap_Control(PC_SAVEPMAP, &pmlsr, &ret);
- return(ret);
- }
- /* -------------------------------------------------------------------------- */
-
- void pmap_IoInitFunc(iofunc)
- pmapioreq_func ((*iofunc));
- /*
- Initialize the global pmap i/o function pointer to point to some function.
- The function is usually def_PmapIoReq as defined in dispmode.h.
- */
- {
- pmapioreq = iofunc;
- }
- /* -------------------------------------------------------------------------- */
-
- int pmap_IoNullReq(msg, indata, outdata)
- int msg; /* message */
- VOID *indata; /* message input data */
- VOID *outdata; /* message output data */
- /*
- Empty pmap io request message handler. Used for initializing function
- pointer so it can point somewhere.
- */
- {
- oak_notused(msg);
- oak_notused(indata);
- oak_notused(outdata);
-
- return(FALSE);
- }
- /* -------------------------------------------------------------------------- */
-