mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-04-02 20:51:01 +02:00
Blending output with paper
This commit is contained in:
parent
e743761ce4
commit
3da8cf2252
@ -650,15 +650,11 @@ const PDFFloatBitmap& PDFTransparencyRenderer::endPaint()
|
|||||||
return *getImmediateBackdrop();
|
return *getImmediateBackdrop();
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage PDFTransparencyRenderer::toImage(bool use16Bit) const
|
QImage PDFTransparencyRenderer::toImageImpl(const PDFFloatBitmapWithColorSpace& floatImage, bool use16Bit) const
|
||||||
{
|
{
|
||||||
QImage image;
|
QImage image;
|
||||||
|
|
||||||
if (m_transparencyGroupDataStack.size() == 1 && // We have finished the painting
|
Q_ASSERT(floatImage.getPixelFormat().getProcessColorChannelCount() == 3);
|
||||||
m_transparencyGroupDataStack.back().immediateBackdrop.getPixelFormat().getProcessColorChannelCount() == 3) // We have exactly three process colors (RGB)
|
|
||||||
{
|
|
||||||
const PDFFloatBitmapWithColorSpace& floatImage = m_transparencyGroupDataStack.back().immediateBackdrop;
|
|
||||||
Q_ASSERT(floatImage.getPixelFormat().hasOpacityChannel());
|
|
||||||
|
|
||||||
if (use16Bit)
|
if (use16Bit)
|
||||||
{
|
{
|
||||||
@ -718,6 +714,38 @@ QImage PDFTransparencyRenderer::toImage(bool use16Bit) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage PDFTransparencyRenderer::toImage(bool use16Bit, bool usePaper, PDFRGB paperColor) const
|
||||||
|
{
|
||||||
|
QImage image;
|
||||||
|
|
||||||
|
if (m_transparencyGroupDataStack.size() == 1 && // We have finished the painting
|
||||||
|
m_transparencyGroupDataStack.back().immediateBackdrop.getPixelFormat().getProcessColorChannelCount() == 3) // We have exactly three process colors (RGB)
|
||||||
|
{
|
||||||
|
const PDFFloatBitmapWithColorSpace& floatImage = m_transparencyGroupDataStack.back().immediateBackdrop;
|
||||||
|
Q_ASSERT(floatImage.getPixelFormat().hasOpacityChannel());
|
||||||
|
|
||||||
|
if (!usePaper)
|
||||||
|
{
|
||||||
|
return toImageImpl(floatImage, use16Bit);
|
||||||
|
}
|
||||||
|
|
||||||
|
PDFFloatBitmapWithColorSpace paperImage(floatImage.getWidth(), floatImage.getHeight(), floatImage.getPixelFormat(), floatImage.getColorSpace());
|
||||||
|
paperImage.makeOpaque();
|
||||||
|
paperImage.fillChannel(0, paperColor[0]);
|
||||||
|
paperImage.fillChannel(1, paperColor[1]);
|
||||||
|
paperImage.fillChannel(2, paperColor[2]);
|
||||||
|
|
||||||
|
PDFFloatBitmap softMask(paperImage.getWidth(), paperImage.getHeight(), PDFPixelFormat::createOpacityMask());
|
||||||
|
softMask.makeOpaque();
|
||||||
|
|
||||||
|
QRect blendRegion(0, 0, floatImage.getWidth(), floatImage.getHeight());
|
||||||
|
PDFFloatBitmapWithColorSpace::blend(floatImage, paperImage, paperImage, paperImage, softMask, false, 1.0f, BlendMode::Normal, false, 0xFFFF, PDFFloatBitmap::OverprintMode::NoOveprint, blendRegion);
|
||||||
|
|
||||||
|
return toImageImpl(paperImage, use16Bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
|
@ -214,10 +214,10 @@ public:
|
|||||||
OverprintMode overprintMode,
|
OverprintMode overprintMode,
|
||||||
QRect blendRegion);
|
QRect blendRegion);
|
||||||
|
|
||||||
private:
|
|
||||||
void fillProcessColorChannels(PDFColorComponent value);
|
void fillProcessColorChannels(PDFColorComponent value);
|
||||||
void fillChannel(size_t channel, PDFColorComponent value);
|
void fillChannel(size_t channel, PDFColorComponent value);
|
||||||
|
|
||||||
|
private:
|
||||||
PDFPixelFormat m_format;
|
PDFPixelFormat m_format;
|
||||||
std::size_t m_width;
|
std::size_t m_width;
|
||||||
std::size_t m_height;
|
std::size_t m_height;
|
||||||
@ -443,9 +443,11 @@ public:
|
|||||||
/// This function should be called only after call to \p endPaint. After painting,
|
/// This function should be called only after call to \p endPaint. After painting,
|
||||||
/// when it is finished, the result float image can be converted to QImage with
|
/// when it is finished, the result float image can be converted to QImage with
|
||||||
/// this function, but only, if the float image is RGB. If error occurs, empty
|
/// this function, but only, if the float image is RGB. If error occurs, empty
|
||||||
/// image is returned.
|
/// image is returned. Also, result image can be painted onto opaque paper
|
||||||
/// \param use16bit
|
/// with paper color \p paperColor.
|
||||||
QImage toImage(bool use16Bit) const;
|
/// \param use16bit Produce 16-bit image instead of standard 8-bit
|
||||||
|
/// \param usePaper Blend image with opaque paper, with color \p paperColor
|
||||||
|
QImage toImage(bool use16Bit, bool usePaper = false, PDFRGB paperColor = PDFRGB()) const;
|
||||||
|
|
||||||
virtual void performPathPainting(const QPainterPath& path, bool stroke, bool fill, bool text, Qt::FillRule fillRule) override;
|
virtual void performPathPainting(const QPainterPath& path, bool stroke, bool fill, bool text, Qt::FillRule fillRule) override;
|
||||||
virtual void performClipping(const QPainterPath& path, Qt::FillRule fillRule) override;
|
virtual void performClipping(const QPainterPath& path, Qt::FillRule fillRule) override;
|
||||||
@ -501,6 +503,9 @@ private:
|
|||||||
PDFMappedColor createMappedColor(const PDFColor& sourceColor,
|
PDFMappedColor createMappedColor(const PDFColor& sourceColor,
|
||||||
const PDFAbstractColorSpace* sourceColorSpace);
|
const PDFAbstractColorSpace* sourceColorSpace);
|
||||||
|
|
||||||
|
/// Converts RGB bitmap to the image.
|
||||||
|
QImage toImageImpl(const PDFFloatBitmapWithColorSpace& floatImage, bool use16Bit) const;
|
||||||
|
|
||||||
PDFFloatBitmapWithColorSpace* getInitialBackdrop();
|
PDFFloatBitmapWithColorSpace* getInitialBackdrop();
|
||||||
PDFFloatBitmapWithColorSpace* getImmediateBackdrop();
|
PDFFloatBitmapWithColorSpace* getImmediateBackdrop();
|
||||||
PDFFloatBitmapWithColorSpace* getBackdrop();
|
PDFFloatBitmapWithColorSpace* getBackdrop();
|
||||||
|
@ -26,7 +26,7 @@ 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),
|
QDialog(parent, Qt::Dialog | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint),
|
||||||
ui(new Ui::OutputPreviewDialog),
|
ui(new Ui::OutputPreviewDialog),
|
||||||
m_inkMapper(document),
|
m_inkMapper(document),
|
||||||
m_document(document),
|
m_document(document),
|
||||||
@ -80,7 +80,7 @@ void OutputPreviewDialog::updateImage()
|
|||||||
renderer.processContents();
|
renderer.processContents();
|
||||||
renderer.endPaint();
|
renderer.endPaint();
|
||||||
|
|
||||||
QImage image = renderer.toImage(false);
|
QImage image = renderer.toImage(false, true, pdf::PDFRGB{ 1.0f, 1.0f, 1.0f });
|
||||||
ui->imageLabel->setPixmap(QPixmap::fromImage(image));
|
ui->imageLabel->setPixmap(QPixmap::fromImage(image));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user