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 <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2020-06-20 21:41:01 +02:00
parent 6f6100ff9f
commit 4a10bb68c7

View File

@ -251,11 +251,15 @@ Pix* ImageThresholder::GetPixRect() {
// The returned Pix must be pixDestroyed. // The returned Pix must be pixDestroyed.
// Provided to the classifier to extract features from the greyscale image. // Provided to the classifier to extract features from the greyscale image.
Pix* ImageThresholder::GetPixRectGrey() { 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); int depth = pixGetDepth(pix);
if (depth != 8) { if (depth != 8) {
Pix* result = depth < 8 ? pixConvertTo8(pix, false) if (depth == 24) {
: pixConvertRGBToLuminance(pix); auto tmp = pixConvert24To32(pix);
pixDestroy(&pix);
pix = tmp;
}
auto result = pixConvertTo8(pix, false);
pixDestroy(&pix); pixDestroy(&pix);
return result; return result;
} }