Commit b10c0aa3 authored by Volker Krause's avatar Volker Krause
Browse files

Create image nodes for PDF raster image masks as well

There are indeed PDFs out there where the actual barcode is not in the
image (that is largely monochrome), but in its mask. With this we also
run the barcode decoder on masks to handle those cases as well.
parent d5c48f37
Pipeline #267634 passed with stage
in 11 minutes and 14 seconds
......@@ -23,19 +23,16 @@ PdfExtractorOutputDevice::PdfExtractorOutputDevice()
{
}
void PdfExtractorOutputDevice::drawImage(GfxState* state, Object* ref, Stream* str, int width, int height, GfxImageColorMap* colorMap, bool interpolate, PopplerMaskColors* maskColors, bool inlineImg)
void PdfExtractorOutputDevice::addRasterImage(GfxState *state, Object *ref, int width, int height, GfxImageColorMap *colorMap, PdfImageType type)
{
Q_UNUSED(str)
Q_UNUSED(interpolate)
Q_UNUSED(maskColors)
Q_UNUSED(inlineImg)
if (!colorMap || !colorMap->isOk() || !ref || !ref->isRef()) {
if ((!colorMap && type == PdfImageType::Image) || (colorMap && !colorMap->isOk()) || !ref || !ref->isRef()) {
return;
}
QImage::Format format;
if (colorMap->getColorSpace()->getMode() == csIndexed) {
if (!colorMap && type != PdfImageType::Image) {
format = QImage::Format_Mono;
} else if (colorMap->getColorSpace()->getMode() == csIndexed) {
format = QImage::Format_RGB888;
} else if (colorMap->getNumPixelComps() == 1 && (colorMap->getBits() >= 1 && colorMap->getBits() <= 8)) {
format = QImage::Format_Grayscale8;
......@@ -46,10 +43,12 @@ void PdfExtractorOutputDevice::drawImage(GfxState* state, Object* ref, Stream* s
}
PdfImage pdfImg;
pdfImg.d->m_ref = PdfImageRef(ref->getRef().num, ref->getRef().gen);
pdfImg.d->m_ref = PdfImageRef(ref->getRef().num, ref->getRef().gen, type);
#if KPOPPLER_VERSION >= QT_VERSION_CHECK(0, 69, 0)
pdfImg.d->m_colorMap.reset(colorMap->copy());
if (colorMap) {
pdfImg.d->m_colorMap.reset(colorMap->copy());
}
#endif
pdfImg.d->m_sourceHeight = height;
pdfImg.d->m_sourceWidth = width;
......@@ -70,6 +69,34 @@ void PdfExtractorOutputDevice::drawImage(GfxState* state, Object* ref, Stream* s
m_images.push_back(pdfImg);
}
void PdfExtractorOutputDevice::drawImage(GfxState* state, Object* ref, Stream* str, int width, int height, GfxImageColorMap* colorMap, bool interpolate, PopplerMaskColors* maskColors, bool inlineImg)
{
Q_UNUSED(str)
Q_UNUSED(interpolate)
Q_UNUSED(maskColors)
Q_UNUSED(inlineImg)
addRasterImage(state, ref, width, height, colorMap, PdfImageType::Image);
}
void PdfExtractorOutputDevice::drawMaskedImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, Stream *maskStr, int maskWidth, int maskHeight, bool maskInvert, bool maskInterpolate)
{
Q_UNUSED(interpolate)
Q_UNUSED(maskStr)
Q_UNUSED(maskInvert)
Q_UNUSED(maskInterpolate)
addRasterImage(state, ref, width, height, colorMap, PdfImageType::Image);
if (ref) {
const auto dict = str->getDict();
const auto maskObj = dict->lookup("Mask");
if (maskObj.isStream()) {
addRasterImage(state, ref, maskWidth, maskHeight, nullptr, PdfImageType::Mask);
}
}
}
void PdfExtractorOutputDevice::saveState(GfxState *state)
{
Q_UNUSED(state)
......
......@@ -6,6 +6,7 @@
#pragma once
#include "pdfimage.h"
#include "pdflink.h"
#include "pdfvectorpicture_p.h"
#include "popplertypes_p.h"
......@@ -27,8 +28,10 @@ public:
// call once displaying has been completed
void finalize();
// raster image operations
bool needNonText() override { return true; }
void drawImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, PopplerMaskColors *maskColors, bool inlineImg) override;
void drawMaskedImage(GfxState *state, Object *ref, Stream *str, int width, int height, GfxImageColorMap *colorMap, bool interpolate, Stream *maskStr, int maskWidth, int maskHeight, bool maskInvert, bool maskInterpolate) override;
// operations used to detect vector barcodes
void saveState(GfxState *state) override;
......@@ -36,8 +39,11 @@ public:
void stroke(GfxState *state) override;
void fill(GfxState *state) override;
void eoFill(GfxState *state) override;
// links
void processLink(AnnotLink *link) override;
void addRasterImage(GfxState *state, Object *ref, int width, int height, GfxImageColorMap *colorMap, PdfImageType type);
void addVectorImage(const PdfVectorPicture &pic);
// extracted images
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment