mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-06-07 18:02:40 +08:00
handle colormaps correctly - fixes #4127
This commit is contained in:
parent
d1fbbb88fc
commit
3299901b9c
@ -283,30 +283,24 @@ bool ImageThresholder::ThresholdToPix(Image *pix) {
|
|||||||
tprintf("Image too large: (%d, %d)\n", image_width_, image_height_);
|
tprintf("Image too large: (%d, %d)\n", image_width_, image_height_);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Image original = GetPixRect();
|
// Handle binary image
|
||||||
if (pix_channels_ == 0) {
|
if (pix_channels_ == 0) {
|
||||||
// We have a binary image, but it still has to be copied, as this API
|
// We have a binary image, but it still has to be copied, as this API
|
||||||
// allows the caller to modify the output.
|
// allows the caller to modify the output.
|
||||||
|
Image original = GetPixRect();
|
||||||
*pix = original.copy();
|
*pix = original.copy();
|
||||||
} else {
|
original.destroy();
|
||||||
if (pixGetColormap(original)) {
|
return true;
|
||||||
Image tmp;
|
}
|
||||||
Image without_cmap =
|
// Handle colormaps
|
||||||
pixRemoveColormap(original, REMOVE_CMAP_BASED_ON_SRC);
|
Image src = pix_;
|
||||||
int depth = pixGetDepth(without_cmap);
|
if (pixGetColormap(src)) {
|
||||||
if (depth > 1 && depth < 8) {
|
src = pixRemoveColormap(src, REMOVE_CMAP_BASED_ON_SRC);
|
||||||
tmp = pixConvertTo8(without_cmap, false);
|
}
|
||||||
} else {
|
OtsuThresholdRectToPix(src, pix);
|
||||||
tmp = without_cmap.copy();
|
if (src != pix_) {
|
||||||
}
|
src.destroy();
|
||||||
without_cmap.destroy();
|
|
||||||
OtsuThresholdRectToPix(tmp, pix);
|
|
||||||
tmp.destroy();
|
|
||||||
} else {
|
|
||||||
OtsuThresholdRectToPix(pix_, pix);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
original.destroy();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user