diff --git a/Pdf4QtLibCore/sources/pdfcolorspaces.cpp b/Pdf4QtLibCore/sources/pdfcolorspaces.cpp index 50897b0..c441871 100644 --- a/Pdf4QtLibCore/sources/pdfcolorspaces.cpp +++ b/Pdf4QtLibCore/sources/pdfcolorspaces.cpp @@ -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 exception; @@ -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 inputColors(imageWidth * componentCount, 0.0f); std::vector outputColors(imageWidth * 3, 0); @@ -379,7 +374,7 @@ QImage PDFAbstractColorSpace::getImage(const PDFImageData& imageData, *outputLine++ = *transformedLine++; *outputLine++ = *transformedLine++; *outputLine++ = *transformedLine++; - *outputLine++ = *alphaLine++; + *outputLine++ = 255; } } catch (const PDFException &lineException) @@ -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; } @@ -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, @@ -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) { @@ -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) { @@ -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; } diff --git a/Pdf4QtLibCore/sources/pdfcolorspaces.h b/Pdf4QtLibCore/sources/pdfcolorspaces.h index 46695f8..a6cf56c 100644 --- a/Pdf4QtLibCore/sources/pdfcolorspaces.h +++ b/Pdf4QtLibCore/sources/pdfcolorspaces.h @@ -456,6 +456,8 @@ public: 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(0.0), component, PDFColorComponent(1.0)); } diff --git a/RELEASES.txt b/RELEASES.txt index 2e13714..94c9011 100644 --- a/RELEASES.txt +++ b/RELEASES.txt @@ -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