From 5fe1390748a15c0e445a5c57c834edff27ff2f4d Mon Sep 17 00:00:00 2001 From: zdenop Date: Thu, 27 Sep 2018 19:40:15 +0200 Subject: [PATCH] remove alpha channel from png: issue #1914 --- src/api/baseapi.cpp | 7 +++++++ src/api/pdfrenderer.cpp | 9 +-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/api/baseapi.cpp b/src/api/baseapi.cpp index b13488974c..6756b52310 100644 --- a/src/api/baseapi.cpp +++ b/src/api/baseapi.cpp @@ -611,6 +611,13 @@ void TessBaseAPI::SetSourceResolution(int ppi) { */ void TessBaseAPI::SetImage(Pix* pix) { if (InternalSetImage()) { + if (pixGetSpp(pix) == 4 && pixGetInputFormat(pix) == IFF_PNG) { + // remove alpha channel from png + PIX* p1 = pixRemoveAlpha(pix); + pixSetSpp(p1, 3); + pix = pixCopy(nullptr, p1); + pixDestroy(&p1); + } thresholder_->SetImage(pix); SetInputImage(thresholder_->GetPixRect()); } diff --git a/src/api/pdfrenderer.cpp b/src/api/pdfrenderer.cpp index 8f9973e252..43d96f8898 100644 --- a/src/api/pdfrenderer.cpp +++ b/src/api/pdfrenderer.cpp @@ -716,14 +716,7 @@ bool TessPDFRenderer::imageToPDFObj(Pix *pix, const int kJpegQuality = jpg_quality; int format, sad; - if (filename) { - findFileFormat(filename, &format); - if (pixGetSpp(pix) == 4 && format == IFF_PNG) { - Pix *p1 = pixAlphaBlendUniform(pix, 0xffffff00); - sad = pixGenerateCIData(p1, L_FLATE_ENCODE, 0, 0, &cid); - pixDestroy(&p1); - } - } + sad = pixGenerateCIData(pix, L_FLATE_ENCODE, 0, 0, &cid); if (!cid) { sad = l_generateCIDataForPdf(filename, pix, kJpegQuality, &cid); }