remove alpha channel from png: issue #1914

This commit is contained in:
zdenop 2018-09-27 19:40:15 +02:00
parent 971fe50031
commit 5fe1390748
2 changed files with 8 additions and 8 deletions

View File

@ -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());
}

View File

@ -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);
}