Debian Codegraph @

nx-X11/lib/src/xcms/HVCGcV.c

raw
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 * TekHVCGcV.c
40 *
41 * DESCRIPTION
42 * Source for XcmsTekHVCClipV() gamut compression routine.
43 *
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 * XcmsTekHVCClipV - Return the closest value
63 *
64 * SYNOPSIS
65 */
66 /* ARGSUSED */
67 Status
68 XcmsTekHVCClipV (
69 XcmsCCC ccc,
70 XcmsColor *pColors_in_out,
71 unsigned int nColors,
72 unsigned int i,
73 Bool *pCompressed)
74 /*
75 * DESCRIPTION
76 * Return the closest value for a specific hue and chroma.
77 * This routine takes any color as input and outputs
78 * a CIE XYZ color.
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 * RETURNS
85 * XcmsFailure - Failure
86 * XcmsSuccess - Succeeded
87 *
88 */
89 {
90 XcmsColor *pColor;
91 XcmsColor hvc_max;
92 XcmsCCCRec myCCC;
93 Status retval;
94
95 /*
96 * Insure TekHVC installed
97 */
98 if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) {
99 return(XcmsFailure);
100 }
101
102 /* Use my own CCC */
103 memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec));
104 myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* Inherit Screen WP */
105 myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut compression */
106
107 /*
108 * Color specification passed as input can be assumed to:
109 * 1. Be in XcmsCIEXYZFormat
110 * 2. Already be white point adjusted for the Screen White Point.
111 * This means that the white point now associated with this
112 * color spec is the Screen White Point (even if the
113 * ccc->clientWhitePt differs).
114 */
115
116 pColor = pColors_in_out + i;
117
118 if (ccc->visual->class < StaticColor &&
119 FunctionSetOfCCC(ccc) != (XPointer) &XcmsLinearRGBFunctionSet) {
120 /*
121 * GRAY !
122 */
123 return(XcmsFailure);
124 } else {
125 /* Convert from CIEXYZ to TekHVC format */
126 if (_XcmsDIConvertColors(&myCCC, pColor,
127 &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat)
128 == XcmsFailure) {
129 return(XcmsFailure);
130 }
131
132 /* check to make sure we have a valid TekHVC number */
133 if (!_XcmsTekHVC_CheckModify (pColor)) {
134 return (XcmsFailure);
135 }
136
137 /* Step 1: compute the maximum value and chroma for this hue. */
138 /* This copy may be overkill but it preserves the pixel etc. */
139 memcpy((char *)&hvc_max, (char *)pColor, sizeof(XcmsColor));
140 if (_XcmsTekHVCQueryMaxVCRGB (&myCCC, hvc_max.spec.TekHVC.H, &hvc_max,
141 (XcmsRGBi *)NULL) == XcmsFailure) {
142 return (XcmsFailure);
143 }
144
145 /* Now check and return the appropriate value */
146 if (pColor->spec.TekHVC.C == hvc_max.spec.TekHVC.C) {
147 /* When the chroma input is equal to the maximum chroma */
148 /* merely return the value for that chroma. */
149 pColor->spec.TekHVC.V = hvc_max.spec.TekHVC.V;
150 if (!_XcmsTekHVC_CheckModify (pColor)) {
151 return (XcmsFailure);
152 }
153 retval = _XcmsDIConvertColors(&myCCC, pColor,
154 &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
155 } else if (pColor->spec.TekHVC.C > hvc_max.spec.TekHVC.C) {
156 /* When the chroma input is greater than the maximum chroma */
157 /* merely return the value and chroma for the given hue. */
158 pColor->spec.TekHVC.C = hvc_max.spec.TekHVC.C;
159 pColor->spec.TekHVC.V = hvc_max.spec.TekHVC.V;
160 return (XcmsFailure);
161 } else if (pColor->spec.TekHVC.V < hvc_max.spec.TekHVC.V) {
162 /* When the value input is less than the maximum value point */
163 /* compute the intersection of the line from 0,0 to max_V, max_C */
164 /* using the chroma input. */
165 pColor->spec.TekHVC.V = pColor->spec.TekHVC.C *
166 hvc_max.spec.TekHVC.V / hvc_max.spec.TekHVC.C;
167 if (pColor->spec.TekHVC.V >= hvc_max.spec.TekHVC.V) {
168 pColor->spec.TekHVC.C = hvc_max.spec.TekHVC.C;
169 pColor->spec.TekHVC.V = hvc_max.spec.TekHVC.V;
170 }
171 if (!_XcmsTekHVC_CheckModify (pColor)) {
172 return (XcmsFailure);
173 }
174 retval = _XcmsDIConvertColors(&myCCC, pColor,
175 &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
176 } else {
177 /* When the value input is greater than the maximum value point */
178 /* use HvcMaxValue to find the maximum value for the given chroma. */
179 if (pColor->format != XcmsTekHVCFormat) {
180 if (_XcmsDIConvertColors(ccc, pColor,
181 &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat)
182 == XcmsFailure) {
183 return(XcmsFailure);
184 }
185 }
186 if (XcmsTekHVCQueryMaxV(&myCCC,
187 pColor->spec.TekHVC.H,
188 pColor->spec.TekHVC.C,
189 pColor)
190 == XcmsFailure) {
191 return (XcmsFailure);
192 }
193 retval = _XcmsDIConvertColors(&myCCC, pColor,
194 &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
195 }
196 if (retval != XcmsFailure && pCompressed != NULL) {
197 *(pCompressed + i) = True;
198 }
199 return(retval);
200 }
201 }