| 1 |
|
| 2 |
/* |
| 3 |
* Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. |
| 4 |
* All Rights Reserved |
| 5 |
* |
| 6 |
* This file is a component of an X Window System-specific implementation |
| 7 |
* of Xcms based on the TekColor Color Management System. TekColor is a |
| 8 |
* trademark of Tektronix, Inc. The term "TekHVC" designates a particular |
| 9 |
* color space that is the subject of U.S. Patent No. 4,985,853 (equivalent |
| 10 |
* foreign patents pending). Permission is hereby granted to use, copy, |
| 11 |
* modify, sell, and otherwise distribute this software and its |
| 12 |
* documentation for any purpose and without fee, provided that: |
| 13 |
* |
| 14 |
* 1. This copyright, permission, and disclaimer notice is reproduced in |
| 15 |
* all copies of this software and any modification thereof and in |
| 16 |
* supporting documentation; |
| 17 |
* 2. Any color-handling application which displays TekHVC color |
| 18 |
* cooordinates identifies these as TekHVC color coordinates in any |
| 19 |
* interface that displays these coordinates and in any associated |
| 20 |
* documentation; |
| 21 |
* 3. The term "TekHVC" is always used, and is only used, in association |
| 22 |
* with the mathematical derivations of the TekHVC Color Space, |
| 23 |
* including those provided in this file and any equivalent pathways and |
| 24 |
* mathematical derivations, regardless of digital (e.g., floating point |
| 25 |
* or integer) representation. |
| 26 |
* |
| 27 |
* Tektronix makes no representation about the suitability of this software |
| 28 |
* for any purpose. It is provided "as is" and with all faults. |
| 29 |
* |
| 30 |
* TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, |
| 31 |
* INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 32 |
* PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY |
| 33 |
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 34 |
* RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF |
| 35 |
* CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 36 |
* CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. |
| 37 |
* |
| 38 |
* NAME |
| 39 |
* TekHVCMxVs.c |
| 40 |
* |
| 41 |
* DESCRIPTION |
| 42 |
* Source for the XcmsTekHVCQueryMaxVSamples() gamut boundary |
| 43 |
* querying routine. |
| 44 |
*/ |
| 45 |
|
| 46 |
#ifdef HAVE_CONFIG_H |
| 47 |
#include <config.h> |
| 48 |
#endif |
| 49 |
#include "Xlibint.h" |
| 50 |
#include "Xcmsint.h" |
| 51 |
#include "Cv.h" |
| 52 |
|
| 53 |
|
| 54 |
/************************************************************************ |
| 55 |
* * |
| 56 |
* PUBLIC ROUTINES * |
| 57 |
* * |
| 58 |
************************************************************************/ |
| 59 |
|
| 60 |
/* |
| 61 |
* NAME |
| 62 |
* XcmsTekHVCQueryMaxVSamples - Compute a set of value/chroma |
| 63 |
* pairs. |
| 64 |
* |
| 65 |
* SYNOPSIS |
| 66 |
*/ |
| 67 |
Status |
| 68 |
XcmsTekHVCQueryMaxVSamples( |
| 69 |
XcmsCCC ccc, |
| 70 |
XcmsFloat hue, |
| 71 |
XcmsColor *pColor_in_out, |
| 72 |
unsigned int nSamples) |
| 73 |
|
| 74 |
/* |
| 75 |
* DESCRIPTION |
| 76 |
* Return a set of values and chromas for the input Hue. |
| 77 |
* This routine will take any color as input. |
| 78 |
* It returns TekHVC colors. |
| 79 |
* |
| 80 |
* Since this routine works with the value within |
| 81 |
* pColor_in_out intermediate results may be returned |
| 82 |
* even though it may be invalid. |
| 83 |
* |
| 84 |
* ASSUMPTIONS |
| 85 |
* This routine assumes that the white point associated with |
| 86 |
* the color specification is the Screen White Point. The |
| 87 |
* Screen White Point will also be associated with the |
| 88 |
* returned color specification. |
| 89 |
* |
| 90 |
* RETURNS |
| 91 |
* XcmsFailure - Failure |
| 92 |
* XcmsSuccess - Succeeded |
| 93 |
* |
| 94 |
*/ |
| 95 |
{ |
| 96 |
XcmsCCCRec myCCC; |
| 97 |
XcmsColor *pHVC; |
| 98 |
XcmsRGBi rgb_saved; |
| 99 |
unsigned short nI; |
| 100 |
XcmsFloat nT; |
| 101 |
|
| 102 |
/* |
| 103 |
* Check Arguments |
| 104 |
*/ |
| 105 |
if (ccc == NULL || pColor_in_out == NULL || nSamples == 0) { |
| 106 |
return(XcmsFailure); |
| 107 |
} |
| 108 |
|
| 109 |
/* |
| 110 |
* Insure TekHVC installed |
| 111 |
*/ |
| 112 |
if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) { |
| 113 |
return(XcmsFailure); |
| 114 |
} |
| 115 |
|
| 116 |
/* setup the CCC to use for the conversions. */ |
| 117 |
memcpy ((char *) &myCCC, (char *) ccc, sizeof(XcmsCCCRec)); |
| 118 |
myCCC.clientWhitePt.format = XcmsUndefinedFormat; |
| 119 |
myCCC.gamutCompProc = (XcmsCompressionProc) NULL; |
| 120 |
|
| 121 |
/* Step 1: compute the maximum value and chroma for this hue. */ |
| 122 |
|
| 123 |
|
| 124 |
/* save the Hue for use later. */ |
| 125 |
while (hue < 0.0) { |
| 126 |
hue += 360.0; |
| 127 |
} |
| 128 |
while (hue > 360.0) { |
| 129 |
hue -= 360.0; |
| 130 |
} |
| 131 |
pColor_in_out->spec.TekHVC.H = hue; |
| 132 |
pColor_in_out->format = XcmsTekHVCFormat; |
| 133 |
|
| 134 |
/* Get the maximum value and chroma point for this hue */ |
| 135 |
if (_XcmsTekHVCQueryMaxVCRGB(&myCCC, pColor_in_out->spec.TekHVC.H, |
| 136 |
pColor_in_out, (XcmsRGBi *)&rgb_saved) == XcmsFailure) { |
| 137 |
return (XcmsFailure); |
| 138 |
} |
| 139 |
|
| 140 |
/* Step 2: Convert each of the RGBi's to HVC's */ |
| 141 |
pHVC = pColor_in_out; |
| 142 |
for (nI = 0; nI < nSamples; nI++, pHVC++) { |
| 143 |
nT = (XcmsFloat) nI / (XcmsFloat) nSamples; |
| 144 |
pHVC->spec.RGBi.red = rgb_saved.red * (1.0 - nT) + nT; |
| 145 |
pHVC->spec.RGBi.green = rgb_saved.green * (1.0 - nT) + nT; |
| 146 |
pHVC->spec.RGBi.blue = rgb_saved.blue * (1.0 - nT) + nT; |
| 147 |
pHVC->format = XcmsRGBiFormat; |
| 148 |
pHVC->pixel = pColor_in_out->pixel; |
| 149 |
/* convert from RGB to HVC */ |
| 150 |
if (_XcmsConvertColorsWithWhitePt(&myCCC, pHVC, |
| 151 |
&myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat, |
| 152 |
(Bool *) NULL) == XcmsFailure) { |
| 153 |
return(XcmsFailure); |
| 154 |
} |
| 155 |
|
| 156 |
/* make sure to return the input hue */ |
| 157 |
pHVC->spec.TekHVC.H = hue; |
| 158 |
} |
| 159 |
|
| 160 |
return(XcmsSuccess); |
| 161 |
} |