ScColorTransform ScLcmsColorMgmtEngineImpl::createProofingTransform(ScColorMgmtEngine& engine, const ScColorProfile& inputProfile , eColorFormat inputFormat, const ScColorProfile& outputProfile, eColorFormat outputFormat, const ScColorProfile& proofProfile , eRenderIntent renderIntent, eRenderIntent proofingIntent, long transformFlags) { ScColorTransform transform(NULL); if (inputProfile.isNull() || outputProfile.isNull()) return transform; int inputProfEngineID = inputProfile.engine().engineID(); int outputProfEngineID = outputProfile.engine().engineID(); int proofProfEngineID = proofProfile.engine().engineID(); if ((engine.engineID() != m_engineID) || (inputProfEngineID != m_engineID) || (outputProfEngineID != m_engineID) || (proofProfEngineID != m_engineID)) return transform; const ScLcmsColorProfileImpl* lcmsInputProf = dynamic_cast<const ScLcmsColorProfileImpl*>(inputProfile.data()); const ScLcmsColorProfileImpl* lcmsOutputProf = dynamic_cast<const ScLcmsColorProfileImpl*>(outputProfile.data()); const ScLcmsColorProfileImpl* lcmsProofingProf = dynamic_cast<const ScLcmsColorProfileImpl*>(proofProfile.data()); if (!lcmsInputProf || !lcmsOutputProf || !lcmsProofingProf) return transform; long strategyFlags = 0; if (m_strategy.useBlackPointCompensation) strategyFlags |= Ctf_BlackPointCompensation; if (m_strategy.useBlackPreservation) strategyFlags |= Ctf_BlackPreservation; ScColorTransformInfo transInfo; transInfo.inputProfile = inputProfile.productDescription(); transInfo.outputProfile = outputProfile.productDescription(); transInfo.proofingProfile = proofProfile.productDescription(); transInfo.inputFormat = inputFormat; transInfo.outputFormat = outputFormat; transInfo.renderIntent = renderIntent; transInfo.proofingIntent = proofingIntent; transInfo.flags = transformFlags | strategyFlags; DWORD lcmsFlags = translateFlagsToLcmsFlags(transformFlags | strategyFlags); DWORD lcmsInputFmt = translateFormatToLcmsFormat(inputFormat); DWORD lcmsOutputFmt = translateFormatToLcmsFormat(outputFormat); int lcmsIntent = translateIntentToLcmsIntent(renderIntent); int lcmsPrfIntent = translateIntentToLcmsIntent(proofingIntent); if (transInfo.inputProfile != transInfo.proofingProfile) { if (transInfo.proofingProfile == transInfo.outputProfile) { transInfo.proofingIntent = Intent_Relative_Colorimetric; lcmsPrfIntent = translateIntentToLcmsIntent(Intent_Relative_Colorimetric); } transform = m_transformPool->findTransform(transInfo); if (transform.isNull()) { cmsSetErrorHandler(&cmsErrorHandler); cmsHTRANSFORM hTransform = NULL; try { hTransform = cmsCreateProofingTransform(lcmsInputProf->m_profileHandle , lcmsInputFmt, lcmsOutputProf->m_profileHandle, lcmsOutputFmt, lcmsProofingProf->m_profileHandle, lcmsIntent, lcmsPrfIntent, lcmsFlags | cmsFLAGS_SOFTPROOFING); if (hTransform) { ScLcmsColorTransformImpl* newTrans = new ScLcmsColorTransformImpl(engine, hTransform); newTrans->setTransformInfo(transInfo); transform = ScColorTransform(dynamic_cast<ScColorTransformData*>(newTrans)); m_transformPool->addTransform(transform, true); } } catch (lcmsException& e) { std::cerr << e.what() << std::endl; // #9922 : no idea why that crash in release mode /*if (transform.isNull() && hTransform) cmsDeleteTransform(hTransform);*/ transform = ScColorTransform(); } cmsSetErrorHandler(NULL); } } else { transformFlags &= (~Ctf_Softproofing); transformFlags &= (~Ctf_GamutCheck); lcmsFlags = translateFlagsToLcmsFlags(transformFlags | strategyFlags); transInfo.flags = transformFlags | strategyFlags; transInfo.renderIntent = proofingIntent; transInfo.proofingIntent = (eRenderIntent) 0; if (transInfo.inputProfile == transInfo.outputProfile) { lcmsFlags |= cmsFLAGS_NULLTRANSFORM; transInfo.inputProfile = QString(); transInfo.outputProfile = QString(); transInfo.proofingProfile = QString(); transInfo.renderIntent = (eRenderIntent) 0; transInfo.proofingIntent = (eRenderIntent) 0; transInfo.flags = 0; } transform = m_transformPool->findTransform(transInfo); if (transform.isNull()) { cmsSetErrorHandler(&cmsErrorHandler); cmsHTRANSFORM hTransform = NULL; try { hTransform = cmsCreateTransform(lcmsInputProf->m_profileHandle , lcmsInputFmt, lcmsOutputProf->m_profileHandle, lcmsOutputFmt, lcmsPrfIntent, lcmsFlags | cmsFLAGS_LOWRESPRECALC); if (hTransform) { ScLcmsColorTransformImpl* newTrans = new ScLcmsColorTransformImpl(engine, hTransform); newTrans->setTransformInfo(transInfo); transform = ScColorTransform(dynamic_cast<ScColorTransformData*>(newTrans)); m_transformPool->addTransform(transform, true); } } catch (lcmsException& e) { std::cerr << e.what() << std::endl; // #9922 : no idea why that crash in release mode /*if (transform.isNull() && hTransform) cmsDeleteTransform(hTransform);*/ transform = ScColorTransform(); } cmsSetErrorHandler(NULL); } } return transform; }
ScColorTransform ScLcms2ColorMgmtEngineImpl::createTransform(ScColorMgmtEngine& engine, const ScColorProfile& inputProfile , eColorFormat inputFormat, const ScColorProfile& outputProfile, eColorFormat outputFormat, eRenderIntent renderIntent, long transformFlags) { ScColorTransform transform(NULL); if (inputProfile.isNull() || outputProfile.isNull()) return transform; int inputProfEngineID = inputProfile.engine().engineID(); int outputProfEngineID = outputProfile.engine().engineID(); if ((engine.engineID() != m_engineID) || (inputProfEngineID != m_engineID) || (outputProfEngineID != m_engineID)) return transform; const ScLcms2ColorProfileImpl* lcmsInputProf = dynamic_cast<const ScLcms2ColorProfileImpl*>(inputProfile.data()); const ScLcms2ColorProfileImpl* lcmsOutputProf = dynamic_cast<const ScLcms2ColorProfileImpl*>(outputProfile.data()); if (!lcmsInputProf || !lcmsOutputProf) return transform; transformFlags &= (~Ctf_Softproofing); transformFlags &= (~Ctf_GamutCheck); long strategyFlags = 0; if (m_strategy.useBlackPointCompensation) strategyFlags |= Ctf_BlackPointCompensation; if (m_strategy.useBlackPreservation) strategyFlags |= Ctf_BlackPreservation; ScColorTransformInfo transInfo; transInfo.inputProfile = inputProfile.productDescription(); transInfo.outputProfile = outputProfile.productDescription(); transInfo.proofingProfile = QString(); transInfo.inputFormat = inputFormat; transInfo.outputFormat = outputFormat; transInfo.renderIntent = renderIntent; transInfo.proofingIntent = (eRenderIntent) 0; transInfo.flags = transformFlags | strategyFlags; bool nullTransform = false; if (transInfo.inputProfile == transInfo.outputProfile) { // This is a null transform transInfo.inputProfile = QString(); transInfo.outputProfile = QString(); transInfo.proofingProfile = QString(); transInfo.renderIntent = (eRenderIntent) 0; transInfo.proofingIntent = (eRenderIntent) 0; transInfo.flags = 0; nullTransform = true; } transform = m_transformPool->findTransform(transInfo); if (transform.isNull()) { cmsUInt32Number lcmsFlags = translateFlagsToLcmsFlags(transformFlags | strategyFlags); cmsUInt32Number lcmsInputFmt = translateFormatToLcmsFormat(inputFormat); cmsUInt32Number lcmsOutputFmt = translateFormatToLcmsFormat(outputFormat); int lcmsIntent = translateIntentToLcmsIntent(renderIntent); if (nullTransform) lcmsFlags |= cmsFLAGS_NULLTRANSFORM; cmsHTRANSFORM hTransform = NULL; hTransform = cmsCreateTransform(lcmsInputProf->m_profileHandle , lcmsInputFmt, lcmsOutputProf->m_profileHandle, lcmsOutputFmt, lcmsIntent, lcmsFlags | cmsFLAGS_LOWRESPRECALC); if (hTransform) { ScLcms2ColorTransformImpl* newTrans = new ScLcms2ColorTransformImpl(engine, hTransform); newTrans->setTransformInfo(transInfo); transform = ScColorTransform(dynamic_cast<ScColorTransformData*>(newTrans)); m_transformPool->addTransform(transform, true); } } return transform; }