AddDIC.c revision 1ab64890
1/* $Xorg: AddDIC.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 * XcmsAddDIC.c 29 * 30 * DESCRIPTION 31 * Source for XcmsAddColorSpace 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/* 46 * DEFINES 47 */ 48#define NextUnregDiCsID(lastid) \ 49 (XCMS_UNREG_ID(lastid) ? ++lastid : XCMS_FIRST_UNREG_DI_ID) 50#define MAX(x,y) ((x) < (y) ? (y) : (x)) 51 52 53/* 54 * NAME 55 * XcmsAddColorSpace - Add a Device-Independent Color Space 56 * 57 * SYNOPSIS 58 */ 59Status 60XcmsAddColorSpace(XcmsColorSpace *pCS) 61/* 62 * DESCRIPTION 63 * DI Color Spaces are managed on a global basis. 64 * This means that with exception of the provided DI color spaces: 65 * CIEXYZ, CIExyY, CIELab, CIEuvY, CIELuv, and TekHVC 66 * DI color spaces may have different XcmsColorFormat IDs between 67 * clients. So, you must be careful when using XcmsColor 68 * structures between clients! Use the routines XcmsFormatOfPrefix() 69 * and XcmsPrefixOfFormat() appropriately. 70 * 71 * RETURNS 72 * XcmsSuccess if succeeded, otherwise XcmsFailure 73 */ 74{ 75 XcmsColorSpace **papColorSpaces; 76 XcmsColorSpace *ptmpCS; 77 XcmsColorFormat lastID = 0; 78 79 if ((pCS->id = _XcmsRegFormatOfPrefix(pCS->prefix)) != 0) { 80 if (XCMS_DD_ID(pCS->id)) { 81 /* This is a Device-Dependent Color Space */ 82 return(XcmsFailure); 83 } 84 /* 85 * REGISTERED DI Color Space 86 * then see if the color space has already been added to the 87 * system: 88 * a. If the same ID/prefix and same XcmsColorSpec is found, 89 * then its a duplicate, so return success. 90 * b. If same ID/prefix but different XcmsColorSpec is 91 * found, then add the color space to the front of the 92 * list using the same ID. This allows one to override 93 * an existing DI Color Space. 94 * c. Otherwise none found so just add the color space. 95 */ 96 if ((papColorSpaces = _XcmsDIColorSpaces) != NULL) { 97 while ((ptmpCS = *papColorSpaces++) != NULL) { 98 if (pCS->id == ptmpCS->id) { 99 if (pCS == ptmpCS) { 100 /* a. duplicate*/ 101 return(XcmsSuccess); 102 } 103 /* b. same ID/prefix but different XcmsColorSpace */ 104 break; 105 } 106 } 107 } 108 /* c. None found */ 109 } else { 110 /* 111 * UNREGISTERED DI Color Space 112 * then see if the color space has already been added to the 113 * system: 114 * a. If same prefix and XcmsColorSpec, then 115 * its a duplicate ... return success. 116 * b. If same prefix but different XcmsColorSpec, then 117 * add the color space to the front of the list using 118 * the same ID. This allows one to override an existing 119 * DI Color Space. 120 * c. Otherwise none found so, add the color space using the 121 * next unregistered ID for the connection. 122 */ 123 if ((papColorSpaces = _XcmsDIColorSpaces) != NULL) { 124 while ((ptmpCS = *papColorSpaces++) != NULL) { 125 lastID = MAX(lastID, ptmpCS->id); 126 if (strcmp(pCS->prefix, ptmpCS->prefix) == 0) { 127 if (pCS == ptmpCS) { 128 /* a. duplicate */ 129 return(XcmsSuccess); 130 } 131 /* b. same prefix but different XcmsColorSpec */ 132 pCS->id = ptmpCS->id; 133 goto AddColorSpace; 134 } 135 } 136 } 137 /* c. None found */ 138 pCS->id = NextUnregDiCsID(lastID); 139 } 140 141 142AddColorSpace: 143 if ((papColorSpaces = (XcmsColorSpace **) 144 _XcmsPushPointerArray((XPointer *)_XcmsDIColorSpaces, 145 (XPointer)pCS, 146 (XPointer *)_XcmsDIColorSpacesInit)) == NULL) { 147 return(XcmsFailure); 148 } 149 _XcmsDIColorSpaces = papColorSpaces; 150 return(XcmsSuccess); 151} 152