Ink coverage tool

This commit is contained in:
Jakub Melka 2021-07-04 18:11:41 +02:00
parent 8e0ad73c4c
commit 91d7355a20
3 changed files with 65 additions and 26 deletions

View File

@ -728,9 +728,9 @@ int PDFLittleCMS::installCmsPlugins()
cmsBool PDFLittleCMS::optimizePipeline(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt32Number* InputFormat, cmsUInt32Number* OutputFormat, cmsUInt32Number* dwFlags) cmsBool PDFLittleCMS::optimizePipeline(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt32Number* InputFormat, cmsUInt32Number* OutputFormat, cmsUInt32Number* dwFlags)
{ {
if (*dwFlags & cmsFLAGS_HIGHRESPRECALC) if (!(*dwFlags & cmsFLAGS_LOWRESPRECALC))
{ {
// Do not optimize // Optimize only on low resolution precalculation
return FALSE; return FALSE;
} }
@ -811,7 +811,7 @@ cmsBool PDFLittleCMS::optimizePipeline(cmsPipeline** Lut, cmsUInt32Number Intent
for (cmsUInt32Number i = 0; i < gridPoints; ++i) for (cmsUInt32Number i = 0; i < gridPoints; ++i)
{ {
const cmsFloat32Number x = i * factor; const cmsFloat32Number x = i * factor;
s2.SampledPoints[i] = cmsEvalToneCurveFloat(curve, x); s2.SampledPoints[i] = cmsEvalToneCurveFloat(curve, interpolate(x, 0.0, 1.0, low, high));
} }
s3.Type = type; s3.Type = type;

View File

@ -3975,6 +3975,7 @@ void PDFInkCoverageCalculator::perform(QSize size, const std::vector<PDFInteger>
info.textName = colorInfo.textName; info.textName = colorInfo.textName;
info.isSpot = colorInfo.isSpot; info.isSpot = colorInfo.isSpot;
info.coveredArea = pageCoverage[i]; info.coveredArea = pageCoverage[i];
info.ratio = pageRatioCoverage[i];
results.emplace_back(qMove(info)); results.emplace_back(qMove(info));
} }

View File

@ -93,8 +93,9 @@ int PDFToolInkCoverageApplication::execute(const PDFToolOptions& options)
formatter.beginTable("ink-coverage-by-page", PDFToolTranslationContext::tr("Ink Coverage by Page")); formatter.beginTable("ink-coverage-by-page", PDFToolTranslationContext::tr("Ink Coverage by Page"));
bool isHeaderProcessed = false; QLocale locale;
std::vector<pdf::PDFInkCoverageCalculator::InkCoverageChannelInfo> headerCoverage; std::vector<pdf::PDFInkCoverageCalculator::InkCoverageChannelInfo> headerCoverage;
for (const pdf::PDFInteger pageIndex : pageIndices) for (const pdf::PDFInteger pageIndex : pageIndices)
{ {
const std::vector<pdf::PDFInkCoverageCalculator::InkCoverageChannelInfo>* coverage = calculator.getInkCoverage(pageIndex); const std::vector<pdf::PDFInkCoverageCalculator::InkCoverageChannelInfo>* coverage = calculator.getInkCoverage(pageIndex);
@ -105,34 +106,71 @@ int PDFToolInkCoverageApplication::execute(const PDFToolOptions& options)
continue; continue;
} }
if (!isHeaderProcessed) for (const auto& info : *coverage)
{ {
if (!pdf::PDFInkCoverageCalculator::findCoverageInfoByName(headerCoverage, info.name))
{
headerCoverage.push_back(info);
}
}
}
formatter.beginTableHeaderRow("header"); formatter.beginTableHeaderRow("header");
formatter.writeTableHeaderColumn("page-no", PDFToolTranslationContext::tr("Page No."), Qt::AlignLeft); formatter.writeTableHeaderColumn("page-no", PDFToolTranslationContext::tr("Page No."), Qt::AlignLeft);
for (const pdf::PDFInkCoverageCalculator::InkCoverageChannelInfo& info : *coverage) for (const pdf::PDFInkCoverageCalculator::InkCoverageChannelInfo& info : headerCoverage)
{ {
formatter.writeTableHeaderColumn(QString("%1-ratio").arg(QString::fromLatin1(info.name)), PDFToolTranslationContext::tr("%1 Ratio [%]").arg(info.textName), Qt::AlignLeft); formatter.writeTableHeaderColumn(QString("%1-ratio").arg(QString::fromLatin1(info.name)), PDFToolTranslationContext::tr("%1 Ratio [%]").arg(info.textName), Qt::AlignLeft);
formatter.writeTableHeaderColumn(QString("%1-area").arg(QString::fromLatin1(info.name)), PDFToolTranslationContext::tr("%1 Covered [mm^2]").arg(info.textName), Qt::AlignLeft); formatter.writeTableHeaderColumn(QString("%1-area").arg(QString::fromLatin1(info.name)), PDFToolTranslationContext::tr("%1 Covered [mm^2]").arg(info.textName), Qt::AlignLeft);
} }
headerCoverage = *coverage;
formatter.endTableHeaderRow(); formatter.endTableHeaderRow();
isHeaderProcessed = true; for (const pdf::PDFInteger pageIndex : pageIndices)
{
const std::vector<pdf::PDFInkCoverageCalculator::InkCoverageChannelInfo>* coverage = calculator.getInkCoverage(pageIndex);
if (!coverage)
{
// Jakub Melka: Something bad happened?
continue;
} }
for (const auto& info : *headerCoverage) formatter.beginTableRow("page-coverage", pageIndex + 1);
formatter.writeTableColumn("page-no", locale.toString(pageIndex + 1), Qt::AlignRight);
for (const auto& info : headerCoverage)
{ {
pdf::PDFInkCoverageCalculator::InkCoverageChannelInfo* channelInfo = pdf::PDFInkCoverageCalculator::findCoverageInfoByName(*coverage, info.name); const pdf::PDFInkCoverageCalculator::InkCoverageChannelInfo* channelInfo = pdf::PDFInkCoverageCalculator::findCoverageInfoByName(*coverage, info.name);
pdf::PDFInkCoverageCalculator::InkCoverageChannelInfo* sumChannelInfo = pdf::PDFInkCoverageCalculator::findCoverageInfoByName(headerCoverage, info.name); pdf::PDFInkCoverageCalculator::InkCoverageChannelInfo* sumChannelInfo = pdf::PDFInkCoverageCalculator::findCoverageInfoByName(headerCoverage, info.name);
if (sumChannelInfo && channelInfo) if (channelInfo)
{ {
formatter.writeTableColumn(QString("%1-ratio").arg(QString::fromLatin1(info.name)), locale.toString(channelInfo->ratio * 100.0, 'f', 2), Qt::AlignRight);
formatter.writeTableColumn(QString("%1-area").arg(QString::fromLatin1(info.name)), locale.toString(channelInfo->coveredArea, 'f', 2), Qt::AlignRight);
sumChannelInfo->coveredArea += channelInfo->coveredArea; sumChannelInfo->coveredArea += channelInfo->coveredArea;
} }
else
{
formatter.writeTableColumn(QString("%1-ratio").arg(QString::fromLatin1(info.name)), QString(), Qt::AlignRight);
formatter.writeTableColumn(QString("%1-area").arg(QString::fromLatin1(info.name)), QString(), Qt::AlignRight);
}
}
formatter.endTableRow();
} }
// Summary
formatter.beginTableRow("sum-coverage");
formatter.writeTableColumn("sum", PDFToolTranslationContext::tr("Sum"), Qt::AlignRight);
for (const auto& info : headerCoverage)
{
const pdf::PDFInkCoverageCalculator::InkCoverageChannelInfo* channelInfo = pdf::PDFInkCoverageCalculator::findCoverageInfoByName(headerCoverage, info.name);
formatter.writeTableColumn(QString("%1-ratio").arg(QString::fromLatin1(info.name)), QString(), Qt::AlignRight);
formatter.writeTableColumn(QString("%1-area").arg(QString::fromLatin1(info.name)), locale.toString(channelInfo->coveredArea, 'f', 2), Qt::AlignRight);
} }
formatter.endTableRow();
formatter.endTable(); formatter.endTable();
formatter.endDocument(); formatter.endDocument();