home *** CD-ROM | disk | FTP | other *** search
- /*
- dispapv.c
-
- % Device independent pixel value allocation.
-
- 2/4/90 by Ted.
-
- OWL 1.2
- Copyright (c) 1988, 1989 by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 3/28/90 jmd ansi-fied
- 5/02/90 ted Fixed GetPixval: dist=0, rbg=>rgb.
- */
-
- #include "oakhead.h"
- #include "disppriv.h"
- #include "disppvs.h"
-
- /* -------------------------------------------------------------------------- */
-
- boolean disp_AllocPixval(opixval *pixvalp)
- /*
- Allocates a pixval for read/write. The system picks a free pixval and
- returns it in 'pixvalp'. Returns FALSE if no pixvals are free.
- */
- {
- return((boolean) disp_Control(DC_PVALLOC, NULL, pixvalp));
- }
- /* -------------------------------------------------------------------------- */
-
- int disp_FindPixval(orgb_struct *rgb, opixval *pixvalp, int maxcdist)
- /*
- Finds a pixel value whose color matches the given rgb value as closely as
- possible and allocates it read-only.
- Fails if no read-only pixval can be found whose color is within 'maxcdist'.
- If a suitable pixval is found, it is returned in 'pixvalp' and its distance
- from the given rgb is returned.
- If no suitable pixval is found, -1 is returned and *pixvalp is undefined.
- */
- {
- findcol_struct findcol;
-
- findcol.rgb = rgb;
- findcol.maxcdist = maxcdist;
-
- return(disp_Control(DC_PVFINDRGB, &findcol, pixvalp));
- }
- /* -------------------------------------------------------------------------- */
-
- void disp_MakePixvalRO(opixval pixval)
- /*
- Allocates a specified pixval for read-only, or for read/write if 'readwrite'
- is TRUE;
- Returns FALSE if 'readwrite' and the pixval is already allocated by someone
- else, or if the pixval is already allocated read/write by someone else.
- */
- {
- disp_Control(DC_PVMAKERO, &pixval, NULL);
- }
- /* -------------------------------------------------------------------------- */
-
- void disp_FreePixval(opixval pixval)
- /*
- Frees a pixval that was allocated as either read/write or read only.
- */
- {
- disp_Control(DC_PVFREE, &pixval, NULL);
- }
- /* -------------------------------------------------------------------------- */
-
- int disp_GetPixval(orgb_struct *rgb, opixval *pixvalp, int maxcdist)
- /*
- Finds or creates a pixel value whose color matches the given rgb value as
- closely as possible.
- If no read-only pixval can be found whose color is within 'maxcdist', one
- is created from an unclaimed pixval.
- If a suitable pixval is found or created, it is returned in 'pixvalp' and
- its distance from the given rgb is returned.
- If no suitable pixval is found or can be created, -1 is returned and
- *pixvalp is undefined.
- */
- {
- int dist;
-
- hard_Claim();
- if ((dist = disp_FindPixval(rgb, pixvalp, maxcdist)) == -1) {
- if (disp_AllocPixval(pixvalp)) {
-
- /* Set the pixval to the color we want */
- disp_SetColMapEntry(*pixvalp, rgb->rgb[ORED], rgb->rgb[OGREEN], rgb->rgb[OBLUE]);
-
- /* Make the pixval read-only. */
- disp_MakePixvalRO(*pixvalp);
-
- dist = 0;
- }
- }
- hard_Release();
- return(dist);
- }
- /* -------------------------------------------------------------------------- */
-
-