From 209cf5c476e393d9f7f0876e0376d11a03dc87ab Mon Sep 17 00:00:00 2001 From: "Sebastian J. Bronner" Date: Sun, 11 Feb 2024 00:08:48 +0100 Subject: [PATCH 1/2] Fix grey result of indexed PNG in pdfrenderer. --- src/api/pdfrenderer.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/api/pdfrenderer.cpp b/src/api/pdfrenderer.cpp index 81cf2e24..34e6b3fd 100644 --- a/src/api/pdfrenderer.cpp +++ b/src/api/pdfrenderer.cpp @@ -664,6 +664,8 @@ bool TessPDFRenderer::BeginDocumentHandler() { bool TessPDFRenderer::imageToPDFObj(Pix *pix, const char *filename, long int objnum, char **pdf_object, long int *pdf_object_size, const int jpg_quality) { + int sad; + if (!pdf_object_size || !pdf_object) { return false; } @@ -674,14 +676,7 @@ bool TessPDFRenderer::imageToPDFObj(Pix *pix, const char *filename, long int obj } L_Compressed_Data *cid = nullptr; - - int sad = 0; - if (pixGetInputFormat(pix) == IFF_PNG) { - sad = pixGenerateCIData(pix, L_FLATE_ENCODE, 0, 0, &cid); - } - if (!cid) { - sad = l_generateCIDataForPdf(filename, pix, jpg_quality, &cid); - } + sad = l_generateCIDataForPdf(filename, pix, jpg_quality, &cid); if (sad || !cid) { l_CIDataDestroy(&cid); From 304014f28a0ceed781addd89d14238741ae4e3f4 Mon Sep 17 00:00:00 2001 From: "Sebastian J. Bronner" Date: Mon, 12 Feb 2024 08:03:11 +0100 Subject: [PATCH 2/2] Simplify variable declaration. --- src/api/pdfrenderer.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/api/pdfrenderer.cpp b/src/api/pdfrenderer.cpp index 34e6b3fd..74404a72 100644 --- a/src/api/pdfrenderer.cpp +++ b/src/api/pdfrenderer.cpp @@ -664,8 +664,6 @@ bool TessPDFRenderer::BeginDocumentHandler() { bool TessPDFRenderer::imageToPDFObj(Pix *pix, const char *filename, long int objnum, char **pdf_object, long int *pdf_object_size, const int jpg_quality) { - int sad; - if (!pdf_object_size || !pdf_object) { return false; } @@ -676,7 +674,7 @@ bool TessPDFRenderer::imageToPDFObj(Pix *pix, const char *filename, long int obj } L_Compressed_Data *cid = nullptr; - sad = l_generateCIDataForPdf(filename, pix, jpg_quality, &cid); + auto sad = l_generateCIDataForPdf(filename, pix, jpg_quality, &cid); if (sad || !cid) { l_CIDataDestroy(&cid);