LRGB.c revision 1ab64890
11ab64890Smrg/* $Xorg: LRGB.c,v 1.3 2000/08/17 19:44:39 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 * NAME 281ab64890Smrg * XcmsLRGB.c 291ab64890Smrg * 301ab64890Smrg * DESCRIPTION 311ab64890Smrg * This file contains the conversion routines: 321ab64890Smrg * 1. CIE XYZ to RGB intensity 331ab64890Smrg * 2. RGB intensity to device RGB 341ab64890Smrg * 3. device RGB to RGB intensity 351ab64890Smrg * 4. RGB intensity to CIE XYZ 361ab64890Smrg * 371ab64890Smrg */ 381ab64890Smrg/* $XFree86: xc/lib/X11/LRGB.c,v 3.6 2003/04/13 19:22:16 dawes Exp $ */ 391ab64890Smrg 401ab64890Smrg#ifdef HAVE_CONFIG_H 411ab64890Smrg#include <config.h> 421ab64890Smrg#endif 431ab64890Smrg#include <stdio.h> 441ab64890Smrg#include <X11/Xos.h> 451ab64890Smrg#include <X11/Xatom.h> 461ab64890Smrg#include "Xlibint.h" 471ab64890Smrg#include "Xcmsint.h" 481ab64890Smrg#include "Cv.h" 491ab64890Smrg 501ab64890Smrg/* 511ab64890Smrg * LOCAL DEFINES 521ab64890Smrg * #define declarations local to this package. 531ab64890Smrg */ 541ab64890Smrg#define EPS 0.001 551ab64890Smrg#ifndef MIN 561ab64890Smrg#define MIN(x,y) ((x) > (y) ? (y) : (x)) 571ab64890Smrg#endif /* MIN */ 581ab64890Smrg#ifndef MAX 591ab64890Smrg#define MAX(x,y) ((x) > (y) ? (x) : (y)) 601ab64890Smrg#endif /* MAX */ 611ab64890Smrg#ifndef MIN3 621ab64890Smrg#define MIN3(x,y,z) ((x) > (MIN((y), (z))) ? (MIN((y), (z))) : (x)) 631ab64890Smrg#endif /* MIN3 */ 641ab64890Smrg#ifndef MAX3 651ab64890Smrg#define MAX3(x,y,z) ((x) > (MAX((y), (z))) ? (x) : (MAX((y), (z)))) 661ab64890Smrg#endif /* MAX3 */ 671ab64890Smrg 681ab64890Smrg/* 691ab64890Smrg * LOCAL TYPEDEFS 701ab64890Smrg * typedefs local to this package (for use with local vars). 711ab64890Smrg * 721ab64890Smrg */ 731ab64890Smrg 741ab64890Smrg/* 751ab64890Smrg * FORWARD DECLARATIONS 761ab64890Smrg */ 771ab64890Smrgstatic void LINEAR_RGB_FreeSCCData(XPointer pScreenDataTemp); 781ab64890Smrgstatic int LINEAR_RGB_InitSCCData(Display *dpy, 791ab64890Smrg int screenNumber, XcmsPerScrnInfo *pPerScrnInfo); 801ab64890Smrgstatic int XcmsLRGB_RGB_ParseString(register char *spec, XcmsColor *pColor); 811ab64890Smrgstatic int XcmsLRGB_RGBi_ParseString(register char *spec, XcmsColor *pColor); 821ab64890Smrgstatic Status 831ab64890Smrg_XcmsGetTableType0( 841ab64890Smrg IntensityTbl *pTbl, 851ab64890Smrg int format, 861ab64890Smrg char **pChar, 871ab64890Smrg unsigned long *pCount); 881ab64890Smrgstatic Status 891ab64890Smrg_XcmsGetTableType1( 901ab64890Smrg IntensityTbl *pTbl, 911ab64890Smrg int format, 921ab64890Smrg char **pChar, 931ab64890Smrg unsigned long *pCount); 941ab64890Smrg 951ab64890Smrg/* 961ab64890Smrg * LOCALS VARIABLES 971ab64890Smrg * Variables local to this package. 981ab64890Smrg * Usage example: 991ab64890Smrg * static int ExampleLocalVar; 1001ab64890Smrg */ 1011ab64890Smrg 1021ab64890Smrgstatic unsigned short const MASK[17] = { 1031ab64890Smrg 0x0000, /* 0 bitsPerRGB */ 1041ab64890Smrg 0x8000, /* 1 bitsPerRGB */ 1051ab64890Smrg 0xc000, /* 2 bitsPerRGB */ 1061ab64890Smrg 0xe000, /* 3 bitsPerRGB */ 1071ab64890Smrg 0xf000, /* 4 bitsPerRGB */ 1081ab64890Smrg 0xf800, /* 5 bitsPerRGB */ 1091ab64890Smrg 0xfc00, /* 6 bitsPerRGB */ 1101ab64890Smrg 0xfe00, /* 7 bitsPerRGB */ 1111ab64890Smrg 0xff00, /* 8 bitsPerRGB */ 1121ab64890Smrg 0xff80, /* 9 bitsPerRGB */ 1131ab64890Smrg 0xffc0, /* 10 bitsPerRGB */ 1141ab64890Smrg 0xffe0, /* 11 bitsPerRGB */ 1151ab64890Smrg 0xfff0, /* 12 bitsPerRGB */ 1161ab64890Smrg 0xfff8, /* 13 bitsPerRGB */ 1171ab64890Smrg 0xfffc, /* 14 bitsPerRGB */ 1181ab64890Smrg 0xfffe, /* 15 bitsPerRGB */ 1191ab64890Smrg 0xffff /* 16 bitsPerRGB */ 1201ab64890Smrg}; 1211ab64890Smrg 1221ab64890Smrg 1231ab64890Smrg /* 1241ab64890Smrg * A NULL terminated array of function pointers that when applied 1251ab64890Smrg * in series will convert an XcmsColor structure from XcmsRGBFormat 1261ab64890Smrg * to XcmsCIEXYZFormat. 1271ab64890Smrg */ 1281ab64890Smrgstatic XcmsConversionProc Fl_RGB_to_CIEXYZ[] = { 1291ab64890Smrg (XcmsConversionProc)XcmsRGBToRGBi, 1301ab64890Smrg (XcmsConversionProc)XcmsRGBiToCIEXYZ, 1311ab64890Smrg NULL 1321ab64890Smrg}; 1331ab64890Smrg 1341ab64890Smrg /* 1351ab64890Smrg * A NULL terminated array of function pointers that when applied 1361ab64890Smrg * in series will convert an XcmsColor structure from XcmsCIEXYZFormat 1371ab64890Smrg * to XcmsRGBFormat. 1381ab64890Smrg */ 1391ab64890Smrgstatic XcmsConversionProc Fl_CIEXYZ_to_RGB[] = { 1401ab64890Smrg (XcmsConversionProc)XcmsCIEXYZToRGBi, 1411ab64890Smrg (XcmsConversionProc)XcmsRGBiToRGB, 1421ab64890Smrg NULL 1431ab64890Smrg}; 1441ab64890Smrg 1451ab64890Smrg /* 1461ab64890Smrg * A NULL terminated array of function pointers that when applied 1471ab64890Smrg * in series will convert an XcmsColor structure from XcmsRGBiFormat 1481ab64890Smrg * to XcmsCIEXYZFormat. 1491ab64890Smrg */ 1501ab64890Smrgstatic XcmsConversionProc Fl_RGBi_to_CIEXYZ[] = { 1511ab64890Smrg (XcmsConversionProc)XcmsRGBiToCIEXYZ, 1521ab64890Smrg NULL 1531ab64890Smrg}; 1541ab64890Smrg 1551ab64890Smrg /* 1561ab64890Smrg * A NULL terminated array of function pointers that when applied 1571ab64890Smrg * in series will convert an XcmsColor structure from XcmsCIEXYZFormat 1581ab64890Smrg * to XcmsRGBiFormat. 1591ab64890Smrg */ 1601ab64890Smrgstatic XcmsConversionProc Fl_CIEXYZ_to_RGBi[] = { 1611ab64890Smrg (XcmsConversionProc)XcmsCIEXYZToRGBi, 1621ab64890Smrg NULL 1631ab64890Smrg}; 1641ab64890Smrg 1651ab64890Smrg /* 1661ab64890Smrg * RGBi Color Spaces 1671ab64890Smrg */ 1681ab64890SmrgXcmsColorSpace XcmsRGBiColorSpace = 1691ab64890Smrg { 1701ab64890Smrg _XcmsRGBi_prefix, /* prefix */ 1711ab64890Smrg XcmsRGBiFormat, /* id */ 1721ab64890Smrg XcmsLRGB_RGBi_ParseString, /* parseString */ 1731ab64890Smrg Fl_RGBi_to_CIEXYZ, /* to_CIEXYZ */ 1741ab64890Smrg Fl_CIEXYZ_to_RGBi, /* from_CIEXYZ */ 1751ab64890Smrg 1 1761ab64890Smrg }; 1771ab64890Smrg 1781ab64890Smrg /* 1791ab64890Smrg * RGB Color Spaces 1801ab64890Smrg */ 1811ab64890SmrgXcmsColorSpace XcmsRGBColorSpace = 1821ab64890Smrg { 1831ab64890Smrg _XcmsRGB_prefix, /* prefix */ 1841ab64890Smrg XcmsRGBFormat, /* id */ 1851ab64890Smrg XcmsLRGB_RGB_ParseString, /* parseString */ 1861ab64890Smrg Fl_RGB_to_CIEXYZ, /* to_CIEXYZ */ 1871ab64890Smrg Fl_CIEXYZ_to_RGB, /* from_CIEXYZ */ 1881ab64890Smrg 1 1891ab64890Smrg }; 1901ab64890Smrg 1911ab64890Smrg /* 1921ab64890Smrg * Device-Independent Color Spaces known to the 1931ab64890Smrg * LINEAR_RGB Screen Color Characteristics Function Set. 1941ab64890Smrg */ 1951ab64890Smrgstatic XcmsColorSpace *DDColorSpaces[] = { 1961ab64890Smrg &XcmsRGBColorSpace, 1971ab64890Smrg &XcmsRGBiColorSpace, 1981ab64890Smrg NULL 1991ab64890Smrg}; 2001ab64890Smrg 2011ab64890Smrg 2021ab64890Smrg/* 2031ab64890Smrg * GLOBALS 2041ab64890Smrg * Variables declared in this package that are allowed 2051ab64890Smrg * to be used globally. 2061ab64890Smrg */ 2071ab64890Smrg 2081ab64890Smrg /* 2091ab64890Smrg * LINEAR_RGB Screen Color Characteristics Function Set. 2101ab64890Smrg */ 2111ab64890SmrgXcmsFunctionSet XcmsLinearRGBFunctionSet = 2121ab64890Smrg { 2131ab64890Smrg &DDColorSpaces[0], /* pDDColorSpaces */ 2141ab64890Smrg LINEAR_RGB_InitSCCData, /* pInitScrnFunc */ 2151ab64890Smrg LINEAR_RGB_FreeSCCData /* pFreeSCCData */ 2161ab64890Smrg }; 2171ab64890Smrg 2181ab64890Smrg/* 2191ab64890Smrg * DESCRIPTION 2201ab64890Smrg * Contents of Default SCCData should be replaced if other 2211ab64890Smrg * data should be used as default. 2221ab64890Smrg * 2231ab64890Smrg * 2241ab64890Smrg */ 2251ab64890Smrg 2261ab64890Smrg/* 2271ab64890Smrg * NAME Tektronix 19" (Sony) CRT 2281ab64890Smrg * PART_NUMBER 119-2451-00 2291ab64890Smrg * MODEL Tek4300, Tek4800 2301ab64890Smrg */ 2311ab64890Smrg 2321ab64890Smrgstatic IntensityRec const Default_RGB_RedTuples[] = { 2331ab64890Smrg /* {unsigned short value, XcmsFloat intensity} */ 2341ab64890Smrg { 0x0000, 0.000000 }, 2351ab64890Smrg { 0x0909, 0.000000 }, 2361ab64890Smrg { 0x0a0a, 0.000936 }, 2371ab64890Smrg { 0x0f0f, 0.001481 }, 2381ab64890Smrg { 0x1414, 0.002329 }, 2391ab64890Smrg { 0x1919, 0.003529 }, 2401ab64890Smrg { 0x1e1e, 0.005127 }, 2411ab64890Smrg { 0x2323, 0.007169 }, 2421ab64890Smrg { 0x2828, 0.009699 }, 2431ab64890Smrg { 0x2d2d, 0.012759 }, 2441ab64890Smrg { 0x3232, 0.016392 }, 2451ab64890Smrg { 0x3737, 0.020637 }, 2461ab64890Smrg { 0x3c3c, 0.025533 }, 2471ab64890Smrg { 0x4141, 0.031119 }, 2481ab64890Smrg { 0x4646, 0.037431 }, 2491ab64890Smrg { 0x4b4b, 0.044504 }, 2501ab64890Smrg { 0x5050, 0.052373 }, 2511ab64890Smrg { 0x5555, 0.061069 }, 2521ab64890Smrg { 0x5a5a, 0.070624 }, 2531ab64890Smrg { 0x5f5f, 0.081070 }, 2541ab64890Smrg { 0x6464, 0.092433 }, 2551ab64890Smrg { 0x6969, 0.104744 }, 2561ab64890Smrg { 0x6e6e, 0.118026 }, 2571ab64890Smrg { 0x7373, 0.132307 }, 2581ab64890Smrg { 0x7878, 0.147610 }, 2591ab64890Smrg { 0x7d7d, 0.163958 }, 2601ab64890Smrg { 0x8282, 0.181371 }, 2611ab64890Smrg { 0x8787, 0.199871 }, 2621ab64890Smrg { 0x8c8c, 0.219475 }, 2631ab64890Smrg { 0x9191, 0.240202 }, 2641ab64890Smrg { 0x9696, 0.262069 }, 2651ab64890Smrg { 0x9b9b, 0.285089 }, 2661ab64890Smrg { 0xa0a0, 0.309278 }, 2671ab64890Smrg { 0xa5a5, 0.334647 }, 2681ab64890Smrg { 0xaaaa, 0.361208 }, 2691ab64890Smrg { 0xafaf, 0.388971 }, 2701ab64890Smrg { 0xb4b4, 0.417945 }, 2711ab64890Smrg { 0xb9b9, 0.448138 }, 2721ab64890Smrg { 0xbebe, 0.479555 }, 2731ab64890Smrg { 0xc3c3, 0.512202 }, 2741ab64890Smrg { 0xc8c8, 0.546082 }, 2751ab64890Smrg { 0xcdcd, 0.581199 }, 2761ab64890Smrg { 0xd2d2, 0.617552 }, 2771ab64890Smrg { 0xd7d7, 0.655144 }, 2781ab64890Smrg { 0xdcdc, 0.693971 }, 2791ab64890Smrg { 0xe1e1, 0.734031 }, 2801ab64890Smrg { 0xe6e6, 0.775322 }, 2811ab64890Smrg { 0xebeb, 0.817837 }, 2821ab64890Smrg { 0xf0f0, 0.861571 }, 2831ab64890Smrg { 0xf5f5, 0.906515 }, 2841ab64890Smrg { 0xfafa, 0.952662 }, 2851ab64890Smrg { 0xffff, 1.000000 } 2861ab64890Smrg}; 2871ab64890Smrg 2881ab64890Smrgstatic IntensityRec const Default_RGB_GreenTuples[] = { 2891ab64890Smrg /* {unsigned short value, XcmsFloat intensity} */ 2901ab64890Smrg { 0x0000, 0.000000 }, 2911ab64890Smrg { 0x1313, 0.000000 }, 2921ab64890Smrg { 0x1414, 0.000832 }, 2931ab64890Smrg { 0x1919, 0.001998 }, 2941ab64890Smrg { 0x1e1e, 0.003612 }, 2951ab64890Smrg { 0x2323, 0.005736 }, 2961ab64890Smrg { 0x2828, 0.008428 }, 2971ab64890Smrg { 0x2d2d, 0.011745 }, 2981ab64890Smrg { 0x3232, 0.015740 }, 2991ab64890Smrg { 0x3737, 0.020463 }, 3001ab64890Smrg { 0x3c3c, 0.025960 }, 3011ab64890Smrg { 0x4141, 0.032275 }, 3021ab64890Smrg { 0x4646, 0.039449 }, 3031ab64890Smrg { 0x4b4b, 0.047519 }, 3041ab64890Smrg { 0x5050, 0.056520 }, 3051ab64890Smrg { 0x5555, 0.066484 }, 3061ab64890Smrg { 0x5a5a, 0.077439 }, 3071ab64890Smrg { 0x5f5f, 0.089409 }, 3081ab64890Smrg { 0x6464, 0.102418 }, 3091ab64890Smrg { 0x6969, 0.116485 }, 3101ab64890Smrg { 0x6e6e, 0.131625 }, 3111ab64890Smrg { 0x7373, 0.147853 }, 3121ab64890Smrg { 0x7878, 0.165176 }, 3131ab64890Smrg { 0x7d7d, 0.183604 }, 3141ab64890Smrg { 0x8282, 0.203140 }, 3151ab64890Smrg { 0x8787, 0.223783 }, 3161ab64890Smrg { 0x8c8c, 0.245533 }, 3171ab64890Smrg { 0x9191, 0.268384 }, 3181ab64890Smrg { 0x9696, 0.292327 }, 3191ab64890Smrg { 0x9b9b, 0.317351 }, 3201ab64890Smrg { 0xa0a0, 0.343441 }, 3211ab64890Smrg { 0xa5a5, 0.370580 }, 3221ab64890Smrg { 0xaaaa, 0.398747 }, 3231ab64890Smrg { 0xafaf, 0.427919 }, 3241ab64890Smrg { 0xb4b4, 0.458068 }, 3251ab64890Smrg { 0xb9b9, 0.489165 }, 3261ab64890Smrg { 0xbebe, 0.521176 }, 3271ab64890Smrg { 0xc3c3, 0.554067 }, 3281ab64890Smrg { 0xc8c8, 0.587797 }, 3291ab64890Smrg { 0xcdcd, 0.622324 }, 3301ab64890Smrg { 0xd2d2, 0.657604 }, 3311ab64890Smrg { 0xd7d7, 0.693588 }, 3321ab64890Smrg { 0xdcdc, 0.730225 }, 3331ab64890Smrg { 0xe1e1, 0.767459 }, 3341ab64890Smrg { 0xe6e6, 0.805235 }, 3351ab64890Smrg { 0xebeb, 0.843491 }, 3361ab64890Smrg { 0xf0f0, 0.882164 }, 3371ab64890Smrg { 0xf5f5, 0.921187 }, 3381ab64890Smrg { 0xfafa, 0.960490 }, 3391ab64890Smrg { 0xffff, 1.000000 } 3401ab64890Smrg}; 3411ab64890Smrg 3421ab64890Smrgstatic IntensityRec const Default_RGB_BlueTuples[] = { 3431ab64890Smrg /* {unsigned short value, XcmsFloat intensity} */ 3441ab64890Smrg { 0x0000, 0.000000 }, 3451ab64890Smrg { 0x0e0e, 0.000000 }, 3461ab64890Smrg { 0x0f0f, 0.001341 }, 3471ab64890Smrg { 0x1414, 0.002080 }, 3481ab64890Smrg { 0x1919, 0.003188 }, 3491ab64890Smrg { 0x1e1e, 0.004729 }, 3501ab64890Smrg { 0x2323, 0.006766 }, 3511ab64890Smrg { 0x2828, 0.009357 }, 3521ab64890Smrg { 0x2d2d, 0.012559 }, 3531ab64890Smrg { 0x3232, 0.016424 }, 3541ab64890Smrg { 0x3737, 0.021004 }, 3551ab64890Smrg { 0x3c3c, 0.026344 }, 3561ab64890Smrg { 0x4141, 0.032489 }, 3571ab64890Smrg { 0x4646, 0.039481 }, 3581ab64890Smrg { 0x4b4b, 0.047357 }, 3591ab64890Smrg { 0x5050, 0.056154 }, 3601ab64890Smrg { 0x5555, 0.065903 }, 3611ab64890Smrg { 0x5a5a, 0.076634 }, 3621ab64890Smrg { 0x5f5f, 0.088373 }, 3631ab64890Smrg { 0x6464, 0.101145 }, 3641ab64890Smrg { 0x6969, 0.114968 }, 3651ab64890Smrg { 0x6e6e, 0.129862 }, 3661ab64890Smrg { 0x7373, 0.145841 }, 3671ab64890Smrg { 0x7878, 0.162915 }, 3681ab64890Smrg { 0x7d7d, 0.181095 }, 3691ab64890Smrg { 0x8282, 0.200386 }, 3701ab64890Smrg { 0x8787, 0.220791 }, 3711ab64890Smrg { 0x8c8c, 0.242309 }, 3721ab64890Smrg { 0x9191, 0.264937 }, 3731ab64890Smrg { 0x9696, 0.288670 }, 3741ab64890Smrg { 0x9b9b, 0.313499 }, 3751ab64890Smrg { 0xa0a0, 0.339410 }, 3761ab64890Smrg { 0xa5a5, 0.366390 }, 3771ab64890Smrg { 0xaaaa, 0.394421 }, 3781ab64890Smrg { 0xafaf, 0.423481 }, 3791ab64890Smrg { 0xb4b4, 0.453547 }, 3801ab64890Smrg { 0xb9b9, 0.484592 }, 3811ab64890Smrg { 0xbebe, 0.516587 }, 3821ab64890Smrg { 0xc3c3, 0.549498 }, 3831ab64890Smrg { 0xc8c8, 0.583291 }, 3841ab64890Smrg { 0xcdcd, 0.617925 }, 3851ab64890Smrg { 0xd2d2, 0.653361 }, 3861ab64890Smrg { 0xd7d7, 0.689553 }, 3871ab64890Smrg { 0xdcdc, 0.726454 }, 3881ab64890Smrg { 0xe1e1, 0.764013 }, 3891ab64890Smrg { 0xe6e6, 0.802178 }, 3901ab64890Smrg { 0xebeb, 0.840891 }, 3911ab64890Smrg { 0xf0f0, 0.880093 }, 3921ab64890Smrg { 0xf5f5, 0.919723 }, 3931ab64890Smrg { 0xfafa, 0.959715 }, 3941ab64890Smrg { 0xffff, 1.00000 } 3951ab64890Smrg}; 3961ab64890Smrg 3971ab64890Smrgstatic IntensityTbl Default_RGB_RedTbl = { 3981ab64890Smrg /* IntensityRec *pBase */ 3991ab64890Smrg (IntensityRec *) Default_RGB_RedTuples, 4001ab64890Smrg /* unsigned int nEntries */ 4011ab64890Smrg 52 4021ab64890Smrg}; 4031ab64890Smrg 4041ab64890Smrgstatic IntensityTbl Default_RGB_GreenTbl = { 4051ab64890Smrg /* IntensityRec *pBase */ 4061ab64890Smrg (IntensityRec *)Default_RGB_GreenTuples, 4071ab64890Smrg /* unsigned int nEntries */ 4081ab64890Smrg 50 4091ab64890Smrg}; 4101ab64890Smrg 4111ab64890Smrgstatic IntensityTbl Default_RGB_BlueTbl = { 4121ab64890Smrg /* IntensityRec *pBase */ 4131ab64890Smrg (IntensityRec *)Default_RGB_BlueTuples, 4141ab64890Smrg /* unsigned int nEntries */ 4151ab64890Smrg 51 4161ab64890Smrg}; 4171ab64890Smrg 4181ab64890Smrgstatic LINEAR_RGB_SCCData Default_RGB_SCCData = { 4191ab64890Smrg /* XcmsFloat XYZtoRGBmatrix[3][3] */ 4201ab64890Smrg { 4211ab64890Smrg { 3.48340481253539000, -1.52176374927285200, -0.55923133354049780 }, 4221ab64890Smrg {-1.07152751306193600, 1.96593795204372400, 0.03673691339553462 }, 4231ab64890Smrg { 0.06351179790497788, -0.20020501000496480, 0.81070942031648220 } 4241ab64890Smrg }, 4251ab64890Smrg 4261ab64890Smrg /* XcmsFloat RGBtoXYZmatrix[3][3] */ 4271ab64890Smrg { 4281ab64890Smrg { 0.38106149108714790, 0.32025712365352110, 0.24834578525933100 }, 4291ab64890Smrg { 0.20729745115140850, 0.68054638776373240, 0.11215616108485920 }, 4301ab64890Smrg { 0.02133944350088028, 0.14297193020246480, 1.24172892629665500 } 4311ab64890Smrg }, 4321ab64890Smrg 4331ab64890Smrg /* IntensityTbl *pRedTbl */ 4341ab64890Smrg &Default_RGB_RedTbl, 4351ab64890Smrg 4361ab64890Smrg /* IntensityTbl *pGreenTbl */ 4371ab64890Smrg &Default_RGB_GreenTbl, 4381ab64890Smrg 4391ab64890Smrg /* IntensityTbl *pBlueTbl */ 4401ab64890Smrg &Default_RGB_BlueTbl 4411ab64890Smrg}; 4421ab64890Smrg 4431ab64890Smrg/************************************************************************ 4441ab64890Smrg * * 4451ab64890Smrg * PRIVATE ROUTINES * 4461ab64890Smrg * * 4471ab64890Smrg ************************************************************************/ 4481ab64890Smrg 4491ab64890Smrg/* 4501ab64890Smrg * NAME 4511ab64890Smrg * LINEAR_RGB_InitSCCData() 4521ab64890Smrg * 4531ab64890Smrg * SYNOPSIS 4541ab64890Smrg */ 4551ab64890Smrgstatic Status 4561ab64890SmrgLINEAR_RGB_InitSCCData( 4571ab64890Smrg Display *dpy, 4581ab64890Smrg int screenNumber, 4591ab64890Smrg XcmsPerScrnInfo *pPerScrnInfo) 4601ab64890Smrg/* 4611ab64890Smrg * DESCRIPTION 4621ab64890Smrg * 4631ab64890Smrg * RETURNS 4641ab64890Smrg * XcmsFailure if failed. 4651ab64890Smrg * XcmsSuccess if succeeded. 4661ab64890Smrg * 4671ab64890Smrg */ 4681ab64890Smrg{ 4691ab64890Smrg Atom CorrectAtom = XInternAtom (dpy, XDCCC_CORRECT_ATOM_NAME, True); 4701ab64890Smrg Atom MatrixAtom = XInternAtom (dpy, XDCCC_MATRIX_ATOM_NAME, True); 4711ab64890Smrg int format_return, count, cType, nTables; 4721ab64890Smrg unsigned long nitems, nbytes_return; 4731ab64890Smrg char *property_return, *pChar; 4741ab64890Smrg XcmsFloat *pValue; 4751ab64890Smrg#ifdef ALLDEBUG 4761ab64890Smrg IntensityRec *pIRec; 4771ab64890Smrg#endif /* ALLDEBUG */ 4781ab64890Smrg VisualID visualID; 4791ab64890Smrg 4801ab64890Smrg LINEAR_RGB_SCCData *pScreenData, *pScreenDefaultData; 4811ab64890Smrg XcmsIntensityMap *pNewMap; 4821ab64890Smrg 4831ab64890Smrg /* 4841ab64890Smrg * Allocate memory for pScreenData 4851ab64890Smrg */ 4861ab64890Smrg if (!(pScreenData = pScreenDefaultData = (LINEAR_RGB_SCCData *) 4871ab64890Smrg Xcalloc (1, sizeof(LINEAR_RGB_SCCData)))) { 4881ab64890Smrg return(XcmsFailure); 4891ab64890Smrg } 4901ab64890Smrg 4911ab64890Smrg /* 4921ab64890Smrg * 1. Get the XYZ->RGB and RGB->XYZ matrices 4931ab64890Smrg */ 4941ab64890Smrg 4951ab64890Smrg if (MatrixAtom == None || 4961ab64890Smrg !_XcmsGetProperty (dpy, RootWindow(dpy, screenNumber), MatrixAtom, 4971ab64890Smrg &format_return, &nitems, &nbytes_return, &property_return) || 4981ab64890Smrg nitems != 18 || format_return != 32) { 4991ab64890Smrg /* 5001ab64890Smrg * As per the XDCCC, there must be 18 data items and each must be 5011ab64890Smrg * in 32 bits ! 5021ab64890Smrg */ 5031ab64890Smrg goto FreeSCCData; 5041ab64890Smrg 5051ab64890Smrg } else { 5061ab64890Smrg 5071ab64890Smrg /* 5081ab64890Smrg * RGBtoXYZ and XYZtoRGB matrices 5091ab64890Smrg */ 5101ab64890Smrg pValue = (XcmsFloat *) pScreenData; 5111ab64890Smrg pChar = property_return; 5121ab64890Smrg for (count = 0; count < 18; count++) { 5131ab64890Smrg *pValue++ = (long)_XcmsGetElement(format_return, &pChar, 5141ab64890Smrg &nitems) / (XcmsFloat)XDCCC_NUMBER; 5151ab64890Smrg } 5161ab64890Smrg Xfree ((char *)property_return); 5171ab64890Smrg pPerScrnInfo->screenWhitePt.spec.CIEXYZ.X = 5181ab64890Smrg pScreenData->RGBtoXYZmatrix[0][0] + 5191ab64890Smrg pScreenData->RGBtoXYZmatrix[0][1] + 5201ab64890Smrg pScreenData->RGBtoXYZmatrix[0][2]; 5211ab64890Smrg pPerScrnInfo->screenWhitePt.spec.CIEXYZ.Y = 5221ab64890Smrg pScreenData->RGBtoXYZmatrix[1][0] + 5231ab64890Smrg pScreenData->RGBtoXYZmatrix[1][1] + 5241ab64890Smrg pScreenData->RGBtoXYZmatrix[1][2]; 5251ab64890Smrg pPerScrnInfo->screenWhitePt.spec.CIEXYZ.Z = 5261ab64890Smrg pScreenData->RGBtoXYZmatrix[2][0] + 5271ab64890Smrg pScreenData->RGBtoXYZmatrix[2][1] + 5281ab64890Smrg pScreenData->RGBtoXYZmatrix[2][2]; 5291ab64890Smrg 5301ab64890Smrg /* 5311ab64890Smrg * Compute the Screen White Point 5321ab64890Smrg */ 5331ab64890Smrg if ((pPerScrnInfo->screenWhitePt.spec.CIEXYZ.Y < (1.0 - EPS) ) 5341ab64890Smrg || (pPerScrnInfo->screenWhitePt.spec.CIEXYZ.Y > (1.0 + EPS))) { 5351ab64890Smrg goto FreeSCCData; 5361ab64890Smrg } else { 5371ab64890Smrg pPerScrnInfo->screenWhitePt.spec.CIEXYZ.Y = 1.0; 5381ab64890Smrg } 5391ab64890Smrg pPerScrnInfo->screenWhitePt.format = XcmsCIEXYZFormat; 5401ab64890Smrg pPerScrnInfo->screenWhitePt.pixel = 0; 5411ab64890Smrg 5421ab64890Smrg#ifdef PDEBUG 5431ab64890Smrg printf ("RGB to XYZ Matrix values:\n"); 5441ab64890Smrg printf (" %f %f %f\n %f %f %f\n %f %f %f\n", 5451ab64890Smrg pScreenData->RGBtoXYZmatrix[0][0], 5461ab64890Smrg pScreenData->RGBtoXYZmatrix[0][1], 5471ab64890Smrg pScreenData->RGBtoXYZmatrix[0][2], 5481ab64890Smrg pScreenData->RGBtoXYZmatrix[1][0], 5491ab64890Smrg pScreenData->RGBtoXYZmatrix[1][1], 5501ab64890Smrg pScreenData->RGBtoXYZmatrix[1][2], 5511ab64890Smrg pScreenData->RGBtoXYZmatrix[2][0], 5521ab64890Smrg pScreenData->RGBtoXYZmatrix[2][1], 5531ab64890Smrg pScreenData->RGBtoXYZmatrix[2][2]); 5541ab64890Smrg printf ("XYZ to RGB Matrix values:\n"); 5551ab64890Smrg printf (" %f %f %f\n %f %f %f\n %f %f %f\n", 5561ab64890Smrg pScreenData->XYZtoRGBmatrix[0][0], 5571ab64890Smrg pScreenData->XYZtoRGBmatrix[0][1], 5581ab64890Smrg pScreenData->XYZtoRGBmatrix[0][2], 5591ab64890Smrg pScreenData->XYZtoRGBmatrix[1][0], 5601ab64890Smrg pScreenData->XYZtoRGBmatrix[1][1], 5611ab64890Smrg pScreenData->XYZtoRGBmatrix[1][2], 5621ab64890Smrg pScreenData->XYZtoRGBmatrix[2][0], 5631ab64890Smrg pScreenData->XYZtoRGBmatrix[2][1], 5641ab64890Smrg pScreenData->XYZtoRGBmatrix[2][2]); 5651ab64890Smrg printf ("Screen White Pt value: %f %f %f\n", 5661ab64890Smrg pPerScrnInfo->screenWhitePt.spec.CIEXYZ.X, 5671ab64890Smrg pPerScrnInfo->screenWhitePt.spec.CIEXYZ.Y, 5681ab64890Smrg pPerScrnInfo->screenWhitePt.spec.CIEXYZ.Z); 5691ab64890Smrg#endif /* PDEBUG */ 5701ab64890Smrg } 5711ab64890Smrg 5721ab64890Smrg /* 5731ab64890Smrg * 2. Get the Intensity Profile 5741ab64890Smrg */ 5751ab64890Smrg if (CorrectAtom == None || 5761ab64890Smrg !_XcmsGetProperty (dpy, RootWindow(dpy, screenNumber), CorrectAtom, 5771ab64890Smrg &format_return, &nitems, &nbytes_return, &property_return)) { 5781ab64890Smrg Xfree ((char *)property_return); 5791ab64890Smrg goto FreeSCCData; 5801ab64890Smrg } 5811ab64890Smrg 5821ab64890Smrg pChar = property_return; 5831ab64890Smrg 5841ab64890Smrg while (nitems) { 5851ab64890Smrg switch (format_return) { 5861ab64890Smrg case 8: 5871ab64890Smrg /* 5881ab64890Smrg * Must have at least: 5891ab64890Smrg * VisualID0 5901ab64890Smrg * VisualID1 5911ab64890Smrg * VisualID2 5921ab64890Smrg * VisualID3 5931ab64890Smrg * type 5941ab64890Smrg * count 5951ab64890Smrg * length 5961ab64890Smrg * intensity1 5971ab64890Smrg * intensity2 5981ab64890Smrg */ 5991ab64890Smrg if (nitems < 9) { 6001ab64890Smrg Xfree ((char *)property_return); 6011ab64890Smrg goto FreeSCCData; 6021ab64890Smrg } 6031ab64890Smrg count = 3; 6041ab64890Smrg break; 6051ab64890Smrg case 16: 6061ab64890Smrg /* 6071ab64890Smrg * Must have at least: 6081ab64890Smrg * VisualID0 6091ab64890Smrg * VisualID3 6101ab64890Smrg * type 6111ab64890Smrg * count 6121ab64890Smrg * length 6131ab64890Smrg * intensity1 6141ab64890Smrg * intensity2 6151ab64890Smrg */ 6161ab64890Smrg if (nitems < 7) { 6171ab64890Smrg Xfree ((char *)property_return); 6181ab64890Smrg goto FreeSCCData; 6191ab64890Smrg } 6201ab64890Smrg count = 1; 6211ab64890Smrg break; 6221ab64890Smrg case 32: 6231ab64890Smrg /* 6241ab64890Smrg * Must have at least: 6251ab64890Smrg * VisualID0 6261ab64890Smrg * type 6271ab64890Smrg * count 6281ab64890Smrg * length 6291ab64890Smrg * intensity1 6301ab64890Smrg * intensity2 6311ab64890Smrg */ 6321ab64890Smrg if (nitems < 6) { 6331ab64890Smrg Xfree ((char *)property_return); 6341ab64890Smrg goto FreeSCCData; 6351ab64890Smrg } 6361ab64890Smrg count = 0; 6371ab64890Smrg break; 6381ab64890Smrg default: 6391ab64890Smrg Xfree ((char *)property_return); 6401ab64890Smrg goto FreeSCCData; 6411ab64890Smrg } 6421ab64890Smrg 6431ab64890Smrg /* 6441ab64890Smrg * Get VisualID 6451ab64890Smrg */ 6461ab64890Smrg visualID = _XcmsGetElement(format_return, &pChar, &nitems); 6471ab64890Smrg while (count--) { 6481ab64890Smrg visualID = visualID << format_return; 6491ab64890Smrg visualID |= _XcmsGetElement(format_return, &pChar, &nitems); 6501ab64890Smrg } 6511ab64890Smrg 6521ab64890Smrg if (visualID == 0) { 6531ab64890Smrg /* 6541ab64890Smrg * This is a shared intensity table 6551ab64890Smrg */ 6561ab64890Smrg pScreenData = pScreenDefaultData; 6571ab64890Smrg } else { 6581ab64890Smrg /* 6591ab64890Smrg * This is a per-Visual intensity table 6601ab64890Smrg */ 6611ab64890Smrg if (!(pScreenData = (LINEAR_RGB_SCCData *) 6621ab64890Smrg Xcalloc (1, sizeof(LINEAR_RGB_SCCData)))) { 6631ab64890Smrg return(XcmsFailure); 6641ab64890Smrg } 6651ab64890Smrg /* copy matrices */ 6661ab64890Smrg memcpy((char *)pScreenData, (char *)pScreenDefaultData, 6671ab64890Smrg 18 * sizeof(XcmsFloat)); 6681ab64890Smrg 6691ab64890Smrg /* Create, initialize, and add map */ 6701ab64890Smrg if (!(pNewMap = (XcmsIntensityMap *) 6711ab64890Smrg Xcalloc (1, sizeof(XcmsIntensityMap)))) { 6721ab64890Smrg Xfree((char *)pScreenData); 6731ab64890Smrg return(XcmsFailure); 6741ab64890Smrg } 6751ab64890Smrg pNewMap->visualID = visualID; 6761ab64890Smrg pNewMap->screenData = (XPointer)pScreenData; 6771ab64890Smrg pNewMap->pFreeScreenData = LINEAR_RGB_FreeSCCData; 6781ab64890Smrg pNewMap->pNext = 6791ab64890Smrg (XcmsIntensityMap *)dpy->cms.perVisualIntensityMaps; 6801ab64890Smrg dpy->cms.perVisualIntensityMaps = (XPointer)pNewMap; 6811ab64890Smrg dpy->free_funcs->intensityMaps = _XcmsFreeIntensityMaps; 6821ab64890Smrg } 6831ab64890Smrg 6841ab64890Smrg cType = _XcmsGetElement(format_return, &pChar, &nitems); 6851ab64890Smrg nTables = _XcmsGetElement(format_return, &pChar, &nitems); 6861ab64890Smrg 6871ab64890Smrg if (cType == 0) { 6881ab64890Smrg 6891ab64890Smrg /* Red Intensity Table */ 6901ab64890Smrg if (!(pScreenData->pRedTbl = (IntensityTbl *) 6911ab64890Smrg Xcalloc (1, sizeof(IntensityTbl)))) { 6921ab64890Smrg goto FreeSCCData; 6931ab64890Smrg } 6941ab64890Smrg if (_XcmsGetTableType0(pScreenData->pRedTbl, format_return, &pChar, 6951ab64890Smrg &nitems) == XcmsFailure) { 6961ab64890Smrg goto FreeRedTbl; 6971ab64890Smrg } 6981ab64890Smrg 6991ab64890Smrg if (nTables == 1) { 7001ab64890Smrg /* Green Intensity Table */ 7011ab64890Smrg pScreenData->pGreenTbl = pScreenData->pRedTbl; 7021ab64890Smrg /* Blue Intensity Table */ 7031ab64890Smrg pScreenData->pBlueTbl = pScreenData->pRedTbl; 7041ab64890Smrg } else { 7051ab64890Smrg /* Green Intensity Table */ 7061ab64890Smrg if (!(pScreenData->pGreenTbl = (IntensityTbl *) 7071ab64890Smrg Xcalloc (1, sizeof(IntensityTbl)))) { 7081ab64890Smrg goto FreeRedTblElements; 7091ab64890Smrg } 7101ab64890Smrg if (_XcmsGetTableType0(pScreenData->pGreenTbl, format_return, &pChar, 7111ab64890Smrg &nitems) == XcmsFailure) { 7121ab64890Smrg goto FreeGreenTbl; 7131ab64890Smrg } 7141ab64890Smrg 7151ab64890Smrg /* Blue Intensity Table */ 7161ab64890Smrg if (!(pScreenData->pBlueTbl = (IntensityTbl *) 7171ab64890Smrg Xcalloc (1, sizeof(IntensityTbl)))) { 7181ab64890Smrg goto FreeGreenTblElements; 7191ab64890Smrg } 7201ab64890Smrg if (_XcmsGetTableType0(pScreenData->pBlueTbl, format_return, &pChar, 7211ab64890Smrg &nitems) == XcmsFailure) { 7221ab64890Smrg goto FreeBlueTbl; 7231ab64890Smrg } 7241ab64890Smrg } 7251ab64890Smrg } else if (cType == 1) { 7261ab64890Smrg /* Red Intensity Table */ 7271ab64890Smrg if (!(pScreenData->pRedTbl = (IntensityTbl *) 7281ab64890Smrg Xcalloc (1, sizeof(IntensityTbl)))) { 7291ab64890Smrg goto FreeSCCData; 7301ab64890Smrg } 7311ab64890Smrg if (_XcmsGetTableType1(pScreenData->pRedTbl, format_return, &pChar, 7321ab64890Smrg &nitems) == XcmsFailure) { 7331ab64890Smrg goto FreeRedTbl; 7341ab64890Smrg } 7351ab64890Smrg 7361ab64890Smrg if (nTables == 1) { 7371ab64890Smrg 7381ab64890Smrg /* Green Intensity Table */ 7391ab64890Smrg pScreenData->pGreenTbl = pScreenData->pRedTbl; 7401ab64890Smrg /* Blue Intensity Table */ 7411ab64890Smrg pScreenData->pBlueTbl = pScreenData->pRedTbl; 7421ab64890Smrg 7431ab64890Smrg } else { 7441ab64890Smrg 7451ab64890Smrg /* Green Intensity Table */ 7461ab64890Smrg if (!(pScreenData->pGreenTbl = (IntensityTbl *) 7471ab64890Smrg Xcalloc (1, sizeof(IntensityTbl)))) { 7481ab64890Smrg goto FreeRedTblElements; 7491ab64890Smrg } 7501ab64890Smrg if (_XcmsGetTableType1(pScreenData->pGreenTbl, format_return, &pChar, 7511ab64890Smrg &nitems) == XcmsFailure) { 7521ab64890Smrg goto FreeGreenTbl; 7531ab64890Smrg } 7541ab64890Smrg 7551ab64890Smrg /* Blue Intensity Table */ 7561ab64890Smrg if (!(pScreenData->pBlueTbl = (IntensityTbl *) 7571ab64890Smrg Xcalloc (1, sizeof(IntensityTbl)))) { 7581ab64890Smrg goto FreeBlueTblElements; 7591ab64890Smrg } 7601ab64890Smrg if (_XcmsGetTableType1(pScreenData->pBlueTbl, format_return, &pChar, 7611ab64890Smrg &nitems) == XcmsFailure) { 7621ab64890Smrg goto FreeBlueTbl; 7631ab64890Smrg } 7641ab64890Smrg } 7651ab64890Smrg } else { 7661ab64890Smrg Xfree ((char *)property_return); 7671ab64890Smrg goto FreeSCCData; 7681ab64890Smrg } 7691ab64890Smrg 7701ab64890Smrg#ifdef ALLDEBUG 7711ab64890Smrg printf ("Intensity Table RED %d\n", pScreenData->pRedTbl->nEntries); 7721ab64890Smrg pIRec = (IntensityRec *) pScreenData->pRedTbl->pBase; 7731ab64890Smrg for (count = 0; count < pScreenData->pRedTbl->nEntries; count++, pIRec++) { 7741ab64890Smrg printf ("\t0x%4x\t%f\n", pIRec->value, pIRec->intensity); 7751ab64890Smrg } 7761ab64890Smrg if (pScreenData->pGreenTbl->pBase != pScreenData->pRedTbl->pBase) { 7771ab64890Smrg printf ("Intensity Table GREEN %d\n", pScreenData->pGreenTbl->nEntries); 7781ab64890Smrg pIRec = (IntensityRec *)pScreenData->pGreenTbl->pBase; 7791ab64890Smrg for (count = 0; count < pScreenData->pGreenTbl->nEntries; count++, pIRec++) { 7801ab64890Smrg printf ("\t0x%4x\t%f\n", pIRec->value, pIRec->intensity); 7811ab64890Smrg } 7821ab64890Smrg } 7831ab64890Smrg if (pScreenData->pBlueTbl->pBase != pScreenData->pRedTbl->pBase) { 7841ab64890Smrg printf ("Intensity Table BLUE %d\n", pScreenData->pBlueTbl->nEntries); 7851ab64890Smrg pIRec = (IntensityRec *) pScreenData->pBlueTbl->pBase; 7861ab64890Smrg for (count = 0; count < pScreenData->pBlueTbl->nEntries; count++, pIRec++) { 7871ab64890Smrg printf ("\t0x%4x\t%f\n", pIRec->value, pIRec->intensity); 7881ab64890Smrg } 7891ab64890Smrg } 7901ab64890Smrg#endif /* ALLDEBUG */ 7911ab64890Smrg } 7921ab64890Smrg 7931ab64890Smrg Xfree ((char *)property_return); 7941ab64890Smrg 7951ab64890Smrg /* Free the old memory and use the new structure created. */ 7961ab64890Smrg LINEAR_RGB_FreeSCCData(pPerScrnInfo->screenData); 7971ab64890Smrg 7981ab64890Smrg pPerScrnInfo->functionSet = (XPointer) &XcmsLinearRGBFunctionSet; 7991ab64890Smrg 8001ab64890Smrg pPerScrnInfo->screenData = (XPointer) pScreenData; 8011ab64890Smrg 8021ab64890Smrg pPerScrnInfo->state = XcmsInitSuccess; 8031ab64890Smrg 8041ab64890Smrg return(XcmsSuccess); 8051ab64890Smrg 8061ab64890SmrgFreeBlueTblElements: 8071ab64890Smrg Xfree((char *)pScreenData->pBlueTbl->pBase); 8081ab64890Smrg 8091ab64890SmrgFreeBlueTbl: 8101ab64890Smrg Xfree((char *)pScreenData->pBlueTbl); 8111ab64890Smrg 8121ab64890SmrgFreeGreenTblElements: 8131ab64890Smrg Xfree((char *)pScreenData->pBlueTbl->pBase); 8141ab64890Smrg 8151ab64890SmrgFreeGreenTbl: 8161ab64890Smrg Xfree((char *)pScreenData->pGreenTbl); 8171ab64890Smrg 8181ab64890SmrgFreeRedTblElements: 8191ab64890Smrg Xfree((char *)pScreenData->pRedTbl->pBase); 8201ab64890Smrg 8211ab64890SmrgFreeRedTbl: 8221ab64890Smrg Xfree((char *)pScreenData->pRedTbl); 8231ab64890Smrg 8241ab64890SmrgFreeSCCData: 8251ab64890Smrg Xfree((char *)pScreenData); 8261ab64890Smrg pPerScrnInfo->state = XcmsInitNone; 8271ab64890Smrg return(XcmsFailure); 8281ab64890Smrg} 8291ab64890Smrg 8301ab64890Smrg 8311ab64890Smrg/* 8321ab64890Smrg * NAME 8331ab64890Smrg * LINEAR_RGB_FreeSCCData() 8341ab64890Smrg * 8351ab64890Smrg * SYNOPSIS 8361ab64890Smrg */ 8371ab64890Smrgstatic void 8381ab64890SmrgLINEAR_RGB_FreeSCCData( 8391ab64890Smrg XPointer pScreenDataTemp) 8401ab64890Smrg/* 8411ab64890Smrg * DESCRIPTION 8421ab64890Smrg * 8431ab64890Smrg * RETURNS 8441ab64890Smrg * 0 if failed. 8451ab64890Smrg * 1 if succeeded with no modifications. 8461ab64890Smrg * 8471ab64890Smrg */ 8481ab64890Smrg{ 8491ab64890Smrg LINEAR_RGB_SCCData *pScreenData = (LINEAR_RGB_SCCData *) pScreenDataTemp; 8501ab64890Smrg 8511ab64890Smrg if (pScreenData && pScreenData != &Default_RGB_SCCData) { 8521ab64890Smrg if (pScreenData->pRedTbl) { 8531ab64890Smrg if (pScreenData->pGreenTbl) { 8541ab64890Smrg if (pScreenData->pRedTbl->pBase != 8551ab64890Smrg pScreenData->pGreenTbl->pBase) { 8561ab64890Smrg if (pScreenData->pGreenTbl->pBase) { 8571ab64890Smrg Xfree ((char *)pScreenData->pGreenTbl->pBase); 8581ab64890Smrg } 8591ab64890Smrg } 8601ab64890Smrg if (pScreenData->pGreenTbl != pScreenData->pRedTbl) { 8611ab64890Smrg Xfree ((char *)pScreenData->pGreenTbl); 8621ab64890Smrg } 8631ab64890Smrg } 8641ab64890Smrg if (pScreenData->pBlueTbl) { 8651ab64890Smrg if (pScreenData->pRedTbl->pBase != 8661ab64890Smrg pScreenData->pBlueTbl->pBase) { 8671ab64890Smrg if (pScreenData->pBlueTbl->pBase) { 8681ab64890Smrg Xfree ((char *)pScreenData->pBlueTbl->pBase); 8691ab64890Smrg } 8701ab64890Smrg } 8711ab64890Smrg if (pScreenData->pBlueTbl != pScreenData->pRedTbl) { 8721ab64890Smrg Xfree ((char *)pScreenData->pBlueTbl); 8731ab64890Smrg } 8741ab64890Smrg } 8751ab64890Smrg if (pScreenData->pRedTbl->pBase) { 8761ab64890Smrg Xfree ((char *)pScreenData->pRedTbl->pBase); 8771ab64890Smrg } 8781ab64890Smrg Xfree ((char *)pScreenData->pRedTbl); 8791ab64890Smrg } 8801ab64890Smrg Xfree ((char *)pScreenData); 8811ab64890Smrg } 8821ab64890Smrg} 8831ab64890Smrg 8841ab64890Smrg 8851ab64890Smrg 8861ab64890Smrg/************************************************************************ 8871ab64890Smrg * * 8881ab64890Smrg * API PRIVATE ROUTINES * 8891ab64890Smrg * * 8901ab64890Smrg ************************************************************************/ 8911ab64890Smrg 8921ab64890Smrg/* 8931ab64890Smrg * NAME 8941ab64890Smrg * _XcmsGetTableType0 8951ab64890Smrg * 8961ab64890Smrg * SYNOPSIS 8971ab64890Smrg */ 8981ab64890Smrgstatic Status 8991ab64890Smrg_XcmsGetTableType0( 9001ab64890Smrg IntensityTbl *pTbl, 9011ab64890Smrg int format, 9021ab64890Smrg char **pChar, 9031ab64890Smrg unsigned long *pCount) 9041ab64890Smrg/* 9051ab64890Smrg * DESCRIPTION 9061ab64890Smrg * 9071ab64890Smrg * RETURNS 9081ab64890Smrg * XcmsFailure if failed. 9091ab64890Smrg * XcmsSuccess if succeeded. 9101ab64890Smrg * 9111ab64890Smrg */ 9121ab64890Smrg{ 9131ab64890Smrg unsigned int nElements; 9141ab64890Smrg IntensityRec *pIRec; 9151ab64890Smrg 9161ab64890Smrg nElements = pTbl->nEntries = 9171ab64890Smrg _XcmsGetElement(format, pChar, pCount) + 1; 9181ab64890Smrg if (!(pIRec = pTbl->pBase = (IntensityRec *) 9191ab64890Smrg Xcalloc (nElements, sizeof(IntensityRec)))) { 9201ab64890Smrg return(XcmsFailure); 9211ab64890Smrg } 9221ab64890Smrg 9231ab64890Smrg switch (format) { 9241ab64890Smrg case 8: 9251ab64890Smrg for (; nElements--; pIRec++) { 9261ab64890Smrg /* 0xFFFF/0xFF = 0x101 */ 9271ab64890Smrg pIRec->value = _XcmsGetElement (format, pChar, pCount) * 0x101; 9281ab64890Smrg pIRec->intensity = 9291ab64890Smrg _XcmsGetElement (format, pChar, pCount) / (XcmsFloat)255.0; 9301ab64890Smrg } 9311ab64890Smrg break; 9321ab64890Smrg case 16: 9331ab64890Smrg for (; nElements--; pIRec++) { 9341ab64890Smrg pIRec->value = _XcmsGetElement (format, pChar, pCount); 9351ab64890Smrg pIRec->intensity = _XcmsGetElement (format, pChar, pCount) 9361ab64890Smrg / (XcmsFloat)65535.0; 9371ab64890Smrg } 9381ab64890Smrg break; 9391ab64890Smrg case 32: 9401ab64890Smrg for (; nElements--; pIRec++) { 9411ab64890Smrg pIRec->value = _XcmsGetElement (format, pChar, pCount); 9421ab64890Smrg pIRec->intensity = _XcmsGetElement (format, pChar, pCount) 9431ab64890Smrg / (XcmsFloat)4294967295.0; 9441ab64890Smrg } 9451ab64890Smrg break; 9461ab64890Smrg default: 9471ab64890Smrg return(XcmsFailure); 9481ab64890Smrg } 9491ab64890Smrg return(XcmsSuccess); 9501ab64890Smrg} 9511ab64890Smrg 9521ab64890Smrg 9531ab64890Smrg/* 9541ab64890Smrg * NAME 9551ab64890Smrg * _XcmsGetTableType1 9561ab64890Smrg * 9571ab64890Smrg * SYNOPSIS 9581ab64890Smrg */ 9591ab64890Smrgstatic Status 9601ab64890Smrg_XcmsGetTableType1( 9611ab64890Smrg IntensityTbl *pTbl, 9621ab64890Smrg int format, 9631ab64890Smrg char **pChar, 9641ab64890Smrg unsigned long *pCount) 9651ab64890Smrg/* 9661ab64890Smrg * DESCRIPTION 9671ab64890Smrg * 9681ab64890Smrg * RETURNS 9691ab64890Smrg * XcmsFailure if failed. 9701ab64890Smrg * XcmsSuccess if succeeded. 9711ab64890Smrg * 9721ab64890Smrg */ 9731ab64890Smrg{ 9741ab64890Smrg int count; 9751ab64890Smrg unsigned int max_index; 9761ab64890Smrg IntensityRec *pIRec; 9771ab64890Smrg 9781ab64890Smrg max_index = _XcmsGetElement(format, pChar, pCount); 9791ab64890Smrg pTbl->nEntries = max_index + 1; 9801ab64890Smrg if (!(pIRec = pTbl->pBase = (IntensityRec *) 9811ab64890Smrg Xcalloc (max_index+1, sizeof(IntensityRec)))) { 9821ab64890Smrg return(XcmsFailure); 9831ab64890Smrg } 9841ab64890Smrg 9851ab64890Smrg switch (format) { 9861ab64890Smrg case 8: 9871ab64890Smrg for (count = 0; count < max_index+1; count++, pIRec++) { 9881ab64890Smrg pIRec->value = (count * 65535) / max_index; 9891ab64890Smrg pIRec->intensity = _XcmsGetElement (format, pChar, pCount) 9901ab64890Smrg / (XcmsFloat)255.0; 9911ab64890Smrg } 9921ab64890Smrg break; 9931ab64890Smrg case 16: 9941ab64890Smrg for (count = 0; count < max_index+1; count++, pIRec++) { 9951ab64890Smrg pIRec->value = (count * 65535) / max_index; 9961ab64890Smrg pIRec->intensity = _XcmsGetElement (format, pChar, pCount) 9971ab64890Smrg / (XcmsFloat)65535.0; 9981ab64890Smrg } 9991ab64890Smrg break; 10001ab64890Smrg case 32: 10011ab64890Smrg for (count = 0; count < max_index+1; count++, pIRec++) { 10021ab64890Smrg pIRec->value = (count * 65535) / max_index; 10031ab64890Smrg pIRec->intensity = _XcmsGetElement (format, pChar, pCount) 10041ab64890Smrg / (XcmsFloat)4294967295.0; 10051ab64890Smrg } 10061ab64890Smrg break; 10071ab64890Smrg default: 10081ab64890Smrg return(XcmsFailure); 10091ab64890Smrg } 10101ab64890Smrg 10111ab64890Smrg return(XcmsSuccess); 10121ab64890Smrg} 10131ab64890Smrg 10141ab64890Smrg 10151ab64890Smrg/* 10161ab64890Smrg * NAME 10171ab64890Smrg * ValueCmp 10181ab64890Smrg * 10191ab64890Smrg * SYNOPSIS 10201ab64890Smrg */ 10211ab64890Smrgstatic int 10221ab64890Smrg_XcmsValueCmp( 10231ab64890Smrg IntensityRec *p1, IntensityRec *p2) 10241ab64890Smrg/* 10251ab64890Smrg * DESCRIPTION 10261ab64890Smrg * Compares the value component of two IntensityRec 10271ab64890Smrg * structures. 10281ab64890Smrg * 10291ab64890Smrg * RETURNS 10301ab64890Smrg * 0 if p1->value is equal to p2->value 10311ab64890Smrg * < 0 if p1->value is less than p2->value 10321ab64890Smrg * > 0 if p1->value is greater than p2->value 10331ab64890Smrg * 10341ab64890Smrg */ 10351ab64890Smrg{ 10361ab64890Smrg return (p1->value - p2->value); 10371ab64890Smrg} 10381ab64890Smrg 10391ab64890Smrg 10401ab64890Smrg/* 10411ab64890Smrg * NAME 10421ab64890Smrg * IntensityCmp 10431ab64890Smrg * 10441ab64890Smrg * SYNOPSIS 10451ab64890Smrg */ 10461ab64890Smrgstatic int 10471ab64890Smrg_XcmsIntensityCmp( 10481ab64890Smrg IntensityRec *p1, IntensityRec *p2) 10491ab64890Smrg/* 10501ab64890Smrg * DESCRIPTION 10511ab64890Smrg * Compares the intensity component of two IntensityRec 10521ab64890Smrg * structures. 10531ab64890Smrg * 10541ab64890Smrg * RETURNS 10551ab64890Smrg * 0 if equal; 10561ab64890Smrg * < 0 if first precedes second 10571ab64890Smrg * > 0 if first succeeds second 10581ab64890Smrg * 10591ab64890Smrg */ 10601ab64890Smrg{ 10611ab64890Smrg if (p1->intensity < p2->intensity) { 10621ab64890Smrg return (-1); 10631ab64890Smrg } 10641ab64890Smrg if (p1->intensity > p2->intensity) { 10651ab64890Smrg return (XcmsSuccess); 10661ab64890Smrg } 10671ab64890Smrg return (XcmsFailure); 10681ab64890Smrg} 10691ab64890Smrg 10701ab64890Smrg/* 10711ab64890Smrg * NAME 10721ab64890Smrg * ValueInterpolation 10731ab64890Smrg * 10741ab64890Smrg * SYNOPSIS 10751ab64890Smrg */ 10761ab64890Smrg/* ARGSUSED */ 10771ab64890Smrgstatic int 10781ab64890Smrg_XcmsValueInterpolation( 10791ab64890Smrg IntensityRec *key, IntensityRec *lo, IntensityRec *hi, IntensityRec *answer, 10801ab64890Smrg int bitsPerRGB) 10811ab64890Smrg/* 10821ab64890Smrg * DESCRIPTION 10831ab64890Smrg * Based on a given value, performs a linear interpolation 10841ab64890Smrg * on the intensities between two IntensityRec structures. 10851ab64890Smrg * Note that the bitsPerRGB parameter is ignored. 10861ab64890Smrg * 10871ab64890Smrg * RETURNS 10881ab64890Smrg * Returns 0 if failed; otherwise non-zero. 10891ab64890Smrg */ 10901ab64890Smrg{ 10911ab64890Smrg XcmsFloat ratio; 10921ab64890Smrg 10931ab64890Smrg ratio = ((XcmsFloat)key->value - (XcmsFloat)lo->value) / 10941ab64890Smrg ((XcmsFloat)hi->value - (XcmsFloat)lo->value); 10951ab64890Smrg answer->value = key->value; 10961ab64890Smrg answer->intensity = (hi->intensity - lo->intensity) * ratio; 10971ab64890Smrg answer->intensity += lo->intensity; 10981ab64890Smrg return (XcmsSuccess); 10991ab64890Smrg} 11001ab64890Smrg 11011ab64890Smrg/* 11021ab64890Smrg * NAME 11031ab64890Smrg * IntensityInterpolation 11041ab64890Smrg * 11051ab64890Smrg * SYNOPSIS 11061ab64890Smrg */ 11071ab64890Smrgstatic int 11081ab64890Smrg_XcmsIntensityInterpolation( 11091ab64890Smrg IntensityRec *key, IntensityRec *lo, IntensityRec *hi, IntensityRec *answer, 11101ab64890Smrg int bitsPerRGB) 11111ab64890Smrg/* 11121ab64890Smrg * DESCRIPTION 11131ab64890Smrg * Based on a given intensity, performs a linear interpolation 11141ab64890Smrg * on the values between two IntensityRec structures. 11151ab64890Smrg * The bitsPerRGB parameter is necessary to perform rounding 11161ab64890Smrg * to the correct number of significant bits. 11171ab64890Smrg * 11181ab64890Smrg * RETURNS 11191ab64890Smrg * Returns 0 if failed; otherwise non-zero. 11201ab64890Smrg */ 11211ab64890Smrg{ 11221ab64890Smrg XcmsFloat ratio; 11231ab64890Smrg long target, up, down; 11241ab64890Smrg int shift = 16 - bitsPerRGB; 11251ab64890Smrg int max_color = (1 << bitsPerRGB) - 1; 11261ab64890Smrg 11271ab64890Smrg ratio = (key->intensity - lo->intensity) / (hi->intensity - lo->intensity); 11281ab64890Smrg answer->intensity = key->intensity; 11291ab64890Smrg target = hi->value - lo->value; 11301ab64890Smrg target *= ratio; 11311ab64890Smrg target += lo->value; 11321ab64890Smrg 11331ab64890Smrg /* 11341ab64890Smrg * Ok now, lets find the closest in respects to bits per RGB 11351ab64890Smrg */ 11361ab64890Smrg up = ((target >> shift) * 0xFFFF) / max_color; 11371ab64890Smrg if (up < target) { 11381ab64890Smrg down = up; 11391ab64890Smrg up = (MIN((down >> shift) + 1, max_color) * 0xFFFF) / max_color; 11401ab64890Smrg } else { 11411ab64890Smrg down = (MAX((up >> shift) - 1, 0) * 0xFFFF) / max_color; 11421ab64890Smrg } 11431ab64890Smrg answer->value = ((up - target) < (target - down) ? up : down); 11441ab64890Smrg answer->value &= MASK[bitsPerRGB]; 11451ab64890Smrg return (XcmsSuccess); 11461ab64890Smrg} 11471ab64890Smrg 11481ab64890Smrg 11491ab64890Smrg 11501ab64890Smrgtypedef int (*comparProcp)( 11511ab64890Smrg char *p1, 11521ab64890Smrg char *p2); 11531ab64890Smrgtypedef int (*interpolProcp)( 11541ab64890Smrg char *key, 11551ab64890Smrg char *lo, 11561ab64890Smrg char *hi, 11571ab64890Smrg char *answer, 11581ab64890Smrg int bitsPerRGB); 11591ab64890Smrg 11601ab64890Smrg/* 11611ab64890Smrg * NAME 11621ab64890Smrg * _XcmsTableSearch 11631ab64890Smrg * 11641ab64890Smrg * SYNOPSIS 11651ab64890Smrg */ 11661ab64890Smrgstatic int 11671ab64890Smrg_XcmsTableSearch( 11681ab64890Smrg char *key, 11691ab64890Smrg int bitsPerRGB, 11701ab64890Smrg char *base, 11711ab64890Smrg unsigned nel, 11721ab64890Smrg unsigned nKeyPtrSize, 11731ab64890Smrg int (*compar)( 11741ab64890Smrg char *p1, 11751ab64890Smrg char *p2), 11761ab64890Smrg int (*interpol)( 11771ab64890Smrg char *key, 11781ab64890Smrg char *lo, 11791ab64890Smrg char *hi, 11801ab64890Smrg char *answer, 11811ab64890Smrg int bitsPerRGB), 11821ab64890Smrg char *answer) 11831ab64890Smrg 11841ab64890Smrg/* 11851ab64890Smrg * DESCRIPTION 11861ab64890Smrg * A binary search through the specificied table. 11871ab64890Smrg * 11881ab64890Smrg * RETURNS 11891ab64890Smrg * Returns 0 if failed; otherwise non-zero. 11901ab64890Smrg * 11911ab64890Smrg */ 11921ab64890Smrg{ 11931ab64890Smrg char *hi, *lo, *mid, *last; 11941ab64890Smrg int result; 11951ab64890Smrg 11961ab64890Smrg last = hi = base + ((nel - 1) * nKeyPtrSize); 11971ab64890Smrg mid = lo = base; 11981ab64890Smrg 11991ab64890Smrg /* use only the significants bits, then scale into 16 bits */ 12001ab64890Smrg ((IntensityRec *)key)->value = ((unsigned long) 12011ab64890Smrg (((IntensityRec *)key)->value >> (16 - bitsPerRGB)) * 0xFFFF) 12021ab64890Smrg / ((1 << bitsPerRGB) - 1); 12031ab64890Smrg 12041ab64890Smrg /* Special case so that zero intensity always maps to zero value */ 12051ab64890Smrg if ((*compar) (key,lo) <= 0) { 12061ab64890Smrg memcpy (answer, lo, nKeyPtrSize); 12071ab64890Smrg ((IntensityRec *)answer)->value &= MASK[bitsPerRGB]; 12081ab64890Smrg return XcmsSuccess; 12091ab64890Smrg } 12101ab64890Smrg while (mid != last) { 12111ab64890Smrg last = mid; 12121ab64890Smrg mid = lo + (((unsigned)(hi - lo) / nKeyPtrSize) / 2) * nKeyPtrSize; 12131ab64890Smrg result = (*compar) (key, mid); 12141ab64890Smrg if (result == 0) { 12151ab64890Smrg 12161ab64890Smrg memcpy(answer, mid, nKeyPtrSize); 12171ab64890Smrg ((IntensityRec *)answer)->value &= MASK[bitsPerRGB]; 12181ab64890Smrg return (XcmsSuccess); 12191ab64890Smrg } else if (result < 0) { 12201ab64890Smrg hi = mid; 12211ab64890Smrg } else { 12221ab64890Smrg lo = mid; 12231ab64890Smrg } 12241ab64890Smrg } 12251ab64890Smrg 12261ab64890Smrg /* 12271ab64890Smrg * If we got to here, we didn't find a solution, so we 12281ab64890Smrg * need to apply interpolation. 12291ab64890Smrg */ 12301ab64890Smrg return ((*interpol)(key, lo, hi, answer, bitsPerRGB)); 12311ab64890Smrg} 12321ab64890Smrg 12331ab64890Smrg 12341ab64890Smrg/* 12351ab64890Smrg * NAME 12361ab64890Smrg * _XcmsMatVec - multiply a 3 x 3 by a 3 x 1 vector 12371ab64890Smrg * 12381ab64890Smrg * SYNOPSIS 12391ab64890Smrg */ 12401ab64890Smrgstatic void _XcmsMatVec( 12411ab64890Smrg XcmsFloat *pMat, XcmsFloat *pIn, XcmsFloat *pOut) 12421ab64890Smrg/* 12431ab64890Smrg * DESCRIPTION 12441ab64890Smrg * Multiply the passed vector by the passed matrix to return a 12451ab64890Smrg * vector. Matrix is 3x3, vectors are of length 3. 12461ab64890Smrg * 12471ab64890Smrg * RETURNS 12481ab64890Smrg * void 12491ab64890Smrg */ 12501ab64890Smrg{ 12511ab64890Smrg int i, j; 12521ab64890Smrg 12531ab64890Smrg for (i = 0; i < 3; i++) { 12541ab64890Smrg pOut[i] = 0.0; 12551ab64890Smrg for (j = 0; j < 3; j++) 12561ab64890Smrg pOut[i] += *(pMat+(i*3)+j) * pIn[j]; 12571ab64890Smrg } 12581ab64890Smrg} 12591ab64890Smrg 12601ab64890Smrg 12611ab64890Smrg/************************************************************************ 12621ab64890Smrg * * 12631ab64890Smrg * PUBLIC ROUTINES * 12641ab64890Smrg * * 12651ab64890Smrg ************************************************************************/ 12661ab64890Smrg 12671ab64890Smrg 12681ab64890Smrg/* 12691ab64890Smrg * NAME 12701ab64890Smrg * XcmsLRGB_RGB_ParseString 12711ab64890Smrg * 12721ab64890Smrg * SYNOPSIS 12731ab64890Smrg */ 12741ab64890Smrgstatic int 12751ab64890SmrgXcmsLRGB_RGB_ParseString( 12761ab64890Smrg register char *spec, 12771ab64890Smrg XcmsColor *pColor) 12781ab64890Smrg/* 12791ab64890Smrg * DESCRIPTION 12801ab64890Smrg * This routines takes a string and attempts to convert 12811ab64890Smrg * it into a XcmsColor structure with XcmsRGBFormat. 12821ab64890Smrg * 12831ab64890Smrg * RETURNS 12841ab64890Smrg * 0 if failed, non-zero otherwise. 12851ab64890Smrg */ 12861ab64890Smrg{ 12871ab64890Smrg register int n, i; 12881ab64890Smrg unsigned short r, g, b; 12891ab64890Smrg char c; 12901ab64890Smrg char *pchar; 12911ab64890Smrg unsigned short *pShort; 12921ab64890Smrg 12931ab64890Smrg /* 12941ab64890Smrg * Check for old # format 12951ab64890Smrg */ 12961ab64890Smrg if (*spec == '#') { 12971ab64890Smrg /* 12981ab64890Smrg * Attempt to parse the value portion. 12991ab64890Smrg */ 13001ab64890Smrg spec++; 13011ab64890Smrg n = strlen(spec); 13021ab64890Smrg if (n != 3 && n != 6 && n != 9 && n != 12) { 13031ab64890Smrg return(XcmsFailure); 13041ab64890Smrg } 13051ab64890Smrg 13061ab64890Smrg n /= 3; 13071ab64890Smrg g = b = 0; 13081ab64890Smrg do { 13091ab64890Smrg r = g; 13101ab64890Smrg g = b; 13111ab64890Smrg b = 0; 13121ab64890Smrg for (i = n; --i >= 0; ) { 13131ab64890Smrg c = *spec++; 13141ab64890Smrg b <<= 4; 13151ab64890Smrg if (c >= '0' && c <= '9') 13161ab64890Smrg b |= c - '0'; 13171ab64890Smrg /* assume string in lowercase 13181ab64890Smrg else if (c >= 'A' && c <= 'F') 13191ab64890Smrg b |= c - ('A' - 10); 13201ab64890Smrg */ 13211ab64890Smrg else if (c >= 'a' && c <= 'f') 13221ab64890Smrg b |= c - ('a' - 10); 13231ab64890Smrg else return (XcmsFailure); 13241ab64890Smrg } 13251ab64890Smrg } while (*spec != '\0'); 13261ab64890Smrg 13271ab64890Smrg /* 13281ab64890Smrg * Succeeded ! 13291ab64890Smrg */ 13301ab64890Smrg n <<= 2; 13311ab64890Smrg n = 16 - n; 13321ab64890Smrg /* shift instead of scale, to match old broken semantics */ 13331ab64890Smrg pColor->spec.RGB.red = r << n; 13341ab64890Smrg pColor->spec.RGB.green = g << n; 13351ab64890Smrg pColor->spec.RGB.blue = b << n; 13361ab64890Smrg } else { 13371ab64890Smrg if ((pchar = strchr(spec, ':')) == NULL) { 13381ab64890Smrg return(XcmsFailure); 13391ab64890Smrg } 13401ab64890Smrg n = (int)(pchar - spec); 13411ab64890Smrg 13421ab64890Smrg /* 13431ab64890Smrg * Check for proper prefix. 13441ab64890Smrg */ 13451ab64890Smrg if (strncmp(spec, _XcmsRGB_prefix, n) != 0) { 13461ab64890Smrg return(XcmsFailure); 13471ab64890Smrg } 13481ab64890Smrg 13491ab64890Smrg /* 13501ab64890Smrg * Attempt to parse the value portion. 13511ab64890Smrg */ 13521ab64890Smrg spec += (n + 1); 13531ab64890Smrg pShort = &pColor->spec.RGB.red; 13541ab64890Smrg for (i = 0; i < 3; i++, pShort++, spec++) { 13551ab64890Smrg n = 0; 13561ab64890Smrg *pShort = 0; 13571ab64890Smrg while (*spec != '/' && *spec != '\0') { 13581ab64890Smrg if (++n > 4) { 13591ab64890Smrg return(XcmsFailure); 13601ab64890Smrg } 13611ab64890Smrg c = *spec++; 13621ab64890Smrg *pShort <<= 4; 13631ab64890Smrg if (c >= '0' && c <= '9') 13641ab64890Smrg *pShort |= c - '0'; 13651ab64890Smrg /* assume string in lowercase 13661ab64890Smrg else if (c >= 'A' && c <= 'F') 13671ab64890Smrg *pShort |= c - ('A' - 10); 13681ab64890Smrg */ 13691ab64890Smrg else if (c >= 'a' && c <= 'f') 13701ab64890Smrg *pShort |= c - ('a' - 10); 13711ab64890Smrg else return (XcmsFailure); 13721ab64890Smrg } 13731ab64890Smrg if (n == 0) 13741ab64890Smrg return (XcmsFailure); 13751ab64890Smrg if (n < 4) { 13761ab64890Smrg *pShort = ((unsigned long)*pShort * 0xFFFF) / ((1 << n*4) - 1); 13771ab64890Smrg } 13781ab64890Smrg } 13791ab64890Smrg } 13801ab64890Smrg pColor->format = XcmsRGBFormat; 13811ab64890Smrg pColor->pixel = 0; 13821ab64890Smrg return (XcmsSuccess); 13831ab64890Smrg} 13841ab64890Smrg 13851ab64890Smrg 13861ab64890Smrg/* 13871ab64890Smrg * NAME 13881ab64890Smrg * XcmsLRGB_RGBi_ParseString 13891ab64890Smrg * 13901ab64890Smrg * SYNOPSIS 13911ab64890Smrg */ 13921ab64890Smrgstatic int 13931ab64890SmrgXcmsLRGB_RGBi_ParseString( 13941ab64890Smrg register char *spec, 13951ab64890Smrg XcmsColor *pColor) 13961ab64890Smrg/* 13971ab64890Smrg * DESCRIPTION 13981ab64890Smrg * This routines takes a string and attempts to convert 13991ab64890Smrg * it into a XcmsColor structure with XcmsRGBiFormat. 14001ab64890Smrg * The assumed RGBi string syntax is: 14011ab64890Smrg * RGBi:<r>/<g>/<b> 14021ab64890Smrg * Where r, g, and b are in string input format for floats 14031ab64890Smrg * consisting of: 14041ab64890Smrg * a. an optional sign 14051ab64890Smrg * b. a string of numbers possibly containing a decimal point, 14061ab64890Smrg * c. an optional exponent field containing an 'E' or 'e' 14071ab64890Smrg * followed by a possibly signed integer string. 14081ab64890Smrg * 14091ab64890Smrg * RETURNS 14101ab64890Smrg * 0 if failed, non-zero otherwise. 14111ab64890Smrg */ 14121ab64890Smrg{ 14131ab64890Smrg int n; 14141ab64890Smrg char *pchar; 14151ab64890Smrg 14161ab64890Smrg if ((pchar = strchr(spec, ':')) == NULL) { 14171ab64890Smrg return(XcmsFailure); 14181ab64890Smrg } 14191ab64890Smrg n = (int)(pchar - spec); 14201ab64890Smrg 14211ab64890Smrg /* 14221ab64890Smrg * Check for proper prefix. 14231ab64890Smrg */ 14241ab64890Smrg if (strncmp(spec, _XcmsRGBi_prefix, n) != 0) { 14251ab64890Smrg return(XcmsFailure); 14261ab64890Smrg } 14271ab64890Smrg 14281ab64890Smrg /* 14291ab64890Smrg * Attempt to parse the value portion. 14301ab64890Smrg */ 14311ab64890Smrg if (sscanf(spec + n + 1, "%lf/%lf/%lf", 14321ab64890Smrg &pColor->spec.RGBi.red, 14331ab64890Smrg &pColor->spec.RGBi.green, 14341ab64890Smrg &pColor->spec.RGBi.blue) != 3) { 14351ab64890Smrg char *s; /* Maybe failed due to locale */ 14361ab64890Smrg int f; 14371ab64890Smrg if ((s = strdup(spec))) { 14381ab64890Smrg for (f = 0; s[f]; ++f) 14391ab64890Smrg if (s[f] == '.') 14401ab64890Smrg s[f] = ','; 14411ab64890Smrg else if (s[f] == ',') 14421ab64890Smrg s[f] = '.'; 14431ab64890Smrg if (sscanf(s + n + 1, "%lf/%lf/%lf", 14441ab64890Smrg &pColor->spec.RGBi.red, 14451ab64890Smrg &pColor->spec.RGBi.green, 14461ab64890Smrg &pColor->spec.RGBi.blue) != 3) { 14471ab64890Smrg free(s); 14481ab64890Smrg return(XcmsFailure); 14491ab64890Smrg } 14501ab64890Smrg free(s); 14511ab64890Smrg } else 14521ab64890Smrg return(XcmsFailure); 14531ab64890Smrg } 14541ab64890Smrg 14551ab64890Smrg /* 14561ab64890Smrg * Succeeded ! 14571ab64890Smrg */ 14581ab64890Smrg pColor->format = XcmsRGBiFormat; 14591ab64890Smrg pColor->pixel = 0; 14601ab64890Smrg return (XcmsSuccess); 14611ab64890Smrg} 14621ab64890Smrg 14631ab64890Smrg 14641ab64890Smrg/* 14651ab64890Smrg * NAME 14661ab64890Smrg * XcmsCIEXYZToRGBi - convert CIE XYZ to RGB 14671ab64890Smrg * 14681ab64890Smrg * SYNOPSIS 14691ab64890Smrg */ 14701ab64890Smrg/* ARGSUSED */ 14711ab64890SmrgStatus 14721ab64890SmrgXcmsCIEXYZToRGBi( 14731ab64890Smrg XcmsCCC ccc, 14741ab64890Smrg XcmsColor *pXcmsColors_in_out,/* pointer to XcmsColors to convert */ 14751ab64890Smrg unsigned int nColors, /* Number of colors */ 14761ab64890Smrg Bool *pCompressed) /* pointer to an array of Bool */ 14771ab64890Smrg/* 14781ab64890Smrg * DESCRIPTION 14791ab64890Smrg * Converts color specifications in an array of XcmsColor 14801ab64890Smrg * structures from RGB format to RGBi format. 14811ab64890Smrg * 14821ab64890Smrg * RETURNS 14831ab64890Smrg * XcmsFailure if failed, 14841ab64890Smrg * XcmsSuccess if succeeded without gamut compression. 14851ab64890Smrg * XcmsSuccessWithCompression if succeeded with gamut 14861ab64890Smrg * compression. 14871ab64890Smrg */ 14881ab64890Smrg{ 14891ab64890Smrg LINEAR_RGB_SCCData *pScreenData; 14901ab64890Smrg XcmsFloat tmp[3]; 14911ab64890Smrg int hasCompressed = 0; 14921ab64890Smrg unsigned int i; 14931ab64890Smrg XcmsColor *pColor = pXcmsColors_in_out; 14941ab64890Smrg 14951ab64890Smrg if (ccc == NULL) { 14961ab64890Smrg return(XcmsFailure); 14971ab64890Smrg } 14981ab64890Smrg 14991ab64890Smrg pScreenData = (LINEAR_RGB_SCCData *)ccc->pPerScrnInfo->screenData; 15001ab64890Smrg 15011ab64890Smrg /* 15021ab64890Smrg * XcmsColors should be White Point Adjusted, if necessary, by now! 15031ab64890Smrg */ 15041ab64890Smrg 15051ab64890Smrg /* 15061ab64890Smrg * NEW!!! for extended gamut compression 15071ab64890Smrg * 15081ab64890Smrg * 1. Need to zero out pCompressed 15091ab64890Smrg * 15101ab64890Smrg * 2. Need to save initial address of pColor 15111ab64890Smrg * 15121ab64890Smrg * 3. Need to save initial address of pCompressed 15131ab64890Smrg */ 15141ab64890Smrg 15151ab64890Smrg for (i = 0; i < nColors; i++) { 15161ab64890Smrg 15171ab64890Smrg /* Make sure format is XcmsCIEXYZFormat */ 15181ab64890Smrg if (pColor->format != XcmsCIEXYZFormat) { 15191ab64890Smrg return(XcmsFailure); 15201ab64890Smrg } 15211ab64890Smrg 15221ab64890Smrg /* Multiply [A]-1 * [XYZ] to get RGB intensity */ 15231ab64890Smrg _XcmsMatVec((XcmsFloat *) pScreenData->XYZtoRGBmatrix, 15241ab64890Smrg (XcmsFloat *) &pColor->spec, tmp); 15251ab64890Smrg 15261ab64890Smrg if ((MIN3 (tmp[0], tmp[1], tmp[2]) < -EPS) || 15271ab64890Smrg (MAX3 (tmp[0], tmp[1], tmp[2]) > (1.0 + EPS))) { 15281ab64890Smrg 15291ab64890Smrg /* 15301ab64890Smrg * RGBi out of screen's gamut 15311ab64890Smrg */ 15321ab64890Smrg 15331ab64890Smrg if (ccc->gamutCompProc == NULL) { 15341ab64890Smrg /* 15351ab64890Smrg * Aha!! Here's that little trick that will allow 15361ab64890Smrg * gamut compression routines to get the out of bound 15371ab64890Smrg * RGBi. 15381ab64890Smrg */ 15391ab64890Smrg memcpy((char *)&pColor->spec, (char *)tmp, sizeof(tmp)); 15401ab64890Smrg pColor->format = XcmsRGBiFormat; 15411ab64890Smrg return(XcmsFailure); 15421ab64890Smrg } else if ((*ccc->gamutCompProc)(ccc, pXcmsColors_in_out, nColors, 15431ab64890Smrg i, pCompressed) == 0) { 15441ab64890Smrg return(XcmsFailure); 15451ab64890Smrg } 15461ab64890Smrg 15471ab64890Smrg /* 15481ab64890Smrg * The gamut compression function should return colors in CIEXYZ 15491ab64890Smrg * Also check again to if the new color is within gamut. 15501ab64890Smrg */ 15511ab64890Smrg if (pColor->format != XcmsCIEXYZFormat) { 15521ab64890Smrg return(XcmsFailure); 15531ab64890Smrg } 15541ab64890Smrg _XcmsMatVec((XcmsFloat *) pScreenData->XYZtoRGBmatrix, 15551ab64890Smrg (XcmsFloat *) &pColor->spec, tmp); 15561ab64890Smrg if ((MIN3 (tmp[0], tmp[1], tmp[2]) < -EPS) || 15571ab64890Smrg (MAX3 (tmp[0], tmp[1], tmp[2]) > (1.0 + EPS))) { 15581ab64890Smrg return(XcmsFailure); 15591ab64890Smrg } 15601ab64890Smrg hasCompressed++; 15611ab64890Smrg } 15621ab64890Smrg memcpy((char *)&pColor->spec, (char *)tmp, sizeof(tmp)); 15631ab64890Smrg /* These if statements are done to ensure the fudge factor is */ 15641ab64890Smrg /* is taken into account. */ 15651ab64890Smrg if (pColor->spec.RGBi.red < 0.0) { 15661ab64890Smrg pColor->spec.RGBi.red = 0.0; 15671ab64890Smrg } else if (pColor->spec.RGBi.red > 1.0) { 15681ab64890Smrg pColor->spec.RGBi.red = 1.0; 15691ab64890Smrg } 15701ab64890Smrg if (pColor->spec.RGBi.green < 0.0) { 15711ab64890Smrg pColor->spec.RGBi.green = 0.0; 15721ab64890Smrg } else if (pColor->spec.RGBi.green > 1.0) { 15731ab64890Smrg pColor->spec.RGBi.green = 1.0; 15741ab64890Smrg } 15751ab64890Smrg if (pColor->spec.RGBi.blue < 0.0) { 15761ab64890Smrg pColor->spec.RGBi.blue = 0.0; 15771ab64890Smrg } else if (pColor->spec.RGBi.blue > 1.0) { 15781ab64890Smrg pColor->spec.RGBi.blue = 1.0; 15791ab64890Smrg } 15801ab64890Smrg (pColor++)->format = XcmsRGBiFormat; 15811ab64890Smrg } 15821ab64890Smrg return (hasCompressed ? XcmsSuccessWithCompression : XcmsSuccess); 15831ab64890Smrg} 15841ab64890Smrg 15851ab64890Smrg 15861ab64890Smrg/* 15871ab64890Smrg * NAME 15881ab64890Smrg * LINEAR_RGBi_to_CIEXYZ - convert RGBi to CIEXYZ 15891ab64890Smrg * 15901ab64890Smrg * SYNOPSIS 15911ab64890Smrg */ 15921ab64890Smrg/* ARGSUSED */ 15931ab64890SmrgStatus 15941ab64890SmrgXcmsRGBiToCIEXYZ( 15951ab64890Smrg XcmsCCC ccc, 15961ab64890Smrg XcmsColor *pXcmsColors_in_out,/* pointer to XcmsColors to convert */ 15971ab64890Smrg unsigned int nColors, /* Number of colors */ 15981ab64890Smrg Bool *pCompressed) /* pointer to a bit array */ 15991ab64890Smrg/* 16001ab64890Smrg * DESCRIPTION 16011ab64890Smrg * Converts color specifications in an array of XcmsColor 16021ab64890Smrg * structures from RGBi format to CIEXYZ format. 16031ab64890Smrg * 16041ab64890Smrg * RETURNS 16051ab64890Smrg * XcmsFailure if failed, 16061ab64890Smrg * XcmsSuccess if succeeded. 16071ab64890Smrg */ 16081ab64890Smrg{ 16091ab64890Smrg LINEAR_RGB_SCCData *pScreenData; 16101ab64890Smrg XcmsFloat tmp[3]; 16111ab64890Smrg 16121ab64890Smrg /* 16131ab64890Smrg * pCompressed ignored in this function. 16141ab64890Smrg */ 16151ab64890Smrg 16161ab64890Smrg if (ccc == NULL) { 16171ab64890Smrg return(XcmsFailure); 16181ab64890Smrg } 16191ab64890Smrg 16201ab64890Smrg pScreenData = (LINEAR_RGB_SCCData *)ccc->pPerScrnInfo->screenData; 16211ab64890Smrg 16221ab64890Smrg /* 16231ab64890Smrg * XcmsColors should be White Point Adjusted, if necessary, by now! 16241ab64890Smrg */ 16251ab64890Smrg 16261ab64890Smrg while (nColors--) { 16271ab64890Smrg 16281ab64890Smrg /* Multiply [A]-1 * [XYZ] to get RGB intensity */ 16291ab64890Smrg _XcmsMatVec((XcmsFloat *) pScreenData->RGBtoXYZmatrix, 16301ab64890Smrg (XcmsFloat *) &pXcmsColors_in_out->spec, tmp); 16311ab64890Smrg 16321ab64890Smrg memcpy((char *)&pXcmsColors_in_out->spec, (char *)tmp, sizeof(tmp)); 16331ab64890Smrg (pXcmsColors_in_out++)->format = XcmsCIEXYZFormat; 16341ab64890Smrg } 16351ab64890Smrg return(XcmsSuccess); 16361ab64890Smrg} 16371ab64890Smrg 16381ab64890Smrg 16391ab64890Smrg/* 16401ab64890Smrg * NAME 16411ab64890Smrg * XcmsRGBiToRGB 16421ab64890Smrg * 16431ab64890Smrg * SYNOPSIS 16441ab64890Smrg */ 16451ab64890Smrg/* ARGSUSED */ 16461ab64890SmrgStatus 16471ab64890SmrgXcmsRGBiToRGB( 16481ab64890Smrg XcmsCCC ccc, 16491ab64890Smrg XcmsColor *pXcmsColors_in_out,/* pointer to XcmsColors to convert */ 16501ab64890Smrg unsigned int nColors, /* Number of colors */ 16511ab64890Smrg Bool *pCompressed) /* pointer to a bit array */ 16521ab64890Smrg/* 16531ab64890Smrg * DESCRIPTION 16541ab64890Smrg * Converts color specifications in an array of XcmsColor 16551ab64890Smrg * structures from RGBi format to RGB format. 16561ab64890Smrg * 16571ab64890Smrg * RETURNS 16581ab64890Smrg * XcmsFailure if failed, 16591ab64890Smrg * XcmsSuccess if succeeded without gamut compression. 16601ab64890Smrg * XcmsSuccessWithCompression if succeeded with gamut 16611ab64890Smrg * compression. 16621ab64890Smrg */ 16631ab64890Smrg{ 16641ab64890Smrg LINEAR_RGB_SCCData *pScreenData; 16651ab64890Smrg XcmsRGB tmpRGB; 16661ab64890Smrg IntensityRec keyIRec, answerIRec; 16671ab64890Smrg 16681ab64890Smrg /* 16691ab64890Smrg * pCompressed ignored in this function. 16701ab64890Smrg */ 16711ab64890Smrg 16721ab64890Smrg if (ccc == NULL) { 16731ab64890Smrg return(XcmsFailure); 16741ab64890Smrg } 16751ab64890Smrg 16761ab64890Smrg pScreenData = (LINEAR_RGB_SCCData *)ccc->pPerScrnInfo->screenData; 16771ab64890Smrg 16781ab64890Smrg while (nColors--) { 16791ab64890Smrg 16801ab64890Smrg /* Make sure format is XcmsRGBiFormat */ 16811ab64890Smrg if (pXcmsColors_in_out->format != XcmsRGBiFormat) { 16821ab64890Smrg return(XcmsFailure); 16831ab64890Smrg } 16841ab64890Smrg 16851ab64890Smrg keyIRec.intensity = pXcmsColors_in_out->spec.RGBi.red; 16861ab64890Smrg if (!_XcmsTableSearch((char *)&keyIRec, ccc->visual->bits_per_rgb, 16871ab64890Smrg (char *)pScreenData->pRedTbl->pBase, 16881ab64890Smrg (unsigned)pScreenData->pRedTbl->nEntries, 16891ab64890Smrg (unsigned)sizeof(IntensityRec), 16901ab64890Smrg (comparProcp)_XcmsIntensityCmp, (interpolProcp)_XcmsIntensityInterpolation, (char *)&answerIRec)) { 16911ab64890Smrg return(XcmsFailure); 16921ab64890Smrg } 16931ab64890Smrg tmpRGB.red = answerIRec.value; 16941ab64890Smrg 16951ab64890Smrg keyIRec.intensity = pXcmsColors_in_out->spec.RGBi.green; 16961ab64890Smrg if (!_XcmsTableSearch((char *)&keyIRec, ccc->visual->bits_per_rgb, 16971ab64890Smrg (char *)pScreenData->pGreenTbl->pBase, 16981ab64890Smrg (unsigned)pScreenData->pGreenTbl->nEntries, 16991ab64890Smrg (unsigned)sizeof(IntensityRec), 17001ab64890Smrg (comparProcp)_XcmsIntensityCmp, (interpolProcp)_XcmsIntensityInterpolation, (char *)&answerIRec)) { 17011ab64890Smrg return(XcmsFailure); 17021ab64890Smrg } 17031ab64890Smrg tmpRGB.green = answerIRec.value; 17041ab64890Smrg 17051ab64890Smrg keyIRec.intensity = pXcmsColors_in_out->spec.RGBi.blue; 17061ab64890Smrg if (!_XcmsTableSearch((char *)&keyIRec, ccc->visual->bits_per_rgb, 17071ab64890Smrg (char *)pScreenData->pBlueTbl->pBase, 17081ab64890Smrg (unsigned)pScreenData->pBlueTbl->nEntries, 17091ab64890Smrg (unsigned)sizeof(IntensityRec), 17101ab64890Smrg (comparProcp)_XcmsIntensityCmp, (interpolProcp)_XcmsIntensityInterpolation, (char *)&answerIRec)) { 17111ab64890Smrg return(XcmsFailure); 17121ab64890Smrg } 17131ab64890Smrg tmpRGB.blue = answerIRec.value; 17141ab64890Smrg 17151ab64890Smrg memcpy((char *)&pXcmsColors_in_out->spec, (char *)&tmpRGB, sizeof(XcmsRGB)); 17161ab64890Smrg (pXcmsColors_in_out++)->format = XcmsRGBFormat; 17171ab64890Smrg } 17181ab64890Smrg return(XcmsSuccess); 17191ab64890Smrg} 17201ab64890Smrg 17211ab64890Smrg 17221ab64890Smrg/* 17231ab64890Smrg * NAME 17241ab64890Smrg * XcmsRGBToRGBi 17251ab64890Smrg * 17261ab64890Smrg * SYNOPSIS 17271ab64890Smrg */ 17281ab64890Smrg/* ARGSUSED */ 17291ab64890SmrgStatus 17301ab64890SmrgXcmsRGBToRGBi( 17311ab64890Smrg XcmsCCC ccc, 17321ab64890Smrg XcmsColor *pXcmsColors_in_out,/* pointer to XcmsColors to convert */ 17331ab64890Smrg unsigned int nColors, /* Number of colors */ 17341ab64890Smrg Bool *pCompressed) /* pointer to a bit array */ 17351ab64890Smrg/* 17361ab64890Smrg * DESCRIPTION 17371ab64890Smrg * Converts color specifications in an array of XcmsColor 17381ab64890Smrg * structures from RGB format to RGBi format. 17391ab64890Smrg * 17401ab64890Smrg * RETURNS 17411ab64890Smrg * XcmsFailure if failed, 17421ab64890Smrg * XcmsSuccess if succeeded. 17431ab64890Smrg */ 17441ab64890Smrg{ 17451ab64890Smrg LINEAR_RGB_SCCData *pScreenData; 17461ab64890Smrg XcmsRGBi tmpRGBi; 17471ab64890Smrg IntensityRec keyIRec, answerIRec; 17481ab64890Smrg 17491ab64890Smrg /* 17501ab64890Smrg * pCompressed ignored in this function. 17511ab64890Smrg */ 17521ab64890Smrg 17531ab64890Smrg if (ccc == NULL) { 17541ab64890Smrg return(XcmsFailure); 17551ab64890Smrg } 17561ab64890Smrg 17571ab64890Smrg pScreenData = (LINEAR_RGB_SCCData *)ccc->pPerScrnInfo->screenData; 17581ab64890Smrg 17591ab64890Smrg while (nColors--) { 17601ab64890Smrg 17611ab64890Smrg /* Make sure format is XcmsRGBFormat */ 17621ab64890Smrg if (pXcmsColors_in_out->format != XcmsRGBFormat) { 17631ab64890Smrg return(XcmsFailure); 17641ab64890Smrg } 17651ab64890Smrg 17661ab64890Smrg keyIRec.value = pXcmsColors_in_out->spec.RGB.red; 17671ab64890Smrg if (!_XcmsTableSearch((char *)&keyIRec, ccc->visual->bits_per_rgb, 17681ab64890Smrg (char *)pScreenData->pRedTbl->pBase, 17691ab64890Smrg (unsigned)pScreenData->pRedTbl->nEntries, 17701ab64890Smrg (unsigned)sizeof(IntensityRec), 17711ab64890Smrg (comparProcp)_XcmsValueCmp, (interpolProcp)_XcmsValueInterpolation, (char *)&answerIRec)) { 17721ab64890Smrg return(XcmsFailure); 17731ab64890Smrg } 17741ab64890Smrg tmpRGBi.red = answerIRec.intensity; 17751ab64890Smrg 17761ab64890Smrg keyIRec.value = pXcmsColors_in_out->spec.RGB.green; 17771ab64890Smrg if (!_XcmsTableSearch((char *)&keyIRec, ccc->visual->bits_per_rgb, 17781ab64890Smrg (char *)pScreenData->pGreenTbl->pBase, 17791ab64890Smrg (unsigned)pScreenData->pGreenTbl->nEntries, 17801ab64890Smrg (unsigned)sizeof(IntensityRec), 17811ab64890Smrg (comparProcp)_XcmsValueCmp, (interpolProcp)_XcmsValueInterpolation, (char *)&answerIRec)) { 17821ab64890Smrg return(XcmsFailure); 17831ab64890Smrg } 17841ab64890Smrg tmpRGBi.green = answerIRec.intensity; 17851ab64890Smrg 17861ab64890Smrg keyIRec.value = pXcmsColors_in_out->spec.RGB.blue; 17871ab64890Smrg if (!_XcmsTableSearch((char *)&keyIRec, ccc->visual->bits_per_rgb, 17881ab64890Smrg (char *)pScreenData->pBlueTbl->pBase, 17891ab64890Smrg (unsigned)pScreenData->pBlueTbl->nEntries, 17901ab64890Smrg (unsigned)sizeof(IntensityRec), 17911ab64890Smrg (comparProcp)_XcmsValueCmp, (interpolProcp)_XcmsValueInterpolation, (char *)&answerIRec)) { 17921ab64890Smrg return(XcmsFailure); 17931ab64890Smrg } 17941ab64890Smrg tmpRGBi.blue = answerIRec.intensity; 17951ab64890Smrg 17961ab64890Smrg memcpy((char *)&pXcmsColors_in_out->spec, (char *)&tmpRGBi, sizeof(XcmsRGBi)); 17971ab64890Smrg (pXcmsColors_in_out++)->format = XcmsRGBiFormat; 17981ab64890Smrg } 17991ab64890Smrg return(XcmsSuccess); 18001ab64890Smrg} 18011ab64890Smrg 18021ab64890Smrg/* 18031ab64890Smrg * NAME 18041ab64890Smrg * _XcmsInitScrnDefaultInfo 18051ab64890Smrg * 18061ab64890Smrg * SYNOPSIS 18071ab64890Smrg */ 18081ab64890Smrg/* ARGSUSED */ 18091ab64890Smrgint 18101ab64890Smrg_XcmsLRGB_InitScrnDefault( 18111ab64890Smrg Display *dpy, 18121ab64890Smrg int screenNumber, 18131ab64890Smrg XcmsPerScrnInfo *pPerScrnInfo) 18141ab64890Smrg/* 18151ab64890Smrg * DESCRIPTION 18161ab64890Smrg * Given a display and screen number, this routine attempts 18171ab64890Smrg * to initialize the Xcms per Screen Info structure 18181ab64890Smrg * (XcmsPerScrnInfo) with defaults. 18191ab64890Smrg * 18201ab64890Smrg * RETURNS 18211ab64890Smrg * Returns zero if initialization failed; non-zero otherwise. 18221ab64890Smrg */ 18231ab64890Smrg{ 18241ab64890Smrg pPerScrnInfo->screenData = (XPointer)&Default_RGB_SCCData; 18251ab64890Smrg pPerScrnInfo->screenWhitePt.spec.CIEXYZ.X = 18261ab64890Smrg Default_RGB_SCCData.RGBtoXYZmatrix[0][0] + 18271ab64890Smrg Default_RGB_SCCData.RGBtoXYZmatrix[0][1] + 18281ab64890Smrg Default_RGB_SCCData.RGBtoXYZmatrix[0][2]; 18291ab64890Smrg pPerScrnInfo->screenWhitePt.spec.CIEXYZ.Y = 18301ab64890Smrg Default_RGB_SCCData.RGBtoXYZmatrix[1][0] + 18311ab64890Smrg Default_RGB_SCCData.RGBtoXYZmatrix[1][1] + 18321ab64890Smrg Default_RGB_SCCData.RGBtoXYZmatrix[1][2]; 18331ab64890Smrg pPerScrnInfo->screenWhitePt.spec.CIEXYZ.Z = 18341ab64890Smrg Default_RGB_SCCData.RGBtoXYZmatrix[2][0] + 18351ab64890Smrg Default_RGB_SCCData.RGBtoXYZmatrix[2][1] + 18361ab64890Smrg Default_RGB_SCCData.RGBtoXYZmatrix[2][2]; 18371ab64890Smrg if ((pPerScrnInfo->screenWhitePt.spec.CIEXYZ.Y < (1.0 - EPS) ) 18381ab64890Smrg || (pPerScrnInfo->screenWhitePt.spec.CIEXYZ.Y > (1.0 + EPS))) { 18391ab64890Smrg pPerScrnInfo->screenData = (XPointer)NULL; 18401ab64890Smrg pPerScrnInfo->state = XcmsInitNone; 18411ab64890Smrg return(0); 18421ab64890Smrg } 18431ab64890Smrg pPerScrnInfo->screenWhitePt.spec.CIEXYZ.Y = 1.0; 18441ab64890Smrg pPerScrnInfo->screenWhitePt.format = XcmsCIEXYZFormat; 18451ab64890Smrg pPerScrnInfo->screenWhitePt.pixel = 0; 18461ab64890Smrg pPerScrnInfo->functionSet = (XPointer)&XcmsLinearRGBFunctionSet; 18471ab64890Smrg pPerScrnInfo->state = XcmsInitFailure; /* default initialization */ 18481ab64890Smrg return(1); 18491ab64890Smrg} 1850