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