JPG loader: print error string on failure

Added error string printing on jpg image loading failure.
The error message help developer find the corrupted jpg file.
Error message is not printed for open from char* data as there the
loaders are tried on by one.
This commit is contained in:
Michal Maciola 2021-08-07 05:00:04 +02:00 committed by GitHub
parent 41b5d8eb4e
commit 3d88d7eefc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -77,7 +77,10 @@ bool JpgLoader::open(const string& path)
if (fread(data, size, 1, jpegFile) < 1) goto failure;
int width, height, subSample, colorSpace;
if (tjDecompressHeader3(jpegDecompressor, data, size, &width, &height, &subSample, &colorSpace) < 0) goto failure;
if (tjDecompressHeader3(jpegDecompressor, data, size, &width, &height, &subSample, &colorSpace) < 0) {
TVGERR("JPG LOADER", "%s", tjGetErrorStr());
goto failure;
}
w = static_cast<float>(width);
h = static_cast<float>(height);
@ -127,6 +130,7 @@ bool JpgLoader::read()
//decompress jpg image
if (tjDecompress2(jpegDecompressor, data, size, image, static_cast<int>(w), 0, static_cast<int>(h), TJPF_BGRX, 0) < 0) {
TVGERR("JPG LOADER", "%s", tjGetErrorStr());
tjFree(image);
image = nullptr;
return false;