11ab64890Smrg
21ab64890Smrg/*
31ab64890Smrg * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
41ab64890Smrg * 	All Rights Reserved
561b2299dSmrg *
61ab64890Smrg * This file is a component of an X Window System-specific implementation
71ab64890Smrg * of Xcms based on the TekColor Color Management System.  TekColor is a
81ab64890Smrg * trademark of Tektronix, Inc.  The term "TekHVC" designates a particular
91ab64890Smrg * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent
101ab64890Smrg * foreign patents pending).  Permission is hereby granted to use, copy,
111ab64890Smrg * modify, sell, and otherwise distribute this software and its
121ab64890Smrg * documentation for any purpose and without fee, provided that:
1361b2299dSmrg *
141ab64890Smrg * 1. This copyright, permission, and disclaimer notice is reproduced in
151ab64890Smrg *    all copies of this software and any modification thereof and in
1661b2299dSmrg *    supporting documentation;
171ab64890Smrg * 2. Any color-handling application which displays TekHVC color
181ab64890Smrg *    cooordinates identifies these as TekHVC color coordinates in any
191ab64890Smrg *    interface that displays these coordinates and in any associated
201ab64890Smrg *    documentation;
211ab64890Smrg * 3. The term "TekHVC" is always used, and is only used, in association
221ab64890Smrg *    with the mathematical derivations of the TekHVC Color Space,
231ab64890Smrg *    including those provided in this file and any equivalent pathways and
241ab64890Smrg *    mathematical derivations, regardless of digital (e.g., floating point
251ab64890Smrg *    or integer) representation.
2661b2299dSmrg *
271ab64890Smrg * Tektronix makes no representation about the suitability of this software
281ab64890Smrg * for any purpose.  It is provided "as is" and with all faults.
2961b2299dSmrg *
301ab64890Smrg * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
311ab64890Smrg * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
321ab64890Smrg * PARTICULAR PURPOSE.  IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
331ab64890Smrg * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
341ab64890Smrg * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
351ab64890Smrg * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
361ab64890Smrg * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
371ab64890Smrg *
381ab64890Smrg *	NAME
391ab64890Smrg *		TekHVCGcC.c
401ab64890Smrg *
411ab64890Smrg *	DESCRIPTION
421ab64890Smrg *		Source for XcmsTekHVCClipC() gamut compression routine.
431ab64890Smrg *
441ab64890Smrg */
451ab64890Smrg
461ab64890Smrg#ifdef HAVE_CONFIG_H
471ab64890Smrg#include <config.h>
481ab64890Smrg#endif
491ab64890Smrg#include "Xlibint.h"
501ab64890Smrg#include "Xcmsint.h"
511ab64890Smrg#include "Cv.h"
521ab64890Smrg
531ab64890Smrg
541ab64890Smrg/************************************************************************
551ab64890Smrg *									*
561ab64890Smrg *			 PUBLIC ROUTINES				*
571ab64890Smrg *									*
581ab64890Smrg ************************************************************************/
591ab64890Smrg
601ab64890Smrg/*
611ab64890Smrg *	NAME
621ab64890Smrg *		XcmsTekHVCClipC - Reduce the chroma for a hue and value
631ab64890Smrg *
641ab64890Smrg *	SYNOPSIS
651ab64890Smrg */
661ab64890Smrg/* ARGSUSED */
671ab64890SmrgStatus
681ab64890SmrgXcmsTekHVCClipC (
6961b2299dSmrg    XcmsCCC ccc,
7061b2299dSmrg    XcmsColor *pColors_in_out,
711ab64890Smrg    unsigned int nColors,
721ab64890Smrg    unsigned int i,
731ab64890Smrg    Bool *pCompressed)
741ab64890Smrg/*
751ab64890Smrg *	DESCRIPTION
761ab64890Smrg *		Reduce the Chroma for a specific hue and value to
7761b2299dSmrg *		to bring the given color into the gamut of the
781ab64890Smrg *		specified device.  As required of gamut compression
791ab64890Smrg *		functions in Xcms, this routine returns pColor_in_out
801ab64890Smrg *		in XcmsCIEXYZFormat on successful completion.
8161b2299dSmrg *
821ab64890Smrg *		Since this routine works with the value within
831ab64890Smrg *		pColor_in_out intermediate results may be returned
841ab64890Smrg *		even though it may be invalid.
851ab64890Smrg *
861ab64890Smrg *	RETURNS
871ab64890Smrg *		XcmsFailure - Failure
881ab64890Smrg *              XcmsSuccess - Succeeded
891ab64890Smrg *
901ab64890Smrg */
911ab64890Smrg{
921ab64890Smrg    Status retval;
931ab64890Smrg    XcmsColor *pColor;
941ab64890Smrg
951ab64890Smrg    /*
961ab64890Smrg     * Color specification passed as input can be assumed to:
971ab64890Smrg     *	1. Be in XcmsCIEXYZFormat
981ab64890Smrg     *	2. Already be white point adjusted for the Screen White Point.
991ab64890Smrg     *	    This means that the white point now associated with this
1001ab64890Smrg     *	    color spec is the Screen White Point (even if the
1011ab64890Smrg     *	    ccc->clientWhitePt differs).
1021ab64890Smrg     */
1031ab64890Smrg
1041ab64890Smrg    /*
1051ab64890Smrg     * Insure TekHVC installed
1061ab64890Smrg     */
1071ab64890Smrg    if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) {
1081ab64890Smrg	return(XcmsFailure);
1091ab64890Smrg    }
1101ab64890Smrg
1111ab64890Smrg    pColor = pColors_in_out + i;
1121ab64890Smrg
1131ab64890Smrg    if (ccc->visual->class < StaticColor &&
1141ab64890Smrg	    FunctionSetOfCCC(ccc) != (XPointer) &XcmsLinearRGBFunctionSet) {
1151ab64890Smrg	/*
1161ab64890Smrg	 * GRAY !
1171ab64890Smrg	 */
1181ab64890Smrg	_XcmsDIConvertColors(ccc, pColor, &ccc->pPerScrnInfo->screenWhitePt,
1191ab64890Smrg		1, XcmsTekHVCFormat);
1201ab64890Smrg	pColor->spec.TekHVC.H = pColor->spec.TekHVC.C = 0.0;
1211ab64890Smrg	_XcmsDIConvertColors(ccc, pColor, &ccc->pPerScrnInfo->screenWhitePt,
1221ab64890Smrg		1, XcmsCIEXYZFormat);
1231ab64890Smrg	if (pCompressed) {
1241ab64890Smrg	    *(pCompressed + i) = True;
1251ab64890Smrg	}
1261ab64890Smrg	return(XcmsSuccess);
1271ab64890Smrg    } else {
1281ab64890Smrg	if (pColor->format != XcmsTekHVCFormat) {
1291ab64890Smrg	    if (_XcmsDIConvertColors(ccc, pColor,
1301ab64890Smrg		    &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat)
1311ab64890Smrg		    == XcmsFailure) {
1321ab64890Smrg		return(XcmsFailure);
1331ab64890Smrg	    }
1341ab64890Smrg	}
1351ab64890Smrg	if (XcmsTekHVCQueryMaxC(ccc,
1361ab64890Smrg		pColor->spec.TekHVC.H,
1371ab64890Smrg		pColor->spec.TekHVC.V,
1381ab64890Smrg		pColor)
1391ab64890Smrg		== XcmsFailure) {
1401ab64890Smrg	    return(XcmsFailure);
1411ab64890Smrg	}
1421ab64890Smrg	retval = _XcmsDIConvertColors(ccc, pColor,
1431ab64890Smrg		&ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
1441ab64890Smrg	if (retval != XcmsFailure && pCompressed != NULL) {
1451ab64890Smrg	    *(pCompressed + i) = True;
1461ab64890Smrg	}
1471ab64890Smrg	return(retval);
1481ab64890Smrg    }
1491ab64890Smrg}
150