/* Get the link from the CMS, but include proofing. We need to note that as an option in the rendering params. If we are doing transparency, that would only occur at the top of the stack TODO: Add error checking */ gcmmhlink_t gscms_get_link_proof(gcmmhprofile_t lcms_srchandle, gcmmhprofile_t lcms_deshandle, gcmmhprofile_t lcms_proofhandle, gsicc_rendering_param_t *rendering_params) { DWORD src_data_type,des_data_type; icColorSpaceSignature src_color_space,des_color_space; int src_nChannels,des_nChannels; /* Get the data types */ src_color_space = cmsGetColorSpace(lcms_srchandle); des_color_space = cmsGetColorSpace(lcms_deshandle); src_nChannels = _cmsChannelsOf(src_color_space); des_nChannels = _cmsChannelsOf(des_color_space); /* For now, just do single byte data, interleaved. We can change this when we use the transformation. */ src_data_type= (CHANNELS_SH(src_nChannels)|BYTES_SH(1)); des_data_type= (CHANNELS_SH(des_nChannels)|BYTES_SH(1)); /* Create the link. Note the gamut check alarm */ return(cmsCreateProofingTransform(lcms_srchandle, src_data_type, lcms_deshandle, des_data_type, lcms_proofhandle, rendering_params->rendering_intent, INTENT_ABSOLUTE_COLORIMETRIC, cmsFLAGS_GAMUTCHECK | cmsFLAGS_SOFTPROOFING )); }
// Read and create a BRAND NEW MPE LUT from a given profile. All stuff dependent of version, etc // is adjusted here in order to create a LUT that takes care of all those details cmsPipeline* _cmsReadInputLUT(cmsHPROFILE hProfile, int Intent) { cmsTagTypeSignature OriginalType; cmsTagSignature tag16 = Device2PCS16[Intent]; cmsTagSignature tagFloat = Device2PCSFloat[Intent]; cmsContext ContextID = cmsGetProfileContextID(hProfile); if (cmsIsTag(hProfile, tagFloat)) { // Float tag takes precedence // Floating point LUT are always V4, so no adjustment is required return cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat)); } // Revert to perceptual if no tag is found if (!cmsIsTag(hProfile, tag16)) { tag16 = Device2PCS16[0]; } if (cmsIsTag(hProfile, tag16)) { // Is there any LUT-Based table? // Check profile version and LUT type. Do the necessary adjustments if needed // First read the tag cmsPipeline* Lut = (cmsPipeline*) cmsReadTag(hProfile, tag16); if (Lut == NULL) return NULL; // After reading it, we have now info about the original type OriginalType = _cmsGetTagTrueType(hProfile, tag16); // The profile owns the Lut, so we need to copy it Lut = cmsPipelineDup(Lut); // We need to adjust data only for Lab16 on output if (OriginalType != cmsSigLut16Type || cmsGetPCS(hProfile) != cmsSigLabData) return Lut; // If the input is Lab, add also a conversion at the begin if (cmsGetColorSpace(hProfile) == cmsSigLabData) cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID)); // Add a matrix for conversion V2 to V4 Lab PCS cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)); return Lut; } // Lut was not found, try to create a matrix-shaper // Check if this is a grayscale profile. if (cmsGetColorSpace(hProfile) == cmsSigGrayData) { // if so, build appropiate conversion tables. // The tables are the PCS iluminant, scaled across GrayTRC return BuildGrayInputMatrixPipeline(hProfile); } // Not gray, create a normal matrix-shaper return BuildRGBInputMatrixShaper(hProfile); }
/* Get the link from the CMS, but include proofing and/or a device link profile. */ gcmmhlink_t gscms_get_link_proof_devlink(gcmmhprofile_t lcms_srchandle, gcmmhprofile_t lcms_proofhandle, gcmmhprofile_t lcms_deshandle, gcmmhprofile_t lcms_devlinkhandle, gsicc_rendering_param_t *rendering_params, bool src_dev_link, int cmm_flags, gs_memory_t *mem) { DWORD src_data_type,des_data_type; icColorSpaceSignature src_color_space,des_color_space; int src_nChannels,des_nChannels; int lcms_src_color_space, lcms_des_color_space; cmsHPROFILE hProfiles[5]; int nProfiles = 0; /* First handle all the source stuff */ src_color_space = cmsGetColorSpace(lcms_srchandle); lcms_src_color_space = _cmsLCMScolorSpace(src_color_space); /* littlecms returns -1 for types it does not (but should) understand */ if (lcms_src_color_space < 0) lcms_src_color_space = 0; src_nChannels = _cmsChannelsOf(src_color_space); /* For now, just do single byte data, interleaved. We can change this when we use the transformation. */ src_data_type = (COLORSPACE_SH(lcms_src_color_space)| CHANNELS_SH(src_nChannels)|BYTES_SH(2)); if (lcms_deshandle != NULL) { des_color_space = cmsGetColorSpace(lcms_deshandle); } else { /* We must have a device link profile. */ des_color_space = cmsGetPCS(lcms_deshandle); } lcms_des_color_space = _cmsLCMScolorSpace(des_color_space); if (lcms_des_color_space < 0) lcms_des_color_space = 0; des_nChannels = _cmsChannelsOf(des_color_space); des_data_type = (COLORSPACE_SH(lcms_des_color_space)| CHANNELS_SH(des_nChannels)|BYTES_SH(2)); /* lcms proofing transform has a clunky API and can't include the device link profile if we have both. So use cmsCreateMultiprofileTransform instead and round trip the proofing profile. */ hProfiles[nProfiles++] = lcms_srchandle; if (lcms_proofhandle != NULL) { hProfiles[nProfiles++] = lcms_proofhandle; hProfiles[nProfiles++] = lcms_proofhandle; } hProfiles[nProfiles++] = lcms_deshandle; if (lcms_devlinkhandle != NULL) { hProfiles[nProfiles++] = lcms_devlinkhandle; } return(cmsCreateMultiprofileTransform(hProfiles, nProfiles, src_data_type, des_data_type, rendering_params->rendering_intent, (cmm_flags | cmsFLAGS_BLACKPOINTCOMPENSATION | cmsFLAGS_HIGHRESPRECALC | cmsFLAGS_NOTCACHE))); }
// Compute Black tone curve on a CMYK -> CMYK transform. This is done by // using the proof direction on both profiles to find K->L* relationship // then joining both curves. dwFlags may include black point compensation. cmsToneCurve* _cmsBuildKToneCurve(cmsContext ContextID, cmsUInt32Number nPoints, cmsUInt32Number nProfiles, const cmsUInt32Number Intents[], const cmsHPROFILE hProfiles[], const cmsBool BPC[], const cmsFloat64Number AdaptationStates[], cmsUInt32Number dwFlags) { cmsToneCurve *in, *out, *KTone; // Make sure CMYK -> CMYK if (cmsGetColorSpace(hProfiles[0]) != cmsSigCmykData || cmsGetColorSpace(hProfiles[nProfiles-1])!= cmsSigCmykData) return NULL; // Make sure last is an output profile if (cmsGetDeviceClass(hProfiles[nProfiles - 1]) != cmsSigOutputClass) return NULL; // Create individual curves. BPC works also as each K to L* is // computed as a BPC to zero black point in case of L* in = ComputeKToLstar(ContextID, nPoints, nProfiles - 1, Intents, hProfiles, BPC, AdaptationStates, dwFlags); if (in == NULL) return NULL; out = ComputeKToLstar(ContextID, nPoints, 1, Intents + (nProfiles - 1), hProfiles + (nProfiles - 1), BPC + (nProfiles - 1), AdaptationStates + (nProfiles - 1), dwFlags); if (out == NULL) { cmsFreeToneCurve(in); return NULL; } // Build the relationship. This effectively limits the maximum accuracy to 16 bits, but // since this is used on black-preserving LUTs, we are not loosing accuracy in any case KTone = cmsJoinToneCurve(ContextID, in, out, nPoints); // Get rid of components cmsFreeToneCurve(in); cmsFreeToneCurve(out); // Something went wrong... if (KTone == NULL) return NULL; // Make sure it is monotonic if (!cmsIsToneCurveMonotonic(KTone)) { cmsFreeToneCurve(KTone); return NULL; } return KTone; }
static cmsBool GetXFormColorSpaces(int nProfiles, cmsHPROFILE hProfiles[], cmsColorSpaceSignature* Input, cmsColorSpaceSignature* Output) { cmsColorSpaceSignature ColorSpaceIn, ColorSpaceOut; cmsColorSpaceSignature PostColorSpace; int i; if (nProfiles <= 0) return FALSE; if (hProfiles[0] == NULL) return FALSE; *Input = PostColorSpace = cmsGetColorSpace(hProfiles[0]); for (i=0; i < nProfiles; i++) { cmsProfileClassSignature cls; cmsHPROFILE hProfile = hProfiles[i]; int lIsInput = (PostColorSpace != cmsSigXYZData) && (PostColorSpace != cmsSigLabData); if (hProfile == NULL) return FALSE; cls = cmsGetDeviceClass(hProfile); if (cls == cmsSigNamedColorClass) { ColorSpaceIn = cmsSig1colorData; ColorSpaceOut = (nProfiles > 1) ? cmsGetPCS(hProfile) : cmsGetColorSpace(hProfile); } else if (lIsInput || (cls == cmsSigLinkClass)) { ColorSpaceIn = cmsGetColorSpace(hProfile); ColorSpaceOut = cmsGetPCS(hProfile); } else { ColorSpaceIn = cmsGetPCS(hProfile); ColorSpaceOut = cmsGetColorSpace(hProfile); } if (i==0) *Input = ColorSpaceIn; PostColorSpace = ColorSpaceOut; } *Output = PostColorSpace; return TRUE; }
void ScImgDataLoader_JPEG::loadEmbeddedProfile(const QString& fn, int /*page*/) { m_embeddedProfile.resize(0); m_profileComponents = 0; if (!QFile::exists(fn)) return; struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; FILE *infile; cinfo.err = jpeg_std_error (&jerr.pub); jerr.pub.error_exit = my_error_exit; infile = NULL; if (setjmp (jerr.setjmp_buffer)) { jpeg_destroy_decompress (&cinfo); if (infile) fclose (infile); return; } jpeg_create_decompress (&cinfo); if ((infile = fopen (fn.toLocal8Bit(), "rb")) == NULL) return; jpeg_stdio_src(&cinfo, infile); jpeg_save_markers(&cinfo, ICC_MARKER, 0xFFFF); jpeg_read_header(&cinfo, true); //jpeg_start_decompress(&cinfo); unsigned int EmbedLen = 0; unsigned char* EmbedBuffer; if (read_jpeg_marker(ICC_MARKER,&cinfo, &EmbedBuffer, &EmbedLen)) { cmsHPROFILE prof = cmsOpenProfileFromMem(EmbedBuffer, EmbedLen); if (prof) { if (static_cast<int>(cmsGetColorSpace(prof)) == icSigRgbData) m_profileComponents = 3; if (static_cast<int>(cmsGetColorSpace(prof)) == icSigCmykData) m_profileComponents = 4; if (static_cast<int>(cmsGetColorSpace(prof)) == icSigGrayData) m_profileComponents = 1; m_embeddedProfile = QByteArray((const char*) EmbedBuffer, EmbedLen); } cmsCloseProfile(prof); free(EmbedBuffer); } //(void) jpeg_finish_decompress(&cinfo); fclose (infile); jpeg_destroy_decompress (&cinfo); }
// Create an output MPE LUT from agiven profile. Version mismatches are handled here cmsPipeline* _cmsReadOutputLUT(cmsHPROFILE hProfile, int Intent) { cmsTagTypeSignature OriginalType; cmsTagSignature tag16 = PCS2Device16[Intent]; cmsTagSignature tagFloat = PCS2DeviceFloat[Intent]; cmsContext ContextID = cmsGetProfileContextID(hProfile); if (cmsIsTag(hProfile, tagFloat)) { // Float tag takes precedence // Floating point LUT are always V4, so no adjustment is required return cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat)); } // Revert to perceptual if no tag is found if (!cmsIsTag(hProfile, tag16)) { tag16 = PCS2Device16[0]; } if (cmsIsTag(hProfile, tag16)) { // Is there any LUT-Based table? // Check profile version and LUT type. Do the necessary adjustments if needed // First read the tag cmsPipeline* Lut = (cmsPipeline*) cmsReadTag(hProfile, tag16); if (Lut == NULL) return NULL; // After reading it, we have info about the original type OriginalType = _cmsGetTagTrueType(hProfile, tag16); // The profile owns the Lut, so we need to copy it Lut = cmsPipelineDup(Lut); if (Lut == NULL) return NULL; // Now it is time for a controversial stuff. I found that for 3D LUTS using // Lab used as indexer space, trilinear interpolation should be used if (cmsGetPCS(hProfile) == cmsSigLabData) ChangeInterpolationToTrilinear(Lut); // We need to adjust data only for Lab and Lut16 type if (OriginalType != cmsSigLut16Type || cmsGetPCS(hProfile) != cmsSigLabData) return Lut; // Add a matrix for conversion V4 to V2 Lab PCS cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID)); return Lut; } // Lut not found, try to create a matrix-shaper // Check if this is a grayscale profile. if (cmsGetColorSpace(hProfile) == cmsSigGrayData) { // if so, build appropiate conversion tables. // The tables are the PCS iluminant, scaled across GrayTRC return BuildGrayOutputPipeline(hProfile); } // Not gray, create a normal matrix-shaper return BuildRGBOutputMatrixShaper(hProfile); }
bool LcmsColorProfileContainer::init() { if (d->profile) cmsCloseProfile(d->profile); d->profile = cmsOpenProfileFromMem((void*)d->data->rawData().constData(), d->data->rawData().size()); #ifndef NDEBUG if (d->data->rawData().size() == 4096) { warnPigment << "Profile has a size of 4096, which is suspicious and indicates a possible misuse of QIODevice::read(int), check your code."; } #endif if (d->profile) { wchar_t buffer[_BUFFER_SIZE_]; d->colorSpaceSignature = cmsGetColorSpace(d->profile); d->deviceClass = cmsGetDeviceClass(d->profile); cmsGetProfileInfo(d->profile, cmsInfoDescription, cmsNoLanguage, cmsNoCountry, buffer, _BUFFER_SIZE_); d->productDescription = QString::fromWCharArray(buffer); d->valid = true; cmsGetProfileInfo(d->profile, cmsInfoModel, cmsNoLanguage, cmsNoCountry, buffer, _BUFFER_SIZE_); d->name = QString::fromWCharArray(buffer); cmsGetProfileInfo(d->profile, cmsInfoManufacturer, cmsNoLanguage, cmsNoCountry, buffer, _BUFFER_SIZE_); d->manufacturer = QString::fromWCharArray(buffer); // Check if the profile can convert (something->this) d->suitableForOutput = cmsIsMatrixShaper(d->profile) || ( cmsIsCLUT(d->profile, INTENT_PERCEPTUAL, LCMS_USED_AS_INPUT) && cmsIsCLUT(d->profile, INTENT_PERCEPTUAL, LCMS_USED_AS_OUTPUT) ); return true; } return false; }
int cmsDetectBlackPoint(LPcmsCIEXYZ BlackPoint, cmsHPROFILE hProfile, int Intent, DWORD dwFlags) { // v4 + perceptual & saturation intents does have its own black point if ((cmsGetProfileICCversion(hProfile) >= 0x4000000) && (Intent == INTENT_PERCEPTUAL || Intent == INTENT_SATURATION)) { return GetV4PerceptualBlack(BlackPoint, hProfile, dwFlags); } #ifdef HONOR_BLACK_POINT_TAG // v2, v4 rel/abs colorimetric if (cmsIsTag(hProfile, icSigMediaBlackPointTag) && Intent == INTENT_RELATIVE_COLORIMETRIC) { cmsCIEXYZ BlackXYZ, UntrustedBlackPoint, TrustedBlackPoint, MediaWhite; cmsCIELab Lab; // If black point is specified, then use it, cmsTakeMediaBlackPoint(&BlackXYZ, hProfile); cmsTakeMediaWhitePoint(&MediaWhite, hProfile); // Black point is absolute XYZ, so adapt to D50 to get PCS value cmsAdaptToIlluminant(&UntrustedBlackPoint, &MediaWhite, cmsD50_XYZ(), &BlackXYZ); // Force a=b=0 to get rid of any chroma cmsXYZ2Lab(NULL, &Lab, &UntrustedBlackPoint); Lab.a = Lab.b = 0; if (Lab.L > 50) Lab.L = 50; // Clip to L* <= 50 cmsLab2XYZ(NULL, &TrustedBlackPoint, &Lab); // Return BP as D50 relative or absolute XYZ (depends on flags) if (!(dwFlags & LCMS_BPFLAGS_D50_ADAPTED)) cmsAdaptToIlluminant(BlackPoint, cmsD50_XYZ(), &MediaWhite, &TrustedBlackPoint); else *BlackPoint = TrustedBlackPoint; } #endif // If output profile, discount ink-limiting if (Intent == INTENT_RELATIVE_COLORIMETRIC && (cmsGetDeviceClass(hProfile) == icSigOutputClass) && (cmsGetColorSpace(hProfile) == icSigCmykData)) return BlackPointUsingPerceptualBlack(BlackPoint, hProfile, dwFlags); // Nope, compute BP using current intent. return BlackPointAsDarkerColorant(hProfile, Intent, BlackPoint, dwFlags); }
/** * gimp_color_profile_is_cmyk: * @profile: a #GimpColorProfile * * Return value: %TRUE if the profile's color space is CMYK, %FALSE * otherwise. * * Since: 2.10 **/ gboolean gimp_color_profile_is_cmyk (GimpColorProfile *profile) { g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), FALSE); return (cmsGetColorSpace (profile->priv->lcms_profile) == cmsSigCmykData); }
// Equivalence between ICC color spaces and lcms color spaces static int GetProfileColorSpace(cmsHPROFILE hProfile) { cmsColorSpaceSignature ProfileSpace = cmsGetColorSpace(hProfile); return _cmsLCMScolorSpace(ProfileSpace); }
static cmsPipeline* _cmsReadFloatOutputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat) { cmsContext ContextID = cmsGetProfileContextID(hProfile); cmsPipeline* Lut = cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat)); cmsColorSpaceSignature PCS = cmsGetPCS(hProfile); cmsColorSpaceSignature dataSpace = cmsGetColorSpace(hProfile); if (Lut == NULL) return NULL; // If PCS is Lab or XYZ, the floating point tag is accepting data in the space encoding, // and since the formatter has already accomodated to 0..1.0, we should undo this change if ( PCS == cmsSigLabData) { cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID)); } else if (PCS == cmsSigXYZData) { cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID)); } // the output can be Lab or XYZ, in which case normalisation is needed on the end of the pipeline if ( dataSpace == cmsSigLabData) { cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID)); } else if ( dataSpace == cmsSigXYZData) { cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID)); } return Lut; }
/*static cmsPipeline* _cmsReadFloatInputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat) { cmsContext ContextID = cmsGetProfileContextID(hProfile); cmsPipeline* Lut = cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat)); cmsColorSpaceSignature spc = cmsGetColorSpace(hProfile); if (Lut == NULL) return NULL; // If PCS is Lab or XYZ, the floating point tag is accepting data in the space encoding, // and since the formatter has already accomodated to 0..1.0, we should undo this change if ( spc == cmsSigLabData) { cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID)); } else if (spc == cmsSigXYZData) { cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID)); } return Lut; } */ static cmsPipeline* _cmsReadFloatInputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat) { cmsContext ContextID = cmsGetProfileContextID(hProfile); cmsPipeline* Lut = cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat)); cmsColorSpaceSignature spc = cmsGetColorSpace(hProfile); cmsColorSpaceSignature PCS = cmsGetPCS(hProfile); if (Lut == NULL) return NULL; // input and output of transform are in lcms 0..1 encoding. If XYZ or Lab spaces are used, // these need to be normalized into the appropriate ranges (Lab = 100,0,0, XYZ=1.0,1.0,1.0) if ( spc == cmsSigLabData) { cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID)); } else if (spc == cmsSigXYZData) { cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID)); } if ( PCS == cmsSigLabData) { cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID)); } else if( PCS == cmsSigXYZData) { cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID)); } return Lut; }
/** * gimp_color_profile_is_rgb: * @profile: a #GimpColorProfile * * Return value: %TRUE if the profile's color space is RGB, %FALSE * otherwise. * * Since: 2.10 **/ gboolean gimp_color_profile_is_rgb (GimpColorProfile profile) { g_return_val_if_fail (profile != NULL, FALSE); return (cmsGetColorSpace (profile) == cmsSigRgbData); }
static PyObject* cms_profile_getattro(CmsProfileObject* self, PyObject* name) { PyObject* name_bytes; char* name_string; if (!PyUnicode_Check(name)) return NULL; if (!(name_bytes = PyUnicode_AsASCIIString(name))) return NULL; if (!(name_string = PyBytes_AsString(name_bytes))) return NULL; if (!strcmp(name_string, "product_name")) return PyUnicode_FromFormat("%s", cmsTakeProductName(self->profile)); if (!strcmp(name_string, "product_desc")) return PyUnicode_FromFormat("%s", cmsTakeProductDesc(self->profile)); if (!strcmp(name_string, "product_info")) return PyUnicode_FromFormat("%s", cmsTakeProductInfo(self->profile)); if (!strcmp(name_string, "rendering_intent")) return PyLong_FromLong(cmsTakeRenderingIntent(self->profile)); if (!strcmp(name_string, "pcs")) return PyUnicode_FromFormat("%s", findICmode(cmsGetPCS(self->profile))); if (!strcmp(name_string, "color_space")) return PyUnicode_FromFormat("%s", findICmode(cmsGetColorSpace(self->profile))); /* FIXME: add more properties (creation_datetime etc) */ return PyObject_GenericGetAttr((PyObject*)self, name); }
static int GetProfileColorSpace(cmsHPROFILE hProfile) { icColorSpaceSignature ProfileSpace = cmsGetColorSpace(hProfile); switch (ProfileSpace) { case icSigGrayData: return PT_GRAY; case icSigRgbData: return PT_RGB; case icSigCmyData: return PT_CMY; case icSigCmykData: return PT_CMYK; case icSigYCbCrData:return PT_YCbCr; case icSigLuvData: return PT_YUV; case icSigXYZData: return PT_XYZ; case icSigLabData: return PT_Lab; case icSigLuvKData: return PT_YUVK; case icSigHsvData: return PT_HSV; case icSigHlsData: return PT_HLS; case icSigYxyData: return PT_Yxy; case icSigHexachromeData: return PT_HiFi; default: return icMaxEnumData; } }
void libcdr::CDRParserState::setColorTransform(const std::vector<unsigned char> &profile) { if (profile.empty()) return; cmsHPROFILE tmpProfile = cmsOpenProfileFromMem(&profile[0], cmsUInt32Number(profile.size())); if (!tmpProfile) return; cmsHPROFILE tmpRGBProfile = cmsCreate_sRGBProfile(); cmsColorSpaceSignature signature = cmsGetColorSpace(tmpProfile); switch (signature) { case cmsSigCmykData: { if (m_colorTransformCMYK2RGB) cmsDeleteTransform(m_colorTransformCMYK2RGB); m_colorTransformCMYK2RGB = cmsCreateTransform(tmpProfile, TYPE_CMYK_DBL, tmpRGBProfile, TYPE_RGB_8, INTENT_PERCEPTUAL, 0); } break; case cmsSigRgbData: { if (m_colorTransformRGB2RGB) cmsDeleteTransform(m_colorTransformRGB2RGB); m_colorTransformRGB2RGB = cmsCreateTransform(tmpProfile, TYPE_RGB_8, tmpRGBProfile, TYPE_RGB_8, INTENT_PERCEPTUAL, 0); } break; default: break; } cmsCloseProfile(tmpProfile); cmsCloseProfile(tmpRGBProfile); }
// Read the AToD0 tag, adjusting the encoding of Lab or XYZ if neded static cmsPipeline* _cmsReadFloatDevicelinkTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat) { cmsContext ContextID = cmsGetProfileContextID(hProfile); cmsPipeline* Lut = cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat)); cmsColorSpaceSignature PCS = cmsGetPCS(hProfile); cmsColorSpaceSignature spc = cmsGetColorSpace(hProfile); if (Lut == NULL) return NULL; if (spc == cmsSigLabData) { cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID)); } else if (spc == cmsSigXYZData) { cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID)); } if (PCS == cmsSigLabData) { cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID)); } else if (PCS == cmsSigXYZData) { cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID)); } return Lut; }
static int WriteInputMatrixShaper(cmsIOHANDLER* m, cmsHPROFILE hProfile, cmsStage* Matrix, cmsStage* Shaper) { cmsColorSpaceSignature ColorSpace; int rc; cmsCIEXYZ BlackPointAdaptedToD50; ColorSpace = cmsGetColorSpace(hProfile); cmsDetectBlackPoint(&BlackPointAdaptedToD50, hProfile, INTENT_RELATIVE_COLORIMETRIC, 0); if (ColorSpace == cmsSigGrayData) { cmsToneCurve** ShaperCurve = _cmsStageGetPtrToCurveSet(Shaper); rc = EmitCIEBasedA(m, ShaperCurve[0], &BlackPointAdaptedToD50); } else if (ColorSpace == cmsSigRgbData) { rc = EmitCIEBasedABC(m, GetPtrToMatrix(Matrix), _cmsStageGetPtrToCurveSet(Shaper), &BlackPointAdaptedToD50); } else { cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Profile is not suitable for CSA. Unsupported colorspace."); return 0; } return rc; }
gboolean gimp_lcms_profile_is_cmyk (GimpColorProfile profile) { g_return_val_if_fail (profile != NULL, FALSE); return (cmsGetColorSpace (profile) == cmsSigCmykData); }
static cmsUInt32Number determine_lcms_format (const Babl *babl, cmsHPROFILE profile) { cmsUInt32Number format = COLORSPACE_SH (PT_ANY); gint channels, bpc, alpha; const Babl *type; channels = cmsChannelsOf (cmsGetColorSpace (profile)); alpha = babl_format_get_n_components (babl) - channels; bpc = babl_format_get_bytes_per_pixel (babl) / babl_format_get_n_components (babl); type = babl_format_get_type (babl, 0); if (type == babl_type ("half") || type == babl_type ("float") || type == babl_type ("double")) format |= FLOAT_SH (1); /* bpc == 8 overflows the bitfield otherwise */ bpc &= 0x07; /* * This is needed so the alpha component lines up with RGBA float * for our memcpy hack later on. */ if (alpha > 1 || (alpha && channels != 3)) return 0; format |= EXTRA_SH (alpha) | CHANNELS_SH (channels) | BYTES_SH (bpc); return format; }
/* Get the number of channels for the profile. Input count */ int gscms_get_input_channel_count(gcmmhprofile_t profile) { icColorSpaceSignature colorspace; colorspace = cmsGetColorSpace(profile); return(_cmsChannelsOf(colorspace)); }
// This one includes abstract profiles as well. Matrix-shaper cannot be obtained on that device class. The // tag name here may default to AToB0 cmsPipeline* _cmsReadDevicelinkLUT(cmsHPROFILE hProfile, int Intent) { cmsPipeline* Lut; cmsTagTypeSignature OriginalType; cmsTagSignature tag16 = Device2PCS16[Intent]; cmsTagSignature tagFloat = Device2PCSFloat[Intent]; cmsContext ContextID = cmsGetProfileContextID(hProfile); if (cmsIsTag(hProfile, tagFloat)) { // Float tag takes precedence // Floating point LUT are always V4, no adjustment is required return cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat)); } tagFloat = Device2PCSFloat[0]; if (cmsIsTag(hProfile, tagFloat)) { return cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat)); } if (!cmsIsTag(hProfile, tag16)) { // Is there any LUT-Based table? tag16 = Device2PCS16[0]; if (!cmsIsTag(hProfile, tag16)) return NULL; } // Check profile version and LUT type. Do the necessary adjustments if needed // Read the tag Lut = (cmsPipeline*) cmsReadTag(hProfile, tag16); if (Lut == NULL) return NULL; // The profile owns the Lut, so we need to copy it Lut = cmsPipelineDup(Lut); // After reading it, we have info about the original type OriginalType = _cmsGetTagTrueType(hProfile, tag16); // We need to adjust data for Lab16 on output if (OriginalType != cmsSigLut16Type) return Lut; // Here it is possible to get Lab on both sides if (cmsGetPCS(hProfile) == cmsSigLabData) { cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageAllocLabV4ToV2(ContextID)); } if (cmsGetColorSpace(hProfile) == cmsSigLabData) { cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageAllocLabV2ToV4(ContextID)); } return Lut; }
/* Get the link from the CMS. TODO: Add error checking */ gcmmhlink_t gscms_get_link(gcmmhprofile_t lcms_srchandle, gcmmhprofile_t lcms_deshandle, gsicc_rendering_param_t *rendering_params) { DWORD src_data_type,des_data_type; icColorSpaceSignature src_color_space,des_color_space; int src_nChannels,des_nChannels; int lcms_src_color_space, lcms_des_color_space; /* Check for case of request for a transfrom from a device link profile in that case, the destination profile is NULL */ /* First handle all the source stuff */ src_color_space = cmsGetColorSpace(lcms_srchandle); lcms_src_color_space = _cmsLCMScolorSpace(src_color_space); /* littlecms returns -1 for types it does not (but should) understand */ if (lcms_src_color_space < 0) lcms_src_color_space = 0; src_nChannels = _cmsChannelsOf(src_color_space); /* For now, just do single byte data, interleaved. We can change this when we use the transformation. */ src_data_type = (COLORSPACE_SH(lcms_src_color_space)| CHANNELS_SH(src_nChannels)|BYTES_SH(2)); if (lcms_deshandle != NULL) { des_color_space = cmsGetColorSpace(lcms_deshandle); } else { /* We must have a device link profile. */ des_color_space = cmsGetPCS(lcms_deshandle); } lcms_des_color_space = _cmsLCMScolorSpace(des_color_space); if (lcms_des_color_space < 0) lcms_des_color_space = 0; des_nChannels = _cmsChannelsOf(des_color_space); des_data_type = (COLORSPACE_SH(lcms_des_color_space)| CHANNELS_SH(des_nChannels)|BYTES_SH(2)); /* Create the link */ return(cmsCreateTransform(lcms_srchandle, src_data_type, lcms_deshandle, des_data_type, rendering_params->rendering_intent, (cmsFLAGS_BLACKPOINTCOMPENSATION | cmsFLAGS_HIGHRESPRECALC))); /* cmsFLAGS_HIGHRESPRECALC) cmsFLAGS_NOTPRECALC cmsFLAGS_LOWRESPRECALC*/ }
KoRGBChromaticities* LcmsColorProfileContainer::chromaticitiesFromProfile() const { if (cmsGetColorSpace(d->profile) != cmsSigRgbData) return 0; KoRGBChromaticities* chromaticities = new KoRGBChromaticities(); chromaticities->primaries.Red = RGB2xyY(d->profile, 1.0f, 0.0f, 0.0f); chromaticities->primaries.Green = RGB2xyY(d->profile, 0.0f, 1.0f, 0.0f); chromaticities->primaries.Blue = RGB2xyY(d->profile, 0.0f, 0.0f, 1.0f); chromaticities->whitePoint = RGB2xyY(d->profile, 1.0f, 1.0f, 1.0f); return chromaticities; }
static PyObject* cms_profile_getattr(CmsProfileObject* self, char* name) { #ifdef PY3 if (!strcmp(name, "product_name")) return PyUnicode_DecodeFSDefault(cmsTakeProductName(self->profile)); if (!strcmp(name, "product_desc")) return PyUnicode_DecodeFSDefault(cmsTakeProductDesc(self->profile)); if (!strcmp(name, "product_info")) return PyUnicode_DecodeFSDefault(cmsTakeProductInfo(self->profile)); if (!strcmp(name, "rendering_intent")) return PyLong_FromLong(cmsTakeRenderingIntent(self->profile)); if (!strcmp(name, "pcs")) return PyUnicode_DecodeFSDefault(findICmode(cmsGetPCS(self->profile))); if (!strcmp(name, "color_space")) return PyUnicode_DecodeFSDefault(findICmode(cmsGetColorSpace(self->profile))); /* FIXME: add more properties (creation_datetime etc) */ return PyObject_GenericGetAttr((PyObject *)self, PyUnicode_DecodeFSDefault(name)); #else if (!strcmp(name, "product_name")) return PyString_FromString(cmsTakeProductName(self->profile)); if (!strcmp(name, "product_desc")) return PyString_FromString(cmsTakeProductDesc(self->profile)); if (!strcmp(name, "product_info")) return PyString_FromString(cmsTakeProductInfo(self->profile)); if (!strcmp(name, "rendering_intent")) return PyInt_FromLong(cmsTakeRenderingIntent(self->profile)); if (!strcmp(name, "pcs")) return PyString_FromString(findICmode(cmsGetPCS(self->profile))); if (!strcmp(name, "color_space")) return PyString_FromString(findICmode(cmsGetColorSpace(self->profile))); /* FIXME: add more properties (creation_datetime etc) */ return Py_FindMethod(cms_profile_methods, (PyObject*) self, name); #endif }
void IccColorProfile::calculateFloatUIMinMax(void) { QVector<KoChannelInfo::DoubleRange> &ret = d->shared->uiMinMaxes; cmsHPROFILE cprofile = d->shared->lcmsProfile->lcmsProfile(); Q_ASSERT(cprofile); cmsColorSpaceSignature color_space_sig = cmsGetColorSpace(cprofile); unsigned int num_channels = cmsChannelsOf(color_space_sig); unsigned int color_space_mask = _cmsLCMScolorSpace(color_space_sig); Q_ASSERT(num_channels>=1 && num_channels <=4); // num_channels==1 is for grayscale, we need to handle it Q_ASSERT(color_space_mask); // to try to find the max range of float/doubles for this profile, // pass in min/max int and make the profile convert that // this is far from perfect, we need a better way, if possible to get the "bounds" of a profile uint16_t in_min_pixel[4] = {0,0,0,0}; uint16_t in_max_pixel[4] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF}; double out_min_pixel[4] = {0,0,0,0}; double out_max_pixel[4] = {0,0,0,0}; cmsHTRANSFORM trans = cmsCreateTransform( cprofile, (COLORSPACE_SH(color_space_mask)|CHANNELS_SH(num_channels)|BYTES_SH(2)), cprofile, (COLORSPACE_SH(color_space_mask)|FLOAT_SH(1)|CHANNELS_SH(num_channels)|BYTES_SH(0)), //NOTE THAT 'BYTES' FIELD IS SET TO ZERO ON DLB because 8 bytes overflows the bitfield INTENT_PERCEPTUAL, 0); // does the intent matter in this case? if (trans) { cmsDoTransform(trans, in_min_pixel, out_min_pixel, 1); cmsDoTransform(trans, in_max_pixel, out_max_pixel, 1); cmsDeleteTransform(trans); }//else, we'll just default to [0..1] below ret.resize(num_channels); for (unsigned int i=0; i<num_channels; ++i) { if (out_min_pixel[i] < out_max_pixel[i]) { ret[i].minVal = out_min_pixel[i]; ret[i].maxVal = out_max_pixel[i]; } else { // aparently we can't even guarentee that converted_to_double(0x0000) < converted_to_double(0xFFFF) // assume [0..1] in such cases // we need to find a really solid way of determining the bounds of a profile, if possible ret[i].minVal = 0; ret[i].maxVal = 1; } } }
static int WriteInputMatrixShaper(cmsIOHANDLER* m, cmsHPROFILE hProfile, cmsStage* Matrix, cmsStage* Shaper) { cmsColorSpaceSignature ColorSpace; int rc; cmsCIEXYZ BlackPointAdaptedToD50; ColorSpace = cmsGetColorSpace(hProfile); cmsDetectBlackPoint(&BlackPointAdaptedToD50, hProfile, INTENT_RELATIVE_COLORIMETRIC, 0); if (ColorSpace == cmsSigGrayData) { cmsToneCurve** ShaperCurve = _cmsStageGetPtrToCurveSet(Shaper); rc = EmitCIEBasedA(m, ShaperCurve[0], &BlackPointAdaptedToD50); } else if (ColorSpace == cmsSigRgbData) { cmsMAT3 Mat; int i, j; memmove(&Mat, GetPtrToMatrix(Matrix), sizeof(Mat)); for (i=0; i < 3; i++) for (j=0; j < 3; j++) Mat.v[i].n[j] *= MAX_ENCODEABLE_XYZ; rc = EmitCIEBasedABC(m, (cmsFloat64Number *) &Mat, _cmsStageGetPtrToCurveSet(Shaper), &BlackPointAdaptedToD50); } else { cmsSignalError(m ->ContextID, cmsERROR_COLORSPACE_CHECK, "Profile is not suitable for CSA. Unsupported colorspace."); return 0; } return rc; }
gsicc_colorbuffer_t gscms_get_profile_data_space(gcmmhprofile_t profile) { icColorSpaceSignature colorspace; colorspace = cmsGetColorSpace(profile); switch( colorspace ) { case icSigXYZData: return(gsCIEXYZ); case icSigLabData: return(gsCIELAB); case icSigRgbData: return(gsRGB); case icSigGrayData: return(gsGRAY); case icSigCmykData: return(gsCMYK); default: return(gsNCHANNEL); } }
// Returns TRUE if the profile is implemented as matrix-shaper cmsBool CMSEXPORT cmsIsMatrixShaper(cmsHPROFILE hProfile) { switch (cmsGetColorSpace(hProfile)) { case cmsSigGrayData: return cmsIsTag(hProfile, cmsSigGrayTRCTag); case cmsSigRgbData: return (cmsIsTag(hProfile, cmsSigRedColorantTag) && cmsIsTag(hProfile, cmsSigGreenColorantTag) && cmsIsTag(hProfile, cmsSigBlueColorantTag) && cmsIsTag(hProfile, cmsSigRedTRCTag) && cmsIsTag(hProfile, cmsSigGreenTRCTag) && cmsIsTag(hProfile, cmsSigBlueTRCTag)); default: return FALSE; } }