From 4359109157ba600c2674eff582085a7fc185aefd Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Sun, 1 Sep 2024 13:39:49 +0200 Subject: [PATCH] Issue #165: Insert > Inline Text latency issues on Flatpak and Appimage packages --- Pdf4QtLibCore/sources/pdfimage.cpp | 26 +++++++++++++++++++ Pdf4QtLibCore/sources/pdfimage.h | 2 ++ .../sources/pdfpagecontentprocessor.cpp | 5 ++++ Pdf4QtLibCore/sources/pdfpainter.cpp | 7 ----- RELEASES.txt | 1 + 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Pdf4QtLibCore/sources/pdfimage.cpp b/Pdf4QtLibCore/sources/pdfimage.cpp index e716023..888f015 100644 --- a/Pdf4QtLibCore/sources/pdfimage.cpp +++ b/Pdf4QtLibCore/sources/pdfimage.cpp @@ -790,6 +790,32 @@ QImage PDFImage::getImage(const PDFCMS* cms, return QImage(); } +bool PDFImage::canBeConvertedToMonochromatic(const QImage& image) +{ + for (int y = 0; y < image.height(); ++y) + { + for (int x = 0; x < image.width(); ++x) + { + QRgb pixel = image.pixel(x, y); + int red = qRed(pixel); + int green = qGreen(pixel); + int blue = qBlue(pixel); + int alpha = qAlpha(pixel); + + if (alpha != 255) + { + return false; + } + + // Zkontrolujte, zda jsou kanály stejné (odstín šedi) a zda jsou pouze 0 (černá) nebo 255 (bílá) + if ((red != green || green != blue) || (red != 0 && red != 255)) { + return false; + } + } + } + return true; +} + OPJ_SIZE_T PDFJPEG2000ImageData::read(void* p_buffer, OPJ_SIZE_T p_nb_bytes, void* p_user_data) { PDFJPEG2000ImageData* data = reinterpret_cast(p_user_data); diff --git a/Pdf4QtLibCore/sources/pdfimage.h b/Pdf4QtLibCore/sources/pdfimage.h index 7ac06a7..aba9972 100644 --- a/Pdf4QtLibCore/sources/pdfimage.h +++ b/Pdf4QtLibCore/sources/pdfimage.h @@ -112,6 +112,8 @@ public: const PDFImageData& getImageData() const { return m_imageData; } const PDFImageData& getSoftMaskData() const { return m_softMask; } + static bool canBeConvertedToMonochromatic(const QImage& image); + private: PDFImageData m_imageData; PDFImageData m_softMask; diff --git a/Pdf4QtLibCore/sources/pdfpagecontentprocessor.cpp b/Pdf4QtLibCore/sources/pdfpagecontentprocessor.cpp index 7eb2029..d66f108 100644 --- a/Pdf4QtLibCore/sources/pdfpagecontentprocessor.cpp +++ b/Pdf4QtLibCore/sources/pdfpagecontentprocessor.cpp @@ -3021,6 +3021,11 @@ void PDFPageContentProcessor::paintXObjectImage(const PDFStream* stream) if (!image.isNull()) { + if (PDFImage::canBeConvertedToMonochromatic(image)) + { + image.convertTo(QImage::Format_Mono); + } + performImagePainting(image); } else diff --git a/Pdf4QtLibCore/sources/pdfpainter.cpp b/Pdf4QtLibCore/sources/pdfpainter.cpp index 02eecb7..a079d11 100644 --- a/Pdf4QtLibCore/sources/pdfpainter.cpp +++ b/Pdf4QtLibCore/sources/pdfpainter.cpp @@ -683,13 +683,6 @@ void PDFPrecompiledPage::addClip(QPainterPath path) void PDFPrecompiledPage::addImage(QImage image) { - // Convert the image into format Format_ARGB32_Premultiplied for fast drawing. - // If this format is used, then no image conversion is performed while drawing. - if (image.format() != QImage::Format_ARGB32_Premultiplied) - { - image.convertTo(QImage::Format_ARGB32_Premultiplied); - } - m_instructions.emplace_back(InstructionType::DrawImage, m_images.size()); m_images.emplace_back(qMove(image)); } diff --git a/RELEASES.txt b/RELEASES.txt index 94c9011..a354736 100644 --- a/RELEASES.txt +++ b/RELEASES.txt @@ -4,6 +4,7 @@ CURRENT: - 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 + - Issue #165: Insert > Inline Text latency issues on Flatpak and Appimage packages V: 1.4.0.0 4.7.2024 - Issue #190: PageMaster crash + black bubbles instead of bubbles with correct color