HVCGcC.c revision 61b2299d
1/* $Xorg: HVCGcC.c,v 1.3 2000/08/17 19:44:36 cpqbld Exp $ */
2
3/*
4 * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
5 * 	All Rights Reserved
6 *
7 * This file is a component of an X Window System-specific implementation
8 * of Xcms based on the TekColor Color Management System.  TekColor is a
9 * trademark of Tektronix, Inc.  The term "TekHVC" designates a particular
10 * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent
11 * foreign patents pending).  Permission is hereby granted to use, copy,
12 * modify, sell, and otherwise distribute this software and its
13 * documentation for any purpose and without fee, provided that:
14 *
15 * 1. This copyright, permission, and disclaimer notice is reproduced in
16 *    all copies of this software and any modification thereof and in
17 *    supporting documentation;
18 * 2. Any color-handling application which displays TekHVC color
19 *    cooordinates identifies these as TekHVC color coordinates in any
20 *    interface that displays these coordinates and in any associated
21 *    documentation;
22 * 3. The term "TekHVC" is always used, and is only used, in association
23 *    with the mathematical derivations of the TekHVC Color Space,
24 *    including those provided in this file and any equivalent pathways and
25 *    mathematical derivations, regardless of digital (e.g., floating point
26 *    or integer) representation.
27 *
28 * Tektronix makes no representation about the suitability of this software
29 * for any purpose.  It is provided "as is" and with all faults.
30 *
31 * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
32 * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
33 * PARTICULAR PURPOSE.  IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
34 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
35 * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
36 * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
37 * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
38 *
39 *	NAME
40 *		TekHVCGcC.c
41 *
42 *	DESCRIPTION
43 *		Source for XcmsTekHVCClipC() gamut compression routine.
44 *
45 */
46/* $XFree86: xc/lib/X11/HVCGcC.c,v 1.3 2001/01/17 19:41:37 dawes Exp $ */
47
48#ifdef HAVE_CONFIG_H
49#include <config.h>
50#endif
51#include "Xlibint.h"
52#include "Xcmsint.h"
53#include "Cv.h"
54
55
56/************************************************************************
57 *									*
58 *			 PUBLIC ROUTINES				*
59 *									*
60 ************************************************************************/
61
62/*
63 *	NAME
64 *		XcmsTekHVCClipC - Reduce the chroma for a hue and value
65 *
66 *	SYNOPSIS
67 */
68/* ARGSUSED */
69Status
70XcmsTekHVCClipC (
71    XcmsCCC ccc,
72    XcmsColor *pColors_in_out,
73    unsigned int nColors,
74    unsigned int i,
75    Bool *pCompressed)
76/*
77 *	DESCRIPTION
78 *		Reduce the Chroma for a specific hue and value to
79 *		to bring the given color into the gamut of the
80 *		specified device.  As required of gamut compression
81 *		functions in Xcms, this routine returns pColor_in_out
82 *		in XcmsCIEXYZFormat on successful completion.
83 *
84 *		Since this routine works with the value within
85 *		pColor_in_out intermediate results may be returned
86 *		even though it may be invalid.
87 *
88 *	RETURNS
89 *		XcmsFailure - Failure
90 *              XcmsSuccess - Succeeded
91 *
92 */
93{
94    Status retval;
95    XcmsColor *pColor;
96
97    /*
98     * Color specification passed as input can be assumed to:
99     *	1. Be in XcmsCIEXYZFormat
100     *	2. Already be white point adjusted for the Screen White Point.
101     *	    This means that the white point now associated with this
102     *	    color spec is the Screen White Point (even if the
103     *	    ccc->clientWhitePt differs).
104     */
105
106    /*
107     * Insure TekHVC installed
108     */
109    if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) {
110	return(XcmsFailure);
111    }
112
113    pColor = pColors_in_out + i;
114
115    if (ccc->visual->class < StaticColor &&
116	    FunctionSetOfCCC(ccc) != (XPointer) &XcmsLinearRGBFunctionSet) {
117	/*
118	 * GRAY !
119	 */
120	_XcmsDIConvertColors(ccc, pColor, &ccc->pPerScrnInfo->screenWhitePt,
121		1, XcmsTekHVCFormat);
122	pColor->spec.TekHVC.H = pColor->spec.TekHVC.C = 0.0;
123	_XcmsDIConvertColors(ccc, pColor, &ccc->pPerScrnInfo->screenWhitePt,
124		1, XcmsCIEXYZFormat);
125	if (pCompressed) {
126	    *(pCompressed + i) = True;
127	}
128	return(XcmsSuccess);
129    } else {
130	if (pColor->format != XcmsTekHVCFormat) {
131	    if (_XcmsDIConvertColors(ccc, pColor,
132		    &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat)
133		    == XcmsFailure) {
134		return(XcmsFailure);
135	    }
136	}
137	if (XcmsTekHVCQueryMaxC(ccc,
138		pColor->spec.TekHVC.H,
139		pColor->spec.TekHVC.V,
140		pColor)
141		== XcmsFailure) {
142	    return(XcmsFailure);
143	}
144	retval = _XcmsDIConvertColors(ccc, pColor,
145		&ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
146	if (retval != XcmsFailure && pCompressed != NULL) {
147	    *(pCompressed + i) = True;
148	}
149	return(retval);
150    }
151}
152