Skip to content

Commit

Permalink
Issue #165: Insert > Inline Text latency issues on Flatpak and Appima…
Browse files Browse the repository at this point in the history
…ge packages
  • Loading branch information
JakubMelka committed Sep 1, 2024
1 parent 30d2d80 commit 4359109
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
26 changes: 26 additions & 0 deletions Pdf4QtLibCore/sources/pdfimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PDFJPEG2000ImageData*>(p_user_data);
Expand Down
2 changes: 2 additions & 0 deletions Pdf4QtLibCore/sources/pdfimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class PDF4QTLIBCORESHARED_EXPORT PDFImage
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;
Expand Down
5 changes: 5 additions & 0 deletions Pdf4QtLibCore/sources/pdfpagecontentprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions Pdf4QtLibCore/sources/pdfpainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
1 change: 1 addition & 0 deletions RELEASES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4359109

Please sign in to comment.