[trunk] Add debug info to track issue 80
[openjpeg.git] / src / lib / openjp2 / t2.c
index a819b8325a64a5d0e13d84c6ff6ccec7aa15a81b..dd5f9cc34627224921bbca927e512da28f492c85 100644 (file)
@@ -441,7 +441,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
 
         /* don't forget to release pi */
         opj_pi_destroy(l_pi,l_nb_pocs);
-        assert( l_current_data - p_src <  UINT32_MAX );
+        assert( (OPJ_INT64)(l_current_data - p_src) < (OPJ_INT64)UINT32_MAX );
         *p_data_read = (OPJ_UINT32)(l_current_data - p_src);
         return OPJ_TRUE;
 }
@@ -573,8 +573,7 @@ OPJ_BOOL opj_t2_encode_packet(  OPJ_UINT32 tileno,
                                 cblk = &prc->cblks.enc[cblkno];
 
                                 cblk->numpasses = 0;
-                                assert(band->numbps>=0);
-                                opj_tgt_setvalue(prc->imsbtree, cblkno, (OPJ_INT32)((OPJ_UINT32)band->numbps - cblk->numbps));
+                                opj_tgt_setvalue(prc->imsbtree, cblkno, band->numbps - (OPJ_INT32)cblk->numbps);
                         }
                         ++band;
                 }
@@ -640,7 +639,8 @@ OPJ_BOOL opj_t2_encode_packet(  OPJ_UINT32 tileno,
                                 len += pass->len;
 
                                 if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) {
-                                        increment = opj_int_max(increment, opj_int_floorlog2(len) + 1 - (cblk->numlenbits + opj_int_floorlog2(nump)));
+                                  increment = (OPJ_UINT32)opj_int_max((OPJ_INT32)increment, opj_int_floorlog2((OPJ_INT32)len) + 1
+                                    - ((OPJ_INT32)cblk->numlenbits + opj_int_floorlog2((OPJ_INT32)nump)));
                                         len = 0;
                                         nump = 0;
                                 }
@@ -659,7 +659,7 @@ OPJ_BOOL opj_t2_encode_packet(  OPJ_UINT32 tileno,
                                 len += pass->len;
 
                                 if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) {
-                                        opj_bio_write(bio, len, cblk->numlenbits + (OPJ_UINT32)opj_int_floorlog2((OPJ_INT32)nump));
+                                        opj_bio_write(bio, (OPJ_UINT32)len, cblk->numlenbits + (OPJ_UINT32)opj_int_floorlog2((OPJ_INT32)nump));
                                         len = 0;
                                         nump = 0;
                                 }
@@ -896,7 +896,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
                         if (p_max_length < 2) {
                                 fprintf(stderr, "Not enough space for expected EPH marker\n");
                         } else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
-                                printf("Error : expected EPH marker\n");
+                                fprintf(stderr, "Error : expected EPH marker\n");
                         } else {
                                 l_header_data += 2;
                         }
@@ -958,7 +958,6 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
                                         ++i;
                                 }
 
-                                assert(l_band->numbps >= 0);
                                 l_cblk->numbps = (OPJ_UINT32)l_band->numbps + 1 - i;
                                 l_cblk->numlenbits = 3;
                         }
@@ -1225,6 +1224,8 @@ OPJ_BOOL opj_t2_skip_packet_data(   opj_t2_t* p_t2,
 
                         do {
                                 if (* p_data_read + l_seg->newlen > p_max_length) {
+                                        fprintf(stderr, "segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
+                                                l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
                                         return OPJ_FALSE;
                                 }