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. Permission is 81ab64890Smrg * hereby granted to use, copy, modify, sell, and otherwise distribute this 91ab64890Smrg * software and its documentation for any purpose and without fee, provided 101ab64890Smrg * that this copyright, permission, and disclaimer notice is reproduced in 111ab64890Smrg * all copies of this software and in supporting documentation. TekColor 121ab64890Smrg * is a trademark of Tektronix, Inc. 1361b2299dSmrg * 141ab64890Smrg * Tektronix makes no representation about the suitability of this software 151ab64890Smrg * for any purpose. It is provided "as is" and with all faults. 1661b2299dSmrg * 171ab64890Smrg * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, 181ab64890Smrg * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 191ab64890Smrg * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY 201ab64890Smrg * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 211ab64890Smrg * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF 221ab64890Smrg * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 231ab64890Smrg * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. 241ab64890Smrg * 251ab64890Smrg * NAME 261ab64890Smrg * CIELuvGcC.c 271ab64890Smrg * 281ab64890Smrg * DESCRIPTION 291ab64890Smrg * Source for XcmsCIELuvClipuv() gamut compression routine. 301ab64890Smrg * 311ab64890Smrg */ 321ab64890Smrg 331ab64890Smrg#ifdef HAVE_CONFIG_H 341ab64890Smrg#include <config.h> 351ab64890Smrg#endif 361ab64890Smrg#include "Xlibint.h" 371ab64890Smrg#include "Xcmsint.h" 381ab64890Smrg#include "Cv.h" 391ab64890Smrg 401ab64890Smrg 411ab64890Smrg/************************************************************************ 421ab64890Smrg * * 431ab64890Smrg * PUBLIC ROUTINES * 441ab64890Smrg * * 451ab64890Smrg ************************************************************************/ 461ab64890Smrg 471ab64890Smrg/* 481ab64890Smrg * NAME 491ab64890Smrg * XcmsCIELuvClipuv - Reduce the chroma for a hue and L* 501ab64890Smrg * 511ab64890Smrg * SYNOPSIS 521ab64890Smrg */ 531ab64890Smrg/* ARGSUSED */ 541ab64890SmrgStatus 551ab64890SmrgXcmsCIELuvClipuv ( 561ab64890Smrg XcmsCCC ccc, 571ab64890Smrg XcmsColor *pColors_in_out, 581ab64890Smrg unsigned int nColors, 591ab64890Smrg unsigned int i, 601ab64890Smrg Bool *pCompressed) 611ab64890Smrg/* 621ab64890Smrg * DESCRIPTION 631ab64890Smrg * Reduce the Chroma for a specific hue and chroma to 6461b2299dSmrg * to bring the given color into the gamut of the 651ab64890Smrg * specified device. As required of gamut compression 661ab64890Smrg * functions, this routine returns pColor_in_out 671ab64890Smrg * in XcmsCIEXYZFormat on successful completion. 6861b2299dSmrg * 691ab64890Smrg * Since this routine works with the L* within 701ab64890Smrg * pColor_in_out intermediate results may be returned 711ab64890Smrg * even though it may be invalid. 721ab64890Smrg * 731ab64890Smrg * RETURNS 741ab64890Smrg * XcmsFailure - Failure 751ab64890Smrg * XcmsSuccess - Succeeded 761ab64890Smrg * 771ab64890Smrg */ 781ab64890Smrg{ 791ab64890Smrg Status retval; 801ab64890Smrg XcmsColor *pColor; 811ab64890Smrg 821ab64890Smrg /* 831ab64890Smrg * Color specification passed as input can be assumed to: 841ab64890Smrg * 1. Be in XcmsCIEXYZFormat 851ab64890Smrg * 2. Already be white point adjusted for the Screen White Point. 861ab64890Smrg * This means that the white point now associated with this 871ab64890Smrg * color spec is the Screen White Point (even if the 881ab64890Smrg * ccc->clientWhitePt differs). 891ab64890Smrg */ 901ab64890Smrg 911ab64890Smrg pColor = pColors_in_out + i; 921ab64890Smrg 931ab64890Smrg if (ccc->visual->class < PseudoColor) { 941ab64890Smrg /* 951ab64890Smrg * GRAY ! 961ab64890Smrg */ 971ab64890Smrg _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc), 981ab64890Smrg 1, XcmsCIELuvFormat); 991ab64890Smrg _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc), 1001ab64890Smrg 1, XcmsCIEXYZFormat); 1011ab64890Smrg if (pCompressed) { 1021ab64890Smrg *(pCompressed + i) = True; 1031ab64890Smrg } 1041ab64890Smrg return(XcmsSuccess); 1051ab64890Smrg } else { 1061ab64890Smrg if (pColor->format != XcmsCIELuvFormat) { 1071ab64890Smrg if (_XcmsDIConvertColors(ccc, pColor, 1081ab64890Smrg &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIELuvFormat) 1091ab64890Smrg == XcmsFailure) { 1101ab64890Smrg return(XcmsFailure); 1111ab64890Smrg } 1121ab64890Smrg } 1131ab64890Smrg if (XcmsCIELuvQueryMaxC(ccc, 11461b2299dSmrg degrees(XCMS_CIELUV_PMETRIC_HUE(pColor->spec.CIELuv.u_star, 1151ab64890Smrg pColor->spec.CIELuv.v_star)), 1161ab64890Smrg pColor->spec.CIELuv.L_star, 1171ab64890Smrg pColor) == XcmsFailure) { 1181ab64890Smrg return(XcmsFailure); 1191ab64890Smrg } 1201ab64890Smrg retval = _XcmsDIConvertColors(ccc, pColor, 1211ab64890Smrg &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat); 1221ab64890Smrg if (retval != XcmsFailure && pCompressed != NULL) { 1231ab64890Smrg *(pCompressed + i) = True; 1241ab64890Smrg } 1251ab64890Smrg return(retval); 1261ab64890Smrg } 1271ab64890Smrg} 128