home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xcms_Int.c < prev    next >
C/C++ Source or Header  |  1999-11-02  |  10KB  |  433 lines

  1. /* $XConsortium: cmsInt.c,v 1.12 94/04/17 20:21:58 rws Exp $" */
  2.  
  3. /*
  4.  * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
  5.  *     All Rights Reserved
  6.  * 
  7.  * This file is a component of an X Window System-specific implementation
  8.  * of Xcms based on the TekColor Color Management System.  Permission is
  9.  * hereby granted to use, copy, modify, sell, and otherwise distribute this
  10.  * software and its documentation for any purpose and without fee, provided
  11.  * that this copyright, permission, and disclaimer notice is reproduced in
  12.  * all copies of this software and in supporting documentation.  TekColor
  13.  * is a trademark of Tektronix, Inc.
  14.  * 
  15.  * Tektronix makes no representation about the suitability of this software
  16.  * for any purpose.  It is provided "as is" and with all faults.
  17.  * 
  18.  * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
  19.  * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  20.  * PARTICULAR PURPOSE.  IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
  21.  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  22.  * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
  23.  * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  24.  * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
  25.  *
  26.  *
  27.  *    NAME
  28.  *        XcmsInt.c - Xcms API utility routines
  29.  *
  30.  *    DESCRIPTION
  31.  *        Xcms Application Program Interface (API) utility
  32.  *        routines for hanging information directly onto
  33.  *        the Display structure.
  34.  *
  35.  *
  36.  */
  37.  
  38. /* #define NEED_EVENTS */
  39. #include <stdio.h>
  40. #include "Xlib_private.h"
  41. #include "Xcmsint.h"
  42.  
  43. #ifndef XCMSCOMPPROC
  44. #  define XCMSCOMPPROC    XcmsTekHVCClipC
  45. #endif
  46.  
  47. /*
  48.  *      EXTERNS
  49.  */
  50. extern XcmsColorSpace **_XcmsDIColorSpaces;
  51. extern XcmsFunctionSet **_XcmsSCCFuncSets;
  52.  
  53. static void _XcmsFreeDefaultCCCs();
  54.  
  55. /*
  56.  *      GLOBALS
  57.  */
  58.  
  59.  
  60.  
  61. /************************************************************************
  62.  *                                    *
  63.  *               API PRIVATE ROUTINES                *
  64.  *                                    *
  65.  ************************************************************************/
  66.  
  67. /*
  68.  *    NAME
  69.  *        _XcmsCopyPointerArray
  70.  *
  71.  *    SYNOPSIS
  72.  */
  73. XPointer *
  74. _XcmsCopyPointerArray(pap)
  75.     XPointer *pap;
  76. /*
  77.  *    DESCRIPTION
  78.  *        Copies an array of NULL terminated pointers.
  79.  *
  80.  *    RETURNS
  81.  *        Returns NULL if failed; otherwise the address to
  82.  *        the copy.
  83.  *
  84.  */
  85. {
  86.     DBUG_ENTER("_XcmsCopyPointerArray")
  87.     XPointer *newArray;
  88.     char **tmp;
  89.     int n;
  90.  
  91.     for (tmp = pap, n = 0; *tmp != NULL; tmp++, n++);
  92.     n++; /* add 1 to include the NULL pointer */
  93.  
  94.     if (newArray = (XPointer *)Xmalloc(n * sizeof(XPointer))) {
  95.     memcpy((char *)newArray, (char *)pap,
  96.            (unsigned)(n * sizeof(XPointer)));
  97.     }
  98.     DBUG_RETURN((XPointer *)newArray);
  99. }
  100.  
  101. /*
  102.  *    NAME
  103.  *        _XcmsFreePointerArray
  104.  *
  105.  *    SYNOPSIS
  106.  */
  107. void
  108. _XcmsFreePointerArray(pap)
  109.     XPointer *pap;
  110. /*
  111.  *    DESCRIPTION
  112.  *        Frees an array of NULL terminated pointers.
  113.  *
  114.  *    RETURNS
  115.  *        void
  116.  *
  117.  */
  118. {
  119.     DBUG_ENTER("_XcmsFreePointerArray")
  120.     Xfree(pap);
  121.     DBUG_VOID_RETURN;
  122. }
  123.  
  124. /*
  125.  *    NAME
  126.  *        _XcmsPushPointerArray
  127.  *
  128.  *    SYNOPSIS
  129.  */
  130. XPointer *
  131. _XcmsPushPointerArray(pap, p, papNoFree)
  132.     XPointer *pap;
  133.     XPointer p;
  134.     XPointer *papNoFree;
  135. /*
  136.  *    DESCRIPTION
  137.  *        Places the specified pointer at the head of an array of NULL
  138.  *        terminated pointers.
  139.  *
  140.  *    RETURNS
  141.  *        Returns NULL if failed; otherwise the address to
  142.  *        the head of the array.
  143.  *
  144.  */
  145. {
  146.     DBUG_ENTER("_XcmsPushPointerArray")
  147.     XPointer *newArray;
  148.     char **tmp;
  149.     int n;
  150.  
  151.     for (tmp = pap, n = 0; *tmp != NULL; tmp++, n++);
  152.  
  153.     /* add 2: 1 for the new pointer and another for the NULL pointer */
  154.     n += 2;
  155.  
  156.     if (newArray = (XPointer *)Xmalloc(n * sizeof(XPointer))) {
  157.     memcpy((char *)(newArray+1),(char *)pap,
  158.            (unsigned)((n-1) * sizeof(XPointer)));
  159.     *newArray = p;
  160.     }
  161.     if (pap != papNoFree) {
  162.         _XcmsFreePointerArray(pap);
  163.     }
  164.     DBUG_RETURN((XPointer *)newArray);
  165. }
  166.  
  167. /*
  168.  *    NAME
  169.  *        _XcmsInitDefaultCCCs
  170.  *
  171.  *    SYNOPSIS
  172.  */
  173. int
  174. _XcmsInitDefaultCCCs(dpy)
  175.     Display *dpy;
  176. /*
  177.  *    DESCRIPTION
  178.  *        Initializes the Xcms per Display Info structure
  179.  *        (XcmsPerDpyInfo).
  180.  *
  181.  *    RETURNS
  182.  *        Returns 0 if failed; otherwise non-zero.
  183.  *
  184.  */
  185. {
  186.     DBUG_ENTER("_XcmsInitDefaultCCCs")
  187.     int nScrn = ScreenCount(dpy);
  188.     int i;
  189.     XcmsCCC ccc;
  190.  
  191.     if (nScrn <= 0) {
  192.     DBUG_RETURN(0);
  193.     }
  194.  
  195.     /*
  196.      * Create an array of XcmsCCC structures, one for each screen.
  197.      * They serve as the screen's default CCC.
  198.      */
  199.     if (!(ccc = (XcmsCCC)
  200.         Xcalloc((unsigned)nScrn, (unsigned) sizeof(XcmsCCCRec)))) {
  201.     DBUG_RETURN(0);
  202.     } 
  203.     dpy->cms.defaultCCCs = (XPointer)ccc;
  204.     dpy->free_funcs->defaultCCCs = _XcmsFreeDefaultCCCs;
  205.  
  206.     for (i = 0; i < nScrn; i++, ccc++) {
  207.     ccc->dpy = dpy;
  208.     ccc->screenNumber = i;
  209.     ccc->visual = DefaultVisual(dpy, i);
  210.     /*
  211.      * Used calloc to allocate memory so:
  212.      *    ccc->clientWhitePt->format == XcmsUndefinedFormat
  213.      *    ccc->gamutCompProc == NULL
  214.      *    ccc->whitePtAdjProc == NULL
  215.      *    ccc->pPerScrnInfo = NULL
  216.      *
  217.      * Don't need to create XcmsPerScrnInfo and its functionSet and
  218.      * pScreenData components until the default CCC is accessed.
  219.      * Note that the XcmsDefaultCCC routine calls _XcmsInitScrnInto
  220.      * to do this.
  221.      */
  222.     ccc->gamutCompProc = XCMSCOMPPROC;
  223.     }
  224.  
  225.     DBUG_RETURN(1);
  226. }
  227.  
  228.  
  229. /*
  230.  *    NAME
  231.  *        _XcmsFreeDefaultCCCs - Free Default CCCs and its PerScrnInfo
  232.  *
  233.  *    SYNOPSIS
  234.  */
  235. static void
  236. _XcmsFreeDefaultCCCs(dpy)
  237.     Display *dpy;
  238. /*
  239.  *    DESCRIPTION
  240.  *        This routine frees the default XcmsCCC's associated with
  241.  *        each screen and its associated substructures as neccessary.
  242.  *
  243.  *    RETURNS
  244.  *        void
  245.  *
  246.  *
  247.  */
  248. {
  249.     DBUG_ENTER("_XcmsFreeDefaultCCCs")
  250.     int nScrn = ScreenCount(dpy);
  251.     XcmsCCC ccc;
  252.     int i;
  253.  
  254.     /*
  255.      * Free Screen data in each DefaultCCC
  256.      *        Do not use XcmsFreeCCC here because it will not free
  257.      *        DefaultCCC's.
  258.      */
  259.     ccc = (XcmsCCC)dpy->cms.defaultCCCs;
  260.     for (i = nScrn; i--; ccc++) {
  261.     /*
  262.      * Check if XcmsPerScrnInfo exists.
  263.      *
  264.      * This is the only place where XcmsPerScrnInfo structures
  265.      * are freed since there is only one allocated per Screen.
  266.      * It just so happens that we place its reference in the
  267.      * default CCC.
  268.      */
  269.     if (ccc->pPerScrnInfo) {
  270.         /* Check if SCCData exists */
  271.         if (ccc->pPerScrnInfo->state != XcmsInitNone
  272.             && ccc->pPerScrnInfo->screenData) {
  273.         (*((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet)->screenFreeProc)
  274.             (ccc->pPerScrnInfo->screenData);
  275.         }
  276.         Xfree(ccc->pPerScrnInfo);
  277.     }
  278.     }
  279.  
  280.     /*
  281.      * Free the array of XcmsCCC structures
  282.      */
  283.     Xfree(dpy->cms.defaultCCCs);
  284.     dpy->cms.defaultCCCs = (XPointer)NULL;
  285.     DBUG_VOID_RETURN;
  286. }
  287.  
  288.  
  289.  
  290. /*
  291.  *    NAME
  292.  *        _XcmsInitScrnInfo
  293.  *
  294.  *    SYNOPSIS
  295.  */
  296. int
  297. _XcmsInitScrnInfo(dpy, screenNumber)
  298.     register Display *dpy;
  299.     int screenNumber;
  300. /*
  301.  *    DESCRIPTION
  302.  *        Given a display and screen number, this routine attempts
  303.  *        to initialize the Xcms per Screen Info structure
  304.  *        (XcmsPerScrnInfo).
  305.  *
  306.  *    RETURNS
  307.  *        Returns zero if initialization failed; non-zero otherwise.
  308.  */
  309. {
  310.     DBUG_ENTER("_XcmsInitScrnInfo")
  311.     XcmsFunctionSet **papSCCFuncSet = _XcmsSCCFuncSets;
  312.     XcmsCCC defaultccc;
  313.  
  314.     /*
  315.      * Check if the XcmsCCC's for each screen has been created.
  316.      * Really dont need to be created until some routine uses the Xcms
  317.      * API routines.
  318.      */
  319.     if ((XcmsCCC)dpy->cms.defaultCCCs == NULL) {
  320.     if (!_XcmsInitDefaultCCCs(dpy)) {
  321.         DBUG_RETURN(0);
  322.     }
  323.     }
  324.  
  325.     defaultccc = (XcmsCCC)dpy->cms.defaultCCCs + screenNumber;
  326.  
  327.     /*
  328.      * For each SCCFuncSet, try its pInitScrnFunc.
  329.      *    If the function succeeds, then we got it!
  330.      */
  331.  
  332.     if (!defaultccc->pPerScrnInfo) {
  333.     /*
  334.      * This is one of two places where XcmsPerScrnInfo structures
  335.      * are allocated.  There is one allocated per Screen that is
  336.      * shared among visuals that do not have specific intensity
  337.      * tables.  Other XcmsPerScrnInfo structures are created
  338.      * for the latter (see XcmsCreateCCC).  The ones created
  339.      * here are referenced by the default CCC.
  340.      */
  341.     if (!(defaultccc->pPerScrnInfo = (XcmsPerScrnInfo *)
  342.         Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) {
  343.         DBUG_RETURN(0);
  344.     } 
  345.     defaultccc->pPerScrnInfo->state = XcmsInitNone;
  346.     }
  347.  
  348.     while (*papSCCFuncSet != NULL) {
  349.     if ((*(*papSCCFuncSet)->screenInitProc)(dpy, screenNumber,
  350.         defaultccc->pPerScrnInfo)) {
  351.         defaultccc->pPerScrnInfo->state = XcmsInitSuccess;
  352.         DBUG_RETURN(1);
  353.     }
  354.     papSCCFuncSet++;
  355.     }
  356.  
  357.     /*
  358.      * Use Default SCCData
  359.      */
  360.     DBUG_RETURN(_XcmsLRGB_InitScrnDefault(dpy, screenNumber, defaultccc->pPerScrnInfo));
  361. }
  362.  
  363.  
  364. /*
  365.  *    NAME
  366.  *        _XcmsFreeIntensityMaps
  367.  *
  368.  *    SYNOPSIS
  369.  */
  370. void
  371. _XcmsFreeIntensityMaps(dpy)
  372.     Display *dpy;
  373. /*
  374.  *    DESCRIPTION
  375.  *        Frees all XcmsIntensityMap structures in the linked list
  376.  *        and sets dpy->cms.perVisualIntensityMaps to NULL.
  377.  *
  378.  *    RETURNS
  379.  *        void
  380.  *
  381.  */
  382. {
  383.     DBUG_ENTER("_XcmsFreeIntensityMaps")
  384.     XcmsIntensityMap *pNext, *pFree;
  385.   
  386.     pNext = (XcmsIntensityMap *)dpy->cms.perVisualIntensityMaps;
  387.     while (pNext != NULL) {
  388.     pFree = pNext;
  389.     pNext = pNext->pNext;
  390.     (*pFree->pFreeScreenData)(pFree->screenData);
  391.     /* Now free the XcmsIntensityMap structure */
  392.     Xfree(pFree);
  393.     }
  394.     dpy->cms.perVisualIntensityMaps = (XPointer)NULL;
  395.     DBUG_VOID_RETURN;
  396. }
  397.  
  398.  
  399. /*
  400.  *    NAME
  401.  *        _XcmsGetIntensityMap
  402.  *
  403.  *    SYNOPSIS
  404.  */
  405. XcmsIntensityMap *
  406. _XcmsGetIntensityMap(dpy, visual)
  407.     Display *dpy;
  408.     Visual *visual;
  409. /*
  410.  *    DESCRIPTION
  411.  *        Attempts to return a per-Visual intensity map.
  412.  *
  413.  *    RETURNS
  414.  *        Pointer to the XcmsIntensityMap structure if found;
  415.  *        otherwise NULL
  416.  *
  417.  */
  418. {
  419.     DBUG_ENTER("_XcmsGetIntensityMap")
  420. /*    VisualID targetID = visual->visualid;
  421.     XcmsIntensityMap *pNext;
  422.  
  423.     pNext = (XcmsIntensityMap *)dpy->cms.perVisualIntensityMaps;
  424.     while (pNext != NULL) {
  425.     if (targetID == pNext->visualID) {
  426.         DBUG_RETURN(pNext);
  427.     }
  428.     pNext = pNext->pNext;
  429.     }
  430. */
  431.     DBUG_RETURN((XcmsIntensityMap *)NULL);
  432. }
  433.