From 4a10bb68c76ccc83334d7dd62fd0a53286474892 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sat, 20 Jun 2020 21:41:01 +0200 Subject: [PATCH] Fix conversion of images with 16 bpp or 24 bpp to grey The old code used pixConvertRGBToLuminance which only converts 32 bpp images. Signed-off-by: Stefan Weil --- src/ccmain/thresholder.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ccmain/thresholder.cpp b/src/ccmain/thresholder.cpp index 38a737ac5..e3934ea65 100644 --- a/src/ccmain/thresholder.cpp +++ b/src/ccmain/thresholder.cpp @@ -251,11 +251,15 @@ Pix* ImageThresholder::GetPixRect() { // The returned Pix must be pixDestroyed. // Provided to the classifier to extract features from the greyscale image. Pix* ImageThresholder::GetPixRectGrey() { - Pix* pix = GetPixRect(); // May have to be reduced to grey. + auto pix = GetPixRect(); // May have to be reduced to grey. int depth = pixGetDepth(pix); if (depth != 8) { - Pix* result = depth < 8 ? pixConvertTo8(pix, false) - : pixConvertRGBToLuminance(pix); + if (depth == 24) { + auto tmp = pixConvert24To32(pix); + pixDestroy(&pix); + pix = tmp; + } + auto result = pixConvertTo8(pix, false); pixDestroy(&pix); return result; }