File tree Expand file tree Collapse file tree 1 file changed +13
-19
lines changed
Expand file tree Collapse file tree 1 file changed +13
-19
lines changed Original file line number Diff line number Diff line change @@ -283,30 +283,24 @@ bool ImageThresholder::ThresholdToPix(Image *pix) {
283283 tprintf (" Image too large: (%d, %d)\n " , image_width_, image_height_);
284284 return false ;
285285 }
286- Image original = GetPixRect ();
286+ // Handle binary image
287287 if (pix_channels_ == 0 ) {
288288 // We have a binary image, but it still has to be copied, as this API
289289 // allows the caller to modify the output.
290+ Image original = GetPixRect ();
290291 *pix = original.copy ();
291- } else {
292- if (pixGetColormap (original)) {
293- Image tmp;
294- Image without_cmap =
295- pixRemoveColormap (original, REMOVE_CMAP_BASED_ON_SRC);
296- int depth = pixGetDepth (without_cmap);
297- if (depth > 1 && depth < 8 ) {
298- tmp = pixConvertTo8 (without_cmap, false );
299- } else {
300- tmp = without_cmap.copy ();
301- }
302- without_cmap.destroy ();
303- OtsuThresholdRectToPix (tmp, pix);
304- tmp.destroy ();
305- } else {
306- OtsuThresholdRectToPix (pix_, pix);
307- }
292+ original.destroy ();
293+ return true ;
294+ }
295+ // Handle colormaps
296+ Image src = pix_;
297+ if (pixGetColormap (src)) {
298+ src = pixRemoveColormap (src, REMOVE_CMAP_BASED_ON_SRC);
299+ }
300+ OtsuThresholdRectToPix (src, pix);
301+ if (src != pix_) {
302+ src.destroy ();
308303 }
309- original.destroy ();
310304 return true ;
311305}
312306
You can’t perform that action at this time.
0 commit comments