tgatoimage(): avoid excessive memory allocation attempt, and fixes unaligned load...
[openjpeg.git] / src / bin / jp2 / opj_decompress.c
index a1e18af7146fa4d119fcb8a22500efbc3142a0b5..848167babe15a1003d1e959cc93864bfe96c7c50 100644 (file)
@@ -237,6 +237,8 @@ static void decode_help_display(void)
         fprintf(stdout, "  -threads <num_threads>\n"
                 "    Number of threads to use for decoding.\n");
     }
+    fprintf(stdout, "  -quiet\n"
+            "    Disable output from the library and other output.\n");
     /* UniPG>> */
 #ifdef USE_JPWL
     fprintf(stdout, "  -W <options>\n"
@@ -935,7 +937,8 @@ OPJ_FLOAT64 opj_clock(void)
     /* cout << "freq = " << ((double) freq.QuadPart) << endl; */
     /* t is the high resolution performance counter (see MSDN) */
     QueryPerformanceCounter(& t) ;
-    return freq.QuadPart ? (t.QuadPart / (OPJ_FLOAT64)freq.QuadPart) : 0;
+    return freq.QuadPart ? ((OPJ_FLOAT64)t.QuadPart / (OPJ_FLOAT64)freq.QuadPart) :
+           0;
 #elif defined(__linux)
     struct timespec ts;
     clock_gettime(CLOCK_REALTIME, &ts);
@@ -987,6 +990,8 @@ sample quiet callback expecting no client object
 */
 static void quiet_callback(const char *msg, void *client_data)
 {
+    (void)msg;
+    (void)client_data;
 }
 
 static void set_default_parameters(opj_decompress_parameters* parameters)
@@ -1349,7 +1354,9 @@ int main(int argc, char **argv)
     /*Decoding image one by one*/
     for (imageno = 0; imageno < num_images ; imageno++)  {
 
-        fprintf(stderr, "\n");
+        if (!parameters.quiet) {
+            fprintf(stderr, "\n");
+        }
 
         if (img_fol.set_imgdir == 1) {
             if (get_next_file(imageno, dirptr, &img_fol, &parameters)) {
@@ -1486,6 +1493,17 @@ int main(int argc, char **argv)
             }
         }
 
+        /* FIXME? Shouldn't that situation be considered as an error of */
+        /* opj_decode() / opj_get_decoded_tile() ? */
+        if (image->comps[0].data == NULL) {
+            fprintf(stderr, "ERROR -> opj_decompress: no image data!\n");
+            opj_destroy_codec(l_codec);
+            opj_stream_destroy(l_stream);
+            opj_image_destroy(image);
+            failed = 1;
+            goto fin;
+        }
+
         tCumulative += opj_clock() - t;
         numDecompressedImages++;
 
@@ -1708,7 +1726,7 @@ fin:
         }
         free(dirptr);
     }
-    if (numDecompressedImages && !(parameters.quiet)) {
+    if (numDecompressedImages && !failed && !(parameters.quiet)) {
         fprintf(stdout, "decode time: %d ms\n",
                 (int)((tCumulative * 1000.0) / (OPJ_FLOAT64)numDecompressedImages));
     }