📄 xcmscvcols.c
字号:
* * Execute the functions all the way to CIEXYZ */ while (*src_to_CIEXYZ) { 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; } /* * Execute the functions from CIEXYZ. */ while (*from_CIEXYZ_start) { if ((*from_CIEXYZ_start++)(ccc, pWhitePt, pColors_in_out, nColors) == XcmsFailure) { return(XcmsFailure); } } return(XcmsSuccess);}/* * NAME * _XcmsDDConvertColors - Convert XcmsColor structures * * SYNOPSIS */Status_XcmsDDConvertColors(ccc, pColors_in_out, nColors, newFormat, pCompressed) XcmsCCC ccc; XcmsColor *pColors_in_out; unsigned int nColors; XcmsColorFormat newFormat; Bool *pCompressed;/* * DESCRIPTION * Convert XcmsColor structures: * * 1. From CIEXYZ to Device-Dependent formats (typically RGB and * RGBi), * or * 2. Between Device-Dependent formats (typically RGB and RGBi). * * Assumes that these specifications have already been white point * adjusted if necessary from Client White Point to Screen * White Point. Therefore, the white point now associated * with the specifications is the Screen White Point. * * pCompressed may be NULL. If so this indicates that the * calling routine is not interested in knowing exactly which * color was compressed, if any. * * * 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. * */{ XcmsColorSpace *pFrom, *pTo; XcmsConversionProc *src_to_CIEXYZ, *src_from_CIEXYZ; XcmsConversionProc *dest_to_CIEXYZ, *dest_from_CIEXYZ; XcmsConversionProc *from_CIEXYZ_start, *to_CIEXYZ_stop; XcmsConversionProc *tmp; int retval; int hasCompressed = 0; if (ccc == NULL || pColors_in_out == NULL) { return(XcmsFailure); } if (nColors == 0 || pColors_in_out->format == newFormat) { /* do nothing */ return(XcmsSuccess); } if (((XcmsFunctionSet *)ccc->pPerScrnInfo->functionSet) == NULL) { return(XcmsFailure); /* hmm, an internal error? */ } /* * Its ok if pColors_in_out->format == XcmsCIEXYZFormat * or * if newFormat == XcmsCIEXYZFormat */ if ( !( ValidDDColorSpaceID(ccc, pColors_in_out->format) || (pColors_in_out->format == XcmsCIEXYZFormat)) || !(ValidDDColorSpaceID(ccc, newFormat) || newFormat == XcmsCIEXYZFormat)) { return(XcmsFailure); } if ((pFrom = ColorSpaceOfID(ccc, pColors_in_out->format)) == NULL){ return(XcmsFailure); } 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 */ while (src_to_CIEXYZ != to_CIEXYZ_stop) { retval = (*src_to_CIEXYZ++)(ccc, pColors_in_out, nColors, pCompressed); if (retval == XcmsFailure) { return(XcmsFailure); } hasCompressed |= (retval == XcmsSuccessWithCompression); } /* * 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] * * Execute the functions all the way to CIEXYZ */ while (*src_to_CIEXYZ) { retval = (*src_to_CIEXYZ++)(ccc, pColors_in_out, nColors, pCompressed); if (retval == XcmsFailure) { return(XcmsFailure); } hasCompressed |= (retval == XcmsSuccessWithCompression); } /* * Determine where to start on the from_CIEXYZ path. */ from_CIEXYZ_start = dest_from_CIEXYZ; } while (*from_CIEXYZ_start) { retval = (*from_CIEXYZ_start++)(ccc, pColors_in_out, nColors, pCompressed); if (retval == XcmsFailure) { return(XcmsFailure); } hasCompressed |= (retval == XcmsSuccessWithCompression); } return(hasCompressed ? XcmsSuccessWithCompression : XcmsSuccess);}/************************************************************************ * * * PUBLIC ROUTINES * * * ************************************************************************//* * NAME * XcmsConvertColors - Convert XcmsColor structures * * SYNOPSIS */StatusXcmsConvertColors(ccc, pColors_in_out, nColors, targetFormat, pCompressed) XcmsCCC ccc; XcmsColor *pColors_in_out; unsigned int nColors; XcmsColorFormat targetFormat; Bool *pCompressed;/* * DESCRIPTION * Convert XcmsColor structures to another format * * RETURNS * XcmsFailure if failed, * XcmsSuccess if succeeded without gamut compression, * XcmsSuccessWithCompression if succeeded with gamut * compression. * */{ XcmsColor clientWhitePt; XcmsColor Color1; XcmsColor *pColors_tmp; int callWhiteAdjustProc = 0; XcmsColorFormat format; Status retval; unsigned char contents_flag = 0x00; unsigned int iColors; if (ccc == NULL || pColors_in_out == NULL || !(ValidDIColorSpaceID(targetFormat) || ValidDDColorSpaceID(ccc, targetFormat))) { return(XcmsFailure); } /* * Check formats in color specification array */ format = pColors_in_out->format; for (pColors_tmp = pColors_in_out, iColors = nColors; iColors; pColors_tmp++, iColors--) { if (!(ValidDIColorSpaceID(pColors_tmp->format) || ValidDDColorSpaceID(ccc, pColors_tmp->format))) { return(XcmsFailure); } if (XCMS_DI_ID(pColors_tmp->format)) { contents_flag |= DI_FORMAT; } else { contents_flag |= DD_FORMAT; } if (pColors_tmp->format != format) { contents_flag |= MIX_FORMAT; } } /* * Check if we need the Client White Point. */ if ((contents_flag & DI_FORMAT) || XCMS_DI_ID(targetFormat)) { /* To proceed, we need to get the Client White Point */ bcopy((char *)&ccc->clientWhitePt, (char *)&clientWhitePt, sizeof(XcmsColor)); if (clientWhitePt.format == XcmsUndefinedFormat) { /* * Client White Point is undefined, therefore set to the Screen * White Point. * Since Client White Point == Screen White Point, WhiteAdjustProc * is not called. */ bcopy((char *)&ccc->pPerScrnInfo->screenWhitePt, (char *)&clientWhitePt, sizeof(XcmsColor)); } else if ((ccc->whitePtAdjProc != NULL) && !_XcmsEqualWhitePts(ccc, &clientWhitePt, ScreenWhitePointOfCCC(ccc))) { /* * Client White Point != Screen White Point, and WhiteAdjustProc * is not NULL, therefore, will need to call it when * converting between DI and DD specifications. */ callWhiteAdjustProc = 1; } } /* * Make copy of array of color specifications */ if (nColors > 1) { pColors_tmp = (XcmsColor *) Xmalloc(nColors * sizeof(XcmsColor)); } else { pColors_tmp = &Color1; } bcopy((char *)pColors_in_out, (char *)pColors_tmp, nColors * sizeof(XcmsColor)); /* * zero out pCompressed */ if (pCompressed) { bzero((char *)pCompressed, nColors * sizeof(Bool)); } if (contents_flag == DD_FORMAT || contents_flag == DI_FORMAT) { /* * ENTIRE ARRAY IS IN ONE FORMAT. */ if (XCMS_DI_ID(format) && XCMS_DI_ID(targetFormat)) { /* * DI-to-DI only conversion */ retval = _XcmsDIConvertColors(ccc, pColors_tmp, &clientWhitePt, nColors, targetFormat); } else if (XCMS_DD_ID(format) && XCMS_DD_ID(targetFormat)) { /* * DD-to-DD only conversion * Since DD->DD there will be no compressed thus we can * pass NULL instead of pCompressed. */ retval = _XcmsDDConvertColors(ccc, pColors_tmp, nColors, targetFormat, (Bool *)NULL); } else { /* * Otherwise we have: * 1. Device-Independent to Device-Dependent Conversion * OR * 2. Device-Dependent to Device-Independent Conversion * * We need to go from oldFormat -> CIEXYZ -> targetFormat * adjusting for white points as necessary. */ if (XCMS_DI_ID(format)) { /* * 1. Device-Independent to Device-Dependent Conversion */ if (callWhiteAdjustProc) { /* * White Point Adjustment * Client White Point to Screen White Point */ retval = (*ccc->whitePtAdjProc)(ccc, &clientWhitePt, ScreenWhitePointOfCCC(ccc), targetFormat, pColors_tmp, nColors, pCompressed); } else { if (_XcmsDIConvertColors(ccc, pColors_tmp, &clientWhitePt, nColors, XcmsCIEXYZFormat) == XcmsFailure) { goto Failure; } retval = _XcmsDDConvertColors(ccc, pColors_tmp, nColors, targetFormat, pCompressed); } } else { /* * 2. Device-Dependent to Device-Independent Conversion */ if (callWhiteAdjustProc) { /* * White Point Adjustment * Screen White Point to Client White Point */ retval = (*ccc->whitePtAdjProc)(ccc, ScreenWhitePointOfCCC(ccc), &clientWhitePt, targetFormat, pColors_tmp, nColors, pCompressed); } else { /* * Since DD->CIEXYZ, no compression takes place therefore * we can pass NULL instead of pCompressed. */ if (_XcmsDDConvertColors(ccc, pColors_tmp, nColors, XcmsCIEXYZFormat, (Bool *)NULL) == XcmsFailure) { goto Failure; } retval = _XcmsDIConvertColors(ccc, pColors_tmp, &clientWhitePt, nColors, targetFormat); } } } } else { /* * ARRAY HAS MIXED FORMATS. */ if ((contents_flag == (DI_FORMAT | MIX_FORMAT)) && XCMS_DI_ID(targetFormat)) { /* * Convert from DI to DI in batches of contiguous formats * * Because DI->DI, WhiteAdjustProc not called. */ retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt, nColors, targetFormat, (unsigned char)DI_FORMAT); } else if ((contents_flag == (DD_FORMAT | MIX_FORMAT)) && XCMS_DD_ID(targetFormat)) { /* * Convert from DD to DD in batches of contiguous formats * * Because DD->DD, WhiteAdjustProc not called. */ retval = ConvertMixedColors(ccc, pColors_tmp, (XcmsColor *)NULL, nColors, targetFormat, (unsigned char)DD_FORMAT); } else if (XCMS_DI_ID(targetFormat)) { /* * We need to convert from DI-to-DI and DD-to-DI, therefore * 1. convert DD specifications to CIEXYZ, then * 2. convert all in batches to the target DI format. * * Note that ConvertMixedColors will call WhiteAdjustProc * as necessary. */ /* * Convert only DD specifications in batches of contiguous formats * to CIEXYZ * * Since DD->CIEXYZ, ConvertMixedColors will apply WhiteAdjustProc * if required. */ retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt, nColors, XcmsCIEXYZFormat, (unsigned char)DD_FORMAT); /* * Because at this point we may have a mix of DI formats * (e.g., CIEXYZ, CIELuv) we must convert the specs to the * target DI format in batches of contiguous source formats. */ retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt, nColors, targetFormat, (unsigned char)DI_FORMAT); } else { /* * We need to convert from DI-to-DD and DD-to-DD, therefore * 1. convert DI specifications to CIEXYZ, then * 2. convert all to the DD target format. * * This allows white point adjustment and gamut compression * to be applied to all the color specifications in one * swoop if those functions do in fact modify the entire * group of color specifications. */ /* * Convert in batches to CIEXYZ * * If DD->CIEXYZ, ConvertMixedColors will apply WhiteAdjustProc * if required. */ if ((retval = ConvertMixedColors(ccc, pColors_tmp, &clientWhitePt, nColors, XcmsCIEXYZFormat, (unsigned char)(DI_FORMAT | DD_FORMAT))) == XcmsFailure) { goto Failure; } /* * Convert all specifications (now in CIEXYZ format) to * the target DD format. * Since CIEXYZ->DD, compression MAY take place therefore * we must pass pCompressed. * Note that WhiteAdjustProc must be used if necessary. */ if (callWhiteAdjustProc) { /* * White Point Adjustment * Client White Point to Screen White Point */ retval = (*ccc->whitePtAdjProc)(ccc, &clientWhitePt, ScreenWhitePointOfCCC(ccc), targetFormat, pColors_tmp, nColors, pCompressed); } else { retval = _XcmsDDConvertColors(ccc, pColors_tmp, nColors, targetFormat, pCompressed); } } } if (retval != XcmsFailure) { bcopy((char *)pColors_tmp, (char *)pColors_in_out, nColors * sizeof(XcmsColor)); } if (nColors > 1) { Xfree((char *)pColors_tmp); } return(retval);Failure: if (nColors > 1) { Xfree((char *)pColors_tmp); } return(XcmsFailure);}/* * NAME * XcmsRegFormatOfPrefix * * SYNOPSIS */XcmsColorFormat_XcmsRegFormatOfPrefix(prefix) char *prefix;/* * DESCRIPTION * Returns a color space ID associated with the specified * X Consortium registered color space prefix. * * RETURNS * The color space ID if found; * otherwise NULL. */{ XcmsRegColorSpaceEntry *pEntry = _XcmsRegColorSpaces; while (pEntry->prefix != NULL) { if (strcmp(prefix, pEntry->prefix) == 0) { return(pEntry->id); } pEntry++; } return(XcmsUndefinedFormat);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -