Correct color of inks

This commit is contained in:
Jakub Melka
2021-03-27 17:36:52 +01:00
parent 019637f9f2
commit 94fdd0f63f
4 changed files with 59 additions and 17 deletions

View File

@ -1987,7 +1987,7 @@ void PDFTransparencyRenderer::processSoftMask(const PDFDictionary* softMask)
return; return;
} }
PDFInkMapper inkMapper(getDocument()); PDFInkMapper inkMapper(nullptr, getDocument());
PDFTransparencyRenderer softMaskRenderer(getPage(), getDocument(), getFontCache(), getCMS(), getOptionalContentActivity(), &inkMapper, m_settings, getPagePointToDevicePointMatrix()); PDFTransparencyRenderer softMaskRenderer(getPage(), getDocument(), getFontCache(), getCMS(), getOptionalContentActivity(), &inkMapper, m_settings, getPagePointToDevicePointMatrix());
softMaskRenderer.initializeProcessor(); softMaskRenderer.initializeProcessor();
@ -3005,7 +3005,8 @@ bool PDFTransparencyRenderer::isMultithreadedPathSamplingUsed(QRect fillRect) co
return fillRect.width() * fillRect.height() > m_settings.multithreadingPathSampleThreshold && fillRect.width() > 1; return fillRect.width() * fillRect.height() > m_settings.multithreadingPathSampleThreshold && fillRect.width() > 1;
} }
PDFInkMapper::PDFInkMapper(const PDFDocument* document) : PDFInkMapper::PDFInkMapper(const PDFCMSManager* manager, const PDFDocument* document) :
m_cmsManager(manager),
m_document(document) m_document(document)
{ {
// Initialize device separations // Initialize device separations
@ -3023,96 +3024,113 @@ std::vector<PDFInkMapper::ColorInfo> PDFInkMapper::getSeparations(uint32_t proce
std::vector<ColorInfo> result; std::vector<ColorInfo> result;
result.reserve(getActiveSpotColorCount() + processColorCount); result.reserve(getActiveSpotColorCount() + processColorCount);
PDFRenderErrorReporterDummy renderErrorReporter;
PDFCMSPointer cms = m_cmsManager ? m_cmsManager->getCurrentCMS() : nullptr;
switch (processColorCount) switch (processColorCount)
{ {
case 1: case 1:
{ {
PDFDeviceGrayColorSpace grayColorSpace;
ColorInfo gray; ColorInfo gray;
gray.name = "Gray"; gray.name = "Gray";
gray.textName = PDFTranslationContext::tr("Process Gray"); gray.textName = PDFTranslationContext::tr("Gray");
gray.canBeActive = true; gray.canBeActive = true;
gray.active = true; gray.active = true;
gray.isSpot = false; gray.isSpot = false;
gray.spotColorIndex = 0; gray.spotColorIndex = 0;
gray.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceGray; gray.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceGray;
gray.color = cms ? grayColorSpace.getColor(PDFColor(1.0f), cms.get(), RenderingIntent::Perceptual, &renderErrorReporter, true) : QColor();
result.emplace_back(qMove(gray)); result.emplace_back(qMove(gray));
break; break;
} }
case 3: case 3:
{ {
PDFDeviceRGBColorSpace rgbColorSpace;
ColorInfo red; ColorInfo red;
red.name = "Red"; red.name = "Red";
red.textName = PDFTranslationContext::tr("Process Red"); red.textName = PDFTranslationContext::tr("Red");
red.canBeActive = true; red.canBeActive = true;
red.active = true; red.active = true;
red.isSpot = false; red.isSpot = false;
red.spotColorIndex = 0; red.spotColorIndex = 0;
red.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceRGB; red.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceRGB;
red.color = cms ? rgbColorSpace.getColor(PDFColor(1.0f, 0.0f, 0.0f), cms.get(), RenderingIntent::Perceptual, &renderErrorReporter, true) : QColor();
result.emplace_back(qMove(red)); result.emplace_back(qMove(red));
ColorInfo green; ColorInfo green;
green.name = "Green"; green.name = "Green";
green.textName = PDFTranslationContext::tr("Process Green"); green.textName = PDFTranslationContext::tr("Green");
green.canBeActive = true; green.canBeActive = true;
green.active = true; green.active = true;
green.isSpot = false; green.isSpot = false;
green.spotColorIndex = 1; green.spotColorIndex = 1;
green.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceRGB; green.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceRGB;
green.color = cms ? rgbColorSpace.getColor(PDFColor(0.0f, 1.0f, 0.0f), cms.get(), RenderingIntent::Perceptual, &renderErrorReporter, true) : QColor();
result.emplace_back(qMove(green)); result.emplace_back(qMove(green));
ColorInfo blue; ColorInfo blue;
blue.name = "Blue"; blue.name = "Blue";
blue.textName = PDFTranslationContext::tr("Process Blue"); blue.textName = PDFTranslationContext::tr("Blue");
blue.canBeActive = true; blue.canBeActive = true;
blue.active = true; blue.active = true;
blue.isSpot = false; blue.isSpot = false;
blue.spotColorIndex = 2; blue.spotColorIndex = 2;
blue.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceRGB; blue.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceRGB;
blue.color = cms ? rgbColorSpace.getColor(PDFColor(0.0f, 0.0f, 1.0f), cms.get(), RenderingIntent::Perceptual, &renderErrorReporter, true) : QColor();
result.emplace_back(qMove(blue)); result.emplace_back(qMove(blue));
break; break;
} }
case 4: case 4:
{ {
PDFDeviceCMYKColorSpace cmykColorSpace;
ColorInfo cyan; ColorInfo cyan;
cyan.name = "Cyan"; cyan.name = "Cyan";
cyan.textName = PDFTranslationContext::tr("Process Cyan"); cyan.textName = PDFTranslationContext::tr("Cyan");
cyan.canBeActive = true; cyan.canBeActive = true;
cyan.active = true; cyan.active = true;
cyan.isSpot = false; cyan.isSpot = false;
cyan.spotColorIndex = 0; cyan.spotColorIndex = 0;
cyan.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceCMYK; cyan.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceCMYK;
cyan.color = cms ? cmykColorSpace.getColor(PDFColor(1.0f, 0.0f, 0.0f, 0.0f), cms.get(), RenderingIntent::Perceptual, &renderErrorReporter, true) : QColor();
result.emplace_back(qMove(cyan)); result.emplace_back(qMove(cyan));
ColorInfo magenta; ColorInfo magenta;
magenta.name = "Magenta"; magenta.name = "Magenta";
magenta.textName = PDFTranslationContext::tr("Process Magenta"); magenta.textName = PDFTranslationContext::tr("Magenta");
magenta.canBeActive = true; magenta.canBeActive = true;
magenta.active = true; magenta.active = true;
magenta.isSpot = false; magenta.isSpot = false;
magenta.spotColorIndex = 1; magenta.spotColorIndex = 1;
magenta.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceCMYK; magenta.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceCMYK;
magenta.color = cms ? cmykColorSpace.getColor(PDFColor(0.0f, 1.0f, 0.0f, 0.0f), cms.get(), RenderingIntent::Perceptual, &renderErrorReporter, true) : QColor();
result.emplace_back(qMove(magenta)); result.emplace_back(qMove(magenta));
ColorInfo yellow; ColorInfo yellow;
yellow.name = "Yellow"; yellow.name = "Yellow";
yellow.textName = PDFTranslationContext::tr("Process Yellow"); yellow.textName = PDFTranslationContext::tr("Yellow");
yellow.canBeActive = true; yellow.canBeActive = true;
yellow.active = true; yellow.active = true;
yellow.isSpot = false; yellow.isSpot = false;
yellow.spotColorIndex = 2; yellow.spotColorIndex = 2;
yellow.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceCMYK; yellow.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceCMYK;
yellow.color = cms ? cmykColorSpace.getColor(PDFColor(0.0f, 0.0f, 1.0f, 0.0f), cms.get(), RenderingIntent::Perceptual, &renderErrorReporter, true) : QColor();
result.emplace_back(qMove(yellow)); result.emplace_back(qMove(yellow));
ColorInfo black; ColorInfo black;
black.name = "Black"; black.name = "Black";
black.textName = PDFTranslationContext::tr("Process Black"); black.textName = PDFTranslationContext::tr("Black");
black.canBeActive = true; black.canBeActive = true;
black.active = true; black.active = true;
black.isSpot = false; black.isSpot = false;
black.spotColorIndex = 3; black.spotColorIndex = 3;
black.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceCMYK; black.colorSpaceType = PDFAbstractColorSpace::ColorSpace::DeviceCMYK;
black.color = cms ? cmykColorSpace.getColor(PDFColor(0.0f, 0.0f, 0.0f, 1.0f), cms.get(), RenderingIntent::Perceptual, &renderErrorReporter, true) : QColor();
result.emplace_back(qMove(black)); result.emplace_back(qMove(black));
break; break;
} }
@ -3155,6 +3173,9 @@ void PDFInkMapper::createSpotColors(bool activate)
m_spotColors.clear(); m_spotColors.clear();
m_activeSpotColors = 0; m_activeSpotColors = 0;
PDFRenderErrorReporterDummy renderErrorReporter;
PDFCMSPointer cms = m_cmsManager ? m_cmsManager->getCurrentCMS() : nullptr;
const PDFCatalog* catalog = m_document->getCatalog(); const PDFCatalog* catalog = m_document->getCatalog();
const size_t pageCount = catalog->getPageCount(); const size_t pageCount = catalog->getPageCount();
for (size_t i = 0; i < pageCount; ++i) for (size_t i = 0; i < pageCount; ++i)
@ -3203,6 +3224,7 @@ void PDFInkMapper::createSpotColors(bool activate)
info.textName = PDFEncoding::convertTextString(info.name); info.textName = PDFEncoding::convertTextString(info.name);
info.colorSpace = colorSpacePointer; info.colorSpace = colorSpacePointer;
info.spotColorIndex = uint32_t(m_spotColors.size()); info.spotColorIndex = uint32_t(m_spotColors.size());
info.color = cms ? separationColorSpace->getColor(pdf::PDFColor(1.0f), cms.get(), pdf::RenderingIntent::Perceptual, &renderErrorReporter, true) : nullptr;
m_spotColors.emplace_back(qMove(info)); m_spotColors.emplace_back(qMove(info));
} }
} }
@ -3222,12 +3244,17 @@ void PDFInkMapper::createSpotColors(bool activate)
const PDFDeviceNColorSpace::ColorantInfo& colorantInfo = colorants[i]; const PDFDeviceNColorSpace::ColorantInfo& colorantInfo = colorants[i];
if (!containsSpotColor(colorantInfo.name) && !containsProcessColor(colorantInfo.name)) if (!containsSpotColor(colorantInfo.name) && !containsProcessColor(colorantInfo.name))
{ {
PDFColor color;
color.resize(deviceNColorSpace->getColorComponentCount());
color[i] = 1.0f;
ColorInfo info; ColorInfo info;
info.name = colorantInfo.name; info.name = colorantInfo.name;
info.textName = PDFEncoding::convertTextString(info.name); info.textName = PDFEncoding::convertTextString(info.name);
info.colorSpaceIndex = uint32_t(i); info.colorSpaceIndex = uint32_t(i);
info.colorSpace = colorSpacePointer; info.colorSpace = colorSpacePointer;
info.spotColorIndex = uint32_t(m_spotColors.size()); info.spotColorIndex = uint32_t(m_spotColors.size());
info.color = cms ? deviceNColorSpace->getColor(color, cms.get(), pdf::RenderingIntent::Perceptual, &renderErrorReporter, true) : nullptr;
m_spotColors.emplace_back(qMove(info)); m_spotColors.emplace_back(qMove(info));
} }
} }

View File

@ -360,7 +360,7 @@ struct PDFInkMapping
class Pdf4QtLIBSHARED_EXPORT PDFInkMapper class Pdf4QtLIBSHARED_EXPORT PDFInkMapper
{ {
public: public:
explicit PDFInkMapper(const PDFDocument* document); explicit PDFInkMapper(const PDFCMSManager* manager, const PDFDocument* document);
struct ColorInfo struct ColorInfo
{ {
@ -372,6 +372,7 @@ public:
bool canBeActive = false; ///< Can spot color be activated? bool canBeActive = false; ///< Can spot color be activated?
bool active = false; ///< Is spot color active? bool active = false; ///< Is spot color active?
bool isSpot = true; bool isSpot = true;
QColor color; ///< Spot/process color transformed to RGB color space
PDFAbstractColorSpace::ColorSpace colorSpaceType = PDFAbstractColorSpace::ColorSpace::Invalid; PDFAbstractColorSpace::ColorSpace colorSpaceType = PDFAbstractColorSpace::ColorSpace::Invalid;
}; };
@ -436,6 +437,7 @@ public:
PDFPixelFormat targetPixelFormat) const; PDFPixelFormat targetPixelFormat) const;
private: private:
const PDFCMSManager* m_cmsManager;
const PDFDocument* m_document; const PDFDocument* m_document;
std::vector<ColorInfo> m_spotColors; std::vector<ColorInfo> m_spotColors;
std::vector<ColorInfo> m_deviceColors; ///< Device color space separations std::vector<ColorInfo> m_deviceColors; ///< Device color space separations

