CCC.c revision b4ee4795
1 2/* 3 * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. 4 * All Rights Reserved 5 * 6 * This file is a component of an X Window System-specific implementation 7 * of Xcms based on the TekColor Color Management System. Permission is 8 * hereby granted to use, copy, modify, sell, and otherwise distribute this 9 * software and its documentation for any purpose and without fee, provided 10 * that this copyright, permission, and disclaimer notice is reproduced in 11 * all copies of this software and in supporting documentation. TekColor 12 * is a trademark of Tektronix, Inc. 13 * 14 * Tektronix makes no representation about the suitability of this software 15 * for any purpose. It is provided "as is" and with all faults. 16 * 17 * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, 18 * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY 20 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 21 * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF 22 * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 23 * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. 24 * 25 * 26 * NAME 27 * XcmsCCC.c - Color Conversion Context Routines 28 * 29 * DESCRIPTION 30 * Routines to create, access, and free Color Conversion 31 * Context structures. 32 * 33 * 34 */ 35 36/* 37 38Copyright 1994, 1998 The Open Group 39 40Permission to use, copy, modify, distribute, and sell this software and its 41documentation for any purpose is hereby granted without fee, provided that 42the above copyright notice appear in all copies and that both that 43copyright notice and this permission notice appear in supporting 44documentation. 45 46The above copyright notice and this permission notice shall be included 47in all copies or substantial portions of the Software. 48 49THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 50OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 51MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 52IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 53OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 54ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 55OTHER DEALINGS IN THE SOFTWARE. 56 57Except as contained in this notice, the name of The Open Group shall 58not be used in advertising or otherwise to promote the sale, use or 59other dealings in this Software without prior written authorization 60from The Open Group. 61 62*/ 63 64#ifdef HAVE_CONFIG_H 65#include <config.h> 66#endif 67#include <stdio.h> 68#include "Xlibint.h" 69#include "Xcmsint.h" 70#include "Cv.h" 71 72 73 74/************************************************************************ 75 * * 76 * PUBLIC INTERFACES * 77 * * 78 ************************************************************************/ 79 80/* 81 * NAME 82 * XcmsCreateCCC 83 * 84 * SYNOPSIS 85 */ 86 87XcmsCCC 88XcmsCreateCCC( 89 Display *dpy, 90 int screenNumber, 91 Visual *visual, 92 XcmsColor *clientWhitePt, 93 XcmsCompressionProc gamutCompProc, 94 XPointer gamutCompClientData, 95 XcmsWhiteAdjustProc whitePtAdjProc, 96 XPointer whitePtAdjClientData) 97/* 98 * DESCRIPTION 99 * Given a Display, Screen, Visual, etc., this routine creates 100 * an appropriate Color Conversion Context. 101 * 102 * RETURNS 103 * Returns NULL if failed; otherwise address of the newly 104 * created XcmsCCC. 105 * 106 */ 107{ 108 XcmsCCC pDefaultCCC = XcmsDefaultCCC(dpy, screenNumber); 109 XcmsCCC newccc; 110 XcmsIntensityMap *pIMap; 111 XcmsPerScrnInfo *pNewScrnInfo; 112 113 if (pDefaultCCC == NULL || 114 !(newccc = (XcmsCCC) Xcalloc(1, (unsigned) sizeof(XcmsCCCRec)))) { 115 return(NULL); 116 } 117 118 /* 119 * Should inherit the following as result of a memmove(): 120 * dpy 121 * screenNumber 122 * pPerScrnInfo 123 */ 124 memcpy((char *)newccc, (char *)pDefaultCCC, sizeof(XcmsCCCRec)); 125 if (clientWhitePt) { 126 memcpy((char *)&newccc->clientWhitePt, (char *)clientWhitePt, 127 sizeof(XcmsColor)); 128 } 129 if (gamutCompProc) { 130 newccc->gamutCompProc = gamutCompProc; 131 } 132 if (gamutCompClientData) { 133 newccc->gamutCompClientData = gamutCompClientData; 134 } 135 if (whitePtAdjProc) { 136 newccc->whitePtAdjProc = whitePtAdjProc; 137 } 138 if (whitePtAdjClientData) { 139 newccc->whitePtAdjClientData = whitePtAdjClientData; 140 } 141 142 /* 143 * Now check our list of per-Visual Intensity tables. 144 * If one exists replace the pPerScrnInfo. 145 */ 146 if ((pIMap = _XcmsGetIntensityMap(dpy, visual)) != NULL) { 147 if (!(pNewScrnInfo = (XcmsPerScrnInfo *) 148 Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) { 149 Xfree(newccc); 150 return(NULL); 151 } 152 memcpy((char *)pNewScrnInfo, (char *)newccc->pPerScrnInfo, 153 sizeof(XcmsPerScrnInfo)); 154 pNewScrnInfo->screenData = pIMap->screenData; 155 newccc->pPerScrnInfo = pNewScrnInfo; 156 } 157 158 /* 159 * Set visual component 160 */ 161 newccc->visual = visual; 162 163 return(newccc); 164} 165 166 167/* 168 * NAME 169 * XcmsDefaultCCC 170 * 171 * SYNOPSIS 172 */ 173XcmsCCC 174XcmsDefaultCCC( 175 Display *dpy, 176 int screenNumber) 177/* 178 * DESCRIPTION 179 * Given a Display and Screen, this routine creates 180 * returns the Screen's default Color Conversion Context. 181 * Note that a Screen's default CCC is built with the 182 * screen default visual. 183 * 184 * RETURNS 185 * Returns NULL if failed; otherwise address of the 186 * XcmsCCC for the Screen's default CCC. 187 * 188 */ 189{ 190 XcmsCCC ccc; 191 192 193 if ((screenNumber < 0) || (screenNumber >= ScreenCount(dpy))) { 194 return((XcmsCCC)NULL); 195 } 196 197 /* 198 * Check if the XcmsCCC's for each screen has been created 199 */ 200 if ((XcmsCCC)dpy->cms.defaultCCCs == NULL) { 201 if (!_XcmsInitDefaultCCCs(dpy)) { 202 return((XcmsCCC)NULL); 203 } 204 } 205 206 ccc = (XcmsCCC)dpy->cms.defaultCCCs + screenNumber; 207 208 if (!ccc->pPerScrnInfo) { 209 /* 210 * Need to create the XcmsPerScrnInfo structure. The 211 * _XcmsInitScrnInfo routine will create the XcmsPerScrnInfo 212 * structure as well as initialize its functionSet and pScreenData 213 * components. 214 */ 215 if (!_XcmsInitScrnInfo(dpy, screenNumber)) { 216 return((XcmsCCC)NULL); 217 } 218 return(ccc); 219 } else { 220 /* 221 * If ccc->pPerScrnInfo->state == XcmsInitSuccess, 222 * then the pPerScrnInfo component has already been initialized 223 * therefore, just return ccc. 224 * If ccc->pPerScrnInfo->state == XcmsInitFailure, 225 * then this means that we already attempted to initialize 226 * the pPerScrnInfo component but failed therefore stuffing 227 * the pPerScrnInfo component with defaults. Just return ccc. 228 * If ccc->pPerScrnInfo->state == XcmsInitNone, 229 * then attempt to initialize the pPerScrnInfo component. 230 */ 231 switch (ccc->pPerScrnInfo->state) { 232 case XcmsInitFailure : 233 /* fall through */ 234 case XcmsInitSuccess : 235 return(ccc); 236 case XcmsInitNone : 237 /* XcmsPerScreenInfo has not been initialized */ 238 if (!_XcmsInitScrnInfo(dpy, screenNumber)) { 239 return((XcmsCCC)NULL); 240 } 241 return(ccc); 242 default : 243 return((XcmsCCC)NULL); 244 } 245 } 246} 247 248 249/* 250 * NAME 251 * XcmsFreeCCC 252 * 253 * SYNOPSIS 254 */ 255void 256XcmsFreeCCC(XcmsCCC ccc) 257/* 258 * DESCRIPTION 259 * Frees memory associated with a Color Conversion Context 260 * that was created with XcmsCreateCCC(). 261 * 262 * RETURNS 263 * void 264 * 265 */ 266{ 267 if (ccc->dpy->cms.defaultCCCs && 268 ccc == ((XcmsCCC)ccc->dpy->cms.defaultCCCs) + ccc->screenNumber) { 269 /* do not allow clients to free DefaultCCC's */ 270 return; 271 } 272 273 /* 274 * Note that XcmsPerScrnInfo sub-structures are freed here only if 275 * they are for visuals that have per-Visual intensity tables. 276 * Otherwise the XcmsPerScrnInfo structure is being shared! 277 * For the latter, there is only one allocated per Screen and it just 278 * so happens * that we place its initial reference is placed in the 279 * default CCC. The routine _XcmsFreeDefaultCCCs frees them. 280 */ 281 if (_XcmsGetIntensityMap(ccc->dpy, ccc->visual) != NULL) { 282 Xfree(ccc->pPerScrnInfo); 283 } 284 285 Xfree(ccc); 286} 287