⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xcmscvcols.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $XConsortium: XcmsCvCols.c,v 1.9 91/07/25 01:08:38 rws Exp $" *//* * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. * 	All Rights Reserved *  * This file is a component of an X Window System-specific implementation * of Xcms based on the TekColor Color Management System.  Permission is * hereby granted to use, copy, modify, sell, and otherwise distribute this * software and its documentation for any purpose and without fee, provided * that this copyright, permission, and disclaimer notice is reproduced in * all copies of this software and in supporting documentation.  TekColor * is a trademark of Tektronix, Inc. *  * Tektronix makes no representation about the suitability of this software * for any purpose.  It is provided "as is" and with all faults. *  * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE.  IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. * * *	NAME *		XcmsCvCols.c * *	DESCRIPTION *		TekCMS API routine that converts between the *		device-independent color spaces. * * */#include "Xlibint.h"#include "Xcmsint.h"/* *      EXTERNS *              External declarations required locally to this package *              that are not already declared in any of the included header *		files (external includes or internal includes). */extern XcmsRegColorSpaceEntry _XcmsRegColorSpaces[];extern XcmsColorSpace **_XcmsDIColorSpaces;extern XcmsColorSpace **_XcmsDDColorSpaces;/* *      LOCAL DEFINES */#define	DD_FORMAT	0x01#define	DI_FORMAT	0x02#define	MIX_FORMAT	0x04#ifndef MAX#  define MAX(x,y) ((x) > (y) ? (x) : (y))#endif/* *      FORWARD DECLARATIONS */Status _XcmsDIConvertColors();Status _XcmsDDConvertColors();/************************************************************************ *									* *			 PRIVATE ROUTINES				* *									* ************************************************************************//* *	NAME *		EqualCIEXYZ * *	SYNOPSIS */static intEqualCIEXYZ(p1, p2)    XcmsColor *p1, *p2;/* *	DESCRIPTION *		Compares two XcmsColor structures that are in XcmsCIEXYZFormat * *	RETURNS *		Returns 1 if equal; 0 otherwise. * */{    if (p1->format != XcmsCIEXYZFormat || p2->format != XcmsCIEXYZFormat) {	return(0);    }    if ((p1->spec.CIEXYZ.X != p2->spec.CIEXYZ.X)	    || (p1->spec.CIEXYZ.Y != p2->spec.CIEXYZ.Y)	    || (p1->spec.CIEXYZ.Z != p2->spec.CIEXYZ.Z)) {	return(0);    }    return(1);}/* *	NAME *		XcmsColorSpace * *	SYNOPSIS */static XcmsColorSpace *ColorSpaceOfID(ccc, id)    XcmsCCC ccc;    XcmsColorFormat	id;/* *	DESCRIPTION *		Returns a pointer to the color space structure *		(XcmsColorSpace) associated with the specified color space *		ID. * *	RETURNS *		Pointer to matching XcmsColorSpace structure if found; *		otherwise NULL. */{    XcmsColorSpace	**papColorSpaces;    if (ccc == NULL) {	return(NULL);    }    /*     * First try Device-Independent color spaces     */    papColorSpaces = _XcmsDIColorSpaces;    if (papColorSpaces != NULL) {	while (*papColorSpaces != NULL) {	    if ((*papColorSpaces)->id == id) {		return(*papColorSpaces);	    }	    papColorSpaces++;	}    }    /*     * Next try Device-Dependent color spaces     */    papColorSpaces = ((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet)->DDColorSpaces;    if (papColorSpaces != NULL) {	while (*papColorSpaces != NULL) {	    if ((*papColorSpaces)->id == id) {		return(*papColorSpaces);	    }	    papColorSpaces++;	}    }    return(NULL);}/* *	NAME *		ValidDIColorSpaceID * *	SYNOPSIS */static intValidDIColorSpaceID(id)    XcmsColorFormat id;/* *	DESCRIPTION *		Determines if the specified color space ID is a valid *		Device-Independent color space in the specified Color *		Conversion Context. * *	RETURNS *		Returns zero if not valid; otherwise non-zero. */{    XcmsColorSpace **papRec;    papRec = _XcmsDIColorSpaces;    if (papRec != NULL) {	while (*papRec != NULL) {	    if ((*papRec)->id == id) {		return(1);	    }	    papRec++;	}    }    return(0);}/* *	NAME *		ValidDDColorSpaceID * *	SYNOPSIS */static intValidDDColorSpaceID(ccc, id)    XcmsCCC ccc;    XcmsColorFormat id;/* *	DESCRIPTION *		Determines if the specified color space ID is a valid *		Device-Dependent color space in the specified Color *		Conversion Context. * *	RETURNS *		Returns zero if not valid; otherwise non-zero. */{    XcmsColorSpace **papRec;    if (ccc->pPerScrnInfo->state == XcmsInitSuccess ||	    ccc->pPerScrnInfo->state == XcmsInitDefault) {	papRec = ((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet)->DDColorSpaces;	while (*papRec != NULL) {	    if ((*papRec)->id == id) {		return(1);	    }	    papRec++;	}    }    return(0);}/* *	NAME *		ConvertMixedColors - Convert XcmsColor structures * *	SYNOPSIS */static StatusConvertMixedColors(ccc, pColors_in_out, pWhitePt, nColors,	targetFormat, format_flag)    XcmsCCC ccc;    XcmsColor *pColors_in_out;    XcmsColor *pWhitePt;    unsigned int nColors;    XcmsColorFormat targetFormat;    unsigned char format_flag;/* *	DESCRIPTION *		This routine will only convert the following types of *		batches: *			DI to DI *			DD to DD *			DD to CIEXYZ *		In other words, it will not convert the following types of *		batches: *			DI to DD *			DD to DI(not CIEXYZ) *		 *		format_flag: *		    0x01 : convert Device-Dependent only specifications to the *			target format. *		    0x02 : convert Device-Independent only specifications to the *			target format. *		    0x03 : convert all specifications to the target format. * *	RETURNS *		XcmsFailure if failed, *		XcmsSuccess if none of the color specifications were *			compressed in the conversion process *		XcmsSuccessWithCompression if at least one of the *			color specifications were compressed in the *			conversion process. * */{    XcmsColor *pColor, *pColors_start;    XcmsColorFormat format;    Status retval_tmp;    Status retval = XcmsSuccess;    unsigned int iColors;    unsigned int nBatch;    /*     * Convert array of mixed color specifications in batches of     * contiguous formats to the target format     */    iColors = 0;    while (iColors < nColors) {	/*	 * Find contiguous array of color specifications with the	 * same format	 */	pColor = pColors_start = pColors_in_out + iColors;	format = pColors_start->format;	nBatch = 0;	while (iColors < nColors && pColor->format == format) {		pColor++;		nBatch++;		iColors++;	}	if (format != targetFormat) {	    /*	     * Need to convert this batch from current format to target format.	     */	    if (XCMS_DI_ID(format) && (format_flag & DI_FORMAT) &&		XCMS_DI_ID(targetFormat)) {		/*		 * DI->DI		 *		 * Format of interest is Device-Independent,		 * This batch contains Device-Independent specifications, and		 * the Target format is Device-Independent.		 */		retval_tmp = _XcmsDIConvertColors(ccc, pColors_start, pWhitePt,			nBatch, targetFormat);	    } else if (XCMS_DD_ID(format) && (format_flag & DD_FORMAT) &&		    (targetFormat == XcmsCIEXYZFormat)) {		/*		 * DD->CIEXYZ		 *		 * Format of interest is Device-Dependent,		 * This batch contains Device-Dependent specifications, and		 * the Target format is CIEXYZ.		 *		 * Since DD->CIEXYZ we can use NULL instead of pCompressed.		 */		if ((ccc->whitePtAdjProc != NULL) && !_XcmsEqualWhitePts(ccc,			pWhitePt, ScreenWhitePointOfCCC(ccc))) {		    /*		     * Need to call WhiteAdjustProc (Screen White Point to		     *   White Point).		     */		    retval_tmp = (*ccc->whitePtAdjProc)(ccc,			    ScreenWhitePointOfCCC(ccc), pWhitePt,			    XcmsCIEXYZFormat, pColors_start, nBatch,			    (Bool *)NULL);		} else {		    retval_tmp = _XcmsDDConvertColors(ccc, pColors_start,			    nBatch, XcmsCIEXYZFormat, (Bool *)NULL);		}	    } else if (XCMS_DD_ID(format) && (format_flag & DD_FORMAT) &&		    XCMS_DD_ID(targetFormat)) {		/*		 * DD->DD(not CIEXYZ)		 *		 * Format of interest is Device-Dependent,		 * This batch contains Device-Dependent specifications, and		 * the Target format is Device-Dependent and not CIEXYZ.		 */		retval_tmp = _XcmsDDConvertColors(ccc, pColors_start, nBatch,			targetFormat, (Bool *)NULL);	    } else {		/*		 * This routine is called for the wrong reason.		 */		return(XcmsFailure);	    }	    if (retval_tmp == XcmsFailure) {		return(XcmsFailure);	    }	    retval = MAX(retval, retval_tmp);	}    }    return(retval);}/************************************************************************ *									* *			 API PRIVATE ROUTINES				* *									* ************************************************************************//* *	NAME *		_XcmsEqualWhitePts * *	SYNOPSIS */int_XcmsEqualWhitePts(ccc, pWhitePt1, pWhitePt2)    XcmsCCC ccc;    XcmsColor *pWhitePt1, *pWhitePt2;/* *	DESCRIPTION * *	RETURNS *		Returns 0 if not equal; otherwise 1. * */{    XcmsColor tmp1, tmp2;    bcopy((char *)pWhitePt1, (char *)&tmp1, sizeof(XcmsColor));    bcopy((char *)pWhitePt2, (char *)&tmp2, sizeof(XcmsColor));    if (tmp1.format != XcmsCIEXYZFormat) {	if (_XcmsDIConvertColors(ccc, &tmp1, (XcmsColor *) NULL, 1,		XcmsCIEXYZFormat)==0) {	    return(0);	}    }    if (tmp2.format != XcmsCIEXYZFormat) {	if (_XcmsDIConvertColors(ccc, &tmp2, (XcmsColor *) NULL, 1,		XcmsCIEXYZFormat)==0) {	    return(0);	}    }    return (EqualCIEXYZ(&tmp1, &tmp2));}/* *	NAME *		_XcmsDIConvertColors - Convert XcmsColor structures * *	SYNOPSIS */Status_XcmsDIConvertColors(ccc, pColors_in_out, pWhitePt, nColors,	newFormat)    XcmsCCC ccc;    XcmsColor *pColors_in_out;    XcmsColor *pWhitePt;    unsigned int nColors;    XcmsColorFormat newFormat;/* *	DESCRIPTION *		Convert XcmsColor structures to another Device-Independent *		form. * *		Here are some assumptions that this routine makes: *		1. The calling routine has already checked if *		    pColors_in_out->format == newFormat, therefore *		    there is no need to check again here. *		2. The calling routine has already checked nColors, *		    therefore this routine assumes nColors > 0. *		3. The calling routine may want to convert only between *			CIExyY <-> CIEXYZ <-> CIEuvY *		    therefore, this routine allows pWhitePt to equal NULL. *		 * *	RETURNS *		XcmsFailure if failed, *		XcmsSuccess if succeeded. * */{    XcmsColorSpace *pFrom, *pTo;    XcmsConversionProc *src_to_CIEXYZ, *src_from_CIEXYZ;    XcmsConversionProc *dest_to_CIEXYZ, *dest_from_CIEXYZ;    XcmsConversionProc *to_CIEXYZ_stop, *from_CIEXYZ_start;    XcmsConversionProc *tmp;    /*     * Allow pWhitePt to equal NULL.  This appropriate when converting     *    anywhere between:     *		CIExyY <-> CIEXYZ <-> CIEuvY     */    if (pColors_in_out == NULL ||	    !ValidDIColorSpaceID(pColors_in_out->format) ||	    !ValidDIColorSpaceID(newFormat)) {	return(XcmsFailure);    }    /*     * Get a handle on the function list for the current specification format     */    if ((pFrom = ColorSpaceOfID(ccc, pColors_in_out->format))	    == NULL) {	return(XcmsFailure);    }    /*     * Get a handle on the function list for the new specification format     */    if ((pTo = ColorSpaceOfID(ccc, newFormat)) == NULL) {	return(XcmsFailure);    }    src_to_CIEXYZ = pFrom->to_CIEXYZ;    src_from_CIEXYZ = pFrom->from_CIEXYZ;    dest_to_CIEXYZ = pTo->to_CIEXYZ;    dest_from_CIEXYZ = pTo->from_CIEXYZ;    if (pTo->inverse_flag && pFrom->inverse_flag) {	/*	 * Find common function pointers	 */	for (to_CIEXYZ_stop = src_to_CIEXYZ; *to_CIEXYZ_stop; to_CIEXYZ_stop++){	    for (tmp = dest_to_CIEXYZ; *tmp; tmp++) {		if (*to_CIEXYZ_stop == *tmp) {		    goto Continue;		}	    }	}Continue:	/*	 * Execute the functions to CIEXYZ, stopping short as necessary	 */	while (src_to_CIEXYZ != to_CIEXYZ_stop) {	    if ((*src_to_CIEXYZ++)(ccc, pWhitePt, pColors_in_out,		    nColors) == XcmsFailure) {		return(XcmsFailure);	    }	}	/*	 * Determine where to start on the from_CIEXYZ path.	 */	from_CIEXYZ_start = dest_from_CIEXYZ;	tmp = src_from_CIEXYZ;	while ((*from_CIEXYZ_start == *tmp) && (*from_CIEXYZ_start != NULL)) {	    from_CIEXYZ_start++;	    tmp++;	}    } else {	/*	 * The function in at least one of the Color Spaces are not	 * complementary, i.e.,	 *	for an i, 0 <= i < n elements	 *	from_CIEXYZ[i] is not the inverse of to_CIEXYZ[i]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -