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