Skip to content

Commit

Permalink
Issue #202: Certain raster content not rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubMelka committed Sep 1, 2024
1 parent 8907183 commit 30d2d80
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
57 changes: 43 additions & 14 deletions Pdf4QtLibCore/sources/pdfcolorspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,7 @@ QImage PDFAbstractColorSpace::getImage(const PDFImageData& imageData,
const unsigned int imageHeight = imageData.getHeight();

QImage alphaMask = createAlphaMask(softMask);
if (alphaMask.size() != image.size())
{
// Scale the alpha mask, if it is masked
alphaMask = alphaMask.scaled(image.size());
}
QSize targetSize = getLargerSizeByArea(alphaMask.size(), image.size());

QMutex exceptionMutex;
std::optional<PDFException> exception;
Expand All @@ -347,7 +343,6 @@ QImage PDFAbstractColorSpace::getImage(const PDFImageData& imageData,
const double max = reader.max();
const double coefficient = 1.0 / max;
unsigned char* outputLine = image.scanLine(i);
unsigned char* alphaLine = alphaMask.scanLine(i);

std::vector<float> inputColors(imageWidth * componentCount, 0.0f);
std::vector<unsigned char> outputColors(imageWidth * 3, 0);
Expand Down Expand Up @@ -379,7 +374,7 @@ QImage PDFAbstractColorSpace::getImage(const PDFImageData& imageData,
*outputLine++ = *transformedLine++;
*outputLine++ = *transformedLine++;
*outputLine++ = *transformedLine++;
*outputLine++ = *alphaLine++;
*outputLine++ = 255;
}
}
catch (const PDFException &lineException)
Expand All @@ -400,6 +395,18 @@ QImage PDFAbstractColorSpace::getImage(const PDFImageData& imageData,
throw *exception;
}

if (image.size() != targetSize)
{
image = image.scaled(targetSize);
}

if (alphaMask.size() != targetSize)
{
alphaMask = alphaMask.scaled(targetSize);
}

image.setAlphaChannel(alphaMask);

return image;
}

Expand Down Expand Up @@ -1032,6 +1039,21 @@ bool PDFAbstractColorSpace::transform(const PDFAbstractColorSpace* source,
return true;
}

QSize PDFAbstractColorSpace::getLargerSizeByArea(QSize s1, QSize s2)
{
int area1 = s1.width() * s1.height();
int area2 = s2.width() * s2.height();

if (area1 > area2)
{
return s1;
}
else
{
return s2;
}
}

PDFColorSpacePointer PDFAbstractColorSpace::createColorSpaceImpl(const PDFDictionary* colorSpaceDictionary,
const PDFDocument* document,
const PDFObject& colorSpace,
Expand Down Expand Up @@ -1947,11 +1969,7 @@ QImage PDFIndexedColorSpace::getImage(const PDFImageData& imageData,
color.resize(1);

QImage alphaMask = createAlphaMask(softMask);
if (alphaMask.size() != image.size())
{
// Scale the alpha mask, if it is masked
alphaMask = alphaMask.scaled(image.size());
}
QSize targetSize = getLargerSizeByArea(alphaMask.size(), image.size());

for (unsigned int i = 0, rowCount = imageData.getHeight(); i < rowCount; ++i)
{
Expand All @@ -1963,7 +1981,6 @@ QImage PDFIndexedColorSpace::getImage(const PDFImageData& imageData,

reader.seek(i * imageData.getStride());
unsigned char* outputLine = image.scanLine(i);
unsigned char* alphaLine = alphaMask.scanLine(i);

for (unsigned int j = 0; j < imageData.getWidth(); ++j)
{
Expand All @@ -1976,10 +1993,22 @@ QImage PDFIndexedColorSpace::getImage(const PDFImageData& imageData,
*outputLine++ = qRed(rgb);
*outputLine++ = qGreen(rgb);
*outputLine++ = qBlue(rgb);
*outputLine++ = *alphaLine++;
*outputLine++ = 255;
}
}

if (image.size() != targetSize)
{
image = image.scaled(targetSize);
}

if (alphaMask.size() != targetSize)
{
alphaMask = alphaMask.scaled(targetSize);
}

image.setAlphaChannel(alphaMask);

return image;
}

Expand Down
2 changes: 2 additions & 0 deletions Pdf4QtLibCore/sources/pdfcolorspaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ class PDF4QTLIBCORESHARED_EXPORT PDFAbstractColorSpace
PDFRenderErrorReporter* reporter);

protected:
static QSize getLargerSizeByArea(QSize s1, QSize s2);

/// Clips the color component to range [0, 1]
static constexpr PDFColorComponent clip01(PDFColorComponent component) { return qBound<PDFColorComponent>(PDFColorComponent(0.0), component, PDFColorComponent(1.0)); }

Expand Down
1 change: 1 addition & 0 deletions RELEASES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CURRENT:
- Issue #207: Zoom to Cursor (Zoom Anchoring)
- Issue #206: Name of the executable / command
- Issue #205: Editor cannot create white, whitesmoke or transparent annotations
- Issue #202: Certain raster content not rendered
- Issue #185: Latest git fails to build in linux

V: 1.4.0.0 4.7.2024
Expand Down

0 comments on commit 30d2d80

Please sign in to comment.