Skip to content

Commit 5fe1390

Browse files
committed
remove alpha channel from png: issue #1914
1 parent 971fe50 commit 5fe1390

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/api/baseapi.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,13 @@ void TessBaseAPI::SetSourceResolution(int ppi) {
611611
*/
612612
void TessBaseAPI::SetImage(Pix* pix) {
613613
if (InternalSetImage()) {
614+
if (pixGetSpp(pix) == 4 && pixGetInputFormat(pix) == IFF_PNG) {
615+
// remove alpha channel from png
616+
PIX* p1 = pixRemoveAlpha(pix);
617+
pixSetSpp(p1, 3);
618+
pix = pixCopy(nullptr, p1);
619+
pixDestroy(&p1);
620+
}
614621
thresholder_->SetImage(pix);
615622
SetInputImage(thresholder_->GetPixRect());
616623
}

src/api/pdfrenderer.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -716,14 +716,7 @@ bool TessPDFRenderer::imageToPDFObj(Pix *pix,
716716
const int kJpegQuality = jpg_quality;
717717

718718
int format, sad;
719-
if (filename) {
720-
findFileFormat(filename, &format);
721-
if (pixGetSpp(pix) == 4 && format == IFF_PNG) {
722-
Pix *p1 = pixAlphaBlendUniform(pix, 0xffffff00);
723-
sad = pixGenerateCIData(p1, L_FLATE_ENCODE, 0, 0, &cid);
724-
pixDestroy(&p1);
725-
}
726-
}
719+
sad = pixGenerateCIData(pix, L_FLATE_ENCODE, 0, 0, &cid);
727720
if (!cid) {
728721
sad = l_generateCIDataForPdf(filename, pix, kJpegQuality, &cid);
729722
}

0 commit comments

Comments
 (0)