Skip to content

Commit

Permalink
backport from 4.00: issue tesseract-ocr#242 - different results when …
Browse files Browse the repository at this point in the history
…same image is lossless-encoded at different bpp
  • Loading branch information
zdenop committed Nov 25, 2016
1 parent 42b101a commit 61888e4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions ccmain/thresholder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,27 @@ void ImageThresholder::SetImage(const Pix* pix) {
int depth;
pixGetDimensions(src, &image_width_, &image_height_, &depth);
// Convert the image as necessary so it is one of binary, plain RGB, or
// 8 bit with no colormap.
if (depth > 1 && depth < 8) {
// 8 bit with no colormap. Guarantee that we always end up with our own copy,
// not just a clone of the input.
if (pixGetColormap(src)) {
Pix* tmp = pixRemoveColormap(src, REMOVE_CMAP_BASED_ON_SRC);
depth = pixGetDepth(tmp);
if (depth > 1 && depth < 8) {
pix_ = pixConvertTo8(tmp, false);
pixDestroy(&tmp);
} else {
pix_ = tmp;
}
} else if (depth > 1 && depth < 8) {
pix_ = pixConvertTo8(src, false);
} else if (pixGetColormap(src)) {
pix_ = pixRemoveColormap(src, REMOVE_CMAP_BASED_ON_SRC);
} else {
pix_ = pixClone(src);
pix_ = pixCopy(NULL, src);
}
depth = pixGetDepth(pix_);
pix_channels_ = depth / 8;
pix_wpl_ = pixGetWpl(pix_);
scale_ = 1;
estimated_res_ = yres_ = pixGetYRes(src);
estimated_res_ = yres_ = pixGetYRes(pix_);
Init();
}

Expand Down

0 comments on commit 61888e4

Please sign in to comment.