11ab64890Smrg
21ab64890Smrg/*
31ab64890Smrg * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
41ab64890Smrg * 	All Rights Reserved
561b2299dSmrg *
61ab64890Smrg * This file is a component of an X Window System-specific implementation
71ab64890Smrg * of Xcms based on the TekColor Color Management System.  Permission is
81ab64890Smrg * hereby granted to use, copy, modify, sell, and otherwise distribute this
91ab64890Smrg * software and its documentation for any purpose and without fee, provided
101ab64890Smrg * that this copyright, permission, and disclaimer notice is reproduced in
111ab64890Smrg * all copies of this software and in supporting documentation.  TekColor
121ab64890Smrg * is a trademark of Tektronix, Inc.
1361b2299dSmrg *
141ab64890Smrg * Tektronix makes no representation about the suitability of this software
151ab64890Smrg * for any purpose.  It is provided "as is" and with all faults.
1661b2299dSmrg *
171ab64890Smrg * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
181ab64890Smrg * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
191ab64890Smrg * PARTICULAR PURPOSE.  IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
201ab64890Smrg * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
211ab64890Smrg * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
221ab64890Smrg * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
231ab64890Smrg * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
241ab64890Smrg *
251ab64890Smrg *
261ab64890Smrg *	NAME
271ab64890Smrg *		XcmsAddSF.c
281ab64890Smrg *
291ab64890Smrg *	DESCRIPTION
301ab64890Smrg *		Source for XcmsAddFunctionSet
311ab64890Smrg *
321ab64890Smrg *
331ab64890Smrg */
341ab64890Smrg
351ab64890Smrg#ifdef HAVE_CONFIG_H
361ab64890Smrg#include <config.h>
371ab64890Smrg#endif
381ab64890Smrg#include "Xlibint.h"
391ab64890Smrg#include "Xcmsint.h"
401ab64890Smrg#include "Cv.h"
411ab64890Smrg
421ab64890Smrg/*
431ab64890Smrg *      DEFINES
441ab64890Smrg */
451ab64890Smrg#define NextUnregDdCsID(lastid) \
461ab64890Smrg	    (XCMS_UNREG_ID(lastid) ? ++lastid : XCMS_FIRST_UNREG_DD_ID)
471ab64890Smrg#define MIN(x,y) ((x) > (y) ? (y) : (x))
481ab64890Smrg
491ab64890Smrg
501ab64890Smrg/*
511ab64890Smrg *	NAME
521ab64890Smrg *		XcmsAddFunctionSet - Add an Screen Color Characterization
531ab64890Smrg *					Function Set
541ab64890Smrg *
551ab64890Smrg *	SYNOPSIS
561ab64890Smrg */
571ab64890SmrgStatus
581ab64890SmrgXcmsAddFunctionSet(XcmsFunctionSet *pNewFS)
591ab64890Smrg/*
601ab64890Smrg *	DESCRIPTION
611ab64890Smrg *		Additional Screen Color Characterization Function Sets are
621ab64890Smrg *		managed on a global basis.  This means that with exception
631ab64890Smrg *		of the provided DD color spaces:
641ab64890Smrg *			    RGB and RGBi
651ab64890Smrg *		DD color spaces may have different XcmsColorFormat IDs between
661ab64890Smrg *		clients.  So, you must be careful when using XcmsColorFormat
671ab64890Smrg *		across clients!  Use the routines XcmsFormatOfPrefix()
681ab64890Smrg *		and XcmsPrefixOfFormat() appropriately.
691ab64890Smrg *
701ab64890Smrg *	RETURNS
711ab64890Smrg *		XcmsSuccess if succeeded, otherwise XcmsFailure
721ab64890Smrg *
731ab64890Smrg *	CAVEATS
741ab64890Smrg *		Additional Screen Color Characterization Function Sets
751ab64890Smrg *		should be added prior to any use of the routine
761ab64890Smrg *		XcmsCreateCCC().  If not, XcmsCCC structures created
771ab64890Smrg *		prior to the call of this routines will not have had
781ab64890Smrg *		a chance to initialize using the added Screen Color
791ab64890Smrg *		Characterization Function Set.
801ab64890Smrg */
811ab64890Smrg{
821ab64890Smrg    XcmsFunctionSet **papSCCFuncSets = _XcmsSCCFuncSets;
831ab64890Smrg    XcmsColorSpace **papNewCSs;
841ab64890Smrg    XcmsColorSpace *pNewCS, **paptmpCS;
851ab64890Smrg    XcmsColorFormat lastID = 0;
861ab64890Smrg
871ab64890Smrg
881ab64890Smrg    if (papSCCFuncSets != NULL) {
891ab64890Smrg	if ((papNewCSs = pNewFS->DDColorSpaces) == NULL) {
901ab64890Smrg	    /*
911ab64890Smrg	     * Error, new Screen Color Characterization Function Set
921ab64890Smrg	     *	missing color spaces
931ab64890Smrg	     */
941ab64890Smrg	    return(XcmsFailure);
951ab64890Smrg	}
961ab64890Smrg	while ((pNewCS = *papNewCSs++) != NULL) {
971ab64890Smrg	    if ((pNewCS->id = _XcmsRegFormatOfPrefix(pNewCS->prefix)) != 0) {
981ab64890Smrg		if (XCMS_DI_ID(pNewCS->id)) {
991ab64890Smrg		    /* This is a Device-Independent Color Space */
1001ab64890Smrg		    return(XcmsFailure);
1011ab64890Smrg		}
1021ab64890Smrg		/*
1031ab64890Smrg		 * REGISTERED DD Color Space
1041ab64890Smrg		 *    therefore use the registered ID.
1051ab64890Smrg		 */
1061ab64890Smrg	    } else {
1071ab64890Smrg		/*
1081ab64890Smrg		 * UNREGISTERED DD Color Space
1091ab64890Smrg		 *    then see if the color space is already in
1101ab64890Smrg		 *    _XcmsDDColorSpaces.
1111ab64890Smrg		 *	    a. If same prefix, then use the same ID.
1121ab64890Smrg		 *	    b. Otherwise, use a new ID.
1131ab64890Smrg		 */
1141ab64890Smrg		for (paptmpCS = _XcmsDDColorSpaces; *paptmpCS != NULL;
1151ab64890Smrg			paptmpCS++){
1161ab64890Smrg		    lastID = MIN(lastID, (*paptmpCS)->id);
1171ab64890Smrg		    if (strcmp(pNewCS->prefix, (*paptmpCS)->prefix) == 0) {
1181ab64890Smrg			pNewCS->id = (*paptmpCS)->id;
1191ab64890Smrg			break;
1201ab64890Smrg		    }
1211ab64890Smrg		}
1221ab64890Smrg		if (pNewCS->id == 0) {
1231ab64890Smrg		    /* still haven't found one */
1241ab64890Smrg		    pNewCS->id = NextUnregDdCsID(lastID);
1251ab64890Smrg		    if ((paptmpCS = (XcmsColorSpace **)_XcmsPushPointerArray(
1261ab64890Smrg		   	    (XPointer *) _XcmsDDColorSpaces,
1271ab64890Smrg			    (XPointer) pNewCS,
1281ab64890Smrg			    (XPointer *) _XcmsDDColorSpacesInit)) == NULL) {
1291ab64890Smrg			return(XcmsFailure);
1301ab64890Smrg		    }
1311ab64890Smrg		    _XcmsDDColorSpaces = paptmpCS;
1321ab64890Smrg		}
1331ab64890Smrg	    }
1341ab64890Smrg	}
1351ab64890Smrg    }
1361ab64890Smrg    if ((papSCCFuncSets = (XcmsFunctionSet **)
1371ab64890Smrg	    _XcmsPushPointerArray((XPointer *) _XcmsSCCFuncSets,
1381ab64890Smrg	    (XPointer) pNewFS,
1391ab64890Smrg	    (XPointer *)_XcmsSCCFuncSetsInit)) == NULL) {
1401ab64890Smrg	return(XcmsFailure);
1411ab64890Smrg    }
1421ab64890Smrg    _XcmsSCCFuncSets = papSCCFuncSets;
1431ab64890Smrg
1441ab64890Smrg    return(XcmsSuccess);
1451ab64890Smrg}
146