Warning coverage area

This commit is contained in:
Jakub Melka
2021-04-02 18:51:38 +02:00
parent 7ca5942fb6
commit 63376400da
2 changed files with 98 additions and 41 deletions

View File

@ -114,22 +114,22 @@ void OutputPreviewWidget::paintEvent(QPaintEvent* event)
case ColorWarningInkCoverage: case ColorWarningInkCoverage:
{ {
const QImage& image = getAlarmCoverageImage(); const AlarmImageInfo& alarmImage = getAlarmCoverageImage();
if (!image.isNull()) if (!alarmImage.image.isNull())
{ {
painter.translate(0, (pageImageRect.height() - image.height()) / 2); painter.translate(0, (pageImageRect.height() - alarmImage.image.height()) / 2);
painter.drawImage(pageImageRect.topLeft(), image); painter.drawImage(pageImageRect.topLeft(), alarmImage.image);
} }
break; break;
} }
case ColorWarningRichBlack: case ColorWarningRichBlack:
{ {
const QImage& image = getAlarmRichBlackImage(); const AlarmImageInfo& image = getAlarmRichBlackImage();
if (!image.isNull()) if (!image.image.isNull())
{ {
painter.translate(0, (pageImageRect.height() - image.height()) / 2); painter.translate(0, (pageImageRect.height() - image.image.height()) / 2);
painter.drawImage(pageImageRect.topLeft(), image); painter.drawImage(pageImageRect.topLeft(), image.image);
} }
break; break;
} }
@ -276,6 +276,8 @@ void OutputPreviewWidget::buildInfoBoxItems()
{ {
m_infoBoxItems.clear(); m_infoBoxItems.clear();
QColor sampleColor;
switch (m_displayMode) switch (m_displayMode)
{ {
case Separations: case Separations:
@ -291,7 +293,6 @@ void OutputPreviewWidget::buildInfoBoxItems()
colorValues.reserve(pixelFormat.getColorChannelCount()); colorValues.reserve(pixelFormat.getColorChannelCount());
Q_ASSERT(pixelFormat.getColorChannelCount() == separations.size()); Q_ASSERT(pixelFormat.getColorChannelCount() == separations.size());
QColor sampleColor;
std::vector<QColor> inkColors; std::vector<QColor> inkColors;
if (m_imagePointUnderCursor.has_value()) if (m_imagePointUnderCursor.has_value())
@ -382,13 +383,6 @@ void OutputPreviewWidget::buildInfoBoxItems()
addInfoBoxColoredItem(colorInfo.color, colorInfo.textName, colorValues[colorValueIndex++]); addInfoBoxColoredItem(colorInfo.color, colorInfo.textName, colorValues[colorValueIndex++]);
} }
} }
if (sampleColor.isValid())
{
addInfoBoxSeparator();
addInfoBoxHeader(tr("Sample Color"));
addInfoBoxColoredRect(sampleColor);
}
} }
break; break;
} }
@ -401,6 +395,28 @@ void OutputPreviewWidget::buildInfoBoxItems()
break; break;
} }
if (m_displayMode == ColorWarningInkCoverage)
{
addInfoBoxSeparator();
addInfoBoxHeader(tr("Warning | Ink Coverage"));
QLocale locale;
const auto& alarmImage = getAlarmCoverageImage();
addInfoBoxColoredItem(Qt::green, tr("OK"), QString("%1 mm²").arg(locale.toString(alarmImage.areaValid, 'f', 2)));
addInfoBoxColoredItem(Qt::red, tr("Failure"), QString("%1 mm²").arg(locale.toString(alarmImage.areaInvalid, 'f', 2)));
}
if (m_displayMode == ColorWarningRichBlack)
{
addInfoBoxSeparator();
addInfoBoxHeader(tr("Warning | Rich Black"));
QLocale locale;
const auto& alarmImage = getAlarmRichBlackImage();
addInfoBoxColoredItem(Qt::green, tr("OK"), QString("%1 mm²").arg(locale.toString(alarmImage.areaValid, 'f', 2)));
addInfoBoxColoredItem(Qt::red, tr("Failure"), QString("%1 mm²").arg(locale.toString(alarmImage.areaInvalid, 'f', 2)));
}
if (m_displayMode == Separations || m_displayMode == InkCoverage) if (m_displayMode == Separations || m_displayMode == InkCoverage)
{ {
if (m_originalProcessBitmap.getWidth() > 0 && m_originalProcessBitmap.getHeight() > 0) if (m_originalProcessBitmap.getWidth() > 0 && m_originalProcessBitmap.getHeight() > 0)
@ -427,6 +443,13 @@ void OutputPreviewWidget::buildInfoBoxItems()
} }
} }
} }
if (sampleColor.isValid())
{
addInfoBoxSeparator();
addInfoBoxHeader(tr("Sample Color"));
addInfoBoxColoredRect(sampleColor);
}
} }
void OutputPreviewWidget::addInfoBoxHeader(QString caption) void OutputPreviewWidget::addInfoBoxHeader(QString caption)
@ -457,12 +480,12 @@ const std::vector<pdf::PDFColorComponent>& OutputPreviewWidget::getInkCoverage()
return m_inkCoverageMM.get(this, &OutputPreviewWidget::getInkCoverageImpl); return m_inkCoverageMM.get(this, &OutputPreviewWidget::getInkCoverageImpl);
} }
const QImage& OutputPreviewWidget::getAlarmCoverageImage() const const OutputPreviewWidget::AlarmImageInfo& OutputPreviewWidget::getAlarmCoverageImage() const
{ {
return m_alarmCoverageImage.get(this, &OutputPreviewWidget::getAlarmCoverageImageImpl); return m_alarmCoverageImage.get(this, &OutputPreviewWidget::getAlarmCoverageImageImpl);
} }
const QImage& OutputPreviewWidget::getAlarmRichBlackImage() const const OutputPreviewWidget::AlarmImageInfo& OutputPreviewWidget::getAlarmRichBlackImage() const
{ {
return m_alarmRichBlackImage.get(this, &OutputPreviewWidget::getAlarmRichBlackImageImpl); return m_alarmRichBlackImage.get(this, &OutputPreviewWidget::getAlarmRichBlackImageImpl);
} }
@ -503,37 +526,56 @@ std::vector<pdf::PDFColorComponent> OutputPreviewWidget::getInkCoverageImpl() co
return result; return result;
} }
QImage OutputPreviewWidget::getAlarmCoverageImageImpl() const OutputPreviewWidget::AlarmImageInfo OutputPreviewWidget::getAlarmCoverageImageImpl() const
{ {
QImage alarmImage = m_pageImage; AlarmImageInfo alarmImage;
alarmImage.image = m_pageImage;
alarmImage.areaValid = 0.0f;
alarmImage.areaInvalid = 0.0f;
const int width = alarmImage.width(); const int width = alarmImage.image.width();
const int height = alarmImage.height(); const int height = alarmImage.image.height();
for (int y = 0; y < height; ++y) for (int y = 0; y < height; ++y)
{ {
for (int x = 0; x < width; ++x) for (int x = 0; x < width; ++x)
{ {
pdf::PDFColorComponent inkCoverage = m_originalProcessBitmap.getPixelInkCoverage(x, y); pdf::PDFColorComponent inkCoverage = m_originalProcessBitmap.getPixelInkCoverage(x, y);
if (inkCoverage > m_inkCoverageLimit) if (inkCoverage > m_inkCoverageLimit)
{ {
alarmImage.setPixelColor(x, y, m_alarmColor); alarmImage.areaInvalid += 1.0f;
alarmImage.image.setPixelColor(x, y, m_alarmColor);
}
else if (!qFuzzyIsNull(inkCoverage))
{
alarmImage.areaValid += 1.0f;
} }
} }
} }
if (width > 0 && height > 0)
{
const pdf::PDFColorComponent factor = m_pageSizeMM.width() * m_pageSizeMM.height() / (pdf::PDFColorComponent(width) * pdf::PDFColorComponent(height));
alarmImage.areaValid *= factor;
alarmImage.areaInvalid *= factor;
}
return alarmImage; return alarmImage;
} }
QImage OutputPreviewWidget::getAlarmRichBlackImageImpl() const OutputPreviewWidget::AlarmImageInfo OutputPreviewWidget::getAlarmRichBlackImageImpl() const
{ {
QImage alarmImage = m_pageImage; AlarmImageInfo alarmImage;
alarmImage.image = m_pageImage;
alarmImage.areaValid = 0.0f;
alarmImage.areaInvalid = 0.0f;
const pdf::PDFPixelFormat pixelFormat = m_originalProcessBitmap.getPixelFormat(); const pdf::PDFPixelFormat pixelFormat = m_originalProcessBitmap.getPixelFormat();
if (pixelFormat.getProcessColorChannelCount() == 4) if (pixelFormat.getProcessColorChannelCount() == 4)
{ {
const int width = alarmImage.width(); const int width = alarmImage.image.width();
const int height = alarmImage.height(); const int height = alarmImage.image.height();
const uint8_t blackChannelIndex = pixelFormat.getProcessColorChannelIndexStart() + 3; const uint8_t blackChannelIndex = pixelFormat.getProcessColorChannelIndexStart() + 3;
@ -543,18 +585,26 @@ QImage OutputPreviewWidget::getAlarmRichBlackImageImpl() const
{ {
pdf::PDFConstColorBuffer buffer = m_originalProcessBitmap.getPixel(x, y); pdf::PDFConstColorBuffer buffer = m_originalProcessBitmap.getPixel(x, y);
pdf::PDFColorComponent blackInk = buffer[blackChannelIndex]; pdf::PDFColorComponent blackInk = buffer[blackChannelIndex];
if (blackInk > m_richBlackLimit)
{
pdf::PDFColorComponent inkCoverage = m_originalProcessBitmap.getPixelInkCoverage(x, y); pdf::PDFColorComponent inkCoverage = m_originalProcessBitmap.getPixelInkCoverage(x, y);
pdf::PDFColorComponent inkCoverageWithoutBlack = inkCoverage - blackInk; pdf::PDFColorComponent inkCoverageWithoutBlack = inkCoverage - blackInk;
if (!qFuzzyIsNull(inkCoverageWithoutBlack)) if (blackInk > m_richBlackLimit && !qFuzzyIsNull(inkCoverageWithoutBlack))
{ {
alarmImage.setPixelColor(x, y, m_alarmColor); alarmImage.areaInvalid += 1.0f;
alarmImage.image.setPixelColor(x, y, m_alarmColor);
}
else if (!qFuzzyIsNull(inkCoverage))
{
alarmImage.areaValid += 1.0f;
} }
} }
} }
if (width > 0 && height > 0)
{
const pdf::PDFColorComponent factor = m_pageSizeMM.width() * m_pageSizeMM.height() / (pdf::PDFColorComponent(width) * pdf::PDFColorComponent(height));
alarmImage.areaValid *= factor;
alarmImage.areaInvalid *= factor;
} }
} }