View File

@ -20,6 +20,7 @@
#include "pdfcms.h" #include "pdfcms.h"
#include "pdfrenderer.h" #include "pdfrenderer.h"
#include "pdfwidgetutils.h"
#include "pdfdrawspacecontroller.h" #include "pdfdrawspacecontroller.h"
#include <QCloseEvent> #include <QCloseEvent>
@ -31,8 +32,8 @@ namespace pdfplugin
OutputPreviewDialog::OutputPreviewDialog(const pdf::PDFDocument* document, pdf::PDFWidget* widget, QWidget* parent) : OutputPreviewDialog::OutputPreviewDialog(const pdf::PDFDocument* document, pdf::PDFWidget* widget, QWidget* parent) :
QDialog(parent, Qt::Dialog | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint), QDialog(parent, Qt::Dialog | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint),
ui(new Ui::OutputPreviewDialog), ui(new Ui::OutputPreviewDialog),
m_inkMapper(document), m_inkMapper(widget->getCMSManager(), document),
m_inkMapperForRendering(document), m_inkMapperForRendering(widget->getCMSManager(), document),
m_document(document), m_document(document),
m_widget(widget), m_widget(widget),
m_needUpdateImage(false), m_needUpdateImage(false),
@ -51,6 +52,7 @@ OutputPreviewDialog::OutputPreviewDialog(const pdf::PDFDocument* document, pdf::
ui->displayModeComboBox->setCurrentIndex(0); ui->displayModeComboBox->setCurrentIndex(0);
ui->imageWidget->setInkMapper(&m_inkMapper); ui->imageWidget->setInkMapper(&m_inkMapper);
ui->inksTreeWidget->setMinimumHeight(pdf::PDFWidgetUtils::scaleDPI_y(ui->inksTreeWidget, 150));
m_inkMapper.createSpotColors(ui->simulateSeparationsCheckBox->isChecked()); m_inkMapper.createSpotColors(ui->simulateSeparationsCheckBox->isChecked());
connect(ui->simulateSeparationsCheckBox, &QCheckBox::clicked, this, &OutputPreviewDialog::onSimulateSeparationsChecked); connect(ui->simulateSeparationsCheckBox, &QCheckBox::clicked, this, &OutputPreviewDialog::onSimulateSeparationsChecked);
@ -111,6 +113,10 @@ void OutputPreviewDialog::updateInks()
spotColorsRoot->setFlags(spotColorsRoot->flags() | Qt::ItemIsUserCheckable); spotColorsRoot->setFlags(spotColorsRoot->flags() | Qt::ItemIsUserCheckable);
spotColorsRoot->setCheckState(0, Qt::Checked); spotColorsRoot->setCheckState(0, Qt::Checked);
QSize iconSize = pdf::PDFWidgetUtils::scaleDPI(ui->inksTreeWidget, QSize(16, 16));
ui->inksTreeWidget->setIconSize(iconSize);
ui->inksTreeWidget->setRootIsDecorated(true);
int colorIndex = 0; int colorIndex = 0;
std::vector<pdf::PDFInkMapper::ColorInfo> separations = m_inkMapper.getSeparations(4); std::vector<pdf::PDFInkMapper::ColorInfo> separations = m_inkMapper.getSeparations(4);
for (const auto& colorInfo : separations) for (const auto& colorInfo : separations)
@ -127,6 +133,13 @@ void OutputPreviewDialog::updateInks()
item = new QTreeWidgetItem(spotColorsRoot, QStringList(colorInfo.textName)); item = new QTreeWidgetItem(spotColorsRoot, QStringList(colorInfo.textName));
} }
if (colorInfo.color.isValid())
{
QPixmap icon(iconSize);
icon.fill(colorInfo.color);
item->setIcon(0, QIcon(icon));
}
item->setFlags(item->flags() | Qt::ItemIsUserCheckable); item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
item->setCheckState(0, Qt::Checked); item->setCheckState(0, Qt::Checked);
item->setData(0, Qt::UserRole, colorIndex++); item->setData(0, Qt::UserRole, colorIndex++);

