mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2025-01-21 00:20:45 +08:00
Replace GenericVector by std::vector in class ImageData
Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
parent
520aeb34aa
commit
4c6cc5a04d
@ -144,7 +144,8 @@ ImageData* ImageData::Build(const char* name, int page_number, const char* lang,
|
||||
image_data->page_number_ = page_number;
|
||||
image_data->language_ = lang;
|
||||
// Save the imagedata.
|
||||
image_data->image_data_.resize_no_init(imagedatasize);
|
||||
// TODO: optimize resize (no init).
|
||||
image_data->image_data_.resize(imagedatasize);
|
||||
memcpy(&image_data->image_data_[0], imagedata, imagedatasize);
|
||||
if (!image_data->AddBoxes(box_text)) {
|
||||
if (truth_text == nullptr || truth_text[0] == '\0') {
|
||||
@ -170,11 +171,11 @@ ImageData* ImageData::Build(const char* name, int page_number, const char* lang,
|
||||
bool ImageData::Serialize(TFile* fp) const {
|
||||
if (!imagefilename_.Serialize(fp)) return false;
|
||||
if (!fp->Serialize(&page_number_)) return false;
|
||||
if (!image_data_.Serialize(fp)) return false;
|
||||
if (!fp->Serialize(image_data_)) return false;
|
||||
if (!language_.Serialize(fp)) return false;
|
||||
if (!transcription_.Serialize(fp)) return false;
|
||||
if (!fp->Serialize(boxes_)) return false;
|
||||
if (!box_texts_.SerializeClasses(fp)) return false;
|
||||
if (!fp->Serialize(box_texts_)) return false;
|
||||
int8_t vertical = vertical_text_;
|
||||
return fp->Serialize(&vertical);
|
||||
}
|
||||
@ -183,11 +184,11 @@ bool ImageData::Serialize(TFile* fp) const {
|
||||
bool ImageData::DeSerialize(TFile* fp) {
|
||||
if (!imagefilename_.DeSerialize(fp)) return false;
|
||||
if (!fp->DeSerialize(&page_number_)) return false;
|
||||
if (!image_data_.DeSerialize(fp)) return false;
|
||||
if (!fp->DeSerialize(image_data_)) return false;
|
||||
if (!language_.DeSerialize(fp)) return false;
|
||||
if (!transcription_.DeSerialize(fp)) return false;
|
||||
if (!fp->DeSerialize(boxes_)) return false;
|
||||
if (!box_texts_.DeSerializeClasses(fp)) return false;
|
||||
if (!fp->DeSerialize(box_texts_)) return false;
|
||||
int8_t vertical = 0;
|
||||
if (!fp->DeSerialize(&vertical)) return false;
|
||||
vertical_text_ = vertical != 0;
|
||||
@ -349,7 +350,7 @@ void ImageData::AddBoxes(const std::vector<TBOX>& boxes,
|
||||
// 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.
|
||||
void ImageData::SetPixInternal(Pix* pix, GenericVector<char>* image_data) {
|
||||
void ImageData::SetPixInternal(Pix* pix, std::vector<char>* image_data) {
|
||||
l_uint8* data;
|
||||
size_t size;
|
||||
l_int32 ret;
|
||||
@ -358,13 +359,14 @@ void ImageData::SetPixInternal(Pix* pix, GenericVector<char>* image_data) {
|
||||
ret = pixWriteMem(&data, &size, pix, IFF_PNM);
|
||||
}
|
||||
pixDestroy(&pix);
|
||||
image_data->resize_no_init(size);
|
||||
// TODO: optimize resize (no init).
|
||||
image_data->resize(size);
|
||||
memcpy(&(*image_data)[0], data, size);
|
||||
lept_free(data);
|
||||
}
|
||||
|
||||
// Returns the Pix image for the image_data. Must be pixDestroyed after use.
|
||||
Pix* ImageData::GetPixInternal(const GenericVector<char>& image_data) {
|
||||
Pix* ImageData::GetPixInternal(const std::vector<char>& image_data) {
|
||||
Pix* pix = nullptr;
|
||||
if (!image_data.empty()) {
|
||||
// Convert the array to an image.
|
||||
|
@ -141,7 +141,7 @@ class TESS_API ImageData {
|
||||
void set_page_number(int num) {
|
||||
page_number_ = num;
|
||||
}
|
||||
const GenericVector<char>& image_data() const {
|
||||
const std::vector<char>& image_data() const {
|
||||
return image_data_;
|
||||
}
|
||||
const STRING& language() const {
|
||||
@ -156,7 +156,7 @@ class TESS_API ImageData {
|
||||
const std::vector<TBOX>& boxes() const {
|
||||
return boxes_;
|
||||
}
|
||||
const GenericVector<STRING>& box_texts() const {
|
||||
const std::vector<STRING>& box_texts() const {
|
||||
return box_texts_;
|
||||
}
|
||||
const STRING& box_text(int index) const {
|
||||
@ -193,9 +193,9 @@ class TESS_API ImageData {
|
||||
// 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.
|
||||
static void SetPixInternal(Pix* pix, GenericVector<char>* image_data);
|
||||
static void SetPixInternal(Pix* pix, std::vector<char>* image_data);
|
||||
// Returns the Pix image for the image_data. Must be pixDestroyed after use.
|
||||
static Pix* GetPixInternal(const GenericVector<char>& image_data);
|
||||
static Pix* GetPixInternal(const std::vector<char>& image_data);
|
||||
// Parses the text string as a box file and adds any discovered boxes that
|
||||
// match the page number. Returns false on error.
|
||||
bool AddBoxes(const char* box_text);
|
||||
@ -206,11 +206,11 @@ class TESS_API ImageData {
|
||||
#ifdef TESSERACT_IMAGEDATA_AS_PIX
|
||||
Pix *internal_pix_;
|
||||
#endif
|
||||
GenericVector<char> image_data_; // PNG/PNM file data.
|
||||
std::vector<char> image_data_; // PNG/PNM file data.
|
||||
STRING language_; // Language code for image.
|
||||
STRING transcription_; // UTF-8 ground truth of image.
|
||||
std::vector<TBOX> boxes_; // If non-empty boxes of the image.
|
||||
GenericVector<STRING> box_texts_; // String for text in each box.
|
||||
std::vector<STRING> box_texts_; // String for text in each box.
|
||||
bool vertical_text_; // Image has been rotated from vertical.
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user