From 53849f51e1a16684c19a773d1077e0af6b77972d Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Sun, 24 Dec 2023 12:01:15 +0100 Subject: [PATCH] Issue #129: Cannot compile with lcms 2.16 --- Pdf4QtLibCore/sources/pdfcms.cpp | 53 ++++++-------------------------- RELEASES.txt | 1 + 2 files changed, 11 insertions(+), 43 deletions(-) diff --git a/Pdf4QtLibCore/sources/pdfcms.cpp b/Pdf4QtLibCore/sources/pdfcms.cpp index 8f2dbed..ff23fab 100644 --- a/Pdf4QtLibCore/sources/pdfcms.cpp +++ b/Pdf4QtLibCore/sources/pdfcms.cpp @@ -803,6 +803,7 @@ cmsBool PDFLittleCMS::optimizePipeline(cmsPipeline** Lut, cmsUInt32Number Intent { cmsContext contextId = cmsGetPipelineContextID(*Lut); cmsPipeline* pipeline = cmsPipelineAlloc(contextId, T_CHANNELS(*InputFormat), T_CHANNELS(*OutputFormat)); + if (!pipeline) { return FALSE; @@ -820,53 +821,19 @@ cmsBool PDFLittleCMS::optimizePipeline(cmsPipeline** Lut, cmsUInt32Number Intent const cmsToneCurve* curve = data->TheCurves[i]; const cmsInt32Number type = cmsGetToneCurveParametricType(curve); - if (type != 0 && !cmsIsToneCurveMultisegment(curve)) + if (type != 0) { - std::array segments = { }; + const cmsUInt32Number tableEntryCount = cmsGetToneCurveEstimatedTableEntries(curve); + const cmsUInt16Number* tableEntries = cmsGetToneCurveEstimatedTable(curve); - const cmsFloat64Number* params = cmsGetToneCurveParams(curve); - - cmsCurveSegment& s1 = segments[0]; - cmsCurveSegment& s2 = segments[1]; - cmsCurveSegment& s3 = segments[2]; - - const cmsFloat32Number eps = cmsFloat32Number(1e-5); - const cmsFloat32Number low = 0.0f - eps; - const cmsFloat32Number high = 1.0f + eps; - - s1.Type = type; - s1.nGridPoints = 0; - s1.SampledPoints = nullptr; - std::copy(params, params + (sizeof(s1.Params) / sizeof(*s1.Params)), s1.Params); - s1.x0 = std::numeric_limits::min(); - s1.x1 = low; - - const cmsUInt32Number gridPoints = 1024; - const cmsFloat32Number factor = 1.0f / cmsFloat32Number(gridPoints - 1); - - s2.Type = 0; - s2.nGridPoints = gridPoints; - s2.SampledPoints = static_cast(_cmsCalloc(contextId, gridPoints, sizeof(*s2.SampledPoints))); - std::copy(params, params + (sizeof(s2.Params) / sizeof(*s2.Params)), s2.Params); - s2.x0 = low; - s2.x1 = high; - - for (cmsUInt32Number iPt = 0; iPt < gridPoints; ++iPt) + if (tableEntryCount > 0) { - const cmsFloat32Number x = iPt * factor; - s2.SampledPoints[iPt] = cmsEvalToneCurveFloat(curve, interpolate(x, 0.0, 1.0, low, high)); + curves[i] = cmsBuildTabulatedToneCurve16(contextId, tableEntryCount, tableEntries); + } + else + { + curves[i] = cmsDupToneCurve(curve); } - - s3.Type = type; - s3.nGridPoints = 0; - s3.SampledPoints = nullptr; - std::copy(params, params + (sizeof(s3.Params) / sizeof(*s3.Params)), s3.Params); - s3.x0 = high; - s3.x1 = std::numeric_limits::max(); - - curves[i] = cmsBuildSegmentedToneCurve(contextId, cmsUInt32Number(segments.size()), segments.data()); - - _cmsFree(contextId, s2.SampledPoints); } else { diff --git a/RELEASES.txt b/RELEASES.txt index 7b9b5af..afb0207 100644 --- a/RELEASES.txt +++ b/RELEASES.txt @@ -1,4 +1,5 @@ CURRENT: + - Issue #129: Cannot compile with lcms 2.16 - Issue #126: Remove include from main headers - Issue #119: Improve search bar 2 (the revenge) - Issue #118: Adding CMAKE options for minimal builds