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