home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / DISPAPV.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-02  |  3.1 KB  |  106 lines

  1. /*
  2.     dispapv.c
  3.  
  4.     % Device independent pixel value allocation.
  5.  
  6.     2/4/90 by Ted.
  7.  
  8.     OWL 1.2
  9.     Copyright (c) 1988, 1989 by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.      3/28/90 jmd    ansi-fied
  15.      5/02/90 ted    Fixed GetPixval: dist=0, rbg=>rgb.
  16. */
  17.  
  18. #include "oakhead.h"
  19. #include "disppriv.h"
  20. #include "disppvs.h"
  21.  
  22. /* -------------------------------------------------------------------------- */
  23.  
  24. boolean disp_AllocPixval(opixval *pixvalp)
  25. /*
  26.     Allocates a pixval for read/write. The system picks a free pixval and
  27.     returns it in 'pixvalp'. Returns FALSE if no pixvals are free.
  28. */
  29. {
  30.     return((boolean) disp_Control(DC_PVALLOC, NULL, pixvalp));
  31. }
  32. /* -------------------------------------------------------------------------- */
  33.  
  34. int disp_FindPixval(orgb_struct *rgb, opixval *pixvalp, int maxcdist)
  35. /*
  36.     Finds a pixel value whose color matches the given rgb value as closely as
  37.     possible and allocates it read-only.
  38.     Fails if no read-only pixval can be found whose color is within 'maxcdist'.
  39.     If a suitable pixval is found, it is returned in 'pixvalp' and its distance
  40.     from the given rgb is returned.
  41.     If no suitable pixval is found, -1 is returned and *pixvalp is undefined.
  42. */
  43. {
  44.     findcol_struct findcol;
  45.  
  46.     findcol.rgb = rgb;
  47.     findcol.maxcdist = maxcdist;
  48.  
  49.     return(disp_Control(DC_PVFINDRGB, &findcol, pixvalp));
  50. }
  51. /* -------------------------------------------------------------------------- */
  52.  
  53. void disp_MakePixvalRO(opixval pixval)
  54. /*
  55.     Allocates a specified pixval for read-only, or for read/write if 'readwrite'
  56.     is TRUE;
  57.     Returns FALSE if 'readwrite' and the pixval is already allocated by someone
  58.     else, or if the pixval is already allocated read/write by someone else.
  59. */
  60. {
  61.     disp_Control(DC_PVMAKERO, &pixval, NULL);
  62. }
  63. /* -------------------------------------------------------------------------- */
  64.  
  65. void disp_FreePixval(opixval pixval)
  66. /*
  67.     Frees a pixval that was allocated as either read/write or read only.
  68. */
  69. {
  70.     disp_Control(DC_PVFREE, &pixval, NULL);
  71. }
  72. /* -------------------------------------------------------------------------- */
  73.  
  74. int disp_GetPixval(orgb_struct *rgb, opixval *pixvalp, int maxcdist)
  75. /*
  76.     Finds or creates a pixel value whose color matches the given rgb value as
  77.     closely as possible.
  78.     If no read-only pixval can be found whose color is within 'maxcdist', one
  79.     is created from an unclaimed pixval. 
  80.     If a suitable pixval is found or created, it is returned in 'pixvalp' and
  81.     its distance from the given rgb is returned.
  82.     If no suitable pixval is found or can be created, -1 is returned and
  83.     *pixvalp is undefined.
  84. */
  85. {
  86.     int dist;
  87.  
  88.     hard_Claim();
  89.     if ((dist = disp_FindPixval(rgb, pixvalp, maxcdist)) == -1) {
  90.         if (disp_AllocPixval(pixvalp)) {
  91.  
  92.             /* Set the pixval to the color we want */
  93.             disp_SetColMapEntry(*pixvalp, rgb->rgb[ORED], rgb->rgb[OGREEN], rgb->rgb[OBLUE]);
  94.  
  95.             /* Make the pixval read-only. */
  96.             disp_MakePixvalRO(*pixvalp);
  97.  
  98.             dist = 0;
  99.         }
  100.     }
  101.     hard_Release();
  102.     return(dist);
  103. }
  104. /* -------------------------------------------------------------------------- */
  105.  
  106.