home *** CD-ROM | disk | FTP | other *** search
- /*
- pmapload.c
-
- % Pixel map loading/saving code.
-
- 5/02/89 by Ted.
-
- OWL 1.2
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 7/05/89 ted Added pmapioreq, pmap_IoInitFunc and related stuff.
- 3/28/90 jmd ansi-fied
- 11/06/90 ted changed pmap_IoNullReq msg arg from int to dig_pcmsg type.
- */
-
- #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(FILE *fd, ocolmap_type crange)
- /*
- 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.
- 'crange' is the color range to use for the loaded image
- */
- {
- 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(VOID *xbfile, char *name, ocolmap_type crange)
- /*
- 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.
- 'crange' is the color range to use for the loaded image
- */
- {
- 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(FILE *fd, pmap_type pmap, ocolmap_type cmap)
- /*
- 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.
- 'cmap' is the color range to use for the saved image
- */
- {
- 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(VOID *xbfile, char *name, pmap_type pmap, ocolmap_type cmap)
- /*
- 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.
- 'cmap' is the color range to use for the saved image
- */
- {
- 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(pmapioreq_fptr 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(dig_pcmsg msg, VOID *indata, VOID *outdata)
- /*
- 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);
- }
- /* -------------------------------------------------------------------------- */
-
-