JPG loader: print error string on failure
authorMichal Maciola <71131832+mmaciola@users.noreply.github.com>
Sat, 7 Aug 2021 03:00:04 +0000 (05:00 +0200)
committerHermet Park <chuneon.park@samsung.com>
Mon, 9 Aug 2021 06:35:13 +0000 (15:35 +0900)
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.

src/loaders/jpg/tvgJpgLoader.cpp

index f08e063..f3327fb 100644 (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;