home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / X / CIELabGcC.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-24  |  3.8 KB  |  125 lines

  1. /* $XConsortium: CIELabGcC.c,v 1.1 91/07/24 23:26:14 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.  *    NAME
  27.  *        CIELabGcC.c
  28.  *
  29.  *    DESCRIPTION
  30.  *        Source for XcmsCIELabClipuv() gamut compression routine.
  31.  *
  32.  */
  33.  
  34. #include "Xlibint.h"
  35. #include "Xcmsint.h"
  36.  
  37.  
  38. /************************************************************************
  39.  *                                    *
  40.  *             PUBLIC ROUTINES                *
  41.  *                                    *
  42.  ************************************************************************/
  43.  
  44. /*
  45.  *    NAME
  46.  *        XcmsCIELabClipab - Reduce the chroma for a hue and L*
  47.  *
  48.  *    SYNOPSIS
  49.  */
  50. /* ARGSUSED */
  51. Status
  52. XcmsCIELabClipab (ccc, pColors_in_out, nColors, i, pCompressed)
  53.     XcmsCCC ccc;
  54.     XcmsColor *pColors_in_out;
  55.     unsigned int nColors;
  56.     unsigned int i;
  57.     Bool *pCompressed;
  58. /*
  59.  *    DESCRIPTION
  60.  *        Reduce the Chroma for a specific hue and chroma to
  61.  *        to bring the given color into the gamut of the 
  62.  *        specified device.  As required of gamut compression
  63.  *        functions, this routine returns pColor_in_out
  64.  *        in XcmsCIEXYZFormat on successful completion.
  65.  *        
  66.  *        Since this routine works with the L* within
  67.  *        pColor_in_out intermediate results may be returned
  68.  *        even though it may be invalid.
  69.  *
  70.  *    RETURNS
  71.  *        XcmsFailure - Failure
  72.  *              XcmsSuccess - Succeeded
  73.  *
  74.  */
  75. {
  76.     Status retval;
  77.     XcmsColor *pColor;
  78.  
  79.     /*
  80.      * Color specification passed as input can be assumed to:
  81.      *    1. Be in XcmsCIEXYZFormat
  82.      *    2. Already be white point adjusted for the Screen White Point.
  83.      *        This means that the white point now associated with this
  84.      *        color spec is the Screen White Point (even if the
  85.      *        ccc->clientWhitePt differs).
  86.      */
  87.  
  88.     pColor = pColors_in_out + i;
  89.  
  90.     if (ccc->visual->class < PseudoColor) {
  91.     /*
  92.      * GRAY !
  93.      */
  94.     _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc),
  95.         1, XcmsCIELabFormat);
  96.     _XcmsDIConvertColors(ccc, pColor, ScreenWhitePointOfCCC(ccc),
  97.         1, XcmsCIEXYZFormat);
  98.     if (pCompressed) {
  99.         *(pCompressed + i) = True;
  100.     }
  101.     return(XcmsSuccess);
  102.     } else {
  103.     if (pColor->format != XcmsCIELabFormat) {
  104.         if (_XcmsDIConvertColors(ccc, pColor,
  105.             &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIELabFormat)
  106.             == XcmsFailure) {
  107.         return(XcmsFailure);
  108.         }
  109.     }
  110.     if (XcmsCIELabQueryMaxC(ccc,
  111.         degrees(XCMS_CIELAB_PMETRIC_HUE(pColor->spec.CIELab.a_star, 
  112.                         pColor->spec.CIELab.b_star)),
  113.         pColor->spec.CIELab.L_star,
  114.         pColor) == XcmsFailure) {
  115.         return(XcmsFailure);
  116.     }
  117.     retval = _XcmsDIConvertColors(ccc, pColor,
  118.         &ccc->pPerScrnInfo->screenWhitePt, 1, XcmsCIEXYZFormat);
  119.     if (retval != XcmsFailure && pCompressed != NULL) {
  120.         *(pCompressed + i) = True;
  121.     }
  122.     return(retval);
  123.     }
  124. }
  125.