Debian Codegraph @

nx-X11/lib/src/xcms/HVCGcC.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 * TekHVCGcC.c
40 *
41 * DESCRIPTION
42 * Source for XcmsTekHVCClipC() 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 * XcmsTekHVCClipC - Reduce the chroma for a hue and value
63 *
64 * SYNOPSIS
65 */
66 /* ARGSUSED */
67 Status
68 XcmsTekHVCClipC (
69 XcmsCCC ccc,
70 XcmsColor *pColors_in_out,
71 unsigned int nColors,
72 unsigned int i,
73 Bool *pCompressed)
74 /*
75 * DESCRIPTION
76 * Reduce the Chroma for a specific hue and value to
77 * to bring the given color into the gamut of the
78 * specified device. As required of gamut compression
79 * functions in Xcms, this routine returns pColor_in_out
80 * in XcmsCIEXYZFormat on successful completion.
81 *
82 * Since this routine works with the value within
83 * pColor_in_out intermediate results may be returned
84 * even though it may be invalid.
85 *
86 * RETURNS
87 * XcmsFailure - Failure
88 * XcmsSuccess - Succeeded
89 *
90 */
91 {
92 Status retval;
93 XcmsColor *pColor;
94
95 /*
96 * Color specification passed as input can be assumed to:
97 * 1. Be in XcmsCIEXYZFormat
98 * 2. Already be white point adjusted for the Screen White Point.
99 * This means that the white point now associated with this
100 * color spec is the Screen White Point (even if the
101 * ccc->clientWhitePt differs).
102 */
103
104 /*
105 * Insure TekHVC installed
106 */
107 if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) {
108 return(XcmsFailure);
109 }
110
111 pColor = pColors_in_out + i;
112
113 if (ccc->visual->class < StaticColor &&
114 FunctionSetOfCCC(ccc) != (XPointer) &XcmsLinearRGBFunctionSet) {
115 /*
116 * GRAY !
117 */
118 _XcmsDIConvertColors(ccc, pColor, &ccc->pPerScrnInfo->screenWhitePt,
119 1, XcmsTekHVCFormat);
120 pColor->spec.TekHVC.H = pColor->spec.TekHVC.C = 0.0;
121 _XcmsDIConvertColors(ccc, pColor, &ccc->pPerScrnInfo->screenWhitePt,
122 1, XcmsCIEXYZFormat);
123 if (pCompressed) {
124 *(pCompressed + i) = True;
125 }
126 return(XcmsSuccess);
127 } else {
128 if (pColor->format != XcmsTekHVCFormat) {
129 if (_XcmsDIConvertColors(ccc, pColor,
130 &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat)
131 == XcmsFailure) {
132 return(XcmsFailure);
133 }
134 }
135 if (XcmsTekHVCQueryMaxC(ccc,
136 pColor->spec.TekHVC.H,
137 pColor->spec.TekHVC.V,
138 pColor)
139 == XcmsFailure) {
140 return(XcmsFailure);
141 }
142 retval = _XcmsDIConvertColors(ccc, pColor,
143 &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
144 if (retval != XcmsFailure && pCompressed != NULL) {
145 *(pCompressed + i) = True;
146 }
147 return(retval);
148 }
149 }