diff options
author | marha <marha@users.sourceforge.net> | 2012-06-08 09:33:13 +0200 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2012-06-08 09:33:13 +0200 |
commit | 990bc3f015a4f8fce2eb918375defcd44980a845 (patch) | |
tree | 8e8301f19482b52cc00bd95b4593522cc93267af /libX11/src/xcms | |
parent | 1af6fc1b5d93e54d6674de8b5870448b29f139a7 (diff) | |
download | vcxsrv-990bc3f015a4f8fce2eb918375defcd44980a845.tar.gz vcxsrv-990bc3f015a4f8fce2eb918375defcd44980a845.tar.bz2 vcxsrv-990bc3f015a4f8fce2eb918375defcd44980a845.zip |
Used synchronise script to update files
Diffstat (limited to 'libX11/src/xcms')
58 files changed, 12224 insertions, 12224 deletions
diff --git a/libX11/src/xcms/AddDIC.c b/libX11/src/xcms/AddDIC.c index ecc6650ab..d38d905cb 100644 --- a/libX11/src/xcms/AddDIC.c +++ b/libX11/src/xcms/AddDIC.c @@ -1,149 +1,149 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsAddDIC.c - * - * DESCRIPTION - * Source for XcmsAddColorSpace - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/* - * DEFINES - */ -#define NextUnregDiCsID(lastid) \ - (XCMS_UNREG_ID(lastid) ? ++lastid : XCMS_FIRST_UNREG_DI_ID) -#define MAX(x,y) ((x) < (y) ? (y) : (x)) - - -/* - * NAME - * XcmsAddColorSpace - Add a Device-Independent Color Space - * - * SYNOPSIS - */ -Status -XcmsAddColorSpace(XcmsColorSpace *pCS) -/* - * DESCRIPTION - * DI Color Spaces are managed on a global basis. - * This means that with exception of the provided DI color spaces: - * CIEXYZ, CIExyY, CIELab, CIEuvY, CIELuv, and TekHVC - * DI color spaces may have different XcmsColorFormat IDs between - * clients. So, you must be careful when using XcmsColor - * structures between clients! Use the routines XcmsFormatOfPrefix() - * and XcmsPrefixOfFormat() appropriately. - * - * RETURNS - * XcmsSuccess if succeeded, otherwise XcmsFailure - */ -{ - XcmsColorSpace **papColorSpaces; - XcmsColorSpace *ptmpCS; - XcmsColorFormat lastID = 0; - - if ((pCS->id = _XcmsRegFormatOfPrefix(pCS->prefix)) != 0) { - if (XCMS_DD_ID(pCS->id)) { - /* This is a Device-Dependent Color Space */ - return(XcmsFailure); - } - /* - * REGISTERED DI Color Space - * then see if the color space has already been added to the - * system: - * a. If the same ID/prefix and same XcmsColorSpec is found, - * then its a duplicate, so return success. - * b. If same ID/prefix but different XcmsColorSpec is - * found, then add the color space to the front of the - * list using the same ID. This allows one to override - * an existing DI Color Space. - * c. Otherwise none found so just add the color space. - */ - if ((papColorSpaces = _XcmsDIColorSpaces) != NULL) { - while ((ptmpCS = *papColorSpaces++) != NULL) { - if (pCS->id == ptmpCS->id) { - if (pCS == ptmpCS) { - /* a. duplicate*/ - return(XcmsSuccess); - } - /* b. same ID/prefix but different XcmsColorSpace */ - break; - } - } - } - /* c. None found */ - } else { - /* - * UNREGISTERED DI Color Space - * then see if the color space has already been added to the - * system: - * a. If same prefix and XcmsColorSpec, then - * its a duplicate ... return success. - * b. If same prefix but different XcmsColorSpec, then - * add the color space to the front of the list using - * the same ID. This allows one to override an existing - * DI Color Space. - * c. Otherwise none found so, add the color space using the - * next unregistered ID for the connection. - */ - if ((papColorSpaces = _XcmsDIColorSpaces) != NULL) { - while ((ptmpCS = *papColorSpaces++) != NULL) { - lastID = MAX(lastID, ptmpCS->id); - if (strcmp(pCS->prefix, ptmpCS->prefix) == 0) { - if (pCS == ptmpCS) { - /* a. duplicate */ - return(XcmsSuccess); - } - /* b. same prefix but different XcmsColorSpec */ - pCS->id = ptmpCS->id; - goto AddColorSpace; - } - } - } - /* c. None found */ - pCS->id = NextUnregDiCsID(lastID); - } - - -AddColorSpace: - if ((papColorSpaces = (XcmsColorSpace **) - _XcmsPushPointerArray((XPointer *)_XcmsDIColorSpaces, - (XPointer)pCS, - (XPointer *)_XcmsDIColorSpacesInit)) == NULL) { - return(XcmsFailure); - } - _XcmsDIColorSpaces = papColorSpaces; - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsAddDIC.c
+ *
+ * DESCRIPTION
+ * Source for XcmsAddColorSpace
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/*
+ * DEFINES
+ */
+#define NextUnregDiCsID(lastid) \
+ (XCMS_UNREG_ID(lastid) ? ++lastid : XCMS_FIRST_UNREG_DI_ID)
+#define MAX(x,y) ((x) < (y) ? (y) : (x))
+
+
+/*
+ * NAME
+ * XcmsAddColorSpace - Add a Device-Independent Color Space
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsAddColorSpace(XcmsColorSpace *pCS)
+/*
+ * DESCRIPTION
+ * DI Color Spaces are managed on a global basis.
+ * This means that with exception of the provided DI color spaces:
+ * CIEXYZ, CIExyY, CIELab, CIEuvY, CIELuv, and TekHVC
+ * DI color spaces may have different XcmsColorFormat IDs between
+ * clients. So, you must be careful when using XcmsColor
+ * structures between clients! Use the routines XcmsFormatOfPrefix()
+ * and XcmsPrefixOfFormat() appropriately.
+ *
+ * RETURNS
+ * XcmsSuccess if succeeded, otherwise XcmsFailure
+ */
+{
+ XcmsColorSpace **papColorSpaces;
+ XcmsColorSpace *ptmpCS;
+ XcmsColorFormat lastID = 0;
+
+ if ((pCS->id = _XcmsRegFormatOfPrefix(pCS->prefix)) != 0) {
+ if (XCMS_DD_ID(pCS->id)) {
+ /* This is a Device-Dependent Color Space */
+ return(XcmsFailure);
+ }
+ /*
+ * REGISTERED DI Color Space
+ * then see if the color space has already been added to the
+ * system:
+ * a. If the same ID/prefix and same XcmsColorSpec is found,
+ * then its a duplicate, so return success.
+ * b. If same ID/prefix but different XcmsColorSpec is
+ * found, then add the color space to the front of the
+ * list using the same ID. This allows one to override
+ * an existing DI Color Space.
+ * c. Otherwise none found so just add the color space.
+ */
+ if ((papColorSpaces = _XcmsDIColorSpaces) != NULL) {
+ while ((ptmpCS = *papColorSpaces++) != NULL) {
+ if (pCS->id == ptmpCS->id) {
+ if (pCS == ptmpCS) {
+ /* a. duplicate*/
+ return(XcmsSuccess);
+ }
+ /* b. same ID/prefix but different XcmsColorSpace */
+ break;
+ }
+ }
+ }
+ /* c. None found */
+ } else {
+ /*
+ * UNREGISTERED DI Color Space
+ * then see if the color space has already been added to the
+ * system:
+ * a. If same prefix and XcmsColorSpec, then
+ * its a duplicate ... return success.
+ * b. If same prefix but different XcmsColorSpec, then
+ * add the color space to the front of the list using
+ * the same ID. This allows one to override an existing
+ * DI Color Space.
+ * c. Otherwise none found so, add the color space using the
+ * next unregistered ID for the connection.
+ */
+ if ((papColorSpaces = _XcmsDIColorSpaces) != NULL) {
+ while ((ptmpCS = *papColorSpaces++) != NULL) {
+ lastID = MAX(lastID, ptmpCS->id);
+ if (strcmp(pCS->prefix, ptmpCS->prefix) == 0) {
+ if (pCS == ptmpCS) {
+ /* a. duplicate */
+ return(XcmsSuccess);
+ }
+ /* b. same prefix but different XcmsColorSpec */
+ pCS->id = ptmpCS->id;
+ goto AddColorSpace;
+ }
+ }
+ }
+ /* c. None found */
+ pCS->id = NextUnregDiCsID(lastID);
+ }
+
+
+AddColorSpace:
+ if ((papColorSpaces = (XcmsColorSpace **)
+ _XcmsPushPointerArray((XPointer *)_XcmsDIColorSpaces,
+ (XPointer)pCS,
+ (XPointer *)_XcmsDIColorSpacesInit)) == NULL) {
+ return(XcmsFailure);
+ }
+ _XcmsDIColorSpaces = papColorSpaces;
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/AddSF.c b/libX11/src/xcms/AddSF.c index 2e244e73b..97c6e09fe 100644 --- a/libX11/src/xcms/AddSF.c +++ b/libX11/src/xcms/AddSF.c @@ -1,145 +1,145 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsAddSF.c - * - * DESCRIPTION - * Source for XcmsAddFunctionSet - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - -/* - * DEFINES - */ -#define NextUnregDdCsID(lastid) \ - (XCMS_UNREG_ID(lastid) ? ++lastid : XCMS_FIRST_UNREG_DD_ID) -#define MIN(x,y) ((x) > (y) ? (y) : (x)) - - -/* - * NAME - * XcmsAddFunctionSet - Add an Screen Color Characterization - * Function Set - * - * SYNOPSIS - */ -Status -XcmsAddFunctionSet(XcmsFunctionSet *pNewFS) -/* - * DESCRIPTION - * Additional Screen Color Characterization Function Sets are - * managed on a global basis. This means that with exception - * of the provided DD color spaces: - * RGB and RGBi - * DD color spaces may have different XcmsColorFormat IDs between - * clients. So, you must be careful when using XcmsColorFormat - * across clients! Use the routines XcmsFormatOfPrefix() - * and XcmsPrefixOfFormat() appropriately. - * - * RETURNS - * XcmsSuccess if succeeded, otherwise XcmsFailure - * - * CAVEATS - * Additional Screen Color Characterization Function Sets - * should be added prior to any use of the routine - * XcmsCreateCCC(). If not, XcmsCCC structures created - * prior to the call of this routines will not have had - * a chance to initialize using the added Screen Color - * Characterization Function Set. - */ -{ - XcmsFunctionSet **papSCCFuncSets = _XcmsSCCFuncSets; - XcmsColorSpace **papNewCSs; - XcmsColorSpace *pNewCS, **paptmpCS; - XcmsColorFormat lastID = 0; - - - if (papSCCFuncSets != NULL) { - if ((papNewCSs = pNewFS->DDColorSpaces) == NULL) { - /* - * Error, new Screen Color Characterization Function Set - * missing color spaces - */ - return(XcmsFailure); - } - while ((pNewCS = *papNewCSs++) != NULL) { - if ((pNewCS->id = _XcmsRegFormatOfPrefix(pNewCS->prefix)) != 0) { - if (XCMS_DI_ID(pNewCS->id)) { - /* This is a Device-Independent Color Space */ - return(XcmsFailure); - } - /* - * REGISTERED DD Color Space - * therefore use the registered ID. - */ - } else { - /* - * UNREGISTERED DD Color Space - * then see if the color space is already in - * _XcmsDDColorSpaces. - * a. If same prefix, then use the same ID. - * b. Otherwise, use a new ID. - */ - for (paptmpCS = _XcmsDDColorSpaces; *paptmpCS != NULL; - paptmpCS++){ - lastID = MIN(lastID, (*paptmpCS)->id); - if (strcmp(pNewCS->prefix, (*paptmpCS)->prefix) == 0) { - pNewCS->id = (*paptmpCS)->id; - break; - } - } - if (pNewCS->id == 0) { - /* still haven't found one */ - pNewCS->id = NextUnregDdCsID(lastID); - if ((paptmpCS = (XcmsColorSpace **)_XcmsPushPointerArray( - (XPointer *) _XcmsDDColorSpaces, - (XPointer) pNewCS, - (XPointer *) _XcmsDDColorSpacesInit)) == NULL) { - return(XcmsFailure); - } - _XcmsDDColorSpaces = paptmpCS; - } - } - } - } - if ((papSCCFuncSets = (XcmsFunctionSet **) - _XcmsPushPointerArray((XPointer *) _XcmsSCCFuncSets, - (XPointer) pNewFS, - (XPointer *)_XcmsSCCFuncSetsInit)) == NULL) { - return(XcmsFailure); - } - _XcmsSCCFuncSets = papSCCFuncSets; - - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsAddSF.c
+ *
+ * DESCRIPTION
+ * Source for XcmsAddFunctionSet
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+/*
+ * DEFINES
+ */
+#define NextUnregDdCsID(lastid) \
+ (XCMS_UNREG_ID(lastid) ? ++lastid : XCMS_FIRST_UNREG_DD_ID)
+#define MIN(x,y) ((x) > (y) ? (y) : (x))
+
+
+/*
+ * NAME
+ * XcmsAddFunctionSet - Add an Screen Color Characterization
+ * Function Set
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsAddFunctionSet(XcmsFunctionSet *pNewFS)
+/*
+ * DESCRIPTION
+ * Additional Screen Color Characterization Function Sets are
+ * managed on a global basis. This means that with exception
+ * of the provided DD color spaces:
+ * RGB and RGBi
+ * DD color spaces may have different XcmsColorFormat IDs between
+ * clients. So, you must be careful when using XcmsColorFormat
+ * across clients! Use the routines XcmsFormatOfPrefix()
+ * and XcmsPrefixOfFormat() appropriately.
+ *
+ * RETURNS
+ * XcmsSuccess if succeeded, otherwise XcmsFailure
+ *
+ * CAVEATS
+ * Additional Screen Color Characterization Function Sets
+ * should be added prior to any use of the routine
+ * XcmsCreateCCC(). If not, XcmsCCC structures created
+ * prior to the call of this routines will not have had
+ * a chance to initialize using the added Screen Color
+ * Characterization Function Set.
+ */
+{
+ XcmsFunctionSet **papSCCFuncSets = _XcmsSCCFuncSets;
+ XcmsColorSpace **papNewCSs;
+ XcmsColorSpace *pNewCS, **paptmpCS;
+ XcmsColorFormat lastID = 0;
+
+
+ if (papSCCFuncSets != NULL) {
+ if ((papNewCSs = pNewFS->DDColorSpaces) == NULL) {
+ /*
+ * Error, new Screen Color Characterization Function Set
+ * missing color spaces
+ */
+ return(XcmsFailure);
+ }
+ while ((pNewCS = *papNewCSs++) != NULL) {
+ if ((pNewCS->id = _XcmsRegFormatOfPrefix(pNewCS->prefix)) != 0) {
+ if (XCMS_DI_ID(pNewCS->id)) {
+ /* This is a Device-Independent Color Space */
+ return(XcmsFailure);
+ }
+ /*
+ * REGISTERED DD Color Space
+ * therefore use the registered ID.
+ */
+ } else {
+ /*
+ * UNREGISTERED DD Color Space
+ * then see if the color space is already in
+ * _XcmsDDColorSpaces.
+ * a. If same prefix, then use the same ID.
+ * b. Otherwise, use a new ID.
+ */
+ for (paptmpCS = _XcmsDDColorSpaces; *paptmpCS != NULL;
+ paptmpCS++){
+ lastID = MIN(lastID, (*paptmpCS)->id);
+ if (strcmp(pNewCS->prefix, (*paptmpCS)->prefix) == 0) {
+ pNewCS->id = (*paptmpCS)->id;
+ break;
+ }
+ }
+ if (pNewCS->id == 0) {
+ /* still haven't found one */
+ pNewCS->id = NextUnregDdCsID(lastID);
+ if ((paptmpCS = (XcmsColorSpace **)_XcmsPushPointerArray(
+ (XPointer *) _XcmsDDColorSpaces,
+ (XPointer) pNewCS,
+ (XPointer *) _XcmsDDColorSpacesInit)) == NULL) {
+ return(XcmsFailure);
+ }
+ _XcmsDDColorSpaces = paptmpCS;
+ }
+ }
+ }
+ }
+ if ((papSCCFuncSets = (XcmsFunctionSet **)
+ _XcmsPushPointerArray((XPointer *) _XcmsSCCFuncSets,
+ (XPointer) pNewFS,
+ (XPointer *)_XcmsSCCFuncSetsInit)) == NULL) {
+ return(XcmsFailure);
+ }
+ _XcmsSCCFuncSets = papSCCFuncSets;
+
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/CCC.c b/libX11/src/xcms/CCC.c index 090b1078c..d0b055b7a 100644 --- a/libX11/src/xcms/CCC.c +++ b/libX11/src/xcms/CCC.c @@ -1,286 +1,286 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsCCC.c - Color Conversion Context Routines - * - * DESCRIPTION - * Routines to create, access, and free Color Conversion - * Context structures. - * - * - */ - -/* - -Copyright 1994, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - -*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <stdio.h> -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - - -/************************************************************************ - * * - * PUBLIC INTERFACES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCreateCCC - * - * SYNOPSIS - */ - -XcmsCCC -XcmsCreateCCC( - Display *dpy, - int screenNumber, - Visual *visual, - XcmsColor *clientWhitePt, - XcmsCompressionProc gamutCompProc, - XPointer gamutCompClientData, - XcmsWhiteAdjustProc whitePtAdjProc, - XPointer whitePtAdjClientData) -/* - * DESCRIPTION - * Given a Display, Screen, Visual, etc., this routine creates - * an appropriate Color Conversion Context. - * - * RETURNS - * Returns NULL if failed; otherwise address of the newly - * created XcmsCCC. - * - */ -{ - XcmsCCC pDefaultCCC = XcmsDefaultCCC(dpy, screenNumber); - XcmsCCC newccc; - XcmsIntensityMap *pIMap; - XcmsPerScrnInfo *pNewScrnInfo; - - if (pDefaultCCC == NULL || - !(newccc = (XcmsCCC) Xcalloc(1, (unsigned) sizeof(XcmsCCCRec)))) { - return(NULL); - } - - /* - * Should inherit the following as result of a memmove(): - * dpy - * screenNumber - * pPerScrnInfo - */ - memcpy((char *)newccc, (char *)pDefaultCCC, sizeof(XcmsCCCRec)); - if (clientWhitePt) { - memcpy((char *)&newccc->clientWhitePt, (char *)clientWhitePt, - sizeof(XcmsColor)); - } - if (gamutCompProc) { - newccc->gamutCompProc = gamutCompProc; - } - if (gamutCompClientData) { - newccc->gamutCompClientData = gamutCompClientData; - } - if (whitePtAdjProc) { - newccc->whitePtAdjProc = whitePtAdjProc; - } - if (whitePtAdjClientData) { - newccc->whitePtAdjClientData = whitePtAdjClientData; - } - - /* - * Now check our list of per-Visual Intensity tables. - * If one exists replace the pPerScrnInfo. - */ - if ((pIMap = _XcmsGetIntensityMap(dpy, visual)) != NULL) { - if (!(pNewScrnInfo = (XcmsPerScrnInfo *) - Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) { - Xfree(newccc); - return(NULL); - } - memcpy((char *)pNewScrnInfo, (char *)newccc->pPerScrnInfo, - sizeof(XcmsPerScrnInfo)); - pNewScrnInfo->screenData = pIMap->screenData; - newccc->pPerScrnInfo = pNewScrnInfo; - } - - /* - * Set visual component - */ - newccc->visual = visual; - - return(newccc); -} - - -/* - * NAME - * XcmsDefaultCCC - * - * SYNOPSIS - */ -XcmsCCC -XcmsDefaultCCC( - Display *dpy, - int screenNumber) -/* - * DESCRIPTION - * Given a Display and Screen, this routine creates - * returns the Screen's default Color Conversion Context. - * Note that a Screen's default CCC is built with the - * screen default visual. - * - * RETURNS - * Returns NULL if failed; otherwise address of the - * XcmsCCC for the Screen's default CCC. - * - */ -{ - XcmsCCC ccc; - - - if ((screenNumber < 0) || (screenNumber >= ScreenCount(dpy))) { - return((XcmsCCC)NULL); - } - - /* - * Check if the XcmsCCC's for each screen has been created - */ - if ((XcmsCCC)dpy->cms.defaultCCCs == NULL) { - if (!_XcmsInitDefaultCCCs(dpy)) { - return((XcmsCCC)NULL); - } - } - - ccc = (XcmsCCC)dpy->cms.defaultCCCs + screenNumber; - - if (!ccc->pPerScrnInfo) { - /* - * Need to create the XcmsPerScrnInfo structure. The - * _XcmsInitScrnInfo routine will create the XcmsPerScrnInfo - * structure as well as initialize its functionSet and pScreenData - * components. - */ - if (!_XcmsInitScrnInfo(dpy, screenNumber)) { - return((XcmsCCC)NULL); - } - return(ccc); - } else { - /* - * If ccc->pPerScrnInfo->state == XcmsInitSuccess, - * then the pPerScrnInfo component has already been initialized - * therefore, just return ccc. - * If ccc->pPerScrnInfo->state == XcmsInitFailure, - * then this means that we already attempted to initialize - * the pPerScrnInfo component but failed therefore stuffing - * the pPerScrnInfo component with defaults. Just return ccc. - * If ccc->pPerScrnInfo->state == XcmsInitNone, - * then attempt to initialize the pPerScrnInfo component. - */ - switch (ccc->pPerScrnInfo->state) { - case XcmsInitFailure : - /* fall through */ - case XcmsInitSuccess : - return(ccc); - case XcmsInitNone : - /* XcmsPerScreenInfo has not been initialized */ - if (!_XcmsInitScrnInfo(dpy, screenNumber)) { - return((XcmsCCC)NULL); - } - return(ccc); - default : - return((XcmsCCC)NULL); - } - } -} - - -/* - * NAME - * XcmsFreeCCC - * - * SYNOPSIS - */ -void -XcmsFreeCCC(XcmsCCC ccc) -/* - * DESCRIPTION - * Frees memory associated with a Color Conversion Context - * that was created with XcmsCreateCCC(). - * - * RETURNS - * void - * - */ -{ - if (ccc->dpy->cms.defaultCCCs && - ccc == ((XcmsCCC)ccc->dpy->cms.defaultCCCs) + ccc->screenNumber) { - /* do not allow clients to free DefaultCCC's */ - return; - } - - /* - * Note that XcmsPerScrnInfo sub-structures are freed here only if - * they are for visuals that have per-Visual intensity tables. - * Otherwise the XcmsPerScrnInfo structure is being shared! - * For the latter, there is only one allocated per Screen and it just - * so happens * that we place its initial reference is placed in the - * default CCC. The routine _XcmsFreeDefaultCCCs frees them. - */ - if (_XcmsGetIntensityMap(ccc->dpy, ccc->visual) != NULL) { - Xfree(ccc->pPerScrnInfo); - } - - Xfree(ccc); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsCCC.c - Color Conversion Context Routines
+ *
+ * DESCRIPTION
+ * Routines to create, access, and free Color Conversion
+ * Context structures.
+ *
+ *
+ */
+
+/*
+
+Copyright 1994, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+
+/************************************************************************
+ * *
+ * PUBLIC INTERFACES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCreateCCC
+ *
+ * SYNOPSIS
+ */
+
+XcmsCCC
+XcmsCreateCCC(
+ Display *dpy,
+ int screenNumber,
+ Visual *visual,
+ XcmsColor *clientWhitePt,
+ XcmsCompressionProc gamutCompProc,
+ XPointer gamutCompClientData,
+ XcmsWhiteAdjustProc whitePtAdjProc,
+ XPointer whitePtAdjClientData)
+/*
+ * DESCRIPTION
+ * Given a Display, Screen, Visual, etc., this routine creates
+ * an appropriate Color Conversion Context.
+ *
+ * RETURNS
+ * Returns NULL if failed; otherwise address of the newly
+ * created XcmsCCC.
+ *
+ */
+{
+ XcmsCCC pDefaultCCC = XcmsDefaultCCC(dpy, screenNumber);
+ XcmsCCC newccc;
+ XcmsIntensityMap *pIMap;
+ XcmsPerScrnInfo *pNewScrnInfo;
+
+ if (pDefaultCCC == NULL ||
+ !(newccc = (XcmsCCC) Xcalloc(1, (unsigned) sizeof(XcmsCCCRec)))) {
+ return(NULL);
+ }
+
+ /*
+ * Should inherit the following as result of a memmove():
+ * dpy
+ * screenNumber
+ * pPerScrnInfo
+ */
+ memcpy((char *)newccc, (char *)pDefaultCCC, sizeof(XcmsCCCRec));
+ if (clientWhitePt) {
+ memcpy((char *)&newccc->clientWhitePt, (char *)clientWhitePt,
+ sizeof(XcmsColor));
+ }
+ if (gamutCompProc) {
+ newccc->gamutCompProc = gamutCompProc;
+ }
+ if (gamutCompClientData) {
+ newccc->gamutCompClientData = gamutCompClientData;
+ }
+ if (whitePtAdjProc) {
+ newccc->whitePtAdjProc = whitePtAdjProc;
+ }
+ if (whitePtAdjClientData) {
+ newccc->whitePtAdjClientData = whitePtAdjClientData;
+ }
+
+ /*
+ * Now check our list of per-Visual Intensity tables.
+ * If one exists replace the pPerScrnInfo.
+ */
+ if ((pIMap = _XcmsGetIntensityMap(dpy, visual)) != NULL) {
+ if (!(pNewScrnInfo = (XcmsPerScrnInfo *)
+ Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) {
+ Xfree(newccc);
+ return(NULL);
+ }
+ memcpy((char *)pNewScrnInfo, (char *)newccc->pPerScrnInfo,
+ sizeof(XcmsPerScrnInfo));
+ pNewScrnInfo->screenData = pIMap->screenData;
+ newccc->pPerScrnInfo = pNewScrnInfo;
+ }
+
+ /*
+ * Set visual component
+ */
+ newccc->visual = visual;
+
+ return(newccc);
+}
+
+
+/*
+ * NAME
+ * XcmsDefaultCCC
+ *
+ * SYNOPSIS
+ */
+XcmsCCC
+XcmsDefaultCCC(
+ Display *dpy,
+ int screenNumber)
+/*
+ * DESCRIPTION
+ * Given a Display and Screen, this routine creates
+ * returns the Screen's default Color Conversion Context.
+ * Note that a Screen's default CCC is built with the
+ * screen default visual.
+ *
+ * RETURNS
+ * Returns NULL if failed; otherwise address of the
+ * XcmsCCC for the Screen's default CCC.
+ *
+ */
+{
+ XcmsCCC ccc;
+
+
+ if ((screenNumber < 0) || (screenNumber >= ScreenCount(dpy))) {
+ return((XcmsCCC)NULL);
+ }
+
+ /*
+ * Check if the XcmsCCC's for each screen has been created
+ */
+ if ((XcmsCCC)dpy->cms.defaultCCCs == NULL) {
+ if (!_XcmsInitDefaultCCCs(dpy)) {
+ return((XcmsCCC)NULL);
+ }
+ }
+
+ ccc = (XcmsCCC)dpy->cms.defaultCCCs + screenNumber;
+
+ if (!ccc->pPerScrnInfo) {
+ /*
+ * Need to create the XcmsPerScrnInfo structure. The
+ * _XcmsInitScrnInfo routine will create the XcmsPerScrnInfo
+ * structure as well as initialize its functionSet and pScreenData
+ * components.
+ */
+ if (!_XcmsInitScrnInfo(dpy, screenNumber)) {
+ return((XcmsCCC)NULL);
+ }
+ return(ccc);
+ } else {
+ /*
+ * If ccc->pPerScrnInfo->state == XcmsInitSuccess,
+ * then the pPerScrnInfo component has already been initialized
+ * therefore, just return ccc.
+ * If ccc->pPerScrnInfo->state == XcmsInitFailure,
+ * then this means that we already attempted to initialize
+ * the pPerScrnInfo component but failed therefore stuffing
+ * the pPerScrnInfo component with defaults. Just return ccc.
+ * If ccc->pPerScrnInfo->state == XcmsInitNone,
+ * then attempt to initialize the pPerScrnInfo component.
+ */
+ switch (ccc->pPerScrnInfo->state) {
+ case XcmsInitFailure :
+ /* fall through */
+ case XcmsInitSuccess :
+ return(ccc);
+ case XcmsInitNone :
+ /* XcmsPerScreenInfo has not been initialized */
+ if (!_XcmsInitScrnInfo(dpy, screenNumber)) {
+ return((XcmsCCC)NULL);
+ }
+ return(ccc);
+ default :
+ return((XcmsCCC)NULL);
+ }
+ }
+}
+
+
+/*
+ * NAME
+ * XcmsFreeCCC
+ *
+ * SYNOPSIS
+ */
+void
+XcmsFreeCCC(XcmsCCC ccc)
+/*
+ * DESCRIPTION
+ * Frees memory associated with a Color Conversion Context
+ * that was created with XcmsCreateCCC().
+ *
+ * RETURNS
+ * void
+ *
+ */
+{
+ if (ccc->dpy->cms.defaultCCCs &&
+ ccc == ((XcmsCCC)ccc->dpy->cms.defaultCCCs) + ccc->screenNumber) {
+ /* do not allow clients to free DefaultCCC's */
+ return;
+ }
+
+ /*
+ * Note that XcmsPerScrnInfo sub-structures are freed here only if
+ * they are for visuals that have per-Visual intensity tables.
+ * Otherwise the XcmsPerScrnInfo structure is being shared!
+ * For the latter, there is only one allocated per Screen and it just
+ * so happens * that we place its initial reference is placed in the
+ * default CCC. The routine _XcmsFreeDefaultCCCs frees them.
+ */
+ if (_XcmsGetIntensityMap(ccc->dpy, ccc->visual) != NULL) {
+ Xfree(ccc->pPerScrnInfo);
+ }
+
+ Xfree(ccc);
+}
diff --git a/libX11/src/xcms/Cv.h b/libX11/src/xcms/Cv.h index 0b662811f..c2a93a4aa 100644 --- a/libX11/src/xcms/Cv.h +++ b/libX11/src/xcms/Cv.h @@ -1,189 +1,189 @@ - -#ifndef _CV_H_ -#define _CV_H_ - -/* variables */ -extern const char _XcmsCIEXYZ_prefix[]; -extern const char _XcmsCIEuvY_prefix[]; -extern const char _XcmsCIExyY_prefix[]; -extern const char _XcmsCIELab_prefix[]; -extern const char _XcmsCIELuv_prefix[]; -extern const char _XcmsTekHVC_prefix[]; -extern const char _XcmsRGBi_prefix[]; -extern const char _XcmsRGB_prefix[]; - -extern XcmsColorSpace XcmsUNDEFINEDColorSpace; -extern XcmsColorSpace XcmsTekHVCColorSpace; -extern XcmsColorSpace XcmsCIEXYZColorSpace; -extern XcmsColorSpace XcmsCIEuvYColorSpace; -extern XcmsColorSpace XcmsCIExyYColorSpace; -extern XcmsColorSpace XcmsCIELabColorSpace; -extern XcmsColorSpace XcmsCIELuvColorSpace; -extern XcmsColorSpace XcmsRGBColorSpace; -extern XcmsColorSpace XcmsRGBiColorSpace; - -extern XcmsColorSpace *_XcmsDIColorSpacesInit[]; -extern XcmsColorSpace **_XcmsDIColorSpaces; - -extern XcmsColorSpace *_XcmsDDColorSpacesInit[]; -extern XcmsColorSpace **_XcmsDDColorSpaces; - -extern XcmsFunctionSet XcmsLinearRGBFunctionSet; - -extern XcmsFunctionSet *_XcmsSCCFuncSetsInit[]; -extern XcmsFunctionSet **_XcmsSCCFuncSets; - -extern XcmsRegColorSpaceEntry _XcmsRegColorSpaces[]; - -/* functions */ -extern XPointer * -_XcmsCopyPointerArray( - XPointer *pap); -extern void -_XcmsFreePointerArray( - XPointer *pap); -extern XPointer * -_XcmsPushPointerArray( - XPointer *pap, - XPointer p, - XPointer *papNoFree); -extern Status -_XcmsCIEXYZ_ValidSpec( - XcmsColor *pColor); -extern Status -_XcmsCIEuvY_ValidSpec( - XcmsColor *pColor); -extern int -_XcmsTekHVC_CheckModify( - XcmsColor *pColor); - -extern Status -_XcmsTekHVCQueryMaxVCRGB( - XcmsCCC ccc, - XcmsFloat hue, - XcmsColor *pColor_return, - XcmsRGBi *pRGB_return); -extern Status -_XcmsCIELabQueryMaxLCRGB( - XcmsCCC ccc, - XcmsFloat hue, /* hue in radians */ - XcmsColor *pColor_return, - XcmsRGBi *pRGB_return); -extern Status -_XcmsConvertColorsWithWhitePt( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - XcmsColor *pWhitePt, - unsigned int nColors, - XcmsColorFormat newFormat, - Bool *pCompressed); - -extern Status -_XcmsDIConvertColors( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - XcmsColor *pWhitePt, - unsigned int nColors, - XcmsColorFormat newFormat); -extern Status -_XcmsDDConvertColors( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - unsigned int nColors, - XcmsColorFormat newFormat, - Bool *pCompressed); -extern XcmsColorFormat -_XcmsRegFormatOfPrefix( - _Xconst char *prefix); -extern void -_XColor_to_XcmsRGB( - XcmsCCC ccc, - XColor *pXColors, - XcmsColor *pColors, - unsigned int nColors); -extern Status -_XcmsSetGetColor( - Status (*xColorProc)( - Display* /* display */, - Colormap /* colormap */, - XColor* /* screen_in_out */), - Display *dpy, - Colormap cmap, - XcmsColor *pColors_in_out, - XcmsColorFormat result_format, - Bool *pCompressed); -extern Status -_XcmsSetGetColors( - Status (*xColorProc)( - Display* /* display */, - Colormap /* colormap */, - XColor* /* screen_in_out */, - int /* nColors */), - Display *dpy, - Colormap cmap, - XcmsColor *pColors_in_out, - int nColors, - XcmsColorFormat result_format, - Bool *pCompressed); -extern Status -_XcmsCIELuvQueryMaxLCRGB( - XcmsCCC ccc, - XcmsFloat hue, /* hue in radians */ - XcmsColor *pColor_return, - XcmsRGBi *pRGB_return); - -extern XcmsIntensityMap * -_XcmsGetIntensityMap( - Display *dpy, - Visual *visual); -extern int -_XcmsInitDefaultCCCs( - Display *dpy); -extern int -_XcmsInitScrnInfo( - register Display *dpy, - int screenNumber); -extern XcmsCmapRec * -_XcmsCopyCmapRecAndFree( - Display *dpy, - Colormap src_cmap, - Colormap copy_cmap); -extern void -_XcmsCopyISOLatin1Lowered( - char *dst, - const char *src); -extern int -_XcmsEqualWhitePts( - XcmsCCC ccc, XcmsColor *pWhitePt1, XcmsColor *pWhitePt2); -extern int -_XcmsLRGB_InitScrnDefault( - Display *dpy, - int screenNumber, - XcmsPerScrnInfo *pPerScrnInfo); -extern void -_XcmsFreeIntensityMaps( - Display *dpy); -extern int -_XcmsGetProperty( - Display *pDpy, - Window w, - Atom property, - int *pFormat, - unsigned long *pNItems, - unsigned long *pNBytes, - char **pValue); -extern unsigned long -_XcmsGetElement( - int format, - char **pValue, - unsigned long *pCount); -extern void -_XcmsUnresolveColor( - XcmsCCC ccc, - XcmsColor *pColor); -extern void -_XcmsResolveColor( - XcmsCCC ccc, - XcmsColor *pXcmsColor); - -#endif /* _CV_H_ */ +
+#ifndef _CV_H_
+#define _CV_H_
+
+/* variables */
+extern const char _XcmsCIEXYZ_prefix[];
+extern const char _XcmsCIEuvY_prefix[];
+extern const char _XcmsCIExyY_prefix[];
+extern const char _XcmsCIELab_prefix[];
+extern const char _XcmsCIELuv_prefix[];
+extern const char _XcmsTekHVC_prefix[];
+extern const char _XcmsRGBi_prefix[];
+extern const char _XcmsRGB_prefix[];
+
+extern XcmsColorSpace XcmsUNDEFINEDColorSpace;
+extern XcmsColorSpace XcmsTekHVCColorSpace;
+extern XcmsColorSpace XcmsCIEXYZColorSpace;
+extern XcmsColorSpace XcmsCIEuvYColorSpace;
+extern XcmsColorSpace XcmsCIExyYColorSpace;
+extern XcmsColorSpace XcmsCIELabColorSpace;
+extern XcmsColorSpace XcmsCIELuvColorSpace;
+extern XcmsColorSpace XcmsRGBColorSpace;
+extern XcmsColorSpace XcmsRGBiColorSpace;
+
+extern XcmsColorSpace *_XcmsDIColorSpacesInit[];
+extern XcmsColorSpace **_XcmsDIColorSpaces;
+
+extern XcmsColorSpace *_XcmsDDColorSpacesInit[];
+extern XcmsColorSpace **_XcmsDDColorSpaces;
+
+extern XcmsFunctionSet XcmsLinearRGBFunctionSet;
+
+extern XcmsFunctionSet *_XcmsSCCFuncSetsInit[];
+extern XcmsFunctionSet **_XcmsSCCFuncSets;
+
+extern XcmsRegColorSpaceEntry _XcmsRegColorSpaces[];
+
+/* functions */
+extern XPointer *
+_XcmsCopyPointerArray(
+ XPointer *pap);
+extern void
+_XcmsFreePointerArray(
+ XPointer *pap);
+extern XPointer *
+_XcmsPushPointerArray(
+ XPointer *pap,
+ XPointer p,
+ XPointer *papNoFree);
+extern Status
+_XcmsCIEXYZ_ValidSpec(
+ XcmsColor *pColor);
+extern Status
+_XcmsCIEuvY_ValidSpec(
+ XcmsColor *pColor);
+extern int
+_XcmsTekHVC_CheckModify(
+ XcmsColor *pColor);
+
+extern Status
+_XcmsTekHVCQueryMaxVCRGB(
+ XcmsCCC ccc,
+ XcmsFloat hue,
+ XcmsColor *pColor_return,
+ XcmsRGBi *pRGB_return);
+extern Status
+_XcmsCIELabQueryMaxLCRGB(
+ XcmsCCC ccc,
+ XcmsFloat hue, /* hue in radians */
+ XcmsColor *pColor_return,
+ XcmsRGBi *pRGB_return);
+extern Status
+_XcmsConvertColorsWithWhitePt(
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ XcmsColor *pWhitePt,
+ unsigned int nColors,
+ XcmsColorFormat newFormat,
+ Bool *pCompressed);
+
+extern Status
+_XcmsDIConvertColors(
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ XcmsColor *pWhitePt,
+ unsigned int nColors,
+ XcmsColorFormat newFormat);
+extern Status
+_XcmsDDConvertColors(
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors,
+ XcmsColorFormat newFormat,
+ Bool *pCompressed);
+extern XcmsColorFormat
+_XcmsRegFormatOfPrefix(
+ _Xconst char *prefix);
+extern void
+_XColor_to_XcmsRGB(
+ XcmsCCC ccc,
+ XColor *pXColors,
+ XcmsColor *pColors,
+ unsigned int nColors);
+extern Status
+_XcmsSetGetColor(
+ Status (*xColorProc)(
+ Display* /* display */,
+ Colormap /* colormap */,
+ XColor* /* screen_in_out */),
+ Display *dpy,
+ Colormap cmap,
+ XcmsColor *pColors_in_out,
+ XcmsColorFormat result_format,
+ Bool *pCompressed);
+extern Status
+_XcmsSetGetColors(
+ Status (*xColorProc)(
+ Display* /* display */,
+ Colormap /* colormap */,
+ XColor* /* screen_in_out */,
+ int /* nColors */),
+ Display *dpy,
+ Colormap cmap,
+ XcmsColor *pColors_in_out,
+ int nColors,
+ XcmsColorFormat result_format,
+ Bool *pCompressed);
+extern Status
+_XcmsCIELuvQueryMaxLCRGB(
+ XcmsCCC ccc,
+ XcmsFloat hue, /* hue in radians */
+ XcmsColor *pColor_return,
+ XcmsRGBi *pRGB_return);
+
+extern XcmsIntensityMap *
+_XcmsGetIntensityMap(
+ Display *dpy,
+ Visual *visual);
+extern int
+_XcmsInitDefaultCCCs(
+ Display *dpy);
+extern int
+_XcmsInitScrnInfo(
+ register Display *dpy,
+ int screenNumber);
+extern XcmsCmapRec *
+_XcmsCopyCmapRecAndFree(
+ Display *dpy,
+ Colormap src_cmap,
+ Colormap copy_cmap);
+extern void
+_XcmsCopyISOLatin1Lowered(
+ char *dst,
+ const char *src);
+extern int
+_XcmsEqualWhitePts(
+ XcmsCCC ccc, XcmsColor *pWhitePt1, XcmsColor *pWhitePt2);
+extern int
+_XcmsLRGB_InitScrnDefault(
+ Display *dpy,
+ int screenNumber,
+ XcmsPerScrnInfo *pPerScrnInfo);
+extern void
+_XcmsFreeIntensityMaps(
+ Display *dpy);
+extern int
+_XcmsGetProperty(
+ Display *pDpy,
+ Window w,
+ Atom property,
+ int *pFormat,
+ unsigned long *pNItems,
+ unsigned long *pNBytes,
+ char **pValue);
+extern unsigned long
+_XcmsGetElement(
+ int format,
+ char **pValue,
+ unsigned long *pCount);
+extern void
+_XcmsUnresolveColor(
+ XcmsCCC ccc,
+ XcmsColor *pColor);
+extern void
+_XcmsResolveColor(
+ XcmsCCC ccc,
+ XcmsColor *pXcmsColor);
+
+#endif /* _CV_H_ */
diff --git a/libX11/src/xcms/CvColW.c b/libX11/src/xcms/CvColW.c index 4aabded0d..2476d1c97 100644 --- a/libX11/src/xcms/CvColW.c +++ b/libX11/src/xcms/CvColW.c @@ -1,141 +1,141 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * - * NAME - * XcmsCvColW.c - * - * DESCRIPTION - * <overall description of what the package does> - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/************************************************************************ - * * - * API PRIVATE ROUTINES * - * * - ************************************************************************/ - - -/* - * NAME - * _XcmsConvertColorsWithWhitePt - Convert XcmsColor structures - * - * SYNOPSIS - */ -Status -_XcmsConvertColorsWithWhitePt( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - XcmsColor *pWhitePt, - unsigned int nColors, - XcmsColorFormat newFormat, - Bool *pCompressed) -/* - * DESCRIPTION - * Convert XcmsColor structures between device-independent - * and/or device-dependent formats but allowing the calling - * routine to specify the white point to be associated - * with the color specifications (overriding - * ccc->clientWhitePt). - * - * This routine has been provided for use in white point - * adjustment routines. - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if succeeded without gamut compression, - * XcmsSuccessWithCompression if succeeded with gamut - * compression. - * - */ -{ - if (ccc == NULL || pColors_in_out == NULL || - pColors_in_out->format == XcmsUndefinedFormat) { - return(XcmsFailure); - } - - if (nColors == 0 || pColors_in_out->format == newFormat) { - /* do nothing */ - return(XcmsSuccess); - } - - if (XCMS_DI_ID(pColors_in_out->format) && XCMS_DI_ID(newFormat)) { - /* - * Device-Independent to Device-Independent Conversion - */ - return(_XcmsDIConvertColors(ccc, pColors_in_out, pWhitePt, nColors, - newFormat)); - } - if (XCMS_DD_ID(pColors_in_out->format) && XCMS_DD_ID(newFormat)) { - /* - * Device-Dependent to Device-Dependent Conversion - */ - return(_XcmsDDConvertColors(ccc, pColors_in_out, nColors, newFormat, - pCompressed)); - } - - /* - * Otherwise we have: - * 1. Device-Independent to Device-Dependent Conversion - * OR - * 2. Device-Dependent to Device-Independent Conversion - */ - - if (XCMS_DI_ID(pColors_in_out->format)) { - /* - * 1. Device-Independent to Device-Dependent Conversion - */ - /* First convert to CIEXYZ */ - if (_XcmsDIConvertColors(ccc, pColors_in_out, pWhitePt, nColors, - XcmsCIEXYZFormat) == XcmsFailure) { - return(XcmsFailure); - } - /* Then convert to DD Format */ - return(_XcmsDDConvertColors(ccc, pColors_in_out, nColors, newFormat, - pCompressed)); - } else { - /* - * 2. Device-Dependent to Device-Independent Conversion - */ - /* First convert to CIEXYZ */ - if (_XcmsDDConvertColors(ccc, pColors_in_out, nColors, - XcmsCIEXYZFormat, pCompressed) == XcmsFailure) { - return(XcmsFailure); - } - /* Then convert to DI Format */ - return(_XcmsDIConvertColors(ccc, pColors_in_out, pWhitePt, nColors, - newFormat)); - } -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ *
+ * NAME
+ * XcmsCvColW.c
+ *
+ * DESCRIPTION
+ * <overall description of what the package does>
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/************************************************************************
+ * *
+ * API PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+
+/*
+ * NAME
+ * _XcmsConvertColorsWithWhitePt - Convert XcmsColor structures
+ *
+ * SYNOPSIS
+ */
+Status
+_XcmsConvertColorsWithWhitePt(
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ XcmsColor *pWhitePt,
+ unsigned int nColors,
+ XcmsColorFormat newFormat,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * Convert XcmsColor structures between device-independent
+ * and/or device-dependent formats but allowing the calling
+ * routine to specify the white point to be associated
+ * with the color specifications (overriding
+ * ccc->clientWhitePt).
+ *
+ * This routine has been provided for use in white point
+ * adjustment routines.
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if succeeded without gamut compression,
+ * XcmsSuccessWithCompression if succeeded with gamut
+ * compression.
+ *
+ */
+{
+ if (ccc == NULL || pColors_in_out == NULL ||
+ pColors_in_out->format == XcmsUndefinedFormat) {
+ return(XcmsFailure);
+ }
+
+ if (nColors == 0 || pColors_in_out->format == newFormat) {
+ /* do nothing */
+ return(XcmsSuccess);
+ }
+
+ if (XCMS_DI_ID(pColors_in_out->format) && XCMS_DI_ID(newFormat)) {
+ /*
+ * Device-Independent to Device-Independent Conversion
+ */
+ return(_XcmsDIConvertColors(ccc, pColors_in_out, pWhitePt, nColors,
+ newFormat));
+ }
+ if (XCMS_DD_ID(pColors_in_out->format) && XCMS_DD_ID(newFormat)) {
+ /*
+ * Device-Dependent to Device-Dependent Conversion
+ */
+ return(_XcmsDDConvertColors(ccc, pColors_in_out, nColors, newFormat,
+ pCompressed));
+ }
+
+ /*
+ * Otherwise we have:
+ * 1. Device-Independent to Device-Dependent Conversion
+ * OR
+ * 2. Device-Dependent to Device-Independent Conversion
+ */
+
+ if (XCMS_DI_ID(pColors_in_out->format)) {
+ /*
+ * 1. Device-Independent to Device-Dependent Conversion
+ */
+ /* First convert to CIEXYZ */
+ if (_XcmsDIConvertColors(ccc, pColors_in_out, pWhitePt, nColors,
+ XcmsCIEXYZFormat) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ /* Then convert to DD Format */
+ return(_XcmsDDConvertColors(ccc, pColors_in_out, nColors, newFormat,
+ pCompressed));
+ } else {
+ /*
+ * 2. Device-Dependent to Device-Independent Conversion
+ */
+ /* First convert to CIEXYZ */
+ if (_XcmsDDConvertColors(ccc, pColors_in_out, nColors,
+ XcmsCIEXYZFormat, pCompressed) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ /* Then convert to DI Format */
+ return(_XcmsDIConvertColors(ccc, pColors_in_out, pWhitePt, nColors,
+ newFormat));
+ }
+}
diff --git a/libX11/src/xcms/CvCols.c b/libX11/src/xcms/CvCols.c index ed3582663..f86595595 100644 --- a/libX11/src/xcms/CvCols.c +++ b/libX11/src/xcms/CvCols.c @@ -1,1030 +1,1030 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsCvCols.c - * - * DESCRIPTION - * Xcms API routine that converts between the - * device-independent color spaces. - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - -/* - * LOCAL DEFINES - */ -#define DD_FORMAT 0x01 -#define DI_FORMAT 0x02 -#define MIX_FORMAT 0x04 -#ifndef MAX -# define MAX(x,y) ((x) > (y) ? (x) : (y)) -#endif - - -/************************************************************************ - * * - * PRIVATE ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * EqualCIEXYZ - * - * SYNOPSIS - */ -static int -EqualCIEXYZ( - XcmsColor *p1, XcmsColor *p2) -/* - * DESCRIPTION - * Compares two XcmsColor structures that are in XcmsCIEXYZFormat - * - * RETURNS - * Returns 1 if equal; 0 otherwise. - * - */ -{ - if (p1->format != XcmsCIEXYZFormat || p2->format != XcmsCIEXYZFormat) { - return(0); - } - if ((p1->spec.CIEXYZ.X != p2->spec.CIEXYZ.X) - || (p1->spec.CIEXYZ.Y != p2->spec.CIEXYZ.Y) - || (p1->spec.CIEXYZ.Z != p2->spec.CIEXYZ.Z)) { - return(0); - } - return(1); -} - - -/* - * NAME - * XcmsColorSpace - * - * SYNOPSIS - */ -static XcmsColorSpace * -ColorSpaceOfID( - XcmsCCC ccc, - XcmsColorFormat id) -/* - * DESCRIPTION - * Returns a pointer to the color space structure - * (XcmsColorSpace) associated with the specified color space - * ID. - * - * RETURNS - * Pointer to matching XcmsColorSpace structure if found; - * otherwise NULL. - */ -{ - XcmsColorSpace **papColorSpaces; - - if (ccc == NULL) { - return(NULL); - } - - /* - * First try Device-Independent color spaces - */ - papColorSpaces = _XcmsDIColorSpaces; - if (papColorSpaces != NULL) { - while (*papColorSpaces != NULL) { - if ((*papColorSpaces)->id == id) { - return(*papColorSpaces); - } - papColorSpaces++; - } - } - - /* - * Next try Device-Dependent color spaces - */ - papColorSpaces = ((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet)->DDColorSpaces; - if (papColorSpaces != NULL) { - while (*papColorSpaces != NULL) { - if ((*papColorSpaces)->id == id) { - return(*papColorSpaces); - } - papColorSpaces++; - } - } - - return(NULL); -} - - -/* - * NAME - * ValidDIColorSpaceID - * - * SYNOPSIS - */ -static int -ValidDIColorSpaceID( - XcmsColorFormat id) -/* - * DESCRIPTION - * Determines if the specified color space ID is a valid - * Device-Independent color space in the specified Color - * Conversion Context. - * - * RETURNS - * Returns zero if not valid; otherwise non-zero. - */ -{ - XcmsColorSpace **papRec; - papRec = _XcmsDIColorSpaces; - if (papRec != NULL) { - while (*papRec != NULL) { - if ((*papRec)->id == id) { - return(1); - } - papRec++; - } - } - return(0); -} - - -/* - * NAME - * ValidDDColorSpaceID - * - * SYNOPSIS - */ -static int -ValidDDColorSpaceID( - XcmsCCC ccc, - XcmsColorFormat id) -/* - * DESCRIPTION - * Determines if the specified color space ID is a valid - * Device-Dependent color space in the specified Color - * Conversion Context. - * - * RETURNS - * Returns zero if not valid; otherwise non-zero. - */ -{ - XcmsColorSpace **papRec; - - if (ccc->pPerScrnInfo->state != XcmsInitNone) { - papRec = ((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet)->DDColorSpaces; - while (*papRec != NULL) { - if ((*papRec)->id == id) { - return(1); - } - papRec++; - } - } - return(0); -} - - -/* - * NAME - * ConvertMixedColors - Convert XcmsColor structures - * - * SYNOPSIS - */ -static Status -ConvertMixedColors( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - XcmsColor *pWhitePt, - unsigned int nColors, - XcmsColorFormat targetFormat, - unsigned char format_flag) -/* - * DESCRIPTION - * This routine will only convert the following types of - * batches: - * DI to DI - * DD to DD - * DD to CIEXYZ - * In other words, it will not convert the following types of - * batches: - * DI to DD - * DD to DI(not CIEXYZ) - * - * format_flag: - * 0x01 : convert Device-Dependent only specifications to the - * target format. - * 0x02 : convert Device-Independent only specifications to the - * target format. - * 0x03 : convert all specifications to the target format. - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if none of the color specifications were - * compressed in the conversion process - * XcmsSuccessWithCompression if at least one of the - * color specifications were compressed in the - * conversion process. - * - */ -{ - XcmsColor *pColor, *pColors_start; - XcmsColorFormat format; - Status retval_tmp; - Status retval = XcmsSuccess; - unsigned int iColors; - unsigned int nBatch; - - /* - * Convert array of mixed color specifications in batches of - * contiguous formats to the target format - */ - iColors = 0; - while (iColors < nColors) { - /* - * Find contiguous array of color specifications with the - * same format - */ - pColor = pColors_start = pColors_in_out + iColors; - format = pColors_start->format; - nBatch = 0; - while (iColors < nColors && pColor->format == format) { - pColor++; - nBatch++; - iColors++; - } - if (format != targetFormat) { - /* - * Need to convert this batch from current format to target format. - */ - if (XCMS_DI_ID(format) && (format_flag & DI_FORMAT) && - XCMS_DI_ID(targetFormat)) { - /* - * DI->DI - * - * Format of interest is Device-Independent, - * This batch contains Device-Independent specifications, and - * the Target format is Device-Independent. - */ - retval_tmp = _XcmsDIConvertColors(ccc, pColors_start, pWhitePt, - nBatch, targetFormat); - } else if (XCMS_DD_ID(format) && (format_flag & DD_FORMAT) && - (targetFormat == XcmsCIEXYZFormat)) { - /* - * DD->CIEXYZ - * - * Format of interest is Device-Dependent, - * This batch contains Device-Dependent specifications, and - * the Target format is CIEXYZ. - * - * Since DD->CIEXYZ we can use NULL instead of pCompressed. - */ - if ((ccc->whitePtAdjProc != NULL) && !_XcmsEqualWhitePts(ccc, - pWhitePt, ScreenWhitePointOfCCC(ccc))) { - /* - * Need to call WhiteAdjustProc (Screen White Point to - * White Point). - */ - retval_tmp = (*ccc->whitePtAdjProc)(ccc, - ScreenWhitePointOfCCC(ccc), pWhitePt, - XcmsCIEXYZFormat, pColors_start, nBatch, - (Bool *)NULL); - } else { - retval_tmp = _XcmsDDConvertColors(ccc, pColors_start, - nBatch, XcmsCIEXYZFormat, (Bool *)NULL); - } - } else if (XCMS_DD_ID(format) && (format_flag & DD_FORMAT) && - XCMS_DD_ID(targetFormat)) { - /* - * DD->DD(not CIEXYZ) - * - * Format of interest is Device-Dependent, - * This batch contains Device-Dependent specifications, and - * the Target format is Device-Dependent and not CIEXYZ. - */ - retval_tmp = _XcmsDDConvertColors(ccc, pColors_start, nBatch, - targetFormat, (Bool *)NULL); - } else { - /* - * This routine is called for the wrong reason. - */ - return(XcmsFailure); - } - if (retval_tmp == XcmsFailure) { - return(XcmsFailure); - } - retval = MAX(retval, retval_tmp); - } - } - return(retval); -} - - -/************************************************************************ - * * - * API PRIVATE ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * _XcmsEqualWhitePts - * - * SYNOPSIS - */ -int -_XcmsEqualWhitePts(XcmsCCC ccc, XcmsColor *pWhitePt1, XcmsColor *pWhitePt2) -/* - * DESCRIPTION - * - * RETURNS - * Returns 0 if not equal; otherwise 1. - * - */ -{ - XcmsColor tmp1, tmp2; - - memcpy((char *)&tmp1, (char *)pWhitePt1, sizeof(XcmsColor)); - memcpy((char *)&tmp2, (char *)pWhitePt2, sizeof(XcmsColor)); - - if (tmp1.format != XcmsCIEXYZFormat) { - if (_XcmsDIConvertColors(ccc, &tmp1, (XcmsColor *) NULL, 1, - XcmsCIEXYZFormat)==0) { - return(0); - } - } - - if (tmp2.format != XcmsCIEXYZFormat) { - if (_XcmsDIConvertColors(ccc, &tmp2, (XcmsColor *) NULL, 1, - XcmsCIEXYZFormat)==0) { - return(0); - } - } - - return (EqualCIEXYZ(&tmp1, &tmp2)); -} - - -/* - * NAME - * _XcmsDIConvertColors - Convert XcmsColor structures - * - * SYNOPSIS - */ -Status -_XcmsDIConvertColors( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - XcmsColor *pWhitePt, - unsigned int nColors, - XcmsColorFormat newFormat) -/* - * DESCRIPTION - * Convert XcmsColor structures to another Device-Independent - * form. - * - * Here are some assumptions that this routine makes: - * 1. The calling routine has already checked if - * pColors_in_out->format == newFormat, therefore - * there is no need to check again here. - * 2. The calling routine has already checked nColors, - * therefore this routine assumes nColors > 0. - * 3. The calling routine may want to convert only between - * CIExyY <-> CIEXYZ <-> CIEuvY - * therefore, this routine allows pWhitePt to equal NULL. - * - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if succeeded. - * - */ -{ - XcmsColorSpace *pFrom, *pTo; - XcmsDIConversionProc *src_to_CIEXYZ, *src_from_CIEXYZ; - XcmsDIConversionProc *dest_to_CIEXYZ, *dest_from_CIEXYZ; - XcmsDIConversionProc *to_CIEXYZ_stop, *from_CIEXYZ_start; - XcmsDIConversionProc *tmp; - - /* - * Allow pWhitePt to equal NULL. This appropriate when converting - * anywhere between: - * CIExyY <-> CIEXYZ <-> CIEuvY - */ - - if (pColors_in_out == NULL || - !ValidDIColorSpaceID(pColors_in_out->format) || - !ValidDIColorSpaceID(newFormat)) { - return(XcmsFailure); - } - - /* - * Get a handle on the function list for the current specification format - */ - if ((pFrom = ColorSpaceOfID(ccc, pColors_in_out->format)) - == NULL) { - return(XcmsFailure); - } - - /* - * Get a handle on the function list for the new specification format - */ - if ((pTo = ColorSpaceOfID(ccc, newFormat)) == NULL) { - return(XcmsFailure); - } - - src_to_CIEXYZ = pFrom->to_CIEXYZ; - src_from_CIEXYZ = pFrom->from_CIEXYZ; - dest_to_CIEXYZ = pTo->to_CIEXYZ; - dest_from_CIEXYZ = pTo->from_CIEXYZ; - - if (pTo->inverse_flag && pFrom->inverse_flag) { - /* - * Find common function pointers - */ - for (to_CIEXYZ_stop = src_to_CIEXYZ; *to_CIEXYZ_stop; to_CIEXYZ_stop++){ - for (tmp = dest_to_CIEXYZ; *tmp; tmp++) { - if (*to_CIEXYZ_stop == *tmp) { - goto Continue; - } - } - } - -Continue: - - /* - * Execute the functions to CIEXYZ, stopping short as necessary - */ - while (src_to_CIEXYZ != to_CIEXYZ_stop) { - if ((*src_to_CIEXYZ++)(ccc, pWhitePt, pColors_in_out, - nColors) == XcmsFailure) { - return(XcmsFailure); - } - } - - /* - * Determine where to start on the from_CIEXYZ path. - */ - from_CIEXYZ_start = dest_from_CIEXYZ; - tmp = src_from_CIEXYZ; - while ((*from_CIEXYZ_start == *tmp) && (*from_CIEXYZ_start != NULL)) { - from_CIEXYZ_start++; - tmp++; - } - - } else { - /* - * The function in at least one of the Color Spaces are not - * complementary, i.e., - * for an i, 0 <= i < n elements - * from_CIEXYZ[i] is not the inverse of to_CIEXYZ[i] - * - * Execute the functions all the way to CIEXYZ - */ - while (*src_to_CIEXYZ) { - if ((*src_to_CIEXYZ++)(ccc, pWhitePt, pColors_in_out, - nColors) == XcmsFailure) { - return(XcmsFailure); - } - } - - /* - * Determine where to start on the from_CIEXYZ path. - */ - from_CIEXYZ_start = dest_from_CIEXYZ; - } - - - /* - * Execute the functions from CIEXYZ. - */ - while (*from_CIEXYZ_start) { - if ((*from_CIEXYZ_start++)(ccc, pWhitePt, pColors_in_out, - nColors) == XcmsFailure) { - return(XcmsFailure); - } - } - - return(XcmsSuccess); -} - - -/* - * NAME - * _XcmsDDConvertColors - Convert XcmsColor structures - * - * SYNOPSIS - */ -Status -_XcmsDDConvertColors( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - unsigned int nColors, - XcmsColorFormat newFormat, - Bool *pCompressed) -/* - * DESCRIPTION - * Convert XcmsColor structures: - * - * 1. From CIEXYZ to Device-Dependent formats (typically RGB and - * RGBi), - * or - * 2. Between Device-Dependent formats (typically RGB and RGBi). - * - * Assumes that these specifications have already been white point - * adjusted if necessary from Client White Point to Screen - * White Point. Therefore, the white point now associated - * with the specifications is the Screen White Point. - * - * pCompressed may be NULL. If so this indicates that the - * calling routine is not interested in knowing exactly which - * color was compressed, if any. - * - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if none of the color specifications were - * compressed in the conversion process - * XcmsSuccessWithCompression if at least one of the - * color specifications were compressed in the - * conversion process. - * - */ -{ - XcmsColorSpace *pFrom, *pTo; - XcmsDDConversionProc *src_to_CIEXYZ, *src_from_CIEXYZ; - XcmsDDConversionProc *dest_to_CIEXYZ, *dest_from_CIEXYZ; - XcmsDDConversionProc *from_CIEXYZ_start, *to_CIEXYZ_stop; - XcmsDDConversionProc *tmp; - int retval; - int hasCompressed = 0; - - if (ccc == NULL || pColors_in_out == NULL) { - return(XcmsFailure); - } - - if (nColors == 0 || pColors_in_out->format == newFormat) { - /* do nothing */ - return(XcmsSuccess); - } - - if (((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet) == NULL) { - return(XcmsFailure); /* hmm, an internal error? */ - } - - /* - * Its ok if pColors_in_out->format == XcmsCIEXYZFormat - * or - * if newFormat == XcmsCIEXYZFormat - */ - if ( !( ValidDDColorSpaceID(ccc, pColors_in_out->format) - || - (pColors_in_out->format == XcmsCIEXYZFormat)) - || - !(ValidDDColorSpaceID(ccc, newFormat) - || - newFormat == XcmsCIEXYZFormat)) { - return(XcmsFailure); - } - - if ((pFrom = ColorSpaceOfID(ccc, pColors_in_out->format)) == NULL){ - return(XcmsFailure); - } - - if ((pTo = ColorSpaceOfID(ccc, newFormat)) == NULL) { - return(XcmsFailure); - } - - src_to_CIEXYZ = (XcmsDDConversionProc *)pFrom->to_CIEXYZ; - src_from_CIEXYZ = (XcmsDDConversionProc *)pFrom->from_CIEXYZ; - dest_to_CIEXYZ = (XcmsDDConversionProc *)pTo->to_CIEXYZ; - dest_from_CIEXYZ = (XcmsDDConversionProc *)pTo->from_CIEXYZ; - - if (pTo->inverse_flag && pFrom->inverse_flag) { - /* - * Find common function pointers - */ - for (to_CIEXYZ_stop = src_to_CIEXYZ; *to_CIEXYZ_stop; to_CIEXYZ_stop++){ - for (tmp = dest_to_CIEXYZ; *tmp; tmp++) { - if (*to_CIEXYZ_stop == *tmp) { - goto Continue; - } - } - } -Continue: - - /* - * Execute the functions - */ - while (src_to_CIEXYZ != to_CIEXYZ_stop) { - retval = (*src_to_CIEXYZ++)(ccc, pColors_in_out, nColors, - pCompressed); - if (retval == XcmsFailure) { - return(XcmsFailure); - } - hasCompressed |= (retval == XcmsSuccessWithCompression); - } - - /* - * Determine where to start on the from_CIEXYZ path. - */ - from_CIEXYZ_start = dest_from_CIEXYZ; - tmp = src_from_CIEXYZ; - while ((*from_CIEXYZ_start == *tmp) && (*from_CIEXYZ_start != NULL)) { - from_CIEXYZ_start++; - tmp++; - } - - } else { - /* - * The function in at least one of the Color Spaces are not - * complementary, i.e., - * for an i, 0 <= i < n elements - * from_CIEXYZ[i] is not the inverse of to_CIEXYZ[i] - * - * Execute the functions all the way to CIEXYZ - */ - while (*src_to_CIEXYZ) { - retval = (*src_to_CIEXYZ++)(ccc, pColors_in_out, nColors, - pCompressed); - if (retval == XcmsFailure) { - return(XcmsFailure); - } - hasCompressed |= (retval == XcmsSuccessWithCompression); - } - - /* - * Determine where to start on the from_CIEXYZ path. - */ - from_CIEXYZ_start = dest_from_CIEXYZ; - } - - while (*from_CIEXYZ_start) { - retval = (*from_CIEXYZ_start++)(ccc, pColors_in_out, nColors, - pCompressed); - if (retval == XcmsFailure) { - return(XcmsFailure); - } - hasCompressed |= (retval == XcmsSuccessWithCompression); - } - - return(hasCompressed ? XcmsSuccessWithCompression : XcmsSuccess); -} - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsConvertColors - Convert XcmsColor structures - * - * SYNOPSIS - */ -Status -XcmsConvertColors( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - unsigned int nColors, - XcmsColorFormat targetFormat, - Bool *pCompressed) -/* - * DESCRIPTION - * Convert XcmsColor structures to another format - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if succeeded without gamut compression, - * XcmsSuccessWithCompression if succeeded with gamut - * compression. - * - */ -{ - XcmsColor clientWhitePt; - XcmsColor Color1; - XcmsColor *pColors_tmp; - int callWhiteAdjustProc = 0; - XcmsColorFormat format; - Status retval; - unsigned char contents_flag = 0x00; - unsigned int iColors; - - if (ccc == NULL || pColors_in_out == NULL || - !(ValidDIColorSpaceID(targetFormat) || - ValidDDColorSpaceID(ccc, targetFormat))) { - return(XcmsFailure); - } - - /* - * Check formats in color specification array - */ - format = pColors_in_out->format; - for (pColors_tmp = pColors_in_out, iColors = nColors; iColors; pColors_tmp++, iColors--) { - if (!(ValidDIColorSpaceID(pColors_tmp->format) || - ValidDDColorSpaceID(ccc, pColors_tmp->format))) { - return(XcmsFailure); - } - if (XCMS_DI_ID(pColors_tmp->format)) { - contents_flag |= DI_FORMAT; - } else { - contents_flag |= DD_FORMAT; - } - if (pColors_tmp->format != format) { - contents_flag |= MIX_FORMAT; - } - } - - /* - * Check if we need the Client White Point. - */ - if ((contents_flag & DI_FORMAT) || XCMS_DI_ID(targetFormat)) { - /* To proceed, we need to get the Client White Point */ - memcpy((char *)&clientWhitePt, (char *)&ccc->clientWhitePt, - sizeof(XcmsColor)); - if (clientWhitePt.format == XcmsUndefinedFormat) { - /* - * Client White Point is undefined, therefore set to the Screen - * White Point. - * Since Client White Point == Screen White Point, WhiteAdjustProc - * is not called. - */ - memcpy((char *)&clientWhitePt, - (char *)&ccc->pPerScrnInfo->screenWhitePt, - sizeof(XcmsColor)); - } else if ((ccc->whitePtAdjProc != NULL) && !_XcmsEqualWhitePts(ccc, - &clientWhitePt, ScreenWhitePointOfCCC(ccc))) { - /* - * Client White Point != Screen White Point, and WhiteAdjustProc - * is not NULL, therefore, will need to call it when - * converting between DI and DD specifications. - */ - callWhiteAdjustProc = 1; - } - } - - /* - * Make copy of array of color specifications - */ - if (nColors > 1) { - pColors_tmp = (XcmsColor *) Xmalloc(nColors * sizeof(XcmsColor)); - } else { - pColors_tmp = &Color1; - } - memcpy((char *)pColors_tmp, (char *)pColors_in_out, - nColors * sizeof(XcmsColor)); - - /* - * zero out pCompressed - */ - if (pCompressed) { - bzero((char *)pCompressed, nColors * sizeof(Bool)); - } - - if (contents_flag == DD_FORMAT || contents_flag == DI_FORMAT) { - /* - * ENTIRE ARRAY IS IN ONE FORMAT. - */ - if (XCMS_DI_ID(format) && XCMS_DI_ID(targetFormat)) { - /* - * DI-to-DI only conversion - */ - retval = _XcmsDIConvertColors(ccc, pColors_tmp, - &clientWhitePt, nColors, targetFormat); - } else if (XCMS_DD_ID(format) && XCMS_DD_ID(targetFormat)) { - /* - * DD-to-DD only conversion - * Since DD->DD there will be no compressed thus we can - * pass NULL instead of pCompressed. - */ - retval = _XcmsDDConvertColors(ccc, pColors_tmp, nColors, - targetFormat, (Bool *)NULL); - } else { - /* - * Otherwise we have: - * 1. Device-Independent to Device-Dependent Conversion - * OR - * 2. Device-Dependent to Device-Independent Conversion - * - * We need to go from oldFormat -> CIEXYZ -> targetFormat - * adjusting for white points as necessary. - */ - - if (XCMS_DI_ID(format)) { - /* - * 1. Device-Independent to Device-Dependent Conversion - */ - if (callWhiteAdjustProc) { - /* - * White Point Adjustment - * Client White Point to Screen White Point - */ - retval = (*ccc->whitePtAdjProc)(ccc, &clientWhitePt, - ScreenWhitePointOfCCC(ccc), targetFormat, - pColors_tmp, nColors, pCompressed); - } else { - if (_XcmsDIConvertColors(ccc, pColors_tmp, - &clientWhitePt, nColors, XcmsCIEXYZFormat) - == XcmsFailure) { - goto Failure; - } - retval = _XcmsDDConvertColors(ccc, pColors_tmp, nColors, - targetFormat, pCompressed); - } - } else { - /* - * 2. Device-Dependent to Device-Independent Conversion - */ - if (callWhiteAdjustProc) { - /* - * White Point Adjustment - * Screen White Point to Client White Point - */ - retval = (*ccc->whitePtAdjProc)(ccc, - ScreenWhitePointOfCCC(ccc), &clientWhitePt, - targetFormat, pColors_tmp, nColors, pCompressed); - } else { - /* - * Since DD->CIEXYZ, no compression takes place therefore - * we can pass NULL instead of pCompressed. - */ - if (_XcmsDDConvertColors(ccc, pColors_tmp, nColors, - XcmsCIEXYZFormat, (Bool *)NULL) == XcmsFailure) { - goto Failure; - } - retval = _XcmsDIConvertColors(ccc, pColors_tmp, - &clientWhitePt, nColors, targetFormat); - } - } - } - } else { - /* - * ARRAY HAS MIXED FORMATS. - */ - if ((contents_flag == (DI_FORMAT | MIX_FORMAT)) && - XCMS_DI_ID(targetFormat)) { - /* - * Convert from DI to DI in batches of contiguous formats - * - * Because DI->DI, WhiteAdjustProc not called. - */ - retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt, - nColors, targetFormat, (unsigned char)DI_FORMAT); - } else if ((contents_flag == (DD_FORMAT | MIX_FORMAT)) && - XCMS_DD_ID(targetFormat)) { - /* - * Convert from DD to DD in batches of contiguous formats - * - * Because DD->DD, WhiteAdjustProc not called. - */ - retval = ConvertMixedColors(ccc, pColors_tmp, - (XcmsColor *)NULL, nColors, targetFormat, - (unsigned char)DD_FORMAT); - } else if (XCMS_DI_ID(targetFormat)) { - /* - * We need to convert from DI-to-DI and DD-to-DI, therefore - * 1. convert DD specifications to CIEXYZ, then - * 2. convert all in batches to the target DI format. - * - * Note that ConvertMixedColors will call WhiteAdjustProc - * as necessary. - */ - - /* - * Convert only DD specifications in batches of contiguous formats - * to CIEXYZ - * - * Since DD->CIEXYZ, ConvertMixedColors will apply WhiteAdjustProc - * if required. - */ - retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt, - nColors, XcmsCIEXYZFormat, (unsigned char)DD_FORMAT); - - /* - * Because at this point we may have a mix of DI formats - * (e.g., CIEXYZ, CIELuv) we must convert the specs to the - * target DI format in batches of contiguous source formats. - */ - retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt, - nColors, targetFormat, (unsigned char)DI_FORMAT); - } else { - /* - * We need to convert from DI-to-DD and DD-to-DD, therefore - * 1. convert DI specifications to CIEXYZ, then - * 2. convert all to the DD target format. - * - * This allows white point adjustment and gamut compression - * to be applied to all the color specifications in one - * swoop if those functions do in fact modify the entire - * group of color specifications. - */ - - /* - * Convert in batches to CIEXYZ - * - * If DD->CIEXYZ, ConvertMixedColors will apply WhiteAdjustProc - * if required. - */ - if ((retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt, - nColors, XcmsCIEXYZFormat, - (unsigned char)(DI_FORMAT | DD_FORMAT))) == XcmsFailure) { - goto Failure; - } - - /* - * Convert all specifications (now in CIEXYZ format) to - * the target DD format. - * Since CIEXYZ->DD, compression MAY take place therefore - * we must pass pCompressed. - * Note that WhiteAdjustProc must be used if necessary. - */ - if (callWhiteAdjustProc) { - /* - * White Point Adjustment - * Client White Point to Screen White Point - */ - retval = (*ccc->whitePtAdjProc)(ccc, - &clientWhitePt, ScreenWhitePointOfCCC(ccc), - targetFormat, pColors_tmp, nColors, pCompressed); - } else { - retval = _XcmsDDConvertColors(ccc, pColors_tmp, nColors, - targetFormat, pCompressed); - } - } - } - - if (retval != XcmsFailure) { - memcpy((char *)pColors_in_out, (char *)pColors_tmp, - nColors * sizeof(XcmsColor)); - } - if (nColors > 1) { - Xfree((char *)pColors_tmp); - } - return(retval); - -Failure: - if (nColors > 1) { - Xfree((char *)pColors_tmp); - } - return(XcmsFailure); -} - - -/* - * NAME - * XcmsRegFormatOfPrefix - * - * SYNOPSIS - */ -XcmsColorFormat -_XcmsRegFormatOfPrefix( - _Xconst char *prefix) -/* - * DESCRIPTION - * Returns a color space ID associated with the specified - * X Consortium registered color space prefix. - * - * RETURNS - * The color space ID if found; - * otherwise NULL. - */ -{ - XcmsRegColorSpaceEntry *pEntry = _XcmsRegColorSpaces; - - while (pEntry->prefix != NULL) { - if (strcmp(prefix, pEntry->prefix) == 0) { - return(pEntry->id); - } - pEntry++; - } - return(XcmsUndefinedFormat); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsCvCols.c
+ *
+ * DESCRIPTION
+ * Xcms API routine that converts between the
+ * device-independent color spaces.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+/*
+ * LOCAL DEFINES
+ */
+#define DD_FORMAT 0x01
+#define DI_FORMAT 0x02
+#define MIX_FORMAT 0x04
+#ifndef MAX
+# define MAX(x,y) ((x) > (y) ? (x) : (y))
+#endif
+
+
+/************************************************************************
+ * *
+ * PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * EqualCIEXYZ
+ *
+ * SYNOPSIS
+ */
+static int
+EqualCIEXYZ(
+ XcmsColor *p1, XcmsColor *p2)
+/*
+ * DESCRIPTION
+ * Compares two XcmsColor structures that are in XcmsCIEXYZFormat
+ *
+ * RETURNS
+ * Returns 1 if equal; 0 otherwise.
+ *
+ */
+{
+ if (p1->format != XcmsCIEXYZFormat || p2->format != XcmsCIEXYZFormat) {
+ return(0);
+ }
+ if ((p1->spec.CIEXYZ.X != p2->spec.CIEXYZ.X)
+ || (p1->spec.CIEXYZ.Y != p2->spec.CIEXYZ.Y)
+ || (p1->spec.CIEXYZ.Z != p2->spec.CIEXYZ.Z)) {
+ return(0);
+ }
+ return(1);
+}
+
+
+/*
+ * NAME
+ * XcmsColorSpace
+ *
+ * SYNOPSIS
+ */
+static XcmsColorSpace *
+ColorSpaceOfID(
+ XcmsCCC ccc,
+ XcmsColorFormat id)
+/*
+ * DESCRIPTION
+ * Returns a pointer to the color space structure
+ * (XcmsColorSpace) associated with the specified color space
+ * ID.
+ *
+ * RETURNS
+ * Pointer to matching XcmsColorSpace structure if found;
+ * otherwise NULL.
+ */
+{
+ XcmsColorSpace **papColorSpaces;
+
+ if (ccc == NULL) {
+ return(NULL);
+ }
+
+ /*
+ * First try Device-Independent color spaces
+ */
+ papColorSpaces = _XcmsDIColorSpaces;
+ if (papColorSpaces != NULL) {
+ while (*papColorSpaces != NULL) {
+ if ((*papColorSpaces)->id == id) {
+ return(*papColorSpaces);
+ }
+ papColorSpaces++;
+ }
+ }
+
+ /*
+ * Next try Device-Dependent color spaces
+ */
+ papColorSpaces = ((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet)->DDColorSpaces;
+ if (papColorSpaces != NULL) {
+ while (*papColorSpaces != NULL) {
+ if ((*papColorSpaces)->id == id) {
+ return(*papColorSpaces);
+ }
+ papColorSpaces++;
+ }
+ }
+
+ return(NULL);
+}
+
+
+/*
+ * NAME
+ * ValidDIColorSpaceID
+ *
+ * SYNOPSIS
+ */
+static int
+ValidDIColorSpaceID(
+ XcmsColorFormat id)
+/*
+ * DESCRIPTION
+ * Determines if the specified color space ID is a valid
+ * Device-Independent color space in the specified Color
+ * Conversion Context.
+ *
+ * RETURNS
+ * Returns zero if not valid; otherwise non-zero.
+ */
+{
+ XcmsColorSpace **papRec;
+ papRec = _XcmsDIColorSpaces;
+ if (papRec != NULL) {
+ while (*papRec != NULL) {
+ if ((*papRec)->id == id) {
+ return(1);
+ }
+ papRec++;
+ }
+ }
+ return(0);
+}
+
+
+/*
+ * NAME
+ * ValidDDColorSpaceID
+ *
+ * SYNOPSIS
+ */
+static int
+ValidDDColorSpaceID(
+ XcmsCCC ccc,
+ XcmsColorFormat id)
+/*
+ * DESCRIPTION
+ * Determines if the specified color space ID is a valid
+ * Device-Dependent color space in the specified Color
+ * Conversion Context.
+ *
+ * RETURNS
+ * Returns zero if not valid; otherwise non-zero.
+ */
+{
+ XcmsColorSpace **papRec;
+
+ if (ccc->pPerScrnInfo->state != XcmsInitNone) {
+ papRec = ((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet)->DDColorSpaces;
+ while (*papRec != NULL) {
+ if ((*papRec)->id == id) {
+ return(1);
+ }
+ papRec++;
+ }
+ }
+ return(0);
+}
+
+
+/*
+ * NAME
+ * ConvertMixedColors - Convert XcmsColor structures
+ *
+ * SYNOPSIS
+ */
+static Status
+ConvertMixedColors(
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ XcmsColor *pWhitePt,
+ unsigned int nColors,
+ XcmsColorFormat targetFormat,
+ unsigned char format_flag)
+/*
+ * DESCRIPTION
+ * This routine will only convert the following types of
+ * batches:
+ * DI to DI
+ * DD to DD
+ * DD to CIEXYZ
+ * In other words, it will not convert the following types of
+ * batches:
+ * DI to DD
+ * DD to DI(not CIEXYZ)
+ *
+ * format_flag:
+ * 0x01 : convert Device-Dependent only specifications to the
+ * target format.
+ * 0x02 : convert Device-Independent only specifications to the
+ * target format.
+ * 0x03 : convert all specifications to the target format.
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if none of the color specifications were
+ * compressed in the conversion process
+ * XcmsSuccessWithCompression if at least one of the
+ * color specifications were compressed in the
+ * conversion process.
+ *
+ */
+{
+ XcmsColor *pColor, *pColors_start;
+ XcmsColorFormat format;
+ Status retval_tmp;
+ Status retval = XcmsSuccess;
+ unsigned int iColors;
+ unsigned int nBatch;
+
+ /*
+ * Convert array of mixed color specifications in batches of
+ * contiguous formats to the target format
+ */
+ iColors = 0;
+ while (iColors < nColors) {
+ /*
+ * Find contiguous array of color specifications with the
+ * same format
+ */
+ pColor = pColors_start = pColors_in_out + iColors;
+ format = pColors_start->format;
+ nBatch = 0;
+ while (iColors < nColors && pColor->format == format) {
+ pColor++;
+ nBatch++;
+ iColors++;
+ }
+ if (format != targetFormat) {
+ /*
+ * Need to convert this batch from current format to target format.
+ */
+ if (XCMS_DI_ID(format) && (format_flag & DI_FORMAT) &&
+ XCMS_DI_ID(targetFormat)) {
+ /*
+ * DI->DI
+ *
+ * Format of interest is Device-Independent,
+ * This batch contains Device-Independent specifications, and
+ * the Target format is Device-Independent.
+ */
+ retval_tmp = _XcmsDIConvertColors(ccc, pColors_start, pWhitePt,
+ nBatch, targetFormat);
+ } else if (XCMS_DD_ID(format) && (format_flag & DD_FORMAT) &&
+ (targetFormat == XcmsCIEXYZFormat)) {
+ /*
+ * DD->CIEXYZ
+ *
+ * Format of interest is Device-Dependent,
+ * This batch contains Device-Dependent specifications, and
+ * the Target format is CIEXYZ.
+ *
+ * Since DD->CIEXYZ we can use NULL instead of pCompressed.
+ */
+ if ((ccc->whitePtAdjProc != NULL) && !_XcmsEqualWhitePts(ccc,
+ pWhitePt, ScreenWhitePointOfCCC(ccc))) {
+ /*
+ * Need to call WhiteAdjustProc (Screen White Point to
+ * White Point).
+ */
+ retval_tmp = (*ccc->whitePtAdjProc)(ccc,
+ ScreenWhitePointOfCCC(ccc), pWhitePt,
+ XcmsCIEXYZFormat, pColors_start, nBatch,
+ (Bool *)NULL);
+ } else {
+ retval_tmp = _XcmsDDConvertColors(ccc, pColors_start,
+ nBatch, XcmsCIEXYZFormat, (Bool *)NULL);
+ }
+ } else if (XCMS_DD_ID(format) && (format_flag & DD_FORMAT) &&
+ XCMS_DD_ID(targetFormat)) {
+ /*
+ * DD->DD(not CIEXYZ)
+ *
+ * Format of interest is Device-Dependent,
+ * This batch contains Device-Dependent specifications, and
+ * the Target format is Device-Dependent and not CIEXYZ.
+ */
+ retval_tmp = _XcmsDDConvertColors(ccc, pColors_start, nBatch,
+ targetFormat, (Bool *)NULL);
+ } else {
+ /*
+ * This routine is called for the wrong reason.
+ */
+ return(XcmsFailure);
+ }
+ if (retval_tmp == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ retval = MAX(retval, retval_tmp);
+ }
+ }
+ return(retval);
+}
+
+
+/************************************************************************
+ * *
+ * API PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * _XcmsEqualWhitePts
+ *
+ * SYNOPSIS
+ */
+int
+_XcmsEqualWhitePts(XcmsCCC ccc, XcmsColor *pWhitePt1, XcmsColor *pWhitePt2)
+/*
+ * DESCRIPTION
+ *
+ * RETURNS
+ * Returns 0 if not equal; otherwise 1.
+ *
+ */
+{
+ XcmsColor tmp1, tmp2;
+
+ memcpy((char *)&tmp1, (char *)pWhitePt1, sizeof(XcmsColor));
+ memcpy((char *)&tmp2, (char *)pWhitePt2, sizeof(XcmsColor));
+
+ if (tmp1.format != XcmsCIEXYZFormat) {
+ if (_XcmsDIConvertColors(ccc, &tmp1, (XcmsColor *) NULL, 1,
+ XcmsCIEXYZFormat)==0) {
+ return(0);
+ }
+ }
+
+ if (tmp2.format != XcmsCIEXYZFormat) {
+ if (_XcmsDIConvertColors(ccc, &tmp2, (XcmsColor *) NULL, 1,
+ XcmsCIEXYZFormat)==0) {
+ return(0);
+ }
+ }
+
+ return (EqualCIEXYZ(&tmp1, &tmp2));
+}
+
+
+/*
+ * NAME
+ * _XcmsDIConvertColors - Convert XcmsColor structures
+ *
+ * SYNOPSIS
+ */
+Status
+_XcmsDIConvertColors(
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ XcmsColor *pWhitePt,
+ unsigned int nColors,
+ XcmsColorFormat newFormat)
+/*
+ * DESCRIPTION
+ * Convert XcmsColor structures to another Device-Independent
+ * form.
+ *
+ * Here are some assumptions that this routine makes:
+ * 1. The calling routine has already checked if
+ * pColors_in_out->format == newFormat, therefore
+ * there is no need to check again here.
+ * 2. The calling routine has already checked nColors,
+ * therefore this routine assumes nColors > 0.
+ * 3. The calling routine may want to convert only between
+ * CIExyY <-> CIEXYZ <-> CIEuvY
+ * therefore, this routine allows pWhitePt to equal NULL.
+ *
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if succeeded.
+ *
+ */
+{
+ XcmsColorSpace *pFrom, *pTo;
+ XcmsDIConversionProc *src_to_CIEXYZ, *src_from_CIEXYZ;
+ XcmsDIConversionProc *dest_to_CIEXYZ, *dest_from_CIEXYZ;
+ XcmsDIConversionProc *to_CIEXYZ_stop, *from_CIEXYZ_start;
+ XcmsDIConversionProc *tmp;
+
+ /*
+ * Allow pWhitePt to equal NULL. This appropriate when converting
+ * anywhere between:
+ * CIExyY <-> CIEXYZ <-> CIEuvY
+ */
+
+ if (pColors_in_out == NULL ||
+ !ValidDIColorSpaceID(pColors_in_out->format) ||
+ !ValidDIColorSpaceID(newFormat)) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Get a handle on the function list for the current specification format
+ */
+ if ((pFrom = ColorSpaceOfID(ccc, pColors_in_out->format))
+ == NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Get a handle on the function list for the new specification format
+ */
+ if ((pTo = ColorSpaceOfID(ccc, newFormat)) == NULL) {
+ return(XcmsFailure);
+ }
+
+ src_to_CIEXYZ = pFrom->to_CIEXYZ;
+ src_from_CIEXYZ = pFrom->from_CIEXYZ;
+ dest_to_CIEXYZ = pTo->to_CIEXYZ;
+ dest_from_CIEXYZ = pTo->from_CIEXYZ;
+
+ if (pTo->inverse_flag && pFrom->inverse_flag) {
+ /*
+ * Find common function pointers
+ */
+ for (to_CIEXYZ_stop = src_to_CIEXYZ; *to_CIEXYZ_stop; to_CIEXYZ_stop++){
+ for (tmp = dest_to_CIEXYZ; *tmp; tmp++) {
+ if (*to_CIEXYZ_stop == *tmp) {
+ goto Continue;
+ }
+ }
+ }
+
+Continue:
+
+ /*
+ * Execute the functions to CIEXYZ, stopping short as necessary
+ */
+ while (src_to_CIEXYZ != to_CIEXYZ_stop) {
+ if ((*src_to_CIEXYZ++)(ccc, pWhitePt, pColors_in_out,
+ nColors) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+
+ /*
+ * Determine where to start on the from_CIEXYZ path.
+ */
+ from_CIEXYZ_start = dest_from_CIEXYZ;
+ tmp = src_from_CIEXYZ;
+ while ((*from_CIEXYZ_start == *tmp) && (*from_CIEXYZ_start != NULL)) {
+ from_CIEXYZ_start++;
+ tmp++;
+ }
+
+ } else {
+ /*
+ * The function in at least one of the Color Spaces are not
+ * complementary, i.e.,
+ * for an i, 0 <= i < n elements
+ * from_CIEXYZ[i] is not the inverse of to_CIEXYZ[i]
+ *
+ * Execute the functions all the way to CIEXYZ
+ */
+ while (*src_to_CIEXYZ) {
+ if ((*src_to_CIEXYZ++)(ccc, pWhitePt, pColors_in_out,
+ nColors) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+
+ /*
+ * Determine where to start on the from_CIEXYZ path.
+ */
+ from_CIEXYZ_start = dest_from_CIEXYZ;
+ }
+
+
+ /*
+ * Execute the functions from CIEXYZ.
+ */
+ while (*from_CIEXYZ_start) {
+ if ((*from_CIEXYZ_start++)(ccc, pWhitePt, pColors_in_out,
+ nColors) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+
+ return(XcmsSuccess);
+}
+
+
+/*
+ * NAME
+ * _XcmsDDConvertColors - Convert XcmsColor structures
+ *
+ * SYNOPSIS
+ */
+Status
+_XcmsDDConvertColors(
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors,
+ XcmsColorFormat newFormat,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * Convert XcmsColor structures:
+ *
+ * 1. From CIEXYZ to Device-Dependent formats (typically RGB and
+ * RGBi),
+ * or
+ * 2. Between Device-Dependent formats (typically RGB and RGBi).
+ *
+ * Assumes that these specifications have already been white point
+ * adjusted if necessary from Client White Point to Screen
+ * White Point. Therefore, the white point now associated
+ * with the specifications is the Screen White Point.
+ *
+ * pCompressed may be NULL. If so this indicates that the
+ * calling routine is not interested in knowing exactly which
+ * color was compressed, if any.
+ *
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if none of the color specifications were
+ * compressed in the conversion process
+ * XcmsSuccessWithCompression if at least one of the
+ * color specifications were compressed in the
+ * conversion process.
+ *
+ */
+{
+ XcmsColorSpace *pFrom, *pTo;
+ XcmsDDConversionProc *src_to_CIEXYZ, *src_from_CIEXYZ;
+ XcmsDDConversionProc *dest_to_CIEXYZ, *dest_from_CIEXYZ;
+ XcmsDDConversionProc *from_CIEXYZ_start, *to_CIEXYZ_stop;
+ XcmsDDConversionProc *tmp;
+ int retval;
+ int hasCompressed = 0;
+
+ if (ccc == NULL || pColors_in_out == NULL) {
+ return(XcmsFailure);
+ }
+
+ if (nColors == 0 || pColors_in_out->format == newFormat) {
+ /* do nothing */
+ return(XcmsSuccess);
+ }
+
+ if (((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet) == NULL) {
+ return(XcmsFailure); /* hmm, an internal error? */
+ }
+
+ /*
+ * Its ok if pColors_in_out->format == XcmsCIEXYZFormat
+ * or
+ * if newFormat == XcmsCIEXYZFormat
+ */
+ if ( !( ValidDDColorSpaceID(ccc, pColors_in_out->format)
+ ||
+ (pColors_in_out->format == XcmsCIEXYZFormat))
+ ||
+ !(ValidDDColorSpaceID(ccc, newFormat)
+ ||
+ newFormat == XcmsCIEXYZFormat)) {
+ return(XcmsFailure);
+ }
+
+ if ((pFrom = ColorSpaceOfID(ccc, pColors_in_out->format)) == NULL){
+ return(XcmsFailure);
+ }
+
+ if ((pTo = ColorSpaceOfID(ccc, newFormat)) == NULL) {
+ return(XcmsFailure);
+ }
+
+ src_to_CIEXYZ = (XcmsDDConversionProc *)pFrom->to_CIEXYZ;
+ src_from_CIEXYZ = (XcmsDDConversionProc *)pFrom->from_CIEXYZ;
+ dest_to_CIEXYZ = (XcmsDDConversionProc *)pTo->to_CIEXYZ;
+ dest_from_CIEXYZ = (XcmsDDConversionProc *)pTo->from_CIEXYZ;
+
+ if (pTo->inverse_flag && pFrom->inverse_flag) {
+ /*
+ * Find common function pointers
+ */
+ for (to_CIEXYZ_stop = src_to_CIEXYZ; *to_CIEXYZ_stop; to_CIEXYZ_stop++){
+ for (tmp = dest_to_CIEXYZ; *tmp; tmp++) {
+ if (*to_CIEXYZ_stop == *tmp) {
+ goto Continue;
+ }
+ }
+ }
+Continue:
+
+ /*
+ * Execute the functions
+ */
+ while (src_to_CIEXYZ != to_CIEXYZ_stop) {
+ retval = (*src_to_CIEXYZ++)(ccc, pColors_in_out, nColors,
+ pCompressed);
+ if (retval == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ hasCompressed |= (retval == XcmsSuccessWithCompression);
+ }
+
+ /*
+ * Determine where to start on the from_CIEXYZ path.
+ */
+ from_CIEXYZ_start = dest_from_CIEXYZ;
+ tmp = src_from_CIEXYZ;
+ while ((*from_CIEXYZ_start == *tmp) && (*from_CIEXYZ_start != NULL)) {
+ from_CIEXYZ_start++;
+ tmp++;
+ }
+
+ } else {
+ /*
+ * The function in at least one of the Color Spaces are not
+ * complementary, i.e.,
+ * for an i, 0 <= i < n elements
+ * from_CIEXYZ[i] is not the inverse of to_CIEXYZ[i]
+ *
+ * Execute the functions all the way to CIEXYZ
+ */
+ while (*src_to_CIEXYZ) {
+ retval = (*src_to_CIEXYZ++)(ccc, pColors_in_out, nColors,
+ pCompressed);
+ if (retval == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ hasCompressed |= (retval == XcmsSuccessWithCompression);
+ }
+
+ /*
+ * Determine where to start on the from_CIEXYZ path.
+ */
+ from_CIEXYZ_start = dest_from_CIEXYZ;
+ }
+
+ while (*from_CIEXYZ_start) {
+ retval = (*from_CIEXYZ_start++)(ccc, pColors_in_out, nColors,
+ pCompressed);
+ if (retval == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ hasCompressed |= (retval == XcmsSuccessWithCompression);
+ }
+
+ return(hasCompressed ? XcmsSuccessWithCompression : XcmsSuccess);
+}
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsConvertColors - Convert XcmsColor structures
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsConvertColors(
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors,
+ XcmsColorFormat targetFormat,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * Convert XcmsColor structures to another format
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if succeeded without gamut compression,
+ * XcmsSuccessWithCompression if succeeded with gamut
+ * compression.
+ *
+ */
+{
+ XcmsColor clientWhitePt;
+ XcmsColor Color1;
+ XcmsColor *pColors_tmp;
+ int callWhiteAdjustProc = 0;
+ XcmsColorFormat format;
+ Status retval;
+ unsigned char contents_flag = 0x00;
+ unsigned int iColors;
+
+ if (ccc == NULL || pColors_in_out == NULL ||
+ !(ValidDIColorSpaceID(targetFormat) ||
+ ValidDDColorSpaceID(ccc, targetFormat))) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Check formats in color specification array
+ */
+ format = pColors_in_out->format;
+ for (pColors_tmp = pColors_in_out, iColors = nColors; iColors; pColors_tmp++, iColors--) {
+ if (!(ValidDIColorSpaceID(pColors_tmp->format) ||
+ ValidDDColorSpaceID(ccc, pColors_tmp->format))) {
+ return(XcmsFailure);
+ }
+ if (XCMS_DI_ID(pColors_tmp->format)) {
+ contents_flag |= DI_FORMAT;
+ } else {
+ contents_flag |= DD_FORMAT;
+ }
+ if (pColors_tmp->format != format) {
+ contents_flag |= MIX_FORMAT;
+ }
+ }
+
+ /*
+ * Check if we need the Client White Point.
+ */
+ if ((contents_flag & DI_FORMAT) || XCMS_DI_ID(targetFormat)) {
+ /* To proceed, we need to get the Client White Point */
+ memcpy((char *)&clientWhitePt, (char *)&ccc->clientWhitePt,
+ sizeof(XcmsColor));
+ if (clientWhitePt.format == XcmsUndefinedFormat) {
+ /*
+ * Client White Point is undefined, therefore set to the Screen
+ * White Point.
+ * Since Client White Point == Screen White Point, WhiteAdjustProc
+ * is not called.
+ */
+ memcpy((char *)&clientWhitePt,
+ (char *)&ccc->pPerScrnInfo->screenWhitePt,
+ sizeof(XcmsColor));
+ } else if ((ccc->whitePtAdjProc != NULL) && !_XcmsEqualWhitePts(ccc,
+ &clientWhitePt, ScreenWhitePointOfCCC(ccc))) {
+ /*
+ * Client White Point != Screen White Point, and WhiteAdjustProc
+ * is not NULL, therefore, will need to call it when
+ * converting between DI and DD specifications.
+ */
+ callWhiteAdjustProc = 1;
+ }
+ }
+
+ /*
+ * Make copy of array of color specifications
+ */
+ if (nColors > 1) {
+ pColors_tmp = (XcmsColor *) Xmalloc(nColors * sizeof(XcmsColor));
+ } else {
+ pColors_tmp = &Color1;
+ }
+ memcpy((char *)pColors_tmp, (char *)pColors_in_out,
+ nColors * sizeof(XcmsColor));
+
+ /*
+ * zero out pCompressed
+ */
+ if (pCompressed) {
+ bzero((char *)pCompressed, nColors * sizeof(Bool));
+ }
+
+ if (contents_flag == DD_FORMAT || contents_flag == DI_FORMAT) {
+ /*
+ * ENTIRE ARRAY IS IN ONE FORMAT.
+ */
+ if (XCMS_DI_ID(format) && XCMS_DI_ID(targetFormat)) {
+ /*
+ * DI-to-DI only conversion
+ */
+ retval = _XcmsDIConvertColors(ccc, pColors_tmp,
+ &clientWhitePt, nColors, targetFormat);
+ } else if (XCMS_DD_ID(format) && XCMS_DD_ID(targetFormat)) {
+ /*
+ * DD-to-DD only conversion
+ * Since DD->DD there will be no compressed thus we can
+ * pass NULL instead of pCompressed.
+ */
+ retval = _XcmsDDConvertColors(ccc, pColors_tmp, nColors,
+ targetFormat, (Bool *)NULL);
+ } else {
+ /*
+ * Otherwise we have:
+ * 1. Device-Independent to Device-Dependent Conversion
+ * OR
+ * 2. Device-Dependent to Device-Independent Conversion
+ *
+ * We need to go from oldFormat -> CIEXYZ -> targetFormat
+ * adjusting for white points as necessary.
+ */
+
+ if (XCMS_DI_ID(format)) {
+ /*
+ * 1. Device-Independent to Device-Dependent Conversion
+ */
+ if (callWhiteAdjustProc) {
+ /*
+ * White Point Adjustment
+ * Client White Point to Screen White Point
+ */
+ retval = (*ccc->whitePtAdjProc)(ccc, &clientWhitePt,
+ ScreenWhitePointOfCCC(ccc), targetFormat,
+ pColors_tmp, nColors, pCompressed);
+ } else {
+ if (_XcmsDIConvertColors(ccc, pColors_tmp,
+ &clientWhitePt, nColors, XcmsCIEXYZFormat)
+ == XcmsFailure) {
+ goto Failure;
+ }
+ retval = _XcmsDDConvertColors(ccc, pColors_tmp, nColors,
+ targetFormat, pCompressed);
+ }
+ } else {
+ /*
+ * 2. Device-Dependent to Device-Independent Conversion
+ */
+ if (callWhiteAdjustProc) {
+ /*
+ * White Point Adjustment
+ * Screen White Point to Client White Point
+ */
+ retval = (*ccc->whitePtAdjProc)(ccc,
+ ScreenWhitePointOfCCC(ccc), &clientWhitePt,
+ targetFormat, pColors_tmp, nColors, pCompressed);
+ } else {
+ /*
+ * Since DD->CIEXYZ, no compression takes place therefore
+ * we can pass NULL instead of pCompressed.
+ */
+ if (_XcmsDDConvertColors(ccc, pColors_tmp, nColors,
+ XcmsCIEXYZFormat, (Bool *)NULL) == XcmsFailure) {
+ goto Failure;
+ }
+ retval = _XcmsDIConvertColors(ccc, pColors_tmp,
+ &clientWhitePt, nColors, targetFormat);
+ }
+ }
+ }
+ } else {
+ /*
+ * ARRAY HAS MIXED FORMATS.
+ */
+ if ((contents_flag == (DI_FORMAT | MIX_FORMAT)) &&
+ XCMS_DI_ID(targetFormat)) {
+ /*
+ * Convert from DI to DI in batches of contiguous formats
+ *
+ * Because DI->DI, WhiteAdjustProc not called.
+ */
+ retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt,
+ nColors, targetFormat, (unsigned char)DI_FORMAT);
+ } else if ((contents_flag == (DD_FORMAT | MIX_FORMAT)) &&
+ XCMS_DD_ID(targetFormat)) {
+ /*
+ * Convert from DD to DD in batches of contiguous formats
+ *
+ * Because DD->DD, WhiteAdjustProc not called.
+ */
+ retval = ConvertMixedColors(ccc, pColors_tmp,
+ (XcmsColor *)NULL, nColors, targetFormat,
+ (unsigned char)DD_FORMAT);
+ } else if (XCMS_DI_ID(targetFormat)) {
+ /*
+ * We need to convert from DI-to-DI and DD-to-DI, therefore
+ * 1. convert DD specifications to CIEXYZ, then
+ * 2. convert all in batches to the target DI format.
+ *
+ * Note that ConvertMixedColors will call WhiteAdjustProc
+ * as necessary.
+ */
+
+ /*
+ * Convert only DD specifications in batches of contiguous formats
+ * to CIEXYZ
+ *
+ * Since DD->CIEXYZ, ConvertMixedColors will apply WhiteAdjustProc
+ * if required.
+ */
+ retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt,
+ nColors, XcmsCIEXYZFormat, (unsigned char)DD_FORMAT);
+
+ /*
+ * Because at this point we may have a mix of DI formats
+ * (e.g., CIEXYZ, CIELuv) we must convert the specs to the
+ * target DI format in batches of contiguous source formats.
+ */
+ retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt,
+ nColors, targetFormat, (unsigned char)DI_FORMAT);
+ } else {
+ /*
+ * We need to convert from DI-to-DD and DD-to-DD, therefore
+ * 1. convert DI specifications to CIEXYZ, then
+ * 2. convert all to the DD target format.
+ *
+ * This allows white point adjustment and gamut compression
+ * to be applied to all the color specifications in one
+ * swoop if those functions do in fact modify the entire
+ * group of color specifications.
+ */
+
+ /*
+ * Convert in batches to CIEXYZ
+ *
+ * If DD->CIEXYZ, ConvertMixedColors will apply WhiteAdjustProc
+ * if required.
+ */
+ if ((retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt,
+ nColors, XcmsCIEXYZFormat,
+ (unsigned char)(DI_FORMAT | DD_FORMAT))) == XcmsFailure) {
+ goto Failure;
+ }
+
+ /*
+ * Convert all specifications (now in CIEXYZ format) to
+ * the target DD format.
+ * Since CIEXYZ->DD, compression MAY take place therefore
+ * we must pass pCompressed.
+ * Note that WhiteAdjustProc must be used if necessary.
+ */
+ if (callWhiteAdjustProc) {
+ /*
+ * White Point Adjustment
+ * Client White Point to Screen White Point
+ */
+ retval = (*ccc->whitePtAdjProc)(ccc,
+ &clientWhitePt, ScreenWhitePointOfCCC(ccc),
+ targetFormat, pColors_tmp, nColors, pCompressed);
+ } else {
+ retval = _XcmsDDConvertColors(ccc, pColors_tmp, nColors,
+ targetFormat, pCompressed);
+ }
+ }
+ }
+
+ if (retval != XcmsFailure) {
+ memcpy((char *)pColors_in_out, (char *)pColors_tmp,
+ nColors * sizeof(XcmsColor));
+ }
+ if (nColors > 1) {
+ Xfree((char *)pColors_tmp);
+ }
+ return(retval);
+
+Failure:
+ if (nColors > 1) {
+ Xfree((char *)pColors_tmp);
+ }
+ return(XcmsFailure);
+}
+
+
+/*
+ * NAME
+ * XcmsRegFormatOfPrefix
+ *
+ * SYNOPSIS
+ */
+XcmsColorFormat
+_XcmsRegFormatOfPrefix(
+ _Xconst char *prefix)
+/*
+ * DESCRIPTION
+ * Returns a color space ID associated with the specified
+ * X Consortium registered color space prefix.
+ *
+ * RETURNS
+ * The color space ID if found;
+ * otherwise NULL.
+ */
+{
+ XcmsRegColorSpaceEntry *pEntry = _XcmsRegColorSpaces;
+
+ while (pEntry->prefix != NULL) {
+ if (strcmp(prefix, pEntry->prefix) == 0) {
+ return(pEntry->id);
+ }
+ pEntry++;
+ }
+ return(XcmsUndefinedFormat);
+}
diff --git a/libX11/src/xcms/HVC.c b/libX11/src/xcms/HVC.c index 80f1735cf..c5c9823e2 100644 --- a/libX11/src/xcms/HVC.c +++ b/libX11/src/xcms/HVC.c @@ -1,625 +1,625 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. TekColor is a - * trademark of Tektronix, Inc. The term "TekHVC" designates a particular - * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent - * foreign patents pending). Permission is hereby granted to use, copy, - * modify, sell, and otherwise distribute this software and its - * documentation for any purpose and without fee, provided that: - * - * 1. This copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and any modification thereof and in - * supporting documentation; - * 2. Any color-handling application which displays TekHVC color - * cooordinates identifies these as TekHVC color coordinates in any - * interface that displays these coordinates and in any associated - * documentation; - * 3. The term "TekHVC" is always used, and is only used, in association - * with the mathematical derivations of the TekHVC Color Space, - * including those provided in this file and any equivalent pathways and - * mathematical derivations, regardless of digital (e.g., floating point - * or integer) representation. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * TekHVC.c - * - * DESCRIPTION - * This file contains routines that support the TekHVC - * color space to include conversions to and from the CIE - * XYZ space. - * - * DOCUMENTATION - * "TekColor Color Management System, System Implementor's Manual" - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include <X11/Xos.h> -#include <math.h> -#include "Cv.h" - -#include <stdio.h> - -/* - * DEFINES - */ -#define u_BR 0.7127 /* u' Best Red */ -#define v_BR 0.4931 /* v' Best Red */ -#define EPS 0.001 -#define CHROMA_SCALE_FACTOR 7.50725 -#ifndef PI -# ifdef M_PI -# define PI M_PI -# else -# define PI 3.14159265358979323846264338327950 -# endif -#endif -#ifndef degrees -# define degrees(r) ((XcmsFloat)(r) * 180.0 / PI) -#endif /* degrees */ -#ifndef radians -# define radians(d) ((XcmsFloat)(d) * PI / 180.0) -#endif /* radians */ - -/************************************************************************* - * Note: The DBL_EPSILON for ANSI is 1e-5 so my checks need to take - * this into account. If your DBL_EPSILON is different then - * adjust this define. - * - * Also note that EPS is the error factor in the calculations - * This may need to be the same as XMY_DBL_EPSILON in - * some implementations. - **************************************************************************/ -#ifdef DBL_EPSILON -# define XMY_DBL_EPSILON DBL_EPSILON -#else -# define XMY_DBL_EPSILON 0.00001 -#endif - -/* - * FORWARD DECLARATIONS - */ -static int TekHVC_ParseString(register char *spec, XcmsColor *pColor); -static Status XcmsTekHVC_ValidSpec(XcmsColor *pColor); - -/* - * LOCAL VARIABLES - */ - - /* - * NULL terminated list of functions applied to get from TekHVC to CIEXYZ - */ -static XcmsConversionProc Fl_TekHVC_to_CIEXYZ[] = { - XcmsTekHVCToCIEuvY, - XcmsCIEuvYToCIEXYZ, - NULL -}; - - /* - * NULL terminated list of functions applied to get from CIEXYZ to TekHVC - */ -static XcmsConversionProc Fl_CIEXYZ_to_TekHVC[] = { - XcmsCIEXYZToCIEuvY, - XcmsCIEuvYToTekHVC, - NULL -}; - -/* - * GLOBALS - */ - - /* - * TekHVC Color Space - */ -XcmsColorSpace XcmsTekHVCColorSpace = - { - _XcmsTekHVC_prefix, /* prefix */ - XcmsTekHVCFormat, /* id */ - TekHVC_ParseString, /* parseString */ - Fl_TekHVC_to_CIEXYZ, /* to_CIEXYZ */ - Fl_CIEXYZ_to_TekHVC, /* from_CIEXYZ */ - 1 - }; - - - - -/************************************************************************ - * * - * PRIVATE ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * TekHVC_ParseString - * - * SYNOPSIS - */ -static int -TekHVC_ParseString( - register char *spec, - XcmsColor *pColor) -/* - * DESCRIPTION - * This routines takes a string and attempts to convert - * it into a XcmsColor structure with XcmsTekHVCFormat. - * The assumed TekHVC string syntax is: - * TekHVC:<H>/<V>/<C> - * Where H, V, and C are in string input format for floats - * consisting of: - * a. an optional sign - * b. a string of numbers possibly containing a decimal point, - * c. an optional exponent field containing an 'E' or 'e' - * followed by a possibly signed integer string. - * - * RETURNS - * XcmsFailure if invalid; - * XcmsSuccess if valid. - */ -{ - int n; - char *pchar; - - if ((pchar = strchr(spec, ':')) == NULL) { - return(XcmsFailure); - } - n = (int)(pchar - spec); - - /* - * Check for proper prefix. - */ - if (strncmp(spec, _XcmsTekHVC_prefix, n) != 0) { - return(XcmsFailure); - } - - /* - * Attempt to parse the value portion. - */ - if (sscanf(spec + n + 1, "%lf/%lf/%lf", - &pColor->spec.TekHVC.H, - &pColor->spec.TekHVC.V, - &pColor->spec.TekHVC.C) != 3) { - char *s; /* Maybe failed due to locale */ - int f; - if ((s = strdup(spec))) { - for (f = 0; s[f]; ++f) - if (s[f] == '.') - s[f] = ','; - else if (s[f] == ',') - s[f] = '.'; - if (sscanf(s + n + 1, "%lf/%lf/%lf", - &pColor->spec.TekHVC.H, - &pColor->spec.TekHVC.V, - &pColor->spec.TekHVC.C) != 3) { - free(s); - return(XcmsFailure); - } - free(s); - } else - return(XcmsFailure); - } - pColor->format = XcmsTekHVCFormat; - pColor->pixel = 0; - return(XcmsTekHVC_ValidSpec(pColor)); -} - - -/* - * NAME - * ThetaOffset -- compute thetaOffset - * - * SYNOPSIS - */ -static int -ThetaOffset( - XcmsColor *pWhitePt, - XcmsFloat *pThetaOffset) -/* - * DESCRIPTION - * This routine computes the theta offset of a given - * white point, i.e. XcmsColor. It is used in both this - * conversion and the printer conversions. - * - * RETURNS - * 0 if failed. - * 1 if succeeded with no modifications. - * - * ASSUMPTIONS - * Assumes: - * pWhitePt != NULL - * pWhitePt->format == XcmsCIEuvYFormat - * - */ -{ - double div, slopeuv; - - if (pWhitePt == NULL || pWhitePt->format != XcmsCIEuvYFormat) { - return(0); - } - - if ((div = u_BR - pWhitePt->spec.CIEuvY.u_prime) == 0.0) { - return(0); - } - slopeuv = (v_BR - pWhitePt->spec.CIEuvY.v_prime) / div; - *pThetaOffset = degrees(XCMS_ATAN(slopeuv)); - return(1); -} - - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsTekHVC_ValidSpec() - * - * SYNOPSIS - */ -static int -XcmsTekHVC_ValidSpec( - XcmsColor *pColor) -/* - * DESCRIPTION - * Checks if values in the color specification are valid. - * Also brings hue into the range 0.0 <= Hue < 360.0 - * - * RETURNS - * 0 if not valid. - * 1 if valid. - * - */ -{ - if (pColor->format != XcmsTekHVCFormat) { - return(XcmsFailure); - } - if (pColor->spec.TekHVC.V < (0.0 - XMY_DBL_EPSILON) - || pColor->spec.TekHVC.V > (100.0 + XMY_DBL_EPSILON) - || (pColor->spec.TekHVC.C < 0.0 - XMY_DBL_EPSILON)) { - return(XcmsFailure); - } - - if (pColor->spec.TekHVC.V < 0.0) { - pColor->spec.TekHVC.V = 0.0 + XMY_DBL_EPSILON; - } else if (pColor->spec.TekHVC.V > 100.0) { - pColor->spec.TekHVC.V = 100.0 - XMY_DBL_EPSILON; - } - - if (pColor->spec.TekHVC.C < 0.0) { - pColor->spec.TekHVC.C = 0.0 - XMY_DBL_EPSILON; - } - - while (pColor->spec.TekHVC.H < 0.0) { - pColor->spec.TekHVC.H += 360.0; - } - while (pColor->spec.TekHVC.H >= 360.0) { - pColor->spec.TekHVC.H -= 360.0; - } - return(XcmsSuccess); -} - -/* - * NAME - * XcmsTekHVCToCIEuvY - convert TekHVC to CIEuvY - * - * SYNOPSIS - */ -Status -XcmsTekHVCToCIEuvY( - XcmsCCC ccc, - XcmsColor *pHVC_WhitePt, - XcmsColor *pColors_in_out, - unsigned int nColors) -/* - * DESCRIPTION - * Transforms an array of TekHVC color specifications, given - * their associated white point, to CIECIEuvY.color - * specifications. - * - * RETURNS - * XcmsFailure if failed, XcmsSuccess otherwise. - * - */ -{ - XcmsFloat thetaOffset; - XcmsColor *pColor = pColors_in_out; - XcmsColor whitePt; - XcmsCIEuvY uvY_return; - XcmsFloat tempHue, u, v; - XcmsFloat tmpVal; - register int i; - - /* - * Check arguments - */ - if (pHVC_WhitePt == NULL || pColors_in_out == NULL) { - return(XcmsFailure); - } - - /* - * Make sure white point is in CIEuvY form - */ - if (pHVC_WhitePt->format != XcmsCIEuvYFormat) { - /* Make copy of the white point because we're going to modify it */ - memcpy((char *)&whitePt, (char *)pHVC_WhitePt, sizeof(XcmsColor)); - if (!_XcmsDIConvertColors(ccc, &whitePt, (XcmsColor *)NULL, 1, - XcmsCIEuvYFormat)) { - return(XcmsFailure); - } - pHVC_WhitePt = &whitePt; - } - /* Make sure it is a white point, i.e., Y == 1.0 */ - if (pHVC_WhitePt->spec.CIEuvY.Y != 1.0) { - return(XcmsFailure); - } - - /* Get the thetaOffset */ - if (!ThetaOffset(pHVC_WhitePt, &thetaOffset)) { - return(XcmsFailure); - } - - /* - * Now convert each XcmsColor structure to CIEXYZ form - */ - for (i = 0; i < nColors; i++, pColor++) { - - /* Make sure original format is TekHVC and is valid */ - if (!XcmsTekHVC_ValidSpec(pColor)) { - return(XcmsFailure); - } - - if (pColor->spec.TekHVC.V == 0.0 || pColor->spec.TekHVC.V == 100.0) { - if (pColor->spec.TekHVC.V == 100.0) { - uvY_return.Y = 1.0; - } else { /* pColor->spec.TekHVC.V == 0.0 */ - uvY_return.Y = 0.0; - } - uvY_return.u_prime = pHVC_WhitePt->spec.CIEuvY.u_prime; - uvY_return.v_prime = pHVC_WhitePt->spec.CIEuvY.v_prime; - } else { - - /* Find the hue based on the white point offset */ - tempHue = pColor->spec.TekHVC.H + thetaOffset; - - while (tempHue < 0.0) { - tempHue += 360.0; - } - while (tempHue >= 360.0) { - tempHue -= 360.0; - } - - tempHue = radians(tempHue); - - /* Calculate u'v' for the obtained hue */ - u = (XcmsFloat) ((XCMS_COS(tempHue) * pColor->spec.TekHVC.C) / - (pColor->spec.TekHVC.V * (double)CHROMA_SCALE_FACTOR)); - v = (XcmsFloat) ((XCMS_SIN(tempHue) * pColor->spec.TekHVC.C) / - (pColor->spec.TekHVC.V * (double)CHROMA_SCALE_FACTOR)); - - /* Based on the white point get the offset from best red */ - uvY_return.u_prime = u + pHVC_WhitePt->spec.CIEuvY.u_prime; - uvY_return.v_prime = v + pHVC_WhitePt->spec.CIEuvY.v_prime; - - /* Calculate the Y value based on the L* = V. */ - if (pColor->spec.TekHVC.V < 7.99953624) { - uvY_return.Y = pColor->spec.TekHVC.V / 903.29; - } else { - tmpVal = (pColor->spec.TekHVC.V + 16.0) / 116.0; - uvY_return.Y = tmpVal * tmpVal * tmpVal; /* tmpVal ** 3 */ - } - } - - /* Copy result to pColor */ - memcpy((char *)&pColor->spec, (char *)&uvY_return, sizeof(XcmsCIEuvY)); - - /* Identify that the format is now CIEuvY */ - pColor->format = XcmsCIEuvYFormat; - } - return(XcmsSuccess); -} - - -/* - * NAME - * XcmsCIEuvYToTekHVC - convert CIEuvY to TekHVC - * - * SYNOPSIS - */ -Status -XcmsCIEuvYToTekHVC( - XcmsCCC ccc, - XcmsColor *pHVC_WhitePt, - XcmsColor *pColors_in_out, - unsigned int nColors) -/* - * DESCRIPTION - * Transforms an array of CIECIEuvY.color specifications, given - * their assiciated white point, to TekHVC specifications. - * - * RETURNS - * XcmsFailure if failed, XcmsSuccess otherwise. - * - */ -{ - XcmsFloat theta, L2, u, v, nThetaLow, nThetaHigh; - XcmsFloat thetaOffset; - XcmsColor *pColor = pColors_in_out; - XcmsColor whitePt; - XcmsTekHVC HVC_return; - register int i; - - /* - * Check arguments - */ - if (pHVC_WhitePt == NULL || pColors_in_out == NULL) { - return(XcmsFailure); - } - - /* - * Make sure white point is in CIEuvY form - */ - if (pHVC_WhitePt->format != XcmsCIEuvYFormat) { - /* Make copy of the white point because we're going to modify it */ - memcpy((char *)&whitePt, (char *)pHVC_WhitePt, sizeof(XcmsColor)); - if (!_XcmsDIConvertColors(ccc, &whitePt, (XcmsColor *)NULL, 1, - XcmsCIEuvYFormat)) { - return(XcmsFailure); - } - pHVC_WhitePt = &whitePt; - } - /* Make sure it is a white point, i.e., Y == 1.0 */ - if (pHVC_WhitePt->spec.CIEuvY.Y != 1.0) { - return(XcmsFailure); - } - if (!ThetaOffset(pHVC_WhitePt, &thetaOffset)) { - return(XcmsFailure); - } - - /* - * Now convert each XcmsColor structure to CIEXYZ form - */ - for (i = 0; i < nColors; i++, pColor++) { - if (!_XcmsCIEuvY_ValidSpec(pColor)) { - return(XcmsFailure); - } - - /* Use the white point offset to determine HVC */ - u = pColor->spec.CIEuvY.u_prime - pHVC_WhitePt->spec.CIEuvY.u_prime; - v = pColor->spec.CIEuvY.v_prime - pHVC_WhitePt->spec.CIEuvY.v_prime; - - /* Calculate the offset */ - if (u == 0.0) { - theta = 0.0; - } else { - theta = v / u; - theta = (XcmsFloat) XCMS_ATAN((double)theta); - theta = degrees(theta); - } - - nThetaLow = 0.0; - nThetaHigh = 360.0; - if (u > 0.0 && v > 0.0) { - nThetaLow = 0.0; - nThetaHigh = 90.0; - } else if (u < 0.0 && v > 0.0) { - nThetaLow = 90.0; - nThetaHigh = 180.0; - } else if (u < 0.0 && v < 0.0) { - nThetaLow = 180.0; - nThetaHigh = 270.0; - } else if (u > 0.0 && v < 0.0) { - nThetaLow = 270.0; - nThetaHigh = 360.0; - } - while (theta < nThetaLow) { - theta += 90.0; - } - while (theta >= nThetaHigh) { - theta -= 90.0; - } - - /* calculate the L value from the given Y */ - L2 = (pColor->spec.CIEuvY.Y < 0.008856) - ? - (pColor->spec.CIEuvY.Y * 903.29) - : - ((XcmsFloat)(XCMS_CUBEROOT(pColor->spec.CIEuvY.Y) * 116.0) - 16.0); - HVC_return.C = L2 * CHROMA_SCALE_FACTOR * XCMS_SQRT((double) ((u * u) + (v * v))); - if (HVC_return.C < 0.0) { - theta = 0.0; - } - HVC_return.V = L2; - HVC_return.H = theta - thetaOffset; - - /* - * If this is within the error margin let some other routine later - * in the chain worry about the slop in the calculations. - */ - while (HVC_return.H < -EPS) { - HVC_return.H += 360.0; - } - while (HVC_return.H >= 360.0 + EPS) { - HVC_return.H -= 360.0; - } - - /* Copy result to pColor */ - memcpy((char *)&pColor->spec, (char *)&HVC_return, sizeof(XcmsTekHVC)); - - /* Identify that the format is now CIEuvY */ - pColor->format = XcmsTekHVCFormat; - } - return(XcmsSuccess); -} - - -/* - * NAME - * _XcmsTekHVC_CheckModify - * - * SYNOPSIS - */ -int -_XcmsTekHVC_CheckModify( - XcmsColor *pColor) -/* - * DESCRIPTION - * Checks if values in the color specification are valid. - * If they are not it modifies the values. - * Also brings hue into the range 0.0 <= Hue < 360.0 - * - * RETURNS - * 0 if not valid. - * 1 if valid. - * - */ -{ - int n; - - /* For now only use the TekHVC numbers as inputs */ - if (pColor->format != XcmsTekHVCFormat) { - return(0); - } - - if (pColor->spec.TekHVC.V < 0.0) { - pColor->spec.TekHVC.V = 0.0 + XMY_DBL_EPSILON; - } else if (pColor->spec.TekHVC.V > 100.0) { - pColor->spec.TekHVC.V = 100.0 - XMY_DBL_EPSILON; - } - - if (pColor->spec.TekHVC.C < 0.0) { - pColor->spec.TekHVC.C = 0.0 - XMY_DBL_EPSILON; - } - - if (pColor->spec.TekHVC.H < 0.0) { - n = -pColor->spec.TekHVC.H / 360.0; - pColor->spec.TekHVC.H += (n + 1) * 360.0; - if (pColor->spec.TekHVC.H >= 360.0) - pColor->spec.TekHVC.H -= 360.0; - } else if (pColor->spec.TekHVC.H >= 360.0) { - n = pColor->spec.TekHVC.H / 360.0; - pColor->spec.TekHVC.H -= n * 360.0; - } - return(1); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. TekColor is a
+ * trademark of Tektronix, Inc. The term "TekHVC" designates a particular
+ * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent
+ * foreign patents pending). Permission is hereby granted to use, copy,
+ * modify, sell, and otherwise distribute this software and its
+ * documentation for any purpose and without fee, provided that:
+ *
+ * 1. This copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and any modification thereof and in
+ * supporting documentation;
+ * 2. Any color-handling application which displays TekHVC color
+ * cooordinates identifies these as TekHVC color coordinates in any
+ * interface that displays these coordinates and in any associated
+ * documentation;
+ * 3. The term "TekHVC" is always used, and is only used, in association
+ * with the mathematical derivations of the TekHVC Color Space,
+ * including those provided in this file and any equivalent pathways and
+ * mathematical derivations, regardless of digital (e.g., floating point
+ * or integer) representation.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * TekHVC.c
+ *
+ * DESCRIPTION
+ * This file contains routines that support the TekHVC
+ * color space to include conversions to and from the CIE
+ * XYZ space.
+ *
+ * DOCUMENTATION
+ * "TekColor Color Management System, System Implementor's Manual"
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include <X11/Xos.h>
+#include <math.h>
+#include "Cv.h"
+
+#include <stdio.h>
+
+/*
+ * DEFINES
+ */
+#define u_BR 0.7127 /* u' Best Red */
+#define v_BR 0.4931 /* v' Best Red */
+#define EPS 0.001
+#define CHROMA_SCALE_FACTOR 7.50725
+#ifndef PI
+# ifdef M_PI
+# define PI M_PI
+# else
+# define PI 3.14159265358979323846264338327950
+# endif
+#endif
+#ifndef degrees
+# define degrees(r) ((XcmsFloat)(r) * 180.0 / PI)
+#endif /* degrees */
+#ifndef radians
+# define radians(d) ((XcmsFloat)(d) * PI / 180.0)
+#endif /* radians */
+
+/*************************************************************************
+ * Note: The DBL_EPSILON for ANSI is 1e-5 so my checks need to take
+ * this into account. If your DBL_EPSILON is different then
+ * adjust this define.
+ *
+ * Also note that EPS is the error factor in the calculations
+ * This may need to be the same as XMY_DBL_EPSILON in
+ * some implementations.
+ **************************************************************************/
+#ifdef DBL_EPSILON
+# define XMY_DBL_EPSILON DBL_EPSILON
+#else
+# define XMY_DBL_EPSILON 0.00001
+#endif
+
+/*
+ * FORWARD DECLARATIONS
+ */
+static int TekHVC_ParseString(register char *spec, XcmsColor *pColor);
+static Status XcmsTekHVC_ValidSpec(XcmsColor *pColor);
+
+/*
+ * LOCAL VARIABLES
+ */
+
+ /*
+ * NULL terminated list of functions applied to get from TekHVC to CIEXYZ
+ */
+static XcmsConversionProc Fl_TekHVC_to_CIEXYZ[] = {
+ XcmsTekHVCToCIEuvY,
+ XcmsCIEuvYToCIEXYZ,
+ NULL
+};
+
+ /*
+ * NULL terminated list of functions applied to get from CIEXYZ to TekHVC
+ */
+static XcmsConversionProc Fl_CIEXYZ_to_TekHVC[] = {
+ XcmsCIEXYZToCIEuvY,
+ XcmsCIEuvYToTekHVC,
+ NULL
+};
+
+/*
+ * GLOBALS
+ */
+
+ /*
+ * TekHVC Color Space
+ */
+XcmsColorSpace XcmsTekHVCColorSpace =
+ {
+ _XcmsTekHVC_prefix, /* prefix */
+ XcmsTekHVCFormat, /* id */
+ TekHVC_ParseString, /* parseString */
+ Fl_TekHVC_to_CIEXYZ, /* to_CIEXYZ */
+ Fl_CIEXYZ_to_TekHVC, /* from_CIEXYZ */
+ 1
+ };
+
+
+
+
+/************************************************************************
+ * *
+ * PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * TekHVC_ParseString
+ *
+ * SYNOPSIS
+ */
+static int
+TekHVC_ParseString(
+ register char *spec,
+ XcmsColor *pColor)
+/*
+ * DESCRIPTION
+ * This routines takes a string and attempts to convert
+ * it into a XcmsColor structure with XcmsTekHVCFormat.
+ * The assumed TekHVC string syntax is:
+ * TekHVC:<H>/<V>/<C>
+ * Where H, V, and C are in string input format for floats
+ * consisting of:
+ * a. an optional sign
+ * b. a string of numbers possibly containing a decimal point,
+ * c. an optional exponent field containing an 'E' or 'e'
+ * followed by a possibly signed integer string.
+ *
+ * RETURNS
+ * XcmsFailure if invalid;
+ * XcmsSuccess if valid.
+ */
+{
+ int n;
+ char *pchar;
+
+ if ((pchar = strchr(spec, ':')) == NULL) {
+ return(XcmsFailure);
+ }
+ n = (int)(pchar - spec);
+
+ /*
+ * Check for proper prefix.
+ */
+ if (strncmp(spec, _XcmsTekHVC_prefix, n) != 0) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Attempt to parse the value portion.
+ */
+ if (sscanf(spec + n + 1, "%lf/%lf/%lf",
+ &pColor->spec.TekHVC.H,
+ &pColor->spec.TekHVC.V,
+ &pColor->spec.TekHVC.C) != 3) {
+ char *s; /* Maybe failed due to locale */
+ int f;
+ if ((s = strdup(spec))) {
+ for (f = 0; s[f]; ++f)
+ if (s[f] == '.')
+ s[f] = ',';
+ else if (s[f] == ',')
+ s[f] = '.';
+ if (sscanf(s + n + 1, "%lf/%lf/%lf",
+ &pColor->spec.TekHVC.H,
+ &pColor->spec.TekHVC.V,
+ &pColor->spec.TekHVC.C) != 3) {
+ free(s);
+ return(XcmsFailure);
+ }
+ free(s);
+ } else
+ return(XcmsFailure);
+ }
+ pColor->format = XcmsTekHVCFormat;
+ pColor->pixel = 0;
+ return(XcmsTekHVC_ValidSpec(pColor));
+}
+
+
+/*
+ * NAME
+ * ThetaOffset -- compute thetaOffset
+ *
+ * SYNOPSIS
+ */
+static int
+ThetaOffset(
+ XcmsColor *pWhitePt,
+ XcmsFloat *pThetaOffset)
+/*
+ * DESCRIPTION
+ * This routine computes the theta offset of a given
+ * white point, i.e. XcmsColor. It is used in both this
+ * conversion and the printer conversions.
+ *
+ * RETURNS
+ * 0 if failed.
+ * 1 if succeeded with no modifications.
+ *
+ * ASSUMPTIONS
+ * Assumes:
+ * pWhitePt != NULL
+ * pWhitePt->format == XcmsCIEuvYFormat
+ *
+ */
+{
+ double div, slopeuv;
+
+ if (pWhitePt == NULL || pWhitePt->format != XcmsCIEuvYFormat) {
+ return(0);
+ }
+
+ if ((div = u_BR - pWhitePt->spec.CIEuvY.u_prime) == 0.0) {
+ return(0);
+ }
+ slopeuv = (v_BR - pWhitePt->spec.CIEuvY.v_prime) / div;
+ *pThetaOffset = degrees(XCMS_ATAN(slopeuv));
+ return(1);
+}
+
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsTekHVC_ValidSpec()
+ *
+ * SYNOPSIS
+ */
+static int
+XcmsTekHVC_ValidSpec(
+ XcmsColor *pColor)
+/*
+ * DESCRIPTION
+ * Checks if values in the color specification are valid.
+ * Also brings hue into the range 0.0 <= Hue < 360.0
+ *
+ * RETURNS
+ * 0 if not valid.
+ * 1 if valid.
+ *
+ */
+{
+ if (pColor->format != XcmsTekHVCFormat) {
+ return(XcmsFailure);
+ }
+ if (pColor->spec.TekHVC.V < (0.0 - XMY_DBL_EPSILON)
+ || pColor->spec.TekHVC.V > (100.0 + XMY_DBL_EPSILON)
+ || (pColor->spec.TekHVC.C < 0.0 - XMY_DBL_EPSILON)) {
+ return(XcmsFailure);
+ }
+
+ if (pColor->spec.TekHVC.V < 0.0) {
+ pColor->spec.TekHVC.V = 0.0 + XMY_DBL_EPSILON;
+ } else if (pColor->spec.TekHVC.V > 100.0) {
+ pColor->spec.TekHVC.V = 100.0 - XMY_DBL_EPSILON;
+ }
+
+ if (pColor->spec.TekHVC.C < 0.0) {
+ pColor->spec.TekHVC.C = 0.0 - XMY_DBL_EPSILON;
+ }
+
+ while (pColor->spec.TekHVC.H < 0.0) {
+ pColor->spec.TekHVC.H += 360.0;
+ }
+ while (pColor->spec.TekHVC.H >= 360.0) {
+ pColor->spec.TekHVC.H -= 360.0;
+ }
+ return(XcmsSuccess);
+}
+
+/*
+ * NAME
+ * XcmsTekHVCToCIEuvY - convert TekHVC to CIEuvY
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsTekHVCToCIEuvY(
+ XcmsCCC ccc,
+ XcmsColor *pHVC_WhitePt,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors)
+/*
+ * DESCRIPTION
+ * Transforms an array of TekHVC color specifications, given
+ * their associated white point, to CIECIEuvY.color
+ * specifications.
+ *
+ * RETURNS
+ * XcmsFailure if failed, XcmsSuccess otherwise.
+ *
+ */
+{
+ XcmsFloat thetaOffset;
+ XcmsColor *pColor = pColors_in_out;
+ XcmsColor whitePt;
+ XcmsCIEuvY uvY_return;
+ XcmsFloat tempHue, u, v;
+ XcmsFloat tmpVal;
+ register int i;
+
+ /*
+ * Check arguments
+ */
+ if (pHVC_WhitePt == NULL || pColors_in_out == NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Make sure white point is in CIEuvY form
+ */
+ if (pHVC_WhitePt->format != XcmsCIEuvYFormat) {
+ /* Make copy of the white point because we're going to modify it */
+ memcpy((char *)&whitePt, (char *)pHVC_WhitePt, sizeof(XcmsColor));
+ if (!_XcmsDIConvertColors(ccc, &whitePt, (XcmsColor *)NULL, 1,
+ XcmsCIEuvYFormat)) {
+ return(XcmsFailure);
+ }
+ pHVC_WhitePt = &whitePt;
+ }
+ /* Make sure it is a white point, i.e., Y == 1.0 */
+ if (pHVC_WhitePt->spec.CIEuvY.Y != 1.0) {
+ return(XcmsFailure);
+ }
+
+ /* Get the thetaOffset */
+ if (!ThetaOffset(pHVC_WhitePt, &thetaOffset)) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Now convert each XcmsColor structure to CIEXYZ form
+ */
+ for (i = 0; i < nColors; i++, pColor++) {
+
+ /* Make sure original format is TekHVC and is valid */
+ if (!XcmsTekHVC_ValidSpec(pColor)) {
+ return(XcmsFailure);
+ }
+
+ if (pColor->spec.TekHVC.V == 0.0 || pColor->spec.TekHVC.V == 100.0) {
+ if (pColor->spec.TekHVC.V == 100.0) {
+ uvY_return.Y = 1.0;
+ } else { /* pColor->spec.TekHVC.V == 0.0 */
+ uvY_return.Y = 0.0;
+ }
+ uvY_return.u_prime = pHVC_WhitePt->spec.CIEuvY.u_prime;
+ uvY_return.v_prime = pHVC_WhitePt->spec.CIEuvY.v_prime;
+ } else {
+
+ /* Find the hue based on the white point offset */
+ tempHue = pColor->spec.TekHVC.H + thetaOffset;
+
+ while (tempHue < 0.0) {
+ tempHue += 360.0;
+ }
+ while (tempHue >= 360.0) {
+ tempHue -= 360.0;
+ }
+
+ tempHue = radians(tempHue);
+
+ /* Calculate u'v' for the obtained hue */
+ u = (XcmsFloat) ((XCMS_COS(tempHue) * pColor->spec.TekHVC.C) /
+ (pColor->spec.TekHVC.V * (double)CHROMA_SCALE_FACTOR));
+ v = (XcmsFloat) ((XCMS_SIN(tempHue) * pColor->spec.TekHVC.C) /
+ (pColor->spec.TekHVC.V * (double)CHROMA_SCALE_FACTOR));
+
+ /* Based on the white point get the offset from best red */
+ uvY_return.u_prime = u + pHVC_WhitePt->spec.CIEuvY.u_prime;
+ uvY_return.v_prime = v + pHVC_WhitePt->spec.CIEuvY.v_prime;
+
+ /* Calculate the Y value based on the L* = V. */
+ if (pColor->spec.TekHVC.V < 7.99953624) {
+ uvY_return.Y = pColor->spec.TekHVC.V / 903.29;
+ } else {
+ tmpVal = (pColor->spec.TekHVC.V + 16.0) / 116.0;
+ uvY_return.Y = tmpVal * tmpVal * tmpVal; /* tmpVal ** 3 */
+ }
+ }
+
+ /* Copy result to pColor */
+ memcpy((char *)&pColor->spec, (char *)&uvY_return, sizeof(XcmsCIEuvY));
+
+ /* Identify that the format is now CIEuvY */
+ pColor->format = XcmsCIEuvYFormat;
+ }
+ return(XcmsSuccess);
+}
+
+
+/*
+ * NAME
+ * XcmsCIEuvYToTekHVC - convert CIEuvY to TekHVC
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIEuvYToTekHVC(
+ XcmsCCC ccc,
+ XcmsColor *pHVC_WhitePt,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors)
+/*
+ * DESCRIPTION
+ * Transforms an array of CIECIEuvY.color specifications, given
+ * their assiciated white point, to TekHVC specifications.
+ *
+ * RETURNS
+ * XcmsFailure if failed, XcmsSuccess otherwise.
+ *
+ */
+{
+ XcmsFloat theta, L2, u, v, nThetaLow, nThetaHigh;
+ XcmsFloat thetaOffset;
+ XcmsColor *pColor = pColors_in_out;
+ XcmsColor whitePt;
+ XcmsTekHVC HVC_return;
+ register int i;
+
+ /*
+ * Check arguments
+ */
+ if (pHVC_WhitePt == NULL || pColors_in_out == NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Make sure white point is in CIEuvY form
+ */
+ if (pHVC_WhitePt->format != XcmsCIEuvYFormat) {
+ /* Make copy of the white point because we're going to modify it */
+ memcpy((char *)&whitePt, (char *)pHVC_WhitePt, sizeof(XcmsColor));
+ if (!_XcmsDIConvertColors(ccc, &whitePt, (XcmsColor *)NULL, 1,
+ XcmsCIEuvYFormat)) {
+ return(XcmsFailure);
+ }
+ pHVC_WhitePt = &whitePt;
+ }
+ /* Make sure it is a white point, i.e., Y == 1.0 */
+ if (pHVC_WhitePt->spec.CIEuvY.Y != 1.0) {
+ return(XcmsFailure);
+ }
+ if (!ThetaOffset(pHVC_WhitePt, &thetaOffset)) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Now convert each XcmsColor structure to CIEXYZ form
+ */
+ for (i = 0; i < nColors; i++, pColor++) {
+ if (!_XcmsCIEuvY_ValidSpec(pColor)) {
+ return(XcmsFailure);
+ }
+
+ /* Use the white point offset to determine HVC */
+ u = pColor->spec.CIEuvY.u_prime - pHVC_WhitePt->spec.CIEuvY.u_prime;
+ v = pColor->spec.CIEuvY.v_prime - pHVC_WhitePt->spec.CIEuvY.v_prime;
+
+ /* Calculate the offset */
+ if (u == 0.0) {
+ theta = 0.0;
+ } else {
+ theta = v / u;
+ theta = (XcmsFloat) XCMS_ATAN((double)theta);
+ theta = degrees(theta);
+ }
+
+ nThetaLow = 0.0;
+ nThetaHigh = 360.0;
+ if (u > 0.0 && v > 0.0) {
+ nThetaLow = 0.0;
+ nThetaHigh = 90.0;
+ } else if (u < 0.0 && v > 0.0) {
+ nThetaLow = 90.0;
+ nThetaHigh = 180.0;
+ } else if (u < 0.0 && v < 0.0) {
+ nThetaLow = 180.0;
+ nThetaHigh = 270.0;
+ } else if (u > 0.0 && v < 0.0) {
+ nThetaLow = 270.0;
+ nThetaHigh = 360.0;
+ }
+ while (theta < nThetaLow) {
+ theta += 90.0;
+ }
+ while (theta >= nThetaHigh) {
+ theta -= 90.0;
+ }
+
+ /* calculate the L value from the given Y */
+ L2 = (pColor->spec.CIEuvY.Y < 0.008856)
+ ?
+ (pColor->spec.CIEuvY.Y * 903.29)
+ :
+ ((XcmsFloat)(XCMS_CUBEROOT(pColor->spec.CIEuvY.Y) * 116.0) - 16.0);
+ HVC_return.C = L2 * CHROMA_SCALE_FACTOR * XCMS_SQRT((double) ((u * u) + (v * v)));
+ if (HVC_return.C < 0.0) {
+ theta = 0.0;
+ }
+ HVC_return.V = L2;
+ HVC_return.H = theta - thetaOffset;
+
+ /*
+ * If this is within the error margin let some other routine later
+ * in the chain worry about the slop in the calculations.
+ */
+ while (HVC_return.H < -EPS) {
+ HVC_return.H += 360.0;
+ }
+ while (HVC_return.H >= 360.0 + EPS) {
+ HVC_return.H -= 360.0;
+ }
+
+ /* Copy result to pColor */
+ memcpy((char *)&pColor->spec, (char *)&HVC_return, sizeof(XcmsTekHVC));
+
+ /* Identify that the format is now CIEuvY */
+ pColor->format = XcmsTekHVCFormat;
+ }
+ return(XcmsSuccess);
+}
+
+
+/*
+ * NAME
+ * _XcmsTekHVC_CheckModify
+ *
+ * SYNOPSIS
+ */
+int
+_XcmsTekHVC_CheckModify(
+ XcmsColor *pColor)
+/*
+ * DESCRIPTION
+ * Checks if values in the color specification are valid.
+ * If they are not it modifies the values.
+ * Also brings hue into the range 0.0 <= Hue < 360.0
+ *
+ * RETURNS
+ * 0 if not valid.
+ * 1 if valid.
+ *
+ */
+{
+ int n;
+
+ /* For now only use the TekHVC numbers as inputs */
+ if (pColor->format != XcmsTekHVCFormat) {
+ return(0);
+ }
+
+ if (pColor->spec.TekHVC.V < 0.0) {
+ pColor->spec.TekHVC.V = 0.0 + XMY_DBL_EPSILON;
+ } else if (pColor->spec.TekHVC.V > 100.0) {
+ pColor->spec.TekHVC.V = 100.0 - XMY_DBL_EPSILON;
+ }
+
+ if (pColor->spec.TekHVC.C < 0.0) {
+ pColor->spec.TekHVC.C = 0.0 - XMY_DBL_EPSILON;
+ }
+
+ if (pColor->spec.TekHVC.H < 0.0) {
+ n = -pColor->spec.TekHVC.H / 360.0;
+ pColor->spec.TekHVC.H += (n + 1) * 360.0;
+ if (pColor->spec.TekHVC.H >= 360.0)
+ pColor->spec.TekHVC.H -= 360.0;
+ } else if (pColor->spec.TekHVC.H >= 360.0) {
+ n = pColor->spec.TekHVC.H / 360.0;
+ pColor->spec.TekHVC.H -= n * 360.0;
+ }
+ return(1);
+}
diff --git a/libX11/src/xcms/HVCGcC.c b/libX11/src/xcms/HVCGcC.c index 6d52eac63..33743dc34 100644 --- a/libX11/src/xcms/HVCGcC.c +++ b/libX11/src/xcms/HVCGcC.c @@ -1,149 +1,149 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. TekColor is a - * trademark of Tektronix, Inc. The term "TekHVC" designates a particular - * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent - * foreign patents pending). Permission is hereby granted to use, copy, - * modify, sell, and otherwise distribute this software and its - * documentation for any purpose and without fee, provided that: - * - * 1. This copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and any modification thereof and in - * supporting documentation; - * 2. Any color-handling application which displays TekHVC color - * cooordinates identifies these as TekHVC color coordinates in any - * interface that displays these coordinates and in any associated - * documentation; - * 3. The term "TekHVC" is always used, and is only used, in association - * with the mathematical derivations of the TekHVC Color Space, - * including those provided in this file and any equivalent pathways and - * mathematical derivations, regardless of digital (e.g., floating point - * or integer) representation. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * TekHVCGcC.c - * - * DESCRIPTION - * Source for XcmsTekHVCClipC() gamut compression routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsTekHVCClipC - Reduce the chroma for a hue and value - * - * SYNOPSIS - */ -/* ARGSUSED */ -Status -XcmsTekHVCClipC ( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - unsigned int nColors, - unsigned int i, - Bool *pCompressed) -/* - * DESCRIPTION - * Reduce the Chroma for a specific hue and value to - * to bring the given color into the gamut of the - * specified device. As required of gamut compression - * functions in Xcms, this routine returns pColor_in_out - * in XcmsCIEXYZFormat on successful completion. - * - * Since this routine works with the value within - * pColor_in_out intermediate results may be returned - * even though it may be invalid. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - Status retval; - XcmsColor *pColor; - - /* - * Color specification passed as input can be assumed to: - * 1. Be in XcmsCIEXYZFormat - * 2. Already be white point adjusted for the Screen White Point. - * This means that the white point now associated with this - * color spec is the Screen White Point (even if the - * ccc->clientWhitePt differs). - */ - - /* - * Insure TekHVC installed - */ - if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) { - return(XcmsFailure); - } - - pColor = pColors_in_out + i; - - if (ccc->visual->class < StaticColor && - FunctionSetOfCCC(ccc) != (XPointer) &XcmsLinearRGBFunctionSet) { - /* - * GRAY ! - */ - _XcmsDIConvertColors(ccc, pColor, &ccc->pPerScrnInfo->screenWhitePt, - 1, XcmsTekHVCFormat); - pColor->spec.TekHVC.H = pColor->spec.TekHVC.C = 0.0; - _XcmsDIConvertColors(ccc, pColor, &ccc->pPerScrnInfo->screenWhitePt, - 1, XcmsCIEXYZFormat); - if (pCompressed) { - *(pCompressed + i) = True; - } - return(XcmsSuccess); - } else { - if (pColor->format != XcmsTekHVCFormat) { - if (_XcmsDIConvertColors(ccc, pColor, - &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat) - == XcmsFailure) { - return(XcmsFailure); - } - } - if (XcmsTekHVCQueryMaxC(ccc, - pColor->spec.TekHVC.H, - pColor->spec.TekHVC.V, - pColor) - == XcmsFailure) { - return(XcmsFailure); - } - retval = _XcmsDIConvertColors(ccc, pColor, - &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat); - if (retval != XcmsFailure && pCompressed != NULL) { - *(pCompressed + i) = True; - } - return(retval); - } -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. TekColor is a
+ * trademark of Tektronix, Inc. The term "TekHVC" designates a particular
+ * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent
+ * foreign patents pending). Permission is hereby granted to use, copy,
+ * modify, sell, and otherwise distribute this software and its
+ * documentation for any purpose and without fee, provided that:
+ *
+ * 1. This copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and any modification thereof and in
+ * supporting documentation;
+ * 2. Any color-handling application which displays TekHVC color
+ * cooordinates identifies these as TekHVC color coordinates in any
+ * interface that displays these coordinates and in any associated
+ * documentation;
+ * 3. The term "TekHVC" is always used, and is only used, in association
+ * with the mathematical derivations of the TekHVC Color Space,
+ * including those provided in this file and any equivalent pathways and
+ * mathematical derivations, regardless of digital (e.g., floating point
+ * or integer) representation.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * TekHVCGcC.c
+ *
+ * DESCRIPTION
+ * Source for XcmsTekHVCClipC() gamut compression routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsTekHVCClipC - Reduce the chroma for a hue and value
+ *
+ * SYNOPSIS
+ */
+/* ARGSUSED */
+Status
+XcmsTekHVCClipC (
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors,
+ unsigned int i,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * Reduce the Chroma for a specific hue and value to
+ * to bring the given color into the gamut of the
+ * specified device. As required of gamut compression
+ * functions in Xcms, this routine returns pColor_in_out
+ * in XcmsCIEXYZFormat on successful completion.
+ *
+ * Since this routine works with the value within
+ * pColor_in_out intermediate results may be returned
+ * even though it may be invalid.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ Status retval;
+ XcmsColor *pColor;
+
+ /*
+ * Color specification passed as input can be assumed to:
+ * 1. Be in XcmsCIEXYZFormat
+ * 2. Already be white point adjusted for the Screen White Point.
+ * This means that the white point now associated with this
+ * color spec is the Screen White Point (even if the
+ * ccc->clientWhitePt differs).
+ */
+
+ /*
+ * Insure TekHVC installed
+ */
+ if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ pColor = pColors_in_out + i;
+
+ if (ccc->visual->class < StaticColor &&
+ FunctionSetOfCCC(ccc) != (XPointer) &XcmsLinearRGBFunctionSet) {
+ /*
+ * GRAY !
+ */
+ _XcmsDIConvertColors(ccc, pColor, &ccc->pPerScrnInfo->screenWhitePt,
+ 1, XcmsTekHVCFormat);
+ pColor->spec.TekHVC.H = pColor->spec.TekHVC.C = 0.0;
+ _XcmsDIConvertColors(ccc, pColor, &ccc->pPerScrnInfo->screenWhitePt,
+ 1, XcmsCIEXYZFormat);
+ if (pCompressed) {
+ *(pCompressed + i) = True;
+ }
+ return(XcmsSuccess);
+ } else {
+ if (pColor->format != XcmsTekHVCFormat) {
+ if (_XcmsDIConvertColors(ccc, pColor,
+ &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+ if (XcmsTekHVCQueryMaxC(ccc,
+ pColor->spec.TekHVC.H,
+ pColor->spec.TekHVC.V,
+ pColor)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ retval = _XcmsDIConvertColors(ccc, pColor,
+ &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
+ if (retval != XcmsFailure && pCompressed != NULL) {
+ *(pCompressed + i) = True;
+ }
+ return(retval);
+ }
+}
diff --git a/libX11/src/xcms/HVCGcV.c b/libX11/src/xcms/HVCGcV.c index 0752a0724..9998cc43d 100644 --- a/libX11/src/xcms/HVCGcV.c +++ b/libX11/src/xcms/HVCGcV.c @@ -1,201 +1,201 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. TekColor is a - * trademark of Tektronix, Inc. The term "TekHVC" designates a particular - * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent - * foreign patents pending). Permission is hereby granted to use, copy, - * modify, sell, and otherwise distribute this software and its - * documentation for any purpose and without fee, provided that: - * - * 1. This copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and any modification thereof and in - * supporting documentation; - * 2. Any color-handling application which displays TekHVC color - * cooordinates identifies these as TekHVC color coordinates in any - * interface that displays these coordinates and in any associated - * documentation; - * 3. The term "TekHVC" is always used, and is only used, in association - * with the mathematical derivations of the TekHVC Color Space, - * including those provided in this file and any equivalent pathways and - * mathematical derivations, regardless of digital (e.g., floating point - * or integer) representation. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * TekHVCGcV.c - * - * DESCRIPTION - * Source for XcmsTekHVCClipV() gamut compression routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsTekHVCClipV - Return the closest value - * - * SYNOPSIS - */ -/* ARGSUSED */ -Status -XcmsTekHVCClipV ( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - unsigned int nColors, - unsigned int i, - Bool *pCompressed) -/* - * DESCRIPTION - * Return the closest value for a specific hue and chroma. - * This routine takes any color as input and outputs - * a CIE XYZ color. - * - * Since this routine works with the value within - * pColor_in_out intermediate results may be returned - * even though it may be invalid. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - XcmsColor *pColor; - XcmsColor hvc_max; - XcmsCCCRec myCCC; - Status retval; - - /* - * Insure TekHVC installed - */ - if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) { - return(XcmsFailure); - } - - /* Use my own CCC */ - memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* Inherit Screen WP */ - myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut compression */ - - /* - * Color specification passed as input can be assumed to: - * 1. Be in XcmsCIEXYZFormat - * 2. Already be white point adjusted for the Screen White Point. - * This means that the white point now associated with this - * color spec is the Screen White Point (even if the - * ccc->clientWhitePt differs). - */ - - pColor = pColors_in_out + i; - - if (ccc->visual->class < StaticColor && - FunctionSetOfCCC(ccc) != (XPointer) &XcmsLinearRGBFunctionSet) { - /* - * GRAY ! - */ - return(XcmsFailure); - } else { - /* Convert from CIEXYZ to TekHVC format */ - if (_XcmsDIConvertColors(&myCCC, pColor, - &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat) - == XcmsFailure) { - return(XcmsFailure); - } - - /* check to make sure we have a valid TekHVC number */ - if (!_XcmsTekHVC_CheckModify (pColor)) { - return (XcmsFailure); - } - - /* Step 1: compute the maximum value and chroma for this hue. */ - /* This copy may be overkill but it preserves the pixel etc. */ - memcpy((char *)&hvc_max, (char *)pColor, sizeof(XcmsColor)); - if (_XcmsTekHVCQueryMaxVCRGB (&myCCC, hvc_max.spec.TekHVC.H, &hvc_max, - (XcmsRGBi *)NULL) == XcmsFailure) { - return (XcmsFailure); - } - - /* Now check and return the appropriate value */ - if (pColor->spec.TekHVC.C == hvc_max.spec.TekHVC.C) { - /* When the chroma input is equal to the maximum chroma */ - /* merely return the value for that chroma. */ - pColor->spec.TekHVC.V = hvc_max.spec.TekHVC.V; - if (!_XcmsTekHVC_CheckModify (pColor)) { - return (XcmsFailure); - } - retval = _XcmsDIConvertColors(&myCCC, pColor, - &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat); - } else if (pColor->spec.TekHVC.C > hvc_max.spec.TekHVC.C) { - /* When the chroma input is greater than the maximum chroma */ - /* merely return the value and chroma for the given hue. */ - pColor->spec.TekHVC.C = hvc_max.spec.TekHVC.C; - pColor->spec.TekHVC.V = hvc_max.spec.TekHVC.V; - return (XcmsFailure); - } else if (pColor->spec.TekHVC.V < hvc_max.spec.TekHVC.V) { - /* When the value input is less than the maximum value point */ - /* compute the intersection of the line from 0,0 to max_V, max_C */ - /* using the chroma input. */ - pColor->spec.TekHVC.V = pColor->spec.TekHVC.C * - hvc_max.spec.TekHVC.V / hvc_max.spec.TekHVC.C; - if (pColor->spec.TekHVC.V >= hvc_max.spec.TekHVC.V) { - pColor->spec.TekHVC.C = hvc_max.spec.TekHVC.C; - pColor->spec.TekHVC.V = hvc_max.spec.TekHVC.V; - } - if (!_XcmsTekHVC_CheckModify (pColor)) { - return (XcmsFailure); - } - retval = _XcmsDIConvertColors(&myCCC, pColor, - &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat); - } else { - /* When the value input is greater than the maximum value point */ - /* use HvcMaxValue to find the maximum value for the given chroma. */ - if (pColor->format != XcmsTekHVCFormat) { - if (_XcmsDIConvertColors(ccc, pColor, - &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat) - == XcmsFailure) { - return(XcmsFailure); - } - } - if (XcmsTekHVCQueryMaxV(&myCCC, - pColor->spec.TekHVC.H, - pColor->spec.TekHVC.C, - pColor) - == XcmsFailure) { - return (XcmsFailure); - } - retval = _XcmsDIConvertColors(&myCCC, pColor, - &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat); - } - if (retval != XcmsFailure && pCompressed != NULL) { - *(pCompressed + i) = True; - } - return(retval); - } -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. TekColor is a
+ * trademark of Tektronix, Inc. The term "TekHVC" designates a particular
+ * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent
+ * foreign patents pending). Permission is hereby granted to use, copy,
+ * modify, sell, and otherwise distribute this software and its
+ * documentation for any purpose and without fee, provided that:
+ *
+ * 1. This copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and any modification thereof and in
+ * supporting documentation;
+ * 2. Any color-handling application which displays TekHVC color
+ * cooordinates identifies these as TekHVC color coordinates in any
+ * interface that displays these coordinates and in any associated
+ * documentation;
+ * 3. The term "TekHVC" is always used, and is only used, in association
+ * with the mathematical derivations of the TekHVC Color Space,
+ * including those provided in this file and any equivalent pathways and
+ * mathematical derivations, regardless of digital (e.g., floating point
+ * or integer) representation.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * TekHVCGcV.c
+ *
+ * DESCRIPTION
+ * Source for XcmsTekHVCClipV() gamut compression routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsTekHVCClipV - Return the closest value
+ *
+ * SYNOPSIS
+ */
+/* ARGSUSED */
+Status
+XcmsTekHVCClipV (
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors,
+ unsigned int i,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * Return the closest value for a specific hue and chroma.
+ * This routine takes any color as input and outputs
+ * a CIE XYZ color.
+ *
+ * Since this routine works with the value within
+ * pColor_in_out intermediate results may be returned
+ * even though it may be invalid.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ XcmsColor *pColor;
+ XcmsColor hvc_max;
+ XcmsCCCRec myCCC;
+ Status retval;
+
+ /*
+ * Insure TekHVC installed
+ */
+ if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* Use my own CCC */
+ memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* Inherit Screen WP */
+ myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut compression */
+
+ /*
+ * Color specification passed as input can be assumed to:
+ * 1. Be in XcmsCIEXYZFormat
+ * 2. Already be white point adjusted for the Screen White Point.
+ * This means that the white point now associated with this
+ * color spec is the Screen White Point (even if the
+ * ccc->clientWhitePt differs).
+ */
+
+ pColor = pColors_in_out + i;
+
+ if (ccc->visual->class < StaticColor &&
+ FunctionSetOfCCC(ccc) != (XPointer) &XcmsLinearRGBFunctionSet) {
+ /*
+ * GRAY !
+ */
+ return(XcmsFailure);
+ } else {
+ /* Convert from CIEXYZ to TekHVC format */
+ if (_XcmsDIConvertColors(&myCCC, pColor,
+ &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* check to make sure we have a valid TekHVC number */
+ if (!_XcmsTekHVC_CheckModify (pColor)) {
+ return (XcmsFailure);
+ }
+
+ /* Step 1: compute the maximum value and chroma for this hue. */
+ /* This copy may be overkill but it preserves the pixel etc. */
+ memcpy((char *)&hvc_max, (char *)pColor, sizeof(XcmsColor));
+ if (_XcmsTekHVCQueryMaxVCRGB (&myCCC, hvc_max.spec.TekHVC.H, &hvc_max,
+ (XcmsRGBi *)NULL) == XcmsFailure) {
+ return (XcmsFailure);
+ }
+
+ /* Now check and return the appropriate value */
+ if (pColor->spec.TekHVC.C == hvc_max.spec.TekHVC.C) {
+ /* When the chroma input is equal to the maximum chroma */
+ /* merely return the value for that chroma. */
+ pColor->spec.TekHVC.V = hvc_max.spec.TekHVC.V;
+ if (!_XcmsTekHVC_CheckModify (pColor)) {
+ return (XcmsFailure);
+ }
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
+ } else if (pColor->spec.TekHVC.C > hvc_max.spec.TekHVC.C) {
+ /* When the chroma input is greater than the maximum chroma */
+ /* merely return the value and chroma for the given hue. */
+ pColor->spec.TekHVC.C = hvc_max.spec.TekHVC.C;
+ pColor->spec.TekHVC.V = hvc_max.spec.TekHVC.V;
+ return (XcmsFailure);
+ } else if (pColor->spec.TekHVC.V < hvc_max.spec.TekHVC.V) {
+ /* When the value input is less than the maximum value point */
+ /* compute the intersection of the line from 0,0 to max_V, max_C */
+ /* using the chroma input. */
+ pColor->spec.TekHVC.V = pColor->spec.TekHVC.C *
+ hvc_max.spec.TekHVC.V / hvc_max.spec.TekHVC.C;
+ if (pColor->spec.TekHVC.V >= hvc_max.spec.TekHVC.V) {
+ pColor->spec.TekHVC.C = hvc_max.spec.TekHVC.C;
+ pColor->spec.TekHVC.V = hvc_max.spec.TekHVC.V;
+ }
+ if (!_XcmsTekHVC_CheckModify (pColor)) {
+ return (XcmsFailure);
+ }
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
+ } else {
+ /* When the value input is greater than the maximum value point */
+ /* use HvcMaxValue to find the maximum value for the given chroma. */
+ if (pColor->format != XcmsTekHVCFormat) {
+ if (_XcmsDIConvertColors(ccc, pColor,
+ &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+ if (XcmsTekHVCQueryMaxV(&myCCC,
+ pColor->spec.TekHVC.H,
+ pColor->spec.TekHVC.C,
+ pColor)
+ == XcmsFailure) {
+ return (XcmsFailure);
+ }
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
+ }
+ if (retval != XcmsFailure && pCompressed != NULL) {
+ *(pCompressed + i) = True;
+ }
+ return(retval);
+ }
+}
diff --git a/libX11/src/xcms/HVCGcVC.c b/libX11/src/xcms/HVCGcVC.c index 7ace5f13f..9c6b598f8 100644 --- a/libX11/src/xcms/HVCGcVC.c +++ b/libX11/src/xcms/HVCGcVC.c @@ -1,262 +1,262 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. TekColor is a - * trademark of Tektronix, Inc. The term "TekHVC" designates a particular - * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent - * foreign patents pending). Permission is hereby granted to use, copy, - * modify, sell, and otherwise distribute this software and its - * documentation for any purpose and without fee, provided that: - * - * 1. This copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and any modification thereof and in - * supporting documentation; - * 2. Any color-handling application which displays TekHVC color - * cooordinates identifies these as TekHVC color coordinates in any - * interface that displays these coordinates and in any associated - * documentation; - * 3. The term "TekHVC" is always used, and is only used, in association - * with the mathematical derivations of the TekHVC Color Space, - * including those provided in this file and any equivalent pathways and - * mathematical derivations, regardless of digital (e.g., floating point - * or integer) representation. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * TekHVCGcVC.c - * - * DESCRIPTION - * Source for XcmsTekHVCClipVC() gamut - * compression function. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include <math.h> -#include "Cv.h" - -/* - * INTERNALS - * Internal defines that need NOT be exported to any package or - * program using this package. - */ -#define MAXBISECTCOUNT 100 - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsTekHVCClipVC - Return the closest value and chroma - * - * SYNOPSIS - */ -/* ARGSUSED */ -Status -XcmsTekHVCClipVC ( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - unsigned int nColors, - unsigned int i, - Bool *pCompressed) -/* - * DESCRIPTION - * This routine will find the closest value and chroma - * for a specific hue. The color input is converted to - * HVC format and returned as CIE XYZ format. - * - * Since this routine works with the value within - * pColor_in_out intermediate results may be returned - * even though it may be invalid. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - Status retval; - XcmsCCCRec myCCC; - XcmsColor *pColor; - XcmsColor hvc_max; - XcmsRGBi rgb_max; - int nCount, nMaxCount, nI, nILast; - XcmsFloat Chroma, Value, bestChroma, bestValue, nT, saveDist, tmpDist; - - /* - * Insure TekHVC installed - */ - if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) { - return(XcmsFailure); - } - - /* Use my own CCC */ - memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* inherit screen white pt */ - myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut compression func */ - - /* - * Color specification passed as input can be assumed to: - * 1. Be in XcmsCIEXYZFormat - * 2. Already be white point adjusted for the Screen White Point. - * This means that the white point now associated with this - * color spec is the Screen White Point (even if the - * ccc->clientWhitePt differs). - */ - - pColor = pColors_in_out + i; - - if (ccc->visual->class < StaticColor && - FunctionSetOfCCC(ccc) != (XPointer) &XcmsLinearRGBFunctionSet) { - /* - * GRAY ! - */ - _XcmsDIConvertColors(ccc, pColor, &ccc->pPerScrnInfo->screenWhitePt, - 1, XcmsTekHVCFormat); - pColor->spec.TekHVC.H = pColor->spec.TekHVC.C = 0.0; - _XcmsDIConvertColors(ccc, pColor, &ccc->pPerScrnInfo->screenWhitePt, - 1, XcmsCIEXYZFormat); - if (pCompressed) { - *(pCompressed + i) = True; - } - return(XcmsSuccess); - } else { - /* Convert from CIEXYZ to TekHVC format */ - if (_XcmsDIConvertColors(&myCCC, pColor, - &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat) - == XcmsFailure) { - return(XcmsFailure); - } - - if (!_XcmsTekHVC_CheckModify(pColor)) { - return (XcmsFailure); - } - - /* Step 1: compute the maximum value and chroma for this hue. */ - /* This copy may be overkill but it preserves the pixel etc. */ - memcpy((char *)&hvc_max, (char *)pColor, sizeof(XcmsColor)); - if (_XcmsTekHVCQueryMaxVCRGB (&myCCC, hvc_max.spec.TekHVC.H, &hvc_max, - &rgb_max) == XcmsFailure) { - return (XcmsFailure); - } - - /* Now check and return the appropriate value */ - if (pColor->spec.TekHVC.V == hvc_max.spec.TekHVC.V) { - /* When the value input is equal to the maximum value */ - /* merely return the chroma for that value. */ - pColor->spec.TekHVC.C = hvc_max.spec.TekHVC.C; - retval = _XcmsDIConvertColors(&myCCC, pColor, - &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat); - } - - if (pColor->spec.TekHVC.V < hvc_max.spec.TekHVC.V) { - /* return the intersection of the perpindicular line through */ - /* the value and chroma given and the line from 0,0 and hvc_max. */ - Chroma = pColor->spec.TekHVC.C; - Value = pColor->spec.TekHVC.V; - pColor->spec.TekHVC.C = - (Value + (hvc_max.spec.TekHVC.C / hvc_max.spec.TekHVC.V * Chroma)) / - ((hvc_max.spec.TekHVC.V / hvc_max.spec.TekHVC.C) + - (hvc_max.spec.TekHVC.C / hvc_max.spec.TekHVC.V)); - if (pColor->spec.TekHVC.C >= hvc_max.spec.TekHVC.C) { - pColor->spec.TekHVC.C = hvc_max.spec.TekHVC.C; - pColor->spec.TekHVC.V = hvc_max.spec.TekHVC.V; - } else { - pColor->spec.TekHVC.V = pColor->spec.TekHVC.C * - hvc_max.spec.TekHVC.V / hvc_max.spec.TekHVC.C; - } - retval = _XcmsDIConvertColors(&myCCC, pColor, - &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat); - - if (retval != XcmsFailure && pCompressed != NULL) { - *(pCompressed + i) = True; - } - return (retval); - } - - /* return the closest point on the upper part of the hue leaf. */ - /* must do a bisection here to compute the delta e. */ - nMaxCount = MAXBISECTCOUNT; - nI = nMaxCount / 2; - bestValue = Value = pColor->spec.TekHVC.V; - bestChroma = Chroma = pColor->spec.TekHVC.C; - saveDist = (XcmsFloat) XCMS_SQRT ((double) (((Chroma - hvc_max.spec.TekHVC.C) * - (Chroma - hvc_max.spec.TekHVC.C)) + - ((Value - hvc_max.spec.TekHVC.V) * - (Value - hvc_max.spec.TekHVC.V)))); - for (nCount = 0; nCount < nMaxCount; nCount++) { - nT = (XcmsFloat) nI / (XcmsFloat) nMaxCount; - pColor->spec.RGBi.red = rgb_max.red * (1.0 - nT) + nT; - pColor->spec.RGBi.green = rgb_max.green * (1.0 - nT) + nT; - pColor->spec.RGBi.blue = rgb_max.blue * (1.0 - nT) + nT; - pColor->format = XcmsRGBiFormat; - - /* Convert from RGBi to HVC */ - if (_XcmsConvertColorsWithWhitePt(&myCCC, pColor, - &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat, - (Bool *) NULL) - == XcmsFailure) { - return (XcmsFailure); - } - if (!_XcmsTekHVC_CheckModify(pColor)) { - return (XcmsFailure); - } - tmpDist = (XcmsFloat) XCMS_SQRT ((double) - (((Chroma - pColor->spec.TekHVC.C) * - (Chroma - pColor->spec.TekHVC.C)) + - ((Value - pColor->spec.TekHVC.V) * - (Value - pColor->spec.TekHVC.V)))); - nILast = nI; - if (tmpDist > saveDist) { - nI /= 2; - } else { - nI = (nMaxCount + nI) / 2; - saveDist = tmpDist; - bestValue = pColor->spec.TekHVC.V; - bestChroma = pColor->spec.TekHVC.C; - } - if (nI == nILast || nI == 0) { - break; - } - - } - - if (bestChroma >= hvc_max.spec.TekHVC.C) { - pColor->spec.TekHVC.C = hvc_max.spec.TekHVC.C; - pColor->spec.TekHVC.V = hvc_max.spec.TekHVC.V; - } else { - pColor->spec.TekHVC.C = bestChroma; - pColor->spec.TekHVC.V = bestValue; - } - if (!_XcmsTekHVC_CheckModify(pColor)) { - return (XcmsFailure); - } - retval = _XcmsDIConvertColors(&myCCC, pColor, - &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat); - - if (retval != XcmsFailure && pCompressed != NULL) { - *(pCompressed + i) = True; - } - return(retval); - } -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. TekColor is a
+ * trademark of Tektronix, Inc. The term "TekHVC" designates a particular
+ * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent
+ * foreign patents pending). Permission is hereby granted to use, copy,
+ * modify, sell, and otherwise distribute this software and its
+ * documentation for any purpose and without fee, provided that:
+ *
+ * 1. This copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and any modification thereof and in
+ * supporting documentation;
+ * 2. Any color-handling application which displays TekHVC color
+ * cooordinates identifies these as TekHVC color coordinates in any
+ * interface that displays these coordinates and in any associated
+ * documentation;
+ * 3. The term "TekHVC" is always used, and is only used, in association
+ * with the mathematical derivations of the TekHVC Color Space,
+ * including those provided in this file and any equivalent pathways and
+ * mathematical derivations, regardless of digital (e.g., floating point
+ * or integer) representation.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * TekHVCGcVC.c
+ *
+ * DESCRIPTION
+ * Source for XcmsTekHVCClipVC() gamut
+ * compression function.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include <math.h>
+#include "Cv.h"
+
+/*
+ * INTERNALS
+ * Internal defines that need NOT be exported to any package or
+ * program using this package.
+ */
+#define MAXBISECTCOUNT 100
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsTekHVCClipVC - Return the closest value and chroma
+ *
+ * SYNOPSIS
+ */
+/* ARGSUSED */
+Status
+XcmsTekHVCClipVC (
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors,
+ unsigned int i,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * This routine will find the closest value and chroma
+ * for a specific hue. The color input is converted to
+ * HVC format and returned as CIE XYZ format.
+ *
+ * Since this routine works with the value within
+ * pColor_in_out intermediate results may be returned
+ * even though it may be invalid.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ Status retval;
+ XcmsCCCRec myCCC;
+ XcmsColor *pColor;
+ XcmsColor hvc_max;
+ XcmsRGBi rgb_max;
+ int nCount, nMaxCount, nI, nILast;
+ XcmsFloat Chroma, Value, bestChroma, bestValue, nT, saveDist, tmpDist;
+
+ /*
+ * Insure TekHVC installed
+ */
+ if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* Use my own CCC */
+ memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* inherit screen white pt */
+ myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut compression func */
+
+ /*
+ * Color specification passed as input can be assumed to:
+ * 1. Be in XcmsCIEXYZFormat
+ * 2. Already be white point adjusted for the Screen White Point.
+ * This means that the white point now associated with this
+ * color spec is the Screen White Point (even if the
+ * ccc->clientWhitePt differs).
+ */
+
+ pColor = pColors_in_out + i;
+
+ if (ccc->visual->class < StaticColor &&
+ FunctionSetOfCCC(ccc) != (XPointer) &XcmsLinearRGBFunctionSet) {
+ /*
+ * GRAY !
+ */
+ _XcmsDIConvertColors(ccc, pColor, &ccc->pPerScrnInfo->screenWhitePt,
+ 1, XcmsTekHVCFormat);
+ pColor->spec.TekHVC.H = pColor->spec.TekHVC.C = 0.0;
+ _XcmsDIConvertColors(ccc, pColor, &ccc->pPerScrnInfo->screenWhitePt,
+ 1, XcmsCIEXYZFormat);
+ if (pCompressed) {
+ *(pCompressed + i) = True;
+ }
+ return(XcmsSuccess);
+ } else {
+ /* Convert from CIEXYZ to TekHVC format */
+ if (_XcmsDIConvertColors(&myCCC, pColor,
+ &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ if (!_XcmsTekHVC_CheckModify(pColor)) {
+ return (XcmsFailure);
+ }
+
+ /* Step 1: compute the maximum value and chroma for this hue. */
+ /* This copy may be overkill but it preserves the pixel etc. */
+ memcpy((char *)&hvc_max, (char *)pColor, sizeof(XcmsColor));
+ if (_XcmsTekHVCQueryMaxVCRGB (&myCCC, hvc_max.spec.TekHVC.H, &hvc_max,
+ &rgb_max) == XcmsFailure) {
+ return (XcmsFailure);
+ }
+
+ /* Now check and return the appropriate value */
+ if (pColor->spec.TekHVC.V == hvc_max.spec.TekHVC.V) {
+ /* When the value input is equal to the maximum value */
+ /* merely return the chroma for that value. */
+ pColor->spec.TekHVC.C = hvc_max.spec.TekHVC.C;
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
+ }
+
+ if (pColor->spec.TekHVC.V < hvc_max.spec.TekHVC.V) {
+ /* return the intersection of the perpindicular line through */
+ /* the value and chroma given and the line from 0,0 and hvc_max. */
+ Chroma = pColor->spec.TekHVC.C;
+ Value = pColor->spec.TekHVC.V;
+ pColor->spec.TekHVC.C =
+ (Value + (hvc_max.spec.TekHVC.C / hvc_max.spec.TekHVC.V * Chroma)) /
+ ((hvc_max.spec.TekHVC.V / hvc_max.spec.TekHVC.C) +
+ (hvc_max.spec.TekHVC.C / hvc_max.spec.TekHVC.V));
+ if (pColor->spec.TekHVC.C >= hvc_max.spec.TekHVC.C) {
+ pColor->spec.TekHVC.C = hvc_max.spec.TekHVC.C;
+ pColor->spec.TekHVC.V = hvc_max.spec.TekHVC.V;
+ } else {
+ pColor->spec.TekHVC.V = pColor->spec.TekHVC.C *
+ hvc_max.spec.TekHVC.V / hvc_max.spec.TekHVC.C;
+ }
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
+
+ if (retval != XcmsFailure && pCompressed != NULL) {
+ *(pCompressed + i) = True;
+ }
+ return (retval);
+ }
+
+ /* return the closest point on the upper part of the hue leaf. */
+ /* must do a bisection here to compute the delta e. */
+ nMaxCount = MAXBISECTCOUNT;
+ nI = nMaxCount / 2;
+ bestValue = Value = pColor->spec.TekHVC.V;
+ bestChroma = Chroma = pColor->spec.TekHVC.C;
+ saveDist = (XcmsFloat) XCMS_SQRT ((double) (((Chroma - hvc_max.spec.TekHVC.C) *
+ (Chroma - hvc_max.spec.TekHVC.C)) +
+ ((Value - hvc_max.spec.TekHVC.V) *
+ (Value - hvc_max.spec.TekHVC.V))));
+ for (nCount = 0; nCount < nMaxCount; nCount++) {
+ nT = (XcmsFloat) nI / (XcmsFloat) nMaxCount;
+ pColor->spec.RGBi.red = rgb_max.red * (1.0 - nT) + nT;
+ pColor->spec.RGBi.green = rgb_max.green * (1.0 - nT) + nT;
+ pColor->spec.RGBi.blue = rgb_max.blue * (1.0 - nT) + nT;
+ pColor->format = XcmsRGBiFormat;
+
+ /* Convert from RGBi to HVC */
+ if (_XcmsConvertColorsWithWhitePt(&myCCC, pColor,
+ &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat,
+ (Bool *) NULL)
+ == XcmsFailure) {
+ return (XcmsFailure);
+ }
+ if (!_XcmsTekHVC_CheckModify(pColor)) {
+ return (XcmsFailure);
+ }
+ tmpDist = (XcmsFloat) XCMS_SQRT ((double)
+ (((Chroma - pColor->spec.TekHVC.C) *
+ (Chroma - pColor->spec.TekHVC.C)) +
+ ((Value - pColor->spec.TekHVC.V) *
+ (Value - pColor->spec.TekHVC.V))));
+ nILast = nI;
+ if (tmpDist > saveDist) {
+ nI /= 2;
+ } else {
+ nI = (nMaxCount + nI) / 2;
+ saveDist = tmpDist;
+ bestValue = pColor->spec.TekHVC.V;
+ bestChroma = pColor->spec.TekHVC.C;
+ }
+ if (nI == nILast || nI == 0) {
+ break;
+ }
+
+ }
+
+ if (bestChroma >= hvc_max.spec.TekHVC.C) {
+ pColor->spec.TekHVC.C = hvc_max.spec.TekHVC.C;
+ pColor->spec.TekHVC.V = hvc_max.spec.TekHVC.V;
+ } else {
+ pColor->spec.TekHVC.C = bestChroma;
+ pColor->spec.TekHVC.V = bestValue;
+ }
+ if (!_XcmsTekHVC_CheckModify(pColor)) {
+ return (XcmsFailure);
+ }
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
+
+ if (retval != XcmsFailure && pCompressed != NULL) {
+ *(pCompressed + i) = True;
+ }
+ return(retval);
+ }
+}
diff --git a/libX11/src/xcms/HVCMnV.c b/libX11/src/xcms/HVCMnV.c index 10a9f857a..14e569932 100644 --- a/libX11/src/xcms/HVCMnV.c +++ b/libX11/src/xcms/HVCMnV.c @@ -1,163 +1,163 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. TekColor is a - * trademark of Tektronix, Inc. The term "TekHVC" designates a particular - * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent - * foreign patents pending). Permission is hereby granted to use, copy, - * modify, sell, and otherwise distribute this software and its - * documentation for any purpose and without fee, provided that: - * - * 1. This copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and any modification thereof and in - * supporting documentation; - * 2. Any color-handling application which displays TekHVC color - * cooordinates identifies these as TekHVC color coordinates in any - * interface that displays these coordinates and in any associated - * documentation; - * 3. The term "TekHVC" is always used, and is only used, in association - * with the mathematical derivations of the TekHVC Color Space, - * including those provided in this file and any equivalent pathways and - * mathematical derivations, regardless of digital (e.g., floating point - * or integer) representation. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * TekHVCMnV.c - * - * DESCRIPTION - * Source for XcmsTekHVCQueryMinV gamut boundary querying routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - -/* - * DEFINES - */ -#define EPS 0.001 - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsTekHVCQueryMinV - Compute minimum value for hue and chroma - * - * SYNOPSIS - */ -Status -XcmsTekHVCQueryMinV ( - XcmsCCC ccc, - XcmsFloat hue, - XcmsFloat chroma, - XcmsColor *pColor_return) - -/* - * DESCRIPTION - * Return the minimum value for a specific hue, and the - * corresponding chroma. The input color specification - * may be in any format, however output is in XcmsTekHVCFormat. - * - * Since this routine works with the value within - * pColor_return intermediate results may be returned - * even though it may be invalid. - * - * ASSUMPTIONS - * This routine assumes that the white point associated with - * the color specification is the Screen White Point. The - * Screen White Point will also be associated with the - * returned color specification. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded with no modifications - * - */ -{ - XcmsCCCRec myCCC; - XcmsColor tmp; - XcmsColor max_vc; - - /* - * Check Arguments - */ - if (ccc == NULL || pColor_return == NULL) { - return(XcmsFailure); - } - - /* - * Insure TekHVC installed - */ - if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) { - return(XcmsFailure); - } - - /* Use my own CCC */ - memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* inherit screen white pt */ - myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut comp func */ - - tmp.spec.TekHVC.H = hue; - tmp.spec.TekHVC.V = 100.0; - tmp.spec.TekHVC.C = chroma; - tmp.pixel = pColor_return->pixel; - tmp.format = XcmsTekHVCFormat; - - - /* Check for a valid HVC */ - if (!_XcmsTekHVC_CheckModify (&tmp)) { - return(XcmsFailure); - } - - /* Step 1: compute the maximum value and chroma for this hue. */ - /* This copy may be overkill but it preserves the pixel etc. */ - memcpy((char *)&max_vc, (char *)&tmp, sizeof(XcmsColor)); - if (_XcmsTekHVCQueryMaxVCRGB (&myCCC, max_vc.spec.TekHVC.H, &max_vc, - (XcmsRGBi *)NULL) == XcmsFailure) { - return(XcmsFailure); - } - - /* Step 2: find the intersection with the maximum hvc and chroma line. */ - if (tmp.spec.TekHVC.C > max_vc.spec.TekHVC.C + EPS) { - /* If the chroma is to large then return maximum hvc. */ - tmp.spec.TekHVC.C = max_vc.spec.TekHVC.C; - tmp.spec.TekHVC.V = max_vc.spec.TekHVC.V; - } else { - tmp.spec.TekHVC.V = tmp.spec.TekHVC.C * - max_vc.spec.TekHVC.V / max_vc.spec.TekHVC.C; - if (tmp.spec.TekHVC.V > max_vc.spec.TekHVC.V) { - tmp.spec.TekHVC.V = max_vc.spec.TekHVC.V; - } else if (tmp.spec.TekHVC.V < 0.0) { - tmp.spec.TekHVC.V = tmp.spec.TekHVC.C = 0.0; - } - } - if (_XcmsTekHVC_CheckModify (&tmp)) { - memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor)); - return(XcmsSuccess); - } else { - return(XcmsFailure); - } -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. TekColor is a
+ * trademark of Tektronix, Inc. The term "TekHVC" designates a particular
+ * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent
+ * foreign patents pending). Permission is hereby granted to use, copy,
+ * modify, sell, and otherwise distribute this software and its
+ * documentation for any purpose and without fee, provided that:
+ *
+ * 1. This copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and any modification thereof and in
+ * supporting documentation;
+ * 2. Any color-handling application which displays TekHVC color
+ * cooordinates identifies these as TekHVC color coordinates in any
+ * interface that displays these coordinates and in any associated
+ * documentation;
+ * 3. The term "TekHVC" is always used, and is only used, in association
+ * with the mathematical derivations of the TekHVC Color Space,
+ * including those provided in this file and any equivalent pathways and
+ * mathematical derivations, regardless of digital (e.g., floating point
+ * or integer) representation.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * TekHVCMnV.c
+ *
+ * DESCRIPTION
+ * Source for XcmsTekHVCQueryMinV gamut boundary querying routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+/*
+ * DEFINES
+ */
+#define EPS 0.001
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsTekHVCQueryMinV - Compute minimum value for hue and chroma
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsTekHVCQueryMinV (
+ XcmsCCC ccc,
+ XcmsFloat hue,
+ XcmsFloat chroma,
+ XcmsColor *pColor_return)
+
+/*
+ * DESCRIPTION
+ * Return the minimum value for a specific hue, and the
+ * corresponding chroma. The input color specification
+ * may be in any format, however output is in XcmsTekHVCFormat.
+ *
+ * Since this routine works with the value within
+ * pColor_return intermediate results may be returned
+ * even though it may be invalid.
+ *
+ * ASSUMPTIONS
+ * This routine assumes that the white point associated with
+ * the color specification is the Screen White Point. The
+ * Screen White Point will also be associated with the
+ * returned color specification.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded with no modifications
+ *
+ */
+{
+ XcmsCCCRec myCCC;
+ XcmsColor tmp;
+ XcmsColor max_vc;
+
+ /*
+ * Check Arguments
+ */
+ if (ccc == NULL || pColor_return == NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Insure TekHVC installed
+ */
+ if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* Use my own CCC */
+ memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* inherit screen white pt */
+ myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut comp func */
+
+ tmp.spec.TekHVC.H = hue;
+ tmp.spec.TekHVC.V = 100.0;
+ tmp.spec.TekHVC.C = chroma;
+ tmp.pixel = pColor_return->pixel;
+ tmp.format = XcmsTekHVCFormat;
+
+
+ /* Check for a valid HVC */
+ if (!_XcmsTekHVC_CheckModify (&tmp)) {
+ return(XcmsFailure);
+ }
+
+ /* Step 1: compute the maximum value and chroma for this hue. */
+ /* This copy may be overkill but it preserves the pixel etc. */
+ memcpy((char *)&max_vc, (char *)&tmp, sizeof(XcmsColor));
+ if (_XcmsTekHVCQueryMaxVCRGB (&myCCC, max_vc.spec.TekHVC.H, &max_vc,
+ (XcmsRGBi *)NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* Step 2: find the intersection with the maximum hvc and chroma line. */
+ if (tmp.spec.TekHVC.C > max_vc.spec.TekHVC.C + EPS) {
+ /* If the chroma is to large then return maximum hvc. */
+ tmp.spec.TekHVC.C = max_vc.spec.TekHVC.C;
+ tmp.spec.TekHVC.V = max_vc.spec.TekHVC.V;
+ } else {
+ tmp.spec.TekHVC.V = tmp.spec.TekHVC.C *
+ max_vc.spec.TekHVC.V / max_vc.spec.TekHVC.C;
+ if (tmp.spec.TekHVC.V > max_vc.spec.TekHVC.V) {
+ tmp.spec.TekHVC.V = max_vc.spec.TekHVC.V;
+ } else if (tmp.spec.TekHVC.V < 0.0) {
+ tmp.spec.TekHVC.V = tmp.spec.TekHVC.C = 0.0;
+ }
+ }
+ if (_XcmsTekHVC_CheckModify (&tmp)) {
+ memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor));
+ return(XcmsSuccess);
+ } else {
+ return(XcmsFailure);
+ }
+}
diff --git a/libX11/src/xcms/HVCMxC.c b/libX11/src/xcms/HVCMxC.c index 074844ccc..cded0e8a5 100644 --- a/libX11/src/xcms/HVCMxC.c +++ b/libX11/src/xcms/HVCMxC.c @@ -1,243 +1,243 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. TekColor is a - * trademark of Tektronix, Inc. The term "TekHVC" designates a particular - * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent - * foreign patents pending). Permission is hereby granted to use, copy, - * modify, sell, and otherwise distribute this software and its - * documentation for any purpose and without fee, provided that: - * - * 1. This copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and any modification thereof and in - * supporting documentation; - * 2. Any color-handling application which displays TekHVC color - * cooordinates identifies these as TekHVC color coordinates in any - * interface that displays these coordinates and in any associated - * documentation; - * 3. The term "TekHVC" is always used, and is only used, in association - * with the mathematical derivations of the TekHVC Color Space, - * including those provided in this file and any equivalent pathways and - * mathematical derivations, regardless of digital (e.g., floating point - * or integer) representation. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * TekHVCMxC.c - * - * DESCRIPTION - * Source for the XcmsTekHVCQueryMaxC() gamut boudary - * querying routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include <math.h> -#include "Cv.h" - -/* - * DEFINES - */ -#define MAXBISECTCOUNT 100 -#define EPS 0.001 - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsTekHVCQueryMaxC - Compute the maximum chroma for a hue and value - * - * SYNOPSIS - */ -Status -XcmsTekHVCQueryMaxC( - XcmsCCC ccc, - XcmsFloat hue, - XcmsFloat value, - XcmsColor *pColor_return) -/* - * DESCRIPTION - * Return the maximum chroma for a specific hue and value. - * The returned format is in XcmsTekHVCFormat. - * - * - * ASSUMPTIONS - * This routine assumes that the white point associated with - * the color specification is the Screen White Point. The - * Screen White Point will also be associated with the - * returned color specification. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - XcmsCCCRec myCCC; - XcmsColor tmp; - XcmsColor max_vc; - XcmsRGBi rgb_saved; - int nCount, nMaxCount; - XcmsFloat nValue, savedValue, lastValue, lastChroma, prevValue; - XcmsFloat maxDist, nT, rFactor; - XcmsFloat ftmp1, ftmp2; - - /* - * Check Arguments - */ - if (ccc == NULL || pColor_return == NULL) { - return(XcmsFailure); - } - - /* - * Insure TekHVC installed - */ - if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) { - return(XcmsFailure); - } - - /* Use my own CCC */ - memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat; /* inherit screen white Pt */ - myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut comp func */ - - tmp.spec.TekHVC.H = hue; - tmp.spec.TekHVC.V = value; - tmp.spec.TekHVC.C = 100.0; - tmp.pixel = pColor_return->pixel; - tmp.format = XcmsTekHVCFormat; - - /* check to make sure we have a valid TekHVC number */ - if (!_XcmsTekHVC_CheckModify(&tmp)) { - return(XcmsFailure); - } - - /* Step 1: compute the maximum value and chroma for this hue. */ - memcpy((char *)&max_vc, (char *)&tmp, sizeof(XcmsColor)); - if (_XcmsTekHVCQueryMaxVCRGB(&myCCC, hue, &max_vc, &rgb_saved) - == XcmsFailure) { - return(XcmsFailure); - } - - /* Step 2: If the value is less than the value for the maximum */ - /* value, chroma point then the chroma is on the line */ - /* from max_vc to 0,0. */ - if (value <= max_vc.spec.TekHVC.V) { - tmp.spec.TekHVC.C = value - * max_vc.spec.TekHVC.C / max_vc.spec.TekHVC.V; - if (_XcmsTekHVC_CheckModify (&tmp)) { - memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor)); - return(XcmsSuccess); - } else { - return(XcmsFailure); - } - } else { - /* must do a bisection here to compute the maximum chroma */ - /* save the structure input so that any elements that */ - /* are not touched are recopied later in the routine. */ - nValue = savedValue = value; - lastChroma = -1.0; - lastValue = -1.0; - nMaxCount = MAXBISECTCOUNT; - maxDist = 100.0 - max_vc.spec.TekHVC.V; - rFactor = 1.0; - - for (nCount = 0; nCount < nMaxCount; nCount++) { - prevValue = lastValue; - lastValue = tmp.spec.TekHVC.V; - lastChroma = tmp.spec.TekHVC.C; - nT = (nValue - max_vc.spec.TekHVC.V) / maxDist * rFactor; - tmp.spec.RGBi.red = rgb_saved.red * (1.0 - nT) + nT; - tmp.spec.RGBi.green = rgb_saved.green * (1.0 - nT) + nT; - tmp.spec.RGBi.blue = rgb_saved.blue * (1.0 - nT) + nT; - tmp.format = XcmsRGBiFormat; - - /* convert from RGB to HVC */ - if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp, - &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat, - (Bool *) NULL) == XcmsFailure) { - return(XcmsFailure); - } - - /* Now check the return against what is expected */ - if (tmp.spec.TekHVC.V <= savedValue + EPS && - tmp.spec.TekHVC.V >= savedValue - EPS) { - /* make sure to return the input hue */ - tmp.spec.TekHVC.H = hue; - if (_XcmsTekHVC_CheckModify (&tmp)) { - memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor)); - return(XcmsSuccess); - } else { - return(XcmsFailure); - } - } - nValue += savedValue - tmp.spec.TekHVC.V; - if (nValue < max_vc.spec.TekHVC.V) { - nValue = max_vc.spec.TekHVC.V; - rFactor *= 0.5; /* selective relaxation employed */ - } else if (nValue > 100.0) { - /* make sure to return the input hue */ - tmp.spec.TekHVC.H = hue; - /* avoid using fabs */ - ftmp1 = lastValue - savedValue; - if (ftmp1 < 0.0) - ftmp1 = -ftmp1; - ftmp2 = tmp.spec.TekHVC.V - savedValue; - if (ftmp2 < 0.0) - ftmp2 = -ftmp2; - if (ftmp1 < ftmp2) { - tmp.spec.TekHVC.V = lastValue; - tmp.spec.TekHVC.C = lastChroma; - } - if (_XcmsTekHVC_CheckModify (&tmp)) { - memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor)); - return(XcmsSuccess); - } else { - return(XcmsFailure); - } - } else if (tmp.spec.TekHVC.V <= prevValue + EPS && - tmp.spec.TekHVC.V >= prevValue - EPS) { - rFactor *= 0.5; /* selective relaxation employed */ - } - } - if (nCount >= nMaxCount) { - /* avoid using fabs */ - ftmp1 = lastValue - savedValue; - if (ftmp1 < 0.0) - ftmp1 = -ftmp1; - ftmp2 = tmp.spec.TekHVC.V - savedValue; - if (ftmp2 < 0.0) - ftmp2 = -ftmp2; - if (ftmp1 < ftmp2) { - tmp.spec.TekHVC.V = lastValue; - tmp.spec.TekHVC.C = lastChroma; - } - } - } - /* make sure to return the input hue */ - tmp.spec.TekHVC.H = hue; - memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor)); - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. TekColor is a
+ * trademark of Tektronix, Inc. The term "TekHVC" designates a particular
+ * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent
+ * foreign patents pending). Permission is hereby granted to use, copy,
+ * modify, sell, and otherwise distribute this software and its
+ * documentation for any purpose and without fee, provided that:
+ *
+ * 1. This copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and any modification thereof and in
+ * supporting documentation;
+ * 2. Any color-handling application which displays TekHVC color
+ * cooordinates identifies these as TekHVC color coordinates in any
+ * interface that displays these coordinates and in any associated
+ * documentation;
+ * 3. The term "TekHVC" is always used, and is only used, in association
+ * with the mathematical derivations of the TekHVC Color Space,
+ * including those provided in this file and any equivalent pathways and
+ * mathematical derivations, regardless of digital (e.g., floating point
+ * or integer) representation.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * TekHVCMxC.c
+ *
+ * DESCRIPTION
+ * Source for the XcmsTekHVCQueryMaxC() gamut boudary
+ * querying routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include <math.h>
+#include "Cv.h"
+
+/*
+ * DEFINES
+ */
+#define MAXBISECTCOUNT 100
+#define EPS 0.001
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsTekHVCQueryMaxC - Compute the maximum chroma for a hue and value
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsTekHVCQueryMaxC(
+ XcmsCCC ccc,
+ XcmsFloat hue,
+ XcmsFloat value,
+ XcmsColor *pColor_return)
+/*
+ * DESCRIPTION
+ * Return the maximum chroma for a specific hue and value.
+ * The returned format is in XcmsTekHVCFormat.
+ *
+ *
+ * ASSUMPTIONS
+ * This routine assumes that the white point associated with
+ * the color specification is the Screen White Point. The
+ * Screen White Point will also be associated with the
+ * returned color specification.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ XcmsCCCRec myCCC;
+ XcmsColor tmp;
+ XcmsColor max_vc;
+ XcmsRGBi rgb_saved;
+ int nCount, nMaxCount;
+ XcmsFloat nValue, savedValue, lastValue, lastChroma, prevValue;
+ XcmsFloat maxDist, nT, rFactor;
+ XcmsFloat ftmp1, ftmp2;
+
+ /*
+ * Check Arguments
+ */
+ if (ccc == NULL || pColor_return == NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Insure TekHVC installed
+ */
+ if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* Use my own CCC */
+ memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat; /* inherit screen white Pt */
+ myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut comp func */
+
+ tmp.spec.TekHVC.H = hue;
+ tmp.spec.TekHVC.V = value;
+ tmp.spec.TekHVC.C = 100.0;
+ tmp.pixel = pColor_return->pixel;
+ tmp.format = XcmsTekHVCFormat;
+
+ /* check to make sure we have a valid TekHVC number */
+ if (!_XcmsTekHVC_CheckModify(&tmp)) {
+ return(XcmsFailure);
+ }
+
+ /* Step 1: compute the maximum value and chroma for this hue. */
+ memcpy((char *)&max_vc, (char *)&tmp, sizeof(XcmsColor));
+ if (_XcmsTekHVCQueryMaxVCRGB(&myCCC, hue, &max_vc, &rgb_saved)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* Step 2: If the value is less than the value for the maximum */
+ /* value, chroma point then the chroma is on the line */
+ /* from max_vc to 0,0. */
+ if (value <= max_vc.spec.TekHVC.V) {
+ tmp.spec.TekHVC.C = value
+ * max_vc.spec.TekHVC.C / max_vc.spec.TekHVC.V;
+ if (_XcmsTekHVC_CheckModify (&tmp)) {
+ memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor));
+ return(XcmsSuccess);
+ } else {
+ return(XcmsFailure);
+ }
+ } else {
+ /* must do a bisection here to compute the maximum chroma */
+ /* save the structure input so that any elements that */
+ /* are not touched are recopied later in the routine. */
+ nValue = savedValue = value;
+ lastChroma = -1.0;
+ lastValue = -1.0;
+ nMaxCount = MAXBISECTCOUNT;
+ maxDist = 100.0 - max_vc.spec.TekHVC.V;
+ rFactor = 1.0;
+
+ for (nCount = 0; nCount < nMaxCount; nCount++) {
+ prevValue = lastValue;
+ lastValue = tmp.spec.TekHVC.V;
+ lastChroma = tmp.spec.TekHVC.C;
+ nT = (nValue - max_vc.spec.TekHVC.V) / maxDist * rFactor;
+ tmp.spec.RGBi.red = rgb_saved.red * (1.0 - nT) + nT;
+ tmp.spec.RGBi.green = rgb_saved.green * (1.0 - nT) + nT;
+ tmp.spec.RGBi.blue = rgb_saved.blue * (1.0 - nT) + nT;
+ tmp.format = XcmsRGBiFormat;
+
+ /* convert from RGB to HVC */
+ if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp,
+ &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* Now check the return against what is expected */
+ if (tmp.spec.TekHVC.V <= savedValue + EPS &&
+ tmp.spec.TekHVC.V >= savedValue - EPS) {
+ /* make sure to return the input hue */
+ tmp.spec.TekHVC.H = hue;
+ if (_XcmsTekHVC_CheckModify (&tmp)) {
+ memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor));
+ return(XcmsSuccess);
+ } else {
+ return(XcmsFailure);
+ }
+ }
+ nValue += savedValue - tmp.spec.TekHVC.V;
+ if (nValue < max_vc.spec.TekHVC.V) {
+ nValue = max_vc.spec.TekHVC.V;
+ rFactor *= 0.5; /* selective relaxation employed */
+ } else if (nValue > 100.0) {
+ /* make sure to return the input hue */
+ tmp.spec.TekHVC.H = hue;
+ /* avoid using fabs */
+ ftmp1 = lastValue - savedValue;
+ if (ftmp1 < 0.0)
+ ftmp1 = -ftmp1;
+ ftmp2 = tmp.spec.TekHVC.V - savedValue;
+ if (ftmp2 < 0.0)
+ ftmp2 = -ftmp2;
+ if (ftmp1 < ftmp2) {
+ tmp.spec.TekHVC.V = lastValue;
+ tmp.spec.TekHVC.C = lastChroma;
+ }
+ if (_XcmsTekHVC_CheckModify (&tmp)) {
+ memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor));
+ return(XcmsSuccess);
+ } else {
+ return(XcmsFailure);
+ }
+ } else if (tmp.spec.TekHVC.V <= prevValue + EPS &&
+ tmp.spec.TekHVC.V >= prevValue - EPS) {
+ rFactor *= 0.5; /* selective relaxation employed */
+ }
+ }
+ if (nCount >= nMaxCount) {
+ /* avoid using fabs */
+ ftmp1 = lastValue - savedValue;
+ if (ftmp1 < 0.0)
+ ftmp1 = -ftmp1;
+ ftmp2 = tmp.spec.TekHVC.V - savedValue;
+ if (ftmp2 < 0.0)
+ ftmp2 = -ftmp2;
+ if (ftmp1 < ftmp2) {
+ tmp.spec.TekHVC.V = lastValue;
+ tmp.spec.TekHVC.C = lastChroma;
+ }
+ }
+ }
+ /* make sure to return the input hue */
+ tmp.spec.TekHVC.H = hue;
+ memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor));
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/HVCMxV.c b/libX11/src/xcms/HVCMxV.c index d5ef94ec5..a0da9fa50 100644 --- a/libX11/src/xcms/HVCMxV.c +++ b/libX11/src/xcms/HVCMxV.c @@ -1,247 +1,247 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. TekColor is a - * trademark of Tektronix, Inc. The term "TekHVC" designates a particular - * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent - * foreign patents pending). Permission is hereby granted to use, copy, - * modify, sell, and otherwise distribute this software and its - * documentation for any purpose and without fee, provided that: - * - * 1. This copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and any modification thereof and in - * supporting documentation; - * 2. Any color-handling application which displays TekHVC color - * cooordinates identifies these as TekHVC color coordinates in any - * interface that displays these coordinates and in any associated - * documentation; - * 3. The term "TekHVC" is always used, and is only used, in association - * with the mathematical derivations of the TekHVC Color Space, - * including those provided in this file and any equivalent pathways and - * mathematical derivations, regardless of digital (e.g., floating point - * or integer) representation. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * TekHVCMxV.c - * - * DESCRIPTION - * Source for the XcmsTekHVCQueryMaxV() gamut boundary - * querying routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include <math.h> -#include "Cv.h" - -/* - * DEFINES - */ -#define MAXBISECTCOUNT 100 -#define EPS 0.001 - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsTekHVCQueryMaxV - Compute maximum value for a hue and chroma - * - * SYNOPSIS - */ -Status -XcmsTekHVCQueryMaxV( - XcmsCCC ccc, - XcmsFloat hue, - XcmsFloat chroma, - XcmsColor *pColor_return) -/* - * DESCRIPTION - * Return the maximum value for a specified hue and chroma. - * - * ASSUMPTIONS - * This routine assumes that the white point associated with - * the color specification is the Screen White Point. The - * Screen White Point will also be associated with the - * returned color specification. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded with no modifications - * - */ -{ - XcmsCCCRec myCCC; - XcmsColor tmp; - XcmsColor max_vc; - XcmsRGBi rgb_saved; - int nCount, nMaxCount; - XcmsFloat nT, nChroma, savedChroma, lastValue, lastChroma, prevChroma; - XcmsFloat rFactor; - XcmsFloat ftmp1, ftmp2; - - /* - * Check Arguments - */ - if (ccc == NULL || pColor_return == NULL) { - return(XcmsFailure); - } - - /* - * Insure TekHVC installed - */ - if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) { - return(XcmsFailure); - } - - /* setup the CCC to use for the conversions. */ - memcpy ((char *) &myCCC, (char *) ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat; - myCCC.gamutCompProc = (XcmsCompressionProc) NULL; - - tmp.spec.TekHVC.H = hue; - tmp.spec.TekHVC.V = 0.0; - tmp.spec.TekHVC.C = chroma; - tmp.pixel = pColor_return->pixel; - tmp.format = XcmsTekHVCFormat; - - if (!_XcmsTekHVC_CheckModify (&tmp)) { - return(XcmsFailure); - } - - /* Step 1: compute the maximum value and chroma for this hue. */ - /* This copy may be overkill but it preserves the pixel etc. */ - memcpy((char *)&max_vc, (char *)&tmp, sizeof(XcmsColor)); - hue = max_vc.spec.TekHVC.H; - if (_XcmsTekHVCQueryMaxVCRGB(&myCCC, max_vc.spec.TekHVC.H, &max_vc, &rgb_saved) - == XcmsFailure) { - return(XcmsFailure); - } - - if (max_vc.spec.TekHVC.C < tmp.spec.TekHVC.C) { - /* - * If the chroma is greater than the chroma for the - * maximum value/chroma point then the value is the - * the value for the maximum value, chroma point. - * This is an error but it I return the best approximation I can. - * Thus the inconsistency. - */ - tmp.spec.TekHVC.C = max_vc.spec.TekHVC.C; - tmp.spec.TekHVC.V = max_vc.spec.TekHVC.V; - memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor)); - return(XcmsSuccess); - } else if (max_vc.spec.TekHVC.C == tmp.spec.TekHVC.C) { - /* - * If the chroma is equal to the chroma for the - * maximum value/chroma point then the value is the - * the value for the maximum value, chroma point. - */ - tmp.spec.TekHVC.V = max_vc.spec.TekHVC.V; - memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor)); - return(XcmsSuccess); - } else { - /* must do a bisection here to compute the maximum value */ - /* save the structure input so that any elements that */ - /* are not touched are recopied later in the routine. */ - nChroma = savedChroma = tmp.spec.TekHVC.C; - tmp.spec.TekHVC.C = max_vc.spec.TekHVC.C; - tmp.spec.TekHVC.V = max_vc.spec.TekHVC.V; - lastChroma = -1.0; - lastValue = -1.0; - nMaxCount = MAXBISECTCOUNT; - rFactor = 1.0; - - for (nCount = 0; nCount < nMaxCount; nCount++) { - prevChroma = lastChroma; - lastValue = tmp.spec.TekHVC.V; - lastChroma = tmp.spec.TekHVC.C; - nT = (1.0 - (nChroma / max_vc.spec.TekHVC.C)) * rFactor; - tmp.spec.RGBi.red = rgb_saved.red * (1.0 - nT) + nT; - tmp.spec.RGBi.green = rgb_saved.green * (1.0 - nT) + nT; - tmp.spec.RGBi.blue = rgb_saved.blue * (1.0 - nT) + nT; - tmp.format = XcmsRGBiFormat; - - /* convert from RGB to HVC */ - if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp, - &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat, - (Bool *) NULL) == XcmsFailure) { - return(XcmsFailure); - } - - /* Now check the return against what is expected */ - if (tmp.spec.TekHVC.C <= savedChroma + EPS && - tmp.spec.TekHVC.C >= savedChroma - EPS) { - tmp.spec.TekHVC.H = hue; /* use the saved hue */ - memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor)); - return(XcmsSuccess); - } - nChroma += savedChroma - tmp.spec.TekHVC.C; - if (nChroma > max_vc.spec.TekHVC.C) { - nChroma = max_vc.spec.TekHVC.C; - rFactor *= 0.5; /* selective relaxation employed */ - } else if (nChroma < 0.0) { - /* avoid using fabs */ - ftmp1 = lastChroma - savedChroma; - if (ftmp1 < 0.0) - ftmp1 = -ftmp1; - ftmp2 = tmp.spec.TekHVC.C - savedChroma; - if (ftmp2 < 0.0) - ftmp2 = -ftmp2; - if (ftmp1 < ftmp2) { - tmp.spec.TekHVC.V = lastValue; - tmp.spec.TekHVC.C = lastChroma; - } - /* make sure to return the input hue */ - tmp.spec.TekHVC.H = hue; - if (!_XcmsTekHVC_CheckModify(&tmp)) { - return(XcmsFailure); - } - memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor)); - return(XcmsSuccess); - } else if (tmp.spec.TekHVC.C <= prevChroma + EPS && - tmp.spec.TekHVC.C >= prevChroma - EPS) { - rFactor *= 0.5; /* selective relaxation employed */ - } - } - if (nCount >= nMaxCount) { - /* avoid using fabs */ - ftmp1 = lastChroma - savedChroma; - if (ftmp1 < 0.0) - ftmp1 = -ftmp1; - ftmp2 = tmp.spec.TekHVC.C - savedChroma; - if (ftmp2 < 0.0) - ftmp2 = -ftmp2; - if (ftmp1 < ftmp2) { - tmp.spec.TekHVC.V = lastValue; - tmp.spec.TekHVC.C = lastChroma; - } - } - } - - /* make sure to return the input hue */ - tmp.spec.TekHVC.H = hue; - memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor)); - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. TekColor is a
+ * trademark of Tektronix, Inc. The term "TekHVC" designates a particular
+ * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent
+ * foreign patents pending). Permission is hereby granted to use, copy,
+ * modify, sell, and otherwise distribute this software and its
+ * documentation for any purpose and without fee, provided that:
+ *
+ * 1. This copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and any modification thereof and in
+ * supporting documentation;
+ * 2. Any color-handling application which displays TekHVC color
+ * cooordinates identifies these as TekHVC color coordinates in any
+ * interface that displays these coordinates and in any associated
+ * documentation;
+ * 3. The term "TekHVC" is always used, and is only used, in association
+ * with the mathematical derivations of the TekHVC Color Space,
+ * including those provided in this file and any equivalent pathways and
+ * mathematical derivations, regardless of digital (e.g., floating point
+ * or integer) representation.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * TekHVCMxV.c
+ *
+ * DESCRIPTION
+ * Source for the XcmsTekHVCQueryMaxV() gamut boundary
+ * querying routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include <math.h>
+#include "Cv.h"
+
+/*
+ * DEFINES
+ */
+#define MAXBISECTCOUNT 100
+#define EPS 0.001
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsTekHVCQueryMaxV - Compute maximum value for a hue and chroma
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsTekHVCQueryMaxV(
+ XcmsCCC ccc,
+ XcmsFloat hue,
+ XcmsFloat chroma,
+ XcmsColor *pColor_return)
+/*
+ * DESCRIPTION
+ * Return the maximum value for a specified hue and chroma.
+ *
+ * ASSUMPTIONS
+ * This routine assumes that the white point associated with
+ * the color specification is the Screen White Point. The
+ * Screen White Point will also be associated with the
+ * returned color specification.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded with no modifications
+ *
+ */
+{
+ XcmsCCCRec myCCC;
+ XcmsColor tmp;
+ XcmsColor max_vc;
+ XcmsRGBi rgb_saved;
+ int nCount, nMaxCount;
+ XcmsFloat nT, nChroma, savedChroma, lastValue, lastChroma, prevChroma;
+ XcmsFloat rFactor;
+ XcmsFloat ftmp1, ftmp2;
+
+ /*
+ * Check Arguments
+ */
+ if (ccc == NULL || pColor_return == NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Insure TekHVC installed
+ */
+ if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* setup the CCC to use for the conversions. */
+ memcpy ((char *) &myCCC, (char *) ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;
+ myCCC.gamutCompProc = (XcmsCompressionProc) NULL;
+
+ tmp.spec.TekHVC.H = hue;
+ tmp.spec.TekHVC.V = 0.0;
+ tmp.spec.TekHVC.C = chroma;
+ tmp.pixel = pColor_return->pixel;
+ tmp.format = XcmsTekHVCFormat;
+
+ if (!_XcmsTekHVC_CheckModify (&tmp)) {
+ return(XcmsFailure);
+ }
+
+ /* Step 1: compute the maximum value and chroma for this hue. */
+ /* This copy may be overkill but it preserves the pixel etc. */
+ memcpy((char *)&max_vc, (char *)&tmp, sizeof(XcmsColor));
+ hue = max_vc.spec.TekHVC.H;
+ if (_XcmsTekHVCQueryMaxVCRGB(&myCCC, max_vc.spec.TekHVC.H, &max_vc, &rgb_saved)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ if (max_vc.spec.TekHVC.C < tmp.spec.TekHVC.C) {
+ /*
+ * If the chroma is greater than the chroma for the
+ * maximum value/chroma point then the value is the
+ * the value for the maximum value, chroma point.
+ * This is an error but it I return the best approximation I can.
+ * Thus the inconsistency.
+ */
+ tmp.spec.TekHVC.C = max_vc.spec.TekHVC.C;
+ tmp.spec.TekHVC.V = max_vc.spec.TekHVC.V;
+ memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor));
+ return(XcmsSuccess);
+ } else if (max_vc.spec.TekHVC.C == tmp.spec.TekHVC.C) {
+ /*
+ * If the chroma is equal to the chroma for the
+ * maximum value/chroma point then the value is the
+ * the value for the maximum value, chroma point.
+ */
+ tmp.spec.TekHVC.V = max_vc.spec.TekHVC.V;
+ memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor));
+ return(XcmsSuccess);
+ } else {
+ /* must do a bisection here to compute the maximum value */
+ /* save the structure input so that any elements that */
+ /* are not touched are recopied later in the routine. */
+ nChroma = savedChroma = tmp.spec.TekHVC.C;
+ tmp.spec.TekHVC.C = max_vc.spec.TekHVC.C;
+ tmp.spec.TekHVC.V = max_vc.spec.TekHVC.V;
+ lastChroma = -1.0;
+ lastValue = -1.0;
+ nMaxCount = MAXBISECTCOUNT;
+ rFactor = 1.0;
+
+ for (nCount = 0; nCount < nMaxCount; nCount++) {
+ prevChroma = lastChroma;
+ lastValue = tmp.spec.TekHVC.V;
+ lastChroma = tmp.spec.TekHVC.C;
+ nT = (1.0 - (nChroma / max_vc.spec.TekHVC.C)) * rFactor;
+ tmp.spec.RGBi.red = rgb_saved.red * (1.0 - nT) + nT;
+ tmp.spec.RGBi.green = rgb_saved.green * (1.0 - nT) + nT;
+ tmp.spec.RGBi.blue = rgb_saved.blue * (1.0 - nT) + nT;
+ tmp.format = XcmsRGBiFormat;
+
+ /* convert from RGB to HVC */
+ if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp,
+ &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* Now check the return against what is expected */
+ if (tmp.spec.TekHVC.C <= savedChroma + EPS &&
+ tmp.spec.TekHVC.C >= savedChroma - EPS) {
+ tmp.spec.TekHVC.H = hue; /* use the saved hue */
+ memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor));
+ return(XcmsSuccess);
+ }
+ nChroma += savedChroma - tmp.spec.TekHVC.C;
+ if (nChroma > max_vc.spec.TekHVC.C) {
+ nChroma = max_vc.spec.TekHVC.C;
+ rFactor *= 0.5; /* selective relaxation employed */
+ } else if (nChroma < 0.0) {
+ /* avoid using fabs */
+ ftmp1 = lastChroma - savedChroma;
+ if (ftmp1 < 0.0)
+ ftmp1 = -ftmp1;
+ ftmp2 = tmp.spec.TekHVC.C - savedChroma;
+ if (ftmp2 < 0.0)
+ ftmp2 = -ftmp2;
+ if (ftmp1 < ftmp2) {
+ tmp.spec.TekHVC.V = lastValue;
+ tmp.spec.TekHVC.C = lastChroma;
+ }
+ /* make sure to return the input hue */
+ tmp.spec.TekHVC.H = hue;
+ if (!_XcmsTekHVC_CheckModify(&tmp)) {
+ return(XcmsFailure);
+ }
+ memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor));
+ return(XcmsSuccess);
+ } else if (tmp.spec.TekHVC.C <= prevChroma + EPS &&
+ tmp.spec.TekHVC.C >= prevChroma - EPS) {
+ rFactor *= 0.5; /* selective relaxation employed */
+ }
+ }
+ if (nCount >= nMaxCount) {
+ /* avoid using fabs */
+ ftmp1 = lastChroma - savedChroma;
+ if (ftmp1 < 0.0)
+ ftmp1 = -ftmp1;
+ ftmp2 = tmp.spec.TekHVC.C - savedChroma;
+ if (ftmp2 < 0.0)
+ ftmp2 = -ftmp2;
+ if (ftmp1 < ftmp2) {
+ tmp.spec.TekHVC.V = lastValue;
+ tmp.spec.TekHVC.C = lastChroma;
+ }
+ }
+ }
+
+ /* make sure to return the input hue */
+ tmp.spec.TekHVC.H = hue;
+ memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor));
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/HVCMxVC.c b/libX11/src/xcms/HVCMxVC.c index c7e087866..729ee12bf 100644 --- a/libX11/src/xcms/HVCMxVC.c +++ b/libX11/src/xcms/HVCMxVC.c @@ -1,235 +1,235 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. TekColor is a - * trademark of Tektronix, Inc. The term "TekHVC" designates a particular - * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent - * foreign patents pending). Permission is hereby granted to use, copy, - * modify, sell, and otherwise distribute this software and its - * documentation for any purpose and without fee, provided that: - * - * 1. This copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and any modification thereof and in - * supporting documentation; - * 2. Any color-handling application which displays TekHVC color - * cooordinates identifies these as TekHVC color coordinates in any - * interface that displays these coordinates and in any associated - * documentation; - * 3. The term "TekHVC" is always used, and is only used, in association - * with the mathematical derivations of the TekHVC Color Space, - * including those provided in this file and any equivalent pathways and - * mathematical derivations, regardless of digital (e.g., floating point - * or integer) representation. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * TekHVCMxVC.c - * - * DESCRIPTION - * Source for the XcmsTekHVCQueryMaxVC() gamut boundary - * querying routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - -/* - * DEFINES - */ -#define MIN(x,y) ((x) > (y) ? (y) : (x)) -#define MIN3(x,y,z) ((x) > (MIN((y), (z))) ? (MIN((y), (z))) : (x)) -#define MAX(x,y) ((x) > (y) ? (x) : (y)) -#define MAX3(x,y,z) ((x) > (MAX((y), (z))) ? (x) : (MAX((y), (z)))) -#define START_V 40.0 -#define START_C 120.0 - - -/************************************************************************ - * * - * API PRIVATE ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * _XcmsTekHVCQueryMaxVCRGB - Compute maximum value/chroma. - * - * SYNOPSIS - */ -Status -_XcmsTekHVCQueryMaxVCRGB( - XcmsCCC ccc, - XcmsFloat hue, - XcmsColor *pColor_return, - XcmsRGBi *pRGB_return) - -/* - * DESCRIPTION - * Return the maximum chroma for a specified hue, and the - * corresponding value. This is computed by a binary search of - * all possible chromas. An assumption is made that there are - * no local maxima. Use the unrounded Max Chroma because - * the difference check can be small. - * - * NOTE: No local CCC is used because this is a private - * routine and all routines that call it are expected - * to behave properly, i.e. send a local CCC with - * no white adjust function and no gamut compression - * function. - * - * This routine only accepts hue as input and outputs - * HVC's and RGBi's. - * - * RETURNS - * XcmsFailure - Failure - * XCMS_SUCCUSS - Succeeded - * - */ -{ - XcmsFloat nSmall, nLarge; - XcmsColor tmp; - - tmp.format = XcmsTekHVCFormat; - tmp.spec.TekHVC.H = hue; - /* Use some unreachable color on the given hue */ - tmp.spec.TekHVC.V = START_V; - tmp.spec.TekHVC.C = START_C; - - - /* - * Convert from HVC to RGB - * - * Note that the CIEXYZ to RGBi conversion routine must stuff the - * out of bounds RGBi values in tmp when the ccc->gamutCompProc - * is NULL. - */ - if ((_XcmsConvertColorsWithWhitePt(ccc, &tmp, - &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsRGBiFormat, (Bool *) NULL) - == XcmsFailure) && tmp.format != XcmsRGBiFormat) { - return (XcmsFailure); - } - - /* Now pick the smallest RGB */ - nSmall = MIN3(tmp.spec.RGBi.red, - tmp.spec.RGBi.green, - tmp.spec.RGBi.blue); - /* Make the smallest RGB equal to zero */ - tmp.spec.RGBi.red -= nSmall; - tmp.spec.RGBi.green -= nSmall; - tmp.spec.RGBi.blue -= nSmall; - - /* Now pick the largest RGB */ - nLarge = MAX3(tmp.spec.RGBi.red, - tmp.spec.RGBi.green, - tmp.spec.RGBi.blue); - /* Scale the RGB values based on the largest one */ - tmp.spec.RGBi.red /= nLarge; - tmp.spec.RGBi.green /= nLarge; - tmp.spec.RGBi.blue /= nLarge; - tmp.format = XcmsRGBiFormat; - - /* If the calling routine wants RGB value give them the ones used. */ - if (pRGB_return) { - pRGB_return->red = tmp.spec.RGBi.red; - pRGB_return->green = tmp.spec.RGBi.green; - pRGB_return->blue = tmp.spec.RGBi.blue; - } - - /* Convert from RGBi to HVC */ - if (_XcmsConvertColorsWithWhitePt(ccc, &tmp, - &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat, (Bool *) NULL) - == XcmsFailure) { - return (XcmsFailure); - } - - /* make sure to return the input hue */ - tmp.spec.TekHVC.H = hue; - memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor)); - return (XcmsSuccess); -} - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsTekHVCQueryMaxVC - Compute maximum value and chroma. - * - * SYNOPSIS - */ -Status -XcmsTekHVCQueryMaxVC ( - XcmsCCC ccc, - XcmsFloat hue, - XcmsColor *pColor_return) - -/* - * DESCRIPTION - * Return the maximum chroma for the specified hue, and the - * corresponding value. - * - * ASSUMPTIONS - * This routine assumes that the white point associated with - * the color specification is the Screen White Point. The - * Screen White Point will also be associated with the - * returned color specification. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - XcmsCCCRec myCCC; - - /* - * Check Arguments - */ - if (ccc == NULL || pColor_return == NULL) { - return(XcmsFailure); - } - - /* - * Insure TekHVC installed - */ - if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) { - return(XcmsFailure); - } - - /* Use my own CCC */ - memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat; - myCCC.gamutCompProc = (XcmsCompressionProc)NULL; - - while (hue < 0.0) { - hue += 360.0; - } - while (hue >= 360.0) { - hue -= 360.0; - } - - return(_XcmsTekHVCQueryMaxVCRGB (&myCCC, hue, pColor_return, - (XcmsRGBi *)NULL)); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. TekColor is a
+ * trademark of Tektronix, Inc. The term "TekHVC" designates a particular
+ * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent
+ * foreign patents pending). Permission is hereby granted to use, copy,
+ * modify, sell, and otherwise distribute this software and its
+ * documentation for any purpose and without fee, provided that:
+ *
+ * 1. This copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and any modification thereof and in
+ * supporting documentation;
+ * 2. Any color-handling application which displays TekHVC color
+ * cooordinates identifies these as TekHVC color coordinates in any
+ * interface that displays these coordinates and in any associated
+ * documentation;
+ * 3. The term "TekHVC" is always used, and is only used, in association
+ * with the mathematical derivations of the TekHVC Color Space,
+ * including those provided in this file and any equivalent pathways and
+ * mathematical derivations, regardless of digital (e.g., floating point
+ * or integer) representation.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * TekHVCMxVC.c
+ *
+ * DESCRIPTION
+ * Source for the XcmsTekHVCQueryMaxVC() gamut boundary
+ * querying routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+/*
+ * DEFINES
+ */
+#define MIN(x,y) ((x) > (y) ? (y) : (x))
+#define MIN3(x,y,z) ((x) > (MIN((y), (z))) ? (MIN((y), (z))) : (x))
+#define MAX(x,y) ((x) > (y) ? (x) : (y))
+#define MAX3(x,y,z) ((x) > (MAX((y), (z))) ? (x) : (MAX((y), (z))))
+#define START_V 40.0
+#define START_C 120.0
+
+
+/************************************************************************
+ * *
+ * API PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * _XcmsTekHVCQueryMaxVCRGB - Compute maximum value/chroma.
+ *
+ * SYNOPSIS
+ */
+Status
+_XcmsTekHVCQueryMaxVCRGB(
+ XcmsCCC ccc,
+ XcmsFloat hue,
+ XcmsColor *pColor_return,
+ XcmsRGBi *pRGB_return)
+
+/*
+ * DESCRIPTION
+ * Return the maximum chroma for a specified hue, and the
+ * corresponding value. This is computed by a binary search of
+ * all possible chromas. An assumption is made that there are
+ * no local maxima. Use the unrounded Max Chroma because
+ * the difference check can be small.
+ *
+ * NOTE: No local CCC is used because this is a private
+ * routine and all routines that call it are expected
+ * to behave properly, i.e. send a local CCC with
+ * no white adjust function and no gamut compression
+ * function.
+ *
+ * This routine only accepts hue as input and outputs
+ * HVC's and RGBi's.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XCMS_SUCCUSS - Succeeded
+ *
+ */
+{
+ XcmsFloat nSmall, nLarge;
+ XcmsColor tmp;
+
+ tmp.format = XcmsTekHVCFormat;
+ tmp.spec.TekHVC.H = hue;
+ /* Use some unreachable color on the given hue */
+ tmp.spec.TekHVC.V = START_V;
+ tmp.spec.TekHVC.C = START_C;
+
+
+ /*
+ * Convert from HVC to RGB
+ *
+ * Note that the CIEXYZ to RGBi conversion routine must stuff the
+ * out of bounds RGBi values in tmp when the ccc->gamutCompProc
+ * is NULL.
+ */
+ if ((_XcmsConvertColorsWithWhitePt(ccc, &tmp,
+ &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsRGBiFormat, (Bool *) NULL)
+ == XcmsFailure) && tmp.format != XcmsRGBiFormat) {
+ return (XcmsFailure);
+ }
+
+ /* Now pick the smallest RGB */
+ nSmall = MIN3(tmp.spec.RGBi.red,
+ tmp.spec.RGBi.green,
+ tmp.spec.RGBi.blue);
+ /* Make the smallest RGB equal to zero */
+ tmp.spec.RGBi.red -= nSmall;
+ tmp.spec.RGBi.green -= nSmall;
+ tmp.spec.RGBi.blue -= nSmall;
+
+ /* Now pick the largest RGB */
+ nLarge = MAX3(tmp.spec.RGBi.red,
+ tmp.spec.RGBi.green,
+ tmp.spec.RGBi.blue);
+ /* Scale the RGB values based on the largest one */
+ tmp.spec.RGBi.red /= nLarge;
+ tmp.spec.RGBi.green /= nLarge;
+ tmp.spec.RGBi.blue /= nLarge;
+ tmp.format = XcmsRGBiFormat;
+
+ /* If the calling routine wants RGB value give them the ones used. */
+ if (pRGB_return) {
+ pRGB_return->red = tmp.spec.RGBi.red;
+ pRGB_return->green = tmp.spec.RGBi.green;
+ pRGB_return->blue = tmp.spec.RGBi.blue;
+ }
+
+ /* Convert from RGBi to HVC */
+ if (_XcmsConvertColorsWithWhitePt(ccc, &tmp,
+ &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat, (Bool *) NULL)
+ == XcmsFailure) {
+ return (XcmsFailure);
+ }
+
+ /* make sure to return the input hue */
+ tmp.spec.TekHVC.H = hue;
+ memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor));
+ return (XcmsSuccess);
+}
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsTekHVCQueryMaxVC - Compute maximum value and chroma.
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsTekHVCQueryMaxVC (
+ XcmsCCC ccc,
+ XcmsFloat hue,
+ XcmsColor *pColor_return)
+
+/*
+ * DESCRIPTION
+ * Return the maximum chroma for the specified hue, and the
+ * corresponding value.
+ *
+ * ASSUMPTIONS
+ * This routine assumes that the white point associated with
+ * the color specification is the Screen White Point. The
+ * Screen White Point will also be associated with the
+ * returned color specification.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ XcmsCCCRec myCCC;
+
+ /*
+ * Check Arguments
+ */
+ if (ccc == NULL || pColor_return == NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Insure TekHVC installed
+ */
+ if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* Use my own CCC */
+ memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;
+ myCCC.gamutCompProc = (XcmsCompressionProc)NULL;
+
+ while (hue < 0.0) {
+ hue += 360.0;
+ }
+ while (hue >= 360.0) {
+ hue -= 360.0;
+ }
+
+ return(_XcmsTekHVCQueryMaxVCRGB (&myCCC, hue, pColor_return,
+ (XcmsRGBi *)NULL));
+}
diff --git a/libX11/src/xcms/HVCMxVs.c b/libX11/src/xcms/HVCMxVs.c index 540e5c2f4..2bd2bfacc 100644 --- a/libX11/src/xcms/HVCMxVs.c +++ b/libX11/src/xcms/HVCMxVs.c @@ -1,161 +1,161 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. TekColor is a - * trademark of Tektronix, Inc. The term "TekHVC" designates a particular - * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent - * foreign patents pending). Permission is hereby granted to use, copy, - * modify, sell, and otherwise distribute this software and its - * documentation for any purpose and without fee, provided that: - * - * 1. This copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and any modification thereof and in - * supporting documentation; - * 2. Any color-handling application which displays TekHVC color - * cooordinates identifies these as TekHVC color coordinates in any - * interface that displays these coordinates and in any associated - * documentation; - * 3. The term "TekHVC" is always used, and is only used, in association - * with the mathematical derivations of the TekHVC Color Space, - * including those provided in this file and any equivalent pathways and - * mathematical derivations, regardless of digital (e.g., floating point - * or integer) representation. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * TekHVCMxVs.c - * - * DESCRIPTION - * Source for the XcmsTekHVCQueryMaxVSamples() gamut boundary - * querying routine. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsTekHVCQueryMaxVSamples - Compute a set of value/chroma - * pairs. - * - * SYNOPSIS - */ -Status -XcmsTekHVCQueryMaxVSamples( - XcmsCCC ccc, - XcmsFloat hue, - XcmsColor *pColor_in_out, - unsigned int nSamples) - -/* - * DESCRIPTION - * Return a set of values and chromas for the input Hue. - * This routine will take any color as input. - * It returns TekHVC colors. - * - * Since this routine works with the value within - * pColor_in_out intermediate results may be returned - * even though it may be invalid. - * - * ASSUMPTIONS - * This routine assumes that the white point associated with - * the color specification is the Screen White Point. The - * Screen White Point will also be associated with the - * returned color specification. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - XcmsCCCRec myCCC; - XcmsColor *pHVC; - XcmsRGBi rgb_saved; - unsigned short nI; - XcmsFloat nT; - - /* - * Check Arguments - */ - if (ccc == NULL || pColor_in_out == NULL || nSamples == 0) { - return(XcmsFailure); - } - - /* - * Insure TekHVC installed - */ - if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) { - return(XcmsFailure); - } - - /* setup the CCC to use for the conversions. */ - memcpy ((char *) &myCCC, (char *) ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat; - myCCC.gamutCompProc = (XcmsCompressionProc) NULL; - - /* Step 1: compute the maximum value and chroma for this hue. */ - - - /* save the Hue for use later. */ - while (hue < 0.0) { - hue += 360.0; - } - while (hue > 360.0) { - hue -= 360.0; - } - pColor_in_out->spec.TekHVC.H = hue; - pColor_in_out->format = XcmsTekHVCFormat; - - /* Get the maximum value and chroma point for this hue */ - if (_XcmsTekHVCQueryMaxVCRGB(&myCCC, pColor_in_out->spec.TekHVC.H, - pColor_in_out, (XcmsRGBi *)&rgb_saved) == XcmsFailure) { - return (XcmsFailure); - } - - /* Step 2: Convert each of the RGBi's to HVC's */ - pHVC = pColor_in_out; - for (nI = 0; nI < nSamples; nI++, pHVC++) { - nT = (XcmsFloat) nI / (XcmsFloat) nSamples; - pHVC->spec.RGBi.red = rgb_saved.red * (1.0 - nT) + nT; - pHVC->spec.RGBi.green = rgb_saved.green * (1.0 - nT) + nT; - pHVC->spec.RGBi.blue = rgb_saved.blue * (1.0 - nT) + nT; - pHVC->format = XcmsRGBiFormat; - pHVC->pixel = pColor_in_out->pixel; - /* convert from RGB to HVC */ - if (_XcmsConvertColorsWithWhitePt(&myCCC, pHVC, - &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat, - (Bool *) NULL) == XcmsFailure) { - return(XcmsFailure); - } - - /* make sure to return the input hue */ - pHVC->spec.TekHVC.H = hue; - } - - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. TekColor is a
+ * trademark of Tektronix, Inc. The term "TekHVC" designates a particular
+ * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent
+ * foreign patents pending). Permission is hereby granted to use, copy,
+ * modify, sell, and otherwise distribute this software and its
+ * documentation for any purpose and without fee, provided that:
+ *
+ * 1. This copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and any modification thereof and in
+ * supporting documentation;
+ * 2. Any color-handling application which displays TekHVC color
+ * cooordinates identifies these as TekHVC color coordinates in any
+ * interface that displays these coordinates and in any associated
+ * documentation;
+ * 3. The term "TekHVC" is always used, and is only used, in association
+ * with the mathematical derivations of the TekHVC Color Space,
+ * including those provided in this file and any equivalent pathways and
+ * mathematical derivations, regardless of digital (e.g., floating point
+ * or integer) representation.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * TekHVCMxVs.c
+ *
+ * DESCRIPTION
+ * Source for the XcmsTekHVCQueryMaxVSamples() gamut boundary
+ * querying routine.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsTekHVCQueryMaxVSamples - Compute a set of value/chroma
+ * pairs.
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsTekHVCQueryMaxVSamples(
+ XcmsCCC ccc,
+ XcmsFloat hue,
+ XcmsColor *pColor_in_out,
+ unsigned int nSamples)
+
+/*
+ * DESCRIPTION
+ * Return a set of values and chromas for the input Hue.
+ * This routine will take any color as input.
+ * It returns TekHVC colors.
+ *
+ * Since this routine works with the value within
+ * pColor_in_out intermediate results may be returned
+ * even though it may be invalid.
+ *
+ * ASSUMPTIONS
+ * This routine assumes that the white point associated with
+ * the color specification is the Screen White Point. The
+ * Screen White Point will also be associated with the
+ * returned color specification.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ XcmsCCCRec myCCC;
+ XcmsColor *pHVC;
+ XcmsRGBi rgb_saved;
+ unsigned short nI;
+ XcmsFloat nT;
+
+ /*
+ * Check Arguments
+ */
+ if (ccc == NULL || pColor_in_out == NULL || nSamples == 0) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Insure TekHVC installed
+ */
+ if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* setup the CCC to use for the conversions. */
+ memcpy ((char *) &myCCC, (char *) ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;
+ myCCC.gamutCompProc = (XcmsCompressionProc) NULL;
+
+ /* Step 1: compute the maximum value and chroma for this hue. */
+
+
+ /* save the Hue for use later. */
+ while (hue < 0.0) {
+ hue += 360.0;
+ }
+ while (hue > 360.0) {
+ hue -= 360.0;
+ }
+ pColor_in_out->spec.TekHVC.H = hue;
+ pColor_in_out->format = XcmsTekHVCFormat;
+
+ /* Get the maximum value and chroma point for this hue */
+ if (_XcmsTekHVCQueryMaxVCRGB(&myCCC, pColor_in_out->spec.TekHVC.H,
+ pColor_in_out, (XcmsRGBi *)&rgb_saved) == XcmsFailure) {
+ return (XcmsFailure);
+ }
+
+ /* Step 2: Convert each of the RGBi's to HVC's */
+ pHVC = pColor_in_out;
+ for (nI = 0; nI < nSamples; nI++, pHVC++) {
+ nT = (XcmsFloat) nI / (XcmsFloat) nSamples;
+ pHVC->spec.RGBi.red = rgb_saved.red * (1.0 - nT) + nT;
+ pHVC->spec.RGBi.green = rgb_saved.green * (1.0 - nT) + nT;
+ pHVC->spec.RGBi.blue = rgb_saved.blue * (1.0 - nT) + nT;
+ pHVC->format = XcmsRGBiFormat;
+ pHVC->pixel = pColor_in_out->pixel;
+ /* convert from RGB to HVC */
+ if (_XcmsConvertColorsWithWhitePt(&myCCC, pHVC,
+ &myCCC.pPerScrnInfo->screenWhitePt, 1, XcmsTekHVCFormat,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* make sure to return the input hue */
+ pHVC->spec.TekHVC.H = hue;
+ }
+
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/HVCWpAj.c b/libX11/src/xcms/HVCWpAj.c index dcefe7535..d77b2b0ef 100644 --- a/libX11/src/xcms/HVCWpAj.c +++ b/libX11/src/xcms/HVCWpAj.c @@ -1,114 +1,114 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. TekColor is a - * trademark of Tektronix, Inc. The term "TekHVC" designates a particular - * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent - * foreign patents pending). Permission is hereby granted to use, copy, - * modify, sell, and otherwise distribute this software and its - * documentation for any purpose and without fee, provided that: - * - * 1. This copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and any modification thereof and in - * supporting documentation; - * 2. Any color-handling application which displays TekHVC color - * cooordinates identifies these as TekHVC color coordinates in any - * interface that displays these coordinates and in any associated - * documentation; - * 3. The term "TekHVC" is always used, and is only used, in association - * with the mathematical derivations of the TekHVC Color Space, - * including those provided in this file and any equivalent pathways and - * mathematical derivations, regardless of digital (e.g., floating point - * or integer) representation. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * DESCRIPTION - * TekHVCWpAj.c - * - * DESCRIPTION - * This file contains routine(s) that support white point - * adjustment of color specifications in the TekHVC color - * space. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsTekHVCWhiteShiftColors - * - * SYNOPSIS - */ -Status -XcmsTekHVCWhiteShiftColors( - XcmsCCC ccc, - XcmsColor *pWhitePtFrom, - XcmsColor *pWhitePtTo, - XcmsColorFormat destSpecFmt, - XcmsColor *pColors_in_out, - unsigned int nColors, - Bool *pCompressed) -/* - * DESCRIPTION - * Convert color specifications in an array of XcmsColor structures - * for differences in white points. - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if succeeded without gamut compression, - * XcmsSuccessWithCompression if succeeded with - * gamut compression. - */ -{ - if (pWhitePtFrom == NULL || pWhitePtTo == NULL || pColors_in_out == NULL) { - return(XcmsFailure); - } - - /* - * Insure TekHVC installed - */ - if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) { - return(XcmsFailure); - } - - /* - * Convert to TekHVC using pWhitePtFrom - * We can ignore return value for compression because we are converting - * to XcmsTekHVCFormat which is device-independent, not device-dependent. - */ - if (_XcmsConvertColorsWithWhitePt(ccc, pColors_in_out, pWhitePtFrom, - nColors, XcmsTekHVCFormat, pCompressed) == XcmsFailure) { - return(XcmsFailure); - } - - /* - * Convert from TekHVC to destSpecFmt using pWhitePtTo - */ - return(_XcmsConvertColorsWithWhitePt(ccc, pColors_in_out, pWhitePtTo, - nColors, destSpecFmt, pCompressed)); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. TekColor is a
+ * trademark of Tektronix, Inc. The term "TekHVC" designates a particular
+ * color space that is the subject of U.S. Patent No. 4,985,853 (equivalent
+ * foreign patents pending). Permission is hereby granted to use, copy,
+ * modify, sell, and otherwise distribute this software and its
+ * documentation for any purpose and without fee, provided that:
+ *
+ * 1. This copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and any modification thereof and in
+ * supporting documentation;
+ * 2. Any color-handling application which displays TekHVC color
+ * cooordinates identifies these as TekHVC color coordinates in any
+ * interface that displays these coordinates and in any associated
+ * documentation;
+ * 3. The term "TekHVC" is always used, and is only used, in association
+ * with the mathematical derivations of the TekHVC Color Space,
+ * including those provided in this file and any equivalent pathways and
+ * mathematical derivations, regardless of digital (e.g., floating point
+ * or integer) representation.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * DESCRIPTION
+ * TekHVCWpAj.c
+ *
+ * DESCRIPTION
+ * This file contains routine(s) that support white point
+ * adjustment of color specifications in the TekHVC color
+ * space.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsTekHVCWhiteShiftColors
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsTekHVCWhiteShiftColors(
+ XcmsCCC ccc,
+ XcmsColor *pWhitePtFrom,
+ XcmsColor *pWhitePtTo,
+ XcmsColorFormat destSpecFmt,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * Convert color specifications in an array of XcmsColor structures
+ * for differences in white points.
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if succeeded without gamut compression,
+ * XcmsSuccessWithCompression if succeeded with
+ * gamut compression.
+ */
+{
+ if (pWhitePtFrom == NULL || pWhitePtTo == NULL || pColors_in_out == NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Insure TekHVC installed
+ */
+ if (XcmsAddColorSpace(&XcmsTekHVCColorSpace) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Convert to TekHVC using pWhitePtFrom
+ * We can ignore return value for compression because we are converting
+ * to XcmsTekHVCFormat which is device-independent, not device-dependent.
+ */
+ if (_XcmsConvertColorsWithWhitePt(ccc, pColors_in_out, pWhitePtFrom,
+ nColors, XcmsTekHVCFormat, pCompressed) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Convert from TekHVC to destSpecFmt using pWhitePtTo
+ */
+ return(_XcmsConvertColorsWithWhitePt(ccc, pColors_in_out, pWhitePtTo,
+ nColors, destSpecFmt, pCompressed));
+}
diff --git a/libX11/src/xcms/IdOfPr.c b/libX11/src/xcms/IdOfPr.c index 3a92e0a11..9da2d3bd2 100644 --- a/libX11/src/xcms/IdOfPr.c +++ b/libX11/src/xcms/IdOfPr.c @@ -1,106 +1,106 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsIdOfPr.c - * - * DESCRIPTION - * Source for XcmsFormatOfPrefix() - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/* - * NAME - * XcmsFormatOfPrefix - * - * SYNOPSIS - */ -XcmsColorFormat -XcmsFormatOfPrefix(char *prefix) -/* - * DESCRIPTION - * Returns the Color Space ID for the specified prefix - * if the color space is found in the Color Conversion - * Context. - * - * RETURNS - * Color Space ID if found; zero otherwise. - */ -{ - XcmsColorSpace **papColorSpaces; - char string_buf[64]; - char *string_lowered; - int len; - - /* - * While copying prefix to string_lowered, convert to lowercase - */ - if ((len = strlen(prefix)) >= sizeof(string_buf)) { - string_lowered = (char *) Xmalloc(len+1); - } else { - string_lowered = string_buf; - } - _XcmsCopyISOLatin1Lowered(string_lowered, prefix); - - /* - * First try Device-Independent color spaces - */ - papColorSpaces = _XcmsDIColorSpaces; - if (papColorSpaces != NULL) { - while (*papColorSpaces != NULL) { - if (strcmp((*papColorSpaces)->prefix, string_lowered) == 0) { - if (len >= sizeof(string_buf)) Xfree(string_lowered); - return((*papColorSpaces)->id); - } - papColorSpaces++; - } - } - - /* - * Next try Device-Dependent color spaces - */ - papColorSpaces = _XcmsDDColorSpaces; - if (papColorSpaces != NULL) { - while (*papColorSpaces != NULL) { - if (strcmp((*papColorSpaces)->prefix, string_lowered) == 0) { - if (len >= sizeof(string_buf)) Xfree(string_lowered); - return((*papColorSpaces)->id); - } - papColorSpaces++; - } - } - - if (len >= sizeof(string_buf)) Xfree(string_lowered); - return(XcmsUndefinedFormat); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsIdOfPr.c
+ *
+ * DESCRIPTION
+ * Source for XcmsFormatOfPrefix()
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/*
+ * NAME
+ * XcmsFormatOfPrefix
+ *
+ * SYNOPSIS
+ */
+XcmsColorFormat
+XcmsFormatOfPrefix(char *prefix)
+/*
+ * DESCRIPTION
+ * Returns the Color Space ID for the specified prefix
+ * if the color space is found in the Color Conversion
+ * Context.
+ *
+ * RETURNS
+ * Color Space ID if found; zero otherwise.
+ */
+{
+ XcmsColorSpace **papColorSpaces;
+ char string_buf[64];
+ char *string_lowered;
+ int len;
+
+ /*
+ * While copying prefix to string_lowered, convert to lowercase
+ */
+ if ((len = strlen(prefix)) >= sizeof(string_buf)) {
+ string_lowered = (char *) Xmalloc(len+1);
+ } else {
+ string_lowered = string_buf;
+ }
+ _XcmsCopyISOLatin1Lowered(string_lowered, prefix);
+
+ /*
+ * First try Device-Independent color spaces
+ */
+ papColorSpaces = _XcmsDIColorSpaces;
+ if (papColorSpaces != NULL) {
+ while (*papColorSpaces != NULL) {
+ if (strcmp((*papColorSpaces)->prefix, string_lowered) == 0) {
+ if (len >= sizeof(string_buf)) Xfree(string_lowered);
+ return((*papColorSpaces)->id);
+ }
+ papColorSpaces++;
+ }
+ }
+
+ /*
+ * Next try Device-Dependent color spaces
+ */
+ papColorSpaces = _XcmsDDColorSpaces;
+ if (papColorSpaces != NULL) {
+ while (*papColorSpaces != NULL) {
+ if (strcmp((*papColorSpaces)->prefix, string_lowered) == 0) {
+ if (len >= sizeof(string_buf)) Xfree(string_lowered);
+ return((*papColorSpaces)->id);
+ }
+ papColorSpaces++;
+ }
+ }
+
+ if (len >= sizeof(string_buf)) Xfree(string_lowered);
+ return(XcmsUndefinedFormat);
+}
diff --git a/libX11/src/xcms/Lab.c b/libX11/src/xcms/Lab.c index 02c8d3b7c..1101754d4 100644 --- a/libX11/src/xcms/Lab.c +++ b/libX11/src/xcms/Lab.c @@ -1,431 +1,431 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * CIELab.c - * - * DESCRIPTION - * This file contains routines that support the CIE L*a*b* - * color space to include conversions to and from the CIE - * XYZ space. These conversions are from Principles of - * Color Technology Second Edition, Fred W. Billmeyer, Jr. - * and Max Saltzman, John Wiley & Sons, Inc., 1981. - * - * Note that the range for L* is 0 to 1. - */ - - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <X11/Xos.h> -#include <stdio.h> /* sscanf */ -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - -/* - * DEFINES - * Internal definitions that need NOT be exported to any package - * or program using this package. - */ -#ifdef DBL_EPSILON -# define XMY_DBL_EPSILON DBL_EPSILON -#else -# define XMY_DBL_EPSILON 0.00001 -#endif -#define DIV16BY116 0.137931 - -/* - * FORWARD DECLARATIONS - */ - -static int CIELab_ParseString(register char *spec, XcmsColor *pColor); -static Status XcmsCIELab_ValidSpec(XcmsColor *pColor); - - -/* - * LOCAL VARIABLES - */ - - - /* - * NULL terminated list of functions applied to get from CIELab to CIEXYZ - */ -static XcmsConversionProc Fl_CIELab_to_CIEXYZ[] = { - XcmsCIELabToCIEXYZ, - NULL -}; - - /* - * NULL terminated list of functions applied to get from CIEXYZ to CIELab - */ -static XcmsConversionProc Fl_CIEXYZ_to_CIELab[] = { - XcmsCIEXYZToCIELab, - NULL -}; - - -/* - * GLOBALS - */ - /* - * CIE Lab Color Space - */ -XcmsColorSpace XcmsCIELabColorSpace = - { - _XcmsCIELab_prefix, /* prefix */ - XcmsCIELabFormat, /* id */ - CIELab_ParseString, /* parseString */ - Fl_CIELab_to_CIEXYZ, /* to_CIEXYZ */ - Fl_CIEXYZ_to_CIELab, /* from_CIEXYZ */ - 1 - }; - - -/************************************************************************ - * * - * PRIVATE ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * CIELab_ParseString - * - * SYNOPSIS - */ -static int -CIELab_ParseString( - register char *spec, - XcmsColor *pColor) -/* - * DESCRIPTION - * This routines takes a string and attempts to convert - * it into a XcmsColor structure with XcmsCIELabFormat. - * The assumed CIELab string syntax is: - * CIELab:<L>/<a>/<b> - * Where L, a, and b are in string input format for floats - * consisting of: - * a. an optional sign - * b. a string of numbers possibly containing a decimal point, - * c. an optional exponent field containing an 'E' or 'e' - * followed by a possibly signed integer string. - * - * RETURNS - * 0 if failed, non-zero otherwise. - */ -{ - int n; - char *pchar; - - if ((pchar = strchr(spec, ':')) == NULL) { - return(XcmsFailure); - } - n = (int)(pchar - spec); - - /* - * Check for proper prefix. - */ - if (strncmp(spec, _XcmsCIELab_prefix, n) != 0) { - return(XcmsFailure); - } - - /* - * Attempt to parse the value portion. - */ - if (sscanf(spec + n + 1, "%lf/%lf/%lf", - &pColor->spec.CIELab.L_star, - &pColor->spec.CIELab.a_star, - &pColor->spec.CIELab.b_star) != 3) { - char *s; /* Maybe failed due to locale */ - int f; - if ((s = strdup(spec))) { - for (f = 0; s[f]; ++f) - if (s[f] == '.') - s[f] = ','; - else if (s[f] == ',') - s[f] = '.'; - if (sscanf(s + n + 1, "%lf/%lf/%lf", - &pColor->spec.CIELab.L_star, - &pColor->spec.CIELab.a_star, - &pColor->spec.CIELab.b_star) != 3) { - free(s); - return(XcmsFailure); - } - free(s); - } else - return(XcmsFailure); - } - pColor->format = XcmsCIELabFormat; - pColor->pixel = 0; - - return(XcmsCIELab_ValidSpec(pColor)); -} - - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELab_ValidSpec - * - * SYNOPSIS - */ -static Status -XcmsCIELab_ValidSpec( - XcmsColor *pColor) -/* - * DESCRIPTION - * Checks if color specification valid for CIE L*a*b*. - * - * RETURNS - * XcmsFailure if invalid, - * XcmsSuccess if valid. - * - */ -{ - if (pColor->format != XcmsCIELabFormat - || - (pColor->spec.CIELab.L_star < 0.0 - XMY_DBL_EPSILON) - || - (pColor->spec.CIELab.L_star > 100.0 + XMY_DBL_EPSILON)) { - return(XcmsFailure); - } - return(XcmsSuccess); -} - - -/* - * NAME - * XcmsCIELabToCIEXYZ - convert CIELab to CIEXYZ - * - * SYNOPSIS - */ -Status -XcmsCIELabToCIEXYZ( - XcmsCCC ccc, - XcmsColor *pLab_WhitePt, - XcmsColor *pColors_in_out, - unsigned int nColors) -/* - * DESCRIPTION - * Converts color specifications in an array of XcmsColor - * structures from CIELab format to CIEXYZ format. - * - * WARNING: This routine assumes that Yn = 1.0; - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if succeeded. - * - */ -{ - XcmsCIEXYZ XYZ_return; - XcmsFloat tmpFloat, tmpL; - XcmsColor whitePt; - int i; - XcmsColor *pColor = pColors_in_out; - - /* - * Check arguments - */ - if (pLab_WhitePt == NULL || pColors_in_out == NULL) { - return(XcmsFailure); - } - - /* - * Make sure white point is in CIEXYZ form, if not, convert it. - */ - if (pLab_WhitePt->format != XcmsCIEXYZFormat) { - /* Make a copy of the white point because we're going to modify it */ - memcpy((char *)&whitePt, (char *)pLab_WhitePt, sizeof(XcmsColor)); - if (!_XcmsDIConvertColors(ccc, &whitePt, - (XcmsColor *)NULL, 1, XcmsCIEXYZFormat)) { - return(XcmsFailure); - } - pLab_WhitePt = &whitePt; - } - - /* - * Make sure it is a white point, i.e., Y == 1.0 - */ - if (pLab_WhitePt->spec.CIEXYZ.Y != 1.0) { - return (0); - } - - /* - * Now convert each XcmsColor structure to CIEXYZ form - */ - for (i = 0; i < nColors; i++, pColor++) { - - /* Make sure original format is CIELab */ - if (!XcmsCIELab_ValidSpec(pColor)) { - return(XcmsFailure); - } - - /* Calculate Y: assume that Yn = 1.0 */ - tmpL = (pColor->spec.CIELab.L_star + 16.0) / 116.0; - XYZ_return.Y = tmpL * tmpL * tmpL; - - if (XYZ_return.Y < 0.008856) { - /* Calculate Y: assume that Yn = 1.0 */ - tmpL = pColor->spec.CIELab.L_star / 9.03292; - - /* Calculate X */ - XYZ_return.X = pLab_WhitePt->spec.CIEXYZ.X * - ((pColor->spec.CIELab.a_star / 3893.5) + tmpL); - /* Calculate Y */ - XYZ_return.Y = tmpL; - /* Calculate Z */ - XYZ_return.Z = pLab_WhitePt->spec.CIEXYZ.Z * - (tmpL - (pColor->spec.CIELab.b_star / 1557.4)); - } else { - /* Calculate X */ - tmpFloat = tmpL + (pColor->spec.CIELab.a_star / 5.0); - XYZ_return.X = pLab_WhitePt->spec.CIEXYZ.X * tmpFloat * tmpFloat * tmpFloat; - - /* Calculate Z */ - tmpFloat = tmpL - (pColor->spec.CIELab.b_star / 2.0); - XYZ_return.Z = pLab_WhitePt->spec.CIEXYZ.Z * tmpFloat * tmpFloat * tmpFloat; - } - - memcpy((char *)&pColor->spec.CIEXYZ, (char *)&XYZ_return, - sizeof(XcmsCIEXYZ)); - pColor->format = XcmsCIEXYZFormat; - } - - return (1); -} - - -/* - * NAME - * XcmsCIEXYZToCIELab - convert CIEXYZ to CIELab - * - * SYNOPSIS - */ -Status -XcmsCIEXYZToCIELab( - XcmsCCC ccc, - XcmsColor *pLab_WhitePt, - XcmsColor *pColors_in_out, - unsigned int nColors) -/* - * DESCRIPTION - * Converts color specifications in an array of XcmsColor - * structures from CIEXYZ format to CIELab format. - * - * WARNING: This routine assumes that Yn = 1.0; - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if succeeded. - * - */ -{ - XcmsCIELab Lab_return; - XcmsFloat fX_Xn, fY_Yn, fZ_Zn; - XcmsColor whitePt; - int i; - XcmsColor *pColor = pColors_in_out; - - /* - * Check arguments - */ - if (pLab_WhitePt == NULL || pColors_in_out == NULL) { - return(XcmsFailure); - } - - /* - * Make sure white point is in CIEXYZ form, if not, convert it. - */ - if (pLab_WhitePt->format != XcmsCIEXYZFormat) { - /* Make a copy of the white point because we're going to modify it */ - memcpy((char *)&whitePt, (char *)pLab_WhitePt, sizeof(XcmsColor)); - if (!_XcmsDIConvertColors(ccc, &whitePt, (XcmsColor *)NULL, - 1, XcmsCIEXYZFormat)) { - return(XcmsFailure); - } - pLab_WhitePt = &whitePt; - } - - /* - * Make sure it is a white point, i.e., Y == 1.0 - */ - if (pLab_WhitePt->spec.CIEXYZ.Y != 1.0) { - return(XcmsFailure); - } - - /* - * Now convert each XcmsColor structure to CIEXYZ form - */ - for (i = 0; i < nColors; i++, pColor++) { - - /* Make sure original format is CIELab */ - if (!_XcmsCIEXYZ_ValidSpec(pColor)) { - return(XcmsFailure); - } - - /* Calculate L*: assume Yn = 1.0 */ - if (pColor->spec.CIEXYZ.Y < 0.008856) { - fY_Yn = (0.07787 * pColor->spec.CIEXYZ.Y) + DIV16BY116; - /* note fY_Yn used to compute Lab_return.a below */ - Lab_return.L_star = 116.0 * (fY_Yn - DIV16BY116); - } else { - fY_Yn = (XcmsFloat)XCMS_CUBEROOT(pColor->spec.CIEXYZ.Y); - /* note fY_Yn used to compute Lab_return.a_star below */ - Lab_return.L_star = (116.0 * fY_Yn) - 16.0; - } - - /* Calculate f(X/Xn) */ - if ((fX_Xn = pColor->spec.CIEXYZ.X / pLab_WhitePt->spec.CIEXYZ.X) < 0.008856) { - fX_Xn = (0.07787 * fX_Xn) + DIV16BY116; - } else { - fX_Xn = (XcmsFloat) XCMS_CUBEROOT(fX_Xn); - } - - /* Calculate f(Z/Zn) */ - if ((fZ_Zn = pColor->spec.CIEXYZ.Z / pLab_WhitePt->spec.CIEXYZ.Z) < 0.008856) { - fZ_Zn = (0.07787 * fZ_Zn) + DIV16BY116; - } else { - fZ_Zn = (XcmsFloat) XCMS_CUBEROOT(fZ_Zn); - } - - Lab_return.a_star = 5.0 * (fX_Xn - fY_Yn); - Lab_return.b_star = 2.0 * (fY_Yn - fZ_Zn); - - memcpy((char *)&pColor->spec.CIELab, (char *)&Lab_return, - sizeof(XcmsCIELab)); - pColor->format = XcmsCIELabFormat; - } - - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * CIELab.c
+ *
+ * DESCRIPTION
+ * This file contains routines that support the CIE L*a*b*
+ * color space to include conversions to and from the CIE
+ * XYZ space. These conversions are from Principles of
+ * Color Technology Second Edition, Fred W. Billmeyer, Jr.
+ * and Max Saltzman, John Wiley & Sons, Inc., 1981.
+ *
+ * Note that the range for L* is 0 to 1.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xos.h>
+#include <stdio.h> /* sscanf */
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+/*
+ * DEFINES
+ * Internal definitions that need NOT be exported to any package
+ * or program using this package.
+ */
+#ifdef DBL_EPSILON
+# define XMY_DBL_EPSILON DBL_EPSILON
+#else
+# define XMY_DBL_EPSILON 0.00001
+#endif
+#define DIV16BY116 0.137931
+
+/*
+ * FORWARD DECLARATIONS
+ */
+
+static int CIELab_ParseString(register char *spec, XcmsColor *pColor);
+static Status XcmsCIELab_ValidSpec(XcmsColor *pColor);
+
+
+/*
+ * LOCAL VARIABLES
+ */
+
+
+ /*
+ * NULL terminated list of functions applied to get from CIELab to CIEXYZ
+ */
+static XcmsConversionProc Fl_CIELab_to_CIEXYZ[] = {
+ XcmsCIELabToCIEXYZ,
+ NULL
+};
+
+ /*
+ * NULL terminated list of functions applied to get from CIEXYZ to CIELab
+ */
+static XcmsConversionProc Fl_CIEXYZ_to_CIELab[] = {
+ XcmsCIEXYZToCIELab,
+ NULL
+};
+
+
+/*
+ * GLOBALS
+ */
+ /*
+ * CIE Lab Color Space
+ */
+XcmsColorSpace XcmsCIELabColorSpace =
+ {
+ _XcmsCIELab_prefix, /* prefix */
+ XcmsCIELabFormat, /* id */
+ CIELab_ParseString, /* parseString */
+ Fl_CIELab_to_CIEXYZ, /* to_CIEXYZ */
+ Fl_CIEXYZ_to_CIELab, /* from_CIEXYZ */
+ 1
+ };
+
+
+/************************************************************************
+ * *
+ * PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * CIELab_ParseString
+ *
+ * SYNOPSIS
+ */
+static int
+CIELab_ParseString(
+ register char *spec,
+ XcmsColor *pColor)
+/*
+ * DESCRIPTION
+ * This routines takes a string and attempts to convert
+ * it into a XcmsColor structure with XcmsCIELabFormat.
+ * The assumed CIELab string syntax is:
+ * CIELab:<L>/<a>/<b>
+ * Where L, a, and b are in string input format for floats
+ * consisting of:
+ * a. an optional sign
+ * b. a string of numbers possibly containing a decimal point,
+ * c. an optional exponent field containing an 'E' or 'e'
+ * followed by a possibly signed integer string.
+ *
+ * RETURNS
+ * 0 if failed, non-zero otherwise.
+ */
+{
+ int n;
+ char *pchar;
+
+ if ((pchar = strchr(spec, ':')) == NULL) {
+ return(XcmsFailure);
+ }
+ n = (int)(pchar - spec);
+
+ /*
+ * Check for proper prefix.
+ */
+ if (strncmp(spec, _XcmsCIELab_prefix, n) != 0) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Attempt to parse the value portion.
+ */
+ if (sscanf(spec + n + 1, "%lf/%lf/%lf",
+ &pColor->spec.CIELab.L_star,
+ &pColor->spec.CIELab.a_star,
+ &pColor->spec.CIELab.b_star) != 3) {
+ char *s; /* Maybe failed due to locale */
+ int f;
+ if ((s = strdup(spec))) {
+ for (f = 0; s[f]; ++f)
+ if (s[f] == '.')
+ s[f] = ',';
+ else if (s[f] == ',')
+ s[f] = '.';
+ if (sscanf(s + n + 1, "%lf/%lf/%lf",
+ &pColor->spec.CIELab.L_star,
+ &pColor->spec.CIELab.a_star,
+ &pColor->spec.CIELab.b_star) != 3) {
+ free(s);
+ return(XcmsFailure);
+ }
+ free(s);
+ } else
+ return(XcmsFailure);
+ }
+ pColor->format = XcmsCIELabFormat;
+ pColor->pixel = 0;
+
+ return(XcmsCIELab_ValidSpec(pColor));
+}
+
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELab_ValidSpec
+ *
+ * SYNOPSIS
+ */
+static Status
+XcmsCIELab_ValidSpec(
+ XcmsColor *pColor)
+/*
+ * DESCRIPTION
+ * Checks if color specification valid for CIE L*a*b*.
+ *
+ * RETURNS
+ * XcmsFailure if invalid,
+ * XcmsSuccess if valid.
+ *
+ */
+{
+ if (pColor->format != XcmsCIELabFormat
+ ||
+ (pColor->spec.CIELab.L_star < 0.0 - XMY_DBL_EPSILON)
+ ||
+ (pColor->spec.CIELab.L_star > 100.0 + XMY_DBL_EPSILON)) {
+ return(XcmsFailure);
+ }
+ return(XcmsSuccess);
+}
+
+
+/*
+ * NAME
+ * XcmsCIELabToCIEXYZ - convert CIELab to CIEXYZ
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIELabToCIEXYZ(
+ XcmsCCC ccc,
+ XcmsColor *pLab_WhitePt,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors)
+/*
+ * DESCRIPTION
+ * Converts color specifications in an array of XcmsColor
+ * structures from CIELab format to CIEXYZ format.
+ *
+ * WARNING: This routine assumes that Yn = 1.0;
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if succeeded.
+ *
+ */
+{
+ XcmsCIEXYZ XYZ_return;
+ XcmsFloat tmpFloat, tmpL;
+ XcmsColor whitePt;
+ int i;
+ XcmsColor *pColor = pColors_in_out;
+
+ /*
+ * Check arguments
+ */
+ if (pLab_WhitePt == NULL || pColors_in_out == NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Make sure white point is in CIEXYZ form, if not, convert it.
+ */
+ if (pLab_WhitePt->format != XcmsCIEXYZFormat) {
+ /* Make a copy of the white point because we're going to modify it */
+ memcpy((char *)&whitePt, (char *)pLab_WhitePt, sizeof(XcmsColor));
+ if (!_XcmsDIConvertColors(ccc, &whitePt,
+ (XcmsColor *)NULL, 1, XcmsCIEXYZFormat)) {
+ return(XcmsFailure);
+ }
+ pLab_WhitePt = &whitePt;
+ }
+
+ /*
+ * Make sure it is a white point, i.e., Y == 1.0
+ */
+ if (pLab_WhitePt->spec.CIEXYZ.Y != 1.0) {
+ return (0);
+ }
+
+ /*
+ * Now convert each XcmsColor structure to CIEXYZ form
+ */
+ for (i = 0; i < nColors; i++, pColor++) {
+
+ /* Make sure original format is CIELab */
+ if (!XcmsCIELab_ValidSpec(pColor)) {
+ return(XcmsFailure);
+ }
+
+ /* Calculate Y: assume that Yn = 1.0 */
+ tmpL = (pColor->spec.CIELab.L_star + 16.0) / 116.0;
+ XYZ_return.Y = tmpL * tmpL * tmpL;
+
+ if (XYZ_return.Y < 0.008856) {
+ /* Calculate Y: assume that Yn = 1.0 */
+ tmpL = pColor->spec.CIELab.L_star / 9.03292;
+
+ /* Calculate X */
+ XYZ_return.X = pLab_WhitePt->spec.CIEXYZ.X *
+ ((pColor->spec.CIELab.a_star / 3893.5) + tmpL);
+ /* Calculate Y */
+ XYZ_return.Y = tmpL;
+ /* Calculate Z */
+ XYZ_return.Z = pLab_WhitePt->spec.CIEXYZ.Z *
+ (tmpL - (pColor->spec.CIELab.b_star / 1557.4));
+ } else {
+ /* Calculate X */
+ tmpFloat = tmpL + (pColor->spec.CIELab.a_star / 5.0);
+ XYZ_return.X = pLab_WhitePt->spec.CIEXYZ.X * tmpFloat * tmpFloat * tmpFloat;
+
+ /* Calculate Z */
+ tmpFloat = tmpL - (pColor->spec.CIELab.b_star / 2.0);
+ XYZ_return.Z = pLab_WhitePt->spec.CIEXYZ.Z * tmpFloat * tmpFloat * tmpFloat;
+ }
+
+ memcpy((char *)&pColor->spec.CIEXYZ, (char *)&XYZ_return,
+ sizeof(XcmsCIEXYZ));
+ pColor->format = XcmsCIEXYZFormat;
+ }
+
+ return (1);
+}
+
+
+/*
+ * NAME
+ * XcmsCIEXYZToCIELab - convert CIEXYZ to CIELab
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIEXYZToCIELab(
+ XcmsCCC ccc,
+ XcmsColor *pLab_WhitePt,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors)
+/*
+ * DESCRIPTION
+ * Converts color specifications in an array of XcmsColor
+ * structures from CIEXYZ format to CIELab format.
+ *
+ * WARNING: This routine assumes that Yn = 1.0;
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if succeeded.
+ *
+ */
+{
+ XcmsCIELab Lab_return;
+ XcmsFloat fX_Xn, fY_Yn, fZ_Zn;
+ XcmsColor whitePt;
+ int i;
+ XcmsColor *pColor = pColors_in_out;
+
+ /*
+ * Check arguments
+ */
+ if (pLab_WhitePt == NULL || pColors_in_out == NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Make sure white point is in CIEXYZ form, if not, convert it.
+ */
+ if (pLab_WhitePt->format != XcmsCIEXYZFormat) {
+ /* Make a copy of the white point because we're going to modify it */
+ memcpy((char *)&whitePt, (char *)pLab_WhitePt, sizeof(XcmsColor));
+ if (!_XcmsDIConvertColors(ccc, &whitePt, (XcmsColor *)NULL,
+ 1, XcmsCIEXYZFormat)) {
+ return(XcmsFailure);
+ }
+ pLab_WhitePt = &whitePt;
+ }
+
+ /*
+ * Make sure it is a white point, i.e., Y == 1.0
+ */
+ if (pLab_WhitePt->spec.CIEXYZ.Y != 1.0) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Now convert each XcmsColor structure to CIEXYZ form
+ */
+ for (i = 0; i < nColors; i++, pColor++) {
+
+ /* Make sure original format is CIELab */
+ if (!_XcmsCIEXYZ_ValidSpec(pColor)) {
+ return(XcmsFailure);
+ }
+
+ /* Calculate L*: assume Yn = 1.0 */
+ if (pColor->spec.CIEXYZ.Y < 0.008856) {
+ fY_Yn = (0.07787 * pColor->spec.CIEXYZ.Y) + DIV16BY116;
+ /* note fY_Yn used to compute Lab_return.a below */
+ Lab_return.L_star = 116.0 * (fY_Yn - DIV16BY116);
+ } else {
+ fY_Yn = (XcmsFloat)XCMS_CUBEROOT(pColor->spec.CIEXYZ.Y);
+ /* note fY_Yn used to compute Lab_return.a_star below */
+ Lab_return.L_star = (116.0 * fY_Yn) - 16.0;
+ }
+
+ /* Calculate f(X/Xn) */
+ if ((fX_Xn = pColor->spec.CIEXYZ.X / pLab_WhitePt->spec.CIEXYZ.X) < 0.008856) {
+ fX_Xn = (0.07787 * fX_Xn) + DIV16BY116;
+ } else {
+ fX_Xn = (XcmsFloat) XCMS_CUBEROOT(fX_Xn);
+ }
+
+ /* Calculate f(Z/Zn) */
+ if ((fZ_Zn = pColor->spec.CIEXYZ.Z / pLab_WhitePt->spec.CIEXYZ.Z) < 0.008856) {
+ fZ_Zn = (0.07787 * fZ_Zn) + DIV16BY116;
+ } else {
+ fZ_Zn = (XcmsFloat) XCMS_CUBEROOT(fZ_Zn);
+ }
+
+ Lab_return.a_star = 5.0 * (fX_Xn - fY_Yn);
+ Lab_return.b_star = 2.0 * (fY_Yn - fZ_Zn);
+
+ memcpy((char *)&pColor->spec.CIELab, (char *)&Lab_return,
+ sizeof(XcmsCIELab));
+ pColor->format = XcmsCIELabFormat;
+ }
+
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/LabGcC.c b/libX11/src/xcms/LabGcC.c index a5ec9f457..84a20cc83 100644 --- a/libX11/src/xcms/LabGcC.c +++ b/libX11/src/xcms/LabGcC.c @@ -1,127 +1,127 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * CIELabGcC.c - * - * DESCRIPTION - * Source for XcmsCIELabClipuv() gamut compression routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELabClipab - Reduce the chroma for a hue and L* - * - * SYNOPSIS - */ -/* ARGSUSED */ -Status -XcmsCIELabClipab ( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - unsigned int nColors, - unsigned int i, - Bool *pCompressed) -/* - * DESCRIPTION - * Reduce the Chroma for a specific hue and chroma to - * to bring the given color into the gamut of the - * specified device. As required of gamut compression - * functions, this routine returns pColor_in_out - * in XcmsCIEXYZFormat on successful completion. - * - * Since this routine works with the L* within - * pColor_in_out intermediate results may be returned - * even though it may be invalid. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - Status retval; - XcmsColor *pColor; - - /* - * Color specification passed as input can be assumed to: - * 1. Be in XcmsCIEXYZFormat - * 2. Already be white point adjusted for the Screen White Point. - * This means that the white point now associated with this - * color spec is the Screen White Point (even if the - * ccc->clientWhitePt differs). - */ - - pColor = pColors_in_out + i; - - if (ccc->visual->class < PseudoColor) { - /* - * GRAY ! - */ - _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc), - 1, XcmsCIELabFormat); - _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc), - 1, XcmsCIEXYZFormat); - if (pCompressed) { - *(pCompressed + i) = True; - } - return(XcmsSuccess); - } else { - if (pColor->format != XcmsCIELabFormat) { - if (_XcmsDIConvertColors(ccc, pColor, - &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIELabFormat) - == XcmsFailure) { - return(XcmsFailure); - } - } - if (XcmsCIELabQueryMaxC(ccc, - degrees(XCMS_CIELAB_PMETRIC_HUE(pColor->spec.CIELab.a_star, - pColor->spec.CIELab.b_star)), - pColor->spec.CIELab.L_star, - pColor) == XcmsFailure) { - return(XcmsFailure); - } - retval = _XcmsDIConvertColors(ccc, pColor, - &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat); - if (retval != XcmsFailure && pCompressed != NULL) { - *(pCompressed + i) = True; - } - return(retval); - } -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * CIELabGcC.c
+ *
+ * DESCRIPTION
+ * Source for XcmsCIELabClipuv() gamut compression routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELabClipab - Reduce the chroma for a hue and L*
+ *
+ * SYNOPSIS
+ */
+/* ARGSUSED */
+Status
+XcmsCIELabClipab (
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors,
+ unsigned int i,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * Reduce the Chroma for a specific hue and chroma to
+ * to bring the given color into the gamut of the
+ * specified device. As required of gamut compression
+ * functions, this routine returns pColor_in_out
+ * in XcmsCIEXYZFormat on successful completion.
+ *
+ * Since this routine works with the L* within
+ * pColor_in_out intermediate results may be returned
+ * even though it may be invalid.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ Status retval;
+ XcmsColor *pColor;
+
+ /*
+ * Color specification passed as input can be assumed to:
+ * 1. Be in XcmsCIEXYZFormat
+ * 2. Already be white point adjusted for the Screen White Point.
+ * This means that the white point now associated with this
+ * color spec is the Screen White Point (even if the
+ * ccc->clientWhitePt differs).
+ */
+
+ pColor = pColors_in_out + i;
+
+ if (ccc->visual->class < PseudoColor) {
+ /*
+ * GRAY !
+ */
+ _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc),
+ 1, XcmsCIELabFormat);
+ _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc),
+ 1, XcmsCIEXYZFormat);
+ if (pCompressed) {
+ *(pCompressed + i) = True;
+ }
+ return(XcmsSuccess);
+ } else {
+ if (pColor->format != XcmsCIELabFormat) {
+ if (_XcmsDIConvertColors(ccc, pColor,
+ &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIELabFormat)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+ if (XcmsCIELabQueryMaxC(ccc,
+ degrees(XCMS_CIELAB_PMETRIC_HUE(pColor->spec.CIELab.a_star,
+ pColor->spec.CIELab.b_star)),
+ pColor->spec.CIELab.L_star,
+ pColor) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ retval = _XcmsDIConvertColors(ccc, pColor,
+ &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
+ if (retval != XcmsFailure && pCompressed != NULL) {
+ *(pCompressed + i) = True;
+ }
+ return(retval);
+ }
+}
diff --git a/libX11/src/xcms/LabGcL.c b/libX11/src/xcms/LabGcL.c index 3038b18a8..169e7ce9f 100644 --- a/libX11/src/xcms/LabGcL.c +++ b/libX11/src/xcms/LabGcL.c @@ -1,174 +1,174 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * CIELabGcL.c - * - * DESCRIPTION - * Source for XcmsCIELabClipL() gamut compression routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELabClipL - Return the closest L* - * - * SYNOPSIS - */ -/* ARGSUSED */ -Status -XcmsCIELabClipL ( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - unsigned int nColors, - unsigned int i, - Bool *pCompressed) -/* - * DESCRIPTION - * Return the closest L* for a specific hue and chroma. - * This routine takes any color as input and outputs - * a CIE XYZ color. - * - * Since this routine works with the L* within - * pColor_in_out intermediate results may be returned - * even though it may be invalid. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - XcmsCCCRec myCCC; - XcmsColor *pColor; - XcmsColor Lab_max; - XcmsFloat hue, chroma, maxChroma; - Status retval; - - /* Use my own CCC */ - memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* Inherit Screen WP */ - myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut compression */ - - /* - * Color specification passed as input can be assumed to: - * 1. Be in XcmsCIEXYZFormat - * 2. Already be white point adjusted for the Screen White Point. - * This means that the white point now associated with this - * color spec is the Screen White Point (even if the - * ccc->clientWhitePt differs). - */ - - pColor = pColors_in_out + i; - - if (ccc->visual->class < StaticColor) { - /* - * GRAY ! - */ - return(XcmsFailure); - } else { - /* Convert from CIEXYZ to CIE L*u*v* format */ - if (_XcmsDIConvertColors(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELabFormat) - == XcmsFailure) { - return(XcmsFailure); - } - - hue = XCMS_CIELAB_PMETRIC_HUE(pColor->spec.CIELab.a_star, - pColor->spec.CIELab.b_star); - chroma = XCMS_CIELAB_PMETRIC_CHROMA(pColor->spec.CIELab.a_star, - pColor->spec.CIELab.b_star); - /* Step 1: compute the maximum L* and chroma for this hue. */ - /* This copy may be overkill but it preserves the pixel etc. */ - memcpy((char *)&Lab_max, (char *)pColor, sizeof(XcmsColor)); - if (_XcmsCIELabQueryMaxLCRGB (&myCCC, hue, &Lab_max, - (XcmsRGBi *)NULL) == XcmsFailure) { - return (XcmsFailure); - } - maxChroma = XCMS_CIELAB_PMETRIC_CHROMA(Lab_max.spec.CIELab.a_star, - Lab_max.spec.CIELab.b_star); - - /* Now check and return the appropriate L* */ - if (chroma == maxChroma) { - /* When the chroma input is equal to the maximum chroma */ - /* merely return the L* for that chroma. */ - memcpy((char *)pColor, (char *)&Lab_max, sizeof(XcmsColor)); - retval = _XcmsDIConvertColors(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat); - } else if (chroma > maxChroma) { - /* When the chroma input is greater than the maximum chroma */ - /* merely return the L* and chroma for the given hue. */ - memcpy((char *)pColor, (char *)&Lab_max, sizeof(XcmsColor)); - return (XcmsFailure); - } else if (pColor->spec.CIELab.L_star < Lab_max.spec.CIELab.L_star) { - /* Find the minimum lightness for the given chroma. */ - if (pColor->format != XcmsCIELabFormat) { - if (_XcmsDIConvertColors(ccc, pColor, - ScreenWhitePointOfCCC(ccc), 1, XcmsCIELabFormat) - == XcmsFailure) { - return(XcmsFailure); - } - } - if (XcmsCIELabQueryMinL(&myCCC, degrees(hue), chroma, pColor) - == XcmsFailure) { - return (XcmsFailure); - } - retval = _XcmsDIConvertColors(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat); - } else { - /* Find the maximum lightness for the given chroma. */ - if (pColor->format != XcmsCIELabFormat) { - if (_XcmsDIConvertColors(ccc, pColor, - ScreenWhitePointOfCCC(ccc), 1, XcmsCIELabFormat) - == XcmsFailure) { - return(XcmsFailure); - } - } - if (XcmsCIELabQueryMaxL(&myCCC, degrees(hue), chroma, pColor) - == XcmsFailure) { - return (XcmsFailure); - } - retval = _XcmsDIConvertColors(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat); - } - if (retval != XcmsFailure && pCompressed != NULL) { - *(pCompressed + i) = True; - } - return(retval); - } -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * CIELabGcL.c
+ *
+ * DESCRIPTION
+ * Source for XcmsCIELabClipL() gamut compression routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELabClipL - Return the closest L*
+ *
+ * SYNOPSIS
+ */
+/* ARGSUSED */
+Status
+XcmsCIELabClipL (
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors,
+ unsigned int i,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * Return the closest L* for a specific hue and chroma.
+ * This routine takes any color as input and outputs
+ * a CIE XYZ color.
+ *
+ * Since this routine works with the L* within
+ * pColor_in_out intermediate results may be returned
+ * even though it may be invalid.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ XcmsCCCRec myCCC;
+ XcmsColor *pColor;
+ XcmsColor Lab_max;
+ XcmsFloat hue, chroma, maxChroma;
+ Status retval;
+
+ /* Use my own CCC */
+ memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* Inherit Screen WP */
+ myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut compression */
+
+ /*
+ * Color specification passed as input can be assumed to:
+ * 1. Be in XcmsCIEXYZFormat
+ * 2. Already be white point adjusted for the Screen White Point.
+ * This means that the white point now associated with this
+ * color spec is the Screen White Point (even if the
+ * ccc->clientWhitePt differs).
+ */
+
+ pColor = pColors_in_out + i;
+
+ if (ccc->visual->class < StaticColor) {
+ /*
+ * GRAY !
+ */
+ return(XcmsFailure);
+ } else {
+ /* Convert from CIEXYZ to CIE L*u*v* format */
+ if (_XcmsDIConvertColors(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELabFormat)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ hue = XCMS_CIELAB_PMETRIC_HUE(pColor->spec.CIELab.a_star,
+ pColor->spec.CIELab.b_star);
+ chroma = XCMS_CIELAB_PMETRIC_CHROMA(pColor->spec.CIELab.a_star,
+ pColor->spec.CIELab.b_star);
+ /* Step 1: compute the maximum L* and chroma for this hue. */
+ /* This copy may be overkill but it preserves the pixel etc. */
+ memcpy((char *)&Lab_max, (char *)pColor, sizeof(XcmsColor));
+ if (_XcmsCIELabQueryMaxLCRGB (&myCCC, hue, &Lab_max,
+ (XcmsRGBi *)NULL) == XcmsFailure) {
+ return (XcmsFailure);
+ }
+ maxChroma = XCMS_CIELAB_PMETRIC_CHROMA(Lab_max.spec.CIELab.a_star,
+ Lab_max.spec.CIELab.b_star);
+
+ /* Now check and return the appropriate L* */
+ if (chroma == maxChroma) {
+ /* When the chroma input is equal to the maximum chroma */
+ /* merely return the L* for that chroma. */
+ memcpy((char *)pColor, (char *)&Lab_max, sizeof(XcmsColor));
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat);
+ } else if (chroma > maxChroma) {
+ /* When the chroma input is greater than the maximum chroma */
+ /* merely return the L* and chroma for the given hue. */
+ memcpy((char *)pColor, (char *)&Lab_max, sizeof(XcmsColor));
+ return (XcmsFailure);
+ } else if (pColor->spec.CIELab.L_star < Lab_max.spec.CIELab.L_star) {
+ /* Find the minimum lightness for the given chroma. */
+ if (pColor->format != XcmsCIELabFormat) {
+ if (_XcmsDIConvertColors(ccc, pColor,
+ ScreenWhitePointOfCCC(ccc), 1, XcmsCIELabFormat)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+ if (XcmsCIELabQueryMinL(&myCCC, degrees(hue), chroma, pColor)
+ == XcmsFailure) {
+ return (XcmsFailure);
+ }
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat);
+ } else {
+ /* Find the maximum lightness for the given chroma. */
+ if (pColor->format != XcmsCIELabFormat) {
+ if (_XcmsDIConvertColors(ccc, pColor,
+ ScreenWhitePointOfCCC(ccc), 1, XcmsCIELabFormat)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+ if (XcmsCIELabQueryMaxL(&myCCC, degrees(hue), chroma, pColor)
+ == XcmsFailure) {
+ return (XcmsFailure);
+ }
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat);
+ }
+ if (retval != XcmsFailure && pCompressed != NULL) {
+ *(pCompressed + i) = True;
+ }
+ return(retval);
+ }
+}
diff --git a/libX11/src/xcms/LabGcLC.c b/libX11/src/xcms/LabGcLC.c index 494d34e57..cedaf1229 100644 --- a/libX11/src/xcms/LabGcLC.c +++ b/libX11/src/xcms/LabGcLC.c @@ -1,223 +1,223 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * CIELabGcLC.c - * - * DESCRIPTION - * Source for XcmsCIELabClipLab() gamut - * compression function. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include <math.h> -#include "Cv.h" - -/* - * INTERNALS - * Internal defines that need NOT be exported to any package or - * program using this package. - */ -#define MAXBISECTCOUNT 100 - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELabClipLab - Return the closest L* and chroma - * - * SYNOPSIS - */ -/* ARGSUSED */ -Status -XcmsCIELabClipLab ( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - unsigned int nColors, - unsigned int i, - Bool *pCompressed) -/* - * DESCRIPTION - * This routine will find the closest L* and chroma - * for a specific hue. The color input is converted to - * CIE L*u*v* format and returned as CIE XYZ format. - * - * Since this routine works with the L* within - * pColor_in_out intermediate results may be returned - * even though it may be invalid. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - Status retval; - XcmsCCCRec myCCC; - XcmsColor *pColor; - XcmsColor Lab_max; - XcmsFloat hue, chroma, maxChroma; - XcmsFloat Chroma, bestChroma, Lstar, maxLstar, saveLstar; - XcmsFloat bestLstar, bestastar, bestbstar; - XcmsFloat nT, saveDist, tmpDist; - XcmsRGBi rgb_max; - int nCount, nMaxCount, nI, nILast; - - /* Use my own CCC */ - memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* inherit screen white */ - myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut compression func */ - - /* - * Color specification passed as input can be assumed to: - * 1. Be in XcmsCIEXYZFormat - * 2. Already be white point adjusted for the Screen White Point. - * This means that the white point now associated with this - * color spec is the Screen White Point (even if the - * ccc->clientWhitePt differs). - */ - - pColor = pColors_in_out + i; - - if (ccc->visual->class < StaticColor) { - /* - * GRAY ! - */ - _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc), - 1, XcmsCIELabFormat); - _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc), - 1, XcmsCIEXYZFormat); - if (pCompressed) { - *(pCompressed + i) = True; - } - return(XcmsSuccess); - } - - /* Convert from CIEXYZ to CIELab format */ - if (_XcmsDIConvertColors(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELabFormat) - == XcmsFailure) { - return(XcmsFailure); - } - - /* Step 1: compute the maximum L* and chroma for this hue. */ - /* This copy may be overkill but it preserves the pixel etc. */ - saveLstar = pColor->spec.CIELab.L_star; - hue = XCMS_CIELAB_PMETRIC_HUE(pColor->spec.CIELab.a_star, - pColor->spec.CIELab.b_star); - chroma = XCMS_CIELAB_PMETRIC_CHROMA(pColor->spec.CIELab.a_star, - pColor->spec.CIELab.b_star); - memcpy((char *)&Lab_max, (char *)pColor, sizeof(XcmsColor)); - if (_XcmsCIELabQueryMaxLCRGB (&myCCC, hue, &Lab_max, &rgb_max) - == XcmsFailure) { - return (XcmsFailure); - } - maxLstar = Lab_max.spec.CIELab.L_star; - - /* Now check and return the appropriate L* */ - if (saveLstar == maxLstar) { - /* When the L* input is equal to the maximum L* */ - /* merely return the maximum Lab point. */ - memcpy((char *)pColor, (char *)&Lab_max, sizeof(XcmsColor)); - retval = _XcmsDIConvertColors(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat); - } else { - /* return the closest point on the hue leaf. */ - /* must do a bisection here to compute the delta e. */ - maxChroma = XCMS_CIELAB_PMETRIC_CHROMA(Lab_max.spec.CIELab.a_star, - Lab_max.spec.CIELab.b_star); - nMaxCount = MAXBISECTCOUNT; - nI = nMaxCount / 2; - bestLstar = Lstar = pColor->spec.CIELab.L_star; - bestastar = pColor->spec.CIELab.a_star; - bestbstar = pColor->spec.CIELab.b_star; - bestChroma = Chroma = chroma; - saveDist = XCMS_SQRT(((Chroma - maxChroma) * (Chroma - maxChroma)) + - ((Lstar - maxLstar) * (Lstar - maxLstar))); - for (nCount = 0; nCount < nMaxCount; nCount++) { - nT = (XcmsFloat) nI / (XcmsFloat) nMaxCount; - if (saveLstar > maxLstar) { - pColor->spec.RGBi.red = rgb_max.red * (1.0 - nT) + nT; - pColor->spec.RGBi.green = rgb_max.green * (1.0 - nT) + nT; - pColor->spec.RGBi.blue = rgb_max.blue * (1.0 - nT) + nT; - } else { - pColor->spec.RGBi.red = rgb_max.red - (rgb_max.red * nT); - pColor->spec.RGBi.green = rgb_max.green - (rgb_max.green * nT); - pColor->spec.RGBi.blue = rgb_max.blue - (rgb_max.blue * nT); - } - pColor->format = XcmsRGBiFormat; - - /* Convert from RGBi to CIE Lab */ - if (_XcmsConvertColorsWithWhitePt(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELabFormat, - (Bool *) NULL) == XcmsFailure) { - return (XcmsFailure); - } - chroma = XCMS_CIELAB_PMETRIC_CHROMA(pColor->spec.CIELab.a_star, - pColor->spec.CIELab.b_star); - tmpDist = XCMS_SQRT(((Chroma - chroma) * (Chroma - chroma)) + - ((Lstar - pColor->spec.CIELab.L_star) * - (Lstar - pColor->spec.CIELab.L_star))); - nILast = nI; - if (tmpDist > saveDist) { - nI /= 2; - } else { - nI = (nMaxCount + nI) / 2; - saveDist = tmpDist; - bestLstar = pColor->spec.CIELab.L_star; - bestastar = pColor->spec.CIELab.a_star; - bestbstar = pColor->spec.CIELab.b_star; - bestChroma = chroma; - } - if (nI == nILast || nI == 0) { - break; - } - } - if (bestChroma >= maxChroma) { - pColor->spec.CIELab.L_star = maxLstar; - pColor->spec.CIELab.a_star = Lab_max.spec.CIELab.a_star; - pColor->spec.CIELab.b_star = Lab_max.spec.CIELab.b_star; - } else { - pColor->spec.CIELab.L_star = bestLstar; - pColor->spec.CIELab.a_star = bestastar; - pColor->spec.CIELab.b_star = bestbstar; - } - retval = _XcmsDIConvertColors(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat); - - if (retval != XcmsFailure && pCompressed != NULL) { - *(pCompressed + i) = True; - } - } - return(retval); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * CIELabGcLC.c
+ *
+ * DESCRIPTION
+ * Source for XcmsCIELabClipLab() gamut
+ * compression function.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include <math.h>
+#include "Cv.h"
+
+/*
+ * INTERNALS
+ * Internal defines that need NOT be exported to any package or
+ * program using this package.
+ */
+#define MAXBISECTCOUNT 100
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELabClipLab - Return the closest L* and chroma
+ *
+ * SYNOPSIS
+ */
+/* ARGSUSED */
+Status
+XcmsCIELabClipLab (
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors,
+ unsigned int i,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * This routine will find the closest L* and chroma
+ * for a specific hue. The color input is converted to
+ * CIE L*u*v* format and returned as CIE XYZ format.
+ *
+ * Since this routine works with the L* within
+ * pColor_in_out intermediate results may be returned
+ * even though it may be invalid.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ Status retval;
+ XcmsCCCRec myCCC;
+ XcmsColor *pColor;
+ XcmsColor Lab_max;
+ XcmsFloat hue, chroma, maxChroma;
+ XcmsFloat Chroma, bestChroma, Lstar, maxLstar, saveLstar;
+ XcmsFloat bestLstar, bestastar, bestbstar;
+ XcmsFloat nT, saveDist, tmpDist;
+ XcmsRGBi rgb_max;
+ int nCount, nMaxCount, nI, nILast;
+
+ /* Use my own CCC */
+ memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* inherit screen white */
+ myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut compression func */
+
+ /*
+ * Color specification passed as input can be assumed to:
+ * 1. Be in XcmsCIEXYZFormat
+ * 2. Already be white point adjusted for the Screen White Point.
+ * This means that the white point now associated with this
+ * color spec is the Screen White Point (even if the
+ * ccc->clientWhitePt differs).
+ */
+
+ pColor = pColors_in_out + i;
+
+ if (ccc->visual->class < StaticColor) {
+ /*
+ * GRAY !
+ */
+ _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc),
+ 1, XcmsCIELabFormat);
+ _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc),
+ 1, XcmsCIEXYZFormat);
+ if (pCompressed) {
+ *(pCompressed + i) = True;
+ }
+ return(XcmsSuccess);
+ }
+
+ /* Convert from CIEXYZ to CIELab format */
+ if (_XcmsDIConvertColors(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELabFormat)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* Step 1: compute the maximum L* and chroma for this hue. */
+ /* This copy may be overkill but it preserves the pixel etc. */
+ saveLstar = pColor->spec.CIELab.L_star;
+ hue = XCMS_CIELAB_PMETRIC_HUE(pColor->spec.CIELab.a_star,
+ pColor->spec.CIELab.b_star);
+ chroma = XCMS_CIELAB_PMETRIC_CHROMA(pColor->spec.CIELab.a_star,
+ pColor->spec.CIELab.b_star);
+ memcpy((char *)&Lab_max, (char *)pColor, sizeof(XcmsColor));
+ if (_XcmsCIELabQueryMaxLCRGB (&myCCC, hue, &Lab_max, &rgb_max)
+ == XcmsFailure) {
+ return (XcmsFailure);
+ }
+ maxLstar = Lab_max.spec.CIELab.L_star;
+
+ /* Now check and return the appropriate L* */
+ if (saveLstar == maxLstar) {
+ /* When the L* input is equal to the maximum L* */
+ /* merely return the maximum Lab point. */
+ memcpy((char *)pColor, (char *)&Lab_max, sizeof(XcmsColor));
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat);
+ } else {
+ /* return the closest point on the hue leaf. */
+ /* must do a bisection here to compute the delta e. */
+ maxChroma = XCMS_CIELAB_PMETRIC_CHROMA(Lab_max.spec.CIELab.a_star,
+ Lab_max.spec.CIELab.b_star);
+ nMaxCount = MAXBISECTCOUNT;
+ nI = nMaxCount / 2;
+ bestLstar = Lstar = pColor->spec.CIELab.L_star;
+ bestastar = pColor->spec.CIELab.a_star;
+ bestbstar = pColor->spec.CIELab.b_star;
+ bestChroma = Chroma = chroma;
+ saveDist = XCMS_SQRT(((Chroma - maxChroma) * (Chroma - maxChroma)) +
+ ((Lstar - maxLstar) * (Lstar - maxLstar)));
+ for (nCount = 0; nCount < nMaxCount; nCount++) {
+ nT = (XcmsFloat) nI / (XcmsFloat) nMaxCount;
+ if (saveLstar > maxLstar) {
+ pColor->spec.RGBi.red = rgb_max.red * (1.0 - nT) + nT;
+ pColor->spec.RGBi.green = rgb_max.green * (1.0 - nT) + nT;
+ pColor->spec.RGBi.blue = rgb_max.blue * (1.0 - nT) + nT;
+ } else {
+ pColor->spec.RGBi.red = rgb_max.red - (rgb_max.red * nT);
+ pColor->spec.RGBi.green = rgb_max.green - (rgb_max.green * nT);
+ pColor->spec.RGBi.blue = rgb_max.blue - (rgb_max.blue * nT);
+ }
+ pColor->format = XcmsRGBiFormat;
+
+ /* Convert from RGBi to CIE Lab */
+ if (_XcmsConvertColorsWithWhitePt(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELabFormat,
+ (Bool *) NULL) == XcmsFailure) {
+ return (XcmsFailure);
+ }
+ chroma = XCMS_CIELAB_PMETRIC_CHROMA(pColor->spec.CIELab.a_star,
+ pColor->spec.CIELab.b_star);
+ tmpDist = XCMS_SQRT(((Chroma - chroma) * (Chroma - chroma)) +
+ ((Lstar - pColor->spec.CIELab.L_star) *
+ (Lstar - pColor->spec.CIELab.L_star)));
+ nILast = nI;
+ if (tmpDist > saveDist) {
+ nI /= 2;
+ } else {
+ nI = (nMaxCount + nI) / 2;
+ saveDist = tmpDist;
+ bestLstar = pColor->spec.CIELab.L_star;
+ bestastar = pColor->spec.CIELab.a_star;
+ bestbstar = pColor->spec.CIELab.b_star;
+ bestChroma = chroma;
+ }
+ if (nI == nILast || nI == 0) {
+ break;
+ }
+ }
+ if (bestChroma >= maxChroma) {
+ pColor->spec.CIELab.L_star = maxLstar;
+ pColor->spec.CIELab.a_star = Lab_max.spec.CIELab.a_star;
+ pColor->spec.CIELab.b_star = Lab_max.spec.CIELab.b_star;
+ } else {
+ pColor->spec.CIELab.L_star = bestLstar;
+ pColor->spec.CIELab.a_star = bestastar;
+ pColor->spec.CIELab.b_star = bestbstar;
+ }
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat);
+
+ if (retval != XcmsFailure && pCompressed != NULL) {
+ *(pCompressed + i) = True;
+ }
+ }
+ return(retval);
+}
diff --git a/libX11/src/xcms/LabMnL.c b/libX11/src/xcms/LabMnL.c index 18ff04cd1..2495ba8fb 100644 --- a/libX11/src/xcms/LabMnL.c +++ b/libX11/src/xcms/LabMnL.c @@ -1,216 +1,216 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * CIELabMnL.c - * - * DESCRIPTION - * Source for the XcmsCIELabQueryMinL() gamut boundary - * querying routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include <math.h> -#include "Cv.h" - -/* - * DEFINES - */ -#define MAXBISECTCOUNT 100 -#define EPS (XcmsFloat)0.001 -#define START_L_STAR (XcmsFloat)40.0 - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELabQueryMinL - Compute max Lstar for a hue and chroma - * - * SYNOPSIS - */ -Status -XcmsCIELabQueryMinL( - XcmsCCC ccc, - XcmsFloat hue_angle, /* hue angle in degrees */ - XcmsFloat chroma, - XcmsColor *pColor_return) -/* - * DESCRIPTION - * Return the maximum Lstar for a specified hue_angle and chroma. - * - * ASSUMPTIONS - * This routine assumes that the white point associated with - * the color specification is the Screen White Point. The - * Screen White Point will also be associated with the - * returned color specification. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded with no modifications - * - */ -{ - XcmsCCCRec myCCC; - XcmsColor max_lc, tmp, prev; - XcmsFloat max_chroma, tmp_chroma; - XcmsFloat hue, nT, nChroma, lastChroma, prevChroma; - XcmsFloat rFactor; - XcmsRGBi rgb_saved; - int nCount, nMaxCount; - - /* - * Check Arguments - */ - if (ccc == NULL || pColor_return == NULL) { - return(XcmsFailure); - } - - /* setup the CCC to use for the conversions. */ - memcpy ((char *) &myCCC, (char *) ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat; - myCCC.gamutCompProc = (XcmsCompressionProc) NULL; - - while (hue_angle < 0.0) { - hue_angle += 360.0; - } - while (hue_angle >= 360.0) { - hue_angle -= 360.0; - } - - hue = radians(hue_angle); - tmp.spec.CIELab.L_star = START_L_STAR; - tmp.spec.CIELab.a_star = XCMS_CIEASTAROFHUE(hue, chroma); - tmp.spec.CIELab.b_star = XCMS_CIEBSTAROFHUE(hue, chroma); - tmp.pixel = pColor_return->pixel; - tmp.format = XcmsCIELabFormat; - - /* Step 1: Obtain the maximum L_star and chroma for this hue. */ - if (_XcmsCIELabQueryMaxLCRGB(&myCCC, hue, &max_lc, &rgb_saved) - == XcmsFailure) { - return(XcmsFailure); - } - - max_chroma = XCMS_CIELAB_PMETRIC_CHROMA(max_lc.spec.CIELab.a_star, - max_lc.spec.CIELab.b_star); - - if (max_chroma <= chroma) { - /* - * If the chroma is greater than the chroma for the - * maximum L/chroma point then the L_star is the - * the L_star for the maximum L_star/chroma point. - * This is an error but I return the best approximation I can. - * Thus the inconsistency. - */ - memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor)); - return(XcmsSuccess); - } - - /* - * If the chroma is equal to the chroma for the - * maximum L_star/chroma point then the L_star is the - * the L_star for the maximum L* and chroma point. - */ - /* if (max_chroma == chroma) { - * memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor)); - * return(XcmsSuccess); - * } - */ - - /* must do a bisection here to compute the maximum L* */ - /* save the structure input so that any elements that */ - /* are not touched are recopied later in the routine. */ - nChroma = chroma; - tmp_chroma = max_chroma; - lastChroma = -1.0; - nMaxCount = MAXBISECTCOUNT; - rFactor = 1.0; - - for (nCount = 0; nCount < nMaxCount; nCount++) { - prevChroma = lastChroma; - lastChroma = tmp_chroma; - nT = (nChroma - max_chroma) / max_chroma * rFactor; - memcpy ((char *)&prev, (char *)&tmp, sizeof(XcmsColor)); - tmp.spec.RGBi.red = rgb_saved.red + (rgb_saved.red * nT); - tmp.spec.RGBi.green = rgb_saved.green + (rgb_saved.green * nT); - tmp.spec.RGBi.blue = rgb_saved.blue + (rgb_saved.blue * nT); - tmp.format = XcmsRGBiFormat; - - /* convert from RGB to CIELab */ - if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELabFormat, - (Bool *) NULL) == XcmsFailure) { - return(XcmsFailure); - } - - /* Now check the return against what is expected */ - tmp_chroma = XCMS_CIELAB_PMETRIC_CHROMA(tmp.spec.CIELab.a_star, - tmp.spec.CIELab.b_star); - if (tmp_chroma <= chroma + EPS && tmp_chroma >= chroma - EPS) { - /* Found It! */ - memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor)); - return(XcmsSuccess); - } - nChroma += chroma - tmp_chroma; - if (nChroma > max_chroma) { - nChroma = max_chroma; - rFactor *= 0.5; /* selective relaxation employed */ - } else if (nChroma < 0.0) { - if (XCMS_FABS(lastChroma - chroma) < - XCMS_FABS(tmp_chroma - chroma)) { - memcpy ((char *)pColor_return, (char *)&prev, - sizeof(XcmsColor)); - } else { - memcpy ((char *)pColor_return, (char *)&tmp, - sizeof(XcmsColor)); - } - return(XcmsSuccess); - } else if (tmp_chroma <= prevChroma + EPS && - tmp_chroma >= prevChroma - EPS) { - rFactor *= 0.5; /* selective relaxation employed */ - } - } - - if (nCount >= nMaxCount) { - if (XCMS_FABS(lastChroma - chroma) < - XCMS_FABS(tmp_chroma - chroma)) { - memcpy ((char *)pColor_return, (char *)&prev, - sizeof(XcmsColor)); - } else { - memcpy ((char *)pColor_return, (char *)&tmp, - sizeof(XcmsColor)); - } - } - memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor)); - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * CIELabMnL.c
+ *
+ * DESCRIPTION
+ * Source for the XcmsCIELabQueryMinL() gamut boundary
+ * querying routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include <math.h>
+#include "Cv.h"
+
+/*
+ * DEFINES
+ */
+#define MAXBISECTCOUNT 100
+#define EPS (XcmsFloat)0.001
+#define START_L_STAR (XcmsFloat)40.0
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELabQueryMinL - Compute max Lstar for a hue and chroma
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIELabQueryMinL(
+ XcmsCCC ccc,
+ XcmsFloat hue_angle, /* hue angle in degrees */
+ XcmsFloat chroma,
+ XcmsColor *pColor_return)
+/*
+ * DESCRIPTION
+ * Return the maximum Lstar for a specified hue_angle and chroma.
+ *
+ * ASSUMPTIONS
+ * This routine assumes that the white point associated with
+ * the color specification is the Screen White Point. The
+ * Screen White Point will also be associated with the
+ * returned color specification.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded with no modifications
+ *
+ */
+{
+ XcmsCCCRec myCCC;
+ XcmsColor max_lc, tmp, prev;
+ XcmsFloat max_chroma, tmp_chroma;
+ XcmsFloat hue, nT, nChroma, lastChroma, prevChroma;
+ XcmsFloat rFactor;
+ XcmsRGBi rgb_saved;
+ int nCount, nMaxCount;
+
+ /*
+ * Check Arguments
+ */
+ if (ccc == NULL || pColor_return == NULL) {
+ return(XcmsFailure);
+ }
+
+ /* setup the CCC to use for the conversions. */
+ memcpy ((char *) &myCCC, (char *) ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;
+ myCCC.gamutCompProc = (XcmsCompressionProc) NULL;
+
+ while (hue_angle < 0.0) {
+ hue_angle += 360.0;
+ }
+ while (hue_angle >= 360.0) {
+ hue_angle -= 360.0;
+ }
+
+ hue = radians(hue_angle);
+ tmp.spec.CIELab.L_star = START_L_STAR;
+ tmp.spec.CIELab.a_star = XCMS_CIEASTAROFHUE(hue, chroma);
+ tmp.spec.CIELab.b_star = XCMS_CIEBSTAROFHUE(hue, chroma);
+ tmp.pixel = pColor_return->pixel;
+ tmp.format = XcmsCIELabFormat;
+
+ /* Step 1: Obtain the maximum L_star and chroma for this hue. */
+ if (_XcmsCIELabQueryMaxLCRGB(&myCCC, hue, &max_lc, &rgb_saved)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ max_chroma = XCMS_CIELAB_PMETRIC_CHROMA(max_lc.spec.CIELab.a_star,
+ max_lc.spec.CIELab.b_star);
+
+ if (max_chroma <= chroma) {
+ /*
+ * If the chroma is greater than the chroma for the
+ * maximum L/chroma point then the L_star is the
+ * the L_star for the maximum L_star/chroma point.
+ * This is an error but I return the best approximation I can.
+ * Thus the inconsistency.
+ */
+ memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor));
+ return(XcmsSuccess);
+ }
+
+ /*
+ * If the chroma is equal to the chroma for the
+ * maximum L_star/chroma point then the L_star is the
+ * the L_star for the maximum L* and chroma point.
+ */
+ /* if (max_chroma == chroma) {
+ * memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor));
+ * return(XcmsSuccess);
+ * }
+ */
+
+ /* must do a bisection here to compute the maximum L* */
+ /* save the structure input so that any elements that */
+ /* are not touched are recopied later in the routine. */
+ nChroma = chroma;
+ tmp_chroma = max_chroma;
+ lastChroma = -1.0;
+ nMaxCount = MAXBISECTCOUNT;
+ rFactor = 1.0;
+
+ for (nCount = 0; nCount < nMaxCount; nCount++) {
+ prevChroma = lastChroma;
+ lastChroma = tmp_chroma;
+ nT = (nChroma - max_chroma) / max_chroma * rFactor;
+ memcpy ((char *)&prev, (char *)&tmp, sizeof(XcmsColor));
+ tmp.spec.RGBi.red = rgb_saved.red + (rgb_saved.red * nT);
+ tmp.spec.RGBi.green = rgb_saved.green + (rgb_saved.green * nT);
+ tmp.spec.RGBi.blue = rgb_saved.blue + (rgb_saved.blue * nT);
+ tmp.format = XcmsRGBiFormat;
+
+ /* convert from RGB to CIELab */
+ if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELabFormat,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* Now check the return against what is expected */
+ tmp_chroma = XCMS_CIELAB_PMETRIC_CHROMA(tmp.spec.CIELab.a_star,
+ tmp.spec.CIELab.b_star);
+ if (tmp_chroma <= chroma + EPS && tmp_chroma >= chroma - EPS) {
+ /* Found It! */
+ memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor));
+ return(XcmsSuccess);
+ }
+ nChroma += chroma - tmp_chroma;
+ if (nChroma > max_chroma) {
+ nChroma = max_chroma;
+ rFactor *= 0.5; /* selective relaxation employed */
+ } else if (nChroma < 0.0) {
+ if (XCMS_FABS(lastChroma - chroma) <
+ XCMS_FABS(tmp_chroma - chroma)) {
+ memcpy ((char *)pColor_return, (char *)&prev,
+ sizeof(XcmsColor));
+ } else {
+ memcpy ((char *)pColor_return, (char *)&tmp,
+ sizeof(XcmsColor));
+ }
+ return(XcmsSuccess);
+ } else if (tmp_chroma <= prevChroma + EPS &&
+ tmp_chroma >= prevChroma - EPS) {
+ rFactor *= 0.5; /* selective relaxation employed */
+ }
+ }
+
+ if (nCount >= nMaxCount) {
+ if (XCMS_FABS(lastChroma - chroma) <
+ XCMS_FABS(tmp_chroma - chroma)) {
+ memcpy ((char *)pColor_return, (char *)&prev,
+ sizeof(XcmsColor));
+ } else {
+ memcpy ((char *)pColor_return, (char *)&tmp,
+ sizeof(XcmsColor));
+ }
+ }
+ memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor));
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/LabMxC.c b/libX11/src/xcms/LabMxC.c index fcadd236a..83226783a 100644 --- a/libX11/src/xcms/LabMxC.c +++ b/libX11/src/xcms/LabMxC.c @@ -1,203 +1,203 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * - * NAME - * CIELabMxC.c - * - * DESCRIPTION - * Source for the XcmsCIELabQueryMaxC() gamut boundary - * querying routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include <math.h> -#include "Cv.h" - -/* - * DEFINES - */ -#define MAXBISECTCOUNT 100 -#define EPS (XcmsFloat)0.001 -#define START_CHROMA (XcmsFloat)3.6 -#define TOPL (XcmsFloat)100.0 - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELabQueryMaxC - max chroma for a hue_angle and L_star - * - * SYNOPSIS - */ -Status -XcmsCIELabQueryMaxC( - XcmsCCC ccc, - XcmsFloat hue_angle, /* hue angle in degrees */ - XcmsFloat L_star, - XcmsColor *pColor_return) -/* - * DESCRIPTION - * Return the maximum chroma for a specific hue_angle and L_star. - * The returned format is in XcmsCIELabFormat. - * - * - * ASSUMPTIONS - * This routine assumes that the white point associated with - * the color specification is the Screen White Point. The - * Screen White Point will also be associated with the - * returned color specification. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - XcmsCCCRec myCCC; - XcmsColor tmp; - XcmsColor max_lc; - XcmsFloat n_L_star, last_L_star, prev_L_star; - XcmsFloat hue, lastaStar, lastbStar, /*lastChroma,*/ maxDist, nT, rFactor; - XcmsRGBi rgb_saved; - int nCount, nMaxCount; - - /* - * Check Arguments - */ - if (ccc == NULL || pColor_return == NULL) { - return(XcmsFailure); - } - - /* Use my own CCC and inherit screen white Pt */ - memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat; - myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut comp func */ - - while (hue_angle < 0.0) { - hue_angle += 360.0; - } - while (hue_angle >= 360.0) { - hue_angle -= 360.0; - } - - hue = radians(hue_angle); - tmp.spec.CIELab.L_star = L_star; - tmp.spec.CIELab.a_star = XCMS_CIEASTAROFHUE(hue, START_CHROMA); - tmp.spec.CIELab.b_star = XCMS_CIEBSTAROFHUE(hue, START_CHROMA); - tmp.pixel = pColor_return->pixel; - tmp.format = XcmsCIELabFormat; - - /* Step 1: compute the maximum L_star and chroma for this hue. */ - memcpy((char *)&max_lc, (char *)&tmp, sizeof(XcmsColor)); - if (_XcmsCIELabQueryMaxLCRGB(&myCCC, hue, &max_lc, &rgb_saved) - == XcmsFailure) { - return(XcmsFailure); - } - - /* - * Step 2: Do a bisection here to compute the maximum chroma - * Note the differences between when the point to be found - * is above the maximum LC point and when it is below. - */ - if (L_star <= max_lc.spec.CIELab.L_star) { - maxDist = max_lc.spec.CIELab.L_star; - } else { - maxDist = TOPL - max_lc.spec.CIELab.L_star; - } - - n_L_star = L_star; - last_L_star = -1.0; - nMaxCount = MAXBISECTCOUNT; - rFactor = 1.0; - - for (nCount = 0; nCount < nMaxCount; nCount++) { - prev_L_star = last_L_star; - last_L_star = tmp.spec.CIELab.L_star; -/* lastChroma = XCMS_CIELAB_PMETRIC_CHROMA(tmp.spec.CIELab.a_star, */ -/* tmp.spec.CIELab.b_star); */ - lastaStar = tmp.spec.CIELab.a_star; - lastbStar = tmp.spec.CIELab.b_star; - nT = (n_L_star - max_lc.spec.CIELab.L_star) / maxDist * rFactor; - if (nT > 0) { - tmp.spec.RGBi.red = rgb_saved.red * (1.0 - nT) + nT; - tmp.spec.RGBi.green = rgb_saved.green * (1.0 - nT) + nT; - tmp.spec.RGBi.blue = rgb_saved.blue * (1.0 - nT) + nT; - } else { - tmp.spec.RGBi.red = rgb_saved.red + (rgb_saved.red * nT); - tmp.spec.RGBi.green = rgb_saved.green + (rgb_saved.green * nT); - tmp.spec.RGBi.blue = rgb_saved.blue + (rgb_saved.blue * nT); - } - tmp.format = XcmsRGBiFormat; - - /* convert from RGB to CIELab */ - if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELabFormat, - (Bool *) NULL) == XcmsFailure) { - return(XcmsFailure); - } - - /* - * Now check if we've reached the target L_star - */ - /* printf("result Lstar = %lf\n", tmp.spec.CIELab.L_star); */ - if (tmp.spec.CIELab.L_star <= L_star + EPS && - tmp.spec.CIELab.L_star >= L_star - EPS) { - memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor)); - return(XcmsSuccess); - } - if (nT > 0) { - n_L_star += ((TOPL - n_L_star) * - (L_star - tmp.spec.CIELab.L_star)) / (TOPL - L_star); - } else { - n_L_star *= L_star / tmp.spec.CIELuv.L_star; - } - if (tmp.spec.CIELab.L_star <= prev_L_star + EPS && - tmp.spec.CIELab.L_star >= prev_L_star - EPS) { - rFactor *= 0.5; /* selective relaxation employed */ - /* printf("rFactor = %lf\n", rFactor); */ - } - } - if (XCMS_FABS(last_L_star - L_star) < - XCMS_FABS(tmp.spec.CIELab.L_star - L_star)) { - tmp.spec.CIELab.a_star = lastaStar; - tmp.spec.CIELab.b_star = lastbStar; -/* tmp.spec.CIELab.a_star = XCMS_CIEASTAROFHUE(hue, lastChroma); */ -/* tmp.spec.CIELab.b_star = XCMS_CIEBSTAROFHUE(hue, lastChroma); */ - } - tmp.spec.CIELab.L_star = L_star; - memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor)); - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ *
+ * NAME
+ * CIELabMxC.c
+ *
+ * DESCRIPTION
+ * Source for the XcmsCIELabQueryMaxC() gamut boundary
+ * querying routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include <math.h>
+#include "Cv.h"
+
+/*
+ * DEFINES
+ */
+#define MAXBISECTCOUNT 100
+#define EPS (XcmsFloat)0.001
+#define START_CHROMA (XcmsFloat)3.6
+#define TOPL (XcmsFloat)100.0
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELabQueryMaxC - max chroma for a hue_angle and L_star
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIELabQueryMaxC(
+ XcmsCCC ccc,
+ XcmsFloat hue_angle, /* hue angle in degrees */
+ XcmsFloat L_star,
+ XcmsColor *pColor_return)
+/*
+ * DESCRIPTION
+ * Return the maximum chroma for a specific hue_angle and L_star.
+ * The returned format is in XcmsCIELabFormat.
+ *
+ *
+ * ASSUMPTIONS
+ * This routine assumes that the white point associated with
+ * the color specification is the Screen White Point. The
+ * Screen White Point will also be associated with the
+ * returned color specification.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ XcmsCCCRec myCCC;
+ XcmsColor tmp;
+ XcmsColor max_lc;
+ XcmsFloat n_L_star, last_L_star, prev_L_star;
+ XcmsFloat hue, lastaStar, lastbStar, /*lastChroma,*/ maxDist, nT, rFactor;
+ XcmsRGBi rgb_saved;
+ int nCount, nMaxCount;
+
+ /*
+ * Check Arguments
+ */
+ if (ccc == NULL || pColor_return == NULL) {
+ return(XcmsFailure);
+ }
+
+ /* Use my own CCC and inherit screen white Pt */
+ memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;
+ myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut comp func */
+
+ while (hue_angle < 0.0) {
+ hue_angle += 360.0;
+ }
+ while (hue_angle >= 360.0) {
+ hue_angle -= 360.0;
+ }
+
+ hue = radians(hue_angle);
+ tmp.spec.CIELab.L_star = L_star;
+ tmp.spec.CIELab.a_star = XCMS_CIEASTAROFHUE(hue, START_CHROMA);
+ tmp.spec.CIELab.b_star = XCMS_CIEBSTAROFHUE(hue, START_CHROMA);
+ tmp.pixel = pColor_return->pixel;
+ tmp.format = XcmsCIELabFormat;
+
+ /* Step 1: compute the maximum L_star and chroma for this hue. */
+ memcpy((char *)&max_lc, (char *)&tmp, sizeof(XcmsColor));
+ if (_XcmsCIELabQueryMaxLCRGB(&myCCC, hue, &max_lc, &rgb_saved)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Step 2: Do a bisection here to compute the maximum chroma
+ * Note the differences between when the point to be found
+ * is above the maximum LC point and when it is below.
+ */
+ if (L_star <= max_lc.spec.CIELab.L_star) {
+ maxDist = max_lc.spec.CIELab.L_star;
+ } else {
+ maxDist = TOPL - max_lc.spec.CIELab.L_star;
+ }
+
+ n_L_star = L_star;
+ last_L_star = -1.0;
+ nMaxCount = MAXBISECTCOUNT;
+ rFactor = 1.0;
+
+ for (nCount = 0; nCount < nMaxCount; nCount++) {
+ prev_L_star = last_L_star;
+ last_L_star = tmp.spec.CIELab.L_star;
+/* lastChroma = XCMS_CIELAB_PMETRIC_CHROMA(tmp.spec.CIELab.a_star, */
+/* tmp.spec.CIELab.b_star); */
+ lastaStar = tmp.spec.CIELab.a_star;
+ lastbStar = tmp.spec.CIELab.b_star;
+ nT = (n_L_star - max_lc.spec.CIELab.L_star) / maxDist * rFactor;
+ if (nT > 0) {
+ tmp.spec.RGBi.red = rgb_saved.red * (1.0 - nT) + nT;
+ tmp.spec.RGBi.green = rgb_saved.green * (1.0 - nT) + nT;
+ tmp.spec.RGBi.blue = rgb_saved.blue * (1.0 - nT) + nT;
+ } else {
+ tmp.spec.RGBi.red = rgb_saved.red + (rgb_saved.red * nT);
+ tmp.spec.RGBi.green = rgb_saved.green + (rgb_saved.green * nT);
+ tmp.spec.RGBi.blue = rgb_saved.blue + (rgb_saved.blue * nT);
+ }
+ tmp.format = XcmsRGBiFormat;
+
+ /* convert from RGB to CIELab */
+ if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELabFormat,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Now check if we've reached the target L_star
+ */
+ /* printf("result Lstar = %lf\n", tmp.spec.CIELab.L_star); */
+ if (tmp.spec.CIELab.L_star <= L_star + EPS &&
+ tmp.spec.CIELab.L_star >= L_star - EPS) {
+ memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor));
+ return(XcmsSuccess);
+ }
+ if (nT > 0) {
+ n_L_star += ((TOPL - n_L_star) *
+ (L_star - tmp.spec.CIELab.L_star)) / (TOPL - L_star);
+ } else {
+ n_L_star *= L_star / tmp.spec.CIELuv.L_star;
+ }
+ if (tmp.spec.CIELab.L_star <= prev_L_star + EPS &&
+ tmp.spec.CIELab.L_star >= prev_L_star - EPS) {
+ rFactor *= 0.5; /* selective relaxation employed */
+ /* printf("rFactor = %lf\n", rFactor); */
+ }
+ }
+ if (XCMS_FABS(last_L_star - L_star) <
+ XCMS_FABS(tmp.spec.CIELab.L_star - L_star)) {
+ tmp.spec.CIELab.a_star = lastaStar;
+ tmp.spec.CIELab.b_star = lastbStar;
+/* tmp.spec.CIELab.a_star = XCMS_CIEASTAROFHUE(hue, lastChroma); */
+/* tmp.spec.CIELab.b_star = XCMS_CIEBSTAROFHUE(hue, lastChroma); */
+ }
+ tmp.spec.CIELab.L_star = L_star;
+ memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor));
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/LabMxL.c b/libX11/src/xcms/LabMxL.c index 66ef48481..34a6499a4 100644 --- a/libX11/src/xcms/LabMxL.c +++ b/libX11/src/xcms/LabMxL.c @@ -1,216 +1,216 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * CIELabMxL.c - * - * DESCRIPTION - * Source for the XcmsCIELabQueryMaxL() gamut boundary - * querying routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include <math.h> -#include "Cv.h" - -/* - * DEFINES - */ -#define MAXBISECTCOUNT 100 -#define EPS (XcmsFloat)0.001 -#define START_L_STAR (XcmsFloat)40 - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELabQueryMaxL - Compute max Lstar for a hue and chroma - * - * SYNOPSIS - */ -Status -XcmsCIELabQueryMaxL( - XcmsCCC ccc, - XcmsFloat hue_angle, /* hue in degrees */ - XcmsFloat chroma, - XcmsColor *pColor_return) -/* - * DESCRIPTION - * Return the maximum Lstar for a specified hue_angle and chroma. - * - * ASSUMPTIONS - * This routine assumes that the white point associated with - * the color specification is the Screen White Point. The - * Screen White Point will also be associated with the - * returned color specification. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded with no modifications - * - */ -{ - XcmsCCCRec myCCC; - XcmsColor max_lc, tmp, prev; - XcmsFloat max_chroma, tmp_chroma; - XcmsFloat hue, nT, nChroma, lastChroma, prevChroma; - XcmsFloat rFactor; - XcmsRGBi rgb_saved; - int nCount, nMaxCount; - - /* - * Check Arguments - */ - if (ccc == NULL || pColor_return == NULL) { - return(XcmsFailure); - } - - /* setup the CCC to use for the conversions. */ - memcpy ((char *) &myCCC, (char *) ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat; - myCCC.gamutCompProc = (XcmsCompressionProc) NULL; - - while (hue_angle < 0.0) { - hue_angle += 360.0; - } - while (hue_angle >= 360.0) { - hue_angle -= 360.0; - } - - hue = radians(hue_angle); - tmp.spec.CIELab.L_star = START_L_STAR; - tmp.spec.CIELab.a_star = XCMS_CIEASTAROFHUE(hue, chroma); - tmp.spec.CIELab.b_star = XCMS_CIEBSTAROFHUE(hue, chroma); - tmp.pixel = pColor_return->pixel; - tmp.format = XcmsCIELabFormat; - - /* Step 1: Obtain the maximum L_star and chroma for this hue. */ - if (_XcmsCIELabQueryMaxLCRGB(&myCCC, hue, &max_lc, &rgb_saved) - == XcmsFailure) { - return(XcmsFailure); - } - - max_chroma = XCMS_CIELAB_PMETRIC_CHROMA(max_lc.spec.CIELab.a_star, - max_lc.spec.CIELab.b_star); - - if (max_chroma <= chroma) { - /* - * If the chroma is greater than the chroma for the - * maximum L/chroma point then the L_star is the - * the L_star for the maximum L_star/chroma point. - * This is an error but I return the best approximation I can. - * Thus the inconsistency. - */ - memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor)); - return(XcmsSuccess); - } - - /* - * If the chroma is equal to the chroma for the - * maximum L_star/chroma point then the L_star is the - * the L_star for the maximum L* and chroma point. - */ - /* if (max_chroma == chroma) { - * memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor)); - * return(XcmsSuccess); - * } - */ - - /* must do a bisection here to compute the maximum L* */ - /* save the structure input so that any elements that */ - /* are not touched are recopied later in the routine. */ - nChroma = chroma; - tmp_chroma = max_chroma; - lastChroma = -1.0; - nMaxCount = MAXBISECTCOUNT; - rFactor = 1.0; - - for (nCount = 0; nCount < nMaxCount; nCount++) { - prevChroma = lastChroma; - lastChroma = tmp_chroma; - nT = (1.0 - (nChroma / max_chroma)) * rFactor; - memcpy ((char *)&prev, (char *)&tmp, sizeof(XcmsColor)); - tmp.spec.RGBi.red = rgb_saved.red * (1.0 - nT) + nT; - tmp.spec.RGBi.green = rgb_saved.green * (1.0 - nT) + nT; - tmp.spec.RGBi.blue = rgb_saved.blue * (1.0 - nT) + nT; - tmp.format = XcmsRGBiFormat; - - /* convert from RGB to CIELab */ - if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELabFormat, - (Bool *) NULL) == XcmsFailure) { - return(XcmsFailure); - } - - /* Now check the return against what is expected */ - tmp_chroma = XCMS_CIELAB_PMETRIC_CHROMA(tmp.spec.CIELab.a_star, - tmp.spec.CIELab.b_star); - if (tmp_chroma <= chroma + EPS && tmp_chroma >= chroma - EPS) { - /* Found It! */ - memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor)); - return(XcmsSuccess); - } - nChroma += chroma - tmp_chroma; - if (nChroma > max_chroma) { - nChroma = max_chroma; - rFactor *= 0.5; /* selective relaxation employed */ - } else if (nChroma < 0.0) { - if (XCMS_FABS(lastChroma - chroma) < - XCMS_FABS(tmp_chroma - chroma)) { - memcpy ((char *)pColor_return, (char *)&prev, - sizeof(XcmsColor)); - } else { - memcpy ((char *)pColor_return, (char *)&tmp, - sizeof(XcmsColor)); - } - return(XcmsSuccess); - } else if (tmp_chroma <= prevChroma + EPS && - tmp_chroma >= prevChroma - EPS) { - rFactor *= 0.5; /* selective relaxation employed */ - } - } - - if (nCount >= nMaxCount) { - if (XCMS_FABS(lastChroma - chroma) < - XCMS_FABS(tmp_chroma - chroma)) { - memcpy ((char *)pColor_return, (char *)&prev, - sizeof(XcmsColor)); - } else { - memcpy ((char *)pColor_return, (char *)&tmp, - sizeof(XcmsColor)); - } - } - memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor)); - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * CIELabMxL.c
+ *
+ * DESCRIPTION
+ * Source for the XcmsCIELabQueryMaxL() gamut boundary
+ * querying routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include <math.h>
+#include "Cv.h"
+
+/*
+ * DEFINES
+ */
+#define MAXBISECTCOUNT 100
+#define EPS (XcmsFloat)0.001
+#define START_L_STAR (XcmsFloat)40
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELabQueryMaxL - Compute max Lstar for a hue and chroma
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIELabQueryMaxL(
+ XcmsCCC ccc,
+ XcmsFloat hue_angle, /* hue in degrees */
+ XcmsFloat chroma,
+ XcmsColor *pColor_return)
+/*
+ * DESCRIPTION
+ * Return the maximum Lstar for a specified hue_angle and chroma.
+ *
+ * ASSUMPTIONS
+ * This routine assumes that the white point associated with
+ * the color specification is the Screen White Point. The
+ * Screen White Point will also be associated with the
+ * returned color specification.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded with no modifications
+ *
+ */
+{
+ XcmsCCCRec myCCC;
+ XcmsColor max_lc, tmp, prev;
+ XcmsFloat max_chroma, tmp_chroma;
+ XcmsFloat hue, nT, nChroma, lastChroma, prevChroma;
+ XcmsFloat rFactor;
+ XcmsRGBi rgb_saved;
+ int nCount, nMaxCount;
+
+ /*
+ * Check Arguments
+ */
+ if (ccc == NULL || pColor_return == NULL) {
+ return(XcmsFailure);
+ }
+
+ /* setup the CCC to use for the conversions. */
+ memcpy ((char *) &myCCC, (char *) ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;
+ myCCC.gamutCompProc = (XcmsCompressionProc) NULL;
+
+ while (hue_angle < 0.0) {
+ hue_angle += 360.0;
+ }
+ while (hue_angle >= 360.0) {
+ hue_angle -= 360.0;
+ }
+
+ hue = radians(hue_angle);
+ tmp.spec.CIELab.L_star = START_L_STAR;
+ tmp.spec.CIELab.a_star = XCMS_CIEASTAROFHUE(hue, chroma);
+ tmp.spec.CIELab.b_star = XCMS_CIEBSTAROFHUE(hue, chroma);
+ tmp.pixel = pColor_return->pixel;
+ tmp.format = XcmsCIELabFormat;
+
+ /* Step 1: Obtain the maximum L_star and chroma for this hue. */
+ if (_XcmsCIELabQueryMaxLCRGB(&myCCC, hue, &max_lc, &rgb_saved)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ max_chroma = XCMS_CIELAB_PMETRIC_CHROMA(max_lc.spec.CIELab.a_star,
+ max_lc.spec.CIELab.b_star);
+
+ if (max_chroma <= chroma) {
+ /*
+ * If the chroma is greater than the chroma for the
+ * maximum L/chroma point then the L_star is the
+ * the L_star for the maximum L_star/chroma point.
+ * This is an error but I return the best approximation I can.
+ * Thus the inconsistency.
+ */
+ memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor));
+ return(XcmsSuccess);
+ }
+
+ /*
+ * If the chroma is equal to the chroma for the
+ * maximum L_star/chroma point then the L_star is the
+ * the L_star for the maximum L* and chroma point.
+ */
+ /* if (max_chroma == chroma) {
+ * memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor));
+ * return(XcmsSuccess);
+ * }
+ */
+
+ /* must do a bisection here to compute the maximum L* */
+ /* save the structure input so that any elements that */
+ /* are not touched are recopied later in the routine. */
+ nChroma = chroma;
+ tmp_chroma = max_chroma;
+ lastChroma = -1.0;
+ nMaxCount = MAXBISECTCOUNT;
+ rFactor = 1.0;
+
+ for (nCount = 0; nCount < nMaxCount; nCount++) {
+ prevChroma = lastChroma;
+ lastChroma = tmp_chroma;
+ nT = (1.0 - (nChroma / max_chroma)) * rFactor;
+ memcpy ((char *)&prev, (char *)&tmp, sizeof(XcmsColor));
+ tmp.spec.RGBi.red = rgb_saved.red * (1.0 - nT) + nT;
+ tmp.spec.RGBi.green = rgb_saved.green * (1.0 - nT) + nT;
+ tmp.spec.RGBi.blue = rgb_saved.blue * (1.0 - nT) + nT;
+ tmp.format = XcmsRGBiFormat;
+
+ /* convert from RGB to CIELab */
+ if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELabFormat,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* Now check the return against what is expected */
+ tmp_chroma = XCMS_CIELAB_PMETRIC_CHROMA(tmp.spec.CIELab.a_star,
+ tmp.spec.CIELab.b_star);
+ if (tmp_chroma <= chroma + EPS && tmp_chroma >= chroma - EPS) {
+ /* Found It! */
+ memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor));
+ return(XcmsSuccess);
+ }
+ nChroma += chroma - tmp_chroma;
+ if (nChroma > max_chroma) {
+ nChroma = max_chroma;
+ rFactor *= 0.5; /* selective relaxation employed */
+ } else if (nChroma < 0.0) {
+ if (XCMS_FABS(lastChroma - chroma) <
+ XCMS_FABS(tmp_chroma - chroma)) {
+ memcpy ((char *)pColor_return, (char *)&prev,
+ sizeof(XcmsColor));
+ } else {
+ memcpy ((char *)pColor_return, (char *)&tmp,
+ sizeof(XcmsColor));
+ }
+ return(XcmsSuccess);
+ } else if (tmp_chroma <= prevChroma + EPS &&
+ tmp_chroma >= prevChroma - EPS) {
+ rFactor *= 0.5; /* selective relaxation employed */
+ }
+ }
+
+ if (nCount >= nMaxCount) {
+ if (XCMS_FABS(lastChroma - chroma) <
+ XCMS_FABS(tmp_chroma - chroma)) {
+ memcpy ((char *)pColor_return, (char *)&prev,
+ sizeof(XcmsColor));
+ } else {
+ memcpy ((char *)pColor_return, (char *)&tmp,
+ sizeof(XcmsColor));
+ }
+ }
+ memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor));
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/LabMxLC.c b/libX11/src/xcms/LabMxLC.c index 8cc089a22..a81c7cfbf 100644 --- a/libX11/src/xcms/LabMxLC.c +++ b/libX11/src/xcms/LabMxLC.c @@ -1,218 +1,218 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * - * NAME - * CIELabMxVC.c - * - * DESCRIPTION - * Source for the XcmsCIELabQueryMaxLC() gamut boundary - * querying routine. - * - * DOCUMENTATION - * "TekColor Color Management System, System Implementor's Manual" - * and - * Fred W. Billmeyer & Max Saltzman, "Principles of Color - * Technology", John Wily & Sons, Inc, 1981. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - -/* - * DEFINES - */ -#define MIN(x,y) ((x) > (y) ? (y) : (x)) -#define MIN3(x,y,z) ((x) > (MIN((y), (z))) ? (MIN((y), (z))) : (x)) -#define MAX(x,y) ((x) > (y) ? (x) : (y)) -#define MAX3(x,y,z) ((x) > (MAX((y), (z))) ? (x) : (MAX((y), (z)))) -#define START_LSTAR (XcmsFloat)40.0 -#define START_CHROMA (XcmsFloat)3.6 - - -/************************************************************************ - * * - * API PRIVATE ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * _XcmsCIELabQueryMaxLCRGB - Compute maximum L* and chroma. - * - * SYNOPSIS - */ -Status -_XcmsCIELabQueryMaxLCRGB( - XcmsCCC ccc, - XcmsFloat hue, /* hue in radians */ - XcmsColor *pColor_return, - XcmsRGBi *pRGB_return) -/* - * DESCRIPTION - * Return the maximum psychometric chroma for a specified - * hue, and the corresponding L*. This is computed - * by a binary search of all possible chromas. An assumption - * is made that there are no local maxima. Use the unrounded - * Max psychometric chroma because the difference check can be - * small. - * - * NOTE: No local CCC is used because this is a private - * routine and all routines that call it are expected - * to behave properly, i.e. send a local CCC with - * no white adjust function and no gamut compression - * function. - * - * This routine only accepts hue in radians as input and outputs - * Lab and RGBi. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - XcmsFloat nSmall, nLarge; - XcmsColor tmp; - - tmp.format = XcmsCIELabFormat; - /* Use some unreachable color on the given hue */ - tmp.spec.CIELab.L_star = START_LSTAR; - tmp.spec.CIELab.a_star = XCMS_CIEASTAROFHUE(hue, START_CHROMA); - tmp.spec.CIELab.b_star = XCMS_CIEBSTAROFHUE(hue, START_CHROMA); - /* - * Convert from Lab to RGB - * - * Note that the CIEXYZ to RGBi conversion routine must stuff the - * out of bounds RGBi values in tmp when the ccc->gamutCompProc - * is NULL. - */ - if ((_XcmsConvertColorsWithWhitePt(ccc, &tmp, ScreenWhitePointOfCCC(ccc), - (unsigned int)1, XcmsRGBiFormat, (Bool *) NULL) - == XcmsFailure) && tmp.format != XcmsRGBiFormat) { - return (XcmsFailure); - } - - /* Now pick the smallest RGB */ - nSmall = MIN3(tmp.spec.RGBi.red, - tmp.spec.RGBi.green, - tmp.spec.RGBi.blue); - /* Make the smallest RGB equal to zero */ - tmp.spec.RGBi.red -= nSmall; - tmp.spec.RGBi.green -= nSmall; - tmp.spec.RGBi.blue -= nSmall; - - /* Now pick the largest RGB */ - nLarge = MAX3(tmp.spec.RGBi.red, - tmp.spec.RGBi.green, - tmp.spec.RGBi.blue); - /* Scale the RGB values based on the largest one */ - tmp.spec.RGBi.red /= nLarge; - tmp.spec.RGBi.green /= nLarge; - tmp.spec.RGBi.blue /= nLarge; - tmp.format = XcmsRGBiFormat; - - /* If the calling routine wants RGB value give them the ones used. */ - if (pRGB_return) { - pRGB_return->red = tmp.spec.RGBi.red; - pRGB_return->green = tmp.spec.RGBi.green; - pRGB_return->blue = tmp.spec.RGBi.blue; - } - - /* Convert from RGBi to Lab */ - if (_XcmsConvertColorsWithWhitePt(ccc, &tmp, - ScreenWhitePointOfCCC(ccc), 1, XcmsCIELabFormat, (Bool *) NULL) - == XcmsFailure) { - return (XcmsFailure); - } - - memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor)); - return (XcmsSuccess); -} - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELabQueryMaxLC - Compute maximum L* and chroma. - * - * SYNOPSIS - */ -Status -XcmsCIELabQueryMaxLC ( - XcmsCCC ccc, - XcmsFloat hue_angle, /* hue_angle in degrees */ - XcmsColor *pColor_return) - -/* - * DESCRIPTION - * Return the point of maximum chroma for the specified - * hue_angle. - * - * ASSUMPTIONS - * This routine assumes that the white point associated with - * the color specification is the Screen White Point. The - * Screen White Point will also be associated with the - * returned color specification. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - XcmsCCCRec myCCC; - - /* - * Check Arguments - */ - if (ccc == NULL || pColor_return == NULL) { - return(XcmsFailure); - } - - /* Use my own CCC */ - memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat; - myCCC.gamutCompProc = (XcmsCompressionProc)NULL; - - while (hue_angle < 0.0) { - hue_angle += 360.0; - } - while (hue_angle >= 360.0) { - hue_angle -= 360.0; - } - - return(_XcmsCIELabQueryMaxLCRGB (&myCCC, radians(hue_angle), pColor_return, - (XcmsRGBi *)NULL)); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ *
+ * NAME
+ * CIELabMxVC.c
+ *
+ * DESCRIPTION
+ * Source for the XcmsCIELabQueryMaxLC() gamut boundary
+ * querying routine.
+ *
+ * DOCUMENTATION
+ * "TekColor Color Management System, System Implementor's Manual"
+ * and
+ * Fred W. Billmeyer & Max Saltzman, "Principles of Color
+ * Technology", John Wily & Sons, Inc, 1981.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+/*
+ * DEFINES
+ */
+#define MIN(x,y) ((x) > (y) ? (y) : (x))
+#define MIN3(x,y,z) ((x) > (MIN((y), (z))) ? (MIN((y), (z))) : (x))
+#define MAX(x,y) ((x) > (y) ? (x) : (y))
+#define MAX3(x,y,z) ((x) > (MAX((y), (z))) ? (x) : (MAX((y), (z))))
+#define START_LSTAR (XcmsFloat)40.0
+#define START_CHROMA (XcmsFloat)3.6
+
+
+/************************************************************************
+ * *
+ * API PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * _XcmsCIELabQueryMaxLCRGB - Compute maximum L* and chroma.
+ *
+ * SYNOPSIS
+ */
+Status
+_XcmsCIELabQueryMaxLCRGB(
+ XcmsCCC ccc,
+ XcmsFloat hue, /* hue in radians */
+ XcmsColor *pColor_return,
+ XcmsRGBi *pRGB_return)
+/*
+ * DESCRIPTION
+ * Return the maximum psychometric chroma for a specified
+ * hue, and the corresponding L*. This is computed
+ * by a binary search of all possible chromas. An assumption
+ * is made that there are no local maxima. Use the unrounded
+ * Max psychometric chroma because the difference check can be
+ * small.
+ *
+ * NOTE: No local CCC is used because this is a private
+ * routine and all routines that call it are expected
+ * to behave properly, i.e. send a local CCC with
+ * no white adjust function and no gamut compression
+ * function.
+ *
+ * This routine only accepts hue in radians as input and outputs
+ * Lab and RGBi.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ XcmsFloat nSmall, nLarge;
+ XcmsColor tmp;
+
+ tmp.format = XcmsCIELabFormat;
+ /* Use some unreachable color on the given hue */
+ tmp.spec.CIELab.L_star = START_LSTAR;
+ tmp.spec.CIELab.a_star = XCMS_CIEASTAROFHUE(hue, START_CHROMA);
+ tmp.spec.CIELab.b_star = XCMS_CIEBSTAROFHUE(hue, START_CHROMA);
+ /*
+ * Convert from Lab to RGB
+ *
+ * Note that the CIEXYZ to RGBi conversion routine must stuff the
+ * out of bounds RGBi values in tmp when the ccc->gamutCompProc
+ * is NULL.
+ */
+ if ((_XcmsConvertColorsWithWhitePt(ccc, &tmp, ScreenWhitePointOfCCC(ccc),
+ (unsigned int)1, XcmsRGBiFormat, (Bool *) NULL)
+ == XcmsFailure) && tmp.format != XcmsRGBiFormat) {
+ return (XcmsFailure);
+ }
+
+ /* Now pick the smallest RGB */
+ nSmall = MIN3(tmp.spec.RGBi.red,
+ tmp.spec.RGBi.green,
+ tmp.spec.RGBi.blue);
+ /* Make the smallest RGB equal to zero */
+ tmp.spec.RGBi.red -= nSmall;
+ tmp.spec.RGBi.green -= nSmall;
+ tmp.spec.RGBi.blue -= nSmall;
+
+ /* Now pick the largest RGB */
+ nLarge = MAX3(tmp.spec.RGBi.red,
+ tmp.spec.RGBi.green,
+ tmp.spec.RGBi.blue);
+ /* Scale the RGB values based on the largest one */
+ tmp.spec.RGBi.red /= nLarge;
+ tmp.spec.RGBi.green /= nLarge;
+ tmp.spec.RGBi.blue /= nLarge;
+ tmp.format = XcmsRGBiFormat;
+
+ /* If the calling routine wants RGB value give them the ones used. */
+ if (pRGB_return) {
+ pRGB_return->red = tmp.spec.RGBi.red;
+ pRGB_return->green = tmp.spec.RGBi.green;
+ pRGB_return->blue = tmp.spec.RGBi.blue;
+ }
+
+ /* Convert from RGBi to Lab */
+ if (_XcmsConvertColorsWithWhitePt(ccc, &tmp,
+ ScreenWhitePointOfCCC(ccc), 1, XcmsCIELabFormat, (Bool *) NULL)
+ == XcmsFailure) {
+ return (XcmsFailure);
+ }
+
+ memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor));
+ return (XcmsSuccess);
+}
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELabQueryMaxLC - Compute maximum L* and chroma.
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIELabQueryMaxLC (
+ XcmsCCC ccc,
+ XcmsFloat hue_angle, /* hue_angle in degrees */
+ XcmsColor *pColor_return)
+
+/*
+ * DESCRIPTION
+ * Return the point of maximum chroma for the specified
+ * hue_angle.
+ *
+ * ASSUMPTIONS
+ * This routine assumes that the white point associated with
+ * the color specification is the Screen White Point. The
+ * Screen White Point will also be associated with the
+ * returned color specification.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ XcmsCCCRec myCCC;
+
+ /*
+ * Check Arguments
+ */
+ if (ccc == NULL || pColor_return == NULL) {
+ return(XcmsFailure);
+ }
+
+ /* Use my own CCC */
+ memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;
+ myCCC.gamutCompProc = (XcmsCompressionProc)NULL;
+
+ while (hue_angle < 0.0) {
+ hue_angle += 360.0;
+ }
+ while (hue_angle >= 360.0) {
+ hue_angle -= 360.0;
+ }
+
+ return(_XcmsCIELabQueryMaxLCRGB (&myCCC, radians(hue_angle), pColor_return,
+ (XcmsRGBi *)NULL));
+}
diff --git a/libX11/src/xcms/LabWpAj.c b/libX11/src/xcms/LabWpAj.c index 0559fdee3..6ec7fff8e 100644 --- a/libX11/src/xcms/LabWpAj.c +++ b/libX11/src/xcms/LabWpAj.c @@ -1,97 +1,97 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * CIELabWpAj.c - * - * DESCRIPTION - * This file contains routine(s) that support white point - * adjustment of color specifications in the CIE L*a*b* color - * space. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - -/* - * EXTERNS - */ - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELabWhiteShiftColors - * - * SYNOPSIS - */ -Status -XcmsCIELabWhiteShiftColors( - XcmsCCC ccc, - XcmsColor *pWhitePtFrom, - XcmsColor *pWhitePtTo, - XcmsColorFormat destSpecFmt, - XcmsColor *pColors_in_out, - unsigned int nColors, - Bool *pCompressed) -/* - * DESCRIPTION - * Adjust color specifications in XcmsColor structures for - * differences in white points. - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if succeeded without gamut compression, - * XcmsSuccessWithCompression if succeeded with gamut - * compression. - */ -{ - if (pWhitePtFrom == NULL || pWhitePtTo == NULL || pColors_in_out == NULL) { - return(0); - } - - /* - * Convert to CIELab using pWhitePtFrom - */ - if (_XcmsConvertColorsWithWhitePt(ccc, pColors_in_out, pWhitePtFrom, - nColors, XcmsCIELabFormat, pCompressed) == XcmsFailure) { - return(XcmsFailure); - } - - /* - * Convert from CIELab to destSpecFmt using pWhitePtTo - */ - return(_XcmsConvertColorsWithWhitePt(ccc, pColors_in_out, - pWhitePtTo, nColors, destSpecFmt, pCompressed)); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * CIELabWpAj.c
+ *
+ * DESCRIPTION
+ * This file contains routine(s) that support white point
+ * adjustment of color specifications in the CIE L*a*b* color
+ * space.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+/*
+ * EXTERNS
+ */
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELabWhiteShiftColors
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIELabWhiteShiftColors(
+ XcmsCCC ccc,
+ XcmsColor *pWhitePtFrom,
+ XcmsColor *pWhitePtTo,
+ XcmsColorFormat destSpecFmt,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * Adjust color specifications in XcmsColor structures for
+ * differences in white points.
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if succeeded without gamut compression,
+ * XcmsSuccessWithCompression if succeeded with gamut
+ * compression.
+ */
+{
+ if (pWhitePtFrom == NULL || pWhitePtTo == NULL || pColors_in_out == NULL) {
+ return(0);
+ }
+
+ /*
+ * Convert to CIELab using pWhitePtFrom
+ */
+ if (_XcmsConvertColorsWithWhitePt(ccc, pColors_in_out, pWhitePtFrom,
+ nColors, XcmsCIELabFormat, pCompressed) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Convert from CIELab to destSpecFmt using pWhitePtTo
+ */
+ return(_XcmsConvertColorsWithWhitePt(ccc, pColors_in_out,
+ pWhitePtTo, nColors, destSpecFmt, pCompressed));
+}
diff --git a/libX11/src/xcms/Luv.c b/libX11/src/xcms/Luv.c index 82bc2946a..0b1325252 100644 --- a/libX11/src/xcms/Luv.c +++ b/libX11/src/xcms/Luv.c @@ -1,401 +1,401 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * CIELuv.c - * - * DESCRIPTION - * This file contains routines that support the CIE L*u*v* - * color space to include conversions to and from the CIE - * XYZ space. - * - * DOCUMENTATION - * "TekColor Color Management System, System Implementor's Manual" - * and - * Fred W. Billmeyer & Max Saltzman, "Principles of Color - * Technology", John Wily & Sons, Inc, 1981. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <X11/Xos.h> -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - -#include <stdio.h> /* sscanf */ - - -/* - * FORWARD DECLARATIONS - */ - -static int CIELuv_ParseString(register char *spec, XcmsColor *pColor); -static Status XcmsCIELuv_ValidSpec(XcmsColor *pColor); - -/* - * DEFINES - * Internal definitions that need NOT be exported to any package - * or program using this package. - */ -#ifdef DBL_EPSILON -# define XMY_DBL_EPSILON DBL_EPSILON -#else -# define XMY_DBL_EPSILON 0.00001 -#endif - - -/* - * LOCAL VARIABLES - */ - - /* - * NULL terminated list of functions applied to get from CIELuv to CIEXYZ - */ -static XcmsConversionProc Fl_CIELuv_to_CIEXYZ[] = { - XcmsCIELuvToCIEuvY, - XcmsCIEuvYToCIEXYZ, - NULL -}; - - /* - * NULL terminated list of functions applied to get from CIEXYZ to CIELuv - */ -static XcmsConversionProc Fl_CIEXYZ_to_CIELuv[] = { - XcmsCIEXYZToCIEuvY, - XcmsCIEuvYToCIELuv, - NULL -}; - -/* - * GLOBALS - */ - - /* - * CIE Luv Color Space - */ -XcmsColorSpace XcmsCIELuvColorSpace = - { - _XcmsCIELuv_prefix, /* prefix */ - XcmsCIELuvFormat, /* id */ - CIELuv_ParseString, /* parseString */ - Fl_CIELuv_to_CIEXYZ, /* to_CIEXYZ */ - Fl_CIEXYZ_to_CIELuv, /* from_CIEXYZ */ - 1 - }; - - -/************************************************************************ - * * - * PRIVATE ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * CIELuv_ParseString - * - * SYNOPSIS - */ -static int -CIELuv_ParseString( - register char *spec, - XcmsColor *pColor) -/* - * DESCRIPTION - * This routines takes a string and attempts to convert - * it into a XcmsColor structure with XcmsCIELuvFormat. - * The assumed CIELuv string syntax is: - * CIELuv:<L>/<u>/<v> - * Where L, u, and v are in string input format for floats - * consisting of: - * a. an optional sign - * b. a string of numbers possibly containing a decimal point, - * c. an optional exponent field containing an 'E' or 'e' - * followed by a possibly signed integer string. - * - * RETURNS - * 0 if failed, non-zero otherwise. - */ -{ - int n; - char *pchar; - - if ((pchar = strchr(spec, ':')) == NULL) { - return(XcmsFailure); - } - n = (int)(pchar - spec); - - /* - * Check for proper prefix. - */ - if (strncmp(spec, _XcmsCIELuv_prefix, n) != 0) { - return(XcmsFailure); - } - - /* - * Attempt to parse the value portion. - */ - if (sscanf(spec + n + 1, "%lf/%lf/%lf", - &pColor->spec.CIELuv.L_star, - &pColor->spec.CIELuv.u_star, - &pColor->spec.CIELuv.v_star) != 3) { - char *s; /* Maybe failed due to locale */ - int f; - if ((s = strdup(spec))) { - for (f = 0; s[f]; ++f) - if (s[f] == '.') - s[f] = ','; - else if (s[f] == ',') - s[f] = '.'; - if (sscanf(s + n + 1, "%lf/%lf/%lf", - &pColor->spec.CIELuv.L_star, - &pColor->spec.CIELuv.u_star, - &pColor->spec.CIELuv.v_star) != 3) { - free(s); - return(XcmsFailure); - } - free(s); - } else - return(XcmsFailure); - } - pColor->format = XcmsCIELuvFormat; - pColor->pixel = 0; - return(XcmsCIELuv_ValidSpec(pColor)); -} - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELuv_ValidSpec - * - * SYNOPSIS - */ -static Status -XcmsCIELuv_ValidSpec( - XcmsColor *pColor) -/* - * DESCRIPTION - * Checks if color specification valid for CIE L*u*v*. - * - * RETURNS - * XcmsFailure if invalid, - * XcmsSuccess if valid. - * - */ -{ - if (pColor->format != XcmsCIELuvFormat - || - (pColor->spec.CIELuv.L_star < 0.0 - XMY_DBL_EPSILON) - || - (pColor->spec.CIELuv.L_star > 100.0 + XMY_DBL_EPSILON)) { - return(XcmsFailure); - } - return(XcmsSuccess); -} - - -/* - * NAME - * XcmsCIELuvToCIEuvY - convert CIELuv to CIEuvY - * - * SYNOPSIS - */ -Status -XcmsCIELuvToCIEuvY( - XcmsCCC ccc, - XcmsColor *pLuv_WhitePt, - XcmsColor *pColors_in_out, - unsigned int nColors) -/* - * DESCRIPTION - * Converts color specifications in an array of XcmsColor - * structures from CIELuv format to CIEuvY format. - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if succeeded. - * - */ -{ - XcmsColor *pColor = pColors_in_out; - XcmsColor whitePt; - XcmsCIEuvY uvY_return; - XcmsFloat tmpVal; - register int i; - - /* - * Check arguments - */ - if (pLuv_WhitePt == NULL || pColors_in_out == NULL) { - return(XcmsFailure); - } - - /* - * Make sure white point is in CIEuvY form - */ - if (pLuv_WhitePt->format != XcmsCIEuvYFormat) { - /* Make copy of the white point because we're going to modify it */ - memcpy((char *)&whitePt, (char *)pLuv_WhitePt, sizeof(XcmsColor)); - if (!_XcmsDIConvertColors(ccc, &whitePt, (XcmsColor *)NULL, - 1, XcmsCIEuvYFormat)) { - return(XcmsFailure); - } - pLuv_WhitePt = &whitePt; - } - /* Make sure it is a white point, i.e., Y == 1.0 */ - if (pLuv_WhitePt->spec.CIEuvY.Y != 1.0) { - return(XcmsFailure); - } - - /* - * Now convert each XcmsColor structure to CIEXYZ form - */ - for (i = 0; i < nColors; i++, pColor++) { - - /* Make sure original format is CIELuv and is valid */ - if (!XcmsCIELuv_ValidSpec(pColor)) { - return(XcmsFailure); - } - - if (pColor->spec.CIELuv.L_star < 7.99953624) { - uvY_return.Y = pColor->spec.CIELuv.L_star / 903.29; - } else { - tmpVal = (pColor->spec.CIELuv.L_star + 16.0) / 116.0; - uvY_return.Y = tmpVal * tmpVal * tmpVal; /* tmpVal ** 3 */ - } - - - - if (pColor->spec.CIELuv.L_star == 0.0) { - uvY_return.u_prime = pLuv_WhitePt->spec.CIEuvY.u_prime; - uvY_return.v_prime = pLuv_WhitePt->spec.CIEuvY.v_prime; - } else { - tmpVal = 13.0 * (pColor->spec.CIELuv.L_star / 100.0); - uvY_return.u_prime = pColor->spec.CIELuv.u_star/tmpVal + - pLuv_WhitePt->spec.CIEuvY.u_prime; - uvY_return.v_prime = pColor->spec.CIELuv.v_star/tmpVal + - pLuv_WhitePt->spec.CIEuvY.v_prime; - } - /* Copy result to pColor */ - memcpy((char *)&pColor->spec, (char *)&uvY_return, sizeof(XcmsCIEuvY)); - - /* Identify that the format is now CIEuvY */ - pColor->format = XcmsCIEuvYFormat; - } - return(XcmsSuccess); -} - - -/* - * NAME - * XcmsCIEuvYToCIELuv - convert CIEuvY to CIELuv - * - * SYNOPSIS - */ -Status -XcmsCIEuvYToCIELuv( - XcmsCCC ccc, - XcmsColor *pLuv_WhitePt, - XcmsColor *pColors_in_out, - unsigned int nColors) -/* - * DESCRIPTION - * Converts color specifications in an array of XcmsColor - * structures from CIEuvY format to CIELab format. - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if succeeded. - * - */ -{ - XcmsColor *pColor = pColors_in_out; - XcmsColor whitePt; - XcmsCIELuv Luv_return; - XcmsFloat tmpVal; - register int i; - - /* - * Check arguments - */ - if (pLuv_WhitePt == NULL || pColors_in_out == NULL) { - return(XcmsFailure); - } - - /* - * Make sure white point is in CIEuvY form - */ - if (pLuv_WhitePt->format != XcmsCIEuvYFormat) { - /* Make copy of the white point because we're going to modify it */ - memcpy((char *)&whitePt, (char *)pLuv_WhitePt, sizeof(XcmsColor)); - if (!_XcmsDIConvertColors(ccc, &whitePt, - (XcmsColor *)NULL, 1, XcmsCIEuvYFormat)) { - return(XcmsFailure); - } - pLuv_WhitePt = &whitePt; - } - /* Make sure it is a white point, i.e., Y == 1.0 */ - if (pLuv_WhitePt->spec.CIEuvY.Y != 1.0) { - return(XcmsFailure); - } - - /* - * Now convert each XcmsColor structure to CIEXYZ form - */ - for (i = 0; i < nColors; i++, pColor++) { - - if (!_XcmsCIEuvY_ValidSpec(pColor)) { - return(XcmsFailure); - } - - /* Now convert the uvY to Luv */ - Luv_return.L_star = - (pColor->spec.CIEuvY.Y < 0.008856) - ? - (pColor->spec.CIEuvY.Y * 903.29) - : - ((XcmsFloat)(XCMS_CUBEROOT(pColor->spec.CIEuvY.Y) * 116.0) - 16.0); - tmpVal = 13.0 * (Luv_return.L_star / 100.0); - Luv_return.u_star = tmpVal * - (pColor->spec.CIEuvY.u_prime - pLuv_WhitePt->spec.CIEuvY.u_prime); - Luv_return.v_star = tmpVal * - (pColor->spec.CIEuvY.v_prime - pLuv_WhitePt->spec.CIEuvY.v_prime); - - /* Copy result to pColor */ - memcpy((char *)&pColor->spec, (char *)&Luv_return, sizeof(XcmsCIELuv)); - - /* Identify that the format is now CIEuvY */ - pColor->format = XcmsCIELuvFormat; - } - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * CIELuv.c
+ *
+ * DESCRIPTION
+ * This file contains routines that support the CIE L*u*v*
+ * color space to include conversions to and from the CIE
+ * XYZ space.
+ *
+ * DOCUMENTATION
+ * "TekColor Color Management System, System Implementor's Manual"
+ * and
+ * Fred W. Billmeyer & Max Saltzman, "Principles of Color
+ * Technology", John Wily & Sons, Inc, 1981.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xos.h>
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+#include <stdio.h> /* sscanf */
+
+
+/*
+ * FORWARD DECLARATIONS
+ */
+
+static int CIELuv_ParseString(register char *spec, XcmsColor *pColor);
+static Status XcmsCIELuv_ValidSpec(XcmsColor *pColor);
+
+/*
+ * DEFINES
+ * Internal definitions that need NOT be exported to any package
+ * or program using this package.
+ */
+#ifdef DBL_EPSILON
+# define XMY_DBL_EPSILON DBL_EPSILON
+#else
+# define XMY_DBL_EPSILON 0.00001
+#endif
+
+
+/*
+ * LOCAL VARIABLES
+ */
+
+ /*
+ * NULL terminated list of functions applied to get from CIELuv to CIEXYZ
+ */
+static XcmsConversionProc Fl_CIELuv_to_CIEXYZ[] = {
+ XcmsCIELuvToCIEuvY,
+ XcmsCIEuvYToCIEXYZ,
+ NULL
+};
+
+ /*
+ * NULL terminated list of functions applied to get from CIEXYZ to CIELuv
+ */
+static XcmsConversionProc Fl_CIEXYZ_to_CIELuv[] = {
+ XcmsCIEXYZToCIEuvY,
+ XcmsCIEuvYToCIELuv,
+ NULL
+};
+
+/*
+ * GLOBALS
+ */
+
+ /*
+ * CIE Luv Color Space
+ */
+XcmsColorSpace XcmsCIELuvColorSpace =
+ {
+ _XcmsCIELuv_prefix, /* prefix */
+ XcmsCIELuvFormat, /* id */
+ CIELuv_ParseString, /* parseString */
+ Fl_CIELuv_to_CIEXYZ, /* to_CIEXYZ */
+ Fl_CIEXYZ_to_CIELuv, /* from_CIEXYZ */
+ 1
+ };
+
+
+/************************************************************************
+ * *
+ * PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * CIELuv_ParseString
+ *
+ * SYNOPSIS
+ */
+static int
+CIELuv_ParseString(
+ register char *spec,
+ XcmsColor *pColor)
+/*
+ * DESCRIPTION
+ * This routines takes a string and attempts to convert
+ * it into a XcmsColor structure with XcmsCIELuvFormat.
+ * The assumed CIELuv string syntax is:
+ * CIELuv:<L>/<u>/<v>
+ * Where L, u, and v are in string input format for floats
+ * consisting of:
+ * a. an optional sign
+ * b. a string of numbers possibly containing a decimal point,
+ * c. an optional exponent field containing an 'E' or 'e'
+ * followed by a possibly signed integer string.
+ *
+ * RETURNS
+ * 0 if failed, non-zero otherwise.
+ */
+{
+ int n;
+ char *pchar;
+
+ if ((pchar = strchr(spec, ':')) == NULL) {
+ return(XcmsFailure);
+ }
+ n = (int)(pchar - spec);
+
+ /*
+ * Check for proper prefix.
+ */
+ if (strncmp(spec, _XcmsCIELuv_prefix, n) != 0) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Attempt to parse the value portion.
+ */
+ if (sscanf(spec + n + 1, "%lf/%lf/%lf",
+ &pColor->spec.CIELuv.L_star,
+ &pColor->spec.CIELuv.u_star,
+ &pColor->spec.CIELuv.v_star) != 3) {
+ char *s; /* Maybe failed due to locale */
+ int f;
+ if ((s = strdup(spec))) {
+ for (f = 0; s[f]; ++f)
+ if (s[f] == '.')
+ s[f] = ',';
+ else if (s[f] == ',')
+ s[f] = '.';
+ if (sscanf(s + n + 1, "%lf/%lf/%lf",
+ &pColor->spec.CIELuv.L_star,
+ &pColor->spec.CIELuv.u_star,
+ &pColor->spec.CIELuv.v_star) != 3) {
+ free(s);
+ return(XcmsFailure);
+ }
+ free(s);
+ } else
+ return(XcmsFailure);
+ }
+ pColor->format = XcmsCIELuvFormat;
+ pColor->pixel = 0;
+ return(XcmsCIELuv_ValidSpec(pColor));
+}
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELuv_ValidSpec
+ *
+ * SYNOPSIS
+ */
+static Status
+XcmsCIELuv_ValidSpec(
+ XcmsColor *pColor)
+/*
+ * DESCRIPTION
+ * Checks if color specification valid for CIE L*u*v*.
+ *
+ * RETURNS
+ * XcmsFailure if invalid,
+ * XcmsSuccess if valid.
+ *
+ */
+{
+ if (pColor->format != XcmsCIELuvFormat
+ ||
+ (pColor->spec.CIELuv.L_star < 0.0 - XMY_DBL_EPSILON)
+ ||
+ (pColor->spec.CIELuv.L_star > 100.0 + XMY_DBL_EPSILON)) {
+ return(XcmsFailure);
+ }
+ return(XcmsSuccess);
+}
+
+
+/*
+ * NAME
+ * XcmsCIELuvToCIEuvY - convert CIELuv to CIEuvY
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIELuvToCIEuvY(
+ XcmsCCC ccc,
+ XcmsColor *pLuv_WhitePt,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors)
+/*
+ * DESCRIPTION
+ * Converts color specifications in an array of XcmsColor
+ * structures from CIELuv format to CIEuvY format.
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if succeeded.
+ *
+ */
+{
+ XcmsColor *pColor = pColors_in_out;
+ XcmsColor whitePt;
+ XcmsCIEuvY uvY_return;
+ XcmsFloat tmpVal;
+ register int i;
+
+ /*
+ * Check arguments
+ */
+ if (pLuv_WhitePt == NULL || pColors_in_out == NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Make sure white point is in CIEuvY form
+ */
+ if (pLuv_WhitePt->format != XcmsCIEuvYFormat) {
+ /* Make copy of the white point because we're going to modify it */
+ memcpy((char *)&whitePt, (char *)pLuv_WhitePt, sizeof(XcmsColor));
+ if (!_XcmsDIConvertColors(ccc, &whitePt, (XcmsColor *)NULL,
+ 1, XcmsCIEuvYFormat)) {
+ return(XcmsFailure);
+ }
+ pLuv_WhitePt = &whitePt;
+ }
+ /* Make sure it is a white point, i.e., Y == 1.0 */
+ if (pLuv_WhitePt->spec.CIEuvY.Y != 1.0) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Now convert each XcmsColor structure to CIEXYZ form
+ */
+ for (i = 0; i < nColors; i++, pColor++) {
+
+ /* Make sure original format is CIELuv and is valid */
+ if (!XcmsCIELuv_ValidSpec(pColor)) {
+ return(XcmsFailure);
+ }
+
+ if (pColor->spec.CIELuv.L_star < 7.99953624) {
+ uvY_return.Y = pColor->spec.CIELuv.L_star / 903.29;
+ } else {
+ tmpVal = (pColor->spec.CIELuv.L_star + 16.0) / 116.0;
+ uvY_return.Y = tmpVal * tmpVal * tmpVal; /* tmpVal ** 3 */
+ }
+
+
+
+ if (pColor->spec.CIELuv.L_star == 0.0) {
+ uvY_return.u_prime = pLuv_WhitePt->spec.CIEuvY.u_prime;
+ uvY_return.v_prime = pLuv_WhitePt->spec.CIEuvY.v_prime;
+ } else {
+ tmpVal = 13.0 * (pColor->spec.CIELuv.L_star / 100.0);
+ uvY_return.u_prime = pColor->spec.CIELuv.u_star/tmpVal +
+ pLuv_WhitePt->spec.CIEuvY.u_prime;
+ uvY_return.v_prime = pColor->spec.CIELuv.v_star/tmpVal +
+ pLuv_WhitePt->spec.CIEuvY.v_prime;
+ }
+ /* Copy result to pColor */
+ memcpy((char *)&pColor->spec, (char *)&uvY_return, sizeof(XcmsCIEuvY));
+
+ /* Identify that the format is now CIEuvY */
+ pColor->format = XcmsCIEuvYFormat;
+ }
+ return(XcmsSuccess);
+}
+
+
+/*
+ * NAME
+ * XcmsCIEuvYToCIELuv - convert CIEuvY to CIELuv
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIEuvYToCIELuv(
+ XcmsCCC ccc,
+ XcmsColor *pLuv_WhitePt,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors)
+/*
+ * DESCRIPTION
+ * Converts color specifications in an array of XcmsColor
+ * structures from CIEuvY format to CIELab format.
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if succeeded.
+ *
+ */
+{
+ XcmsColor *pColor = pColors_in_out;
+ XcmsColor whitePt;
+ XcmsCIELuv Luv_return;
+ XcmsFloat tmpVal;
+ register int i;
+
+ /*
+ * Check arguments
+ */
+ if (pLuv_WhitePt == NULL || pColors_in_out == NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Make sure white point is in CIEuvY form
+ */
+ if (pLuv_WhitePt->format != XcmsCIEuvYFormat) {
+ /* Make copy of the white point because we're going to modify it */
+ memcpy((char *)&whitePt, (char *)pLuv_WhitePt, sizeof(XcmsColor));
+ if (!_XcmsDIConvertColors(ccc, &whitePt,
+ (XcmsColor *)NULL, 1, XcmsCIEuvYFormat)) {
+ return(XcmsFailure);
+ }
+ pLuv_WhitePt = &whitePt;
+ }
+ /* Make sure it is a white point, i.e., Y == 1.0 */
+ if (pLuv_WhitePt->spec.CIEuvY.Y != 1.0) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Now convert each XcmsColor structure to CIEXYZ form
+ */
+ for (i = 0; i < nColors; i++, pColor++) {
+
+ if (!_XcmsCIEuvY_ValidSpec(pColor)) {
+ return(XcmsFailure);
+ }
+
+ /* Now convert the uvY to Luv */
+ Luv_return.L_star =
+ (pColor->spec.CIEuvY.Y < 0.008856)
+ ?
+ (pColor->spec.CIEuvY.Y * 903.29)
+ :
+ ((XcmsFloat)(XCMS_CUBEROOT(pColor->spec.CIEuvY.Y) * 116.0) - 16.0);
+ tmpVal = 13.0 * (Luv_return.L_star / 100.0);
+ Luv_return.u_star = tmpVal *
+ (pColor->spec.CIEuvY.u_prime - pLuv_WhitePt->spec.CIEuvY.u_prime);
+ Luv_return.v_star = tmpVal *
+ (pColor->spec.CIEuvY.v_prime - pLuv_WhitePt->spec.CIEuvY.v_prime);
+
+ /* Copy result to pColor */
+ memcpy((char *)&pColor->spec, (char *)&Luv_return, sizeof(XcmsCIELuv));
+
+ /* Identify that the format is now CIEuvY */
+ pColor->format = XcmsCIELuvFormat;
+ }
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/LuvGcC.c b/libX11/src/xcms/LuvGcC.c index cadf4a8b2..c760f0fbb 100644 --- a/libX11/src/xcms/LuvGcC.c +++ b/libX11/src/xcms/LuvGcC.c @@ -1,127 +1,127 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * CIELuvGcC.c - * - * DESCRIPTION - * Source for XcmsCIELuvClipuv() gamut compression routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELuvClipuv - Reduce the chroma for a hue and L* - * - * SYNOPSIS - */ -/* ARGSUSED */ -Status -XcmsCIELuvClipuv ( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - unsigned int nColors, - unsigned int i, - Bool *pCompressed) -/* - * DESCRIPTION - * Reduce the Chroma for a specific hue and chroma to - * to bring the given color into the gamut of the - * specified device. As required of gamut compression - * functions, this routine returns pColor_in_out - * in XcmsCIEXYZFormat on successful completion. - * - * Since this routine works with the L* within - * pColor_in_out intermediate results may be returned - * even though it may be invalid. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - Status retval; - XcmsColor *pColor; - - /* - * Color specification passed as input can be assumed to: - * 1. Be in XcmsCIEXYZFormat - * 2. Already be white point adjusted for the Screen White Point. - * This means that the white point now associated with this - * color spec is the Screen White Point (even if the - * ccc->clientWhitePt differs). - */ - - pColor = pColors_in_out + i; - - if (ccc->visual->class < PseudoColor) { - /* - * GRAY ! - */ - _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc), - 1, XcmsCIELuvFormat); - _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc), - 1, XcmsCIEXYZFormat); - if (pCompressed) { - *(pCompressed + i) = True; - } - return(XcmsSuccess); - } else { - if (pColor->format != XcmsCIELuvFormat) { - if (_XcmsDIConvertColors(ccc, pColor, - &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIELuvFormat) - == XcmsFailure) { - return(XcmsFailure); - } - } - if (XcmsCIELuvQueryMaxC(ccc, - degrees(XCMS_CIELUV_PMETRIC_HUE(pColor->spec.CIELuv.u_star, - pColor->spec.CIELuv.v_star)), - pColor->spec.CIELuv.L_star, - pColor) == XcmsFailure) { - return(XcmsFailure); - } - retval = _XcmsDIConvertColors(ccc, pColor, - &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat); - if (retval != XcmsFailure && pCompressed != NULL) { - *(pCompressed + i) = True; - } - return(retval); - } -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * CIELuvGcC.c
+ *
+ * DESCRIPTION
+ * Source for XcmsCIELuvClipuv() gamut compression routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELuvClipuv - Reduce the chroma for a hue and L*
+ *
+ * SYNOPSIS
+ */
+/* ARGSUSED */
+Status
+XcmsCIELuvClipuv (
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors,
+ unsigned int i,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * Reduce the Chroma for a specific hue and chroma to
+ * to bring the given color into the gamut of the
+ * specified device. As required of gamut compression
+ * functions, this routine returns pColor_in_out
+ * in XcmsCIEXYZFormat on successful completion.
+ *
+ * Since this routine works with the L* within
+ * pColor_in_out intermediate results may be returned
+ * even though it may be invalid.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ Status retval;
+ XcmsColor *pColor;
+
+ /*
+ * Color specification passed as input can be assumed to:
+ * 1. Be in XcmsCIEXYZFormat
+ * 2. Already be white point adjusted for the Screen White Point.
+ * This means that the white point now associated with this
+ * color spec is the Screen White Point (even if the
+ * ccc->clientWhitePt differs).
+ */
+
+ pColor = pColors_in_out + i;
+
+ if (ccc->visual->class < PseudoColor) {
+ /*
+ * GRAY !
+ */
+ _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc),
+ 1, XcmsCIELuvFormat);
+ _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc),
+ 1, XcmsCIEXYZFormat);
+ if (pCompressed) {
+ *(pCompressed + i) = True;
+ }
+ return(XcmsSuccess);
+ } else {
+ if (pColor->format != XcmsCIELuvFormat) {
+ if (_XcmsDIConvertColors(ccc, pColor,
+ &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIELuvFormat)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+ if (XcmsCIELuvQueryMaxC(ccc,
+ degrees(XCMS_CIELUV_PMETRIC_HUE(pColor->spec.CIELuv.u_star,
+ pColor->spec.CIELuv.v_star)),
+ pColor->spec.CIELuv.L_star,
+ pColor) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ retval = _XcmsDIConvertColors(ccc, pColor,
+ &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
+ if (retval != XcmsFailure && pCompressed != NULL) {
+ *(pCompressed + i) = True;
+ }
+ return(retval);
+ }
+}
diff --git a/libX11/src/xcms/LuvGcL.c b/libX11/src/xcms/LuvGcL.c index f5b6d99e4..b6305eae1 100644 --- a/libX11/src/xcms/LuvGcL.c +++ b/libX11/src/xcms/LuvGcL.c @@ -1,174 +1,174 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * CIELuvGcL.c - * - * DESCRIPTION - * Source for XcmsCIELuvClipL() gamut compression routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELuvClipL - Return the closest L* - * - * SYNOPSIS - */ -/* ARGSUSED */ -Status -XcmsCIELuvClipL ( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - unsigned int nColors, - unsigned int i, - Bool *pCompressed) -/* - * DESCRIPTION - * Return the closest L* for a specific hue and chroma. - * This routine takes any color as input and outputs - * a CIE XYZ color. - * - * Since this routine works with the L* within - * pColor_in_out intermediate results may be returned - * even though it may be invalid. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - XcmsCCCRec myCCC; - XcmsColor *pColor; - XcmsColor Luv_max; - XcmsFloat hue, chroma, maxChroma; - Status retval; - - /* Use my own CCC */ - memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* Inherit Screen WP */ - myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut compression */ - - /* - * Color specification passed as input can be assumed to: - * 1. Be in XcmsCIEXYZFormat - * 2. Already be white point adjusted for the Screen White Point. - * This means that the white point now associated with this - * color spec is the Screen White Point (even if the - * ccc->clientWhitePt differs). - */ - - pColor = pColors_in_out + i; - - if (ccc->visual->class < StaticColor) { - /* - * GRAY ! - */ - return(XcmsFailure); - } else { - /* Convert from CIEXYZ to CIE L*u*v* format */ - if (_XcmsDIConvertColors(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELuvFormat) - == XcmsFailure) { - return(XcmsFailure); - } - - hue = XCMS_CIELUV_PMETRIC_HUE(pColor->spec.CIELuv.u_star, - pColor->spec.CIELuv.v_star); - chroma = XCMS_CIELUV_PMETRIC_CHROMA(pColor->spec.CIELuv.u_star, - pColor->spec.CIELuv.v_star); - /* Step 1: compute the maximum L* and chroma for this hue. */ - /* This copy may be overkill but it preserves the pixel etc. */ - memcpy((char *)&Luv_max, (char *)pColor, sizeof(XcmsColor)); - if (_XcmsCIELuvQueryMaxLCRGB (&myCCC, hue, &Luv_max, - (XcmsRGBi *)NULL) == XcmsFailure) { - return (XcmsFailure); - } - maxChroma = XCMS_CIELUV_PMETRIC_CHROMA(Luv_max.spec.CIELuv.u_star, - Luv_max.spec.CIELuv.v_star); - - /* Now check and return the appropriate L* */ - if (chroma == maxChroma) { - /* When the chroma input is equal to the maximum chroma */ - /* merely return the L* for that chroma. */ - memcpy((char *)pColor, (char *)&Luv_max, sizeof(XcmsColor)); - retval = _XcmsDIConvertColors(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat); - } else if (chroma > maxChroma) { - /* When the chroma input is greater than the maximum chroma */ - /* merely return the L* and chroma for the given hue. */ - memcpy((char *)pColor, (char *)&Luv_max, sizeof(XcmsColor)); - return (XcmsFailure); - } else if (pColor->spec.CIELuv.L_star < Luv_max.spec.CIELuv.L_star) { - /* Find the minimum lightness for the given chroma. */ - if (pColor->format != XcmsCIELuvFormat) { - if (_XcmsDIConvertColors(ccc, pColor, - ScreenWhitePointOfCCC(ccc), 1, XcmsCIELuvFormat) - == XcmsFailure) { - return(XcmsFailure); - } - } - if (XcmsCIELuvQueryMinL(&myCCC, degrees(hue), chroma, pColor) - == XcmsFailure) { - return (XcmsFailure); - } - retval = _XcmsDIConvertColors(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat); - } else { - /* Find the maximum lightness for the given chroma. */ - if (pColor->format != XcmsCIELuvFormat) { - if (_XcmsDIConvertColors(ccc, pColor, - ScreenWhitePointOfCCC(ccc), 1, XcmsCIELuvFormat) - == XcmsFailure) { - return(XcmsFailure); - } - } - if (XcmsCIELuvQueryMaxL(&myCCC, degrees(hue), chroma, pColor) - == XcmsFailure) { - return (XcmsFailure); - } - retval = _XcmsDIConvertColors(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat); - } - if (retval != XcmsFailure && pCompressed != NULL) { - *(pCompressed + i) = True; - } - return(retval); - } -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * CIELuvGcL.c
+ *
+ * DESCRIPTION
+ * Source for XcmsCIELuvClipL() gamut compression routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELuvClipL - Return the closest L*
+ *
+ * SYNOPSIS
+ */
+/* ARGSUSED */
+Status
+XcmsCIELuvClipL (
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors,
+ unsigned int i,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * Return the closest L* for a specific hue and chroma.
+ * This routine takes any color as input and outputs
+ * a CIE XYZ color.
+ *
+ * Since this routine works with the L* within
+ * pColor_in_out intermediate results may be returned
+ * even though it may be invalid.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ XcmsCCCRec myCCC;
+ XcmsColor *pColor;
+ XcmsColor Luv_max;
+ XcmsFloat hue, chroma, maxChroma;
+ Status retval;
+
+ /* Use my own CCC */
+ memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* Inherit Screen WP */
+ myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut compression */
+
+ /*
+ * Color specification passed as input can be assumed to:
+ * 1. Be in XcmsCIEXYZFormat
+ * 2. Already be white point adjusted for the Screen White Point.
+ * This means that the white point now associated with this
+ * color spec is the Screen White Point (even if the
+ * ccc->clientWhitePt differs).
+ */
+
+ pColor = pColors_in_out + i;
+
+ if (ccc->visual->class < StaticColor) {
+ /*
+ * GRAY !
+ */
+ return(XcmsFailure);
+ } else {
+ /* Convert from CIEXYZ to CIE L*u*v* format */
+ if (_XcmsDIConvertColors(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELuvFormat)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ hue = XCMS_CIELUV_PMETRIC_HUE(pColor->spec.CIELuv.u_star,
+ pColor->spec.CIELuv.v_star);
+ chroma = XCMS_CIELUV_PMETRIC_CHROMA(pColor->spec.CIELuv.u_star,
+ pColor->spec.CIELuv.v_star);
+ /* Step 1: compute the maximum L* and chroma for this hue. */
+ /* This copy may be overkill but it preserves the pixel etc. */
+ memcpy((char *)&Luv_max, (char *)pColor, sizeof(XcmsColor));
+ if (_XcmsCIELuvQueryMaxLCRGB (&myCCC, hue, &Luv_max,
+ (XcmsRGBi *)NULL) == XcmsFailure) {
+ return (XcmsFailure);
+ }
+ maxChroma = XCMS_CIELUV_PMETRIC_CHROMA(Luv_max.spec.CIELuv.u_star,
+ Luv_max.spec.CIELuv.v_star);
+
+ /* Now check and return the appropriate L* */
+ if (chroma == maxChroma) {
+ /* When the chroma input is equal to the maximum chroma */
+ /* merely return the L* for that chroma. */
+ memcpy((char *)pColor, (char *)&Luv_max, sizeof(XcmsColor));
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat);
+ } else if (chroma > maxChroma) {
+ /* When the chroma input is greater than the maximum chroma */
+ /* merely return the L* and chroma for the given hue. */
+ memcpy((char *)pColor, (char *)&Luv_max, sizeof(XcmsColor));
+ return (XcmsFailure);
+ } else if (pColor->spec.CIELuv.L_star < Luv_max.spec.CIELuv.L_star) {
+ /* Find the minimum lightness for the given chroma. */
+ if (pColor->format != XcmsCIELuvFormat) {
+ if (_XcmsDIConvertColors(ccc, pColor,
+ ScreenWhitePointOfCCC(ccc), 1, XcmsCIELuvFormat)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+ if (XcmsCIELuvQueryMinL(&myCCC, degrees(hue), chroma, pColor)
+ == XcmsFailure) {
+ return (XcmsFailure);
+ }
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat);
+ } else {
+ /* Find the maximum lightness for the given chroma. */
+ if (pColor->format != XcmsCIELuvFormat) {
+ if (_XcmsDIConvertColors(ccc, pColor,
+ ScreenWhitePointOfCCC(ccc), 1, XcmsCIELuvFormat)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+ if (XcmsCIELuvQueryMaxL(&myCCC, degrees(hue), chroma, pColor)
+ == XcmsFailure) {
+ return (XcmsFailure);
+ }
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat);
+ }
+ if (retval != XcmsFailure && pCompressed != NULL) {
+ *(pCompressed + i) = True;
+ }
+ return(retval);
+ }
+}
diff --git a/libX11/src/xcms/LuvGcLC.c b/libX11/src/xcms/LuvGcLC.c index a9f8cbaf1..03da90ff4 100644 --- a/libX11/src/xcms/LuvGcLC.c +++ b/libX11/src/xcms/LuvGcLC.c @@ -1,223 +1,223 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * CIELuvGcLC.c - * - * DESCRIPTION - * Source for XcmsCIELuvClipLuv() gamut - * compression function. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include <math.h> -#include "Cv.h" - -/* - * INTERNALS - * Internal defines that need NOT be exported to any package or - * program using this package. - */ -#define MAXBISECTCOUNT 100 - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELuvClipLuv - Return the closest L* and chroma - * - * SYNOPSIS - */ -/* ARGSUSED */ -Status -XcmsCIELuvClipLuv ( - XcmsCCC ccc, - XcmsColor *pColors_in_out, - unsigned int nColors, - unsigned int i, - Bool *pCompressed) -/* - * DESCRIPTION - * This routine will find the closest L* and chroma - * for a specific hue. The color input is converted to - * CIE L*u*v* format and returned as CIE XYZ format. - * - * Since this routine works with the L* within - * pColor_in_out intermediate results may be returned - * even though it may be invalid. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - Status retval; - XcmsCCCRec myCCC; - XcmsColor *pColor; - XcmsColor Luv_max; - XcmsFloat hue, chroma, maxChroma; - XcmsFloat Chroma, bestChroma, Lstar, maxLstar, saveLstar; - XcmsFloat bestLstar, bestustar, bestvstar; - XcmsFloat nT, saveDist, tmpDist; - XcmsRGBi rgb_max; - int nCount, nMaxCount, nI, nILast; - - /* Use my own CCC */ - memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* inherit screen white */ - myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut compression func */ - - /* - * Color specification passed as input can be assumed to: - * 1. Be in XcmsCIEXYZFormat - * 2. Already be white point adjusted for the Screen White Point. - * This means that the white point now associated with this - * color spec is the Screen White Point (even if the - * ccc->clientWhitePt differs). - */ - - pColor = pColors_in_out + i; - - if (ccc->visual->class < StaticColor) { - /* - * GRAY ! - */ - _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc), - 1, XcmsCIELuvFormat); - _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc), - 1, XcmsCIEXYZFormat); - if (pCompressed) { - *(pCompressed + i) = True; - } - return(XcmsSuccess); - } - - /* Convert from CIEXYZ to CIELuv format */ - if (_XcmsDIConvertColors(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELuvFormat) - == XcmsFailure) { - return(XcmsFailure); - } - - /* Step 1: compute the maximum L* and chroma for this hue. */ - /* This copy may be overkill but it preserves the pixel etc. */ - saveLstar = pColor->spec.CIELuv.L_star; - hue = XCMS_CIELUV_PMETRIC_HUE(pColor->spec.CIELuv.u_star, - pColor->spec.CIELuv.v_star); - chroma = XCMS_CIELUV_PMETRIC_CHROMA(pColor->spec.CIELuv.u_star, - pColor->spec.CIELuv.v_star); - memcpy((char *)&Luv_max, (char *)pColor, sizeof(XcmsColor)); - if (_XcmsCIELuvQueryMaxLCRGB (&myCCC, hue, &Luv_max, &rgb_max) - == XcmsFailure) { - return (XcmsFailure); - } - maxLstar = Luv_max.spec.CIELuv.L_star; - - /* Now check and return the appropriate L* */ - if (saveLstar == maxLstar) { - /* When the L* input is equal to the maximum L* */ - /* merely return the maximum Luv point. */ - memcpy((char *)pColor, (char *)&Luv_max, sizeof(XcmsColor)); - retval = _XcmsDIConvertColors(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat); - } else { - /* return the closest point on the hue leaf. */ - /* must do a bisection here to compute the delta e. */ - maxChroma = XCMS_CIELUV_PMETRIC_CHROMA(Luv_max.spec.CIELuv.u_star, - Luv_max.spec.CIELuv.v_star); - nMaxCount = MAXBISECTCOUNT; - nI = nMaxCount / 2; - bestLstar = Lstar = pColor->spec.CIELuv.L_star; - bestustar = pColor->spec.CIELuv.u_star; - bestvstar = pColor->spec.CIELuv.v_star; - bestChroma = Chroma = chroma; - saveDist = XCMS_SQRT(((Chroma - maxChroma) * (Chroma - maxChroma)) + - ((Lstar - maxLstar) * (Lstar - maxLstar))); - for (nCount = 0; nCount < nMaxCount; nCount++) { - nT = (XcmsFloat) nI / (XcmsFloat) nMaxCount; - if (saveLstar > maxLstar) { - pColor->spec.RGBi.red = rgb_max.red * (1.0 - nT) + nT; - pColor->spec.RGBi.green = rgb_max.green * (1.0 - nT) + nT; - pColor->spec.RGBi.blue = rgb_max.blue * (1.0 - nT) + nT; - } else { - pColor->spec.RGBi.red = rgb_max.red - (rgb_max.red * nT); - pColor->spec.RGBi.green = rgb_max.green - (rgb_max.green * nT); - pColor->spec.RGBi.blue = rgb_max.blue - (rgb_max.blue * nT); - } - pColor->format = XcmsRGBiFormat; - - /* Convert from RGBi to CIE Luv */ - if (_XcmsConvertColorsWithWhitePt(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELuvFormat, - (Bool *) NULL) == XcmsFailure) { - return (XcmsFailure); - } - chroma = XCMS_CIELUV_PMETRIC_CHROMA(pColor->spec.CIELuv.u_star, - pColor->spec.CIELuv.v_star); - tmpDist = XCMS_SQRT(((Chroma - chroma) * (Chroma - chroma)) + - ((Lstar - pColor->spec.CIELuv.L_star) * - (Lstar - pColor->spec.CIELuv.L_star))); - nILast = nI; - if (tmpDist > saveDist) { - nI /= 2; - } else { - nI = (nMaxCount + nI) / 2; - saveDist = tmpDist; - bestLstar = pColor->spec.CIELuv.L_star; - bestustar = pColor->spec.CIELuv.u_star; - bestvstar = pColor->spec.CIELuv.v_star; - bestChroma = chroma; - } - if (nI == nILast || nI == 0) { - break; - } - } - if (bestChroma >= maxChroma) { - pColor->spec.CIELuv.L_star = maxLstar; - pColor->spec.CIELuv.u_star = Luv_max.spec.CIELuv.u_star; - pColor->spec.CIELuv.v_star = Luv_max.spec.CIELuv.v_star; - } else { - pColor->spec.CIELuv.L_star = bestLstar; - pColor->spec.CIELuv.u_star = bestustar; - pColor->spec.CIELuv.v_star = bestvstar; - } - retval = _XcmsDIConvertColors(&myCCC, pColor, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat); - - if (retval != XcmsFailure && pCompressed != NULL) { - *(pCompressed + i) = True; - } - } - return(retval); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * CIELuvGcLC.c
+ *
+ * DESCRIPTION
+ * Source for XcmsCIELuvClipLuv() gamut
+ * compression function.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include <math.h>
+#include "Cv.h"
+
+/*
+ * INTERNALS
+ * Internal defines that need NOT be exported to any package or
+ * program using this package.
+ */
+#define MAXBISECTCOUNT 100
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELuvClipLuv - Return the closest L* and chroma
+ *
+ * SYNOPSIS
+ */
+/* ARGSUSED */
+Status
+XcmsCIELuvClipLuv (
+ XcmsCCC ccc,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors,
+ unsigned int i,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * This routine will find the closest L* and chroma
+ * for a specific hue. The color input is converted to
+ * CIE L*u*v* format and returned as CIE XYZ format.
+ *
+ * Since this routine works with the L* within
+ * pColor_in_out intermediate results may be returned
+ * even though it may be invalid.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ Status retval;
+ XcmsCCCRec myCCC;
+ XcmsColor *pColor;
+ XcmsColor Luv_max;
+ XcmsFloat hue, chroma, maxChroma;
+ XcmsFloat Chroma, bestChroma, Lstar, maxLstar, saveLstar;
+ XcmsFloat bestLstar, bestustar, bestvstar;
+ XcmsFloat nT, saveDist, tmpDist;
+ XcmsRGBi rgb_max;
+ int nCount, nMaxCount, nI, nILast;
+
+ /* Use my own CCC */
+ memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;/* inherit screen white */
+ myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut compression func */
+
+ /*
+ * Color specification passed as input can be assumed to:
+ * 1. Be in XcmsCIEXYZFormat
+ * 2. Already be white point adjusted for the Screen White Point.
+ * This means that the white point now associated with this
+ * color spec is the Screen White Point (even if the
+ * ccc->clientWhitePt differs).
+ */
+
+ pColor = pColors_in_out + i;
+
+ if (ccc->visual->class < StaticColor) {
+ /*
+ * GRAY !
+ */
+ _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc),
+ 1, XcmsCIELuvFormat);
+ _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc),
+ 1, XcmsCIEXYZFormat);
+ if (pCompressed) {
+ *(pCompressed + i) = True;
+ }
+ return(XcmsSuccess);
+ }
+
+ /* Convert from CIEXYZ to CIELuv format */
+ if (_XcmsDIConvertColors(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELuvFormat)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* Step 1: compute the maximum L* and chroma for this hue. */
+ /* This copy may be overkill but it preserves the pixel etc. */
+ saveLstar = pColor->spec.CIELuv.L_star;
+ hue = XCMS_CIELUV_PMETRIC_HUE(pColor->spec.CIELuv.u_star,
+ pColor->spec.CIELuv.v_star);
+ chroma = XCMS_CIELUV_PMETRIC_CHROMA(pColor->spec.CIELuv.u_star,
+ pColor->spec.CIELuv.v_star);
+ memcpy((char *)&Luv_max, (char *)pColor, sizeof(XcmsColor));
+ if (_XcmsCIELuvQueryMaxLCRGB (&myCCC, hue, &Luv_max, &rgb_max)
+ == XcmsFailure) {
+ return (XcmsFailure);
+ }
+ maxLstar = Luv_max.spec.CIELuv.L_star;
+
+ /* Now check and return the appropriate L* */
+ if (saveLstar == maxLstar) {
+ /* When the L* input is equal to the maximum L* */
+ /* merely return the maximum Luv point. */
+ memcpy((char *)pColor, (char *)&Luv_max, sizeof(XcmsColor));
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat);
+ } else {
+ /* return the closest point on the hue leaf. */
+ /* must do a bisection here to compute the delta e. */
+ maxChroma = XCMS_CIELUV_PMETRIC_CHROMA(Luv_max.spec.CIELuv.u_star,
+ Luv_max.spec.CIELuv.v_star);
+ nMaxCount = MAXBISECTCOUNT;
+ nI = nMaxCount / 2;
+ bestLstar = Lstar = pColor->spec.CIELuv.L_star;
+ bestustar = pColor->spec.CIELuv.u_star;
+ bestvstar = pColor->spec.CIELuv.v_star;
+ bestChroma = Chroma = chroma;
+ saveDist = XCMS_SQRT(((Chroma - maxChroma) * (Chroma - maxChroma)) +
+ ((Lstar - maxLstar) * (Lstar - maxLstar)));
+ for (nCount = 0; nCount < nMaxCount; nCount++) {
+ nT = (XcmsFloat) nI / (XcmsFloat) nMaxCount;
+ if (saveLstar > maxLstar) {
+ pColor->spec.RGBi.red = rgb_max.red * (1.0 - nT) + nT;
+ pColor->spec.RGBi.green = rgb_max.green * (1.0 - nT) + nT;
+ pColor->spec.RGBi.blue = rgb_max.blue * (1.0 - nT) + nT;
+ } else {
+ pColor->spec.RGBi.red = rgb_max.red - (rgb_max.red * nT);
+ pColor->spec.RGBi.green = rgb_max.green - (rgb_max.green * nT);
+ pColor->spec.RGBi.blue = rgb_max.blue - (rgb_max.blue * nT);
+ }
+ pColor->format = XcmsRGBiFormat;
+
+ /* Convert from RGBi to CIE Luv */
+ if (_XcmsConvertColorsWithWhitePt(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELuvFormat,
+ (Bool *) NULL) == XcmsFailure) {
+ return (XcmsFailure);
+ }
+ chroma = XCMS_CIELUV_PMETRIC_CHROMA(pColor->spec.CIELuv.u_star,
+ pColor->spec.CIELuv.v_star);
+ tmpDist = XCMS_SQRT(((Chroma - chroma) * (Chroma - chroma)) +
+ ((Lstar - pColor->spec.CIELuv.L_star) *
+ (Lstar - pColor->spec.CIELuv.L_star)));
+ nILast = nI;
+ if (tmpDist > saveDist) {
+ nI /= 2;
+ } else {
+ nI = (nMaxCount + nI) / 2;
+ saveDist = tmpDist;
+ bestLstar = pColor->spec.CIELuv.L_star;
+ bestustar = pColor->spec.CIELuv.u_star;
+ bestvstar = pColor->spec.CIELuv.v_star;
+ bestChroma = chroma;
+ }
+ if (nI == nILast || nI == 0) {
+ break;
+ }
+ }
+ if (bestChroma >= maxChroma) {
+ pColor->spec.CIELuv.L_star = maxLstar;
+ pColor->spec.CIELuv.u_star = Luv_max.spec.CIELuv.u_star;
+ pColor->spec.CIELuv.v_star = Luv_max.spec.CIELuv.v_star;
+ } else {
+ pColor->spec.CIELuv.L_star = bestLstar;
+ pColor->spec.CIELuv.u_star = bestustar;
+ pColor->spec.CIELuv.v_star = bestvstar;
+ }
+ retval = _XcmsDIConvertColors(&myCCC, pColor,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIEXYZFormat);
+
+ if (retval != XcmsFailure && pCompressed != NULL) {
+ *(pCompressed + i) = True;
+ }
+ }
+ return(retval);
+}
diff --git a/libX11/src/xcms/LuvMnL.c b/libX11/src/xcms/LuvMnL.c index b873fa652..d463c4da5 100644 --- a/libX11/src/xcms/LuvMnL.c +++ b/libX11/src/xcms/LuvMnL.c @@ -1,216 +1,216 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * CIELuvMnL.c - * - * DESCRIPTION - * Source for the XcmsCIELuvQueryMinL() gamut boundary - * querying routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include <math.h> -#include "Cv.h" - -/* - * DEFINES - */ -#define MAXBISECTCOUNT 100 -#define EPS (XcmsFloat)0.001 -#define START_L_STAR (XcmsFloat)40.0 - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELuvQueryMinL - Compute max Lstar for a hue and chroma - * - * SYNOPSIS - */ -Status -XcmsCIELuvQueryMinL( - XcmsCCC ccc, - XcmsFloat hue_angle, /* hue angle in degrees */ - XcmsFloat chroma, - XcmsColor *pColor_return) -/* - * DESCRIPTION - * Return the maximum Lstar for a specified hue_angle and chroma. - * - * ASSUMPTIONS - * This routine assumes that the white point associated with - * the color specification is the Screen White Point. The - * Screen White Point will also be associated with the - * returned color specification. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded with no modifications - * - */ -{ - XcmsCCCRec myCCC; - XcmsColor max_lc, tmp, prev; - XcmsFloat max_chroma, tmp_chroma; - XcmsFloat hue, nT, nChroma, lastChroma, prevChroma; - XcmsFloat rFactor; - XcmsRGBi rgb_saved; - int nCount, nMaxCount; - - /* - * Check Arguments - */ - if (ccc == NULL || pColor_return == NULL) { - return(XcmsFailure); - } - - /* setup the CCC to use for the conversions. */ - memcpy ((char *) &myCCC, (char *) ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat; - myCCC.gamutCompProc = (XcmsCompressionProc) NULL; - - while (hue_angle < 0.0) { - hue_angle += 360.0; - } - while (hue_angle >= 360.0) { - hue_angle -= 360.0; - } - - hue = radians(hue_angle); - tmp.spec.CIELuv.L_star = START_L_STAR; - tmp.spec.CIELuv.u_star = XCMS_CIEUSTAROFHUE(hue, chroma); - tmp.spec.CIELuv.v_star = XCMS_CIEVSTAROFHUE(hue, chroma); - tmp.pixel = pColor_return->pixel; - tmp.format = XcmsCIELuvFormat; - - /* Step 1: Obtain the maximum L_star and chroma for this hue. */ - if (_XcmsCIELuvQueryMaxLCRGB(&myCCC, hue, &max_lc, &rgb_saved) - == XcmsFailure) { - return(XcmsFailure); - } - - max_chroma = XCMS_CIELUV_PMETRIC_CHROMA(max_lc.spec.CIELuv.u_star, - max_lc.spec.CIELuv.v_star); - - if (max_chroma <= chroma) { - /* - * If the chroma is greater than the chroma for the - * maximum L/chroma point then the L_star is the - * the L_star for the maximum L_star/chroma point. - * This is an error but I return the best approximation I can. - * Thus the inconsistency. - */ - memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor)); - return(XcmsSuccess); - } - - /* - * If the chroma is equal to the chroma for the - * maximum L_star/chroma point then the L_star is the - * the L_star for the maximum L* and chroma point. - */ - /* if (max_chroma == chroma) { - * memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor)); - * return(XcmsSuccess); - * } - */ - - /* must do a bisection here to compute the maximum L* */ - /* save the structure input so that any elements that */ - /* are not touched are recopied later in the routine. */ - nChroma = chroma; - tmp_chroma = max_chroma; - lastChroma = -1.0; - nMaxCount = MAXBISECTCOUNT; - rFactor = 1.0; - - for (nCount = 0; nCount < nMaxCount; nCount++) { - prevChroma = lastChroma; - lastChroma = tmp_chroma; - nT = (nChroma - max_chroma) / max_chroma * rFactor; - memcpy ((char *)&prev, (char *)&tmp, sizeof(XcmsColor)); - tmp.spec.RGBi.red = rgb_saved.red + (rgb_saved.red * nT); - tmp.spec.RGBi.green = rgb_saved.green + (rgb_saved.green * nT); - tmp.spec.RGBi.blue = rgb_saved.blue + (rgb_saved.blue * nT); - tmp.format = XcmsRGBiFormat; - - /* convert from RGB to CIELuv */ - if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELuvFormat, - (Bool *) NULL) == XcmsFailure) { - return(XcmsFailure); - } - - /* Now check the return against what is expected */ - tmp_chroma = XCMS_CIELUV_PMETRIC_CHROMA(tmp.spec.CIELuv.u_star, - tmp.spec.CIELuv.v_star); - if (tmp_chroma <= chroma + EPS && tmp_chroma >= chroma - EPS) { - /* Found It! */ - memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor)); - return(XcmsSuccess); - } - nChroma += chroma - tmp_chroma; - if (nChroma > max_chroma) { - nChroma = max_chroma; - rFactor *= 0.5; /* selective relaxation employed */ - } else if (nChroma < 0.0) { - if (XCMS_FABS(lastChroma - chroma) < - XCMS_FABS(tmp_chroma - chroma)) { - memcpy ((char *)pColor_return, (char *)&prev, - sizeof(XcmsColor)); - } else { - memcpy ((char *)pColor_return, (char *)&tmp, - sizeof(XcmsColor)); - } - return(XcmsSuccess); - } else if (tmp_chroma <= prevChroma + EPS && - tmp_chroma >= prevChroma - EPS) { - rFactor *= 0.5; /* selective relaxation employed */ - } - } - - if (nCount >= nMaxCount) { - if (XCMS_FABS(lastChroma - chroma) < - XCMS_FABS(tmp_chroma - chroma)) { - memcpy ((char *)pColor_return, (char *)&prev, - sizeof(XcmsColor)); - } else { - memcpy ((char *)pColor_return, (char *)&tmp, - sizeof(XcmsColor)); - } - } - memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor)); - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * CIELuvMnL.c
+ *
+ * DESCRIPTION
+ * Source for the XcmsCIELuvQueryMinL() gamut boundary
+ * querying routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include <math.h>
+#include "Cv.h"
+
+/*
+ * DEFINES
+ */
+#define MAXBISECTCOUNT 100
+#define EPS (XcmsFloat)0.001
+#define START_L_STAR (XcmsFloat)40.0
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELuvQueryMinL - Compute max Lstar for a hue and chroma
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIELuvQueryMinL(
+ XcmsCCC ccc,
+ XcmsFloat hue_angle, /* hue angle in degrees */
+ XcmsFloat chroma,
+ XcmsColor *pColor_return)
+/*
+ * DESCRIPTION
+ * Return the maximum Lstar for a specified hue_angle and chroma.
+ *
+ * ASSUMPTIONS
+ * This routine assumes that the white point associated with
+ * the color specification is the Screen White Point. The
+ * Screen White Point will also be associated with the
+ * returned color specification.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded with no modifications
+ *
+ */
+{
+ XcmsCCCRec myCCC;
+ XcmsColor max_lc, tmp, prev;
+ XcmsFloat max_chroma, tmp_chroma;
+ XcmsFloat hue, nT, nChroma, lastChroma, prevChroma;
+ XcmsFloat rFactor;
+ XcmsRGBi rgb_saved;
+ int nCount, nMaxCount;
+
+ /*
+ * Check Arguments
+ */
+ if (ccc == NULL || pColor_return == NULL) {
+ return(XcmsFailure);
+ }
+
+ /* setup the CCC to use for the conversions. */
+ memcpy ((char *) &myCCC, (char *) ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;
+ myCCC.gamutCompProc = (XcmsCompressionProc) NULL;
+
+ while (hue_angle < 0.0) {
+ hue_angle += 360.0;
+ }
+ while (hue_angle >= 360.0) {
+ hue_angle -= 360.0;
+ }
+
+ hue = radians(hue_angle);
+ tmp.spec.CIELuv.L_star = START_L_STAR;
+ tmp.spec.CIELuv.u_star = XCMS_CIEUSTAROFHUE(hue, chroma);
+ tmp.spec.CIELuv.v_star = XCMS_CIEVSTAROFHUE(hue, chroma);
+ tmp.pixel = pColor_return->pixel;
+ tmp.format = XcmsCIELuvFormat;
+
+ /* Step 1: Obtain the maximum L_star and chroma for this hue. */
+ if (_XcmsCIELuvQueryMaxLCRGB(&myCCC, hue, &max_lc, &rgb_saved)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ max_chroma = XCMS_CIELUV_PMETRIC_CHROMA(max_lc.spec.CIELuv.u_star,
+ max_lc.spec.CIELuv.v_star);
+
+ if (max_chroma <= chroma) {
+ /*
+ * If the chroma is greater than the chroma for the
+ * maximum L/chroma point then the L_star is the
+ * the L_star for the maximum L_star/chroma point.
+ * This is an error but I return the best approximation I can.
+ * Thus the inconsistency.
+ */
+ memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor));
+ return(XcmsSuccess);
+ }
+
+ /*
+ * If the chroma is equal to the chroma for the
+ * maximum L_star/chroma point then the L_star is the
+ * the L_star for the maximum L* and chroma point.
+ */
+ /* if (max_chroma == chroma) {
+ * memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor));
+ * return(XcmsSuccess);
+ * }
+ */
+
+ /* must do a bisection here to compute the maximum L* */
+ /* save the structure input so that any elements that */
+ /* are not touched are recopied later in the routine. */
+ nChroma = chroma;
+ tmp_chroma = max_chroma;
+ lastChroma = -1.0;
+ nMaxCount = MAXBISECTCOUNT;
+ rFactor = 1.0;
+
+ for (nCount = 0; nCount < nMaxCount; nCount++) {
+ prevChroma = lastChroma;
+ lastChroma = tmp_chroma;
+ nT = (nChroma - max_chroma) / max_chroma * rFactor;
+ memcpy ((char *)&prev, (char *)&tmp, sizeof(XcmsColor));
+ tmp.spec.RGBi.red = rgb_saved.red + (rgb_saved.red * nT);
+ tmp.spec.RGBi.green = rgb_saved.green + (rgb_saved.green * nT);
+ tmp.spec.RGBi.blue = rgb_saved.blue + (rgb_saved.blue * nT);
+ tmp.format = XcmsRGBiFormat;
+
+ /* convert from RGB to CIELuv */
+ if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELuvFormat,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* Now check the return against what is expected */
+ tmp_chroma = XCMS_CIELUV_PMETRIC_CHROMA(tmp.spec.CIELuv.u_star,
+ tmp.spec.CIELuv.v_star);
+ if (tmp_chroma <= chroma + EPS && tmp_chroma >= chroma - EPS) {
+ /* Found It! */
+ memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor));
+ return(XcmsSuccess);
+ }
+ nChroma += chroma - tmp_chroma;
+ if (nChroma > max_chroma) {
+ nChroma = max_chroma;
+ rFactor *= 0.5; /* selective relaxation employed */
+ } else if (nChroma < 0.0) {
+ if (XCMS_FABS(lastChroma - chroma) <
+ XCMS_FABS(tmp_chroma - chroma)) {
+ memcpy ((char *)pColor_return, (char *)&prev,
+ sizeof(XcmsColor));
+ } else {
+ memcpy ((char *)pColor_return, (char *)&tmp,
+ sizeof(XcmsColor));
+ }
+ return(XcmsSuccess);
+ } else if (tmp_chroma <= prevChroma + EPS &&
+ tmp_chroma >= prevChroma - EPS) {
+ rFactor *= 0.5; /* selective relaxation employed */
+ }
+ }
+
+ if (nCount >= nMaxCount) {
+ if (XCMS_FABS(lastChroma - chroma) <
+ XCMS_FABS(tmp_chroma - chroma)) {
+ memcpy ((char *)pColor_return, (char *)&prev,
+ sizeof(XcmsColor));
+ } else {
+ memcpy ((char *)pColor_return, (char *)&tmp,
+ sizeof(XcmsColor));
+ }
+ }
+ memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor));
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/LuvMxC.c b/libX11/src/xcms/LuvMxC.c index a67251477..be8bc4f70 100644 --- a/libX11/src/xcms/LuvMxC.c +++ b/libX11/src/xcms/LuvMxC.c @@ -1,204 +1,204 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * - * NAME - * CIELuvMxC.c - * - * DESCRIPTION - * Source for the XcmsCIELuvQueryMaxC() gamut boundary - * querying routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include <math.h> -#include "Cv.h" - -/* - * DEFINES - */ -#define MAXBISECTCOUNT 100 -#define EPS (XcmsFloat)0.001 -#define START_CHROMA (XcmsFloat)2.2 -#define TOPL (XcmsFloat)100.0 - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELuvQueryMaxC - max chroma for a hue_angle and L_star - * - * SYNOPSIS - */ -Status -XcmsCIELuvQueryMaxC( - XcmsCCC ccc, - XcmsFloat hue_angle, /* hue angle in degrees */ - XcmsFloat L_star, - XcmsColor *pColor_return) -/* - * DESCRIPTION - * Return the maximum chroma for a specific hue_angle and L_star. - * The returned format is in XcmsCIELuvFormat. - * - * - * ASSUMPTIONS - * This routine assumes that the white point associated with - * the color specification is the Screen White Point. The - * Screen White Point will also be associated with the - * returned color specification. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - XcmsCCCRec myCCC; - XcmsColor tmp; - XcmsColor max_lc; - XcmsFloat n_L_star, last_L_star, prev_L_star; - XcmsFloat hue, lastuStar, lastvStar, /*lastChroma,*/ maxDist, nT, rFactor; - XcmsRGBi rgb_saved; - int nCount, nMaxCount; - - /* - * Check Arguments - */ - if (ccc == NULL || pColor_return == NULL) { - return(XcmsFailure); - } - - /* Use my own CCC and inherit screen white Pt */ - memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat; - myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut comp func */ - - while (hue_angle < 0.0) { - hue_angle += 360.0; - } - while (hue_angle >= 360.0) { - hue_angle -= 360.0; - } - - hue = radians(hue_angle); - tmp.spec.CIELuv.L_star = L_star; - tmp.spec.CIELuv.u_star = XCMS_CIEUSTAROFHUE(hue, START_CHROMA); - tmp.spec.CIELuv.v_star = XCMS_CIEVSTAROFHUE(hue, START_CHROMA); - tmp.pixel = pColor_return->pixel; - tmp.format = XcmsCIELuvFormat; - - /* Step 1: compute the maximum L_star and chroma for this hue. */ - memcpy((char *)&max_lc, (char *)&tmp, sizeof(XcmsColor)); - if (_XcmsCIELuvQueryMaxLCRGB(&myCCC, hue, &max_lc, &rgb_saved) - == XcmsFailure) { - return(XcmsFailure); - } - - /* - * Step 2: Do a bisection here to compute the maximum chroma - * Note the differences between when the point to be found - * is above the maximum LC point and when it is below. - */ - if (L_star <= max_lc.spec.CIELuv.L_star) { - maxDist = max_lc.spec.CIELuv.L_star; - } else { - maxDist = TOPL - max_lc.spec.CIELuv.L_star; - } - - n_L_star = L_star; - last_L_star = -1.0; - nMaxCount = MAXBISECTCOUNT; - rFactor = 1.0; - - for (nCount = 0; nCount < nMaxCount; nCount++) { - prev_L_star = last_L_star; - last_L_star = tmp.spec.CIELuv.L_star; -/* lastChroma = XCMS_CIELUV_PMETRIC_CHROMA(tmp.spec.CIELuv.u_star, */ -/* tmp.spec.CIELuv.v_star); */ - lastuStar = tmp.spec.CIELuv.u_star; - lastvStar = tmp.spec.CIELuv.v_star; - nT = (n_L_star - max_lc.spec.CIELuv.L_star) / maxDist * rFactor; - /* printf("(n_L_star, nT) = %lf %lf ", n_L_star, nT); */ - if (nT > 0) { - tmp.spec.RGBi.red = rgb_saved.red * (1.0 - nT) + nT; - tmp.spec.RGBi.green = rgb_saved.green * (1.0 - nT) + nT; - tmp.spec.RGBi.blue = rgb_saved.blue * (1.0 - nT) + nT; - } else { - tmp.spec.RGBi.red = rgb_saved.red + (rgb_saved.red * nT); - tmp.spec.RGBi.green = rgb_saved.green + (rgb_saved.green * nT); - tmp.spec.RGBi.blue = rgb_saved.blue + (rgb_saved.blue * nT); - } - tmp.format = XcmsRGBiFormat; - - /* convert from RGB to CIELuv */ - if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELuvFormat, - (Bool *) NULL) == XcmsFailure) { - return(XcmsFailure); - } - - /* - * Now check if we've reached the target L_star - */ - /* printf("result Lstar = %lf\n", tmp.spec.CIELuv.L_star); */ - if (tmp.spec.CIELuv.L_star <= L_star + EPS && - tmp.spec.CIELuv.L_star >= L_star - EPS) { - memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor)); - return(XcmsSuccess); - } - if (nT > 0) { - n_L_star += ((TOPL - n_L_star) * - (L_star - tmp.spec.CIELuv.L_star)) / (TOPL - L_star); - } else { - n_L_star *= L_star / tmp.spec.CIELuv.L_star; - } - if (tmp.spec.CIELuv.L_star <= prev_L_star + EPS && - tmp.spec.CIELuv.L_star >= prev_L_star - EPS) { - rFactor *= 0.5; /* selective relaxation employed */ - /* printf("rFactor = %lf\n", rFactor); */ - } - } - if (XCMS_FABS(last_L_star - L_star) < - XCMS_FABS(tmp.spec.CIELuv.L_star - L_star)) { - tmp.spec.CIELuv.u_star = lastuStar; - tmp.spec.CIELuv.v_star = lastvStar; -/* tmp.spec.CIELuv.u_star = XCMS_CIEUSTAROFHUE(hue, lastChroma); */ -/* tmp.spec.CIELuv.v_star = XCMS_CIEVSTAROFHUE(hue, lastChroma); */ - } - tmp.spec.CIELuv.L_star = L_star; - memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor)); - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ *
+ * NAME
+ * CIELuvMxC.c
+ *
+ * DESCRIPTION
+ * Source for the XcmsCIELuvQueryMaxC() gamut boundary
+ * querying routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include <math.h>
+#include "Cv.h"
+
+/*
+ * DEFINES
+ */
+#define MAXBISECTCOUNT 100
+#define EPS (XcmsFloat)0.001
+#define START_CHROMA (XcmsFloat)2.2
+#define TOPL (XcmsFloat)100.0
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELuvQueryMaxC - max chroma for a hue_angle and L_star
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIELuvQueryMaxC(
+ XcmsCCC ccc,
+ XcmsFloat hue_angle, /* hue angle in degrees */
+ XcmsFloat L_star,
+ XcmsColor *pColor_return)
+/*
+ * DESCRIPTION
+ * Return the maximum chroma for a specific hue_angle and L_star.
+ * The returned format is in XcmsCIELuvFormat.
+ *
+ *
+ * ASSUMPTIONS
+ * This routine assumes that the white point associated with
+ * the color specification is the Screen White Point. The
+ * Screen White Point will also be associated with the
+ * returned color specification.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ XcmsCCCRec myCCC;
+ XcmsColor tmp;
+ XcmsColor max_lc;
+ XcmsFloat n_L_star, last_L_star, prev_L_star;
+ XcmsFloat hue, lastuStar, lastvStar, /*lastChroma,*/ maxDist, nT, rFactor;
+ XcmsRGBi rgb_saved;
+ int nCount, nMaxCount;
+
+ /*
+ * Check Arguments
+ */
+ if (ccc == NULL || pColor_return == NULL) {
+ return(XcmsFailure);
+ }
+
+ /* Use my own CCC and inherit screen white Pt */
+ memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;
+ myCCC.gamutCompProc = (XcmsCompressionProc)NULL;/* no gamut comp func */
+
+ while (hue_angle < 0.0) {
+ hue_angle += 360.0;
+ }
+ while (hue_angle >= 360.0) {
+ hue_angle -= 360.0;
+ }
+
+ hue = radians(hue_angle);
+ tmp.spec.CIELuv.L_star = L_star;
+ tmp.spec.CIELuv.u_star = XCMS_CIEUSTAROFHUE(hue, START_CHROMA);
+ tmp.spec.CIELuv.v_star = XCMS_CIEVSTAROFHUE(hue, START_CHROMA);
+ tmp.pixel = pColor_return->pixel;
+ tmp.format = XcmsCIELuvFormat;
+
+ /* Step 1: compute the maximum L_star and chroma for this hue. */
+ memcpy((char *)&max_lc, (char *)&tmp, sizeof(XcmsColor));
+ if (_XcmsCIELuvQueryMaxLCRGB(&myCCC, hue, &max_lc, &rgb_saved)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Step 2: Do a bisection here to compute the maximum chroma
+ * Note the differences between when the point to be found
+ * is above the maximum LC point and when it is below.
+ */
+ if (L_star <= max_lc.spec.CIELuv.L_star) {
+ maxDist = max_lc.spec.CIELuv.L_star;
+ } else {
+ maxDist = TOPL - max_lc.spec.CIELuv.L_star;
+ }
+
+ n_L_star = L_star;
+ last_L_star = -1.0;
+ nMaxCount = MAXBISECTCOUNT;
+ rFactor = 1.0;
+
+ for (nCount = 0; nCount < nMaxCount; nCount++) {
+ prev_L_star = last_L_star;
+ last_L_star = tmp.spec.CIELuv.L_star;
+/* lastChroma = XCMS_CIELUV_PMETRIC_CHROMA(tmp.spec.CIELuv.u_star, */
+/* tmp.spec.CIELuv.v_star); */
+ lastuStar = tmp.spec.CIELuv.u_star;
+ lastvStar = tmp.spec.CIELuv.v_star;
+ nT = (n_L_star - max_lc.spec.CIELuv.L_star) / maxDist * rFactor;
+ /* printf("(n_L_star, nT) = %lf %lf ", n_L_star, nT); */
+ if (nT > 0) {
+ tmp.spec.RGBi.red = rgb_saved.red * (1.0 - nT) + nT;
+ tmp.spec.RGBi.green = rgb_saved.green * (1.0 - nT) + nT;
+ tmp.spec.RGBi.blue = rgb_saved.blue * (1.0 - nT) + nT;
+ } else {
+ tmp.spec.RGBi.red = rgb_saved.red + (rgb_saved.red * nT);
+ tmp.spec.RGBi.green = rgb_saved.green + (rgb_saved.green * nT);
+ tmp.spec.RGBi.blue = rgb_saved.blue + (rgb_saved.blue * nT);
+ }
+ tmp.format = XcmsRGBiFormat;
+
+ /* convert from RGB to CIELuv */
+ if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELuvFormat,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Now check if we've reached the target L_star
+ */
+ /* printf("result Lstar = %lf\n", tmp.spec.CIELuv.L_star); */
+ if (tmp.spec.CIELuv.L_star <= L_star + EPS &&
+ tmp.spec.CIELuv.L_star >= L_star - EPS) {
+ memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor));
+ return(XcmsSuccess);
+ }
+ if (nT > 0) {
+ n_L_star += ((TOPL - n_L_star) *
+ (L_star - tmp.spec.CIELuv.L_star)) / (TOPL - L_star);
+ } else {
+ n_L_star *= L_star / tmp.spec.CIELuv.L_star;
+ }
+ if (tmp.spec.CIELuv.L_star <= prev_L_star + EPS &&
+ tmp.spec.CIELuv.L_star >= prev_L_star - EPS) {
+ rFactor *= 0.5; /* selective relaxation employed */
+ /* printf("rFactor = %lf\n", rFactor); */
+ }
+ }
+ if (XCMS_FABS(last_L_star - L_star) <
+ XCMS_FABS(tmp.spec.CIELuv.L_star - L_star)) {
+ tmp.spec.CIELuv.u_star = lastuStar;
+ tmp.spec.CIELuv.v_star = lastvStar;
+/* tmp.spec.CIELuv.u_star = XCMS_CIEUSTAROFHUE(hue, lastChroma); */
+/* tmp.spec.CIELuv.v_star = XCMS_CIEVSTAROFHUE(hue, lastChroma); */
+ }
+ tmp.spec.CIELuv.L_star = L_star;
+ memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor));
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/LuvMxL.c b/libX11/src/xcms/LuvMxL.c index d1d495b08..71ef0fffe 100644 --- a/libX11/src/xcms/LuvMxL.c +++ b/libX11/src/xcms/LuvMxL.c @@ -1,216 +1,216 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * CIELuvMxL.c - * - * DESCRIPTION - * Source for the XcmsCIELuvQueryMaxL() gamut boundary - * querying routine. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include <math.h> -#include "Cv.h" - -/* - * DEFINES - */ -#define MAXBISECTCOUNT 100 -#define EPS (XcmsFloat)0.001 -#define START_L_STAR (XcmsFloat)40.0 - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELuvQueryMaxL - Compute max Lstar for a hue and chroma - * - * SYNOPSIS - */ -Status -XcmsCIELuvQueryMaxL( - XcmsCCC ccc, - XcmsFloat hue_angle, /* hue angle in degrees */ - XcmsFloat chroma, - XcmsColor *pColor_return) -/* - * DESCRIPTION - * Return the maximum Lstar for a specified hue_angle and chroma. - * - * ASSUMPTIONS - * This routine assumes that the white point associated with - * the color specification is the Screen White Point. The - * Screen White Point will also be associated with the - * returned color specification. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded with no modifications - * - */ -{ - XcmsCCCRec myCCC; - XcmsColor max_lc, tmp, prev; - XcmsFloat max_chroma, tmp_chroma; - XcmsFloat hue, nT, nChroma, lastChroma, prevChroma; - XcmsFloat rFactor; - XcmsRGBi rgb_saved; - int nCount, nMaxCount; - - /* - * Check Arguments - */ - if (ccc == NULL || pColor_return == NULL) { - return(XcmsFailure); - } - - /* setup the CCC to use for the conversions. */ - memcpy ((char *) &myCCC, (char *) ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat; - myCCC.gamutCompProc = (XcmsCompressionProc) NULL; - - while (hue_angle < 0.0) { - hue_angle += 360.0; - } - while (hue_angle >= 360.0) { - hue_angle -= 360.0; - } - - hue = radians(hue_angle); - tmp.spec.CIELuv.L_star = START_L_STAR; - tmp.spec.CIELuv.u_star = XCMS_CIEUSTAROFHUE(hue, chroma); - tmp.spec.CIELuv.v_star = XCMS_CIEVSTAROFHUE(hue, chroma); - tmp.pixel = pColor_return->pixel; - tmp.format = XcmsCIELuvFormat; - - /* Step 1: Obtain the maximum L_star and chroma for this hue. */ - if (_XcmsCIELuvQueryMaxLCRGB(&myCCC, hue, &max_lc, &rgb_saved) - == XcmsFailure) { - return(XcmsFailure); - } - - max_chroma = XCMS_CIELUV_PMETRIC_CHROMA(max_lc.spec.CIELuv.u_star, - max_lc.spec.CIELuv.v_star); - - if (max_chroma <= chroma) { - /* - * If the chroma is greater than the chroma for the - * maximum L/chroma point then the L_star is the - * the L_star for the maximum L_star/chroma point. - * This is an error but I return the best approximation I can. - * Thus the inconsistency. - */ - memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor)); - return(XcmsSuccess); - } - - /* - * If the chroma is equal to the chroma for the - * maximum L_star/chroma point then the L_star is the - * the L_star for the maximum L* and chroma point. - */ - /* if (max_chroma == chroma) { - * memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor)); - * return(XcmsSuccess); - * } - */ - - /* must do a bisection here to compute the maximum L* */ - /* save the structure input so that any elements that */ - /* are not touched are recopied later in the routine. */ - nChroma = chroma; - tmp_chroma = max_chroma; - lastChroma = -1.0; - nMaxCount = MAXBISECTCOUNT; - rFactor = 1.0; - - for (nCount = 0; nCount < nMaxCount; nCount++) { - prevChroma = lastChroma; - lastChroma = tmp_chroma; - nT = (1.0 - (nChroma / max_chroma)) * rFactor; - memcpy ((char *)&prev, (char *)&tmp, sizeof(XcmsColor)); - tmp.spec.RGBi.red = rgb_saved.red * (1.0 - nT) + nT; - tmp.spec.RGBi.green = rgb_saved.green * (1.0 - nT) + nT; - tmp.spec.RGBi.blue = rgb_saved.blue * (1.0 - nT) + nT; - tmp.format = XcmsRGBiFormat; - - /* convert from RGB to CIELuv */ - if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp, - ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELuvFormat, - (Bool *) NULL) == XcmsFailure) { - return(XcmsFailure); - } - - /* Now check the return against what is expected */ - tmp_chroma = XCMS_CIELUV_PMETRIC_CHROMA(tmp.spec.CIELuv.u_star, - tmp.spec.CIELuv.v_star); - if (tmp_chroma <= chroma + EPS && tmp_chroma >= chroma - EPS) { - /* Found It! */ - memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor)); - return(XcmsSuccess); - } - nChroma += chroma - tmp_chroma; - if (nChroma > max_chroma) { - nChroma = max_chroma; - rFactor *= 0.5; /* selective relaxation employed */ - } else if (nChroma < 0.0) { - if (XCMS_FABS(lastChroma - chroma) < - XCMS_FABS(tmp_chroma - chroma)) { - memcpy ((char *)pColor_return, (char *)&prev, - sizeof(XcmsColor)); - } else { - memcpy ((char *)pColor_return, (char *)&tmp, - sizeof(XcmsColor)); - } - return(XcmsSuccess); - } else if (tmp_chroma <= prevChroma + EPS && - tmp_chroma >= prevChroma - EPS) { - rFactor *= 0.5; /* selective relaxation employed */ - } - } - - if (nCount >= nMaxCount) { - if (XCMS_FABS(lastChroma - chroma) < - XCMS_FABS(tmp_chroma - chroma)) { - memcpy ((char *)pColor_return, (char *)&prev, - sizeof(XcmsColor)); - } else { - memcpy ((char *)pColor_return, (char *)&tmp, - sizeof(XcmsColor)); - } - } - memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor)); - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * CIELuvMxL.c
+ *
+ * DESCRIPTION
+ * Source for the XcmsCIELuvQueryMaxL() gamut boundary
+ * querying routine.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include <math.h>
+#include "Cv.h"
+
+/*
+ * DEFINES
+ */
+#define MAXBISECTCOUNT 100
+#define EPS (XcmsFloat)0.001
+#define START_L_STAR (XcmsFloat)40.0
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELuvQueryMaxL - Compute max Lstar for a hue and chroma
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIELuvQueryMaxL(
+ XcmsCCC ccc,
+ XcmsFloat hue_angle, /* hue angle in degrees */
+ XcmsFloat chroma,
+ XcmsColor *pColor_return)
+/*
+ * DESCRIPTION
+ * Return the maximum Lstar for a specified hue_angle and chroma.
+ *
+ * ASSUMPTIONS
+ * This routine assumes that the white point associated with
+ * the color specification is the Screen White Point. The
+ * Screen White Point will also be associated with the
+ * returned color specification.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded with no modifications
+ *
+ */
+{
+ XcmsCCCRec myCCC;
+ XcmsColor max_lc, tmp, prev;
+ XcmsFloat max_chroma, tmp_chroma;
+ XcmsFloat hue, nT, nChroma, lastChroma, prevChroma;
+ XcmsFloat rFactor;
+ XcmsRGBi rgb_saved;
+ int nCount, nMaxCount;
+
+ /*
+ * Check Arguments
+ */
+ if (ccc == NULL || pColor_return == NULL) {
+ return(XcmsFailure);
+ }
+
+ /* setup the CCC to use for the conversions. */
+ memcpy ((char *) &myCCC, (char *) ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;
+ myCCC.gamutCompProc = (XcmsCompressionProc) NULL;
+
+ while (hue_angle < 0.0) {
+ hue_angle += 360.0;
+ }
+ while (hue_angle >= 360.0) {
+ hue_angle -= 360.0;
+ }
+
+ hue = radians(hue_angle);
+ tmp.spec.CIELuv.L_star = START_L_STAR;
+ tmp.spec.CIELuv.u_star = XCMS_CIEUSTAROFHUE(hue, chroma);
+ tmp.spec.CIELuv.v_star = XCMS_CIEVSTAROFHUE(hue, chroma);
+ tmp.pixel = pColor_return->pixel;
+ tmp.format = XcmsCIELuvFormat;
+
+ /* Step 1: Obtain the maximum L_star and chroma for this hue. */
+ if (_XcmsCIELuvQueryMaxLCRGB(&myCCC, hue, &max_lc, &rgb_saved)
+ == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ max_chroma = XCMS_CIELUV_PMETRIC_CHROMA(max_lc.spec.CIELuv.u_star,
+ max_lc.spec.CIELuv.v_star);
+
+ if (max_chroma <= chroma) {
+ /*
+ * If the chroma is greater than the chroma for the
+ * maximum L/chroma point then the L_star is the
+ * the L_star for the maximum L_star/chroma point.
+ * This is an error but I return the best approximation I can.
+ * Thus the inconsistency.
+ */
+ memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor));
+ return(XcmsSuccess);
+ }
+
+ /*
+ * If the chroma is equal to the chroma for the
+ * maximum L_star/chroma point then the L_star is the
+ * the L_star for the maximum L* and chroma point.
+ */
+ /* if (max_chroma == chroma) {
+ * memcpy ((char *) pColor_return, (char *) &max_lc, sizeof (XcmsColor));
+ * return(XcmsSuccess);
+ * }
+ */
+
+ /* must do a bisection here to compute the maximum L* */
+ /* save the structure input so that any elements that */
+ /* are not touched are recopied later in the routine. */
+ nChroma = chroma;
+ tmp_chroma = max_chroma;
+ lastChroma = -1.0;
+ nMaxCount = MAXBISECTCOUNT;
+ rFactor = 1.0;
+
+ for (nCount = 0; nCount < nMaxCount; nCount++) {
+ prevChroma = lastChroma;
+ lastChroma = tmp_chroma;
+ nT = (1.0 - (nChroma / max_chroma)) * rFactor;
+ memcpy ((char *)&prev, (char *)&tmp, sizeof(XcmsColor));
+ tmp.spec.RGBi.red = rgb_saved.red * (1.0 - nT) + nT;
+ tmp.spec.RGBi.green = rgb_saved.green * (1.0 - nT) + nT;
+ tmp.spec.RGBi.blue = rgb_saved.blue * (1.0 - nT) + nT;
+ tmp.format = XcmsRGBiFormat;
+
+ /* convert from RGB to CIELuv */
+ if (_XcmsConvertColorsWithWhitePt(&myCCC, &tmp,
+ ScreenWhitePointOfCCC(&myCCC), 1, XcmsCIELuvFormat,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /* Now check the return against what is expected */
+ tmp_chroma = XCMS_CIELUV_PMETRIC_CHROMA(tmp.spec.CIELuv.u_star,
+ tmp.spec.CIELuv.v_star);
+ if (tmp_chroma <= chroma + EPS && tmp_chroma >= chroma - EPS) {
+ /* Found It! */
+ memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor));
+ return(XcmsSuccess);
+ }
+ nChroma += chroma - tmp_chroma;
+ if (nChroma > max_chroma) {
+ nChroma = max_chroma;
+ rFactor *= 0.5; /* selective relaxation employed */
+ } else if (nChroma < 0.0) {
+ if (XCMS_FABS(lastChroma - chroma) <
+ XCMS_FABS(tmp_chroma - chroma)) {
+ memcpy ((char *)pColor_return, (char *)&prev,
+ sizeof(XcmsColor));
+ } else {
+ memcpy ((char *)pColor_return, (char *)&tmp,
+ sizeof(XcmsColor));
+ }
+ return(XcmsSuccess);
+ } else if (tmp_chroma <= prevChroma + EPS &&
+ tmp_chroma >= prevChroma - EPS) {
+ rFactor *= 0.5; /* selective relaxation employed */
+ }
+ }
+
+ if (nCount >= nMaxCount) {
+ if (XCMS_FABS(lastChroma - chroma) <
+ XCMS_FABS(tmp_chroma - chroma)) {
+ memcpy ((char *)pColor_return, (char *)&prev,
+ sizeof(XcmsColor));
+ } else {
+ memcpy ((char *)pColor_return, (char *)&tmp,
+ sizeof(XcmsColor));
+ }
+ }
+ memcpy ((char *) pColor_return, (char *) &tmp, sizeof (XcmsColor));
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/LuvMxLC.c b/libX11/src/xcms/LuvMxLC.c index 60b954916..f63e1528f 100644 --- a/libX11/src/xcms/LuvMxLC.c +++ b/libX11/src/xcms/LuvMxLC.c @@ -1,218 +1,218 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * - * NAME - * CIELuvMxVC.c - * - * DESCRIPTION - * Source for the XcmsCIELuvQueryMaxLC() gamut boundary - * querying routine. - * - * DOCUMENTATION - * "TekColor Color Management System, System Implementor's Manual" - * and - * Fred W. Billmeyer & Max Saltzman, "Principles of Color - * Technology", John Wily & Sons, Inc, 1981. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - -/* - * DEFINES - */ -#define MIN(x,y) ((x) > (y) ? (y) : (x)) -#define MIN3(x,y,z) ((x) > (MIN((y), (z))) ? (MIN((y), (z))) : (x)) -#define MAX(x,y) ((x) > (y) ? (x) : (y)) -#define MAX3(x,y,z) ((x) > (MAX((y), (z))) ? (x) : (MAX((y), (z)))) -#define START_LSTAR (XcmsFloat)40.0 -#define START_CHROMA (XcmsFloat)2.2 - - -/************************************************************************ - * * - * API PRIVATE ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * _XcmsCIELuvQueryMaxLCRGB - Compute maximum L* and chroma. - * - * SYNOPSIS - */ -Status -_XcmsCIELuvQueryMaxLCRGB( - XcmsCCC ccc, - XcmsFloat hue, /* hue in radians */ - XcmsColor *pColor_return, - XcmsRGBi *pRGB_return) -/* - * DESCRIPTION - * Return the maximum psychometric chroma for a specified - * hue angle(radians), and the corresponding L*. This is computed - * by a binary search of all possible chromas. An assumption - * is made that there are no local maxima. Use the unrounded - * Max psychometric chroma because the difference check can be - * small. - * - * NOTE: No local CCC is used because this is a private - * routine and all routines that call it are expected - * to behave properly, i.e. send a local CCC with - * no white adjust function and no gamut compression - * function. - * - * This routine only accepts hue as input and outputs - * Luv and RGBi. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - XcmsFloat nSmall, nLarge; - XcmsColor tmp; - - tmp.format = XcmsCIELuvFormat; - /* Use some unreachable color on the given hue angle */ - tmp.spec.CIELuv.L_star = START_LSTAR; - tmp.spec.CIELuv.u_star = XCMS_CIEUSTAROFHUE(hue, START_CHROMA); - tmp.spec.CIELuv.v_star = XCMS_CIEVSTAROFHUE(hue, START_CHROMA); - /* - * Convert from Luv to RGB - * - * Note that the CIEXYZ to RGBi conversion routine must stuff the - * out of bounds RGBi values in tmp when the ccc->gamutCompProc - * is NULL. - */ - if ((_XcmsConvertColorsWithWhitePt(ccc, &tmp, ScreenWhitePointOfCCC(ccc), - (unsigned int)1, XcmsRGBiFormat, (Bool *) NULL) - == XcmsFailure) && tmp.format != XcmsRGBiFormat) { - return (XcmsFailure); - } - - /* Now pick the smallest RGB */ - nSmall = MIN3(tmp.spec.RGBi.red, - tmp.spec.RGBi.green, - tmp.spec.RGBi.blue); - /* Make the smallest RGB equal to zero */ - tmp.spec.RGBi.red -= nSmall; - tmp.spec.RGBi.green -= nSmall; - tmp.spec.RGBi.blue -= nSmall; - - /* Now pick the largest RGB */ - nLarge = MAX3(tmp.spec.RGBi.red, - tmp.spec.RGBi.green, - tmp.spec.RGBi.blue); - /* Scale the RGB values based on the largest one */ - tmp.spec.RGBi.red /= nLarge; - tmp.spec.RGBi.green /= nLarge; - tmp.spec.RGBi.blue /= nLarge; - tmp.format = XcmsRGBiFormat; - - /* If the calling routine wants RGB value give them the ones used. */ - if (pRGB_return) { - pRGB_return->red = tmp.spec.RGBi.red; - pRGB_return->green = tmp.spec.RGBi.green; - pRGB_return->blue = tmp.spec.RGBi.blue; - } - - /* Convert from RGBi to Luv */ - if (_XcmsConvertColorsWithWhitePt(ccc, &tmp, - ScreenWhitePointOfCCC(ccc), 1, XcmsCIELuvFormat, (Bool *) NULL) - == XcmsFailure) { - return (XcmsFailure); - } - - memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor)); - return (XcmsSuccess); -} - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELuvQueryMaxLC - Compute maximum L* and chroma. - * - * SYNOPSIS - */ -Status -XcmsCIELuvQueryMaxLC ( - XcmsCCC ccc, - XcmsFloat hue_angle, /* hue angle in degrees */ - XcmsColor *pColor_return) - -/* - * DESCRIPTION - * Return the point of maximum chroma for the specified - * hue angle. - * - * ASSUMPTIONS - * This routine assumes that the white point associated with - * the color specification is the Screen White Point. The - * Screen White Point will also be associated with the - * returned color specification. - * - * RETURNS - * XcmsFailure - Failure - * XcmsSuccess - Succeeded - * - */ -{ - XcmsCCCRec myCCC; - - /* - * Check Arguments - */ - if (ccc == NULL || pColor_return == NULL) { - return(XcmsFailure); - } - - /* Use my own CCC */ - memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec)); - myCCC.clientWhitePt.format = XcmsUndefinedFormat; - myCCC.gamutCompProc = (XcmsCompressionProc)NULL; - - while (hue_angle < 0.0) { - hue_angle += 360.0; - } - while (hue_angle >= 360.0) { - hue_angle -= 360.0; - } - - return(_XcmsCIELuvQueryMaxLCRGB (&myCCC, radians(hue_angle), pColor_return, - (XcmsRGBi *)NULL)); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ *
+ * NAME
+ * CIELuvMxVC.c
+ *
+ * DESCRIPTION
+ * Source for the XcmsCIELuvQueryMaxLC() gamut boundary
+ * querying routine.
+ *
+ * DOCUMENTATION
+ * "TekColor Color Management System, System Implementor's Manual"
+ * and
+ * Fred W. Billmeyer & Max Saltzman, "Principles of Color
+ * Technology", John Wily & Sons, Inc, 1981.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+/*
+ * DEFINES
+ */
+#define MIN(x,y) ((x) > (y) ? (y) : (x))
+#define MIN3(x,y,z) ((x) > (MIN((y), (z))) ? (MIN((y), (z))) : (x))
+#define MAX(x,y) ((x) > (y) ? (x) : (y))
+#define MAX3(x,y,z) ((x) > (MAX((y), (z))) ? (x) : (MAX((y), (z))))
+#define START_LSTAR (XcmsFloat)40.0
+#define START_CHROMA (XcmsFloat)2.2
+
+
+/************************************************************************
+ * *
+ * API PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * _XcmsCIELuvQueryMaxLCRGB - Compute maximum L* and chroma.
+ *
+ * SYNOPSIS
+ */
+Status
+_XcmsCIELuvQueryMaxLCRGB(
+ XcmsCCC ccc,
+ XcmsFloat hue, /* hue in radians */
+ XcmsColor *pColor_return,
+ XcmsRGBi *pRGB_return)
+/*
+ * DESCRIPTION
+ * Return the maximum psychometric chroma for a specified
+ * hue angle(radians), and the corresponding L*. This is computed
+ * by a binary search of all possible chromas. An assumption
+ * is made that there are no local maxima. Use the unrounded
+ * Max psychometric chroma because the difference check can be
+ * small.
+ *
+ * NOTE: No local CCC is used because this is a private
+ * routine and all routines that call it are expected
+ * to behave properly, i.e. send a local CCC with
+ * no white adjust function and no gamut compression
+ * function.
+ *
+ * This routine only accepts hue as input and outputs
+ * Luv and RGBi.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ XcmsFloat nSmall, nLarge;
+ XcmsColor tmp;
+
+ tmp.format = XcmsCIELuvFormat;
+ /* Use some unreachable color on the given hue angle */
+ tmp.spec.CIELuv.L_star = START_LSTAR;
+ tmp.spec.CIELuv.u_star = XCMS_CIEUSTAROFHUE(hue, START_CHROMA);
+ tmp.spec.CIELuv.v_star = XCMS_CIEVSTAROFHUE(hue, START_CHROMA);
+ /*
+ * Convert from Luv to RGB
+ *
+ * Note that the CIEXYZ to RGBi conversion routine must stuff the
+ * out of bounds RGBi values in tmp when the ccc->gamutCompProc
+ * is NULL.
+ */
+ if ((_XcmsConvertColorsWithWhitePt(ccc, &tmp, ScreenWhitePointOfCCC(ccc),
+ (unsigned int)1, XcmsRGBiFormat, (Bool *) NULL)
+ == XcmsFailure) && tmp.format != XcmsRGBiFormat) {
+ return (XcmsFailure);
+ }
+
+ /* Now pick the smallest RGB */
+ nSmall = MIN3(tmp.spec.RGBi.red,
+ tmp.spec.RGBi.green,
+ tmp.spec.RGBi.blue);
+ /* Make the smallest RGB equal to zero */
+ tmp.spec.RGBi.red -= nSmall;
+ tmp.spec.RGBi.green -= nSmall;
+ tmp.spec.RGBi.blue -= nSmall;
+
+ /* Now pick the largest RGB */
+ nLarge = MAX3(tmp.spec.RGBi.red,
+ tmp.spec.RGBi.green,
+ tmp.spec.RGBi.blue);
+ /* Scale the RGB values based on the largest one */
+ tmp.spec.RGBi.red /= nLarge;
+ tmp.spec.RGBi.green /= nLarge;
+ tmp.spec.RGBi.blue /= nLarge;
+ tmp.format = XcmsRGBiFormat;
+
+ /* If the calling routine wants RGB value give them the ones used. */
+ if (pRGB_return) {
+ pRGB_return->red = tmp.spec.RGBi.red;
+ pRGB_return->green = tmp.spec.RGBi.green;
+ pRGB_return->blue = tmp.spec.RGBi.blue;
+ }
+
+ /* Convert from RGBi to Luv */
+ if (_XcmsConvertColorsWithWhitePt(ccc, &tmp,
+ ScreenWhitePointOfCCC(ccc), 1, XcmsCIELuvFormat, (Bool *) NULL)
+ == XcmsFailure) {
+ return (XcmsFailure);
+ }
+
+ memcpy((char *)pColor_return, (char *)&tmp, sizeof(XcmsColor));
+ return (XcmsSuccess);
+}
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELuvQueryMaxLC - Compute maximum L* and chroma.
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIELuvQueryMaxLC (
+ XcmsCCC ccc,
+ XcmsFloat hue_angle, /* hue angle in degrees */
+ XcmsColor *pColor_return)
+
+/*
+ * DESCRIPTION
+ * Return the point of maximum chroma for the specified
+ * hue angle.
+ *
+ * ASSUMPTIONS
+ * This routine assumes that the white point associated with
+ * the color specification is the Screen White Point. The
+ * Screen White Point will also be associated with the
+ * returned color specification.
+ *
+ * RETURNS
+ * XcmsFailure - Failure
+ * XcmsSuccess - Succeeded
+ *
+ */
+{
+ XcmsCCCRec myCCC;
+
+ /*
+ * Check Arguments
+ */
+ if (ccc == NULL || pColor_return == NULL) {
+ return(XcmsFailure);
+ }
+
+ /* Use my own CCC */
+ memcpy ((char *)&myCCC, (char *)ccc, sizeof(XcmsCCCRec));
+ myCCC.clientWhitePt.format = XcmsUndefinedFormat;
+ myCCC.gamutCompProc = (XcmsCompressionProc)NULL;
+
+ while (hue_angle < 0.0) {
+ hue_angle += 360.0;
+ }
+ while (hue_angle >= 360.0) {
+ hue_angle -= 360.0;
+ }
+
+ return(_XcmsCIELuvQueryMaxLCRGB (&myCCC, radians(hue_angle), pColor_return,
+ (XcmsRGBi *)NULL));
+}
diff --git a/libX11/src/xcms/LuvWpAj.c b/libX11/src/xcms/LuvWpAj.c index aa2a3f462..9f811d27e 100644 --- a/libX11/src/xcms/LuvWpAj.c +++ b/libX11/src/xcms/LuvWpAj.c @@ -1,96 +1,96 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * CIELuvWpAj.c - * - * DESCRIPTION - * This file contains routine(s) that support white point - * adjustment of color specifications in the CIE CIELuv.color - * space. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELuvWhiteShiftColors - * - * SYNOPSIS - */ -Status -XcmsCIELuvWhiteShiftColors( - XcmsCCC ccc, - XcmsColor *pWhitePtFrom, - XcmsColor *pWhitePtTo, - XcmsColorFormat destSpecFmt, - XcmsColor *pColors_in_out, - unsigned int nColors, - Bool *pCompressed) -/* - * DESCRIPTION - * Adjusts color specifications in an array of XcmsColor - * structures for white point differences. - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if succeeded without gamut compression, - * XcmsSuccessWithCompression if succeeded with - * gamut compression. - */ -{ - if (pWhitePtFrom == NULL || pWhitePtTo == NULL || pColors_in_out == NULL) { - return(XcmsFailure); - } - - /* - * Convert to CIELuv using pWhitePtFrom - * We can ignore return value for compression because we are converting - * to XcmsCIELuvFormat which is device-independent, not device-dependent. - */ - if (_XcmsConvertColorsWithWhitePt(ccc, pColors_in_out, pWhitePtFrom, - nColors, XcmsCIELuvFormat, pCompressed) == XcmsFailure) { - return(XcmsFailure); - } - - /* - * Convert from CIELuv to destSpecFmt using pWhitePtTo - */ - return(_XcmsConvertColorsWithWhitePt(ccc, pColors_in_out, pWhitePtTo, - nColors, destSpecFmt, pCompressed)); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * CIELuvWpAj.c
+ *
+ * DESCRIPTION
+ * This file contains routine(s) that support white point
+ * adjustment of color specifications in the CIE CIELuv.color
+ * space.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELuvWhiteShiftColors
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIELuvWhiteShiftColors(
+ XcmsCCC ccc,
+ XcmsColor *pWhitePtFrom,
+ XcmsColor *pWhitePtTo,
+ XcmsColorFormat destSpecFmt,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * Adjusts color specifications in an array of XcmsColor
+ * structures for white point differences.
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if succeeded without gamut compression,
+ * XcmsSuccessWithCompression if succeeded with
+ * gamut compression.
+ */
+{
+ if (pWhitePtFrom == NULL || pWhitePtTo == NULL || pColors_in_out == NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Convert to CIELuv using pWhitePtFrom
+ * We can ignore return value for compression because we are converting
+ * to XcmsCIELuvFormat which is device-independent, not device-dependent.
+ */
+ if (_XcmsConvertColorsWithWhitePt(ccc, pColors_in_out, pWhitePtFrom,
+ nColors, XcmsCIELuvFormat, pCompressed) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Convert from CIELuv to destSpecFmt using pWhitePtTo
+ */
+ return(_XcmsConvertColorsWithWhitePt(ccc, pColors_in_out, pWhitePtTo,
+ nColors, destSpecFmt, pCompressed));
+}
diff --git a/libX11/src/xcms/OfCCC.c b/libX11/src/xcms/OfCCC.c index 06fc3d7a1..1d8e0b436 100644 --- a/libX11/src/xcms/OfCCC.c +++ b/libX11/src/xcms/OfCCC.c @@ -1,162 +1,162 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsOfCCC.c - Color Conversion Context Querying Routines - * - * DESCRIPTION - * Routines to query components of a Color Conversion - * Context structure. - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlib.h" -#include "Xcms.h" - - - -/************************************************************************ - * * - * PUBLIC INTERFACES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsDisplayOfCCC - * - * SYNOPSIS - */ - -Display * -XcmsDisplayOfCCC( - XcmsCCC ccc) -/* - * DESCRIPTION - * Queries the Display of the specified CCC. - * - * RETURNS - * Pointer to the Display. - * - */ -{ - return(ccc->dpy); -} - - -/* - * NAME - * XcmsVisualOfCCC - * - * SYNOPSIS - */ - -Visual * -XcmsVisualOfCCC( - XcmsCCC ccc) -/* - * DESCRIPTION - * Queries the Visual of the specified CCC. - * - * RETURNS - * Pointer to the Visual. - * - */ -{ - return(ccc->visual); -} - - -/* - * NAME - * XcmsScreenNumberOfCCC - * - * SYNOPSIS - */ - -int -XcmsScreenNumberOfCCC( - XcmsCCC ccc) -/* - * DESCRIPTION - * Queries the screen number of the specified CCC. - * - * RETURNS - * screen number. - * - */ -{ - return(ccc->screenNumber); -} - - -/* - * NAME - * XcmsScreenWhitePointOfCCC - * - * SYNOPSIS - */ - -XcmsColor * -XcmsScreenWhitePointOfCCC( - XcmsCCC ccc) -/* - * DESCRIPTION - * Queries the screen white point of the specified CCC. - * - * RETURNS - * Pointer to the XcmsColor containing the screen white point. - * - */ -{ - return(&ccc->pPerScrnInfo->screenWhitePt); -} - - -/* - * NAME - * XcmsClientWhitePointOfCCC - * - * SYNOPSIS - */ - -XcmsColor * -XcmsClientWhitePointOfCCC( - XcmsCCC ccc) -/* - * DESCRIPTION - * Queries the client white point of the specified CCC. - * - * RETURNS - * Pointer to the XcmsColor containing the client white point. - * - */ -{ - return(&ccc->clientWhitePt); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsOfCCC.c - Color Conversion Context Querying Routines
+ *
+ * DESCRIPTION
+ * Routines to query components of a Color Conversion
+ * Context structure.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlib.h"
+#include "Xcms.h"
+
+
+
+/************************************************************************
+ * *
+ * PUBLIC INTERFACES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsDisplayOfCCC
+ *
+ * SYNOPSIS
+ */
+
+Display *
+XcmsDisplayOfCCC(
+ XcmsCCC ccc)
+/*
+ * DESCRIPTION
+ * Queries the Display of the specified CCC.
+ *
+ * RETURNS
+ * Pointer to the Display.
+ *
+ */
+{
+ return(ccc->dpy);
+}
+
+
+/*
+ * NAME
+ * XcmsVisualOfCCC
+ *
+ * SYNOPSIS
+ */
+
+Visual *
+XcmsVisualOfCCC(
+ XcmsCCC ccc)
+/*
+ * DESCRIPTION
+ * Queries the Visual of the specified CCC.
+ *
+ * RETURNS
+ * Pointer to the Visual.
+ *
+ */
+{
+ return(ccc->visual);
+}
+
+
+/*
+ * NAME
+ * XcmsScreenNumberOfCCC
+ *
+ * SYNOPSIS
+ */
+
+int
+XcmsScreenNumberOfCCC(
+ XcmsCCC ccc)
+/*
+ * DESCRIPTION
+ * Queries the screen number of the specified CCC.
+ *
+ * RETURNS
+ * screen number.
+ *
+ */
+{
+ return(ccc->screenNumber);
+}
+
+
+/*
+ * NAME
+ * XcmsScreenWhitePointOfCCC
+ *
+ * SYNOPSIS
+ */
+
+XcmsColor *
+XcmsScreenWhitePointOfCCC(
+ XcmsCCC ccc)
+/*
+ * DESCRIPTION
+ * Queries the screen white point of the specified CCC.
+ *
+ * RETURNS
+ * Pointer to the XcmsColor containing the screen white point.
+ *
+ */
+{
+ return(&ccc->pPerScrnInfo->screenWhitePt);
+}
+
+
+/*
+ * NAME
+ * XcmsClientWhitePointOfCCC
+ *
+ * SYNOPSIS
+ */
+
+XcmsColor *
+XcmsClientWhitePointOfCCC(
+ XcmsCCC ccc)
+/*
+ * DESCRIPTION
+ * Queries the client white point of the specified CCC.
+ *
+ * RETURNS
+ * Pointer to the XcmsColor containing the client white point.
+ *
+ */
+{
+ return(&ccc->clientWhitePt);
+}
diff --git a/libX11/src/xcms/QBlack.c b/libX11/src/xcms/QBlack.c index d7a69d399..fc28e16be 100644 --- a/libX11/src/xcms/QBlack.c +++ b/libX11/src/xcms/QBlack.c @@ -1,84 +1,84 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsQBlack.c - Query Black - * - * DESCRIPTION - * Routine to obtain a color specification for zero - * red, green, and blue intensities. - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcms.h" - - - -/************************************************************************ - * * - * PUBLIC INTERFACES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsQueryBlack - * - * SYNOPSIS - */ - -Status -XcmsQueryBlack( - XcmsCCC ccc, - XcmsColorFormat target_format, - XcmsColor *pColor_ret) -/* - * DESCRIPTION - * Returns the color specification in the target format for - * zero intensity red, green, and blue. - * - * RETURNS - * Returns XcmsSuccess, if failed; otherwise XcmsFailure - * - */ -{ - XcmsColor tmp; - - tmp.format = XcmsRGBiFormat; - tmp.pixel = 0; - tmp.spec.RGBi.red = 0.0; - tmp.spec.RGBi.green = 0.0; - tmp.spec.RGBi.blue = 0.0; - if (XcmsConvertColors(ccc, &tmp, 1, target_format, NULL) != XcmsSuccess) { - return(XcmsFailure); - } - memcpy((char *)pColor_ret, (char *)&tmp, sizeof(XcmsColor)); - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsQBlack.c - Query Black
+ *
+ * DESCRIPTION
+ * Routine to obtain a color specification for zero
+ * red, green, and blue intensities.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcms.h"
+
+
+
+/************************************************************************
+ * *
+ * PUBLIC INTERFACES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsQueryBlack
+ *
+ * SYNOPSIS
+ */
+
+Status
+XcmsQueryBlack(
+ XcmsCCC ccc,
+ XcmsColorFormat target_format,
+ XcmsColor *pColor_ret)
+/*
+ * DESCRIPTION
+ * Returns the color specification in the target format for
+ * zero intensity red, green, and blue.
+ *
+ * RETURNS
+ * Returns XcmsSuccess, if failed; otherwise XcmsFailure
+ *
+ */
+{
+ XcmsColor tmp;
+
+ tmp.format = XcmsRGBiFormat;
+ tmp.pixel = 0;
+ tmp.spec.RGBi.red = 0.0;
+ tmp.spec.RGBi.green = 0.0;
+ tmp.spec.RGBi.blue = 0.0;
+ if (XcmsConvertColors(ccc, &tmp, 1, target_format, NULL) != XcmsSuccess) {
+ return(XcmsFailure);
+ }
+ memcpy((char *)pColor_ret, (char *)&tmp, sizeof(XcmsColor));
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/QBlue.c b/libX11/src/xcms/QBlue.c index 4555344e6..ac79dc2e9 100644 --- a/libX11/src/xcms/QBlue.c +++ b/libX11/src/xcms/QBlue.c @@ -1,84 +1,84 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsQBlue.c - Query Blue - * - * DESCRIPTION - * Routine to obtain a color specification for full - * blue intensity and zero red and green intensities. - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcms.h" - - - -/************************************************************************ - * * - * PUBLIC INTERFACES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsQueryBlue - * - * SYNOPSIS - */ - -Status -XcmsQueryBlue( - XcmsCCC ccc, - XcmsColorFormat target_format, - XcmsColor *pColor_ret) -/* - * DESCRIPTION - * Returns the color specification in the target format for - * full intensity blue and zero intensity red and green. - * - * RETURNS - * Returns XcmsSuccess, if failed; otherwise XcmsFailure - * - */ -{ - XcmsColor tmp; - - tmp.format = XcmsRGBiFormat; - tmp.pixel = 0; - tmp.spec.RGBi.red = 0.0; - tmp.spec.RGBi.green = 0.0; - tmp.spec.RGBi.blue = 1.0; - if (XcmsConvertColors(ccc, &tmp, 1, target_format, NULL) != XcmsSuccess) { - return(XcmsFailure); - } - memcpy((char *)pColor_ret, (char *)&tmp, sizeof(XcmsColor)); - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsQBlue.c - Query Blue
+ *
+ * DESCRIPTION
+ * Routine to obtain a color specification for full
+ * blue intensity and zero red and green intensities.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcms.h"
+
+
+
+/************************************************************************
+ * *
+ * PUBLIC INTERFACES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsQueryBlue
+ *
+ * SYNOPSIS
+ */
+
+Status
+XcmsQueryBlue(
+ XcmsCCC ccc,
+ XcmsColorFormat target_format,
+ XcmsColor *pColor_ret)
+/*
+ * DESCRIPTION
+ * Returns the color specification in the target format for
+ * full intensity blue and zero intensity red and green.
+ *
+ * RETURNS
+ * Returns XcmsSuccess, if failed; otherwise XcmsFailure
+ *
+ */
+{
+ XcmsColor tmp;
+
+ tmp.format = XcmsRGBiFormat;
+ tmp.pixel = 0;
+ tmp.spec.RGBi.red = 0.0;
+ tmp.spec.RGBi.green = 0.0;
+ tmp.spec.RGBi.blue = 1.0;
+ if (XcmsConvertColors(ccc, &tmp, 1, target_format, NULL) != XcmsSuccess) {
+ return(XcmsFailure);
+ }
+ memcpy((char *)pColor_ret, (char *)&tmp, sizeof(XcmsColor));
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/QGreen.c b/libX11/src/xcms/QGreen.c index 0c888358a..bc6b7bb7a 100644 --- a/libX11/src/xcms/QGreen.c +++ b/libX11/src/xcms/QGreen.c @@ -1,84 +1,84 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsQGreen.c - Query Green - * - * DESCRIPTION - * Routine to obtain a color specification for full - * green intensity and zero red and blue intensities. - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcms.h" - - - -/************************************************************************ - * * - * PUBLIC INTERFACES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsQueryGreen - * - * SYNOPSIS - */ - -Status -XcmsQueryGreen( - XcmsCCC ccc, - XcmsColorFormat target_format, - XcmsColor *pColor_ret) -/* - * DESCRIPTION - * Returns the color specification in the target format for - * full intensity green and zero intensity red and blue. - * - * RETURNS - * Returns XcmsSuccess, if failed; otherwise XcmsFailure - * - */ -{ - XcmsColor tmp; - - tmp.format = XcmsRGBiFormat; - tmp.pixel = 0; - tmp.spec.RGBi.red = 0.0; - tmp.spec.RGBi.green = 1.0; - tmp.spec.RGBi.blue = 0.0; - if (XcmsConvertColors(ccc, &tmp, 1, target_format, NULL) != XcmsSuccess) { - return(XcmsFailure); - } - memcpy((char *)pColor_ret, (char *)&tmp, sizeof(XcmsColor)); - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsQGreen.c - Query Green
+ *
+ * DESCRIPTION
+ * Routine to obtain a color specification for full
+ * green intensity and zero red and blue intensities.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcms.h"
+
+
+
+/************************************************************************
+ * *
+ * PUBLIC INTERFACES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsQueryGreen
+ *
+ * SYNOPSIS
+ */
+
+Status
+XcmsQueryGreen(
+ XcmsCCC ccc,
+ XcmsColorFormat target_format,
+ XcmsColor *pColor_ret)
+/*
+ * DESCRIPTION
+ * Returns the color specification in the target format for
+ * full intensity green and zero intensity red and blue.
+ *
+ * RETURNS
+ * Returns XcmsSuccess, if failed; otherwise XcmsFailure
+ *
+ */
+{
+ XcmsColor tmp;
+
+ tmp.format = XcmsRGBiFormat;
+ tmp.pixel = 0;
+ tmp.spec.RGBi.red = 0.0;
+ tmp.spec.RGBi.green = 1.0;
+ tmp.spec.RGBi.blue = 0.0;
+ if (XcmsConvertColors(ccc, &tmp, 1, target_format, NULL) != XcmsSuccess) {
+ return(XcmsFailure);
+ }
+ memcpy((char *)pColor_ret, (char *)&tmp, sizeof(XcmsColor));
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/QRed.c b/libX11/src/xcms/QRed.c index 357380d60..32cde9e9c 100644 --- a/libX11/src/xcms/QRed.c +++ b/libX11/src/xcms/QRed.c @@ -1,84 +1,84 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsQRed.c - Query Red - * - * DESCRIPTION - * Routine to obtain a color specification for full - * red intensity and zero green and blue intensities. - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcms.h" - - - -/************************************************************************ - * * - * PUBLIC INTERFACES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsQueryRed - * - * SYNOPSIS - */ - -Status -XcmsQueryRed( - XcmsCCC ccc, - XcmsColorFormat target_format, - XcmsColor *pColor_ret) -/* - * DESCRIPTION - * Returns the color specification in the target format for - * full intensity red and zero intensity green and blue. - * - * RETURNS - * Returns XcmsSuccess, if failed; otherwise XcmsFailure - * - */ -{ - XcmsColor tmp; - - tmp.format = XcmsRGBiFormat; - tmp.pixel = 0; - tmp.spec.RGBi.red = 1.0; - tmp.spec.RGBi.green = 0.0; - tmp.spec.RGBi.blue = 0.0; - if (XcmsConvertColors(ccc, &tmp, 1, target_format, NULL) != XcmsSuccess) { - return(XcmsFailure); - } - memcpy((char *)pColor_ret, (char *)&tmp, sizeof(XcmsColor)); - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsQRed.c - Query Red
+ *
+ * DESCRIPTION
+ * Routine to obtain a color specification for full
+ * red intensity and zero green and blue intensities.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcms.h"
+
+
+
+/************************************************************************
+ * *
+ * PUBLIC INTERFACES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsQueryRed
+ *
+ * SYNOPSIS
+ */
+
+Status
+XcmsQueryRed(
+ XcmsCCC ccc,
+ XcmsColorFormat target_format,
+ XcmsColor *pColor_ret)
+/*
+ * DESCRIPTION
+ * Returns the color specification in the target format for
+ * full intensity red and zero intensity green and blue.
+ *
+ * RETURNS
+ * Returns XcmsSuccess, if failed; otherwise XcmsFailure
+ *
+ */
+{
+ XcmsColor tmp;
+
+ tmp.format = XcmsRGBiFormat;
+ tmp.pixel = 0;
+ tmp.spec.RGBi.red = 1.0;
+ tmp.spec.RGBi.green = 0.0;
+ tmp.spec.RGBi.blue = 0.0;
+ if (XcmsConvertColors(ccc, &tmp, 1, target_format, NULL) != XcmsSuccess) {
+ return(XcmsFailure);
+ }
+ memcpy((char *)pColor_ret, (char *)&tmp, sizeof(XcmsColor));
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/QWhite.c b/libX11/src/xcms/QWhite.c index 36b764c9d..1f89f2e20 100644 --- a/libX11/src/xcms/QWhite.c +++ b/libX11/src/xcms/QWhite.c @@ -1,84 +1,84 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsQWhite.c - Query White - * - * DESCRIPTION - * Routine to obtain a color specification for full - * red, green, and blue intensities. - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcms.h" - - - -/************************************************************************ - * * - * PUBLIC INTERFACES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsQueryWhite - * - * SYNOPSIS - */ - -Status -XcmsQueryWhite( - XcmsCCC ccc, - XcmsColorFormat target_format, - XcmsColor *pColor_ret) -/* - * DESCRIPTION - * Returns the color specification in the target format for - * full intensity red, green, and blue. - * - * RETURNS - * Returns XcmsSuccess, if failed; otherwise XcmsFailure - * - */ -{ - XcmsColor tmp; - - tmp.format = XcmsRGBiFormat; - tmp.pixel = 0; - tmp.spec.RGBi.red = 1.0; - tmp.spec.RGBi.green = 1.0; - tmp.spec.RGBi.blue = 1.0; - if (XcmsConvertColors(ccc, &tmp, 1, target_format, NULL) != XcmsSuccess) { - return(XcmsFailure); - } - memcpy((char *)pColor_ret, (char *)&tmp, sizeof(XcmsColor)); - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsQWhite.c - Query White
+ *
+ * DESCRIPTION
+ * Routine to obtain a color specification for full
+ * red, green, and blue intensities.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcms.h"
+
+
+
+/************************************************************************
+ * *
+ * PUBLIC INTERFACES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsQueryWhite
+ *
+ * SYNOPSIS
+ */
+
+Status
+XcmsQueryWhite(
+ XcmsCCC ccc,
+ XcmsColorFormat target_format,
+ XcmsColor *pColor_ret)
+/*
+ * DESCRIPTION
+ * Returns the color specification in the target format for
+ * full intensity red, green, and blue.
+ *
+ * RETURNS
+ * Returns XcmsSuccess, if failed; otherwise XcmsFailure
+ *
+ */
+{
+ XcmsColor tmp;
+
+ tmp.format = XcmsRGBiFormat;
+ tmp.pixel = 0;
+ tmp.spec.RGBi.red = 1.0;
+ tmp.spec.RGBi.green = 1.0;
+ tmp.spec.RGBi.blue = 1.0;
+ if (XcmsConvertColors(ccc, &tmp, 1, target_format, NULL) != XcmsSuccess) {
+ return(XcmsFailure);
+ }
+ memcpy((char *)pColor_ret, (char *)&tmp, sizeof(XcmsColor));
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/QuCol.c b/libX11/src/xcms/QuCol.c index b4c1cd33a..d70d29431 100644 --- a/libX11/src/xcms/QuCol.c +++ b/libX11/src/xcms/QuCol.c @@ -1,78 +1,78 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsQuCol.c - * - * DESCRIPTION - * Source for XcmsQueryColors - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsQueryColor - Query Color - * - * SYNOPSIS - */ -Status -XcmsQueryColor( - Display *dpy, - Colormap colormap, - XcmsColor *pXcmsColor_in_out, - XcmsColorFormat result_format) -/* - * DESCRIPTION - * This routine uses XQueryColor to obtain the X RGB values - * stored in the specified colormap for the specified pixel. - * The X RGB values are then converted to the target format as - * specified by the format component of the XcmsColor structure. - * - * RETURNS - * XcmsFailure if failed; - * XcmsSuccess if it succeeded. - * - * Returns a color specification of the color stored in the - * specified pixel. - */ -{ - return(_XcmsSetGetColor(XQueryColor, dpy, colormap, - pXcmsColor_in_out, result_format, (Bool *) NULL)); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsQuCol.c
+ *
+ * DESCRIPTION
+ * Source for XcmsQueryColors
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsQueryColor - Query Color
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsQueryColor(
+ Display *dpy,
+ Colormap colormap,
+ XcmsColor *pXcmsColor_in_out,
+ XcmsColorFormat result_format)
+/*
+ * DESCRIPTION
+ * This routine uses XQueryColor to obtain the X RGB values
+ * stored in the specified colormap for the specified pixel.
+ * The X RGB values are then converted to the target format as
+ * specified by the format component of the XcmsColor structure.
+ *
+ * RETURNS
+ * XcmsFailure if failed;
+ * XcmsSuccess if it succeeded.
+ *
+ * Returns a color specification of the color stored in the
+ * specified pixel.
+ */
+{
+ return(_XcmsSetGetColor(XQueryColor, dpy, colormap,
+ pXcmsColor_in_out, result_format, (Bool *) NULL));
+}
diff --git a/libX11/src/xcms/QuCols.c b/libX11/src/xcms/QuCols.c index 25a38b818..b286935d8 100644 --- a/libX11/src/xcms/QuCols.c +++ b/libX11/src/xcms/QuCols.c @@ -1,78 +1,78 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsQuCol.c - * - * DESCRIPTION - * Source for XcmsQueryColors - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ -/* - * NAME - * XcmsQueryColors - Query Colors - * - * SYNOPSIS - */ -Status -XcmsQueryColors( - Display *dpy, - Colormap colormap, - XcmsColor *pXcmsColors_in_out, - unsigned int nColors, - XcmsColorFormat result_format) -/* - * DESCRIPTION - * This routine uses XQueryColors to obtain the X RGB values - * stored in the specified colormap for the specified pixels. - * The X RGB values are then converted to the target format as - * specified by the format component of the XcmsColor structure. - * - * RETURNS - * XcmsFailure if failed; - * XcmsSuccess if it succeeded. - * - * Returns the color specifications of the colors stored in the - * specified pixels. - */ -{ - return(_XcmsSetGetColors(XQueryColors, dpy, colormap, - pXcmsColors_in_out, nColors, result_format, (Bool *) NULL)); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsQuCol.c
+ *
+ * DESCRIPTION
+ * Source for XcmsQueryColors
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+/*
+ * NAME
+ * XcmsQueryColors - Query Colors
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsQueryColors(
+ Display *dpy,
+ Colormap colormap,
+ XcmsColor *pXcmsColors_in_out,
+ unsigned int nColors,
+ XcmsColorFormat result_format)
+/*
+ * DESCRIPTION
+ * This routine uses XQueryColors to obtain the X RGB values
+ * stored in the specified colormap for the specified pixels.
+ * The X RGB values are then converted to the target format as
+ * specified by the format component of the XcmsColor structure.
+ *
+ * RETURNS
+ * XcmsFailure if failed;
+ * XcmsSuccess if it succeeded.
+ *
+ * Returns the color specifications of the colors stored in the
+ * specified pixels.
+ */
+{
+ return(_XcmsSetGetColors(XQueryColors, dpy, colormap,
+ pXcmsColors_in_out, nColors, result_format, (Bool *) NULL));
+}
diff --git a/libX11/src/xcms/SetCCC.c b/libX11/src/xcms/SetCCC.c index e8171b4ea..8ae6278f8 100644 --- a/libX11/src/xcms/SetCCC.c +++ b/libX11/src/xcms/SetCCC.c @@ -1,138 +1,138 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsSetCCC.c - Color Conversion Context Setting Routines - * - * DESCRIPTION - * Routines to set components of a Color Conversion - * Context structure. - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcms.h" - - - -/************************************************************************ - * * - * PUBLIC INTERFACES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsSetWhitePoint - * - * SYNOPSIS - */ - -Status -XcmsSetWhitePoint( - XcmsCCC ccc, - XcmsColor *pColor) -/* - * DESCRIPTION - * Sets the Client White Point in the specified CCC. - * - * RETURNS - * Returns XcmsSuccess if succeeded; otherwise XcmsFailure. - * - */ -{ - if (pColor == NULL || pColor->format == XcmsUndefinedFormat) { - ccc->clientWhitePt.format = XcmsUndefinedFormat; - } else if (pColor->format != XcmsCIEXYZFormat && - pColor->format != XcmsCIEuvYFormat && - pColor->format != XcmsCIExyYFormat) { - return(XcmsFailure); - } else { - memcpy((char *)&ccc->clientWhitePt, (char *)pColor, sizeof(XcmsColor)); - } - return(XcmsSuccess); -} - - -/* - * NAME - * XcmsSetCompressionProc - * - * SYNOPSIS - */ - -XcmsCompressionProc -XcmsSetCompressionProc( - XcmsCCC ccc, - XcmsCompressionProc compression_proc, - XPointer client_data) -/* - * DESCRIPTION - * Set the specified CCC's compression function and client data. - * - * RETURNS - * Returns the old compression function. - * - */ -{ - XcmsCompressionProc old = ccc->gamutCompProc; - - ccc->gamutCompProc = compression_proc; - ccc->gamutCompClientData = client_data; - return(old); -} - - -/* - * NAME - * XcmsSetWhiteAdjustProc - * - * SYNOPSIS - */ - -XcmsWhiteAdjustProc -XcmsSetWhiteAdjustProc( - XcmsCCC ccc, - XcmsWhiteAdjustProc white_adjust_proc, - XPointer client_data ) -/* - * DESCRIPTION - * Set the specified CCC's white_adjust function and client data. - * - * RETURNS - * Returns the old white_adjust function. - * - */ -{ - XcmsWhiteAdjustProc old = ccc->whitePtAdjProc; - - ccc->whitePtAdjProc = white_adjust_proc; - ccc->whitePtAdjClientData = client_data; - return(old); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsSetCCC.c - Color Conversion Context Setting Routines
+ *
+ * DESCRIPTION
+ * Routines to set components of a Color Conversion
+ * Context structure.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcms.h"
+
+
+
+/************************************************************************
+ * *
+ * PUBLIC INTERFACES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsSetWhitePoint
+ *
+ * SYNOPSIS
+ */
+
+Status
+XcmsSetWhitePoint(
+ XcmsCCC ccc,
+ XcmsColor *pColor)
+/*
+ * DESCRIPTION
+ * Sets the Client White Point in the specified CCC.
+ *
+ * RETURNS
+ * Returns XcmsSuccess if succeeded; otherwise XcmsFailure.
+ *
+ */
+{
+ if (pColor == NULL || pColor->format == XcmsUndefinedFormat) {
+ ccc->clientWhitePt.format = XcmsUndefinedFormat;
+ } else if (pColor->format != XcmsCIEXYZFormat &&
+ pColor->format != XcmsCIEuvYFormat &&
+ pColor->format != XcmsCIExyYFormat) {
+ return(XcmsFailure);
+ } else {
+ memcpy((char *)&ccc->clientWhitePt, (char *)pColor, sizeof(XcmsColor));
+ }
+ return(XcmsSuccess);
+}
+
+
+/*
+ * NAME
+ * XcmsSetCompressionProc
+ *
+ * SYNOPSIS
+ */
+
+XcmsCompressionProc
+XcmsSetCompressionProc(
+ XcmsCCC ccc,
+ XcmsCompressionProc compression_proc,
+ XPointer client_data)
+/*
+ * DESCRIPTION
+ * Set the specified CCC's compression function and client data.
+ *
+ * RETURNS
+ * Returns the old compression function.
+ *
+ */
+{
+ XcmsCompressionProc old = ccc->gamutCompProc;
+
+ ccc->gamutCompProc = compression_proc;
+ ccc->gamutCompClientData = client_data;
+ return(old);
+}
+
+
+/*
+ * NAME
+ * XcmsSetWhiteAdjustProc
+ *
+ * SYNOPSIS
+ */
+
+XcmsWhiteAdjustProc
+XcmsSetWhiteAdjustProc(
+ XcmsCCC ccc,
+ XcmsWhiteAdjustProc white_adjust_proc,
+ XPointer client_data )
+/*
+ * DESCRIPTION
+ * Set the specified CCC's white_adjust function and client data.
+ *
+ * RETURNS
+ * Returns the old white_adjust function.
+ *
+ */
+{
+ XcmsWhiteAdjustProc old = ccc->whitePtAdjProc;
+
+ ccc->whitePtAdjProc = white_adjust_proc;
+ ccc->whitePtAdjClientData = client_data;
+ return(old);
+}
diff --git a/libX11/src/xcms/SetGetCols.c b/libX11/src/xcms/SetGetCols.c index 9b548dbb2..763e6dda4 100644 --- a/libX11/src/xcms/SetGetCols.c +++ b/libX11/src/xcms/SetGetCols.c @@ -1,301 +1,301 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsSetGet.c - * - * DESCRIPTION - * Source for _XcmsSetGetColors() - * - * - */ - -/* - * EXTERNAL INCLUDES - * Include files that must be exported to any package or - * program using this package. - */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/************************************************************************ - * * - * API PRIVATE ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsSetColor - - * - * SYNOPSIS - */ -Status -_XcmsSetGetColor( - Status (*xColorProc)( - Display* /* display */, - Colormap /* colormap */, - XColor* /* screen_in_out */), - Display *dpy, - Colormap cmap, - XcmsColor *pColors_in_out, - XcmsColorFormat result_format, - Bool *pCompressed) -/* - * DESCRIPTION - * Routine containing code common to: - * XcmsAllocColor - * XcmsQueryColor - * XcmsStoreColor - * - * RETURNS - * XcmsFailure if failed; - * XcmsSuccess if it succeeded without gamut compression; - * XcmsSuccessWithCompression if it succeeded with gamut - * compression; - */ -{ - XcmsCCC ccc; - XColor XColors_in_out; - Status retval = XcmsSuccess; - - /* - * Argument Checking - * 1. Assume xColorProc is correct - * 2. Insure ccc not NULL - * 3. Assume cmap correct (should be checked by Server) - * 4. Insure pColors_in_out valid - * 5. Assume method_in is valid (should be checked by Server) - */ - - if (dpy == NULL) { - return(XcmsFailure); - } - - if (result_format == XcmsUndefinedFormat) { - return(XcmsFailure); - } - - if ( !((*xColorProc == XAllocColor) || (*xColorProc == XStoreColor) - || (*xColorProc == XQueryColor)) ) { - return(XcmsFailure); - } - - if ((ccc = XcmsCCCOfColormap(dpy, cmap)) == (XcmsCCC)NULL) { - return(XcmsFailure); - } - - if (*xColorProc == XQueryColor) { - goto Query; - } - - /* - * Convert to RGB, adjusting for white point differences if necessary. - */ - if ((retval = XcmsConvertColors(ccc, pColors_in_out, 1, XcmsRGBFormat, - pCompressed)) == XcmsFailure) { - return(XcmsFailure); - } - -Query: - /* - * Convert XcmsColor to XColor structures - */ - _XcmsRGB_to_XColor(pColors_in_out, &XColors_in_out, 1); - - /* - * Now make appropriate X Call - */ - if (*xColorProc == XAllocColor) { - if ((*xColorProc)(ccc->dpy, cmap, &XColors_in_out) == 0) { - return(XcmsFailure); - } - } else if ((*xColorProc == XQueryColor) || (*xColorProc == XStoreColor)) { - /* Note: XQueryColor and XStoreColor do not return any Status */ - (*xColorProc)(ccc->dpy, cmap, &XColors_in_out); - } else { - return(XcmsFailure); - } - - if ((*xColorProc == XStoreColor)) { - return(retval); - } - - /* - * Now, convert the returned XColor (i.e., rgb) to XcmsColor structures - */ - _XColor_to_XcmsRGB(ccc, &XColors_in_out, pColors_in_out, 1); - - /* - * Then, convert XcmsColor structures to the original specification - * format. Note that we must use NULL instead of passing - * pCompressed. - */ - - if (result_format != XcmsRGBFormat) { - if (XcmsConvertColors(ccc, pColors_in_out, 1, result_format, - (Bool *) NULL) == XcmsFailure) { - return(XcmsFailure); - } - } - return(retval); -} - -/* - * NAME - * XcmsSetColors - - * - * SYNOPSIS - */ -Status -_XcmsSetGetColors( - Status (*xColorProc)( - Display* /* display */, - Colormap /* colormap */, - XColor* /* screen_in_out */, - int /* nColors */), - Display *dpy, - Colormap cmap, - XcmsColor *pColors_in_out, - int nColors, - XcmsColorFormat result_format, - Bool *pCompressed) -/* - * DESCRIPTION - * Routine containing code common to: - * XcmsQueryColors - * XcmsStoreColors - * - * RETURNS - * XcmsFailure if failed; - * XcmsSuccess if it succeeded without gamut compression; - * XcmsSuccessWithCompression if it succeeded with gamut - * compression; - */ -{ - XcmsCCC ccc; - XColor *pXColors_in_out; - Status retval = XcmsSuccess; - - /* - * Argument Checking - * 1. Assume xColorProc is correct - * 2. Insure ccc not NULL - * 3. Assume cmap correct (should be checked by Server) - * 4. Insure pColors_in_out valid - * 5. Assume method_in is valid (should be checked by Server) - * 6. Insure nColors > 0 - */ - - if (dpy == NULL) { - return(XcmsFailure); - } - - if (nColors == 0) { - return(XcmsSuccess); - } - - if (result_format == XcmsUndefinedFormat) { - return(XcmsFailure); - } - - if ( !((*xColorProc == XStoreColors) || (*xColorProc == XQueryColors)) ) { - return(XcmsFailure); - } - - if ((ccc = XcmsCCCOfColormap(dpy, cmap)) == (XcmsCCC)NULL) { - return(XcmsFailure); - } - - /* - * Allocate space for XColors - */ - if ((pXColors_in_out = (XColor *)Xcalloc(nColors, sizeof(XColor))) == - NULL) { - return(XcmsFailure); - } - - if (*xColorProc == XQueryColors) { - goto Query; - } - - /* - * Convert to RGB, adjusting for white point differences if necessary. - */ - if ((retval = XcmsConvertColors(ccc, pColors_in_out, nColors, XcmsRGBFormat, - pCompressed)) == XcmsFailure) { - Xfree((char *)pXColors_in_out); - return(XcmsFailure); - } - -Query: - /* - * Convert XcmsColor to XColor structures - */ - _XcmsRGB_to_XColor(pColors_in_out, pXColors_in_out, nColors); - - /* - * Now make appropriate X Call - */ - if ((*xColorProc == XQueryColors) || (*xColorProc == XStoreColors)){ - /* Note: XQueryColors and XStoreColors do not return any Status */ - (*xColorProc)(ccc->dpy, cmap, pXColors_in_out, nColors); - } else { - Xfree((char *)pXColors_in_out); - return(XcmsFailure); - } - - if (*xColorProc == XStoreColors) { - Xfree((char *)pXColors_in_out); - return(retval); - } - - /* - * Now, convert the returned XColor (i.e., rgb) to XcmsColor structures - */ - _XColor_to_XcmsRGB(ccc, pXColors_in_out, pColors_in_out, nColors); - Xfree((char *)pXColors_in_out); - - /* - * Then, convert XcmsColor structures to the original specification - * format. Note that we must use NULL instead of passing - * pCompressed. - */ - if (result_format != XcmsRGBFormat) { - if (XcmsConvertColors(ccc, pColors_in_out, nColors, result_format, - (Bool *) NULL) == XcmsFailure) { - return(XcmsFailure); - } - } - - return(retval); -} - -/* ### EOF ### */ +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsSetGet.c
+ *
+ * DESCRIPTION
+ * Source for _XcmsSetGetColors()
+ *
+ *
+ */
+
+/*
+ * EXTERNAL INCLUDES
+ * Include files that must be exported to any package or
+ * program using this package.
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/************************************************************************
+ * *
+ * API PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsSetColor -
+ *
+ * SYNOPSIS
+ */
+Status
+_XcmsSetGetColor(
+ Status (*xColorProc)(
+ Display* /* display */,
+ Colormap /* colormap */,
+ XColor* /* screen_in_out */),
+ Display *dpy,
+ Colormap cmap,
+ XcmsColor *pColors_in_out,
+ XcmsColorFormat result_format,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * Routine containing code common to:
+ * XcmsAllocColor
+ * XcmsQueryColor
+ * XcmsStoreColor
+ *
+ * RETURNS
+ * XcmsFailure if failed;
+ * XcmsSuccess if it succeeded without gamut compression;
+ * XcmsSuccessWithCompression if it succeeded with gamut
+ * compression;
+ */
+{
+ XcmsCCC ccc;
+ XColor XColors_in_out;
+ Status retval = XcmsSuccess;
+
+ /*
+ * Argument Checking
+ * 1. Assume xColorProc is correct
+ * 2. Insure ccc not NULL
+ * 3. Assume cmap correct (should be checked by Server)
+ * 4. Insure pColors_in_out valid
+ * 5. Assume method_in is valid (should be checked by Server)
+ */
+
+ if (dpy == NULL) {
+ return(XcmsFailure);
+ }
+
+ if (result_format == XcmsUndefinedFormat) {
+ return(XcmsFailure);
+ }
+
+ if ( !((*xColorProc == XAllocColor) || (*xColorProc == XStoreColor)
+ || (*xColorProc == XQueryColor)) ) {
+ return(XcmsFailure);
+ }
+
+ if ((ccc = XcmsCCCOfColormap(dpy, cmap)) == (XcmsCCC)NULL) {
+ return(XcmsFailure);
+ }
+
+ if (*xColorProc == XQueryColor) {
+ goto Query;
+ }
+
+ /*
+ * Convert to RGB, adjusting for white point differences if necessary.
+ */
+ if ((retval = XcmsConvertColors(ccc, pColors_in_out, 1, XcmsRGBFormat,
+ pCompressed)) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+
+Query:
+ /*
+ * Convert XcmsColor to XColor structures
+ */
+ _XcmsRGB_to_XColor(pColors_in_out, &XColors_in_out, 1);
+
+ /*
+ * Now make appropriate X Call
+ */
+ if (*xColorProc == XAllocColor) {
+ if ((*xColorProc)(ccc->dpy, cmap, &XColors_in_out) == 0) {
+ return(XcmsFailure);
+ }
+ } else if ((*xColorProc == XQueryColor) || (*xColorProc == XStoreColor)) {
+ /* Note: XQueryColor and XStoreColor do not return any Status */
+ (*xColorProc)(ccc->dpy, cmap, &XColors_in_out);
+ } else {
+ return(XcmsFailure);
+ }
+
+ if ((*xColorProc == XStoreColor)) {
+ return(retval);
+ }
+
+ /*
+ * Now, convert the returned XColor (i.e., rgb) to XcmsColor structures
+ */
+ _XColor_to_XcmsRGB(ccc, &XColors_in_out, pColors_in_out, 1);
+
+ /*
+ * Then, convert XcmsColor structures to the original specification
+ * format. Note that we must use NULL instead of passing
+ * pCompressed.
+ */
+
+ if (result_format != XcmsRGBFormat) {
+ if (XcmsConvertColors(ccc, pColors_in_out, 1, result_format,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+ return(retval);
+}
+
+/*
+ * NAME
+ * XcmsSetColors -
+ *
+ * SYNOPSIS
+ */
+Status
+_XcmsSetGetColors(
+ Status (*xColorProc)(
+ Display* /* display */,
+ Colormap /* colormap */,
+ XColor* /* screen_in_out */,
+ int /* nColors */),
+ Display *dpy,
+ Colormap cmap,
+ XcmsColor *pColors_in_out,
+ int nColors,
+ XcmsColorFormat result_format,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * Routine containing code common to:
+ * XcmsQueryColors
+ * XcmsStoreColors
+ *
+ * RETURNS
+ * XcmsFailure if failed;
+ * XcmsSuccess if it succeeded without gamut compression;
+ * XcmsSuccessWithCompression if it succeeded with gamut
+ * compression;
+ */
+{
+ XcmsCCC ccc;
+ XColor *pXColors_in_out;
+ Status retval = XcmsSuccess;
+
+ /*
+ * Argument Checking
+ * 1. Assume xColorProc is correct
+ * 2. Insure ccc not NULL
+ * 3. Assume cmap correct (should be checked by Server)
+ * 4. Insure pColors_in_out valid
+ * 5. Assume method_in is valid (should be checked by Server)
+ * 6. Insure nColors > 0
+ */
+
+ if (dpy == NULL) {
+ return(XcmsFailure);
+ }
+
+ if (nColors == 0) {
+ return(XcmsSuccess);
+ }
+
+ if (result_format == XcmsUndefinedFormat) {
+ return(XcmsFailure);
+ }
+
+ if ( !((*xColorProc == XStoreColors) || (*xColorProc == XQueryColors)) ) {
+ return(XcmsFailure);
+ }
+
+ if ((ccc = XcmsCCCOfColormap(dpy, cmap)) == (XcmsCCC)NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Allocate space for XColors
+ */
+ if ((pXColors_in_out = (XColor *)Xcalloc(nColors, sizeof(XColor))) ==
+ NULL) {
+ return(XcmsFailure);
+ }
+
+ if (*xColorProc == XQueryColors) {
+ goto Query;
+ }
+
+ /*
+ * Convert to RGB, adjusting for white point differences if necessary.
+ */
+ if ((retval = XcmsConvertColors(ccc, pColors_in_out, nColors, XcmsRGBFormat,
+ pCompressed)) == XcmsFailure) {
+ Xfree((char *)pXColors_in_out);
+ return(XcmsFailure);
+ }
+
+Query:
+ /*
+ * Convert XcmsColor to XColor structures
+ */
+ _XcmsRGB_to_XColor(pColors_in_out, pXColors_in_out, nColors);
+
+ /*
+ * Now make appropriate X Call
+ */
+ if ((*xColorProc == XQueryColors) || (*xColorProc == XStoreColors)){
+ /* Note: XQueryColors and XStoreColors do not return any Status */
+ (*xColorProc)(ccc->dpy, cmap, pXColors_in_out, nColors);
+ } else {
+ Xfree((char *)pXColors_in_out);
+ return(XcmsFailure);
+ }
+
+ if (*xColorProc == XStoreColors) {
+ Xfree((char *)pXColors_in_out);
+ return(retval);
+ }
+
+ /*
+ * Now, convert the returned XColor (i.e., rgb) to XcmsColor structures
+ */
+ _XColor_to_XcmsRGB(ccc, pXColors_in_out, pColors_in_out, nColors);
+ Xfree((char *)pXColors_in_out);
+
+ /*
+ * Then, convert XcmsColor structures to the original specification
+ * format. Note that we must use NULL instead of passing
+ * pCompressed.
+ */
+ if (result_format != XcmsRGBFormat) {
+ if (XcmsConvertColors(ccc, pColors_in_out, nColors, result_format,
+ (Bool *) NULL) == XcmsFailure) {
+ return(XcmsFailure);
+ }
+ }
+
+ return(retval);
+}
+
+/* ### EOF ### */
diff --git a/libX11/src/xcms/StCol.c b/libX11/src/xcms/StCol.c index 941ad0743..b882ff706 100644 --- a/libX11/src/xcms/StCol.c +++ b/libX11/src/xcms/StCol.c @@ -1,82 +1,82 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsStCol.c - * - * DESCRIPTION - * Source for XcmsStoreColor - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsStoreColor - Store Color - * - * SYNOPSIS - */ -Status -XcmsStoreColor( - Display *dpy, - Colormap colormap, - XcmsColor *pColor_in) -/* - * DESCRIPTION - * Given a device-dependent or device-independent color - * specification, this routine will convert it to X RGB - * values then use it in a call to XStoreColor. - * - * RETURNS - * XcmsFailure if failed; - * XcmsSuccess if it succeeded without gamut compression; - * XcmsSuccessWithCompression if it succeeded with gamut - * compression; - * - * Since XStoreColor has no return value this routine - * does not return the color specification of the color actually - * stored. - */ -{ - XcmsColor tmpColor; - - tmpColor = *pColor_in; - return(_XcmsSetGetColor(XStoreColor, dpy, colormap, - &tmpColor, XcmsRGBFormat, (Bool *) NULL)); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsStCol.c
+ *
+ * DESCRIPTION
+ * Source for XcmsStoreColor
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsStoreColor - Store Color
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsStoreColor(
+ Display *dpy,
+ Colormap colormap,
+ XcmsColor *pColor_in)
+/*
+ * DESCRIPTION
+ * Given a device-dependent or device-independent color
+ * specification, this routine will convert it to X RGB
+ * values then use it in a call to XStoreColor.
+ *
+ * RETURNS
+ * XcmsFailure if failed;
+ * XcmsSuccess if it succeeded without gamut compression;
+ * XcmsSuccessWithCompression if it succeeded with gamut
+ * compression;
+ *
+ * Since XStoreColor has no return value this routine
+ * does not return the color specification of the color actually
+ * stored.
+ */
+{
+ XcmsColor tmpColor;
+
+ tmpColor = *pColor_in;
+ return(_XcmsSetGetColor(XStoreColor, dpy, colormap,
+ &tmpColor, XcmsRGBFormat, (Bool *) NULL));
+}
diff --git a/libX11/src/xcms/StCols.c b/libX11/src/xcms/StCols.c index 24ccd386f..01ad78115 100644 --- a/libX11/src/xcms/StCols.c +++ b/libX11/src/xcms/StCols.c @@ -1,112 +1,112 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsStCols.c - * - * DESCRIPTION - * Source for XcmsStoreColors - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsStoreColors - Store Colors - * - * SYNOPSIS - */ -Status -XcmsStoreColors( - Display *dpy, - Colormap colormap, - XcmsColor *pColors_in, - unsigned int nColors, - Bool *pCompressed) -/* - * DESCRIPTION - * Given device-dependent or device-independent color - * specifications, this routine will convert them to X RGB - * values then use it in a call to XStoreColors. - * - * RETURNS - * XcmsFailure if failed; - * XcmsSuccess if it succeeded without gamut compression; - * XcmsSuccessWithCompression if it succeeded with gamut - * compression; - * - * Since XStoreColors has no return value, this routine - * does not return color specifications of the colors actually - * stored. - */ -{ - XcmsColor Color1; - XcmsColor *pColors_tmp; - Status retval; - - /* - * Make copy of array of color specifications so we don't - * overwrite the contents. - */ - if (nColors > 1) { - pColors_tmp = (XcmsColor *) Xmalloc(nColors * sizeof(XcmsColor)); - } else { - pColors_tmp = &Color1; - } - memcpy((char *)pColors_tmp, (char *)pColors_in, - nColors * sizeof(XcmsColor)); - - /* - * Call routine to store colors using the copied color structures - */ - retval = _XcmsSetGetColors (XStoreColors, dpy, colormap, - pColors_tmp, nColors, XcmsRGBFormat, pCompressed); - - /* - * Free copies as needed. - */ - if (nColors > 1) { - Xfree((char *)pColors_tmp); - } - - /* - * Ah, finally return. - */ - return(retval); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsStCols.c
+ *
+ * DESCRIPTION
+ * Source for XcmsStoreColors
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsStoreColors - Store Colors
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsStoreColors(
+ Display *dpy,
+ Colormap colormap,
+ XcmsColor *pColors_in,
+ unsigned int nColors,
+ Bool *pCompressed)
+/*
+ * DESCRIPTION
+ * Given device-dependent or device-independent color
+ * specifications, this routine will convert them to X RGB
+ * values then use it in a call to XStoreColors.
+ *
+ * RETURNS
+ * XcmsFailure if failed;
+ * XcmsSuccess if it succeeded without gamut compression;
+ * XcmsSuccessWithCompression if it succeeded with gamut
+ * compression;
+ *
+ * Since XStoreColors has no return value, this routine
+ * does not return color specifications of the colors actually
+ * stored.
+ */
+{
+ XcmsColor Color1;
+ XcmsColor *pColors_tmp;
+ Status retval;
+
+ /*
+ * Make copy of array of color specifications so we don't
+ * overwrite the contents.
+ */
+ if (nColors > 1) {
+ pColors_tmp = (XcmsColor *) Xmalloc(nColors * sizeof(XcmsColor));
+ } else {
+ pColors_tmp = &Color1;
+ }
+ memcpy((char *)pColors_tmp, (char *)pColors_in,
+ nColors * sizeof(XcmsColor));
+
+ /*
+ * Call routine to store colors using the copied color structures
+ */
+ retval = _XcmsSetGetColors (XStoreColors, dpy, colormap,
+ pColors_tmp, nColors, XcmsRGBFormat, pCompressed);
+
+ /*
+ * Free copies as needed.
+ */
+ if (nColors > 1) {
+ Xfree((char *)pColors_tmp);
+ }
+
+ /*
+ * Ah, finally return.
+ */
+ return(retval);
+}
diff --git a/libX11/src/xcms/UNDEFINED.c b/libX11/src/xcms/UNDEFINED.c index 7b1bdb68c..d7a3631fc 100644 --- a/libX11/src/xcms/UNDEFINED.c +++ b/libX11/src/xcms/UNDEFINED.c @@ -1,131 +1,131 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * - * NAME - * UNDEFINED.c - * - * DESCRIPTION - * UNDEFINED Color Space - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" - -/* - * FORWARD DECLARATIONS - */ -static int DummyParseStringProc( - char* /* color_string */, - XcmsColor* /* color_return */ - ); -static Status ReturnZero( - XcmsCCC /* ccc */, - XcmsColor* /* white_point */, - XcmsColor* /* colors */, - unsigned int /* ncolors */ - ); - - -/* - * LOCALS VARIABLES - */ - -static Status (*(Fl_ReturnZero[]))( - XcmsCCC /* ccc */, - XcmsColor* /* white_point */, - XcmsColor* /* colors */, - unsigned int /* ncolors */ - ) = { - ReturnZero, - NULL -}; - - -/* - * GLOBALS - * Variables declared in this package that are allowed - * to be used globally. - */ - /* - * UNDEFINED Color Space - */ -XcmsColorSpace XcmsUNDEFINEDColorSpace = - { - "undefined", /* prefix */ - XcmsUndefinedFormat, /* id */ - &DummyParseStringProc, /* parseString */ - Fl_ReturnZero, /* to_CIEXYZ */ - Fl_ReturnZero /* from_CIEXYZ */ - }; - - - -/************************************************************************ - * * - * PRIVATE ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * ReturnZero - * - * SYNOPSIS - */ -/* ARGSUSED */ -static Status -ReturnZero( - XcmsCCC ccc /* ccc */, - XcmsColor* white /* white_point */, - XcmsColor* colors /* colors */, - unsigned int ncolors /* ncolors */ - ) -/* - * DESCRIPTION - * Does nothing. - * - * RETURNS - * 0 - * - */ -{ - return(0); -} - -static int DummyParseStringProc( - char* color_string /* color_string */, - XcmsColor* color_return /* color_return */ - ) -{ - return(0); -} - -/* ### EOF ### */ +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ *
+ * NAME
+ * UNDEFINED.c
+ *
+ * DESCRIPTION
+ * UNDEFINED Color Space
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+
+/*
+ * FORWARD DECLARATIONS
+ */
+static int DummyParseStringProc(
+ char* /* color_string */,
+ XcmsColor* /* color_return */
+ );
+static Status ReturnZero(
+ XcmsCCC /* ccc */,
+ XcmsColor* /* white_point */,
+ XcmsColor* /* colors */,
+ unsigned int /* ncolors */
+ );
+
+
+/*
+ * LOCALS VARIABLES
+ */
+
+static Status (*(Fl_ReturnZero[]))(
+ XcmsCCC /* ccc */,
+ XcmsColor* /* white_point */,
+ XcmsColor* /* colors */,
+ unsigned int /* ncolors */
+ ) = {
+ ReturnZero,
+ NULL
+};
+
+
+/*
+ * GLOBALS
+ * Variables declared in this package that are allowed
+ * to be used globally.
+ */
+ /*
+ * UNDEFINED Color Space
+ */
+XcmsColorSpace XcmsUNDEFINEDColorSpace =
+ {
+ "undefined", /* prefix */
+ XcmsUndefinedFormat, /* id */
+ &DummyParseStringProc, /* parseString */
+ Fl_ReturnZero, /* to_CIEXYZ */
+ Fl_ReturnZero /* from_CIEXYZ */
+ };
+
+
+
+/************************************************************************
+ * *
+ * PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * ReturnZero
+ *
+ * SYNOPSIS
+ */
+/* ARGSUSED */
+static Status
+ReturnZero(
+ XcmsCCC ccc /* ccc */,
+ XcmsColor* white /* white_point */,
+ XcmsColor* colors /* colors */,
+ unsigned int ncolors /* ncolors */
+ )
+/*
+ * DESCRIPTION
+ * Does nothing.
+ *
+ * RETURNS
+ * 0
+ *
+ */
+{
+ return(0);
+}
+
+static int DummyParseStringProc(
+ char* color_string /* color_string */,
+ XcmsColor* color_return /* color_return */
+ )
+{
+ return(0);
+}
+
+/* ### EOF ### */
diff --git a/libX11/src/xcms/XRGB.c b/libX11/src/xcms/XRGB.c index 03f980e99..d9db8c074 100644 --- a/libX11/src/xcms/XRGB.c +++ b/libX11/src/xcms/XRGB.c @@ -1,242 +1,242 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsRtoX.c - * - * DESCRIPTION - * Convert color specifications in XcmsRGB format in one array of - * XcmsColor structures to RGB in an array of XColor structures. - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - -/* - * LOCAL VARIABLES - */ - -static unsigned short const MASK[17] = { - 0x0000, /* 0 bitsPerRGB */ - 0x8000, /* 1 bitsPerRGB */ - 0xc000, /* 2 bitsPerRGB */ - 0xe000, /* 3 bitsPerRGB */ - 0xf000, /* 4 bitsPerRGB */ - 0xf800, /* 5 bitsPerRGB */ - 0xfc00, /* 6 bitsPerRGB */ - 0xfe00, /* 7 bitsPerRGB */ - 0xff00, /* 8 bitsPerRGB */ - 0xff80, /* 9 bitsPerRGB */ - 0xffc0, /* 10 bitsPerRGB */ - 0xffe0, /* 11 bitsPerRGB */ - 0xfff0, /* 12 bitsPerRGB */ - 0xfff8, /* 13 bitsPerRGB */ - 0xfffc, /* 14 bitsPerRGB */ - 0xfffe, /* 15 bitsPerRGB */ - 0xffff /* 16 bitsPerRGB */ -}; - - - -/************************************************************************ - * * - * API PRIVATE ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * _XcmsRGB_to_XColor - - * - * SYNOPSIS - */ -void -_XcmsRGB_to_XColor( - XcmsColor *pColors, - XColor *pXColors, - unsigned int nColors) -/* - * DESCRIPTION - * Translates a color specification in XcmsRGBFormat in a XcmsColor - * structure to an XColor structure. - * - * RETURNS - * void. - */ -{ - for (; nColors--; pXColors++, pColors++) { - pXColors->pixel = pColors->pixel; - pXColors->red = pColors->spec.RGB.red; - pXColors->green = pColors->spec.RGB.green; - pXColors->blue = pColors->spec.RGB.blue; - pXColors->flags = (DoRed | DoGreen | DoBlue); - } -} - - -/* - * NAME - * _XColor_to_XcmsRGB - * - * SYNOPSIS - */ -void -_XColor_to_XcmsRGB( - XcmsCCC ccc, - XColor *pXColors, - XcmsColor *pColors, - unsigned int nColors) -/* - * DESCRIPTION - * Translates an RGB color specification in an XColor - * structure to an XcmsRGB structure. - * - * IMPORTANT NOTE: Bit replication that may have been caused - * with ResolveColor() routine in the X Server is undone - * here if requested! For example, if red = 0xcaca and the - * bits_per_rgb is 8, then spec.RGB.red will be 0xca00. - * - * RETURNS - * void - */ -{ - int bits_per_rgb = ccc->visual->bits_per_rgb; - - for (; nColors--; pXColors++, pColors++) { - pColors->spec.RGB.red = (pXColors->red & MASK[bits_per_rgb]); - pColors->spec.RGB.green = (pXColors->green & MASK[bits_per_rgb]); - pColors->spec.RGB.blue = (pXColors->blue & MASK[bits_per_rgb]); - pColors->format = XcmsRGBFormat; - pColors->pixel = pXColors->pixel; - } -} - - -/* - * NAME - * _XcmsResolveColor - * - * SYNOPSIS - */ -void -_XcmsResolveColor( - XcmsCCC ccc, - XcmsColor *pXcmsColor) -/* - * DESCRIPTION - * Uses the X Server ResolveColor() algorithm to - * modify values to closest values supported by hardware. - * Old algorithm simply masked low-order bits. The new algorithm - * has the effect of replicating significant bits into lower order - * bits in order to stretch the hardware value into all 16 bits. - * - * On a display with N-bit DACs, the "hardware" color is computed as: - * - * ((unsignedlong)(ClientValue >> (16-N)) * 0xFFFF) / ((1 << N) - 1) - * - * - * RETURNS - * void. - */ -{ - int shift; - int max_color; - - shift = 16 - ccc->visual->bits_per_rgb; - max_color = (1 << ccc->visual->bits_per_rgb) - 1; - - - pXcmsColor->spec.RGB.red = - ((unsigned long)(pXcmsColor->spec.RGB.red >> shift) * 0xFFFF) - / max_color; - pXcmsColor->spec.RGB.green = - ((unsigned long)(pXcmsColor->spec.RGB.green >> shift) * 0xFFFF) - / max_color; - pXcmsColor->spec.RGB.blue = - ((unsigned long)(pXcmsColor->spec.RGB.blue >> shift) * 0xFFFF) - / max_color; -} - - -/* - * NAME - * _XcmsUnresolveColor - * - * SYNOPSIS - */ -void -_XcmsUnresolveColor( - XcmsCCC ccc, - XcmsColor *pColor) -/* - * DESCRIPTION - * Masks out insignificant bits. - * - * RETURNS - * void. - * - * ASSUMPTIONS - * format == XcmsRGBFormat - */ -{ - int bits_per_rgb = ccc->visual->bits_per_rgb; - - pColor->spec.RGB.red &= MASK[bits_per_rgb]; - pColor->spec.RGB.green &= MASK[bits_per_rgb]; - pColor->spec.RGB.blue &= MASK[bits_per_rgb]; -} - - -/* - * NAME - * _XUnresolveColor - * - * SYNOPSIS - */ -void -_XUnresolveColor( - XcmsCCC ccc, - XColor *pXColor) -/* - * DESCRIPTION - * Masks out insignificant bits. - * - * RETURNS - * void. - */ -{ - int bits_per_rgb = ccc->visual->bits_per_rgb; - - pXColor->red &= MASK[bits_per_rgb]; - pXColor->green &= MASK[bits_per_rgb]; - pXColor->blue &= MASK[bits_per_rgb]; -} - +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsRtoX.c
+ *
+ * DESCRIPTION
+ * Convert color specifications in XcmsRGB format in one array of
+ * XcmsColor structures to RGB in an array of XColor structures.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+/*
+ * LOCAL VARIABLES
+ */
+
+static unsigned short const MASK[17] = {
+ 0x0000, /* 0 bitsPerRGB */
+ 0x8000, /* 1 bitsPerRGB */
+ 0xc000, /* 2 bitsPerRGB */
+ 0xe000, /* 3 bitsPerRGB */
+ 0xf000, /* 4 bitsPerRGB */
+ 0xf800, /* 5 bitsPerRGB */
+ 0xfc00, /* 6 bitsPerRGB */
+ 0xfe00, /* 7 bitsPerRGB */
+ 0xff00, /* 8 bitsPerRGB */
+ 0xff80, /* 9 bitsPerRGB */
+ 0xffc0, /* 10 bitsPerRGB */
+ 0xffe0, /* 11 bitsPerRGB */
+ 0xfff0, /* 12 bitsPerRGB */
+ 0xfff8, /* 13 bitsPerRGB */
+ 0xfffc, /* 14 bitsPerRGB */
+ 0xfffe, /* 15 bitsPerRGB */
+ 0xffff /* 16 bitsPerRGB */
+};
+
+
+
+/************************************************************************
+ * *
+ * API PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * _XcmsRGB_to_XColor -
+ *
+ * SYNOPSIS
+ */
+void
+_XcmsRGB_to_XColor(
+ XcmsColor *pColors,
+ XColor *pXColors,
+ unsigned int nColors)
+/*
+ * DESCRIPTION
+ * Translates a color specification in XcmsRGBFormat in a XcmsColor
+ * structure to an XColor structure.
+ *
+ * RETURNS
+ * void.
+ */
+{
+ for (; nColors--; pXColors++, pColors++) {
+ pXColors->pixel = pColors->pixel;
+ pXColors->red = pColors->spec.RGB.red;
+ pXColors->green = pColors->spec.RGB.green;
+ pXColors->blue = pColors->spec.RGB.blue;
+ pXColors->flags = (DoRed | DoGreen | DoBlue);
+ }
+}
+
+
+/*
+ * NAME
+ * _XColor_to_XcmsRGB
+ *
+ * SYNOPSIS
+ */
+void
+_XColor_to_XcmsRGB(
+ XcmsCCC ccc,
+ XColor *pXColors,
+ XcmsColor *pColors,
+ unsigned int nColors)
+/*
+ * DESCRIPTION
+ * Translates an RGB color specification in an XColor
+ * structure to an XcmsRGB structure.
+ *
+ * IMPORTANT NOTE: Bit replication that may have been caused
+ * with ResolveColor() routine in the X Server is undone
+ * here if requested! For example, if red = 0xcaca and the
+ * bits_per_rgb is 8, then spec.RGB.red will be 0xca00.
+ *
+ * RETURNS
+ * void
+ */
+{
+ int bits_per_rgb = ccc->visual->bits_per_rgb;
+
+ for (; nColors--; pXColors++, pColors++) {
+ pColors->spec.RGB.red = (pXColors->red & MASK[bits_per_rgb]);
+ pColors->spec.RGB.green = (pXColors->green & MASK[bits_per_rgb]);
+ pColors->spec.RGB.blue = (pXColors->blue & MASK[bits_per_rgb]);
+ pColors->format = XcmsRGBFormat;
+ pColors->pixel = pXColors->pixel;
+ }
+}
+
+
+/*
+ * NAME
+ * _XcmsResolveColor
+ *
+ * SYNOPSIS
+ */
+void
+_XcmsResolveColor(
+ XcmsCCC ccc,
+ XcmsColor *pXcmsColor)
+/*
+ * DESCRIPTION
+ * Uses the X Server ResolveColor() algorithm to
+ * modify values to closest values supported by hardware.
+ * Old algorithm simply masked low-order bits. The new algorithm
+ * has the effect of replicating significant bits into lower order
+ * bits in order to stretch the hardware value into all 16 bits.
+ *
+ * On a display with N-bit DACs, the "hardware" color is computed as:
+ *
+ * ((unsignedlong)(ClientValue >> (16-N)) * 0xFFFF) / ((1 << N) - 1)
+ *
+ *
+ * RETURNS
+ * void.
+ */
+{
+ int shift;
+ int max_color;
+
+ shift = 16 - ccc->visual->bits_per_rgb;
+ max_color = (1 << ccc->visual->bits_per_rgb) - 1;
+
+
+ pXcmsColor->spec.RGB.red =
+ ((unsigned long)(pXcmsColor->spec.RGB.red >> shift) * 0xFFFF)
+ / max_color;
+ pXcmsColor->spec.RGB.green =
+ ((unsigned long)(pXcmsColor->spec.RGB.green >> shift) * 0xFFFF)
+ / max_color;
+ pXcmsColor->spec.RGB.blue =
+ ((unsigned long)(pXcmsColor->spec.RGB.blue >> shift) * 0xFFFF)
+ / max_color;
+}
+
+
+/*
+ * NAME
+ * _XcmsUnresolveColor
+ *
+ * SYNOPSIS
+ */
+void
+_XcmsUnresolveColor(
+ XcmsCCC ccc,
+ XcmsColor *pColor)
+/*
+ * DESCRIPTION
+ * Masks out insignificant bits.
+ *
+ * RETURNS
+ * void.
+ *
+ * ASSUMPTIONS
+ * format == XcmsRGBFormat
+ */
+{
+ int bits_per_rgb = ccc->visual->bits_per_rgb;
+
+ pColor->spec.RGB.red &= MASK[bits_per_rgb];
+ pColor->spec.RGB.green &= MASK[bits_per_rgb];
+ pColor->spec.RGB.blue &= MASK[bits_per_rgb];
+}
+
+
+/*
+ * NAME
+ * _XUnresolveColor
+ *
+ * SYNOPSIS
+ */
+void
+_XUnresolveColor(
+ XcmsCCC ccc,
+ XColor *pXColor)
+/*
+ * DESCRIPTION
+ * Masks out insignificant bits.
+ *
+ * RETURNS
+ * void.
+ */
+{
+ int bits_per_rgb = ccc->visual->bits_per_rgb;
+
+ pXColor->red &= MASK[bits_per_rgb];
+ pXColor->green &= MASK[bits_per_rgb];
+ pXColor->blue &= MASK[bits_per_rgb];
+}
+
diff --git a/libX11/src/xcms/XYZ.c b/libX11/src/xcms/XYZ.c index 40d6ed3bb..82215478b 100644 --- a/libX11/src/xcms/XYZ.c +++ b/libX11/src/xcms/XYZ.c @@ -1,203 +1,203 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * - * NAME - * CIEXYZ.c - * - * DESCRIPTION - * CIE XYZ Color Space - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <X11/Xos.h> -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - -#include <stdio.h> /* sscanf */ - -/* - * DEFINES - * Internal definitions that need NOT be exported to any package - * or program using this package. - */ -#ifdef DBL_EPSILON -# define XMY_DBL_EPSILON DBL_EPSILON -#else -# define XMY_DBL_EPSILON 0.00001 -#endif - -/* - * FORWARD DECLARATIONS - */ -static int CIEXYZ_ParseString(register char *spec, XcmsColor *pColor); - -/* - * LOCALS VARIABLES - */ - -static XcmsConversionProc Fl_CIEXYZ_to_CIEXYZ[] = { - NULL -}; - - - -/* - * GLOBALS - * Variables declared in this package that are allowed - * to be used globally. - */ - /* - * CIE XYZ Color Space - */ -XcmsColorSpace XcmsCIEXYZColorSpace = - { - _XcmsCIEXYZ_prefix, /* prefix */ - XcmsCIEXYZFormat, /* id */ - CIEXYZ_ParseString, /* parseString */ - Fl_CIEXYZ_to_CIEXYZ, /* to_CIEXYZ */ - Fl_CIEXYZ_to_CIEXYZ, /* from_CIEXYZ */ - 1 - }; - - -/************************************************************************ - * * - * PRIVATE ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * CIEXYZ_ParseString - * - * SYNOPSIS - */ -static int -CIEXYZ_ParseString( - register char *spec, - XcmsColor *pColor) -/* - * DESCRIPTION - * This routines takes a string and attempts to convert - * it into a XcmsColor structure with XcmsCIEXYZFormat. - * The assumed CIEXYZ string syntax is: - * CIEXYZ:<X>/<Y>/<Z> - * Where X, Y, and Z are in string input format for floats - * consisting of: - * a. an optional sign - * b. a string of numbers possibly containing a decimal point, - * c. an optional exponent field containing an 'E' or 'e' - * followed by a possibly signed integer string. - * - * RETURNS - */ -{ - int n; - char *pchar; - - if ((pchar = strchr(spec, ':')) == NULL) { - return(XcmsFailure); - } - n = (int)(pchar - spec); - - /* - * Check for proper prefix. - */ - if (strncmp(spec, _XcmsCIEXYZ_prefix, n) != 0) { - return(XcmsFailure); - } - - /* - * Attempt to parse the value portion. - */ - if (sscanf(spec + n + 1, "%lf/%lf/%lf", - &pColor->spec.CIEXYZ.X, - &pColor->spec.CIEXYZ.Y, - &pColor->spec.CIEXYZ.Z) != 3) { - char *s; /* Maybe failed due to locale */ - int f; - if ((s = strdup(spec))) { - for (f = 0; s[f]; ++f) - if (s[f] == '.') - s[f] = ','; - else if (s[f] == ',') - s[f] = '.'; - if (sscanf(s + n + 1, "%lf/%lf/%lf", - &pColor->spec.CIEXYZ.X, - &pColor->spec.CIEXYZ.Y, - &pColor->spec.CIEXYZ.Z) != 3) { - free(s); - return(XcmsFailure); - } - free(s); - } else - return(XcmsFailure); - } - pColor->format = XcmsCIEXYZFormat; - pColor->pixel = 0; - return(_XcmsCIEXYZ_ValidSpec(pColor)); -} - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIELab_ValidSpec - * - * SYNOPSIS - */ -Status -_XcmsCIEXYZ_ValidSpec( - XcmsColor *pColor) -/* - * DESCRIPTION - * Checks if color specification valid for CIE XYZ - * - * RETURNS - * XcmsFailure if invalid, - * XcmsSuccess if valid. - * - */ -{ - if (pColor->format != XcmsCIEXYZFormat - || - (pColor->spec.CIEXYZ.Y < 0.0 - XMY_DBL_EPSILON) - || - (pColor->spec.CIEXYZ.Y > 1.0 + XMY_DBL_EPSILON)) { - return(XcmsFailure); - } - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ *
+ * NAME
+ * CIEXYZ.c
+ *
+ * DESCRIPTION
+ * CIE XYZ Color Space
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xos.h>
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+#include <stdio.h> /* sscanf */
+
+/*
+ * DEFINES
+ * Internal definitions that need NOT be exported to any package
+ * or program using this package.
+ */
+#ifdef DBL_EPSILON
+# define XMY_DBL_EPSILON DBL_EPSILON
+#else
+# define XMY_DBL_EPSILON 0.00001
+#endif
+
+/*
+ * FORWARD DECLARATIONS
+ */
+static int CIEXYZ_ParseString(register char *spec, XcmsColor *pColor);
+
+/*
+ * LOCALS VARIABLES
+ */
+
+static XcmsConversionProc Fl_CIEXYZ_to_CIEXYZ[] = {
+ NULL
+};
+
+
+
+/*
+ * GLOBALS
+ * Variables declared in this package that are allowed
+ * to be used globally.
+ */
+ /*
+ * CIE XYZ Color Space
+ */
+XcmsColorSpace XcmsCIEXYZColorSpace =
+ {
+ _XcmsCIEXYZ_prefix, /* prefix */
+ XcmsCIEXYZFormat, /* id */
+ CIEXYZ_ParseString, /* parseString */
+ Fl_CIEXYZ_to_CIEXYZ, /* to_CIEXYZ */
+ Fl_CIEXYZ_to_CIEXYZ, /* from_CIEXYZ */
+ 1
+ };
+
+
+/************************************************************************
+ * *
+ * PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * CIEXYZ_ParseString
+ *
+ * SYNOPSIS
+ */
+static int
+CIEXYZ_ParseString(
+ register char *spec,
+ XcmsColor *pColor)
+/*
+ * DESCRIPTION
+ * This routines takes a string and attempts to convert
+ * it into a XcmsColor structure with XcmsCIEXYZFormat.
+ * The assumed CIEXYZ string syntax is:
+ * CIEXYZ:<X>/<Y>/<Z>
+ * Where X, Y, and Z are in string input format for floats
+ * consisting of:
+ * a. an optional sign
+ * b. a string of numbers possibly containing a decimal point,
+ * c. an optional exponent field containing an 'E' or 'e'
+ * followed by a possibly signed integer string.
+ *
+ * RETURNS
+ */
+{
+ int n;
+ char *pchar;
+
+ if ((pchar = strchr(spec, ':')) == NULL) {
+ return(XcmsFailure);
+ }
+ n = (int)(pchar - spec);
+
+ /*
+ * Check for proper prefix.
+ */
+ if (strncmp(spec, _XcmsCIEXYZ_prefix, n) != 0) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Attempt to parse the value portion.
+ */
+ if (sscanf(spec + n + 1, "%lf/%lf/%lf",
+ &pColor->spec.CIEXYZ.X,
+ &pColor->spec.CIEXYZ.Y,
+ &pColor->spec.CIEXYZ.Z) != 3) {
+ char *s; /* Maybe failed due to locale */
+ int f;
+ if ((s = strdup(spec))) {
+ for (f = 0; s[f]; ++f)
+ if (s[f] == '.')
+ s[f] = ',';
+ else if (s[f] == ',')
+ s[f] = '.';
+ if (sscanf(s + n + 1, "%lf/%lf/%lf",
+ &pColor->spec.CIEXYZ.X,
+ &pColor->spec.CIEXYZ.Y,
+ &pColor->spec.CIEXYZ.Z) != 3) {
+ free(s);
+ return(XcmsFailure);
+ }
+ free(s);
+ } else
+ return(XcmsFailure);
+ }
+ pColor->format = XcmsCIEXYZFormat;
+ pColor->pixel = 0;
+ return(_XcmsCIEXYZ_ValidSpec(pColor));
+}
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIELab_ValidSpec
+ *
+ * SYNOPSIS
+ */
+Status
+_XcmsCIEXYZ_ValidSpec(
+ XcmsColor *pColor)
+/*
+ * DESCRIPTION
+ * Checks if color specification valid for CIE XYZ
+ *
+ * RETURNS
+ * XcmsFailure if invalid,
+ * XcmsSuccess if valid.
+ *
+ */
+{
+ if (pColor->format != XcmsCIEXYZFormat
+ ||
+ (pColor->spec.CIEXYZ.Y < 0.0 - XMY_DBL_EPSILON)
+ ||
+ (pColor->spec.CIEXYZ.Y > 1.0 + XMY_DBL_EPSILON)) {
+ return(XcmsFailure);
+ }
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/Xcms.txt b/libX11/src/xcms/Xcms.txt index 1c5b1adec..bf302d17f 100644 --- a/libX11/src/xcms/Xcms.txt +++ b/libX11/src/xcms/Xcms.txt @@ -1,44 +1,44 @@ -/* - * (c) Copyright 1990 1991 Tektronix Inc. - * All Rights Reserved - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, - * provided that the above copyright notice appear in all copies and that - * both that copyright notice and this permission notice appear in - * supporting documentation, and that the name of Tektronix not be used - * in advertising or publicity pertaining to distribution of the software - * without specific, written prior permission. - * - * Tektronix disclaims all warranties with regard to this software, including - * all implied warranties of merchantability and fitness, in no event shall - * Tektronix be liable for any special, indirect or consequential damages or - * any damages whatsoever resulting from loss of use, data or profits, - * whether in an action of contract, negligence or other tortious action, - * arising out of or in connection with the use or performance of this - * software. - * - * - * NAME - * Xcms.txt - * - * DESCRIPTION - * Sample Color Name Database - * - */ - - -This device-independent color name database is provided just as an example. -There are no claims that these color specifications are or should be bound -to the corresponding color name. - -As you can see, the start of the database is indicated by "XCMS_COLORDB_START". -Anything before this is assumed to be comments. The "0.1" indicates the -version number of the format/syntax used in this file. The color name is -delimited from the color specification by one or more tabs. - -XCMS_COLORDB_START 0.1 -cms red CIEXYZ:0.3811/0.2073/0.0213 -cms green CIEXYZ:0.3203/0.6805/0.1430 -cms blue CIEXYZ:0.2483/0.1122/1.2417 -XCMS_COLORDB_END +/*
+ * (c) Copyright 1990 1991 Tektronix Inc.
+ * All Rights Reserved
+ *
+ * Permission to use, copy, modify, and distribute this software and its
+ * documentation for any purpose and without fee is hereby granted,
+ * provided that the above copyright notice appear in all copies and that
+ * both that copyright notice and this permission notice appear in
+ * supporting documentation, and that the name of Tektronix not be used
+ * in advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission.
+ *
+ * Tektronix disclaims all warranties with regard to this software, including
+ * all implied warranties of merchantability and fitness, in no event shall
+ * Tektronix be liable for any special, indirect or consequential damages or
+ * any damages whatsoever resulting from loss of use, data or profits,
+ * whether in an action of contract, negligence or other tortious action,
+ * arising out of or in connection with the use or performance of this
+ * software.
+ *
+ *
+ * NAME
+ * Xcms.txt
+ *
+ * DESCRIPTION
+ * Sample Color Name Database
+ *
+ */
+
+
+This device-independent color name database is provided just as an example.
+There are no claims that these color specifications are or should be bound
+to the corresponding color name.
+
+As you can see, the start of the database is indicated by "XCMS_COLORDB_START".
+Anything before this is assumed to be comments. The "0.1" indicates the
+version number of the format/syntax used in this file. The color name is
+delimited from the color specification by one or more tabs.
+
+XCMS_COLORDB_START 0.1
+cms red CIEXYZ:0.3811/0.2073/0.0213
+cms green CIEXYZ:0.3203/0.6805/0.1430
+cms blue CIEXYZ:0.2483/0.1122/1.2417
+XCMS_COLORDB_END
diff --git a/libX11/src/xcms/Xcmsint.h b/libX11/src/xcms/Xcmsint.h index 75d947184..a28a2ff60 100644 --- a/libX11/src/xcms/Xcmsint.h +++ b/libX11/src/xcms/Xcmsint.h @@ -1,260 +1,260 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * DESCRIPTION - * Private include file for Color Management System. - * (i.e., for API internal use only) - * - */ - -#ifndef _XCMSINT_H_ -#define _XCMSINT_H_ - -#include <X11/Xcms.h> - -/* - * DEFINES - */ - - /* - * Private Status Value - */ -#define _XCMS_NEWNAME -1 - - /* - * Color Space ID's are of XcmsColorFormat type. - * - * bit 31 - * 0 == Device-Independent - * 1 == Device-Dependent - * - * bit 30: - * 0 == Registered with X Consortium - * 1 == Unregistered - */ -#define XCMS_DD_ID(id) ((id) & (XcmsColorFormat)0x80000000) -#define XCMS_DI_ID(id) (!((id) & (XcmsColorFormat)0x80000000)) -#define XCMS_UNREG_ID(id) ((id) & (XcmsColorFormat)0x40000000) -#define XCMS_REG_ID(id) (!((id) & (XcmsColorFormat)0x40000000)) -#define XCMS_FIRST_REG_DI_ID (XcmsColorFormat)0x00000001 -#define XCMS_FIRST_UNREG_DI_ID (XcmsColorFormat)0x40000000 -#define XCMS_FIRST_REG_DD_ID (XcmsColorFormat)0x80000000 -#define XCMS_FIRST_UNREG_DD_ID (XcmsColorFormat)0xc0000000 - -/* - * TYPEDEFS - */ - - /* - * Structure for caching Colormap info. - * This is provided for the Xlib modifications to: - * XAllocNamedColor() - * XLookupColor() - * XParseColor() - * XStoreNamedColor() - */ -typedef struct _XcmsCmapRec { - Colormap cmapID; - Display *dpy; - Window windowID; - Visual *visual; - struct _XcmsCCC *ccc; - struct _XcmsCmapRec *pNext; -} XcmsCmapRec; - - /* - * Intensity Record (i.e., value / intensity tuple) - */ -typedef struct _IntensityRec { - unsigned short value; - XcmsFloat intensity; -} IntensityRec; - - /* - * Intensity Table - */ -typedef struct _IntensityTbl { - IntensityRec *pBase; - unsigned int nEntries; -} IntensityTbl; - - /* - * Structure for storing per-Visual Intensity Tables (aka gamma maps). - */ -typedef struct _XcmsIntensityMap { - VisualID visualID; - XPointer screenData; /* pointer to corresponding Screen Color*/ - /* Characterization Data */ - void (*pFreeScreenData)(XPointer pScreenDataTemp); /* Function that frees a Screen */ - /* structure. */ - struct _XcmsIntensityMap *pNext; -} XcmsIntensityMap; - - - /* - * Structure for storing "registered" color space prefix/ID - */ -typedef struct _XcmsRegColorSpaceEntry { - const char *prefix; /* Color Space prefix (e.g., "CIEXYZ:") */ - XcmsColorFormat id; /* Color Space ID (e.g., XcmsCIEXYZFormat) */ -} XcmsRegColorSpaceEntry; - - - /* - * Xcms Per Display (i.e. connection) related data - */ -typedef struct _XcmsPerDpyInfo { - - XcmsCCC paDefaultCCC; /* based on default visual of screen */ - /* - * Pointer to an array of XcmsCCC structures, one for - * each screen. - */ - XcmsCmapRec *pClientCmaps; /* Pointer to linked list of XcmsCmapRec's */ - -} XcmsPerDpyInfo, *XcmsPerDpyInfoPtr; - -/* - * DEFINES - */ - -#define XDCCC_NUMBER 0x8000000L /* 2**27 per XDCCC */ - -#ifdef GRAY -#define XDCCC_SCREENWHITEPT_ATOM_NAME "XDCCC_GRAY_SCREENWHITEPOINT" -#define XDCCC_GRAY_CORRECT_ATOM_NAME "XDCCC_GRAY_CORRECTION" -#endif /* GRAY */ - -#ifndef _ConversionValues -typedef struct _ConversionValues { - IntensityTbl IntensityTbl; -} ConversionValues; -#endif - -#ifdef GRAY -typedef struct { - IntensityTbl *IntensityTbl; -} GRAY_SCCData; -#endif /* GRAY */ - -/* - * DEFINES - */ - -#define XDCCC_MATRIX_ATOM_NAME "XDCCC_LINEAR_RGB_MATRICES" -#define XDCCC_CORRECT_ATOM_NAME "XDCCC_LINEAR_RGB_CORRECTION" - -typedef struct { - XcmsFloat XYZtoRGBmatrix[3][3]; - XcmsFloat RGBtoXYZmatrix[3][3]; - IntensityTbl *pRedTbl; - IntensityTbl *pGreenTbl; - IntensityTbl *pBlueTbl; -} LINEAR_RGB_SCCData; - -/* function prototypes */ -extern XcmsCmapRec * -_XcmsAddCmapRec( - Display *dpy, - Colormap cmap, - Window windowID, - Visual *visual); -extern void -_XcmsRGB_to_XColor( - XcmsColor *pColors, - XColor *pXColors, - unsigned int nColors); -extern Status -_XcmsResolveColorString ( - XcmsCCC ccc, - const char **color_string, - XcmsColor *pColor_exact_return, - XcmsColorFormat result_format); -extern void -_XUnresolveColor( - XcmsCCC ccc, - XColor *pXColor); -/* - * DESCRIPTION - * Include file for defining the math macros used in the - * XCMS source. Instead of using math library routines - * directly, XCMS uses macros so that based on the - * definitions here, vendors and sites can specify exactly - * what routine will be called (those from libm.a or their - * custom routines). If not defined to math library routines - * (e.g., sqrt in libm.a), then the client is not forced to - * be linked with -lm. - */ - -#define XCMS_ATAN(x) _XcmsArcTangent(x) -#define XCMS_COS(x) _XcmsCosine(x) -#define XCMS_CUBEROOT(x) _XcmsCubeRoot(x) -#define XCMS_FABS(x) ((x) < 0.0 ? -(x) : (x)) -#define XCMS_SIN(x) _XcmsSine(x) -#define XCMS_SQRT(x) _XcmsSquareRoot(x) -#define XCMS_TAN(x) (XCMS_SIN(x) / XCMS_COS(x)) - -double _XcmsArcTangent(double a); -double _XcmsCosine(double a); -double _XcmsCubeRoot(double a); -double _XcmsSine(double a); -double _XcmsSquareRoot(double a); - -/* - * DEFINES FOR GAMUT COMPRESSION AND QUERY ROUTINES - */ -#ifndef PI -# ifdef M_PI -# define PI M_PI -# else -# define PI 3.14159265358979323846264338327950 -# endif /* M_PI */ -#endif /* PI */ -#ifndef degrees -# define degrees(r) ((XcmsFloat)(r) * 180.0 / PI) -#endif /* degrees */ -#ifndef radians -# define radians(d) ((XcmsFloat)(d) * PI / 180.0) -#endif /* radians */ - -#define XCMS_CIEUSTAROFHUE(h,c) \ -((XCMS_COS((h)) == 0.0) ? (XcmsFloat)0.0 : (XcmsFloat) \ -((XcmsFloat)(c) / (XcmsFloat)XCMS_SQRT((XCMS_TAN(h) * XCMS_TAN(h)) + \ -(XcmsFloat)1.0))) -#define XCMS_CIEVSTAROFHUE(h,c) \ -((XCMS_COS((h)) == 0.0) ? (XcmsFloat)0.0 : (XcmsFloat) \ -((XcmsFloat)(c) / (XcmsFloat)XCMS_SQRT(((XcmsFloat)1.0 / \ -(XcmsFloat)(XCMS_TAN(h) * XCMS_TAN(h))) + (XcmsFloat)1.0))) -/* this hue is returned in radians */ -#define XCMS_CIELUV_PMETRIC_HUE(u,v) \ -(((u) != 0.0) ? XCMS_ATAN( (v) / (u)) : ((v >= 0.0) ? PI / 2 : -(PI / 2))) -#define XCMS_CIELUV_PMETRIC_CHROMA(u,v) XCMS_SQRT(((u)*(u)) + ((v)*(v))) - -#define XCMS_CIEASTAROFHUE(h,c) XCMS_CIEUSTAROFHUE((h), (c)) -#define XCMS_CIEBSTAROFHUE(h,c) XCMS_CIEVSTAROFHUE((h), (c)) -#define XCMS_CIELAB_PMETRIC_HUE(a,b) XCMS_CIELUV_PMETRIC_HUE((a), (b)) -#define XCMS_CIELAB_PMETRIC_CHROMA(a,b) XCMS_CIELUV_PMETRIC_CHROMA((a), (b)) - -#endif /* _XCMSINT_H_ */ +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * DESCRIPTION
+ * Private include file for Color Management System.
+ * (i.e., for API internal use only)
+ *
+ */
+
+#ifndef _XCMSINT_H_
+#define _XCMSINT_H_
+
+#include <X11/Xcms.h>
+
+/*
+ * DEFINES
+ */
+
+ /*
+ * Private Status Value
+ */
+#define _XCMS_NEWNAME -1
+
+ /*
+ * Color Space ID's are of XcmsColorFormat type.
+ *
+ * bit 31
+ * 0 == Device-Independent
+ * 1 == Device-Dependent
+ *
+ * bit 30:
+ * 0 == Registered with X Consortium
+ * 1 == Unregistered
+ */
+#define XCMS_DD_ID(id) ((id) & (XcmsColorFormat)0x80000000)
+#define XCMS_DI_ID(id) (!((id) & (XcmsColorFormat)0x80000000))
+#define XCMS_UNREG_ID(id) ((id) & (XcmsColorFormat)0x40000000)
+#define XCMS_REG_ID(id) (!((id) & (XcmsColorFormat)0x40000000))
+#define XCMS_FIRST_REG_DI_ID (XcmsColorFormat)0x00000001
+#define XCMS_FIRST_UNREG_DI_ID (XcmsColorFormat)0x40000000
+#define XCMS_FIRST_REG_DD_ID (XcmsColorFormat)0x80000000
+#define XCMS_FIRST_UNREG_DD_ID (XcmsColorFormat)0xc0000000
+
+/*
+ * TYPEDEFS
+ */
+
+ /*
+ * Structure for caching Colormap info.
+ * This is provided for the Xlib modifications to:
+ * XAllocNamedColor()
+ * XLookupColor()
+ * XParseColor()
+ * XStoreNamedColor()
+ */
+typedef struct _XcmsCmapRec {
+ Colormap cmapID;
+ Display *dpy;
+ Window windowID;
+ Visual *visual;
+ struct _XcmsCCC *ccc;
+ struct _XcmsCmapRec *pNext;
+} XcmsCmapRec;
+
+ /*
+ * Intensity Record (i.e., value / intensity tuple)
+ */
+typedef struct _IntensityRec {
+ unsigned short value;
+ XcmsFloat intensity;
+} IntensityRec;
+
+ /*
+ * Intensity Table
+ */
+typedef struct _IntensityTbl {
+ IntensityRec *pBase;
+ unsigned int nEntries;
+} IntensityTbl;
+
+ /*
+ * Structure for storing per-Visual Intensity Tables (aka gamma maps).
+ */
+typedef struct _XcmsIntensityMap {
+ VisualID visualID;
+ XPointer screenData; /* pointer to corresponding Screen Color*/
+ /* Characterization Data */
+ void (*pFreeScreenData)(XPointer pScreenDataTemp); /* Function that frees a Screen */
+ /* structure. */
+ struct _XcmsIntensityMap *pNext;
+} XcmsIntensityMap;
+
+
+ /*
+ * Structure for storing "registered" color space prefix/ID
+ */
+typedef struct _XcmsRegColorSpaceEntry {
+ const char *prefix; /* Color Space prefix (e.g., "CIEXYZ:") */
+ XcmsColorFormat id; /* Color Space ID (e.g., XcmsCIEXYZFormat) */
+} XcmsRegColorSpaceEntry;
+
+
+ /*
+ * Xcms Per Display (i.e. connection) related data
+ */
+typedef struct _XcmsPerDpyInfo {
+
+ XcmsCCC paDefaultCCC; /* based on default visual of screen */
+ /*
+ * Pointer to an array of XcmsCCC structures, one for
+ * each screen.
+ */
+ XcmsCmapRec *pClientCmaps; /* Pointer to linked list of XcmsCmapRec's */
+
+} XcmsPerDpyInfo, *XcmsPerDpyInfoPtr;
+
+/*
+ * DEFINES
+ */
+
+#define XDCCC_NUMBER 0x8000000L /* 2**27 per XDCCC */
+
+#ifdef GRAY
+#define XDCCC_SCREENWHITEPT_ATOM_NAME "XDCCC_GRAY_SCREENWHITEPOINT"
+#define XDCCC_GRAY_CORRECT_ATOM_NAME "XDCCC_GRAY_CORRECTION"
+#endif /* GRAY */
+
+#ifndef _ConversionValues
+typedef struct _ConversionValues {
+ IntensityTbl IntensityTbl;
+} ConversionValues;
+#endif
+
+#ifdef GRAY
+typedef struct {
+ IntensityTbl *IntensityTbl;
+} GRAY_SCCData;
+#endif /* GRAY */
+
+/*
+ * DEFINES
+ */
+
+#define XDCCC_MATRIX_ATOM_NAME "XDCCC_LINEAR_RGB_MATRICES"
+#define XDCCC_CORRECT_ATOM_NAME "XDCCC_LINEAR_RGB_CORRECTION"
+
+typedef struct {
+ XcmsFloat XYZtoRGBmatrix[3][3];
+ XcmsFloat RGBtoXYZmatrix[3][3];
+ IntensityTbl *pRedTbl;
+ IntensityTbl *pGreenTbl;
+ IntensityTbl *pBlueTbl;
+} LINEAR_RGB_SCCData;
+
+/* function prototypes */
+extern XcmsCmapRec *
+_XcmsAddCmapRec(
+ Display *dpy,
+ Colormap cmap,
+ Window windowID,
+ Visual *visual);
+extern void
+_XcmsRGB_to_XColor(
+ XcmsColor *pColors,
+ XColor *pXColors,
+ unsigned int nColors);
+extern Status
+_XcmsResolveColorString (
+ XcmsCCC ccc,
+ const char **color_string,
+ XcmsColor *pColor_exact_return,
+ XcmsColorFormat result_format);
+extern void
+_XUnresolveColor(
+ XcmsCCC ccc,
+ XColor *pXColor);
+/*
+ * DESCRIPTION
+ * Include file for defining the math macros used in the
+ * XCMS source. Instead of using math library routines
+ * directly, XCMS uses macros so that based on the
+ * definitions here, vendors and sites can specify exactly
+ * what routine will be called (those from libm.a or their
+ * custom routines). If not defined to math library routines
+ * (e.g., sqrt in libm.a), then the client is not forced to
+ * be linked with -lm.
+ */
+
+#define XCMS_ATAN(x) _XcmsArcTangent(x)
+#define XCMS_COS(x) _XcmsCosine(x)
+#define XCMS_CUBEROOT(x) _XcmsCubeRoot(x)
+#define XCMS_FABS(x) ((x) < 0.0 ? -(x) : (x))
+#define XCMS_SIN(x) _XcmsSine(x)
+#define XCMS_SQRT(x) _XcmsSquareRoot(x)
+#define XCMS_TAN(x) (XCMS_SIN(x) / XCMS_COS(x))
+
+double _XcmsArcTangent(double a);
+double _XcmsCosine(double a);
+double _XcmsCubeRoot(double a);
+double _XcmsSine(double a);
+double _XcmsSquareRoot(double a);
+
+/*
+ * DEFINES FOR GAMUT COMPRESSION AND QUERY ROUTINES
+ */
+#ifndef PI
+# ifdef M_PI
+# define PI M_PI
+# else
+# define PI 3.14159265358979323846264338327950
+# endif /* M_PI */
+#endif /* PI */
+#ifndef degrees
+# define degrees(r) ((XcmsFloat)(r) * 180.0 / PI)
+#endif /* degrees */
+#ifndef radians
+# define radians(d) ((XcmsFloat)(d) * PI / 180.0)
+#endif /* radians */
+
+#define XCMS_CIEUSTAROFHUE(h,c) \
+((XCMS_COS((h)) == 0.0) ? (XcmsFloat)0.0 : (XcmsFloat) \
+((XcmsFloat)(c) / (XcmsFloat)XCMS_SQRT((XCMS_TAN(h) * XCMS_TAN(h)) + \
+(XcmsFloat)1.0)))
+#define XCMS_CIEVSTAROFHUE(h,c) \
+((XCMS_COS((h)) == 0.0) ? (XcmsFloat)0.0 : (XcmsFloat) \
+((XcmsFloat)(c) / (XcmsFloat)XCMS_SQRT(((XcmsFloat)1.0 / \
+(XcmsFloat)(XCMS_TAN(h) * XCMS_TAN(h))) + (XcmsFloat)1.0)))
+/* this hue is returned in radians */
+#define XCMS_CIELUV_PMETRIC_HUE(u,v) \
+(((u) != 0.0) ? XCMS_ATAN( (v) / (u)) : ((v >= 0.0) ? PI / 2 : -(PI / 2)))
+#define XCMS_CIELUV_PMETRIC_CHROMA(u,v) XCMS_SQRT(((u)*(u)) + ((v)*(v)))
+
+#define XCMS_CIEASTAROFHUE(h,c) XCMS_CIEUSTAROFHUE((h), (c))
+#define XCMS_CIEBSTAROFHUE(h,c) XCMS_CIEVSTAROFHUE((h), (c))
+#define XCMS_CIELAB_PMETRIC_HUE(a,b) XCMS_CIELUV_PMETRIC_HUE((a), (b))
+#define XCMS_CIELAB_PMETRIC_CHROMA(a,b) XCMS_CIELUV_PMETRIC_CHROMA((a), (b))
+
+#endif /* _XCMSINT_H_ */
diff --git a/libX11/src/xcms/cmsAllCol.c b/libX11/src/xcms/cmsAllCol.c index aeea46461..1ada07c1b 100644 --- a/libX11/src/xcms/cmsAllCol.c +++ b/libX11/src/xcms/cmsAllCol.c @@ -1,74 +1,74 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsAllCol.c - * - * DESCRIPTION - * Source for XcmsAllocColor - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - - -/* - * NAME - * XcmsAllocColor - Allocate Color - * - * SYNOPSIS - */ -Status -XcmsAllocColor( - Display *dpy, - Colormap colormap, - XcmsColor *pXcmsColor_in_out, - XcmsColorFormat result_format) -/* - * DESCRIPTION - * Given a device-dependent or device-independent color - * specification, XcmsAllocColor will convert it to X RGB - * values then use it in a call to XAllocColor. - * - * RETURNS - * XcmsFailure if failed; - * XcmsSuccess if it succeeded without gamut compression; - * XcmsSuccessWithCompression if it succeeded with gamut - * compression; - * - * Also returns the pixel value of the color cell and a color - * specification of the color actually stored. - * - */ -{ - return(_XcmsSetGetColor(XAllocColor, dpy, colormap, pXcmsColor_in_out, - result_format, (Bool *)NULL)); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsAllCol.c
+ *
+ * DESCRIPTION
+ * Source for XcmsAllocColor
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+
+/*
+ * NAME
+ * XcmsAllocColor - Allocate Color
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsAllocColor(
+ Display *dpy,
+ Colormap colormap,
+ XcmsColor *pXcmsColor_in_out,
+ XcmsColorFormat result_format)
+/*
+ * DESCRIPTION
+ * Given a device-dependent or device-independent color
+ * specification, XcmsAllocColor will convert it to X RGB
+ * values then use it in a call to XAllocColor.
+ *
+ * RETURNS
+ * XcmsFailure if failed;
+ * XcmsSuccess if it succeeded without gamut compression;
+ * XcmsSuccessWithCompression if it succeeded with gamut
+ * compression;
+ *
+ * Also returns the pixel value of the color cell and a color
+ * specification of the color actually stored.
+ *
+ */
+{
+ return(_XcmsSetGetColor(XAllocColor, dpy, colormap, pXcmsColor_in_out,
+ result_format, (Bool *)NULL));
+}
diff --git a/libX11/src/xcms/cmsGlobls.c b/libX11/src/xcms/cmsGlobls.c index c9e82f242..13f351841 100644 --- a/libX11/src/xcms/cmsGlobls.c +++ b/libX11/src/xcms/cmsGlobls.c @@ -1,126 +1,126 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * XcmsGlobls.c - * - * DESCRIPTION - * Source file containing Xcms globals - * - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - -/* - * GLOBALS - * Variables declared in this package that are allowed - * to be used globally. - */ - - /* - * Initial array of Device Independent Color Spaces - */ -XcmsColorSpace *_XcmsDIColorSpacesInit[] = { - &XcmsCIEXYZColorSpace, - &XcmsCIEuvYColorSpace, - &XcmsCIExyYColorSpace, - &XcmsCIELabColorSpace, - &XcmsCIELuvColorSpace, - &XcmsTekHVCColorSpace, - &XcmsUNDEFINEDColorSpace, - NULL -}; - /* - * Pointer to the array of pointers to XcmsColorSpace structures for - * Device-Independent Color Spaces that are currently accessible by - * the color management system. End of list is indicated by a NULL pointer. - */ -XcmsColorSpace **_XcmsDIColorSpaces = _XcmsDIColorSpacesInit; - - /* - * Initial array of Device Dependent Color Spaces - */ -XcmsColorSpace *_XcmsDDColorSpacesInit[] = { - &XcmsRGBColorSpace, - &XcmsRGBiColorSpace, - NULL -}; - /* - * Pointer to the array of pointers to XcmsColorSpace structures for - * Device-Dependent Color Spaces that are currently accessible by - * the color management system. End of list is indicated by a NULL pointer. - */ -XcmsColorSpace **_XcmsDDColorSpaces = &_XcmsDDColorSpacesInit[0]; - - /* - * Initial array of Screen Color Characterization Function Sets - */ -XcmsFunctionSet *_XcmsSCCFuncSetsInit[] = { - &XcmsLinearRGBFunctionSet, -#ifdef GRAY - &XcmsGrayFunctionSet, -#endif /* GRAY */ - NULL}; - /* - * Pointer to the array of pointers to XcmsSCCFuncSet structures - * (Screen Color Characterization Function Sets) that are currently - * accessible by the color management system. End of list is - * indicated by a NULL pointer. - */ -XcmsFunctionSet **_XcmsSCCFuncSets = _XcmsSCCFuncSetsInit; - - /* - * X Consortium Registered Device-Independent Color Spaces - * Note that prefix must be in lowercase. - */ -const char _XcmsCIEXYZ_prefix[] = "ciexyz"; -const char _XcmsCIEuvY_prefix[] = "cieuvy"; -const char _XcmsCIExyY_prefix[] = "ciexyy"; -const char _XcmsCIELab_prefix[] = "cielab"; -const char _XcmsCIELuv_prefix[] = "cieluv"; -const char _XcmsTekHVC_prefix[] = "tekhvc"; - /* - * Registered Device-Dependent Color Spaces - */ -const char _XcmsRGBi_prefix[] = "rgbi"; -const char _XcmsRGB_prefix[] = "rgb"; - -XcmsRegColorSpaceEntry _XcmsRegColorSpaces[] = { - { _XcmsCIEXYZ_prefix, XcmsCIEXYZFormat }, - { _XcmsCIEuvY_prefix, XcmsCIEuvYFormat }, - { _XcmsCIExyY_prefix, XcmsCIExyYFormat }, - { _XcmsCIELab_prefix, XcmsCIELabFormat }, - { _XcmsCIELuv_prefix, XcmsCIELuvFormat }, - { _XcmsTekHVC_prefix, XcmsTekHVCFormat }, - { _XcmsRGB_prefix, XcmsRGBFormat }, - { _XcmsRGBi_prefix, XcmsRGBiFormat }, - { NULL, 0 } -}; +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * XcmsGlobls.c
+ *
+ * DESCRIPTION
+ * Source file containing Xcms globals
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+/*
+ * GLOBALS
+ * Variables declared in this package that are allowed
+ * to be used globally.
+ */
+
+ /*
+ * Initial array of Device Independent Color Spaces
+ */
+XcmsColorSpace *_XcmsDIColorSpacesInit[] = {
+ &XcmsCIEXYZColorSpace,
+ &XcmsCIEuvYColorSpace,
+ &XcmsCIExyYColorSpace,
+ &XcmsCIELabColorSpace,
+ &XcmsCIELuvColorSpace,
+ &XcmsTekHVCColorSpace,
+ &XcmsUNDEFINEDColorSpace,
+ NULL
+};
+ /*
+ * Pointer to the array of pointers to XcmsColorSpace structures for
+ * Device-Independent Color Spaces that are currently accessible by
+ * the color management system. End of list is indicated by a NULL pointer.
+ */
+XcmsColorSpace **_XcmsDIColorSpaces = _XcmsDIColorSpacesInit;
+
+ /*
+ * Initial array of Device Dependent Color Spaces
+ */
+XcmsColorSpace *_XcmsDDColorSpacesInit[] = {
+ &XcmsRGBColorSpace,
+ &XcmsRGBiColorSpace,
+ NULL
+};
+ /*
+ * Pointer to the array of pointers to XcmsColorSpace structures for
+ * Device-Dependent Color Spaces that are currently accessible by
+ * the color management system. End of list is indicated by a NULL pointer.
+ */
+XcmsColorSpace **_XcmsDDColorSpaces = &_XcmsDDColorSpacesInit[0];
+
+ /*
+ * Initial array of Screen Color Characterization Function Sets
+ */
+XcmsFunctionSet *_XcmsSCCFuncSetsInit[] = {
+ &XcmsLinearRGBFunctionSet,
+#ifdef GRAY
+ &XcmsGrayFunctionSet,
+#endif /* GRAY */
+ NULL};
+ /*
+ * Pointer to the array of pointers to XcmsSCCFuncSet structures
+ * (Screen Color Characterization Function Sets) that are currently
+ * accessible by the color management system. End of list is
+ * indicated by a NULL pointer.
+ */
+XcmsFunctionSet **_XcmsSCCFuncSets = _XcmsSCCFuncSetsInit;
+
+ /*
+ * X Consortium Registered Device-Independent Color Spaces
+ * Note that prefix must be in lowercase.
+ */
+const char _XcmsCIEXYZ_prefix[] = "ciexyz";
+const char _XcmsCIEuvY_prefix[] = "cieuvy";
+const char _XcmsCIExyY_prefix[] = "ciexyy";
+const char _XcmsCIELab_prefix[] = "cielab";
+const char _XcmsCIELuv_prefix[] = "cieluv";
+const char _XcmsTekHVC_prefix[] = "tekhvc";
+ /*
+ * Registered Device-Dependent Color Spaces
+ */
+const char _XcmsRGBi_prefix[] = "rgbi";
+const char _XcmsRGB_prefix[] = "rgb";
+
+XcmsRegColorSpaceEntry _XcmsRegColorSpaces[] = {
+ { _XcmsCIEXYZ_prefix, XcmsCIEXYZFormat },
+ { _XcmsCIEuvY_prefix, XcmsCIEuvYFormat },
+ { _XcmsCIExyY_prefix, XcmsCIExyYFormat },
+ { _XcmsCIELab_prefix, XcmsCIELabFormat },
+ { _XcmsCIELuv_prefix, XcmsCIELuvFormat },
+ { _XcmsTekHVC_prefix, XcmsTekHVCFormat },
+ { _XcmsRGB_prefix, XcmsRGBFormat },
+ { _XcmsRGBi_prefix, XcmsRGBiFormat },
+ { NULL, 0 }
+};
diff --git a/libX11/src/xcms/cmsMath.c b/libX11/src/xcms/cmsMath.c index 70b067587..009a623b4 100644 --- a/libX11/src/xcms/cmsMath.c +++ b/libX11/src/xcms/cmsMath.c @@ -1,136 +1,136 @@ - -/* - -Copyright 1990, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - -*/ - -/* - * Stephen Gildea, MIT X Consortium, January 1991 - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xlibint.h" -#include "Xcmsint.h" - -#include <float.h> -#ifndef DBL_EPSILON -#define DBL_EPSILON 1e-6 -#endif - -#ifdef _X_ROOT_STATS -int cbrt_loopcount; -int sqrt_loopcount; -#endif - -/* Newton's Method: x_n+1 = x_n - ( f(x_n) / f'(x_n) ) */ - - -/* for cube roots, x^3 - a = 0, x_new = x - 1/3 (x - a/x^2) */ - -double -_XcmsCubeRoot(double a) -{ - register double abs_a, cur_guess, delta; - -#ifdef DEBUG - printf("_XcmsCubeRoot passed in %g\n", a); -#endif -#ifdef _X_ROOT_STATS - cbrt_loopcount = 0; -#endif - if (a == 0.) - return 0.; - - abs_a = a<0. ? -a : a; /* convert to positive to speed loop tests */ - - /* arbitrary first guess */ - if (abs_a > 1.) - cur_guess = abs_a/8.; - else - cur_guess = abs_a*8.; - - do { -#ifdef _X_ROOT_STATS - cbrt_loopcount++; -#endif - delta = (cur_guess - abs_a/(cur_guess*cur_guess))/3.; - cur_guess -= delta; - if (delta < 0.) delta = -delta; - } while (delta >= cur_guess*DBL_EPSILON); - - if (a < 0.) - cur_guess = -cur_guess; - -#ifdef DEBUG - printf("_XcmsCubeRoot returning %g\n", cur_guess); -#endif - return cur_guess; -} - - - -/* for square roots, x^2 - a = 0, x_new = x - 1/2 (x - a/x) */ - -double -_XcmsSquareRoot(double a) -{ - register double cur_guess, delta; - -#ifdef DEBUG - printf("_XcmsSquareRoot passed in %g\n", a); -#endif -#ifdef _X_ROOT_STATS - sqrt_loopcount = 0; -#endif - if (a == 0.) - return 0.; - - if (a < 0.) { - /* errno = EDOM; */ - return 0.; - } - - /* arbitrary first guess */ - if (a > 1.) - cur_guess = a/4.; - else - cur_guess = a*4.; - - do { -#ifdef _X_ROOT_STATS - sqrt_loopcount++; -#endif - delta = (cur_guess - a/cur_guess)/2.; - cur_guess -= delta; - if (delta < 0.) delta = -delta; - } while (delta >= cur_guess*DBL_EPSILON); - -#ifdef DEBUG - printf("_XcmsSquareRoot returning %g\n", cur_guess); -#endif - return cur_guess; -} - +
+/*
+
+Copyright 1990, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+/*
+ * Stephen Gildea, MIT X Consortium, January 1991
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xlibint.h"
+#include "Xcmsint.h"
+
+#include <float.h>
+#ifndef DBL_EPSILON
+#define DBL_EPSILON 1e-6
+#endif
+
+#ifdef _X_ROOT_STATS
+int cbrt_loopcount;
+int sqrt_loopcount;
+#endif
+
+/* Newton's Method: x_n+1 = x_n - ( f(x_n) / f'(x_n) ) */
+
+
+/* for cube roots, x^3 - a = 0, x_new = x - 1/3 (x - a/x^2) */
+
+double
+_XcmsCubeRoot(double a)
+{
+ register double abs_a, cur_guess, delta;
+
+#ifdef DEBUG
+ printf("_XcmsCubeRoot passed in %g\n", a);
+#endif
+#ifdef _X_ROOT_STATS
+ cbrt_loopcount = 0;
+#endif
+ if (a == 0.)
+ return 0.;
+
+ abs_a = a<0. ? -a : a; /* convert to positive to speed loop tests */
+
+ /* arbitrary first guess */
+ if (abs_a > 1.)
+ cur_guess = abs_a/8.;
+ else
+ cur_guess = abs_a*8.;
+
+ do {
+#ifdef _X_ROOT_STATS
+ cbrt_loopcount++;
+#endif
+ delta = (cur_guess - abs_a/(cur_guess*cur_guess))/3.;
+ cur_guess -= delta;
+ if (delta < 0.) delta = -delta;
+ } while (delta >= cur_guess*DBL_EPSILON);
+
+ if (a < 0.)
+ cur_guess = -cur_guess;
+
+#ifdef DEBUG
+ printf("_XcmsCubeRoot returning %g\n", cur_guess);
+#endif
+ return cur_guess;
+}
+
+
+
+/* for square roots, x^2 - a = 0, x_new = x - 1/2 (x - a/x) */
+
+double
+_XcmsSquareRoot(double a)
+{
+ register double cur_guess, delta;
+
+#ifdef DEBUG
+ printf("_XcmsSquareRoot passed in %g\n", a);
+#endif
+#ifdef _X_ROOT_STATS
+ sqrt_loopcount = 0;
+#endif
+ if (a == 0.)
+ return 0.;
+
+ if (a < 0.) {
+ /* errno = EDOM; */
+ return 0.;
+ }
+
+ /* arbitrary first guess */
+ if (a > 1.)
+ cur_guess = a/4.;
+ else
+ cur_guess = a*4.;
+
+ do {
+#ifdef _X_ROOT_STATS
+ sqrt_loopcount++;
+#endif
+ delta = (cur_guess - a/cur_guess)/2.;
+ cur_guess -= delta;
+ if (delta < 0.) delta = -delta;
+ } while (delta >= cur_guess*DBL_EPSILON);
+
+#ifdef DEBUG
+ printf("_XcmsSquareRoot returning %g\n", cur_guess);
+#endif
+ return cur_guess;
+}
+
diff --git a/libX11/src/xcms/cmsTrig.c b/libX11/src/xcms/cmsTrig.c index 5a01a56c8..26ae05f75 100644 --- a/libX11/src/xcms/cmsTrig.c +++ b/libX11/src/xcms/cmsTrig.c @@ -1,593 +1,593 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * It should be pointed out that for simplicity's sake, the - * environment parameters are defined as floating point constants, - * rather than octal or hexadecimal initializations of allocated - * storage areas. This means that the range of allowed numbers - * may not exactly match the hardware's capabilities. For example, - * if the maximum positive double precision floating point number - * is EXACTLY 1.11...E100 and the constant "MAXDOUBLE is - * defined to be 1.11E100 then the numbers between 1.11E100 and - * 1.11...E100 are considered to be undefined. For most - * applications, this will cause no problems. - * - * An alternate method is to allocate a global static "double" variable, - * say "maxdouble", and use a union declaration and initialization - * to initialize it with the proper bits for the EXACT maximum value. - * This was not done because the only compilers available to the - * author did not fully support union initialization features. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include "Xcmsint.h" - -/* forward/static */ -static double _XcmsModulo(double value, double base); -static double _XcmsPolynomial( - register int order, - double const *coeffs, - double x); -static double -_XcmsModuloF( - double val, - register double *dp); - -/* - * DEFINES - */ -#define XCMS_MAXERROR 0.000001 -#define XCMS_MAXITER 10000 -#define XCMS_PI 3.14159265358979323846264338327950 -#define XCMS_TWOPI 6.28318530717958620 -#define XCMS_HALFPI 1.57079632679489660 -#define XCMS_FOURTHPI 0.785398163397448280 -#define XCMS_SIXTHPI 0.523598775598298820 -#define XCMS_RADIANS(d) ((d) * XCMS_PI / 180.0) -#define XCMS_DEGREES(r) ((r) * 180.0 / XCMS_PI) -#define XCMS_X6_UNDERFLOWS (4.209340e-52) /* X**6 almost underflows */ -#define XCMS_X16_UNDERFLOWS (5.421010e-20) /* X**16 almost underflows*/ -#define XCMS_CHAR_BIT 8 -#define XCMS_LONG_MAX 0x7FFFFFFF -#define XCMS_DEXPLEN 11 -#define XCMS_NBITS(type) (XCMS_CHAR_BIT * (int)sizeof(type)) -#define XCMS_FABS(x) ((x) < 0.0 ? -(x) : (x)) - -/* XCMS_DMAXPOWTWO - largest power of two exactly representable as a double */ -#ifdef _CRAY -#define XCMS_DMAXPOWTWO ((double)(1 < 47)) -#else -#define XCMS_DMAXPOWTWO ((double)(XCMS_LONG_MAX) * \ - (1L << ((XCMS_NBITS(double)-XCMS_DEXPLEN) - XCMS_NBITS(int) + 1))) -#endif - -/* - * LOCAL VARIABLES - */ - -static double const cos_pcoeffs[] = { - 0.12905394659037374438e7, - -0.37456703915723204710e6, - 0.13432300986539084285e5, - -0.11231450823340933092e3 -}; - -static double const cos_qcoeffs[] = { - 0.12905394659037373590e7, - 0.23467773107245835052e5, - 0.20969518196726306286e3, - 1.0 -}; - -static double const sin_pcoeffs[] = { - 0.20664343336995858240e7, - -0.18160398797407332550e6, - 0.35999306949636188317e4, - -0.20107483294588615719e2 -}; - -static double const sin_qcoeffs[] = { - 0.26310659102647698963e7, - 0.39270242774649000308e5, - 0.27811919481083844087e3, - 1.0 -}; - -/* - * - * FUNCTION - * - * _XcmsCosine double precision cosine - * - * KEY WORDS - * - * cos - * machine independent routines - * trigonometric functions - * math libraries - * - * DESCRIPTION - * - * Returns double precision cosine of double precision - * floating point argument. - * - * USAGE - * - * double _XcmsCosine (x) - * double x; - * - * REFERENCES - * - * Computer Approximations, J.F. Hart et al, John Wiley & Sons, - * 1968, pp. 112-120. - * - * RESTRICTIONS - * - * The sin and cos routines are interactive in the sense that - * in the process of reducing the argument to the range -PI/4 - * to PI/4, each may call the other. Ultimately one or the - * other uses a polynomial approximation on the reduced - * argument. The sin approximation has a maximum relative error - * of 10**(-17.59) and the cos approximation has a maximum - * relative error of 10**(-16.18). - * - * These error bounds assume exact arithmetic - * in the polynomial evaluation. Additional rounding and - * truncation errors may occur as the argument is reduced - * to the range over which the polynomial approximation - * is valid, and as the polynomial is evaluated using - * finite-precision arithmetic. - * - * PROGRAMMER - * - * Fred Fish - * - * INTERNALS - * - * Computes cos(x) from: - * - * (1) Reduce argument x to range -PI to PI. - * - * (2) If x > PI/2 then call cos recursively - * using relation cos(x) = -cos(x - PI). - * - * (3) If x < -PI/2 then call cos recursively - * using relation cos(x) = -cos(x + PI). - * - * (4) If x > PI/4 then call sin using - * relation cos(x) = sin(PI/2 - x). - * - * (5) If x < -PI/4 then call cos using - * relation cos(x) = sin(PI/2 + x). - * - * (6) If x would cause underflow in approx - * evaluation arithmetic then return - * sqrt(1.0 - x**2). - * - * (7) By now x has been reduced to range - * -PI/4 to PI/4 and the approximation - * from HART pg. 119 can be used: - * - * cos(x) = ( p(y) / q(y) ) - * Where: - * - * y = x * (4/PI) - * - * p(y) = SUM [ Pj * (y**(2*j)) ] - * over j = {0,1,2,3} - * - * q(y) = SUM [ Qj * (y**(2*j)) ] - * over j = {0,1,2,3} - * - * P0 = 0.12905394659037374438571854e+7 - * P1 = -0.3745670391572320471032359e+6 - * P2 = 0.134323009865390842853673e+5 - * P3 = -0.112314508233409330923e+3 - * Q0 = 0.12905394659037373590295914e+7 - * Q1 = 0.234677731072458350524124e+5 - * Q2 = 0.2096951819672630628621e+3 - * Q3 = 1.0000... - * (coefficients from HART table #3843 pg 244) - * - * - * **** NOTE **** The range reduction relations used in - * this routine depend on the final approximation being valid - * over the negative argument range in addition to the positive - * argument range. The particular approximation chosen from - * HART satisfies this requirement, although not explicitly - * stated in the text. This may not be true of other - * approximations given in the reference. - * - */ - -double _XcmsCosine(double x) -{ - auto double y; - auto double yt2; - double retval; - - if (x < -XCMS_PI || x > XCMS_PI) { - x = _XcmsModulo (x, XCMS_TWOPI); - if (x > XCMS_PI) { - x = x - XCMS_TWOPI; - } else if (x < -XCMS_PI) { - x = x + XCMS_TWOPI; - } - } - if (x > XCMS_HALFPI) { - retval = -(_XcmsCosine (x - XCMS_PI)); - } else if (x < -XCMS_HALFPI) { - retval = -(_XcmsCosine (x + XCMS_PI)); - } else if (x > XCMS_FOURTHPI) { - retval = _XcmsSine (XCMS_HALFPI - x); - } else if (x < -XCMS_FOURTHPI) { - retval = _XcmsSine (XCMS_HALFPI + x); - } else if (x < XCMS_X6_UNDERFLOWS && x > -XCMS_X6_UNDERFLOWS) { - retval = _XcmsSquareRoot (1.0 - (x * x)); - } else { - y = x / XCMS_FOURTHPI; - yt2 = y * y; - retval = _XcmsPolynomial (3, cos_pcoeffs, yt2) / _XcmsPolynomial (3, cos_qcoeffs, yt2); - } - return (retval); -} - - -/* - * FUNCTION - * - * _XcmsModulo double precision modulo - * - * KEY WORDS - * - * _XcmsModulo - * machine independent routines - * math libraries - * - * DESCRIPTION - * - * Returns double precision modulo of two double - * precision arguments. - * - * USAGE - * - * double _XcmsModulo (value, base) - * double value; - * double base; - * - * PROGRAMMER - * - * Fred Fish - * - */ -static double _XcmsModulo(double value, double base) -{ - auto double intpart; - - value /= base; - value = _XcmsModuloF (value, &intpart); - value *= base; - return(value); -} - - -/* - * frac = (double) _XcmsModuloF(double val, double *dp) - * return fractional part of 'val' - * set *dp to integer part of 'val' - * - * Note -> only compiled for the CA or KA. For the KB/MC, - * "math.c" instantiates a copy of the inline function - * defined in "math.h". - */ -static double -_XcmsModuloF( - double val, - register double *dp) -{ - register double abs; - /* - * Don't use a register for this. The extra precision this results - * in on some systems causes problems. - */ - double ip; - - /* should check for illegal values here - nan, inf, etc */ - abs = XCMS_FABS(val); - if (abs >= XCMS_DMAXPOWTWO) { - ip = val; - } else { - ip = abs + XCMS_DMAXPOWTWO; /* dump fraction */ - ip -= XCMS_DMAXPOWTWO; /* restore w/o frac */ - if (ip > abs) /* if it rounds up */ - ip -= 1.0; /* fix it */ - ip = XCMS_FABS(ip); - } - *dp = ip; - return (val - ip); /* signed fractional part */ -} - - -/* - * FUNCTION - * - * _XcmsPolynomial double precision polynomial evaluation - * - * KEY WORDS - * - * poly - * machine independent routines - * math libraries - * - * DESCRIPTION - * - * Evaluates a polynomial and returns double precision - * result. Is passed a the order of the polynomial, - * a pointer to an array of double precision polynomial - * coefficients (in ascending order), and the independent - * variable. - * - * USAGE - * - * double _XcmsPolynomial (order, coeffs, x) - * int order; - * double *coeffs; - * double x; - * - * PROGRAMMER - * - * Fred Fish - * - * INTERNALS - * - * Evalates the polynomial using recursion and the form: - * - * P(x) = P0 + x(P1 + x(P2 +...x(Pn))) - * - */ - -static double _XcmsPolynomial( - register int order, - double const *coeffs, - double x) -{ - auto double rtn_value; - -#if 0 - auto double curr_coeff; - if (order <= 0) { - rtn_value = *coeffs; - } else { - curr_coeff = *coeffs; /* Bug in Unisoft's compiler. Does not */ - coeffs++; /* generate good code for *coeffs++ */ - rtn_value = curr_coeff + x * _XcmsPolynomial (--order, coeffs, x); - } -#else /* ++jrb -- removed tail recursion */ - coeffs += order; - rtn_value = *coeffs--; - while(order-- > 0) - rtn_value = *coeffs-- + (x * rtn_value); -#endif - - return(rtn_value); -} - - -/* - * FUNCTION - * - * _XcmsSine double precision sine - * - * KEY WORDS - * - * sin - * machine independent routines - * trigonometric functions - * math libraries - * - * DESCRIPTION - * - * Returns double precision sine of double precision - * floating point argument. - * - * USAGE - * - * double _XcmsSine (x) - * double x; - * - * REFERENCES - * - * Computer Approximations, J.F. Hart et al, John Wiley & Sons, - * 1968, pp. 112-120. - * - * RESTRICTIONS - * - * The sin and cos routines are interactive in the sense that - * in the process of reducing the argument to the range -PI/4 - * to PI/4, each may call the other. Ultimately one or the - * other uses a polynomial approximation on the reduced - * argument. The sin approximation has a maximum relative error - * of 10**(-17.59) and the cos approximation has a maximum - * relative error of 10**(-16.18). - * - * These error bounds assume exact arithmetic - * in the polynomial evaluation. Additional rounding and - * truncation errors may occur as the argument is reduced - * to the range over which the polynomial approximation - * is valid, and as the polynomial is evaluated using - * finite-precision arithmetic. - * - * PROGRAMMER - * - * Fred Fish - * - * INTERNALS - * - * Computes sin(x) from: - * - * (1) Reduce argument x to range -PI to PI. - * - * (2) If x > PI/2 then call sin recursively - * using relation sin(x) = -sin(x - PI). - * - * (3) If x < -PI/2 then call sin recursively - * using relation sin(x) = -sin(x + PI). - * - * (4) If x > PI/4 then call cos using - * relation sin(x) = cos(PI/2 - x). - * - * (5) If x < -PI/4 then call cos using - * relation sin(x) = -cos(PI/2 + x). - * - * (6) If x is small enough that polynomial - * evaluation would cause underflow - * then return x, since sin(x) - * approaches x as x approaches zero. - * - * (7) By now x has been reduced to range - * -PI/4 to PI/4 and the approximation - * from HART pg. 118 can be used: - * - * sin(x) = y * ( p(y) / q(y) ) - * Where: - * - * y = x * (4/PI) - * - * p(y) = SUM [ Pj * (y**(2*j)) ] - * over j = {0,1,2,3} - * - * q(y) = SUM [ Qj * (y**(2*j)) ] - * over j = {0,1,2,3} - * - * P0 = 0.206643433369958582409167054e+7 - * P1 = -0.18160398797407332550219213e+6 - * P2 = 0.359993069496361883172836e+4 - * P3 = -0.2010748329458861571949e+2 - * Q0 = 0.263106591026476989637710307e+7 - * Q1 = 0.3927024277464900030883986e+5 - * Q2 = 0.27811919481083844087953e+3 - * Q3 = 1.0000... - * (coefficients from HART table #3063 pg 234) - * - * - * **** NOTE **** The range reduction relations used in - * this routine depend on the final approximation being valid - * over the negative argument range in addition to the positive - * argument range. The particular approximation chosen from - * HART satisfies this requirement, although not explicitly - * stated in the text. This may not be true of other - * approximations given in the reference. - * - */ - -double -_XcmsSine (double x) -{ - double y; - double yt2; - double retval; - - if (x < -XCMS_PI || x > XCMS_PI) { - x = _XcmsModulo (x, XCMS_TWOPI); - if (x > XCMS_PI) { - x = x - XCMS_TWOPI; - } else if (x < -XCMS_PI) { - x = x + XCMS_TWOPI; - } - } - if (x > XCMS_HALFPI) { - retval = -(_XcmsSine (x - XCMS_PI)); - } else if (x < -XCMS_HALFPI) { - retval = -(_XcmsSine (x + XCMS_PI)); - } else if (x > XCMS_FOURTHPI) { - retval = _XcmsCosine (XCMS_HALFPI - x); - } else if (x < -XCMS_FOURTHPI) { - retval = -(_XcmsCosine (XCMS_HALFPI + x)); - } else if (x < XCMS_X6_UNDERFLOWS && x > -XCMS_X6_UNDERFLOWS) { - retval = x; - } else { - y = x / XCMS_FOURTHPI; - yt2 = y * y; - retval = y * (_XcmsPolynomial (3, sin_pcoeffs, yt2) / _XcmsPolynomial(3, sin_qcoeffs, yt2)); - } - return(retval); -} - - -/* - * NAME - * _XcmsArcTangent - * - * SYNOPSIS - */ -double -_XcmsArcTangent(double x) -/* - * DESCRIPTION - * Computes the arctangent. - * This is an implementation of the Gauss algorithm as - * described in: - * Forman S. Acton, Numerical Methods That Work, - * New York, NY, Harper & Row, 1970. - * - * RETURNS - * Returns the arctangent - */ -{ - double ai, a1 = 0.0, bi, b1 = 0.0, l, d; - double maxerror; - int i; - - if (x == 0.0) { - return (0.0); - } - if (x < 1.0) { - maxerror = x * XCMS_MAXERROR; - } else { - maxerror = XCMS_MAXERROR; - } - ai = _XcmsSquareRoot( 1.0 / (1.0 + (x * x)) ); - bi = 1.0; - for (i = 0; i < XCMS_MAXITER; i++) { - a1 = (ai + bi) / 2.0; - b1 = _XcmsSquareRoot((a1 * bi)); - if (a1 == b1) - break; - d = XCMS_FABS(a1 - b1); - if (d < maxerror) - break; - ai = a1; - bi = b1; - } - - l = ((a1 > b1) ? b1 : a1); - - a1 = _XcmsSquareRoot(1 + (x * x)); - return (x / (a1 * l)); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * It should be pointed out that for simplicity's sake, the
+ * environment parameters are defined as floating point constants,
+ * rather than octal or hexadecimal initializations of allocated
+ * storage areas. This means that the range of allowed numbers
+ * may not exactly match the hardware's capabilities. For example,
+ * if the maximum positive double precision floating point number
+ * is EXACTLY 1.11...E100 and the constant "MAXDOUBLE is
+ * defined to be 1.11E100 then the numbers between 1.11E100 and
+ * 1.11...E100 are considered to be undefined. For most
+ * applications, this will cause no problems.
+ *
+ * An alternate method is to allocate a global static "double" variable,
+ * say "maxdouble", and use a union declaration and initialization
+ * to initialize it with the proper bits for the EXACT maximum value.
+ * This was not done because the only compilers available to the
+ * author did not fully support union initialization features.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include "Xcmsint.h"
+
+/* forward/static */
+static double _XcmsModulo(double value, double base);
+static double _XcmsPolynomial(
+ register int order,
+ double const *coeffs,
+ double x);
+static double
+_XcmsModuloF(
+ double val,
+ register double *dp);
+
+/*
+ * DEFINES
+ */
+#define XCMS_MAXERROR 0.000001
+#define XCMS_MAXITER 10000
+#define XCMS_PI 3.14159265358979323846264338327950
+#define XCMS_TWOPI 6.28318530717958620
+#define XCMS_HALFPI 1.57079632679489660
+#define XCMS_FOURTHPI 0.785398163397448280
+#define XCMS_SIXTHPI 0.523598775598298820
+#define XCMS_RADIANS(d) ((d) * XCMS_PI / 180.0)
+#define XCMS_DEGREES(r) ((r) * 180.0 / XCMS_PI)
+#define XCMS_X6_UNDERFLOWS (4.209340e-52) /* X**6 almost underflows */
+#define XCMS_X16_UNDERFLOWS (5.421010e-20) /* X**16 almost underflows*/
+#define XCMS_CHAR_BIT 8
+#define XCMS_LONG_MAX 0x7FFFFFFF
+#define XCMS_DEXPLEN 11
+#define XCMS_NBITS(type) (XCMS_CHAR_BIT * (int)sizeof(type))
+#define XCMS_FABS(x) ((x) < 0.0 ? -(x) : (x))
+
+/* XCMS_DMAXPOWTWO - largest power of two exactly representable as a double */
+#ifdef _CRAY
+#define XCMS_DMAXPOWTWO ((double)(1 < 47))
+#else
+#define XCMS_DMAXPOWTWO ((double)(XCMS_LONG_MAX) * \
+ (1L << ((XCMS_NBITS(double)-XCMS_DEXPLEN) - XCMS_NBITS(int) + 1)))
+#endif
+
+/*
+ * LOCAL VARIABLES
+ */
+
+static double const cos_pcoeffs[] = {
+ 0.12905394659037374438e7,
+ -0.37456703915723204710e6,
+ 0.13432300986539084285e5,
+ -0.11231450823340933092e3
+};
+
+static double const cos_qcoeffs[] = {
+ 0.12905394659037373590e7,
+ 0.23467773107245835052e5,
+ 0.20969518196726306286e3,
+ 1.0
+};
+
+static double const sin_pcoeffs[] = {
+ 0.20664343336995858240e7,
+ -0.18160398797407332550e6,
+ 0.35999306949636188317e4,
+ -0.20107483294588615719e2
+};
+
+static double const sin_qcoeffs[] = {
+ 0.26310659102647698963e7,
+ 0.39270242774649000308e5,
+ 0.27811919481083844087e3,
+ 1.0
+};
+
+/*
+ *
+ * FUNCTION
+ *
+ * _XcmsCosine double precision cosine
+ *
+ * KEY WORDS
+ *
+ * cos
+ * machine independent routines
+ * trigonometric functions
+ * math libraries
+ *
+ * DESCRIPTION
+ *
+ * Returns double precision cosine of double precision
+ * floating point argument.
+ *
+ * USAGE
+ *
+ * double _XcmsCosine (x)
+ * double x;
+ *
+ * REFERENCES
+ *
+ * Computer Approximations, J.F. Hart et al, John Wiley & Sons,
+ * 1968, pp. 112-120.
+ *
+ * RESTRICTIONS
+ *
+ * The sin and cos routines are interactive in the sense that
+ * in the process of reducing the argument to the range -PI/4
+ * to PI/4, each may call the other. Ultimately one or the
+ * other uses a polynomial approximation on the reduced
+ * argument. The sin approximation has a maximum relative error
+ * of 10**(-17.59) and the cos approximation has a maximum
+ * relative error of 10**(-16.18).
+ *
+ * These error bounds assume exact arithmetic
+ * in the polynomial evaluation. Additional rounding and
+ * truncation errors may occur as the argument is reduced
+ * to the range over which the polynomial approximation
+ * is valid, and as the polynomial is evaluated using
+ * finite-precision arithmetic.
+ *
+ * PROGRAMMER
+ *
+ * Fred Fish
+ *
+ * INTERNALS
+ *
+ * Computes cos(x) from:
+ *
+ * (1) Reduce argument x to range -PI to PI.
+ *
+ * (2) If x > PI/2 then call cos recursively
+ * using relation cos(x) = -cos(x - PI).
+ *
+ * (3) If x < -PI/2 then call cos recursively
+ * using relation cos(x) = -cos(x + PI).
+ *
+ * (4) If x > PI/4 then call sin using
+ * relation cos(x) = sin(PI/2 - x).
+ *
+ * (5) If x < -PI/4 then call cos using
+ * relation cos(x) = sin(PI/2 + x).
+ *
+ * (6) If x would cause underflow in approx
+ * evaluation arithmetic then return
+ * sqrt(1.0 - x**2).
+ *
+ * (7) By now x has been reduced to range
+ * -PI/4 to PI/4 and the approximation
+ * from HART pg. 119 can be used:
+ *
+ * cos(x) = ( p(y) / q(y) )
+ * Where:
+ *
+ * y = x * (4/PI)
+ *
+ * p(y) = SUM [ Pj * (y**(2*j)) ]
+ * over j = {0,1,2,3}
+ *
+ * q(y) = SUM [ Qj * (y**(2*j)) ]
+ * over j = {0,1,2,3}
+ *
+ * P0 = 0.12905394659037374438571854e+7
+ * P1 = -0.3745670391572320471032359e+6
+ * P2 = 0.134323009865390842853673e+5
+ * P3 = -0.112314508233409330923e+3
+ * Q0 = 0.12905394659037373590295914e+7
+ * Q1 = 0.234677731072458350524124e+5
+ * Q2 = 0.2096951819672630628621e+3
+ * Q3 = 1.0000...
+ * (coefficients from HART table #3843 pg 244)
+ *
+ *
+ * **** NOTE **** The range reduction relations used in
+ * this routine depend on the final approximation being valid
+ * over the negative argument range in addition to the positive
+ * argument range. The particular approximation chosen from
+ * HART satisfies this requirement, although not explicitly
+ * stated in the text. This may not be true of other
+ * approximations given in the reference.
+ *
+ */
+
+double _XcmsCosine(double x)
+{
+ auto double y;
+ auto double yt2;
+ double retval;
+
+ if (x < -XCMS_PI || x > XCMS_PI) {
+ x = _XcmsModulo (x, XCMS_TWOPI);
+ if (x > XCMS_PI) {
+ x = x - XCMS_TWOPI;
+ } else if (x < -XCMS_PI) {
+ x = x + XCMS_TWOPI;
+ }
+ }
+ if (x > XCMS_HALFPI) {
+ retval = -(_XcmsCosine (x - XCMS_PI));
+ } else if (x < -XCMS_HALFPI) {
+ retval = -(_XcmsCosine (x + XCMS_PI));
+ } else if (x > XCMS_FOURTHPI) {
+ retval = _XcmsSine (XCMS_HALFPI - x);
+ } else if (x < -XCMS_FOURTHPI) {
+ retval = _XcmsSine (XCMS_HALFPI + x);
+ } else if (x < XCMS_X6_UNDERFLOWS && x > -XCMS_X6_UNDERFLOWS) {
+ retval = _XcmsSquareRoot (1.0 - (x * x));
+ } else {
+ y = x / XCMS_FOURTHPI;
+ yt2 = y * y;
+ retval = _XcmsPolynomial (3, cos_pcoeffs, yt2) / _XcmsPolynomial (3, cos_qcoeffs, yt2);
+ }
+ return (retval);
+}
+
+
+/*
+ * FUNCTION
+ *
+ * _XcmsModulo double precision modulo
+ *
+ * KEY WORDS
+ *
+ * _XcmsModulo
+ * machine independent routines
+ * math libraries
+ *
+ * DESCRIPTION
+ *
+ * Returns double precision modulo of two double
+ * precision arguments.
+ *
+ * USAGE
+ *
+ * double _XcmsModulo (value, base)
+ * double value;
+ * double base;
+ *
+ * PROGRAMMER
+ *
+ * Fred Fish
+ *
+ */
+static double _XcmsModulo(double value, double base)
+{
+ auto double intpart;
+
+ value /= base;
+ value = _XcmsModuloF (value, &intpart);
+ value *= base;
+ return(value);
+}
+
+
+/*
+ * frac = (double) _XcmsModuloF(double val, double *dp)
+ * return fractional part of 'val'
+ * set *dp to integer part of 'val'
+ *
+ * Note -> only compiled for the CA or KA. For the KB/MC,
+ * "math.c" instantiates a copy of the inline function
+ * defined in "math.h".
+ */
+static double
+_XcmsModuloF(
+ double val,
+ register double *dp)
+{
+ register double abs;
+ /*
+ * Don't use a register for this. The extra precision this results
+ * in on some systems causes problems.
+ */
+ double ip;
+
+ /* should check for illegal values here - nan, inf, etc */
+ abs = XCMS_FABS(val);
+ if (abs >= XCMS_DMAXPOWTWO) {
+ ip = val;
+ } else {
+ ip = abs + XCMS_DMAXPOWTWO; /* dump fraction */
+ ip -= XCMS_DMAXPOWTWO; /* restore w/o frac */
+ if (ip > abs) /* if it rounds up */
+ ip -= 1.0; /* fix it */
+ ip = XCMS_FABS(ip);
+ }
+ *dp = ip;
+ return (val - ip); /* signed fractional part */
+}
+
+
+/*
+ * FUNCTION
+ *
+ * _XcmsPolynomial double precision polynomial evaluation
+ *
+ * KEY WORDS
+ *
+ * poly
+ * machine independent routines
+ * math libraries
+ *
+ * DESCRIPTION
+ *
+ * Evaluates a polynomial and returns double precision
+ * result. Is passed a the order of the polynomial,
+ * a pointer to an array of double precision polynomial
+ * coefficients (in ascending order), and the independent
+ * variable.
+ *
+ * USAGE
+ *
+ * double _XcmsPolynomial (order, coeffs, x)
+ * int order;
+ * double *coeffs;
+ * double x;
+ *
+ * PROGRAMMER
+ *
+ * Fred Fish
+ *
+ * INTERNALS
+ *
+ * Evalates the polynomial using recursion and the form:
+ *
+ * P(x) = P0 + x(P1 + x(P2 +...x(Pn)))
+ *
+ */
+
+static double _XcmsPolynomial(
+ register int order,
+ double const *coeffs,
+ double x)
+{
+ auto double rtn_value;
+
+#if 0
+ auto double curr_coeff;
+ if (order <= 0) {
+ rtn_value = *coeffs;
+ } else {
+ curr_coeff = *coeffs; /* Bug in Unisoft's compiler. Does not */
+ coeffs++; /* generate good code for *coeffs++ */
+ rtn_value = curr_coeff + x * _XcmsPolynomial (--order, coeffs, x);
+ }
+#else /* ++jrb -- removed tail recursion */
+ coeffs += order;
+ rtn_value = *coeffs--;
+ while(order-- > 0)
+ rtn_value = *coeffs-- + (x * rtn_value);
+#endif
+
+ return(rtn_value);
+}
+
+
+/*
+ * FUNCTION
+ *
+ * _XcmsSine double precision sine
+ *
+ * KEY WORDS
+ *
+ * sin
+ * machine independent routines
+ * trigonometric functions
+ * math libraries
+ *
+ * DESCRIPTION
+ *
+ * Returns double precision sine of double precision
+ * floating point argument.
+ *
+ * USAGE
+ *
+ * double _XcmsSine (x)
+ * double x;
+ *
+ * REFERENCES
+ *
+ * Computer Approximations, J.F. Hart et al, John Wiley & Sons,
+ * 1968, pp. 112-120.
+ *
+ * RESTRICTIONS
+ *
+ * The sin and cos routines are interactive in the sense that
+ * in the process of reducing the argument to the range -PI/4
+ * to PI/4, each may call the other. Ultimately one or the
+ * other uses a polynomial approximation on the reduced
+ * argument. The sin approximation has a maximum relative error
+ * of 10**(-17.59) and the cos approximation has a maximum
+ * relative error of 10**(-16.18).
+ *
+ * These error bounds assume exact arithmetic
+ * in the polynomial evaluation. Additional rounding and
+ * truncation errors may occur as the argument is reduced
+ * to the range over which the polynomial approximation
+ * is valid, and as the polynomial is evaluated using
+ * finite-precision arithmetic.
+ *
+ * PROGRAMMER
+ *
+ * Fred Fish
+ *
+ * INTERNALS
+ *
+ * Computes sin(x) from:
+ *
+ * (1) Reduce argument x to range -PI to PI.
+ *
+ * (2) If x > PI/2 then call sin recursively
+ * using relation sin(x) = -sin(x - PI).
+ *
+ * (3) If x < -PI/2 then call sin recursively
+ * using relation sin(x) = -sin(x + PI).
+ *
+ * (4) If x > PI/4 then call cos using
+ * relation sin(x) = cos(PI/2 - x).
+ *
+ * (5) If x < -PI/4 then call cos using
+ * relation sin(x) = -cos(PI/2 + x).
+ *
+ * (6) If x is small enough that polynomial
+ * evaluation would cause underflow
+ * then return x, since sin(x)
+ * approaches x as x approaches zero.
+ *
+ * (7) By now x has been reduced to range
+ * -PI/4 to PI/4 and the approximation
+ * from HART pg. 118 can be used:
+ *
+ * sin(x) = y * ( p(y) / q(y) )
+ * Where:
+ *
+ * y = x * (4/PI)
+ *
+ * p(y) = SUM [ Pj * (y**(2*j)) ]
+ * over j = {0,1,2,3}
+ *
+ * q(y) = SUM [ Qj * (y**(2*j)) ]
+ * over j = {0,1,2,3}
+ *
+ * P0 = 0.206643433369958582409167054e+7
+ * P1 = -0.18160398797407332550219213e+6
+ * P2 = 0.359993069496361883172836e+4
+ * P3 = -0.2010748329458861571949e+2
+ * Q0 = 0.263106591026476989637710307e+7
+ * Q1 = 0.3927024277464900030883986e+5
+ * Q2 = 0.27811919481083844087953e+3
+ * Q3 = 1.0000...
+ * (coefficients from HART table #3063 pg 234)
+ *
+ *
+ * **** NOTE **** The range reduction relations used in
+ * this routine depend on the final approximation being valid
+ * over the negative argument range in addition to the positive
+ * argument range. The particular approximation chosen from
+ * HART satisfies this requirement, although not explicitly
+ * stated in the text. This may not be true of other
+ * approximations given in the reference.
+ *
+ */
+
+double
+_XcmsSine (double x)
+{
+ double y;
+ double yt2;
+ double retval;
+
+ if (x < -XCMS_PI || x > XCMS_PI) {
+ x = _XcmsModulo (x, XCMS_TWOPI);
+ if (x > XCMS_PI) {
+ x = x - XCMS_TWOPI;
+ } else if (x < -XCMS_PI) {
+ x = x + XCMS_TWOPI;
+ }
+ }
+ if (x > XCMS_HALFPI) {
+ retval = -(_XcmsSine (x - XCMS_PI));
+ } else if (x < -XCMS_HALFPI) {
+ retval = -(_XcmsSine (x + XCMS_PI));
+ } else if (x > XCMS_FOURTHPI) {
+ retval = _XcmsCosine (XCMS_HALFPI - x);
+ } else if (x < -XCMS_FOURTHPI) {
+ retval = -(_XcmsCosine (XCMS_HALFPI + x));
+ } else if (x < XCMS_X6_UNDERFLOWS && x > -XCMS_X6_UNDERFLOWS) {
+ retval = x;
+ } else {
+ y = x / XCMS_FOURTHPI;
+ yt2 = y * y;
+ retval = y * (_XcmsPolynomial (3, sin_pcoeffs, yt2) / _XcmsPolynomial(3, sin_qcoeffs, yt2));
+ }
+ return(retval);
+}
+
+
+/*
+ * NAME
+ * _XcmsArcTangent
+ *
+ * SYNOPSIS
+ */
+double
+_XcmsArcTangent(double x)
+/*
+ * DESCRIPTION
+ * Computes the arctangent.
+ * This is an implementation of the Gauss algorithm as
+ * described in:
+ * Forman S. Acton, Numerical Methods That Work,
+ * New York, NY, Harper & Row, 1970.
+ *
+ * RETURNS
+ * Returns the arctangent
+ */
+{
+ double ai, a1 = 0.0, bi, b1 = 0.0, l, d;
+ double maxerror;
+ int i;
+
+ if (x == 0.0) {
+ return (0.0);
+ }
+ if (x < 1.0) {
+ maxerror = x * XCMS_MAXERROR;
+ } else {
+ maxerror = XCMS_MAXERROR;
+ }
+ ai = _XcmsSquareRoot( 1.0 / (1.0 + (x * x)) );
+ bi = 1.0;
+ for (i = 0; i < XCMS_MAXITER; i++) {
+ a1 = (ai + bi) / 2.0;
+ b1 = _XcmsSquareRoot((a1 * bi));
+ if (a1 == b1)
+ break;
+ d = XCMS_FABS(a1 - b1);
+ if (d < maxerror)
+ break;
+ ai = a1;
+ bi = b1;
+ }
+
+ l = ((a1 > b1) ? b1 : a1);
+
+ a1 = _XcmsSquareRoot(1 + (x * x));
+ return (x / (a1 * l));
+}
diff --git a/libX11/src/xcms/uvY.c b/libX11/src/xcms/uvY.c index 5344fb17c..a4abc66cd 100644 --- a/libX11/src/xcms/uvY.c +++ b/libX11/src/xcms/uvY.c @@ -1,423 +1,423 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of XCMS based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * - * NAME - * CIEuvy.c - * - * DESCRIPTION - * This file contains routines that support the CIE u'v'Y - * color space to include conversions to and from the CIE - * XYZ space. - * - * DOCUMENTATION - * "TekColor Color Management System, System Implementor's Manual" - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <X11/Xos.h> -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - -#include <stdio.h> - -/* - * FORWARD DECLARATIONS - */ -static int CIEuvY_ParseString(register char *spec, XcmsColor *pColor); - -/* - * DEFINES - * Internal definitions that need NOT be exported to any package - * or program using this package. - */ -#ifdef DBL_EPSILON -# define XMY_DBL_EPSILON DBL_EPSILON -#else -# define XMY_DBL_EPSILON 0.00001 -#endif - - -/* - * LOCAL VARIABLES - */ - - /* - * NULL terminated list of functions applied to get from CIEuvY to CIEXYZ - */ -static XcmsConversionProc Fl_CIEuvY_to_CIEXYZ[] = { - XcmsCIEuvYToCIEXYZ, - NULL -}; - - /* - * NULL terminated list of functions applied to get from CIEXYZ to CIEuvY - */ -static XcmsConversionProc Fl_CIEXYZ_to_CIEuvY[] = { - XcmsCIEXYZToCIEuvY, - NULL -}; - - -/* - * GLOBALS - */ - - /* - * CIE uvY Color Space - */ -XcmsColorSpace XcmsCIEuvYColorSpace = - { - _XcmsCIEuvY_prefix, /* prefix */ - XcmsCIEuvYFormat, /* id */ - CIEuvY_ParseString, /* parseString */ - Fl_CIEuvY_to_CIEXYZ, /* to_CIEXYZ */ - Fl_CIEXYZ_to_CIEuvY, /* from_CIEXYZ */ - 1 - }; - - - -/************************************************************************ - * * - * PRIVATE ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * CIEuvY_ParseString - * - * SYNOPSIS - */ -static int -CIEuvY_ParseString( - register char *spec, - XcmsColor *pColor) -/* - * DESCRIPTION - * This routines takes a string and attempts to convert - * it into a XcmsColor structure with XcmsCIEuvYFormat. - * The assumed CIEuvY string syntax is: - * CIEuvY:<u>/<v>/<Y> - * Where u, v, and Y are in string input format for floats - * consisting of: - * a. an optional sign - * b. a string of numbers possibly containing a decimal point, - * c. an optional exponent field containing an 'E' or 'e' - * followed by a possibly signed integer string. - * - * RETURNS - * 0 if failed, non-zero otherwise. - */ -{ - int n; - char *pchar; - - if ((pchar = strchr(spec, ':')) == NULL) { - return(XcmsFailure); - } - n = (int)(pchar - spec); - - /* - * Check for proper prefix. - */ - if (strncmp(spec, _XcmsCIEuvY_prefix, n) != 0) { - return(XcmsFailure); - } - - /* - * Attempt to parse the value portion. - */ - if (sscanf(spec + n + 1, "%lf/%lf/%lf", - &pColor->spec.CIEuvY.u_prime, - &pColor->spec.CIEuvY.v_prime, - &pColor->spec.CIEuvY.Y) != 3) { - char *s; /* Maybe failed due to locale */ - int f; - if ((s = strdup(spec))) { - for (f = 0; s[f]; ++f) - if (s[f] == '.') - s[f] = ','; - else if (s[f] == ',') - s[f] = '.'; - if (sscanf(s + n + 1, "%lf/%lf/%lf", - &pColor->spec.CIEuvY.u_prime, - &pColor->spec.CIEuvY.v_prime, - &pColor->spec.CIEuvY.Y) != 3) { - free(s); - return(XcmsFailure); - } - free(s); - } else - return(XcmsFailure); - } - pColor->format = XcmsCIEuvYFormat; - pColor->pixel = 0; - return(_XcmsCIEuvY_ValidSpec(pColor)); -} - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * XcmsCIEuvY_ValidSpec - * - * SYNOPSIS - */ -Status -_XcmsCIEuvY_ValidSpec( - XcmsColor *pColor) -/* - * DESCRIPTION - * Checks if color specification valid for CIE u'v'Y. - * - * RETURNS - * XcmsFailure if invalid, - * XcmsSuccess if valid. - * - */ -{ - if (pColor->format != XcmsCIEuvYFormat - || - (pColor->spec.CIEuvY.Y < 0.0 - XMY_DBL_EPSILON) - || - (pColor->spec.CIEuvY.Y > 1.0 + XMY_DBL_EPSILON)) { - return(XcmsFailure); - } - return(XcmsSuccess); -} - - -/* - * NAME - * XcmsCIEuvYToCIEXYZ - convert CIEuvY to CIEXYZ - * - * SYNOPSIS - */ -Status -XcmsCIEuvYToCIEXYZ( - XcmsCCC ccc, - XcmsColor *puvY_WhitePt, - XcmsColor *pColors_in_out, - unsigned int nColors) -/* - * DESCRIPTION - * Converts color specifications in an array of XcmsColor - * structures from CIEuvY format to CIEXYZ format. - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if succeeded. - * - */ -{ - XcmsCIEXYZ XYZ_return; - XcmsColor whitePt; - int i; - XcmsColor *pColor = pColors_in_out; - XcmsFloat div, x, y, z, Y; - - /* - * Check arguments - * Postpone checking puvY_WhitePt until it is actually needed - * otherwise converting between XYZ and uvY will fail. - */ - if (pColors_in_out == NULL) { - return(XcmsFailure); - } - - - /* - * Now convert each XcmsColor structure to CIEXYZ form - */ - for (i = 0; i < nColors; i++, pColor++) { - - /* Make sure original format is CIEuvY */ - if (!_XcmsCIEuvY_ValidSpec(pColor)) { - return(XcmsFailure); - } - - /* - * Convert to CIEXYZ - */ - - Y = pColor->spec.CIEuvY.Y; - - /* Convert color u'v' to xyz space */ - div = (6.0 * pColor->spec.CIEuvY.u_prime) - (16.0 * pColor->spec.CIEuvY.v_prime) + 12.0; - if (div == 0.0) { - /* use white point since div == 0 */ - if (puvY_WhitePt == NULL ) { - return(XcmsFailure); - } - /* - * Make sure white point is in CIEuvY form - */ - if (puvY_WhitePt->format != XcmsCIEuvYFormat) { - /* Make copy of the white point because we're going to modify it */ - memcpy((char *)&whitePt, (char *)puvY_WhitePt, sizeof(XcmsColor)); - if (!_XcmsDIConvertColors(ccc, &whitePt, (XcmsColor *)NULL, 1, - XcmsCIEuvYFormat)) { - return(XcmsFailure); - } - puvY_WhitePt = &whitePt; - } - /* Make sure it is a white point, i.e., Y == 1.0 */ - if (puvY_WhitePt->spec.CIEuvY.Y != 1.0) { - return(XcmsFailure); - } - div = (6.0 * puvY_WhitePt->spec.CIEuvY.u_prime) - - (16.0 * puvY_WhitePt->spec.CIEuvY.v_prime) + 12.0; - if (div == 0) { - /* internal error */ - return(XcmsFailure); - } - x = 9.0 * puvY_WhitePt->spec.CIEuvY.u_prime / div; - y = 4.0 * puvY_WhitePt->spec.CIEuvY.v_prime / div; - } else { - x = 9.0 * pColor->spec.CIEuvY.u_prime / div; - y = 4.0 * pColor->spec.CIEuvY.v_prime / div; - } - z = 1.0 - x - y; - - /* Convert from xyz to XYZ */ - /* Conversion uses color normalized lightness based on Y */ - if (y != 0.0) { - XYZ_return.X = x * Y / y; - } else { - XYZ_return.X = x; - } - XYZ_return.Y = Y; - if (y != 0.0) { - XYZ_return.Z = z * Y / y; - } else { - XYZ_return.Z = z; - } - - memcpy((char *)&pColor->spec.CIEXYZ, (char *)&XYZ_return, sizeof(XcmsCIEXYZ)); - /* Identify that format is now CIEXYZ */ - pColor->format = XcmsCIEXYZFormat; - } - - return(XcmsSuccess); -} - - -/* - * NAME - * XcmsCIEXYZToCIEuvY - convert CIEXYZ to CIEuvY - * - * SYNOPSIS - */ -Status -XcmsCIEXYZToCIEuvY( - XcmsCCC ccc, - XcmsColor *puvY_WhitePt, - XcmsColor *pColors_in_out, - unsigned int nColors) -/* - * DESCRIPTION - * Converts color specifications in an array of XcmsColor - * structures from CIEXYZ format to CIEuvY format. - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if succeeded. - * - */ -{ - XcmsCIEuvY uvY_return; - XcmsColor whitePt; - int i; - XcmsColor *pColor = pColors_in_out; - XcmsFloat div; - - /* - * Check arguments - * Postpone checking puvY_WhitePt until it is actually needed - * otherwise converting between XYZ and uvY will fail. - */ - if (pColors_in_out == NULL) { - return(XcmsFailure); - } - - /* - * Now convert each XcmsColor structure to CIEuvY form - */ - for (i = 0; i < nColors; i++, pColor++) { - - /* Make sure original format is CIEXYZ */ - if (!_XcmsCIEXYZ_ValidSpec(pColor)) { - return(XcmsFailure); - } - - /* Convert to CIEuvY */ - div = pColor->spec.CIEXYZ.X + (15.0 * pColor->spec.CIEXYZ.Y) + - (3.0 * pColor->spec.CIEXYZ.Z); - if (div == 0.0) { - /* Use white point since div == 0.0 */ - if (puvY_WhitePt == NULL ) { - return(XcmsFailure); - } - /* - * Make sure white point is in CIEuvY form - */ - if (puvY_WhitePt->format != XcmsCIEuvYFormat) { - /* Make copy of the white point because we're going to modify it */ - memcpy((char *)&whitePt, (char *)puvY_WhitePt, sizeof(XcmsColor)); - if (!_XcmsDIConvertColors(ccc, &whitePt, (XcmsColor *)NULL, 1, - XcmsCIEuvYFormat)) { - return(XcmsFailure); - } - puvY_WhitePt = &whitePt; - } - /* Make sure it is a white point, i.e., Y == 1.0 */ - if (puvY_WhitePt->spec.CIEuvY.Y != 1.0) { - return(XcmsFailure); - } - uvY_return.Y = pColor->spec.CIEXYZ.Y; - uvY_return.u_prime = puvY_WhitePt->spec.CIEuvY.u_prime; - uvY_return.v_prime = puvY_WhitePt->spec.CIEuvY.v_prime; - } else { - uvY_return.u_prime = 4.0 * pColor->spec.CIEXYZ.X / div; - uvY_return.v_prime = 9.0 * pColor->spec.CIEXYZ.Y / div; - uvY_return.Y = pColor->spec.CIEXYZ.Y; - } - - memcpy((char *)&pColor->spec.CIEuvY, (char *)&uvY_return, sizeof(XcmsCIEuvY)); - /* Identify that format is now CIEuvY */ - pColor->format = XcmsCIEuvYFormat; - } - - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of XCMS based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ *
+ * NAME
+ * CIEuvy.c
+ *
+ * DESCRIPTION
+ * This file contains routines that support the CIE u'v'Y
+ * color space to include conversions to and from the CIE
+ * XYZ space.
+ *
+ * DOCUMENTATION
+ * "TekColor Color Management System, System Implementor's Manual"
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xos.h>
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+#include <stdio.h>
+
+/*
+ * FORWARD DECLARATIONS
+ */
+static int CIEuvY_ParseString(register char *spec, XcmsColor *pColor);
+
+/*
+ * DEFINES
+ * Internal definitions that need NOT be exported to any package
+ * or program using this package.
+ */
+#ifdef DBL_EPSILON
+# define XMY_DBL_EPSILON DBL_EPSILON
+#else
+# define XMY_DBL_EPSILON 0.00001
+#endif
+
+
+/*
+ * LOCAL VARIABLES
+ */
+
+ /*
+ * NULL terminated list of functions applied to get from CIEuvY to CIEXYZ
+ */
+static XcmsConversionProc Fl_CIEuvY_to_CIEXYZ[] = {
+ XcmsCIEuvYToCIEXYZ,
+ NULL
+};
+
+ /*
+ * NULL terminated list of functions applied to get from CIEXYZ to CIEuvY
+ */
+static XcmsConversionProc Fl_CIEXYZ_to_CIEuvY[] = {
+ XcmsCIEXYZToCIEuvY,
+ NULL
+};
+
+
+/*
+ * GLOBALS
+ */
+
+ /*
+ * CIE uvY Color Space
+ */
+XcmsColorSpace XcmsCIEuvYColorSpace =
+ {
+ _XcmsCIEuvY_prefix, /* prefix */
+ XcmsCIEuvYFormat, /* id */
+ CIEuvY_ParseString, /* parseString */
+ Fl_CIEuvY_to_CIEXYZ, /* to_CIEXYZ */
+ Fl_CIEXYZ_to_CIEuvY, /* from_CIEXYZ */
+ 1
+ };
+
+
+
+/************************************************************************
+ * *
+ * PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * CIEuvY_ParseString
+ *
+ * SYNOPSIS
+ */
+static int
+CIEuvY_ParseString(
+ register char *spec,
+ XcmsColor *pColor)
+/*
+ * DESCRIPTION
+ * This routines takes a string and attempts to convert
+ * it into a XcmsColor structure with XcmsCIEuvYFormat.
+ * The assumed CIEuvY string syntax is:
+ * CIEuvY:<u>/<v>/<Y>
+ * Where u, v, and Y are in string input format for floats
+ * consisting of:
+ * a. an optional sign
+ * b. a string of numbers possibly containing a decimal point,
+ * c. an optional exponent field containing an 'E' or 'e'
+ * followed by a possibly signed integer string.
+ *
+ * RETURNS
+ * 0 if failed, non-zero otherwise.
+ */
+{
+ int n;
+ char *pchar;
+
+ if ((pchar = strchr(spec, ':')) == NULL) {
+ return(XcmsFailure);
+ }
+ n = (int)(pchar - spec);
+
+ /*
+ * Check for proper prefix.
+ */
+ if (strncmp(spec, _XcmsCIEuvY_prefix, n) != 0) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Attempt to parse the value portion.
+ */
+ if (sscanf(spec + n + 1, "%lf/%lf/%lf",
+ &pColor->spec.CIEuvY.u_prime,
+ &pColor->spec.CIEuvY.v_prime,
+ &pColor->spec.CIEuvY.Y) != 3) {
+ char *s; /* Maybe failed due to locale */
+ int f;
+ if ((s = strdup(spec))) {
+ for (f = 0; s[f]; ++f)
+ if (s[f] == '.')
+ s[f] = ',';
+ else if (s[f] == ',')
+ s[f] = '.';
+ if (sscanf(s + n + 1, "%lf/%lf/%lf",
+ &pColor->spec.CIEuvY.u_prime,
+ &pColor->spec.CIEuvY.v_prime,
+ &pColor->spec.CIEuvY.Y) != 3) {
+ free(s);
+ return(XcmsFailure);
+ }
+ free(s);
+ } else
+ return(XcmsFailure);
+ }
+ pColor->format = XcmsCIEuvYFormat;
+ pColor->pixel = 0;
+ return(_XcmsCIEuvY_ValidSpec(pColor));
+}
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * XcmsCIEuvY_ValidSpec
+ *
+ * SYNOPSIS
+ */
+Status
+_XcmsCIEuvY_ValidSpec(
+ XcmsColor *pColor)
+/*
+ * DESCRIPTION
+ * Checks if color specification valid for CIE u'v'Y.
+ *
+ * RETURNS
+ * XcmsFailure if invalid,
+ * XcmsSuccess if valid.
+ *
+ */
+{
+ if (pColor->format != XcmsCIEuvYFormat
+ ||
+ (pColor->spec.CIEuvY.Y < 0.0 - XMY_DBL_EPSILON)
+ ||
+ (pColor->spec.CIEuvY.Y > 1.0 + XMY_DBL_EPSILON)) {
+ return(XcmsFailure);
+ }
+ return(XcmsSuccess);
+}
+
+
+/*
+ * NAME
+ * XcmsCIEuvYToCIEXYZ - convert CIEuvY to CIEXYZ
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIEuvYToCIEXYZ(
+ XcmsCCC ccc,
+ XcmsColor *puvY_WhitePt,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors)
+/*
+ * DESCRIPTION
+ * Converts color specifications in an array of XcmsColor
+ * structures from CIEuvY format to CIEXYZ format.
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if succeeded.
+ *
+ */
+{
+ XcmsCIEXYZ XYZ_return;
+ XcmsColor whitePt;
+ int i;
+ XcmsColor *pColor = pColors_in_out;
+ XcmsFloat div, x, y, z, Y;
+
+ /*
+ * Check arguments
+ * Postpone checking puvY_WhitePt until it is actually needed
+ * otherwise converting between XYZ and uvY will fail.
+ */
+ if (pColors_in_out == NULL) {
+ return(XcmsFailure);
+ }
+
+
+ /*
+ * Now convert each XcmsColor structure to CIEXYZ form
+ */
+ for (i = 0; i < nColors; i++, pColor++) {
+
+ /* Make sure original format is CIEuvY */
+ if (!_XcmsCIEuvY_ValidSpec(pColor)) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Convert to CIEXYZ
+ */
+
+ Y = pColor->spec.CIEuvY.Y;
+
+ /* Convert color u'v' to xyz space */
+ div = (6.0 * pColor->spec.CIEuvY.u_prime) - (16.0 * pColor->spec.CIEuvY.v_prime) + 12.0;
+ if (div == 0.0) {
+ /* use white point since div == 0 */
+ if (puvY_WhitePt == NULL ) {
+ return(XcmsFailure);
+ }
+ /*
+ * Make sure white point is in CIEuvY form
+ */
+ if (puvY_WhitePt->format != XcmsCIEuvYFormat) {
+ /* Make copy of the white point because we're going to modify it */
+ memcpy((char *)&whitePt, (char *)puvY_WhitePt, sizeof(XcmsColor));
+ if (!_XcmsDIConvertColors(ccc, &whitePt, (XcmsColor *)NULL, 1,
+ XcmsCIEuvYFormat)) {
+ return(XcmsFailure);
+ }
+ puvY_WhitePt = &whitePt;
+ }
+ /* Make sure it is a white point, i.e., Y == 1.0 */
+ if (puvY_WhitePt->spec.CIEuvY.Y != 1.0) {
+ return(XcmsFailure);
+ }
+ div = (6.0 * puvY_WhitePt->spec.CIEuvY.u_prime) -
+ (16.0 * puvY_WhitePt->spec.CIEuvY.v_prime) + 12.0;
+ if (div == 0) {
+ /* internal error */
+ return(XcmsFailure);
+ }
+ x = 9.0 * puvY_WhitePt->spec.CIEuvY.u_prime / div;
+ y = 4.0 * puvY_WhitePt->spec.CIEuvY.v_prime / div;
+ } else {
+ x = 9.0 * pColor->spec.CIEuvY.u_prime / div;
+ y = 4.0 * pColor->spec.CIEuvY.v_prime / div;
+ }
+ z = 1.0 - x - y;
+
+ /* Convert from xyz to XYZ */
+ /* Conversion uses color normalized lightness based on Y */
+ if (y != 0.0) {
+ XYZ_return.X = x * Y / y;
+ } else {
+ XYZ_return.X = x;
+ }
+ XYZ_return.Y = Y;
+ if (y != 0.0) {
+ XYZ_return.Z = z * Y / y;
+ } else {
+ XYZ_return.Z = z;
+ }
+
+ memcpy((char *)&pColor->spec.CIEXYZ, (char *)&XYZ_return, sizeof(XcmsCIEXYZ));
+ /* Identify that format is now CIEXYZ */
+ pColor->format = XcmsCIEXYZFormat;
+ }
+
+ return(XcmsSuccess);
+}
+
+
+/*
+ * NAME
+ * XcmsCIEXYZToCIEuvY - convert CIEXYZ to CIEuvY
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIEXYZToCIEuvY(
+ XcmsCCC ccc,
+ XcmsColor *puvY_WhitePt,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors)
+/*
+ * DESCRIPTION
+ * Converts color specifications in an array of XcmsColor
+ * structures from CIEXYZ format to CIEuvY format.
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if succeeded.
+ *
+ */
+{
+ XcmsCIEuvY uvY_return;
+ XcmsColor whitePt;
+ int i;
+ XcmsColor *pColor = pColors_in_out;
+ XcmsFloat div;
+
+ /*
+ * Check arguments
+ * Postpone checking puvY_WhitePt until it is actually needed
+ * otherwise converting between XYZ and uvY will fail.
+ */
+ if (pColors_in_out == NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Now convert each XcmsColor structure to CIEuvY form
+ */
+ for (i = 0; i < nColors; i++, pColor++) {
+
+ /* Make sure original format is CIEXYZ */
+ if (!_XcmsCIEXYZ_ValidSpec(pColor)) {
+ return(XcmsFailure);
+ }
+
+ /* Convert to CIEuvY */
+ div = pColor->spec.CIEXYZ.X + (15.0 * pColor->spec.CIEXYZ.Y) +
+ (3.0 * pColor->spec.CIEXYZ.Z);
+ if (div == 0.0) {
+ /* Use white point since div == 0.0 */
+ if (puvY_WhitePt == NULL ) {
+ return(XcmsFailure);
+ }
+ /*
+ * Make sure white point is in CIEuvY form
+ */
+ if (puvY_WhitePt->format != XcmsCIEuvYFormat) {
+ /* Make copy of the white point because we're going to modify it */
+ memcpy((char *)&whitePt, (char *)puvY_WhitePt, sizeof(XcmsColor));
+ if (!_XcmsDIConvertColors(ccc, &whitePt, (XcmsColor *)NULL, 1,
+ XcmsCIEuvYFormat)) {
+ return(XcmsFailure);
+ }
+ puvY_WhitePt = &whitePt;
+ }
+ /* Make sure it is a white point, i.e., Y == 1.0 */
+ if (puvY_WhitePt->spec.CIEuvY.Y != 1.0) {
+ return(XcmsFailure);
+ }
+ uvY_return.Y = pColor->spec.CIEXYZ.Y;
+ uvY_return.u_prime = puvY_WhitePt->spec.CIEuvY.u_prime;
+ uvY_return.v_prime = puvY_WhitePt->spec.CIEuvY.v_prime;
+ } else {
+ uvY_return.u_prime = 4.0 * pColor->spec.CIEXYZ.X / div;
+ uvY_return.v_prime = 9.0 * pColor->spec.CIEXYZ.Y / div;
+ uvY_return.Y = pColor->spec.CIEXYZ.Y;
+ }
+
+ memcpy((char *)&pColor->spec.CIEuvY, (char *)&uvY_return, sizeof(XcmsCIEuvY));
+ /* Identify that format is now CIEuvY */
+ pColor->format = XcmsCIEuvYFormat;
+ }
+
+ return(XcmsSuccess);
+}
diff --git a/libX11/src/xcms/xyY.c b/libX11/src/xcms/xyY.c index 6f9457496..6f6562621 100644 --- a/libX11/src/xcms/xyY.c +++ b/libX11/src/xcms/xyY.c @@ -1,395 +1,395 @@ - -/* - * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. - * All Rights Reserved - * - * This file is a component of an X Window System-specific implementation - * of Xcms based on the TekColor Color Management System. Permission is - * hereby granted to use, copy, modify, sell, and otherwise distribute this - * software and its documentation for any purpose and without fee, provided - * that this copyright, permission, and disclaimer notice is reproduced in - * all copies of this software and in supporting documentation. TekColor - * is a trademark of Tektronix, Inc. - * - * Tektronix makes no representation about the suitability of this software - * for any purpose. It is provided "as is" and with all faults. - * - * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, - * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. - * - * NAME - * CIExyY.c - * - * DESCRIPTION - * This file contains routines that support the CIE xyY - * color space to include conversions to and from the CIE - * XYZ space. - * - * DOCUMENTATION - * "TekColor Color Management System, System Implementor's Manual" - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <stdio.h> -#include <X11/Xos.h> -#include "Xlibint.h" -#include "Xcmsint.h" -#include "Cv.h" - -/* - * DEFINES - */ -#define EPS 0.00001 /* some extremely small number */ -#ifdef DBL_EPSILON -# define XMY_DBL_EPSILON DBL_EPSILON -#else -# define XMY_DBL_EPSILON 0.00001 -#endif - -/* - * FORWARD DECLARATIONS - */ - -static int CIExyY_ParseString(register char *spec, XcmsColor *pColor); -static Status XcmsCIExyY_ValidSpec(XcmsColor *pColor); - - -/* - * LOCAL VARIABLES - */ - - /* - * NULL terminated list of functions applied to get from CIExyY to CIEXYZ - */ -static XcmsConversionProc Fl_CIExyY_to_CIEXYZ[] = { - XcmsCIExyYToCIEXYZ, - NULL -}; - - /* - * NULL terminated list of functions applied to get from CIEXYZ to CIExyY - */ -static XcmsConversionProc Fl_CIEXYZ_to_CIExyY[] = { - XcmsCIEXYZToCIExyY, - NULL -}; - - -/* - * GLOBALS - */ - - /* - * CIE xyY Color Space - */ -XcmsColorSpace XcmsCIExyYColorSpace = - { - _XcmsCIExyY_prefix, /* prefix */ - XcmsCIExyYFormat, /* id */ - CIExyY_ParseString, /* parseString */ - Fl_CIExyY_to_CIEXYZ, /* to_CIEXYZ */ - Fl_CIEXYZ_to_CIExyY, /* from_CIEXYZ */ - 1 - }; - - - -/************************************************************************ - * * - * PRIVATE ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * CIExyY_ParseString - * - * SYNOPSIS - */ -static int -CIExyY_ParseString( - register char *spec, - XcmsColor *pColor) -/* - * DESCRIPTION - * This routines takes a string and attempts to convert - * it into a XcmsColor structure with XcmsCIExyYFormat. - * The assumed CIExyY string syntax is: - * CIExyY:<x>/<y>/<Y> - * Where x, y, and Y are in string input format for floats - * consisting of: - * a. an optional sign - * b. a string of numbers possibly containing a decimal point, - * c. an optional exponent field containing an 'E' or 'e' - * followed by a possibly signed integer string. - * - * RETURNS - * 0 if failed, non-zero otherwise. - */ -{ - int n; - char *pchar; - - if ((pchar = strchr(spec, ':')) == NULL) { - return(XcmsFailure); - } - n = (int)(pchar - spec); - - /* - * Check for proper prefix. - */ - if (strncmp(spec, _XcmsCIExyY_prefix, n) != 0) { - return(XcmsFailure); - } - - /* - * Attempt to parse the value portion. - */ - if (sscanf(spec + n + 1, "%lf/%lf/%lf", - &pColor->spec.CIExyY.x, - &pColor->spec.CIExyY.y, - &pColor->spec.CIExyY.Y) != 3) { - char *s; /* Maybe failed due to locale */ - int f; - if ((s = strdup(spec))) { - for (f = 0; s[f]; ++f) - if (s[f] == '.') - s[f] = ','; - else if (s[f] == ',') - s[f] = '.'; - if (sscanf(s + n + 1, "%lf/%lf/%lf", - &pColor->spec.CIExyY.x, - &pColor->spec.CIExyY.y, - &pColor->spec.CIExyY.Y) != 3) { - free(s); - return(XcmsFailure); - } - free(s); - } else - return(XcmsFailure); - } - pColor->format = XcmsCIExyYFormat; - pColor->pixel = 0; - return(XcmsCIExyY_ValidSpec(pColor)); -} - - - -/************************************************************************ - * * - * PUBLIC ROUTINES * - * * - ************************************************************************/ - -/* - * NAME - * CIExyY_ValidSpec() - * - * SYNOPSIS - */ -static Status -XcmsCIExyY_ValidSpec( - XcmsColor *pColor) -/* - * DESCRIPTION - * Checks a valid CIExyY color specification. - * - * RETURNS - * XcmsFailure if invalid. - * XcmsSuccess if valid. - * - */ -{ - if (pColor->format != XcmsCIExyYFormat - || - (pColor->spec.CIExyY.x < 0.0 - XMY_DBL_EPSILON) - || - (pColor->spec.CIExyY.x > 1.0 + XMY_DBL_EPSILON) - || - (pColor->spec.CIExyY.y < 0.0 - XMY_DBL_EPSILON) - || - (pColor->spec.CIExyY.y > 1.0 + XMY_DBL_EPSILON) - || - (pColor->spec.CIExyY.Y < 0.0 - XMY_DBL_EPSILON) - || - (pColor->spec.CIExyY.Y > 1.0 + XMY_DBL_EPSILON)) { - return(XcmsFailure); - } - return(XcmsSuccess); -} - - -/* - * NAME - * XcmsCIExyYToCIEXYZ - convert CIExyY to CIEXYZ - * - * SYNOPSIS - */ -Status -XcmsCIExyYToCIEXYZ( - XcmsCCC ccc, - XcmsColor *pxyY_WhitePt, - XcmsColor *pColors_in_out, - unsigned int nColors) -/* - * DESCRIPTION - * Converts color specifications in an array of XcmsColor - * structures from CIExyY format to CIEXYZ format. - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if succeeded. - */ -{ - XcmsColor *pColor = pColors_in_out; - XcmsColor whitePt; - XcmsCIEXYZ XYZ_return; - XcmsFloat div; /* temporary storage in case divisor is zero */ - XcmsFloat u, v, x, y, z; /* temporary storage */ - register int i; - - /* - * Check arguments - */ - if (pxyY_WhitePt == NULL || pColors_in_out == NULL) { - return(XcmsFailure); - } - - - /* - * Now convert each XcmsColor structure to CIEXYZ form - */ - for (i = 0; i < nColors; i++, pColor++) { - /* Make sure original format is CIExyY and valid */ - if (!XcmsCIExyY_ValidSpec(pColor)) { - return(XcmsFailure); - } - - if ((div = (-2 * pColor->spec.CIExyY.x) + (12 * pColor->spec.CIExyY.y) + 3) == 0.0) { - /* Note that the divisor is zero */ - /* This return is abitrary. */ - XYZ_return.X = 0; - XYZ_return.Y = 0; - XYZ_return.Z = 0; - } else { - /* - * Make sure white point is in CIEXYZ form - */ - if (pxyY_WhitePt->format != XcmsCIEXYZFormat) { - /* Make copy of the white point because we're going to modify it */ - memcpy((char *)&whitePt, (char *)pxyY_WhitePt, sizeof(XcmsColor)); - if (!_XcmsDIConvertColors(ccc, &whitePt, (XcmsColor *)NULL, 1, - XcmsCIEXYZFormat)) { - return(XcmsFailure); - } - pxyY_WhitePt = &whitePt; - } - - /* Make sure it is a white point, i.e., Y == 1.0 */ - if (pxyY_WhitePt->spec.CIEXYZ.Y != 1.0) { - return(XcmsFailure); - } - - /* Convert from xyY to uvY to XYZ */ - u = (4 * pColor->spec.CIExyY.x) / div; - v = (9 * pColor->spec.CIExyY.y) / div; - div = (6.0 * u) - (16.0 * v) + 12.0; - if (div == 0.0) { - /* Note that the divisor is zero */ - /* This return is abitrary. */ - if ((div = (6.0 * whitePt.spec.CIEuvY.u_prime) - - (16.0 * whitePt.spec.CIEuvY.v_prime) + 12.0) == 0.0) { - div = EPS; - } - x = 9.0 * whitePt.spec.CIEuvY.u_prime / div; - y = 4.0 * whitePt.spec.CIEuvY.u_prime / div; - } else { - /* convert u, v to small xyz */ - x = 9.0 * u / div; - y = 4.0 * v / div; - } - z = 1.0 - x - y; - if (y == 0.0) y = EPS; /* Have to worry about divide by 0 */ - XYZ_return.Y = pColor->spec.CIExyY.Y; - XYZ_return.X = x * XYZ_return.Y / y; - XYZ_return.Z = z * XYZ_return.Y / y; - } - - /* Copy result to pColor */ - memcpy ((char *)&pColor->spec, (char *)&XYZ_return, sizeof(XcmsCIEXYZ)); - - /* Identify that the format is now CIEXYZ */ - pColor->format = XcmsCIEXYZFormat; - } - return(XcmsSuccess); -} - - -/* - * NAME - * XcmsCIEXYZToCIExyY - convert CIEXYZ to CIExyY - * - * SYNOPSIS - */ -/* ARGSUSED */ -Status -XcmsCIEXYZToCIExyY( - XcmsCCC ccc, - XcmsColor *pxyY_WhitePt, - XcmsColor *pColors_in_out, - unsigned int nColors) -/* - * DESCRIPTION - * Converts color specifications in an array of XcmsColor - * structures from CIEXYZ format to CIExyY format. - * - * RETURNS - * XcmsFailure if failed, - * XcmsSuccess if succeeded. - * - */ -{ - XcmsColor *pColor = pColors_in_out; - XcmsCIExyY xyY_return; - XcmsFloat div; /* temporary storage in case divisor is zero */ - register int i; - - /* - * Check arguments - * pxyY_WhitePt ignored - */ - if (pColors_in_out == NULL) { - return(XcmsFailure); - } - - /* - * Now convert each XcmsColor structure to CIEXYZ form - */ - for (i = 0; i < nColors; i++, pColor++) { - - if (!_XcmsCIEXYZ_ValidSpec(pColor)) { - return(XcmsFailure); - } - /* Now convert for XYZ to xyY */ - if ((div = pColor->spec.CIEXYZ.X + pColor->spec.CIEXYZ.Y + pColor->spec.CIEXYZ.Z) == 0.0) { - div = EPS; - } - xyY_return.x = pColor->spec.CIEXYZ.X / div; - xyY_return.y = pColor->spec.CIEXYZ.Y / div; - xyY_return.Y = pColor->spec.CIEXYZ.Y; - - /* Copy result to pColor */ - memcpy ((char *)&pColor->spec, (char *)&xyY_return, sizeof(XcmsCIExyY)); - - /* Identify that the format is now CIEXYZ */ - pColor->format = XcmsCIExyYFormat; - } - return(XcmsSuccess); -} +
+/*
+ * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
+ * All Rights Reserved
+ *
+ * This file is a component of an X Window System-specific implementation
+ * of Xcms based on the TekColor Color Management System. Permission is
+ * hereby granted to use, copy, modify, sell, and otherwise distribute this
+ * software and its documentation for any purpose and without fee, provided
+ * that this copyright, permission, and disclaimer notice is reproduced in
+ * all copies of this software and in supporting documentation. TekColor
+ * is a trademark of Tektronix, Inc.
+ *
+ * Tektronix makes no representation about the suitability of this software
+ * for any purpose. It is provided "as is" and with all faults.
+ *
+ * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
+ * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
+ *
+ * NAME
+ * CIExyY.c
+ *
+ * DESCRIPTION
+ * This file contains routines that support the CIE xyY
+ * color space to include conversions to and from the CIE
+ * XYZ space.
+ *
+ * DOCUMENTATION
+ * "TekColor Color Management System, System Implementor's Manual"
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <X11/Xos.h>
+#include "Xlibint.h"
+#include "Xcmsint.h"
+#include "Cv.h"
+
+/*
+ * DEFINES
+ */
+#define EPS 0.00001 /* some extremely small number */
+#ifdef DBL_EPSILON
+# define XMY_DBL_EPSILON DBL_EPSILON
+#else
+# define XMY_DBL_EPSILON 0.00001
+#endif
+
+/*
+ * FORWARD DECLARATIONS
+ */
+
+static int CIExyY_ParseString(register char *spec, XcmsColor *pColor);
+static Status XcmsCIExyY_ValidSpec(XcmsColor *pColor);
+
+
+/*
+ * LOCAL VARIABLES
+ */
+
+ /*
+ * NULL terminated list of functions applied to get from CIExyY to CIEXYZ
+ */
+static XcmsConversionProc Fl_CIExyY_to_CIEXYZ[] = {
+ XcmsCIExyYToCIEXYZ,
+ NULL
+};
+
+ /*
+ * NULL terminated list of functions applied to get from CIEXYZ to CIExyY
+ */
+static XcmsConversionProc Fl_CIEXYZ_to_CIExyY[] = {
+ XcmsCIEXYZToCIExyY,
+ NULL
+};
+
+
+/*
+ * GLOBALS
+ */
+
+ /*
+ * CIE xyY Color Space
+ */
+XcmsColorSpace XcmsCIExyYColorSpace =
+ {
+ _XcmsCIExyY_prefix, /* prefix */
+ XcmsCIExyYFormat, /* id */
+ CIExyY_ParseString, /* parseString */
+ Fl_CIExyY_to_CIEXYZ, /* to_CIEXYZ */
+ Fl_CIEXYZ_to_CIExyY, /* from_CIEXYZ */
+ 1
+ };
+
+
+
+/************************************************************************
+ * *
+ * PRIVATE ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * CIExyY_ParseString
+ *
+ * SYNOPSIS
+ */
+static int
+CIExyY_ParseString(
+ register char *spec,
+ XcmsColor *pColor)
+/*
+ * DESCRIPTION
+ * This routines takes a string and attempts to convert
+ * it into a XcmsColor structure with XcmsCIExyYFormat.
+ * The assumed CIExyY string syntax is:
+ * CIExyY:<x>/<y>/<Y>
+ * Where x, y, and Y are in string input format for floats
+ * consisting of:
+ * a. an optional sign
+ * b. a string of numbers possibly containing a decimal point,
+ * c. an optional exponent field containing an 'E' or 'e'
+ * followed by a possibly signed integer string.
+ *
+ * RETURNS
+ * 0 if failed, non-zero otherwise.
+ */
+{
+ int n;
+ char *pchar;
+
+ if ((pchar = strchr(spec, ':')) == NULL) {
+ return(XcmsFailure);
+ }
+ n = (int)(pchar - spec);
+
+ /*
+ * Check for proper prefix.
+ */
+ if (strncmp(spec, _XcmsCIExyY_prefix, n) != 0) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Attempt to parse the value portion.
+ */
+ if (sscanf(spec + n + 1, "%lf/%lf/%lf",
+ &pColor->spec.CIExyY.x,
+ &pColor->spec.CIExyY.y,
+ &pColor->spec.CIExyY.Y) != 3) {
+ char *s; /* Maybe failed due to locale */
+ int f;
+ if ((s = strdup(spec))) {
+ for (f = 0; s[f]; ++f)
+ if (s[f] == '.')
+ s[f] = ',';
+ else if (s[f] == ',')
+ s[f] = '.';
+ if (sscanf(s + n + 1, "%lf/%lf/%lf",
+ &pColor->spec.CIExyY.x,
+ &pColor->spec.CIExyY.y,
+ &pColor->spec.CIExyY.Y) != 3) {
+ free(s);
+ return(XcmsFailure);
+ }
+ free(s);
+ } else
+ return(XcmsFailure);
+ }
+ pColor->format = XcmsCIExyYFormat;
+ pColor->pixel = 0;
+ return(XcmsCIExyY_ValidSpec(pColor));
+}
+
+
+
+/************************************************************************
+ * *
+ * PUBLIC ROUTINES *
+ * *
+ ************************************************************************/
+
+/*
+ * NAME
+ * CIExyY_ValidSpec()
+ *
+ * SYNOPSIS
+ */
+static Status
+XcmsCIExyY_ValidSpec(
+ XcmsColor *pColor)
+/*
+ * DESCRIPTION
+ * Checks a valid CIExyY color specification.
+ *
+ * RETURNS
+ * XcmsFailure if invalid.
+ * XcmsSuccess if valid.
+ *
+ */
+{
+ if (pColor->format != XcmsCIExyYFormat
+ ||
+ (pColor->spec.CIExyY.x < 0.0 - XMY_DBL_EPSILON)
+ ||
+ (pColor->spec.CIExyY.x > 1.0 + XMY_DBL_EPSILON)
+ ||
+ (pColor->spec.CIExyY.y < 0.0 - XMY_DBL_EPSILON)
+ ||
+ (pColor->spec.CIExyY.y > 1.0 + XMY_DBL_EPSILON)
+ ||
+ (pColor->spec.CIExyY.Y < 0.0 - XMY_DBL_EPSILON)
+ ||
+ (pColor->spec.CIExyY.Y > 1.0 + XMY_DBL_EPSILON)) {
+ return(XcmsFailure);
+ }
+ return(XcmsSuccess);
+}
+
+
+/*
+ * NAME
+ * XcmsCIExyYToCIEXYZ - convert CIExyY to CIEXYZ
+ *
+ * SYNOPSIS
+ */
+Status
+XcmsCIExyYToCIEXYZ(
+ XcmsCCC ccc,
+ XcmsColor *pxyY_WhitePt,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors)
+/*
+ * DESCRIPTION
+ * Converts color specifications in an array of XcmsColor
+ * structures from CIExyY format to CIEXYZ format.
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if succeeded.
+ */
+{
+ XcmsColor *pColor = pColors_in_out;
+ XcmsColor whitePt;
+ XcmsCIEXYZ XYZ_return;
+ XcmsFloat div; /* temporary storage in case divisor is zero */
+ XcmsFloat u, v, x, y, z; /* temporary storage */
+ register int i;
+
+ /*
+ * Check arguments
+ */
+ if (pxyY_WhitePt == NULL || pColors_in_out == NULL) {
+ return(XcmsFailure);
+ }
+
+
+ /*
+ * Now convert each XcmsColor structure to CIEXYZ form
+ */
+ for (i = 0; i < nColors; i++, pColor++) {
+ /* Make sure original format is CIExyY and valid */
+ if (!XcmsCIExyY_ValidSpec(pColor)) {
+ return(XcmsFailure);
+ }
+
+ if ((div = (-2 * pColor->spec.CIExyY.x) + (12 * pColor->spec.CIExyY.y) + 3) == 0.0) {
+ /* Note that the divisor is zero */
+ /* This return is abitrary. */
+ XYZ_return.X = 0;
+ XYZ_return.Y = 0;
+ XYZ_return.Z = 0;
+ } else {
+ /*
+ * Make sure white point is in CIEXYZ form
+ */
+ if (pxyY_WhitePt->format != XcmsCIEXYZFormat) {
+ /* Make copy of the white point because we're going to modify it */
+ memcpy((char *)&whitePt, (char *)pxyY_WhitePt, sizeof(XcmsColor));
+ if (!_XcmsDIConvertColors(ccc, &whitePt, (XcmsColor *)NULL, 1,
+ XcmsCIEXYZFormat)) {
+ return(XcmsFailure);
+ }
+ pxyY_WhitePt = &whitePt;
+ }
+
+ /* Make sure it is a white point, i.e., Y == 1.0 */
+ if (pxyY_WhitePt->spec.CIEXYZ.Y != 1.0) {
+ return(XcmsFailure);
+ }
+
+ /* Convert from xyY to uvY to XYZ */
+ u = (4 * pColor->spec.CIExyY.x) / div;
+ v = (9 * pColor->spec.CIExyY.y) / div;
+ div = (6.0 * u) - (16.0 * v) + 12.0;
+ if (div == 0.0) {
+ /* Note that the divisor is zero */
+ /* This return is abitrary. */
+ if ((div = (6.0 * whitePt.spec.CIEuvY.u_prime) -
+ (16.0 * whitePt.spec.CIEuvY.v_prime) + 12.0) == 0.0) {
+ div = EPS;
+ }
+ x = 9.0 * whitePt.spec.CIEuvY.u_prime / div;
+ y = 4.0 * whitePt.spec.CIEuvY.u_prime / div;
+ } else {
+ /* convert u, v to small xyz */
+ x = 9.0 * u / div;
+ y = 4.0 * v / div;
+ }
+ z = 1.0 - x - y;
+ if (y == 0.0) y = EPS; /* Have to worry about divide by 0 */
+ XYZ_return.Y = pColor->spec.CIExyY.Y;
+ XYZ_return.X = x * XYZ_return.Y / y;
+ XYZ_return.Z = z * XYZ_return.Y / y;
+ }
+
+ /* Copy result to pColor */
+ memcpy ((char *)&pColor->spec, (char *)&XYZ_return, sizeof(XcmsCIEXYZ));
+
+ /* Identify that the format is now CIEXYZ */
+ pColor->format = XcmsCIEXYZFormat;
+ }
+ return(XcmsSuccess);
+}
+
+
+/*
+ * NAME
+ * XcmsCIEXYZToCIExyY - convert CIEXYZ to CIExyY
+ *
+ * SYNOPSIS
+ */
+/* ARGSUSED */
+Status
+XcmsCIEXYZToCIExyY(
+ XcmsCCC ccc,
+ XcmsColor *pxyY_WhitePt,
+ XcmsColor *pColors_in_out,
+ unsigned int nColors)
+/*
+ * DESCRIPTION
+ * Converts color specifications in an array of XcmsColor
+ * structures from CIEXYZ format to CIExyY format.
+ *
+ * RETURNS
+ * XcmsFailure if failed,
+ * XcmsSuccess if succeeded.
+ *
+ */
+{
+ XcmsColor *pColor = pColors_in_out;
+ XcmsCIExyY xyY_return;
+ XcmsFloat div; /* temporary storage in case divisor is zero */
+ register int i;
+
+ /*
+ * Check arguments
+ * pxyY_WhitePt ignored
+ */
+ if (pColors_in_out == NULL) {
+ return(XcmsFailure);
+ }
+
+ /*
+ * Now convert each XcmsColor structure to CIEXYZ form
+ */
+ for (i = 0; i < nColors; i++, pColor++) {
+
+ if (!_XcmsCIEXYZ_ValidSpec(pColor)) {
+ return(XcmsFailure);
+ }
+ /* Now convert for XYZ to xyY */
+ if ((div = pColor->spec.CIEXYZ.X + pColor->spec.CIEXYZ.Y + pColor->spec.CIEXYZ.Z) == 0.0) {
+ div = EPS;
+ }
+ xyY_return.x = pColor->spec.CIEXYZ.X / div;
+ xyY_return.y = pColor->spec.CIEXYZ.Y / div;
+ xyY_return.Y = pColor->spec.CIEXYZ.Y;
+
+ /* Copy result to pColor */
+ memcpy ((char *)&pColor->spec, (char *)&xyY_return, sizeof(XcmsCIExyY));
+
+ /* Identify that the format is now CIEXYZ */
+ pColor->format = XcmsCIExyYFormat;
+ }
+ return(XcmsSuccess);
+}
|