Skip to content

Commit

Permalink
Revert 4fa05b9. Make a note.
Browse files Browse the repository at this point in the history
  • Loading branch information
egorpugin committed Mar 31, 2021
1 parent a792b67 commit 1628a9a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/ccstruct/imagedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ ImageData::ImageData(bool vertical, Image pix) : page_number_(0), vertical_text_
SetPix(pix);
}
ImageData::~ImageData() {
#ifdef TESSERACT_IMAGEDATA_AS_PIX
internal_pix_.destroy();
#endif
}

// Builds and returns an ImageData from the basic data. Note that imagedata,
Expand Down Expand Up @@ -177,12 +180,28 @@ bool ImageData::SkipDeSerialize(TFile *fp) {
// In case of missing PNG support in Leptonica use PNM format,
// which requires more memory.
void ImageData::SetPix(Image pix) {
#ifdef TESSERACT_IMAGEDATA_AS_PIX
internal_pix_ = pix;
#else
SetPixInternal(pix, &image_data_);
#endif
}

// Returns the Pix image for *this. Must be pixDestroyed after use.
Image ImageData::GetPix() const {
#ifdef TESSERACT_IMAGEDATA_AS_PIX
# ifdef GRAPHICS_DISABLED
/* 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. */
return pixClone(internal_pix_);
# else
/* pixCopy always does an actual copy, so the caller can modify the
* changed data. */
return pixCopy(NULL, internal_pix_);
# endif
#else
return GetPixInternal(image_data_);
#endif
}

// Gets anything and everything with a non-nullptr pointer, prescaled to a
Expand Down Expand Up @@ -303,6 +322,7 @@ void ImageData::AddBoxes(const std::vector<TBOX> &boxes, const std::vector<std::
}
}

#ifndef TESSERACT_IMAGEDATA_AS_PIX
// Saves the given Pix as a PNG-encoded string and destroys it.
// In case of missing PNG support in Leptonica use PNM format,
// which requires more memory.
Expand Down Expand Up @@ -331,6 +351,7 @@ Image ImageData::GetPixInternal(const std::vector<char> &image_data) {
}
return pix;
}
#endif

// Parses the text string as a box file and adds any discovered boxes that
// match the page number. Returns false on error.
Expand Down
5 changes: 5 additions & 0 deletions src/ccstruct/imagedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ class TESS_API ImageData {
private:
std::string imagefilename_; // File to read image from.
int32_t page_number_; // Page number if multi-page tif or -1.
// see https://github.com/tesseract-ocr/tesseract/pull/2965
// EP: reconsider for tess6.0/opencv
#ifdef TESSERACT_IMAGEDATA_AS_PIX
Image internal_pix_;
#endif
std::vector<char> image_data_; // PNG/PNM file data.
std::string language_; // Language code for image.
std::string transcription_; // UTF-8 ground truth of image.
Expand Down

0 comments on commit 1628a9a

Please sign in to comment.