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