Skip to content

Commit cec1037

Browse files
committed
Fixed BestPix to always return the highest resolution available, even if a lower bit depth than the original
1 parent 66e686a commit cec1037

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

ccmain/tesseractclass.h

+12-4
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,22 @@ class Tesseract : public Wordrec {
206206
sub_langs_[i]->set_pix_original(original_pix ? pixClone(original_pix)
207207
: nullptr);
208208
}
209-
// Returns a pointer to a Pix representing the best available (original) image
210-
// of the page. Can be of any bit depth, but never color-mapped, as that has
211-
// always been dealt with. Note that in grey and color, 0 is black and 255 is
209+
// Returns a pointer to a Pix representing the best available resolution image
210+
// of the page, with best available bit depth as second priority. Result can
211+
// be of any bit depth, but never color-mapped, as that has always been
212+
// removed. Note that in grey and color, 0 is black and 255 is
212213
// white. If the input was binary, then black is 1 and white is 0.
213214
// To tell the difference pixGetDepth() will return 32, 8 or 1.
214215
// In any case, the return value is a borrowed Pix, and should not be
215216
// deleted or pixDestroyed.
216-
Pix* BestPix() const { return pix_original_; }
217+
Pix* BestPix() const {
218+
if (pixGetWidth(pix_original_) == ImageWidth())
219+
return pix_original_;
220+
else if (pix_grey_ != NULL)
221+
return pix_grey_;
222+
else
223+
return pix_binary_;
224+
}
217225
void set_pix_thresholds(Pix* thresholds) {
218226
pixDestroy(&pix_thresholds_);
219227
pix_thresholds_ = thresholds;

0 commit comments

Comments
 (0)