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 *		TekHVCMnV.c
40 *
41 *	DESCRIPTION
42 *		Source for XcmsTekHVCQueryMinV gamut boundary querying 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 *	DEFINES
55 */
56#define EPS	    0.001
57
58
59/************************************************************************
60 *									*
61 *			 PUBLIC ROUTINES				*
62 *									*
63 ************************************************************************/
64
65/*
66 *	NAME
67 *		XcmsTekHVCQueryMinV - Compute minimum value for hue and chroma
68 *
69 *	SYNOPSIS
70 */
71Status
72XcmsTekHVCQueryMinV (
73    XcmsCCC ccc,
74    XcmsFloat hue,
75    XcmsFloat chroma,
76    XcmsColor *pColor_return)
77
78/*
79 *	DESCRIPTION
80 *		Return the minimum value for a specific hue, and the
81 *		corresponding chroma.  The input color specification
82 *		may be in any format, however output is in XcmsTekHVCFormat.
83 *
84 *		Since this routine works with the value within
85 *		pColor_return intermediate results may be returned
86 *		even though it may be invalid.
87 *
88 *	ASSUMPTIONS
89 *		This routine assumes that the white point associated with
90 *		the color specification is the Screen White Point.  The
91 *		Screen White Point will also be associated with the
92 *		returned color specification.
93 *
94 *	RETURNS
95 *		XcmsFailure - Failure
96 *		XcmsSuccess - Succeeded with no modifications
97 *
98 */
99{
100    XcmsCCCRec myCCC;
101    XcmsColor tmp;
102    XcmsColor max_vc;
103
104    /*
105     * Check Arguments
106     */
107    if (ccc == NULL || pColor_return == NULL) {
108	return(XcmsFailure);
109    }
110
111    /*
112     * Insure TekHVC installed
113     */
114    if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) {
115	return(XcmsFailure);
116    }
117
118    /* Use my own CCC */
119    memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec));
120    myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* inherit screen white pt */
121    myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut comp func */
122
123    tmp.spec.TekHVC.H = hue;
124    tmp.spec.TekHVC.V = 100.0;
125    tmp.spec.TekHVC.C = chroma;
126    tmp.pixel = pColor_return->pixel;
127    tmp.format = XcmsTekHVCFormat;
128
129
130    /* Check for a valid HVC */
131    if (!_XcmsTekHVC_CheckModify (&tmp)) {
132	return(XcmsFailure);
133    }
134
135    /* Step 1: compute the maximum value and chroma for this hue. */
136    /*         This copy may be overkill but it preserves the pixel etc. */
137    memcpy((char *)&max_vc, (char *)&tmp, sizeof(XcmsColor));
138    if (_XcmsTekHVCQueryMaxVCRGB (&myCCC, max_vc.spec.TekHVC.H, &max_vc,
139	    (XcmsRGBi *)NULL) == XcmsFailure) {
140	return(XcmsFailure);
141    }
142
143    /* Step 2: find the intersection with the maximum hvc and chroma line. */
144    if (tmp.spec.TekHVC.C > max_vc.spec.TekHVC.C + EPS) {
145	/* If the chroma is to large then return maximum hvc. */
146	tmp.spec.TekHVC.C = max_vc.spec.TekHVC.C;
147	tmp.spec.TekHVC.V = max_vc.spec.TekHVC.V;
148    } else {
149	tmp.spec.TekHVC.V = tmp.spec.TekHVC.C *
150		max_vc.spec.TekHVC.V / max_vc.spec.TekHVC.C;
151	if (tmp.spec.TekHVC.V > max_vc.spec.TekHVC.V) {
152	    tmp.spec.TekHVC.V = max_vc.spec.TekHVC.V;
153	} else if (tmp.spec.TekHVC.V < 0.0) {
154	    tmp.spec.TekHVC.V = tmp.spec.TekHVC.C = 0.0;
155	}
156    }
157    if (_XcmsTekHVC_CheckModify (&tmp)) {
158	memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor));
159	return(XcmsSuccess);
160    } else {
161	return(XcmsFailure);
162    }
163}
164