test_decode_area.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /*
  2. * The copyright in this software is being made available under the 2-clauses
  3. * BSD License, included below. This software may be subject to other third
  4. * party and contributor rights, including patent rights, and no such rights
  5. * are granted under this license.
  6. *
  7. * Copyright (c) 2017, IntoPix SA <contact@intopix.com>
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #include <string.h>
  32. #include <stdlib.h>
  33. #include "openjpeg.h"
  34. #include "format_defs.h"
  35. /* -------------------------------------------------------------------------- */
  36. #define JP2_RFC3745_MAGIC "\x00\x00\x00\x0c\x6a\x50\x20\x20\x0d\x0a\x87\x0a"
  37. #define JP2_MAGIC "\x0d\x0a\x87\x0a"
  38. /* position 45: "\xff\x52" */
  39. #define J2K_CODESTREAM_MAGIC "\xff\x4f\xff\x51"
  40. static int infile_format(const char *fname)
  41. {
  42. FILE *reader;
  43. unsigned char buf[12];
  44. unsigned int l_nb_read;
  45. reader = fopen(fname, "rb");
  46. if (reader == NULL) {
  47. return -1;
  48. }
  49. memset(buf, 0, 12);
  50. l_nb_read = (unsigned int)fread(buf, 1, 12, reader);
  51. fclose(reader);
  52. if (l_nb_read != 12) {
  53. return -1;
  54. }
  55. if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) {
  56. return JP2_CFMT;
  57. } else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) {
  58. return J2K_CFMT;
  59. } else {
  60. return -1;
  61. }
  62. }
  63. /* -------------------------------------------------------------------------- */
  64. /**
  65. sample error debug callback expecting no client object
  66. */
  67. static void error_callback(const char *msg, void *client_data)
  68. {
  69. (void)client_data;
  70. fprintf(stdout, "[ERROR] %s", msg);
  71. }
  72. /**
  73. sample warning debug callback expecting no client object
  74. */
  75. static void warning_callback(const char *msg, void *client_data)
  76. {
  77. (void)client_data;
  78. fprintf(stdout, "[WARNING] %s", msg);
  79. }
  80. /**
  81. sample debug callback expecting no client object
  82. */
  83. static void info_callback(const char *msg, void *client_data)
  84. {
  85. (void)client_data;
  86. (void)msg;
  87. /*fprintf(stdout, "[INFO] %s", msg);*/
  88. }
  89. static opj_codec_t* create_codec_and_stream(const char* input_file,
  90. opj_stream_t** pOutStream)
  91. {
  92. opj_dparameters_t l_param;
  93. opj_codec_t * l_codec = NULL;
  94. opj_stream_t * l_stream = NULL;
  95. l_stream = opj_stream_create_default_file_stream(input_file, OPJ_TRUE);
  96. if (!l_stream) {
  97. fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
  98. return NULL;
  99. }
  100. /* Set the default decoding parameters */
  101. opj_set_default_decoder_parameters(&l_param);
  102. /* */
  103. l_param.decod_format = infile_format(input_file);
  104. switch (l_param.decod_format) {
  105. case J2K_CFMT: { /* JPEG-2000 codestream */
  106. /* Get a decoder handle */
  107. l_codec = opj_create_decompress(OPJ_CODEC_J2K);
  108. break;
  109. }
  110. case JP2_CFMT: { /* JPEG 2000 compressed image data */
  111. /* Get a decoder handle */
  112. l_codec = opj_create_decompress(OPJ_CODEC_JP2);
  113. break;
  114. }
  115. default: {
  116. fprintf(stderr, "ERROR -> Not a valid JPEG2000 file!\n");
  117. opj_stream_destroy(l_stream);
  118. return NULL;
  119. }
  120. }
  121. /* catch events using our callbacks and give a local context */
  122. opj_set_info_handler(l_codec, info_callback, 00);
  123. opj_set_warning_handler(l_codec, warning_callback, 00);
  124. opj_set_error_handler(l_codec, error_callback, 00);
  125. /* Setup the decoder decoding parameters using user parameters */
  126. if (! opj_setup_decoder(l_codec, &l_param)) {
  127. fprintf(stderr, "ERROR ->failed to setup the decoder\n");
  128. opj_stream_destroy(l_stream);
  129. opj_destroy_codec(l_codec);
  130. return NULL;
  131. }
  132. *pOutStream = l_stream;
  133. return l_codec;
  134. }
  135. opj_image_t* decode(
  136. OPJ_BOOL quiet,
  137. const char* input_file,
  138. OPJ_INT32 x0,
  139. OPJ_INT32 y0,
  140. OPJ_INT32 x1,
  141. OPJ_INT32 y1,
  142. OPJ_UINT32* ptilew,
  143. OPJ_UINT32* ptileh,
  144. OPJ_UINT32* pcblkw,
  145. OPJ_UINT32* pcblkh)
  146. {
  147. opj_codec_t * l_codec = NULL;
  148. opj_image_t * l_image = NULL;
  149. opj_stream_t * l_stream = NULL;
  150. if (!quiet) {
  151. if (x0 != 0 || x1 != 0 || y0 != 0 || y1 != 0) {
  152. printf("Decoding %d,%d,%d,%d\n", x0, y0, x1, y1);
  153. } else {
  154. printf("Decoding full image\n");
  155. }
  156. }
  157. l_codec = create_codec_and_stream(input_file, &l_stream);
  158. if (l_codec == NULL) {
  159. return NULL;
  160. }
  161. /* Read the main header of the codestream and if necessary the JP2 boxes*/
  162. if (! opj_read_header(l_stream, l_codec, &l_image)) {
  163. fprintf(stderr, "ERROR -> failed to read the header\n");
  164. opj_stream_destroy(l_stream);
  165. opj_destroy_codec(l_codec);
  166. return NULL;
  167. }
  168. {
  169. opj_codestream_info_v2_t* pCodeStreamInfo = opj_get_cstr_info(l_codec);
  170. if (ptilew) {
  171. *ptilew = pCodeStreamInfo->tdx;
  172. }
  173. if (ptileh) {
  174. *ptileh = pCodeStreamInfo->tdy;
  175. }
  176. //int numResolutions = pCodeStreamInfo->m_default_tile_info.tccp_info[0].numresolutions;
  177. if (pcblkw) {
  178. *pcblkw = 1U << pCodeStreamInfo->m_default_tile_info.tccp_info[0].cblkw;
  179. }
  180. if (pcblkh) {
  181. *pcblkh = 1U << pCodeStreamInfo->m_default_tile_info.tccp_info[0].cblkh;
  182. }
  183. opj_destroy_cstr_info(&pCodeStreamInfo);
  184. }
  185. if (x0 != 0 || x1 != 0 || y0 != 0 || y1 != 0) {
  186. if (!opj_set_decode_area(l_codec, l_image, x0, y0, x1, y1)) {
  187. fprintf(stderr, "ERROR -> failed to set the decoded area\n");
  188. opj_stream_destroy(l_stream);
  189. opj_destroy_codec(l_codec);
  190. opj_image_destroy(l_image);
  191. return NULL;
  192. }
  193. }
  194. /* Get the decoded image */
  195. if (!(opj_decode(l_codec, l_stream, l_image))) {
  196. fprintf(stderr, "ERROR -> failed to decode image!\n");
  197. opj_stream_destroy(l_stream);
  198. opj_destroy_codec(l_codec);
  199. opj_image_destroy(l_image);
  200. return NULL;
  201. }
  202. if (! opj_end_decompress(l_codec, l_stream)) {
  203. opj_stream_destroy(l_stream);
  204. opj_destroy_codec(l_codec);
  205. opj_image_destroy(l_image);
  206. return NULL;
  207. }
  208. opj_stream_destroy(l_stream);
  209. opj_destroy_codec(l_codec);
  210. return l_image;
  211. }
  212. int decode_by_strip(OPJ_BOOL quiet,
  213. const char* input_file,
  214. OPJ_UINT32 strip_height,
  215. OPJ_INT32 da_x0,
  216. OPJ_INT32 da_y0,
  217. OPJ_INT32 da_x1,
  218. OPJ_INT32 da_y1,
  219. opj_image_t* full_image)
  220. {
  221. /* OPJ_UINT32 tilew, tileh; */
  222. opj_codec_t * l_codec = NULL;
  223. opj_image_t * l_image = NULL;
  224. opj_stream_t * l_stream = NULL;
  225. OPJ_UINT32 x0, y0, x1, y1, y;
  226. OPJ_UINT32 full_x0, full_y0, full_x1, full_y1;
  227. l_codec = create_codec_and_stream(input_file, &l_stream);
  228. if (l_codec == NULL) {
  229. return 1;
  230. }
  231. /* Read the main header of the codestream and if necessary the JP2 boxes*/
  232. if (! opj_read_header(l_stream, l_codec, &l_image)) {
  233. fprintf(stderr, "ERROR -> failed to read the header\n");
  234. opj_stream_destroy(l_stream);
  235. opj_destroy_codec(l_codec);
  236. return 1;
  237. }
  238. full_x0 = l_image->x0;
  239. full_y0 = l_image->y0;
  240. full_x1 = l_image->x1;
  241. full_y1 = l_image->y1;
  242. if (da_x0 != 0 || da_y0 != 0 || da_x1 != 0 || da_y1 != 0) {
  243. x0 = (OPJ_UINT32)da_x0;
  244. y0 = (OPJ_UINT32)da_y0;
  245. x1 = (OPJ_UINT32)da_x1;
  246. y1 = (OPJ_UINT32)da_y1;
  247. } else {
  248. x0 = l_image->x0;
  249. y0 = l_image->y0;
  250. x1 = l_image->x1;
  251. y1 = l_image->y1;
  252. }
  253. for (y = y0; y < y1; y += strip_height) {
  254. OPJ_UINT32 h_req = strip_height;
  255. if (y + h_req > y1) {
  256. h_req = y1 - y;
  257. }
  258. if (!quiet) {
  259. printf("Decoding %u...%u\n", y, y + h_req);
  260. }
  261. if (!opj_set_decode_area(l_codec, l_image, (OPJ_INT32)x0, (OPJ_INT32)y,
  262. (OPJ_INT32)x1, (OPJ_INT32)(y + h_req))) {
  263. fprintf(stderr, "ERROR -> failed to set the decoded area\n");
  264. opj_stream_destroy(l_stream);
  265. opj_destroy_codec(l_codec);
  266. opj_image_destroy(l_image);
  267. return 1;
  268. }
  269. /* Get the decoded image */
  270. if (!(opj_decode(l_codec, l_stream, l_image))) {
  271. fprintf(stderr, "ERROR -> failed to decode image!\n");
  272. opj_stream_destroy(l_stream);
  273. opj_destroy_codec(l_codec);
  274. opj_image_destroy(l_image);
  275. return 1;
  276. }
  277. if (full_image) {
  278. OPJ_UINT32 y_check, x;
  279. OPJ_UINT32 compno;
  280. for (compno = 0; compno < l_image->numcomps; compno ++) {
  281. for (y_check = 0; y_check < h_req; y_check++) {
  282. for (x = x0; x < x1; x++) {
  283. OPJ_INT32 sub_image_val =
  284. l_image->comps[compno].data[y_check * (x1 - x0) + (x - x0)];
  285. OPJ_INT32 image_val =
  286. full_image->comps[compno].data[(y + y_check) * (x1 - x0) + (x - x0)];
  287. if (sub_image_val != image_val) {
  288. fprintf(stderr,
  289. "Difference found at subimage pixel (%u,%u) "
  290. "of compno=%u: got %d, expected %d\n",
  291. x, y_check + y, compno, sub_image_val, image_val);
  292. return 1;
  293. }
  294. }
  295. }
  296. }
  297. }
  298. }
  299. /* If image is small enough, try a final whole image read */
  300. if (full_x1 - full_x0 < 10000 && full_y1 - full_y0 < 10000) {
  301. if (!quiet) {
  302. printf("Decoding full image\n");
  303. }
  304. if (!opj_set_decode_area(l_codec, l_image,
  305. (OPJ_INT32)full_x0, (OPJ_INT32)full_y0,
  306. (OPJ_INT32)full_x1, (OPJ_INT32)full_y1)) {
  307. fprintf(stderr, "ERROR -> failed to set the decoded area\n");
  308. opj_stream_destroy(l_stream);
  309. opj_destroy_codec(l_codec);
  310. opj_image_destroy(l_image);
  311. return 1;
  312. }
  313. /* Get the decoded image */
  314. if (!(opj_decode(l_codec, l_stream, l_image))) {
  315. fprintf(stderr, "ERROR -> failed to decode image!\n");
  316. opj_stream_destroy(l_stream);
  317. opj_destroy_codec(l_codec);
  318. opj_image_destroy(l_image);
  319. return 1;
  320. }
  321. }
  322. if (! opj_end_decompress(l_codec, l_stream)) {
  323. opj_stream_destroy(l_stream);
  324. opj_destroy_codec(l_codec);
  325. opj_image_destroy(l_image);
  326. return 1;
  327. }
  328. opj_stream_destroy(l_stream);
  329. opj_destroy_codec(l_codec);
  330. opj_image_destroy(l_image);
  331. return 0;
  332. }
  333. OPJ_BOOL check_consistency(opj_image_t* p_image, opj_image_t* p_sub_image)
  334. {
  335. OPJ_UINT32 compno;
  336. for (compno = 0; compno < p_image->numcomps; compno ++) {
  337. OPJ_UINT32 y;
  338. OPJ_UINT32 shift_y = p_sub_image->comps[compno].y0 - p_image->comps[compno].y0;
  339. OPJ_UINT32 shift_x = p_sub_image->comps[compno].x0 - p_image->comps[compno].x0;
  340. OPJ_UINT32 image_w = p_image->comps[compno].w;
  341. OPJ_UINT32 sub_image_w = p_sub_image->comps[compno].w;
  342. for (y = 0; y < p_sub_image->comps[compno].h; y++) {
  343. OPJ_UINT32 x;
  344. for (x = 0; x < sub_image_w; x++) {
  345. OPJ_INT32 sub_image_val =
  346. p_sub_image->comps[compno].data[y * sub_image_w + x];
  347. OPJ_INT32 image_val =
  348. p_image->comps[compno].data[(y + shift_y) * image_w + x + shift_x];
  349. if (sub_image_val != image_val) {
  350. fprintf(stderr,
  351. "Difference found at subimage pixel (%u,%u) "
  352. "of compno=%u: got %d, expected %d\n",
  353. x, y, compno, sub_image_val, image_val);
  354. return OPJ_FALSE;
  355. }
  356. }
  357. }
  358. }
  359. return OPJ_TRUE;
  360. }
  361. static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b)
  362. {
  363. return (a < b) ? a : b;
  364. }
  365. int main(int argc, char** argv)
  366. {
  367. opj_image_t * l_image = NULL;
  368. opj_image_t * l_sub_image = NULL;
  369. OPJ_INT32 da_x0 = 0, da_y0 = 0, da_x1 = 0, da_y1 = 0;
  370. const char* input_file = NULL;
  371. OPJ_UINT32 tilew, tileh, cblkw, cblkh;
  372. OPJ_UINT32 w, h;
  373. OPJ_UINT32 x, y;
  374. OPJ_UINT32 step_x, step_y;
  375. OPJ_BOOL quiet = OPJ_FALSE;
  376. OPJ_UINT32 nsteps = 100;
  377. OPJ_UINT32 strip_height = 0;
  378. OPJ_BOOL strip_check = OPJ_FALSE;
  379. if (argc < 2) {
  380. fprintf(stderr,
  381. "Usage: test_decode_area [-q] [-steps n] input_file_jp2_or_jk2 [x0 y0 x1 y1]\n"
  382. "or : test_decode_area [-q] [-strip_height h] [-strip_check] input_file_jp2_or_jk2 [x0 y0 x1 y1]\n");
  383. return 1;
  384. }
  385. {
  386. int iarg;
  387. for (iarg = 1; iarg < argc; iarg++) {
  388. if (strcmp(argv[iarg], "-q") == 0) {
  389. quiet = OPJ_TRUE;
  390. } else if (strcmp(argv[iarg], "-steps") == 0 && iarg + 1 < argc) {
  391. nsteps = (OPJ_UINT32)atoi(argv[iarg + 1]);
  392. iarg ++;
  393. } else if (strcmp(argv[iarg], "-strip_height") == 0 && iarg + 1 < argc) {
  394. strip_height = (OPJ_UINT32)atoi(argv[iarg + 1]);
  395. iarg ++;
  396. } else if (strcmp(argv[iarg], "-strip_check") == 0) {
  397. strip_check = OPJ_TRUE;
  398. } else if (input_file == NULL) {
  399. input_file = argv[iarg];
  400. } else if (iarg + 3 < argc) {
  401. da_x0 = atoi(argv[iarg]);
  402. da_y0 = atoi(argv[iarg + 1]);
  403. da_x1 = atoi(argv[iarg + 2]);
  404. da_y1 = atoi(argv[iarg + 3]);
  405. if (da_x0 < 0 || da_y0 < 0 || da_x1 < 0 || da_y1 < 0) {
  406. fprintf(stderr, "Wrong bounds\n");
  407. return 1;
  408. }
  409. iarg += 3;
  410. }
  411. }
  412. }
  413. if (!strip_height || strip_check) {
  414. l_image = decode(quiet, input_file, 0, 0, 0, 0,
  415. &tilew, &tileh, &cblkw, &cblkh);
  416. if (!l_image) {
  417. return 1;
  418. }
  419. }
  420. if (strip_height) {
  421. int ret = decode_by_strip(quiet, input_file, strip_height, da_x0, da_y0, da_x1,
  422. da_y1, l_image);
  423. if (l_image) {
  424. opj_image_destroy(l_image);
  425. }
  426. return ret;
  427. }
  428. if (da_x0 != 0 || da_x1 != 0 || da_y0 != 0 || da_y1 != 0) {
  429. l_sub_image = decode(quiet, input_file, da_x0, da_y0, da_x1, da_y1,
  430. NULL, NULL, NULL, NULL);
  431. if (!l_sub_image) {
  432. fprintf(stderr, "decode failed for %d,%d,%d,%d\n",
  433. da_x0, da_y0, da_x1, da_y1);
  434. opj_image_destroy(l_sub_image);
  435. opj_image_destroy(l_image);
  436. return 1;
  437. }
  438. if (!check_consistency(l_image, l_sub_image)) {
  439. fprintf(stderr, "Consistency checked failed for %d,%d,%d,%d\n",
  440. da_x0, da_y0, da_x1, da_y1);
  441. opj_image_destroy(l_sub_image);
  442. opj_image_destroy(l_image);
  443. return 1;
  444. }
  445. opj_image_destroy(l_sub_image);
  446. opj_image_destroy(l_image);
  447. return 0;
  448. }
  449. w = l_image->x1 - l_image->x0;
  450. h = l_image->y1 - l_image->y0;
  451. step_x = w > nsteps ? w / nsteps : 1;
  452. step_y = h > nsteps ? h / nsteps : 1;
  453. for (y = 0; y < h; y += step_y) {
  454. for (x = 0; x < w; x += step_x) {
  455. da_x0 = (OPJ_INT32)(l_image->x0 + x);
  456. da_y0 = (OPJ_INT32)(l_image->y0 + y);
  457. da_x1 = (OPJ_INT32)opj_uint_min(l_image->x1, l_image->x0 + x + 1);
  458. da_y1 = (OPJ_INT32)opj_uint_min(l_image->y1, l_image->y0 + y + 1);
  459. l_sub_image = decode(quiet, input_file, da_x0, da_y0, da_x1, da_y1,
  460. NULL, NULL, NULL, NULL);
  461. if (!l_sub_image) {
  462. fprintf(stderr, "decode failed for %d,%d,%d,%d\n",
  463. da_x0, da_y0, da_x1, da_y1);
  464. opj_image_destroy(l_sub_image);
  465. opj_image_destroy(l_image);
  466. return 1;
  467. }
  468. if (!check_consistency(l_image, l_sub_image)) {
  469. fprintf(stderr, "Consistency checked failed for %d,%d,%d,%d\n",
  470. da_x0, da_y0, da_x1, da_y1);
  471. opj_image_destroy(l_sub_image);
  472. opj_image_destroy(l_image);
  473. return 1;
  474. }
  475. opj_image_destroy(l_sub_image);
  476. if (step_x > 1 || step_y > 1) {
  477. if (step_x > 1) {
  478. da_x0 = (OPJ_INT32)opj_uint_min(l_image->x1, (OPJ_UINT32)da_x0 + 1);
  479. da_x1 = (OPJ_INT32)opj_uint_min(l_image->x1, (OPJ_UINT32)da_x1 + 1);
  480. }
  481. if (step_y > 1) {
  482. da_y0 = (OPJ_INT32)opj_uint_min(l_image->y1, (OPJ_UINT32)da_y0 + 1);
  483. da_y1 = (OPJ_INT32)opj_uint_min(l_image->y1, (OPJ_UINT32)da_y1 + 1);
  484. }
  485. if (da_x0 < (OPJ_INT32)l_image->x1 && da_y0 < (OPJ_INT32)l_image->y1) {
  486. l_sub_image = decode(quiet, input_file, da_x0, da_y0, da_x1, da_y1,
  487. NULL, NULL, NULL, NULL);
  488. if (!l_sub_image) {
  489. fprintf(stderr, "decode failed for %d,%d,%d,%d\n",
  490. da_x0, da_y0, da_x1, da_y1);
  491. opj_image_destroy(l_sub_image);
  492. opj_image_destroy(l_image);
  493. return 1;
  494. }
  495. if (!check_consistency(l_image, l_sub_image)) {
  496. fprintf(stderr, "Consistency checked failed for %d,%d,%d,%d\n",
  497. da_x0, da_y0, da_x1, da_y1);
  498. opj_image_destroy(l_sub_image);
  499. opj_image_destroy(l_image);
  500. return 1;
  501. }
  502. opj_image_destroy(l_sub_image);
  503. }
  504. }
  505. }
  506. }
  507. opj_image_destroy(l_image);
  508. return 0;
  509. }