11ab64890Smrg
21ab64890Smrg/*
31ab64890Smrg * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
41ab64890Smrg * 	All Rights Reserved
561b2299dSmrg *
61ab64890Smrg * This file is a component of an X Window System-specific implementation
71ab64890Smrg * of Xcms based on the TekColor Color Management System.  Permission is
81ab64890Smrg * hereby granted to use, copy, modify, sell, and otherwise distribute this
91ab64890Smrg * software and its documentation for any purpose and without fee, provided
101ab64890Smrg * that this copyright, permission, and disclaimer notice is reproduced in
111ab64890Smrg * all copies of this software and in supporting documentation.  TekColor
121ab64890Smrg * is a trademark of Tektronix, Inc.
1361b2299dSmrg *
141ab64890Smrg * Tektronix makes no representation about the suitability of this software
151ab64890Smrg * for any purpose.  It is provided "as is" and with all faults.
1661b2299dSmrg *
171ab64890Smrg * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
181ab64890Smrg * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
191ab64890Smrg * PARTICULAR PURPOSE.  IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
201ab64890Smrg * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
211ab64890Smrg * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
221ab64890Smrg * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
231ab64890Smrg * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
241ab64890Smrg *
251ab64890Smrg *
261ab64890Smrg *	DESCRIPTION
271ab64890Smrg *		Private include file for Color Management System.
281ab64890Smrg *		(i.e., for API internal use only)
291ab64890Smrg *
301ab64890Smrg */
311ab64890Smrg
321ab64890Smrg#ifndef _XCMSINT_H_
331ab64890Smrg#define _XCMSINT_H_
341ab64890Smrg
351ab64890Smrg#include <X11/Xcms.h>
361ab64890Smrg
371ab64890Smrg/*
381ab64890Smrg *	DEFINES
391ab64890Smrg */
401ab64890Smrg
411ab64890Smrg	/*
421ab64890Smrg	 * Private Status Value
431ab64890Smrg	 */
441ab64890Smrg#define	_XCMS_NEWNAME	-1
451ab64890Smrg
461ab64890Smrg	/*
471ab64890Smrg	 * Color Space ID's are of XcmsColorFormat type.
481ab64890Smrg	 *
491ab64890Smrg	 *	bit 31
501ab64890Smrg	 *	    0 == Device-Independent
511ab64890Smrg	 *	    1 == Device-Dependent
521ab64890Smrg	 *
531ab64890Smrg	 *	bit 30:
541ab64890Smrg         *          0 == Registered with X Consortium
551ab64890Smrg         *          1 == Unregistered
561ab64890Smrg         */
571ab64890Smrg#define       XCMS_DD_ID(id)          ((id) & (XcmsColorFormat)0x80000000)
581ab64890Smrg#define       XCMS_DI_ID(id)          (!((id) & (XcmsColorFormat)0x80000000))
591ab64890Smrg#define       XCMS_UNREG_ID(id)       ((id) & (XcmsColorFormat)0x40000000)
601ab64890Smrg#define       XCMS_REG_ID(id)         (!((id) & (XcmsColorFormat)0x40000000))
611ab64890Smrg#define       XCMS_FIRST_REG_DI_ID    (XcmsColorFormat)0x00000001
621ab64890Smrg#define       XCMS_FIRST_UNREG_DI_ID  (XcmsColorFormat)0x40000000
631ab64890Smrg#define       XCMS_FIRST_REG_DD_ID    (XcmsColorFormat)0x80000000
641ab64890Smrg#define       XCMS_FIRST_UNREG_DD_ID  (XcmsColorFormat)0xc0000000
651ab64890Smrg
661ab64890Smrg/*
671ab64890Smrg *	TYPEDEFS
681ab64890Smrg */
691ab64890Smrg
701ab64890Smrg    /*
711ab64890Smrg     * Structure for caching Colormap info.
721ab64890Smrg     *    This is provided for the Xlib modifications to:
731ab64890Smrg     *		XAllocNamedColor()
741ab64890Smrg     *		XLookupColor()
751ab64890Smrg     *		XParseColor()
761ab64890Smrg     *		XStoreNamedColor()
771ab64890Smrg     */
781ab64890Smrgtypedef struct _XcmsCmapRec {
791ab64890Smrg    Colormap cmapID;
801ab64890Smrg    Display *dpy;
811ab64890Smrg    Window windowID;
821ab64890Smrg    Visual *visual;
831ab64890Smrg    struct _XcmsCCC *ccc;
841ab64890Smrg    struct _XcmsCmapRec *pNext;
851ab64890Smrg} XcmsCmapRec;
861ab64890Smrg
871ab64890Smrg    /*
881ab64890Smrg     * Intensity Record (i.e., value / intensity tuple)
891ab64890Smrg     */
901ab64890Smrgtypedef struct _IntensityRec {
911ab64890Smrg    unsigned short value;
921ab64890Smrg    XcmsFloat intensity;
931ab64890Smrg} IntensityRec;
941ab64890Smrg
951ab64890Smrg    /*
961ab64890Smrg     * Intensity Table
971ab64890Smrg     */
981ab64890Smrgtypedef struct _IntensityTbl {
991ab64890Smrg    IntensityRec *pBase;
1001ab64890Smrg    unsigned int nEntries;
1011ab64890Smrg} IntensityTbl;
1021ab64890Smrg
1031ab64890Smrg    /*
1041ab64890Smrg     * Structure for storing per-Visual Intensity Tables (aka gamma maps).
1051ab64890Smrg     */
1061ab64890Smrgtypedef struct _XcmsIntensityMap {
1071ab64890Smrg    VisualID visualID;
1081ab64890Smrg    XPointer	screenData;	/* pointer to corresponding Screen Color*/
1091ab64890Smrg				/*	Characterization Data		*/
1101ab64890Smrg    void (*pFreeScreenData)(XPointer pScreenDataTemp);	/* Function that frees a Screen		*/
1111ab64890Smrg				/*   structure.				*/
1121ab64890Smrg    struct _XcmsIntensityMap *pNext;
1131ab64890Smrg} XcmsIntensityMap;
1141ab64890Smrg
1151ab64890Smrg
1161ab64890Smrg    /*
1171ab64890Smrg     * Structure for storing "registered" color space prefix/ID
1181ab64890Smrg     */
1191ab64890Smrgtypedef struct _XcmsRegColorSpaceEntry {
1201ab64890Smrg    const char *prefix;	/* Color Space prefix (e.g., "CIEXYZ:") */
1211ab64890Smrg    XcmsColorFormat id;	/* Color Space ID (e.g., XcmsCIEXYZFormat) */
1221ab64890Smrg} XcmsRegColorSpaceEntry;
1231ab64890Smrg
1241ab64890Smrg
1251ab64890Smrg    /*
1261ab64890Smrg     * Xcms Per Display (i.e. connection) related data
1271ab64890Smrg     */
1281ab64890Smrgtypedef struct _XcmsPerDpyInfo {
1291ab64890Smrg
1301ab64890Smrg    XcmsCCC paDefaultCCC; /* based on default visual of screen */
1311ab64890Smrg	    /*
1321ab64890Smrg	     * Pointer to an array of XcmsCCC structures, one for
1331ab64890Smrg	     * each screen.
1341ab64890Smrg	     */
1351ab64890Smrg    XcmsCmapRec *pClientCmaps;	/* Pointer to linked list of XcmsCmapRec's */
1361ab64890Smrg
1371ab64890Smrg} XcmsPerDpyInfo, *XcmsPerDpyInfoPtr;
1381ab64890Smrg
1391ab64890Smrg/*
1401ab64890Smrg *	DEFINES
1411ab64890Smrg */
1421ab64890Smrg
1431ab64890Smrg#define XDCCC_NUMBER	0x8000000L	/* 2**27 per XDCCC */
1441ab64890Smrg
1451ab64890Smrg#ifdef GRAY
1461ab64890Smrg#define XDCCC_SCREENWHITEPT_ATOM_NAME	"XDCCC_GRAY_SCREENWHITEPOINT"
1471ab64890Smrg#define XDCCC_GRAY_CORRECT_ATOM_NAME	"XDCCC_GRAY_CORRECTION"
1481ab64890Smrg#endif /* GRAY */
1491ab64890Smrg
1501ab64890Smrg#ifndef _ConversionValues
1511ab64890Smrgtypedef struct _ConversionValues {
1521ab64890Smrg    IntensityTbl IntensityTbl;
1531ab64890Smrg} ConversionValues;
1541ab64890Smrg#endif
1551ab64890Smrg
1561ab64890Smrg#ifdef GRAY
1571ab64890Smrgtypedef struct {
1581ab64890Smrg    IntensityTbl *IntensityTbl;
1591ab64890Smrg} GRAY_SCCData;
1601ab64890Smrg#endif /* GRAY */
1611ab64890Smrg
1621ab64890Smrg/*
1631ab64890Smrg *	DEFINES
1641ab64890Smrg */
1651ab64890Smrg
1661ab64890Smrg#define XDCCC_MATRIX_ATOM_NAME	"XDCCC_LINEAR_RGB_MATRICES"
1671ab64890Smrg#define XDCCC_CORRECT_ATOM_NAME "XDCCC_LINEAR_RGB_CORRECTION"
1681ab64890Smrg
1691ab64890Smrgtypedef struct {
1701ab64890Smrg    XcmsFloat XYZtoRGBmatrix[3][3];
1711ab64890Smrg    XcmsFloat RGBtoXYZmatrix[3][3];
1721ab64890Smrg    IntensityTbl *pRedTbl;
1731ab64890Smrg    IntensityTbl *pGreenTbl;
1741ab64890Smrg    IntensityTbl *pBlueTbl;
1751ab64890Smrg} LINEAR_RGB_SCCData;
1761ab64890Smrg
1771ab64890Smrg/* function prototypes */
1781ab64890Smrgextern XcmsCmapRec *
1791ab64890Smrg_XcmsAddCmapRec(
1801ab64890Smrg    Display *dpy,
1811ab64890Smrg    Colormap cmap,
1821ab64890Smrg    Window windowID,
1831ab64890Smrg    Visual *visual);
1841ab64890Smrgextern void
1851ab64890Smrg_XcmsRGB_to_XColor(
1861ab64890Smrg    XcmsColor *pColors,
1871ab64890Smrg    XColor *pXColors,
1881ab64890Smrg    unsigned int nColors);
1891ab64890Smrgextern Status
1901ab64890Smrg_XcmsResolveColorString (
1911ab64890Smrg    XcmsCCC ccc,
1921ab64890Smrg    const char **color_string,
1931ab64890Smrg    XcmsColor *pColor_exact_return,
1941ab64890Smrg    XcmsColorFormat result_format);
1951ab64890Smrgextern void
1961ab64890Smrg_XUnresolveColor(
1971ab64890Smrg    XcmsCCC ccc,
1981ab64890Smrg    XColor *pXColor);
1991ab64890Smrg/*
2001ab64890Smrg *	DESCRIPTION
2011ab64890Smrg *		Include file for defining the math macros used in the
2021ab64890Smrg *		XCMS source.  Instead of using math library routines
2031ab64890Smrg *		directly, XCMS uses macros so that based on the
2041ab64890Smrg *		definitions here, vendors and sites can specify exactly
2051ab64890Smrg *		what routine will be called (those from libm.a or their
2061ab64890Smrg *		custom routines).  If not defined to math library routines
2071ab64890Smrg *		(e.g., sqrt in libm.a), then the client is not forced to
2081ab64890Smrg *		be linked with -lm.
2091ab64890Smrg */
2101ab64890Smrg
2111ab64890Smrg#define XCMS_ATAN(x)		_XcmsArcTangent(x)
2121ab64890Smrg#define XCMS_COS(x)		_XcmsCosine(x)
2131ab64890Smrg#define XCMS_CUBEROOT(x)	_XcmsCubeRoot(x)
2141ab64890Smrg#define XCMS_FABS(x)		((x) < 0.0 ? -(x) : (x))
2151ab64890Smrg#define XCMS_SIN(x)		_XcmsSine(x)
2161ab64890Smrg#define XCMS_SQRT(x)		_XcmsSquareRoot(x)
2171ab64890Smrg#define XCMS_TAN(x)		(XCMS_SIN(x) / XCMS_COS(x))
2181ab64890Smrg
2191ab64890Smrgdouble _XcmsArcTangent(double a);
2201ab64890Smrgdouble _XcmsCosine(double a);
2211ab64890Smrgdouble _XcmsCubeRoot(double a);
2221ab64890Smrgdouble _XcmsSine(double a);
2231ab64890Smrgdouble _XcmsSquareRoot(double a);
2241ab64890Smrg
2251ab64890Smrg/*
2261ab64890Smrg *  DEFINES FOR GAMUT COMPRESSION AND QUERY ROUTINES
2271ab64890Smrg */
2281ab64890Smrg#ifndef PI
2291ab64890Smrg#  ifdef M_PI
2301ab64890Smrg#    define PI M_PI
2311ab64890Smrg#  else
2321ab64890Smrg#    define PI 3.14159265358979323846264338327950
2331ab64890Smrg#  endif /* M_PI */
2341ab64890Smrg#endif /* PI */
2351ab64890Smrg#ifndef degrees
2361ab64890Smrg#  define degrees(r) ((XcmsFloat)(r) * 180.0 / PI)
2371ab64890Smrg#endif /* degrees */
2381ab64890Smrg#ifndef radians
2391ab64890Smrg#  define radians(d) ((XcmsFloat)(d) * PI / 180.0)
2401ab64890Smrg#endif /* radians */
2411ab64890Smrg
2421ab64890Smrg#define XCMS_CIEUSTAROFHUE(h,c)	\
2431ab64890Smrg((XCMS_COS((h)) == 0.0) ? (XcmsFloat)0.0 : (XcmsFloat) \
2441ab64890Smrg((XcmsFloat)(c) / (XcmsFloat)XCMS_SQRT((XCMS_TAN(h) * XCMS_TAN(h)) + \
2451ab64890Smrg(XcmsFloat)1.0)))
2461ab64890Smrg#define XCMS_CIEVSTAROFHUE(h,c)	\
2471ab64890Smrg((XCMS_COS((h)) == 0.0) ? (XcmsFloat)0.0 : (XcmsFloat) \
2481ab64890Smrg((XcmsFloat)(c) / (XcmsFloat)XCMS_SQRT(((XcmsFloat)1.0 / \
2491ab64890Smrg(XcmsFloat)(XCMS_TAN(h) * XCMS_TAN(h))) + (XcmsFloat)1.0)))
2501ab64890Smrg/* this hue is returned in radians */
2511ab64890Smrg#define XCMS_CIELUV_PMETRIC_HUE(u,v)	\
2521ab64890Smrg(((u) != 0.0) ? XCMS_ATAN( (v) / (u)) : ((v >= 0.0) ? PI / 2 : -(PI / 2)))
2531ab64890Smrg#define XCMS_CIELUV_PMETRIC_CHROMA(u,v)	XCMS_SQRT(((u)*(u)) + ((v)*(v)))
2541ab64890Smrg
2551ab64890Smrg#define XCMS_CIEASTAROFHUE(h,c)		XCMS_CIEUSTAROFHUE((h), (c))
2561ab64890Smrg#define XCMS_CIEBSTAROFHUE(h,c)		XCMS_CIEVSTAROFHUE((h), (c))
2571ab64890Smrg#define XCMS_CIELAB_PMETRIC_HUE(a,b)	XCMS_CIELUV_PMETRIC_HUE((a), (b))
2581ab64890Smrg#define XCMS_CIELAB_PMETRIC_CHROMA(a,b)	XCMS_CIELUV_PMETRIC_CHROMA((a), (b))
2591ab64890Smrg
2601ab64890Smrg#endif /* _XCMSINT_H_ */
261