LuvGcC.c revision 61b2299d
1/* $Xorg: LuvGcC.c,v 1.3 2000/08/17 19:44:41 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.  Permission is
9 * hereby granted to use, copy, modify, sell, and otherwise distribute this
10 * software and its documentation for any purpose and without fee, provided
11 * that this copyright, permission, and disclaimer notice is reproduced in
12 * all copies of this software and in supporting documentation.  TekColor
13 * is a trademark of Tektronix, Inc.
14 *
15 * Tektronix makes no representation about the suitability of this software
16 * for any purpose.  It is provided "as is" and with all faults.
17 *
18 * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
19 * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE.  IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
21 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
22 * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
23 * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
24 * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
25 *
26 *	NAME
27 *		CIELuvGcC.c
28 *
29 *	DESCRIPTION
30 *		Source for XcmsCIELuvClipuv() gamut compression routine.
31 *
32 */
33/* $XFree86: xc/lib/X11/LuvGcC.c,v 1.3 2001/01/17 19:41:39 dawes Exp $ */
34
35#ifdef HAVE_CONFIG_H
36#include <config.h>
37#endif
38#include "Xlibint.h"
39#include "Xcmsint.h"
40#include "Cv.h"
41
42
43/************************************************************************
44 *									*
45 *			 PUBLIC ROUTINES				*
46 *									*
47 ************************************************************************/
48
49/*
50 *	NAME
51 *		XcmsCIELuvClipuv - Reduce the chroma for a hue and L*
52 *
53 *	SYNOPSIS
54 */
55/* ARGSUSED */
56Status
57XcmsCIELuvClipuv (
58    XcmsCCC ccc,
59    XcmsColor *pColors_in_out,
60    unsigned int nColors,
61    unsigned int i,
62    Bool *pCompressed)
63/*
64 *	DESCRIPTION
65 *		Reduce the Chroma for a specific hue and chroma to
66 *		to bring the given color into the gamut of the
67 *		specified device.  As required of gamut compression
68 *		functions, this routine returns pColor_in_out
69 *		in XcmsCIEXYZFormat on successful completion.
70 *
71 *		Since this routine works with the L* within
72 *		pColor_in_out intermediate results may be returned
73 *		even though it may be invalid.
74 *
75 *	RETURNS
76 *		XcmsFailure - Failure
77 *              XcmsSuccess - Succeeded
78 *
79 */
80{
81    Status retval;
82    XcmsColor *pColor;
83
84    /*
85     * Color specification passed as input can be assumed to:
86     *	1. Be in XcmsCIEXYZFormat
87     *	2. Already be white point adjusted for the Screen White Point.
88     *	    This means that the white point now associated with this
89     *	    color spec is the Screen White Point (even if the
90     *	    ccc->clientWhitePt differs).
91     */
92
93    pColor = pColors_in_out + i;
94
95    if (ccc->visual->class < PseudoColor) {
96	/*
97	 * GRAY !
98	 */
99	_XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc),
100		1, XcmsCIELuvFormat);
101	_XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc),
102		1, XcmsCIEXYZFormat);
103	if (pCompressed) {
104	    *(pCompressed + i) = True;
105	}
106	return(XcmsSuccess);
107    } else {
108	if (pColor->format != XcmsCIELuvFormat) {
109	    if (_XcmsDIConvertColors(ccc, pColor,
110		    &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIELuvFormat)
111		    == XcmsFailure) {
112		return(XcmsFailure);
113	    }
114	}
115	if (XcmsCIELuvQueryMaxC(ccc,
116		degrees(XCMS_CIELUV_PMETRIC_HUE(pColor->spec.CIELuv.u_star,
117						pColor->spec.CIELuv.v_star)),
118		pColor->spec.CIELuv.L_star,
119		pColor) == XcmsFailure) {
120	    return(XcmsFailure);
121	}
122	retval = _XcmsDIConvertColors(ccc, pColor,
123		&ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
124	if (retval != XcmsFailure && pCompressed != NULL) {
125	    *(pCompressed + i) = True;
126	}
127	return(retval);
128    }
129}
130