-#ifndef NO_PACKETS_DECODING
- opj_tcd_t *tcd = tcd_create(j2k->cinfo);
- tcd_malloc_decode(tcd, j2k->image, j2k->cp);
- for (i = 0; i < j2k->cp->tileno_size; i++) {
- tileno = j2k->cp->tileno[i];
- tcd_decode_tile(tcd, j2k->tile_data[tileno], j2k->tile_len[tileno], tileno);
- opj_free(j2k->tile_data[tileno]);
- j2k->tile_data[tileno] = NULL;
- }
- tcd_free_decode(tcd);
- tcd_destroy(tcd);
-#else
- for (i = 0; i < j2k->cp->tileno_size; i++) {
- tileno = j2k->cp->tileno[i];
- opj_free(j2k->tile_data[tileno]);
- j2k->tile_data[tileno] = NULL;
+ /* if packets should be decoded */
+ if (j2k->cp->limit_decoding != DECODE_ALL_BUT_PACKETS) {
+ opj_tcd_t *tcd = tcd_create(j2k->cinfo);
+ tcd_malloc_decode(tcd, j2k->image, j2k->cp);
+ for (i = 0; i < j2k->cp->tileno_size; i++) {
+ tileno = j2k->cp->tileno[i];
+ tcd_decode_tile(tcd, j2k->tile_data[tileno], j2k->tile_len[tileno], tileno);
+ opj_free(j2k->tile_data[tileno]);
+ j2k->tile_data[tileno] = NULL;
+ }
+ tcd_free_decode(tcd);
+ tcd_destroy(tcd);
+ }
+ /* if packets should not be decoded */
+ else {
+ for (i = 0; i < j2k->cp->tileno_size; i++) {
+ tileno = j2k->cp->tileno[i];
+ opj_free(j2k->tile_data[tileno]);
+ j2k->tile_data[tileno] = NULL;
+ }