Add Image::clone().

This commit is contained in:
Egor Pugin 2021-04-01 17:06:30 +03:00
parent 2aca22439e
commit 306d296979
11 changed files with 20 additions and 15 deletions

View File

@ -634,7 +634,7 @@ Pix *TessBaseAPI::GetThresholdedImage() {
if (tesseract_->pix_binary() == nullptr && !Threshold(&tesseract_->mutable_pix_binary()->pix_)) { if (tesseract_->pix_binary() == nullptr && !Threshold(&tesseract_->mutable_pix_binary()->pix_)) {
return nullptr; return nullptr;
} }
return pixClone(tesseract_->pix_binary()); return tesseract_->pix_binary().clone();
} }
/** /**

View File

@ -297,7 +297,7 @@ ColumnFinder *Tesseract::SetupPageSegAndDetectOrientation(PageSegMode pageseg_mo
if (*photo_mask_pix != nullptr) { if (*photo_mask_pix != nullptr) {
pix_no_image_ = pixSubtract(nullptr, pix_binary_, *photo_mask_pix); pix_no_image_ = pixSubtract(nullptr, pix_binary_, *photo_mask_pix);
} else { } else {
pix_no_image_ = pixClone(pix_binary_); pix_no_image_ = pix_binary_.clone();
} }
pixa_debug_.AddPix(pix_no_image_, "NoImages"); pixa_debug_.AddPix(pix_no_image_, "NoImages");
pix_no_image_.destroy(); pix_no_image_.destroy();

View File

@ -519,7 +519,7 @@ void Tesseract::PrepareForPageseg() {
max_pageseg_strategy = pageseg_strategy; max_pageseg_strategy = pageseg_strategy;
} }
sub_lang->pix_binary_.destroy(); sub_lang->pix_binary_.destroy();
sub_lang->pix_binary_ = pixClone(pix_binary()); sub_lang->pix_binary_ = pix_binary().clone();
} }
// Perform shiro-rekha (top-line) splitting and replace the current image by // Perform shiro-rekha (top-line) splitting and replace the current image by
// the newly split image. // the newly split image.
@ -528,7 +528,7 @@ void Tesseract::PrepareForPageseg() {
if (splitter_.Split(true, &pixa_debug_)) { if (splitter_.Split(true, &pixa_debug_)) {
ASSERT_HOST(splitter_.splitted_image()); ASSERT_HOST(splitter_.splitted_image());
pix_binary_.destroy(); pix_binary_.destroy();
pix_binary_ = pixClone(splitter_.splitted_image()); pix_binary_ = splitter_.splitted_image().clone();
} }
} }
@ -556,7 +556,7 @@ void Tesseract::PrepareForTessOCR(BLOCK_LIST *block_list, Tesseract *osd_tess, O
// Restore pix_binary to the binarized original pix for future reference. // Restore pix_binary to the binarized original pix for future reference.
ASSERT_HOST(splitter_.orig_pix()); ASSERT_HOST(splitter_.orig_pix());
pix_binary_.destroy(); pix_binary_.destroy();
pix_binary_ = pixClone(splitter_.orig_pix()); pix_binary_ = splitter_.orig_pix().clone();
// If the pageseg and ocr strategies are different, refresh the block list // If the pageseg and ocr strategies are different, refresh the block list
// (from the last SegmentImage call) with blobs from the real image to be used // (from the last SegmentImage call) with blobs from the real image to be used
// for OCR. // for OCR.

View File

@ -220,7 +220,7 @@ public:
pix_original_ = original_pix; pix_original_ = original_pix;
// Clone to sublangs as well. // Clone to sublangs as well.
for (auto &lang : sub_langs_) { for (auto &lang : sub_langs_) {
lang->set_pix_original(original_pix ? pixClone(original_pix) : nullptr); lang->set_pix_original(original_pix ? original_pix.clone() : nullptr);
} }
} }
// Returns a pointer to a Pix representing the best available resolution image // Returns a pointer to a Pix representing the best available resolution image

View File

@ -242,7 +242,7 @@ void ImageThresholder::Init() {
Image ImageThresholder::GetPixRect() { Image ImageThresholder::GetPixRect() {
if (IsFullImage()) { if (IsFullImage()) {
// Just clone the whole thing. // Just clone the whole thing.
return pixClone(pix_); return pix_.clone();
} else { } else {
// Crop to the given rectangle. // Crop to the given rectangle.
Box *box = boxCreate(rect_left_, rect_top_, rect_width_, rect_height_); Box *box = boxCreate(rect_left_, rect_top_, rect_width_, rect_height_);

View File

@ -21,8 +21,12 @@
namespace tesseract { namespace tesseract {
Image Image::clone() const {
return pixClone(pix_);
}
Image Image::copy(Image dest) const { Image Image::copy(Image dest) const {
return pixCopy(dest, *this); return pixCopy(dest, pix_);
} }
void Image::destroy() { void Image::destroy() {

View File

@ -35,7 +35,8 @@ public:
Pix *operator->() const { return pix_; } Pix *operator->() const { return pix_; }
// api // api
Image copy(Image dest = nullptr) const; Image clone() const; // increases refcount
Image copy(Image dest = nullptr) const; // does full copy
void destroy(); void destroy();
}; };

View File

@ -193,7 +193,7 @@ Image ImageData::GetPix() const {
# ifdef GRAPHICS_DISABLED # ifdef GRAPHICS_DISABLED
/* The only caller of this is the scaling functions to prescale the /* The only caller of this is the scaling functions to prescale the
* source. Thus we can just return a new pointer to the same data. */ * source. Thus we can just return a new pointer to the same data. */
return pixClone(internal_pix_); return internal_pix_.clone();
# else # else
/* pixCopy always does an actual copy, so the caller can modify the /* pixCopy always does an actual copy, so the caller can modify the
* changed data. */ * changed data. */

