Make opj_set_decode_area() and opj_decode() take into account opj_set_decoded_resolut...
[openjpeg.git] / src / bin / jp2 / opj_decompress.c
index e2d8cbde85906d0be6962b201cc062a66f16f5ea..479d83822eee5f715d8396e01f5e999051e8eb78 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"
@@ -1295,6 +1297,7 @@ int main(int argc, char **argv)
     int failed = 0;
     OPJ_FLOAT64 t, tCumulative = 0;
     OPJ_UINT32 numDecompressedImages = 0;
+    OPJ_UINT32 cp_reduce;
 
     /* set decoding parameters to default values */
     set_default_parameters(&parameters);
@@ -1308,6 +1311,14 @@ int main(int argc, char **argv)
         goto fin;
     }
 
+    cp_reduce = parameters.core.cp_reduce;
+    if (getenv("USE_OPJ_SET_DECODED_RESOLUTION_FACTOR") != NULL) {
+        /* For debugging/testing purposes, do not set the cp_reduce member */
+        /* if USE_OPJ_SET_DECODED_RESOLUTION_FACTOR is defined, but used */
+        /* the opj_set_decoded_resolution_factor() API instead */
+        parameters.core.cp_reduce = 0;
+    }
+
 
     /* Initialize reading of directory */
     if (img_fol.set_imgdir == 1) {
@@ -1352,7 +1363,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)) {
@@ -1442,11 +1455,35 @@ int main(int argc, char **argv)
             goto fin;
         }
 
+        if (getenv("USE_OPJ_SET_DECODED_RESOLUTION_FACTOR") != NULL) {
+            /* For debugging/testing purposes, and also an illustration on how to */
+            /* use the alternative API opj_set_decoded_resolution_factor() instead */
+            /* of setting parameters.cp_reduce */
+            if (! opj_set_decoded_resolution_factor(l_codec, cp_reduce)) {
+                fprintf(stderr,
+                        "ERROR -> opj_decompress: failed to set the resolution factor tile!\n");
+                opj_destroy_codec(l_codec);
+                opj_stream_destroy(l_stream);
+                opj_image_destroy(image);
+                failed = 1;
+                goto fin;
+            }
+        }
+
         if (!parameters.nb_tile_to_decode) {
+            if (getenv("SKIP_OPJ_SET_DECODE_AREA") != NULL &&
+                    parameters.DA_x0 == 0 &&
+                    parameters.DA_y0 == 0 &&
+                    parameters.DA_x1 == 0 &&
+                    parameters.DA_y1 == 0) {
+                /* For debugging/testing purposes, */
+                /* do nothing if SKIP_OPJ_SET_DECODE_AREA env variable */
+                /* is defined and no decoded area has been set */
+            }
             /* Optional if you want decode the entire image */
-            if (!opj_set_decode_area(l_codec, image, (OPJ_INT32)parameters.DA_x0,
-                                     (OPJ_INT32)parameters.DA_y0, (OPJ_INT32)parameters.DA_x1,
-                                     (OPJ_INT32)parameters.DA_y1)) {
+            else if (!opj_set_decode_area(l_codec, image, (OPJ_INT32)parameters.DA_x0,
+                                          (OPJ_INT32)parameters.DA_y0, (OPJ_INT32)parameters.DA_x1,
+                                          (OPJ_INT32)parameters.DA_y1)) {
                 fprintf(stderr, "ERROR -> opj_decompress: failed to set the decoded area\n");
                 opj_stream_destroy(l_stream);
                 opj_destroy_codec(l_codec);
@@ -1467,15 +1504,6 @@ int main(int argc, char **argv)
             }
         } else {
 
-            /* It is just here to illustrate how to use the resolution after set parameters */
-            /*if (!opj_set_decoded_resolution_factor(l_codec, 5)) {
-                fprintf(stderr, "ERROR -> opj_decompress: failed to set the resolution factor tile!\n");
-                opj_destroy_codec(l_codec);
-                opj_stream_destroy(l_stream);
-                opj_image_destroy(image);
-                failed = 1; goto fin;
-            }*/
-
             if (!opj_get_decoded_tile(l_codec, l_stream, image, parameters.tile_index)) {
                 fprintf(stderr, "ERROR -> opj_decompress: failed to decode tile!\n");
                 opj_destroy_codec(l_codec);