Fixed a bug in JPWL module, which prevented to exploit the full error correction...
authorGiuseppe Baruffa <gbaruffa@users.noreply.github.com>
Thu, 12 Jul 2007 08:31:01 +0000 (08:31 +0000)
committerGiuseppe Baruffa <gbaruffa@users.noreply.github.com>
Thu, 12 Jul 2007 08:31:01 +0000 (08:31 +0000)
ChangeLog
jpwl/jpwl_lib.c
libopenjpeg/openjpeg.h

index c81800daf28fdad8047fbb4754a01931109bce96..b46a1249ceac2c394ec2fd190c23f1c84053f35f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,9 @@ What's New for OpenJPEG
 ! : changed
 + : added
 
+July 12, 2007
+* [GB] fixed a bug in JPWL module, which prevented to exploit the full error correction capability of RS codes (e.g. it gave up at 5 errors, even if 6 were correctable); defined a JPWL_MAXIMUM_EPB_ROOM for better customization of the maximum dimension of EPBs (the dimension is pre-calculated on an hypothesis, if it goes beyond 65535 there will be problems, thus we give a little less than the max, let's say 65450)
+
 July 8, 2007
 * [ANTONIN] fixed the size of the memory allocation in cio.c (confusion between bits and bytes)
 
index 96e6f69dd29de0cbf35d76643e98dfad118800ad..b24aa09f6934387513beba600c4fc210843599b6 100644 (file)
@@ -128,20 +128,20 @@ int jpwl_epbs_add(opj_j2k_t *j2k, jpwl_marker_t *jwmarker, int *jwmarker_num,
        while (post_len > 0) {
 
                /* maximum postlen in order to respect EPB size
-               (we use 65450 instead of 65535 for keeping room for EPB parms)*/
+               (we use JPWL_MAXIMUM_EPB_ROOM instead of 65535 for keeping room for EPB parms)*/
                /*      (message word size)    *            (number of containable parity words)  */
-               max_postlen = k_post * (unsigned long int) floor(65450.0 / (double) (n_post - k_post));
+               max_postlen = k_post * (unsigned long int) floor((double) JPWL_MAXIMUM_EPB_ROOM / (double) (n_post - k_post));
 
                /* maximum postlen in order to respect EPB size */
                if (*idx == 0)
-                       /* (we use (65500 - L2) instead of 65535 for keeping room for EPB parms + pre-data) */
+                       /* (we use (JPWL_MAXIMUM_EPB_ROOM - L2) instead of 65535 for keeping room for EPB parms + pre-data) */
                        /*      (message word size)    *                   (number of containable parity words)  */
-                       max_postlen = k_post * (unsigned long int) floor((double) (65500 - L2) / (double) (n_post - k_post));
+                       max_postlen = k_post * (unsigned long int) floor((double) (JPWL_MAXIMUM_EPB_ROOM - L2) / (double) (n_post - k_post));
 
                else
-                       /* (we use 65500 instead of 65535 for keeping room for EPB parms) */
+                       /* (we use JPWL_MAXIMUM_EPB_ROOM instead of 65535 for keeping room for EPB parms) */
                        /*      (message word size)    *            (number of containable parity words)  */
-                       max_postlen = k_post * (unsigned long int) floor(65500.0 / (double) (n_post - k_post));
+                       max_postlen = k_post * (unsigned long int) floor((double) JPWL_MAXIMUM_EPB_ROOM / (double) (n_post - k_post));
 
                /* length to use */
                dL4 = min(max_postlen, post_len);
@@ -793,7 +793,7 @@ bool jpwl_epb_correct(opj_j2k_t *j2k, unsigned char *buffer, int type, int pre_l
        /* Initialize RS structures */
        P = n_pre - k_pre;
        NN_P = NN - P;
-       tt = (int) floor((float) P / 2.0F);
+       tt = (int) floor((float) P / 2.0F); /* correction capability of the code */
        memset(codeword, 0, NN);
        parityword = codeword + NN_P;
        init_rs(NN_P);
@@ -834,7 +834,8 @@ bool jpwl_epb_correct(opj_j2k_t *j2k, unsigned char *buffer, int type, int pre_l
                        /*if (conn == NULL)
                                opj_event_msg(j2k->cinfo, EVT_INFO, "codeword is correctly decoded\n");*/
 
-               } else if (status < tt) {
+               } else if (status <= tt) {
+                       /* it has corrected 0 <= errs <= tt */
                        /*if (conn == NULL)
                                opj_event_msg(j2k->cinfo, EVT_WARNING, "%d errors corrected in codeword\n", status);*/
                        errnum += status;
@@ -848,21 +849,21 @@ bool jpwl_epb_correct(opj_j2k_t *j2k, unsigned char *buffer, int type, int pre_l
 
 
                /* advance parity buffer */
-               if ((status >= 0) && (status < tt))
+               if ((status >= 0) && (status <= tt))
                        /* copy back corrected parity only if all is OK */
                        memcpy(L2_buf, parityword, P);
                L2_buf += P;
 
                /* advance message buffer */
                if (remaining < k_pre) {
-                       if ((status >= 0) && (status < tt))
+                       if ((status >= 0) && (status <= tt))
                                /* copy back corrected data only if all is OK */
                                memcpy(L1_buf, codeword, remaining);
                        L1_buf += remaining;
                        remaining = 0;
 
                } else {
-                       if ((status >= 0) && (status < tt))
+                       if ((status >= 0) && (status <= tt))
                                /* copy back corrected data only if all is OK */
                                memcpy(L1_buf, codeword, k_pre);
                        L1_buf += k_pre;
@@ -1043,7 +1044,7 @@ bool jpwl_epb_correct(opj_j2k_t *j2k, unsigned char *buffer, int type, int pre_l
                /* Initialize RS structures */
                P = n_post - k_post;
                NN_P = NN - P;
-               tt = (int) floor((float) P / 2.0F);
+               tt = (int) floor((float) P / 2.0F); /* again, correction capability */
                memset(codeword, 0, NN);
                parityword = codeword + NN_P;
                init_rs(NN_P);
@@ -1080,7 +1081,7 @@ bool jpwl_epb_correct(opj_j2k_t *j2k, unsigned char *buffer, int type, int pre_l
                                /*if (conn == NULL)
                                        opj_event_msg(j2k->cinfo, EVT_INFO, "codeword is correctly decoded\n");*/
 
-                       } else if (status < tt) {
+                       } else if (status <= tt) {
                                /*if (conn == NULL)
                                        opj_event_msg(j2k->cinfo, EVT_WARNING, "%d errors corrected in codeword\n", status);*/
                                errnum += status;
@@ -1094,21 +1095,21 @@ bool jpwl_epb_correct(opj_j2k_t *j2k, unsigned char *buffer, int type, int pre_l
 
 
                        /* advance parity buffer */
-                       if ((status >= 0) && (status < tt))
+                       if ((status >= 0) && (status <= tt))
                                /* copy back corrected data only if all is OK */
                                memcpy(L3_buf, parityword, P);
                        L3_buf += P;
 
                        /* advance message buffer */
                        if (remaining < k_post) {
-                               if ((status >= 0) && (status < tt))
+                               if ((status >= 0) && (status <= tt))
                                        /* copy back corrected data only if all is OK */
                                        memcpy(L4_buf, codeword, remaining);
                                L4_buf += remaining;
                                remaining = 0;
 
                        } else {
-                               if ((status >= 0) && (status < tt))
+                               if ((status >= 0) && (status <= tt))
                                        /* copy back corrected data only if all is OK */
                                        memcpy(L4_buf, codeword, k_post);
                                L4_buf += k_post;
index e74c90ee3cbbe7d7fac5eccec4c2365944f1aff4..c3d765e4f780df7d5175de1de0c429e6abb0a946 100644 (file)
@@ -104,6 +104,7 @@ braindamage below.
 #define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
 #define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
 #define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
+#define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
 /* <<UniPG */
 
 /*