fix crash in case of missing PNG support in Leptonica see #2333

This commit is contained in:
zdenop 2019-05-01 19:51:54 +02:00 committed by Stefan Weil
parent b2fc3eba8f
commit ef33a06e65
2 changed files with 15 additions and 3 deletions

View File

@ -208,6 +208,8 @@ bool ImageData::SkipDeSerialize(TFile* fp) {
}
// 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::SetPix(Pix* pix) {
SetPixInternal(pix, &image_data_);
}
@ -323,10 +325,16 @@ void ImageData::AddBoxes(const GenericVector<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) {
l_uint8* data;
size_t size;
pixWriteMem(&data, &size, pix, IFF_PNG);
l_int32 ret;
ret = pixWriteMem(&data, &size, pix, IFF_PNG);
if (ret) {
ret = pixWriteMem(&data, &size, pix, IFF_PNM);
}
pixDestroy(&pix);
image_data->resize_no_init(size);
memcpy(&(*image_data)[0], data, size);

View File

@ -157,6 +157,8 @@ class ImageData {
return box_texts_[index];
}
// 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 SetPix(Pix* pix);
// Returns the Pix image for *this. Must be pixDestroyed after use.
Pix* GetPix() const;
@ -183,6 +185,8 @@ class ImageData {
private:
// 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);
// Returns the Pix image for the image_data. Must be pixDestroyed after use.
static Pix* GetPixInternal(const GenericVector<char>& image_data);
@ -192,8 +196,8 @@ class ImageData {
private:
STRING imagefilename_; // File to read image from.
int32_t page_number_; // Page number if multi-page tif or -1.
GenericVector<char> image_data_; // PNG file data.
int32_t page_number_; // Page number if multi-page tif or -1.
GenericVector<char> image_data_; // PNG/PNM file data.
STRING language_; // Language code for image.
STRING transcription_; // UTF-8 ground truth of image.
GenericVector<TBOX> boxes_; // If non-empty boxes of the image.