From 30fc6fd5c0601a6be94a1c0a74a2abac9b603b88 Mon Sep 17 00:00:00 2001 From: Ray Smith Date: Tue, 6 Dec 2016 13:40:57 -0800 Subject: [PATCH] Fixed damage to binary images when processing PDFs, issue #535 --- ccmain/thresholder.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ccmain/thresholder.cpp b/ccmain/thresholder.cpp index 545ad5854e..fc8111ef7b 100644 --- a/ccmain/thresholder.cpp +++ b/ccmain/thresholder.cpp @@ -181,8 +181,11 @@ void ImageThresholder::SetImage(const Pix* pix) { // Caller must use pixDestroy to free the created Pix. void ImageThresholder::ThresholdToPix(PageSegMode pageseg_mode, Pix** pix) { if (pix_channels_ == 0) { - // We have a binary image, so it just has to be cloned. - *pix = GetPixRect(); + // We have a binary image, but it still has to be copied, as this API + // allows the caller to modify the output. + Pix* original = GetPixRect(); + *pix = pixCopy(nullptr, original); + pixDestroy(&original); } else { OtsuThresholdRectToPix(pix_, pix); }