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

  1. /* $XConsortium: CCC.c,v 1.14 94/04/17 20:18:36 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.  *        XcmsCCC.c - Color Conversion Context Routines
  29.  *
  30.  *    DESCRIPTION
  31.  *        Routines to create, access, and free Color Conversion
  32.  *        Context structures.
  33.  *
  34.  *
  35.  */
  36.  
  37. /*
  38.  
  39. Copyright (c) 1994  X Consortium
  40.  
  41. Permission is hereby granted, free of charge, to any person obtaining
  42. a copy of this software and associated documentation files (the
  43. "Software"), to deal in the Software without restriction, including
  44. without limitation the rights to use, copy, modify, merge, publish,
  45. distribute, sublicense, and/or sell copies of the Software, and to
  46. permit persons to whom the Software is furnished to do so, subject to
  47. the following conditions:
  48.  
  49. The above copyright notice and this permission notice shall be included
  50. in all copies or substantial portions of the Software.
  51.  
  52. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  53. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  54. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  55. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
  56. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  57. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  58. OTHER DEALINGS IN THE SOFTWARE.
  59.  
  60. Except as contained in this notice, the name of the X Consortium shall
  61. not be used in advertising or otherwise to promote the sale, use or
  62. other dealings in this Software without prior written authorization
  63. from the X Consortium.
  64.  
  65. */
  66.  
  67. #include <stdio.h>
  68. #include "Xlib_private.h"
  69. #include "Xcmsint.h"
  70.  
  71. extern XcmsIntensityMap *_XcmsGetIntensityMap();
  72.  
  73.  
  74.  
  75. /************************************************************************
  76.  *                                    *
  77.  *            PUBLIC INTERFACES                *
  78.  *                                    *
  79.  ************************************************************************/
  80.  
  81. /*
  82.  *    NAME
  83.  *        XcmsCreateCCC
  84.  *
  85.  *    SYNOPSIS
  86.  */
  87.  
  88. XcmsCCC 
  89. XcmsCreateCCC(dpy, screenNumber, visual, clientWhitePt, gamutCompProc,
  90.     gamutCompClientData, whitePtAdjProc, whitePtAdjClientData)
  91.     Display *dpy;
  92.     int    screenNumber;
  93.     Visual *visual;
  94.     XcmsColor *clientWhitePt;
  95.     XcmsCompressionProc gamutCompProc;
  96.     XPointer gamutCompClientData;
  97.     XcmsWhiteAdjustProc whitePtAdjProc;
  98.     XPointer whitePtAdjClientData;
  99. /*
  100.  *    DESCRIPTION
  101.  *        Given a Display, Screen, Visual, etc., this routine creates
  102.  *        an appropriate Color Conversion Context.
  103.  *
  104.  *    RETURNS
  105.  *        Returns NULL if failed; otherwise address of the newly
  106.  *        created XcmsCCC.
  107.  *
  108.  */
  109. {
  110.     DBUG_ENTER("XcmsCreateCCC")
  111.     XcmsCCC pDefaultCCC;
  112.     XcmsCCC newccc;
  113.     XcmsIntensityMap *pIMap;
  114.     XcmsPerScrnInfo *pNewScrnInfo;
  115.  
  116.     pDefaultCCC = XcmsDefaultCCC(dpy, screenNumber);
  117.  
  118.     if (pDefaultCCC == NULL ||
  119.         !(newccc = (XcmsCCC) Xcalloc(1, (unsigned) sizeof(XcmsCCCRec)))) {
  120.     DBUG_RETURN(NULL);
  121.     } 
  122.  
  123.     /*
  124.      * Should inherit the following as result of a memmove():
  125.      *        dpy
  126.      *        screenNumber
  127.      *        pPerScrnInfo
  128.      */
  129.     memcpy((char *)newccc, (char *)pDefaultCCC, sizeof(XcmsCCCRec));
  130.     if (clientWhitePt) {
  131.     memcpy((char *)&newccc->clientWhitePt, (char *)clientWhitePt,
  132.         sizeof(XcmsColor));
  133.     }
  134.     if (gamutCompProc) {
  135.     newccc->gamutCompProc = gamutCompProc;
  136.     }
  137.     if (gamutCompClientData) {
  138.     newccc->gamutCompClientData = gamutCompClientData;
  139.     }
  140.     if (whitePtAdjProc) {
  141.     newccc->whitePtAdjProc = whitePtAdjProc;
  142.     }
  143.     if (whitePtAdjClientData) {
  144.     newccc->whitePtAdjClientData = whitePtAdjClientData;
  145.     }
  146.  
  147.     /*
  148.      * Now check our list of per-Visual Intensity tables.
  149.      * If one exists replace the pPerScrnInfo.
  150.      */
  151.     if ((pIMap = _XcmsGetIntensityMap(dpy, visual)) != NULL) {
  152.     if (!(pNewScrnInfo = (XcmsPerScrnInfo *)
  153.         Xcalloc(1, (unsigned) sizeof(XcmsPerScrnInfo)))) {
  154.         Xfree(newccc);
  155.         DBUG_RETURN(NULL);
  156.     }
  157.     memcpy((char *)pNewScrnInfo, (char *)newccc->pPerScrnInfo,
  158.         sizeof(XcmsPerScrnInfo));
  159.     pNewScrnInfo->screenData = pIMap->screenData;
  160.     newccc->pPerScrnInfo = pNewScrnInfo;
  161.     }
  162.  
  163.     /*
  164.      * Set visual component
  165.      */
  166.     newccc->visual = visual;
  167.  
  168.     DBUG_RETURN(newccc);
  169. }
  170.  
  171.  
  172. /*
  173.  *    NAME
  174.  *        XcmsDefaultCCC
  175.  *
  176.  *    SYNOPSIS
  177.  */
  178. XcmsCCC 
  179. XcmsDefaultCCC(dpy, screenNumber)
  180.     Display *dpy;
  181.     int screenNumber;
  182. /*
  183.  *    DESCRIPTION
  184.  *        Given a Display and Screen, this routine creates
  185.  *        returns the Screen's default Color Conversion Context.
  186.  *        Note that a Screen's default CCC is built with the
  187.  *        screen default visual.
  188.  *
  189.  *    RETURNS
  190.  *        Returns NULL if failed; otherwise address of the
  191.  *        XcmsCCC for the Screen's default CCC.
  192.  *
  193.  */
  194. {
  195.     DBUG_ENTER("XcmsDefaultCCC")
  196.     XcmsCCC ccc;
  197.  
  198.     if ((screenNumber < 0) || (screenNumber >= ScreenCount(dpy))) {
  199.     DBUG_RETURN((XcmsCCC)NULL);
  200.     }
  201.  
  202.     /*
  203.      * Check if the XcmsCCC's for each screen has been created
  204.      */
  205.     if ((XcmsCCC)dpy->cms.defaultCCCs == NULL) {
  206.     if (!_XcmsInitDefaultCCCs(dpy)) {
  207.         DBUG_RETURN((XcmsCCC)NULL);
  208.     }
  209.     }
  210.  
  211.     ccc = (XcmsCCC)dpy->cms.defaultCCCs + screenNumber;
  212.  
  213.     if (!ccc->pPerScrnInfo) {
  214.     /*
  215.      * Need to create the XcmsPerScrnInfo structure.  The
  216.      * _XcmsInitScrnInfo routine will create the XcmsPerScrnInfo
  217.      * structure as well as initialize its functionSet and pScreenData
  218.      * components.
  219.      */
  220.     if (!_XcmsInitScrnInfo(dpy, screenNumber)) {
  221.         DBUG_RETURN((XcmsCCC)NULL);
  222.     }
  223.     DBUG_RETURN(ccc);
  224.     } else {
  225.     /*
  226.      * If ccc->pPerScrnInfo->state == XcmsInitSuccess,
  227.      *    then the pPerScrnInfo component has already been initialized
  228.      *    therefore, just return ccc.
  229.      * If ccc->pPerScrnInfo->state == XcmsInitFailure,
  230.      *    then this means that we already attempted to initialize
  231.      *    the pPerScrnInfo component but failed therefore stuffing
  232.      *    the pPerScrnInfo component with defaults.  Just return ccc.
  233.      * If ccc->pPerScrnInfo->state == XcmsInitNone,
  234.      *    then attempt to initialize the pPerScrnInfo component.
  235.      */
  236.     switch (ccc->pPerScrnInfo->state) {
  237.        case XcmsInitFailure :
  238.         /* fall through */
  239.        case XcmsInitSuccess :
  240.         DBUG_RETURN(ccc);
  241.        case XcmsInitNone :
  242.         /* XcmsPerScreenInfo has not been initialized */
  243.         if (!_XcmsInitScrnInfo(dpy, screenNumber)) {
  244.         DBUG_RETURN((XcmsCCC)NULL);
  245.         }
  246.         DBUG_RETURN(ccc);
  247.        default :
  248.         DBUG_RETURN((XcmsCCC)NULL);
  249.     }
  250.     }
  251. }
  252.  
  253.  
  254. /*
  255.  *    NAME
  256.  *        XcmsFreeCCC
  257.  *
  258.  *    SYNOPSIS
  259.  */
  260. void
  261. XcmsFreeCCC(ccc)
  262.     XcmsCCC ccc;
  263. /*
  264.  *    DESCRIPTION
  265.  *        Frees memory associated with a Color Conversion Context
  266.  *        that was created with XcmsCreateCCC().
  267.  *
  268.  *    RETURNS
  269.  *        void
  270.  *
  271.  */
  272. {
  273.     DBUG_ENTER("XcmsFreeCCC")
  274.     if (ccc->dpy->cms.defaultCCCs &&
  275.     ccc == ((XcmsCCC)ccc->dpy->cms.defaultCCCs) + ccc->screenNumber) {
  276.     /* do not allow clients to free DefaultCCC's */
  277.     DBUG_VOID_RETURN;
  278.     }
  279.  
  280.     /*
  281.      * Note that XcmsPerScrnInfo sub-structures are freed here only if
  282.      * they are for visuals that have per-Visual intensity tables.
  283.      * Otherwise the XcmsPerScrnInfo structure is being shared!
  284.      * For the latter, there is only one allocated per Screen and it just
  285.      * so happens * that we place its initial reference is placed in the
  286.      *     default CCC.  The routine _XcmsFreeDefaultCCCs frees them.
  287.      */
  288.     if (_XcmsGetIntensityMap(ccc->dpy, ccc->visual) != NULL) {
  289.     Xfree(ccc->pPerScrnInfo);
  290.     }
  291.  
  292.     Xfree(ccc);
  293.     DBUG_VOID_RETURN;
  294. }
  295.