View File

@ -88,13 +88,20 @@ private:
void addInfoBoxColoredItem(QColor color, QString caption, QString value); void addInfoBoxColoredItem(QColor color, QString caption, QString value);
void addInfoBoxColoredRect(QColor color); void addInfoBoxColoredRect(QColor color);
struct AlarmImageInfo
{
QImage image;
pdf::PDFColorComponent areaValid = 0.0f;
pdf::PDFColorComponent areaInvalid = 0.0f;
};
const std::vector<pdf::PDFColorComponent>& getInkCoverage() const; const std::vector<pdf::PDFColorComponent>& getInkCoverage() const;
const QImage& getAlarmCoverageImage() const; const AlarmImageInfo& getAlarmCoverageImage() const;
const QImage& getAlarmRichBlackImage() const; const AlarmImageInfo& getAlarmRichBlackImage() const;
std::vector<pdf::PDFColorComponent> getInkCoverageImpl() const; std::vector<pdf::PDFColorComponent> getInkCoverageImpl() const;
QImage getAlarmCoverageImageImpl() const; AlarmImageInfo getAlarmCoverageImageImpl() const;
QImage getAlarmRichBlackImageImpl() const; AlarmImageInfo getAlarmRichBlackImageImpl() const;
enum InfoBoxStyle enum InfoBoxStyle
{ {
@ -130,8 +137,8 @@ private:
pdf::PDFColorComponent m_richBlackLimit; pdf::PDFColorComponent m_richBlackLimit;
mutable pdf::PDFCachedItem<std::vector<pdf::PDFColorComponent>> m_inkCoverageMM; mutable pdf::PDFCachedItem<std::vector<pdf::PDFColorComponent>> m_inkCoverageMM;
mutable pdf::PDFCachedItem<QImage> m_alarmCoverageImage; mutable pdf::PDFCachedItem<AlarmImageInfo> m_alarmCoverageImage;
mutable pdf::PDFCachedItem<QImage> m_alarmRichBlackImage; mutable pdf::PDFCachedItem<AlarmImageInfo> m_alarmRichBlackImage;
QImage m_pageImage; QImage m_pageImage;
pdf::PDFFloatBitmapWithColorSpace m_originalProcessBitmap; pdf::PDFFloatBitmapWithColorSpace m_originalProcessBitmap;