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 * DESCRIPTION 27 * Private include file for Color Management System. 28 * (i.e., for API internal use only) 29 * 30 */ 31 32#ifndef _XCMSINT_H_ 33#define _XCMSINT_H_ 34 35#include <X11/Xcms.h> 36 37/* 38 * DEFINES 39 */ 40 41 /* 42 * Private Status Value 43 */ 44#define _XCMS_NEWNAME -1 45 46 /* 47 * Color Space ID's are of XcmsColorFormat type. 48 * 49 * bit 31 50 * 0 == Device-Independent 51 * 1 == Device-Dependent 52 * 53 * bit 30: 54 * 0 == Registered with X Consortium 55 * 1 == Unregistered 56 */ 57#define XCMS_DD_ID(id) ((id) & (XcmsColorFormat)0x80000000) 58#define XCMS_DI_ID(id) (!((id) & (XcmsColorFormat)0x80000000)) 59#define XCMS_UNREG_ID(id) ((id) & (XcmsColorFormat)0x40000000) 60#define XCMS_REG_ID(id) (!((id) & (XcmsColorFormat)0x40000000)) 61#define XCMS_FIRST_REG_DI_ID (XcmsColorFormat)0x00000001 62#define XCMS_FIRST_UNREG_DI_ID (XcmsColorFormat)0x40000000 63#define XCMS_FIRST_REG_DD_ID (XcmsColorFormat)0x80000000 64#define XCMS_FIRST_UNREG_DD_ID (XcmsColorFormat)0xc0000000 65 66/* 67 * TYPEDEFS 68 */ 69 70 /* 71 * Structure for caching Colormap info. 72 * This is provided for the Xlib modifications to: 73 * XAllocNamedColor() 74 * XLookupColor() 75 * XParseColor() 76 * XStoreNamedColor() 77 */ 78typedef struct _XcmsCmapRec { 79 Colormap cmapID; 80 Display *dpy; 81 Window windowID; 82 Visual *visual; 83 struct _XcmsCCC *ccc; 84 struct _XcmsCmapRec *pNext; 85} XcmsCmapRec; 86 87 /* 88 * Intensity Record (i.e., value / intensity tuple) 89 */ 90typedef struct _IntensityRec { 91 unsigned short value; 92 XcmsFloat intensity; 93} IntensityRec; 94 95 /* 96 * Intensity Table 97 */ 98typedef struct _IntensityTbl { 99 IntensityRec *pBase; 100 unsigned int nEntries; 101} IntensityTbl; 102 103 /* 104 * Structure for storing per-Visual Intensity Tables (aka gamma maps). 105 */ 106typedef struct _XcmsIntensityMap { 107 VisualID visualID; 108 XPointer screenData; /* pointer to corresponding Screen Color*/ 109 /* Characterization Data */ 110 void (*pFreeScreenData)(XPointer pScreenDataTemp); /* Function that frees a Screen */ 111 /* structure. */ 112 struct _XcmsIntensityMap *pNext; 113} XcmsIntensityMap; 114 115 116 /* 117 * Structure for storing "registered" color space prefix/ID 118 */ 119typedef struct _XcmsRegColorSpaceEntry { 120 const char *prefix; /* Color Space prefix (e.g., "CIEXYZ:") */ 121 XcmsColorFormat id; /* Color Space ID (e.g., XcmsCIEXYZFormat) */ 122} XcmsRegColorSpaceEntry; 123 124 125 /* 126 * Xcms Per Display (i.e. connection) related data 127 */ 128typedef struct _XcmsPerDpyInfo { 129 130 XcmsCCC paDefaultCCC; /* based on default visual of screen */ 131 /* 132 * Pointer to an array of XcmsCCC structures, one for 133 * each screen. 134 */ 135 XcmsCmapRec *pClientCmaps; /* Pointer to linked list of XcmsCmapRec's */ 136 137} XcmsPerDpyInfo, *XcmsPerDpyInfoPtr; 138 139/* 140 * DEFINES 141 */ 142 143#define XDCCC_NUMBER 0x8000000L /* 2**27 per XDCCC */ 144 145#ifdef GRAY 146#define XDCCC_SCREENWHITEPT_ATOM_NAME "XDCCC_GRAY_SCREENWHITEPOINT" 147#define XDCCC_GRAY_CORRECT_ATOM_NAME "XDCCC_GRAY_CORRECTION" 148#endif /* GRAY */ 149 150#ifndef _ConversionValues 151typedef struct _ConversionValues { 152 IntensityTbl IntensityTbl; 153} ConversionValues; 154#endif 155 156#ifdef GRAY 157typedef struct { 158 IntensityTbl *IntensityTbl; 159} GRAY_SCCData; 160#endif /* GRAY */ 161 162/* 163 * DEFINES 164 */ 165 166#define XDCCC_MATRIX_ATOM_NAME "XDCCC_LINEAR_RGB_MATRICES" 167#define XDCCC_CORRECT_ATOM_NAME "XDCCC_LINEAR_RGB_CORRECTION" 168 169typedef struct { 170 XcmsFloat XYZtoRGBmatrix[3][3]; 171 XcmsFloat RGBtoXYZmatrix[3][3]; 172 IntensityTbl *pRedTbl; 173 IntensityTbl *pGreenTbl; 174 IntensityTbl *pBlueTbl; 175} LINEAR_RGB_SCCData; 176 177/* function prototypes */ 178extern XcmsCmapRec * 179_XcmsAddCmapRec( 180 Display *dpy, 181 Colormap cmap, 182 Window windowID, 183 Visual *visual); 184extern void 185_XcmsRGB_to_XColor( 186 XcmsColor *pColors, 187 XColor *pXColors, 188 unsigned int nColors); 189extern Status 190_XcmsResolveColorString ( 191 XcmsCCC ccc, 192 const char **color_string, 193 XcmsColor *pColor_exact_return, 194 XcmsColorFormat result_format); 195extern void 196_XUnresolveColor( 197 XcmsCCC ccc, 198 XColor *pXColor); 199/* 200 * DESCRIPTION 201 * Include file for defining the math macros used in the 202 * XCMS source. Instead of using math library routines 203 * directly, XCMS uses macros so that based on the 204 * definitions here, vendors and sites can specify exactly 205 * what routine will be called (those from libm.a or their 206 * custom routines). If not defined to math library routines 207 * (e.g., sqrt in libm.a), then the client is not forced to 208 * be linked with -lm. 209 */ 210 211#define XCMS_ATAN(x) _XcmsArcTangent(x) 212#define XCMS_COS(x) _XcmsCosine(x) 213#define XCMS_CUBEROOT(x) _XcmsCubeRoot(x) 214#define XCMS_FABS(x) ((x) < 0.0 ? -(x) : (x)) 215#define XCMS_SIN(x) _XcmsSine(x) 216#define XCMS_SQRT(x) _XcmsSquareRoot(x) 217#define XCMS_TAN(x) (XCMS_SIN(x) / XCMS_COS(x)) 218 219double _XcmsArcTangent(double a); 220double _XcmsCosine(double a); 221double _XcmsCubeRoot(double a); 222double _XcmsSine(double a); 223double _XcmsSquareRoot(double a); 224 225/* 226 * DEFINES FOR GAMUT COMPRESSION AND QUERY ROUTINES 227 */ 228#ifndef PI 229# ifdef M_PI 230# define PI M_PI 231# else 232# define PI 3.14159265358979323846264338327950 233# endif /* M_PI */ 234#endif /* PI */ 235#ifndef degrees 236# define degrees(r) ((XcmsFloat)(r) * 180.0 / PI) 237#endif /* degrees */ 238#ifndef radians 239# define radians(d) ((XcmsFloat)(d) * PI / 180.0) 240#endif /* radians */ 241 242#define XCMS_CIEUSTAROFHUE(h,c) \ 243((XCMS_COS((h)) == 0.0) ? (XcmsFloat)0.0 : (XcmsFloat) \ 244((XcmsFloat)(c) / (XcmsFloat)XCMS_SQRT((XCMS_TAN(h) * XCMS_TAN(h)) + \ 245(XcmsFloat)1.0))) 246#define XCMS_CIEVSTAROFHUE(h,c) \ 247((XCMS_COS((h)) == 0.0) ? (XcmsFloat)0.0 : (XcmsFloat) \ 248((XcmsFloat)(c) / (XcmsFloat)XCMS_SQRT(((XcmsFloat)1.0 / \ 249(XcmsFloat)(XCMS_TAN(h) * XCMS_TAN(h))) + (XcmsFloat)1.0))) 250/* this hue is returned in radians */ 251#define XCMS_CIELUV_PMETRIC_HUE(u,v) \ 252(((u) != 0.0) ? XCMS_ATAN( (v) / (u)) : ((v >= 0.0) ? PI / 2 : -(PI / 2))) 253#define XCMS_CIELUV_PMETRIC_CHROMA(u,v) XCMS_SQRT(((u)*(u)) + ((v)*(v))) 254 255#define XCMS_CIEASTAROFHUE(h,c) XCMS_CIEUSTAROFHUE((h), (c)) 256#define XCMS_CIEBSTAROFHUE(h,c) XCMS_CIEVSTAROFHUE((h), (c)) 257#define XCMS_CIELAB_PMETRIC_HUE(a,b) XCMS_CIELUV_PMETRIC_HUE((a), (b)) 258#define XCMS_CIELAB_PMETRIC_CHROMA(a,b) XCMS_CIELUV_PMETRIC_CHROMA((a), (b)) 259 260#endif /* _XCMSINT_H_ */ 261