Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle colormaps correctly #4369

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions src/ccmain/thresholder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,30 +283,24 @@ bool ImageThresholder::ThresholdToPix(Image *pix) {
tprintf("Image too large: (%d, %d)\n", image_width_, image_height_);
return false;
}
Image original = GetPixRect();
// Handle binary image
if (pix_channels_ == 0) {
// We have a binary image, but it still has to be copied, as this API
// allows the caller to modify the output.
Image original = GetPixRect();
*pix = original.copy();
} else {
if (pixGetColormap(original)) {
Image tmp;
Image without_cmap =
pixRemoveColormap(original, REMOVE_CMAP_BASED_ON_SRC);
int depth = pixGetDepth(without_cmap);
if (depth > 1 && depth < 8) {
tmp = pixConvertTo8(without_cmap, false);
} else {
tmp = without_cmap.copy();
}
without_cmap.destroy();
OtsuThresholdRectToPix(tmp, pix);
tmp.destroy();
} else {
OtsuThresholdRectToPix(pix_, pix);
}
original.destroy();
return true;
}
// Handle colormaps
Image src = pix_;
if (pixGetColormap(src)) {
src = pixRemoveColormap(src, REMOVE_CMAP_BASED_ON_SRC);
}
OtsuThresholdRectToPix(src, pix);
if (src != pix_) {
src.destroy();
}
original.destroy();
return true;
}

Expand Down
Loading