mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-12-14 16:49:30 +08:00
fix crash in case of missing PNG support in Leptonica see #2333
This commit is contained in:
parent
b2fc3eba8f
commit
ef33a06e65
@ -208,6 +208,8 @@ bool ImageData::SkipDeSerialize(TFile* fp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Saves the given Pix as a PNG-encoded string and destroys it.
|
// 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) {
|
void ImageData::SetPix(Pix* pix) {
|
||||||
SetPixInternal(pix, &image_data_);
|
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.
|
// 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, GenericVector<char>* image_data) {
|
||||||
l_uint8* data;
|
l_uint8* data;
|
||||||
size_t size;
|
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);
|
pixDestroy(&pix);
|
||||||
image_data->resize_no_init(size);
|
image_data->resize_no_init(size);
|
||||||
memcpy(&(*image_data)[0], data, size);
|
memcpy(&(*image_data)[0], data, size);
|
||||||
|
@ -157,6 +157,8 @@ class ImageData {
|
|||||||
return box_texts_[index];
|
return box_texts_[index];
|
||||||
}
|
}
|
||||||
// Saves the given Pix as a PNG-encoded string and destroys it.
|
// 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);
|
void SetPix(Pix* pix);
|
||||||
// Returns the Pix image for *this. Must be pixDestroyed after use.
|
// Returns the Pix image for *this. Must be pixDestroyed after use.
|
||||||
Pix* GetPix() const;
|
Pix* GetPix() const;
|
||||||
@ -183,6 +185,8 @@ class ImageData {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// Saves the given Pix as a PNG-encoded string and destroys it.
|
// 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, GenericVector<char>* image_data);
|
||||||
// Returns the Pix image for the image_data. Must be pixDestroyed after use.
|
// 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 GenericVector<char>& image_data);
|
||||||
@ -192,8 +196,8 @@ class ImageData {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
STRING imagefilename_; // File to read image from.
|
STRING imagefilename_; // File to read image from.
|
||||||
int32_t page_number_; // Page number if multi-page tif or -1.
|
int32_t page_number_; // Page number if multi-page tif or -1.
|
||||||
GenericVector<char> image_data_; // PNG file data.
|
GenericVector<char> image_data_; // PNG/PNM file data.
|
||||||
STRING language_; // Language code for image.
|
STRING language_; // Language code for image.
|
||||||
STRING transcription_; // UTF-8 ground truth of image.
|
STRING transcription_; // UTF-8 ground truth of image.
|
||||||
GenericVector<TBOX> boxes_; // If non-empty boxes of the image.
|
GenericVector<TBOX> boxes_; // If non-empty boxes of the image.
|
||||||
|
Loading…
Reference in New Issue
Block a user