HVCMnV.c revision 1ab64890
1/* $Xorg: HVCMnV.c,v 1.3 2000/08/17 19:44:37 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. TekColor is a 9 * trademark of Tektronix, Inc. The term "TekHVC" designates a particular 10 * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent 11 * foreign patents pending). Permission is hereby granted to use, copy, 12 * modify, sell, and otherwise distribute this software and its 13 * documentation for any purpose and without fee, provided that: 14 * 15 * 1. This copyright, permission, and disclaimer notice is reproduced in 16 * all copies of this software and any modification thereof and in 17 * supporting documentation; 18 * 2. Any color-handling application which displays TekHVC color 19 * cooordinates identifies these as TekHVC color coordinates in any 20 * interface that displays these coordinates and in any associated 21 * documentation; 22 * 3. The term "TekHVC" is always used, and is only used, in association 23 * with the mathematical derivations of the TekHVC Color Space, 24 * including those provided in this file and any equivalent pathways and 25 * mathematical derivations, regardless of digital (e.g., floating point 26 * or integer) representation. 27 * 28 * Tektronix makes no representation about the suitability of this software 29 * for any purpose. It is provided "as is" and with all faults. 30 * 31 * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, 32 * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 33 * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY 34 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 35 * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF 36 * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 37 * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. 38 * 39 * NAME 40 * TekHVCMnV.c 41 * 42 * DESCRIPTION 43 * Source for XcmsTekHVCQueryMinV gamut boundary querying routine. 44 * 45 */ 46/* $XFree86$ */ 47 48#ifdef HAVE_CONFIG_H 49#include <config.h> 50#endif 51#include "Xlibint.h" 52#include "Xcmsint.h" 53#include "Cv.h" 54 55/* 56 * DEFINES 57 */ 58#define EPS 0.001 59 60 61/************************************************************************ 62 * * 63 * PUBLIC ROUTINES * 64 * * 65 ************************************************************************/ 66 67/* 68 * NAME 69 * XcmsTekHVCQueryMinV - Compute minimum value for hue and chroma 70 * 71 * SYNOPSIS 72 */ 73Status 74XcmsTekHVCQueryMinV ( 75 XcmsCCC ccc, 76 XcmsFloat hue, 77 XcmsFloat chroma, 78 XcmsColor *pColor_return) 79 80/* 81 * DESCRIPTION 82 * Return the minimum value for a specific hue, and the 83 * corresponding chroma. The input color specification 84 * may be in any format, however output is in XcmsTekHVCFormat. 85 * 86 * Since this routine works with the value within 87 * pColor_return intermediate results may be returned 88 * even though it may be invalid. 89 * 90 * ASSUMPTIONS 91 * This routine assumes that the white point associated with 92 * the color specification is the Screen White Point. The 93 * Screen White Point will also be associated with the 94 * returned color specification. 95 * 96 * RETURNS 97 * XcmsFailure - Failure 98 * XcmsSuccess - Succeeded with no modifications 99 * 100 */ 101{ 102 XcmsCCCRec myCCC; 103 XcmsColor tmp; 104 XcmsColor max_vc; 105 106 /* 107 * Check Arguments 108 */ 109 if (ccc == NULL || pColor_return == NULL) { 110 return(XcmsFailure); 111 } 112 113 /* 114 * Insure TekHVC installed 115 */ 116 if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) { 117 return(XcmsFailure); 118 } 119 120 /* Use my own CCC */ 121 memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec)); 122 myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* inherit screen white pt */ 123 myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut comp func */ 124 125 tmp.spec.TekHVC.H = hue; 126 tmp.spec.TekHVC.V = 100.0; 127 tmp.spec.TekHVC.C = chroma; 128 tmp.pixel = pColor_return->pixel; 129 tmp.format = XcmsTekHVCFormat; 130 131 132 /* Check for a valid HVC */ 133 if (!_XcmsTekHVC_CheckModify (&tmp)) { 134 return(XcmsFailure); 135 } 136 137 /* Step 1: compute the maximum value and chroma for this hue. */ 138 /* This copy may be overkill but it preserves the pixel etc. */ 139 memcpy((char *)&max_vc, (char *)&tmp, sizeof(XcmsColor)); 140 if (_XcmsTekHVCQueryMaxVCRGB (&myCCC, max_vc.spec.TekHVC.H, &max_vc, 141 (XcmsRGBi *)NULL) == XcmsFailure) { 142 return(XcmsFailure); 143 } 144 145 /* Step 2: find the intersection with the maximum hvc and chroma line. */ 146 if (tmp.spec.TekHVC.C > max_vc.spec.TekHVC.C + EPS) { 147 /* If the chroma is to large then return maximum hvc. */ 148 tmp.spec.TekHVC.C = max_vc.spec.TekHVC.C; 149 tmp.spec.TekHVC.V = max_vc.spec.TekHVC.V; 150 } else { 151 tmp.spec.TekHVC.V = tmp.spec.TekHVC.C * 152 max_vc.spec.TekHVC.V / max_vc.spec.TekHVC.C; 153 if (tmp.spec.TekHVC.V > max_vc.spec.TekHVC.V) { 154 tmp.spec.TekHVC.V = max_vc.spec.TekHVC.V; 155 } else if (tmp.spec.TekHVC.V < 0.0) { 156 tmp.spec.TekHVC.V = tmp.spec.TekHVC.C = 0.0; 157 } 158 } 159 if (_XcmsTekHVC_CheckModify (&tmp)) { 160 memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor)); 161 return(XcmsSuccess); 162 } else { 163 return(XcmsFailure); 164 } 165} 166