AddSF.c revision 61b2299d
1/* $Xorg: AddSF.c,v 1.3 2000/08/17 19:44:29 cpqbld Exp $ */ 2 3/* 4 * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. 5 * All Rights Reserved 6 * 7 * This file is a component of an X Window System-specific implementation 8 * of Xcms based on the TekColor Color Management System. Permission is 9 * hereby granted to use, copy, modify, sell, and otherwise distribute this 10 * software and its documentation for any purpose and without fee, provided 11 * that this copyright, permission, and disclaimer notice is reproduced in 12 * all copies of this software and in supporting documentation. TekColor 13 * is a trademark of Tektronix, Inc. 14 * 15 * Tektronix makes no representation about the suitability of this software 16 * for any purpose. It is provided "as is" and with all faults. 17 * 18 * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, 19 * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 20 * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY 21 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 22 * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF 23 * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 24 * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. 25 * 26 * 27 * NAME 28 * XcmsAddSF.c 29 * 30 * DESCRIPTION 31 * Source for XcmsAddFunctionSet 32 * 33 * 34 */ 35/* $XFree86$ */ 36 37#ifdef HAVE_CONFIG_H 38#include <config.h> 39#endif 40#include "Xlibint.h" 41#include "Xcmsint.h" 42#include "Cv.h" 43 44/* 45 * DEFINES 46 */ 47#define NextUnregDdCsID(lastid) \ 48 (XCMS_UNREG_ID(lastid) ? ++lastid : XCMS_FIRST_UNREG_DD_ID) 49#define MIN(x,y) ((x) > (y) ? (y) : (x)) 50 51 52/* 53 * NAME 54 * XcmsAddFunctionSet - Add an Screen Color Characterization 55 * Function Set 56 * 57 * SYNOPSIS 58 */ 59Status 60XcmsAddFunctionSet(XcmsFunctionSet *pNewFS) 61/* 62 * DESCRIPTION 63 * Additional Screen Color Characterization Function Sets are 64 * managed on a global basis. This means that with exception 65 * of the provided DD color spaces: 66 * RGB and RGBi 67 * DD color spaces may have different XcmsColorFormat IDs between 68 * clients. So, you must be careful when using XcmsColorFormat 69 * across clients! Use the routines XcmsFormatOfPrefix() 70 * and XcmsPrefixOfFormat() appropriately. 71 * 72 * RETURNS 73 * XcmsSuccess if succeeded, otherwise XcmsFailure 74 * 75 * CAVEATS 76 * Additional Screen Color Characterization Function Sets 77 * should be added prior to any use of the routine 78 * XcmsCreateCCC(). If not, XcmsCCC structures created 79 * prior to the call of this routines will not have had 80 * a chance to initialize using the added Screen Color 81 * Characterization Function Set. 82 */ 83{ 84 XcmsFunctionSet **papSCCFuncSets = _XcmsSCCFuncSets; 85 XcmsColorSpace **papNewCSs; 86 XcmsColorSpace *pNewCS, **paptmpCS; 87 XcmsColorFormat lastID = 0; 88 89 90 if (papSCCFuncSets != NULL) { 91 if ((papNewCSs = pNewFS->DDColorSpaces) == NULL) { 92 /* 93 * Error, new Screen Color Characterization Function Set 94 * missing color spaces 95 */ 96 return(XcmsFailure); 97 } 98 while ((pNewCS = *papNewCSs++) != NULL) { 99 if ((pNewCS->id = _XcmsRegFormatOfPrefix(pNewCS->prefix)) != 0) { 100 if (XCMS_DI_ID(pNewCS->id)) { 101 /* This is a Device-Independent Color Space */ 102 return(XcmsFailure); 103 } 104 /* 105 * REGISTERED DD Color Space 106 * therefore use the registered ID. 107 */ 108 } else { 109 /* 110 * UNREGISTERED DD Color Space 111 * then see if the color space is already in 112 * _XcmsDDColorSpaces. 113 * a. If same prefix, then use the same ID. 114 * b. Otherwise, use a new ID. 115 */ 116 for (paptmpCS = _XcmsDDColorSpaces; *paptmpCS != NULL; 117 paptmpCS++){ 118 lastID = MIN(lastID, (*paptmpCS)->id); 119 if (strcmp(pNewCS->prefix, (*paptmpCS)->prefix) == 0) { 120 pNewCS->id = (*paptmpCS)->id; 121 break; 122 } 123 } 124 if (pNewCS->id == 0) { 125 /* still haven't found one */ 126 pNewCS->id = NextUnregDdCsID(lastID); 127 if ((paptmpCS = (XcmsColorSpace **)_XcmsPushPointerArray( 128 (XPointer *) _XcmsDDColorSpaces, 129 (XPointer) pNewCS, 130 (XPointer *) _XcmsDDColorSpacesInit)) == NULL) { 131 return(XcmsFailure); 132 } 133 _XcmsDDColorSpaces = paptmpCS; 134 } 135 } 136 } 137 } 138 if ((papSCCFuncSets = (XcmsFunctionSet **) 139 _XcmsPushPointerArray((XPointer *) _XcmsSCCFuncSets, 140 (XPointer) pNewFS, 141 (XPointer *)_XcmsSCCFuncSetsInit)) == NULL) { 142 return(XcmsFailure); 143 } 144 _XcmsSCCFuncSets = papSCCFuncSets; 145 146 return(XcmsSuccess); 147} 148