View File

@ -115,14 +115,14 @@ void Input::PreparePixInput(const StaticShape &shape, const Image pix, TRand *ra
if (color) { if (color) {
// Force RGB. // Force RGB.
if (depth == 32) { if (depth == 32) {
normed_pix = pixClone(var_pix); normed_pix = var_pix.clone();
} else { } else {
normed_pix = pixConvertTo32(var_pix); normed_pix = pixConvertTo32(var_pix);
} }
} else { } else {
// Convert non-8-bit images to 8 bit. // Convert non-8-bit images to 8 bit.
if (depth == 8) { if (depth == 8) {
normed_pix = pixClone(var_pix); normed_pix = var_pix.clone();
} else { } else {
normed_pix = pixConvertTo8(var_pix, false); normed_pix = pixConvertTo8(var_pix, false);
} }

View File

@ -70,7 +70,7 @@ void ShiroRekhaSplitter::set_orig_pix(Image pix) {
if (orig_pix_) { if (orig_pix_) {
orig_pix_.destroy(); orig_pix_.destroy();
} }
orig_pix_ = pixClone(pix); orig_pix_ = pix.clone();
} }
// Top-level method to perform splitting based on current settings. // Top-level method to perform splitting based on current settings.
@ -102,7 +102,7 @@ bool ShiroRekhaSplitter::Split(bool split_for_pageseg, DebugPixa *pixa_debug) {
// Determine all connected components in the input image. A close operation // Determine all connected components in the input image. A close operation
// may be required prior to this, depending on the current settings. // may be required prior to this, depending on the current settings.
Image pix_for_ccs = pixClone(orig_pix_); Image pix_for_ccs = orig_pix_.clone();
if (perform_close_ && global_xheight_ != kUnspecifiedXheight && !segmentation_block_list_) { if (perform_close_ && global_xheight_ != kUnspecifiedXheight && !segmentation_block_list_) {
if (devanagari_split_debuglevel > 0) { if (devanagari_split_debuglevel > 0) {
tprintf("Performing a global close operation..\n"); tprintf("Performing a global close operation..\n");

View File

@ -78,7 +78,7 @@ protected:
nullptr, 0, nullptr, nullptr, false, &mgr), nullptr, 0, nullptr, nullptr, false, &mgr),
0); 0);
bin_pix_ = api_.GetThresholdedImage(); bin_pix_ = api_.GetThresholdedImage();
*tesseract_->mutable_pix_binary() = pixClone(bin_pix_); *tesseract_->mutable_pix_binary() = bin_pix_.clone();
osd_tess->set_source_resolution(api_.tesseract()->source_resolution()); osd_tess->set_source_resolution(api_.tesseract()->source_resolution());
tesseract_->set_source_resolution(api_.tesseract()->source_resolution()); tesseract_->set_source_resolution(api_.tesseract()->source_resolution());
int width = pixGetWidth(bin_pix_); int width = pixGetWidth(bin_pix_);