View File

@ -35,12 +35,12 @@ OutputPreviewWidget::OutputPreviewWidget(QWidget* parent) :
QSize OutputPreviewWidget::sizeHint() const QSize OutputPreviewWidget::sizeHint() const
{ {
return pdf::PDFWidgetUtils::scaleDPI(this, QSize(400, 300)); return pdf::PDFWidgetUtils::scaleDPI(this, QSize(500, 300));
} }
QSize OutputPreviewWidget::minimumSizeHint() const QSize OutputPreviewWidget::minimumSizeHint() const
{ {
return pdf::PDFWidgetUtils::scaleDPI(this, QSize(200, 200)); return pdf::PDFWidgetUtils::scaleDPI(this, QSize(400, 300));
} }
void OutputPreviewWidget::clear() void OutputPreviewWidget::clear()
@ -244,7 +244,7 @@ void OutputPreviewWidget::buildInfoBoxItems()
continue; continue;
} }
addInfoBoxColoredItem(Qt::green, colorInfo.textName, QString("100 %")); addInfoBoxColoredItem(colorInfo.color, colorInfo.textName, QString("100 %"));
} }
} }
@ -260,7 +260,7 @@ void OutputPreviewWidget::buildInfoBoxItems()
continue; continue;
} }
addInfoBoxColoredItem(Qt::blue, colorInfo.textName, QString("100 %")); addInfoBoxColoredItem(colorInfo.color, colorInfo.textName, QString("100 %"));
} }
} }
} }