[trunk] WIP: add output elements about decoding of jp2 files with last tile part...
[openjpeg.git] / libopenjpeg / mqc.c
index e26cd80be686e84f756194c48ba2b326f6147df5..14129fbf4e5970bfb3b9d3dbf2594aadeb59eac7 100644 (file)
@@ -521,22 +521,21 @@ void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
                unsigned int c;
                unsigned int *ip;
                unsigned char *end = mqc->end - 1;
-               mqc->buffer = opj_realloc(mqc->buffer, (2 * len + 1) * sizeof(unsigned int));
+               mqc->buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(unsigned int));
                ip = (unsigned int *) mqc->buffer;
 
-               while (bp != end) {
+               while (bp < end) {
                        c = *(bp + 1);
                        if (*bp == 0xff) {
                                if (c > 0x8f) {
-                                       *ip = 0x0000ff18;
+                                       break;
                                } else {
-                                       bp++;
                                        *ip = 0x00000017 | (c << 9);
                                }
                        } else {
-                               bp++;
                                *ip = 0x00000018 | (c << 8);
                        }
+                       bp++;
                        ip++;
                }
 
@@ -560,7 +559,7 @@ void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
        mqc->a = 0x8000;
 }
 
-INLINE int mqc_decode(opj_mqc_t *const mqc) {
+int mqc_decode(opj_mqc_t *const mqc) {
        int d;
        mqc->a -= (*mqc->curctx)->qeval;
        if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {