test_decode_area: fix to make it work with odd image dimensions 990/head
authorEven Rouault <even.rouault@spatialys.com>
Fri, 18 Aug 2017 10:30:11 +0000 (12:30 +0200)
committerEven Rouault <even.rouault@spatialys.com>
Fri, 18 Aug 2017 10:30:11 +0000 (12:30 +0200)
tests/test_decode_area.c

index 5a36747a6723fb489b71aaf8dbdbd450b6d06104..e773bc667111e900927f62518155e7f399bd1f1b 100644 (file)
@@ -367,24 +367,26 @@ int main(int argc, char** argv)
                     da_y0 = (OPJ_INT32)opj_uint_min(l_image->y1, (OPJ_UINT32)da_y0 + 1);
                     da_y1 = (OPJ_INT32)opj_uint_min(l_image->y1, (OPJ_UINT32)da_y1 + 1);
                 }
-                l_sub_image = decode(quiet, input_file, da_x0, da_y0, da_x1, da_y1,
-                                     NULL, NULL, NULL, NULL);
-                if (!l_sub_image) {
-                    fprintf(stderr, "decode failed for %d,%d,%d,%d\n",
-                            da_x0, da_y0, da_x1, da_y1);
+                if (da_x0 < (OPJ_INT32)l_image->x1 && da_y0 < (OPJ_INT32)l_image->y1) {
+                    l_sub_image = decode(quiet, input_file, da_x0, da_y0, da_x1, da_y1,
+                                         NULL, NULL, NULL, NULL);
+                    if (!l_sub_image) {
+                        fprintf(stderr, "decode failed for %d,%d,%d,%d\n",
+                                da_x0, da_y0, da_x1, da_y1);
+                        opj_image_destroy(l_sub_image);
+                        opj_image_destroy(l_image);
+                        return 1;
+                    }
+
+                    if (!check_consistency(l_image, l_sub_image)) {
+                        fprintf(stderr, "Consistency checked failed for %d,%d,%d,%d\n",
+                                da_x0, da_y0, da_x1, da_y1);
+                        opj_image_destroy(l_sub_image);
+                        opj_image_destroy(l_image);
+                        return 1;
+                    }
                     opj_image_destroy(l_sub_image);
-                    opj_image_destroy(l_image);
-                    return 1;
                 }
-
-                if (!check_consistency(l_image, l_sub_image)) {
-                    fprintf(stderr, "Consistency checked failed for %d,%d,%d,%d\n",
-                            da_x0, da_y0, da_x1, da_y1);
-                    opj_image_destroy(l_sub_image);
-                    opj_image_destroy(l_image);
-                    return 1;
-                }
-                opj_image_destroy(l_sub_image);
             }
         }
     }