shithub: jbig2

Download patch

ref: 15013a4b69bb42d7268613b6c4ccb69f1a2f7cfe
parent: d34dadbda7d4cf2433f1a0eadb84ba4c963ad324
author: Sebastian Rasmussen <sebras@gmail.com>
date: Tue Apr 24 09:54:47 EDT 2018

jbig2dec: Rename variables to closely follow the specification.

--- a/jbig2_refinement.c
+++ b/jbig2_refinement.c
@@ -52,9 +52,9 @@
 {
     const int GRW = image->width;
     const int GRH = image->height;
-    const int dx = params->DX;
-    const int dy = params->DY;
-    Jbig2Image *ref = params->reference;
+    Jbig2Image *ref = params->GRREFERENCE;
+    const int dx = params->GRREFERENCEDX;
+    const int dy = params->GRREFERENCEDY;
     uint32_t CONTEXT;
     int x, y;
     bool bit;
@@ -115,9 +115,9 @@
 {
     const int GRW = image->width;
     const int GRH = image->height;
-    const int dx = params->DX;
-    const int dy = params->DY;
-    Jbig2Image *ref = params->reference;
+    Jbig2Image *ref = params->GRREFERENCE;
+    const int dx = params->GRREFERENCEDX;
+    const int dy = params->GRREFERENCEDY;
     uint32_t CONTEXT;
     int x, y;
     bool bit;
@@ -242,9 +242,9 @@
 static int
 implicit_value(const Jbig2RefinementRegionParams *params, Jbig2Image *image, int x, int y)
 {
-    Jbig2Image *ref = params->reference;
-    int i = x - params->DX;
-    int j = y - params->DY;
+    Jbig2Image *ref = params->GRREFERENCE;
+    int i = x - params->GRREFERENCEDX;
+    int j = y - params->GRREFERENCEDY;
     int m = jbig2_image_get_pixel(ref, i, j);
 
     return ((jbig2_image_get_pixel(ref, i - 1, j - 1) == m) &&
@@ -261,9 +261,9 @@
 static uint32_t
 mkctx0(const Jbig2RefinementRegionParams *params, Jbig2Image *image, int x, int y)
 {
-    const int dx = params->DX;
-    const int dy = params->DY;
-    Jbig2Image *ref = params->reference;
+    Jbig2Image *ref = params->GRREFERENCE;
+    const int dx = params->GRREFERENCEDX;
+    const int dy = params->GRREFERENCEDY;
     uint32_t CONTEXT;
 
     CONTEXT = jbig2_image_get_pixel(image, x - 1, y + 0);
@@ -285,9 +285,9 @@
 static uint32_t
 mkctx1(const Jbig2RefinementRegionParams *params, Jbig2Image *image, int x, int y)
 {
-    const int dx = params->DX;
-    const int dy = params->DY;
-    Jbig2Image *ref = params->reference;
+    Jbig2Image *ref = params->GRREFERENCE;
+    const int dx = params->GRREFERENCEDX;
+    const int dy = params->GRREFERENCEDY;
     uint32_t CONTEXT;
 
     CONTEXT = jbig2_image_get_pixel(image, x - 1, y + 0);
@@ -370,8 +370,8 @@
                                const Jbig2RefinementRegionParams *params, Jbig2ArithState *as, Jbig2Image *image, Jbig2ArithCx *GR_stats)
 {
     jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
-            "decoding generic refinement region with offset %d,%x, GRTEMPLATE=%d, TPGRON=%d",
-            params->DX, params->DY, params->GRTEMPLATE, params->TPGRON);
+                "decoding generic refinement region with offset %d,%x, GRTEMPLATE=%d, TPGRON=%d",
+                params->GRREFERENCEDX, params->GRREFERENCEDY, params->GRTEMPLATE, params->TPGRON);
 
     if (params->TPGRON)
         return jbig2_decode_refinement_TPGRON(ctx, params, as, image, GR_stats);
@@ -471,7 +471,7 @@
            rules say to use the first one available, and not to
            reuse any intermediate result, so we simply take another
            reference to it and free the original to keep track of this. */
-        params.reference = jbig2_image_reference(ctx, (Jbig2Image *) ref->result);
+        params.GRREFERENCE = jbig2_image_reference(ctx, (Jbig2Image *) ref->result);
         jbig2_image_release(ctx, (Jbig2Image *) ref->result);
         ref->result = NULL;
         jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number, "found reference bitmap in segment %d", ref->number);
@@ -479,13 +479,13 @@
         /* the reference is just (a subset of) the page buffer */
         if (ctx->pages[ctx->current_page].image == NULL)
             return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "reference page bitmap has no decoded image");
-        params.reference = jbig2_image_reference(ctx, ctx->pages[ctx->current_page].image);
+        params.GRREFERENCE = jbig2_image_reference(ctx, ctx->pages[ctx->current_page].image);
         /* TODO: subset the image if appropriate */
     }
 
     /* 7.4.7.5 */
-    params.DX = 0;
-    params.DY = 0;
+    params.GRREFERENCEDX = 0;
+    params.GRREFERENCEDY = 0;
     {
         Jbig2WordStream *ws = NULL;
         Jbig2ArithState *as = NULL;
@@ -542,7 +542,7 @@
 
 cleanup:
         jbig2_image_release(ctx, image);
-        jbig2_image_release(ctx, params.reference);
+        jbig2_image_release(ctx, params.GRREFERENCE);
         jbig2_free(ctx->allocator, as);
         jbig2_word_stream_buf_free(ctx, ws);
         jbig2_free(ctx->allocator, GR_stats);
--- a/jbig2_refinement.h
+++ b/jbig2_refinement.h
@@ -25,8 +25,8 @@
     /* GRW */
     /* GRH */
     bool GRTEMPLATE;
-    Jbig2Image *reference;
-    int32_t DX, DY;
+    Jbig2Image *GRREFERENCE;
+    int32_t GRREFERENCEDX, GRREFERENCEDY;
     bool TPGRON;
     int8_t grat[4];
 } Jbig2RefinementRegionParams;
--- a/jbig2_symbol_dict.c
+++ b/jbig2_symbol_dict.c
@@ -593,15 +593,15 @@
 
                         /* Table 18 */
                         rparams.GRTEMPLATE = params->SDRTEMPLATE;
-                        rparams.reference = (ID < ninsyms) ? params->SDINSYMS->glyphs[ID] : SDNEWSYMS->glyphs[ID - ninsyms];
+                        rparams.GRREFERENCE = (ID < ninsyms) ? params->SDINSYMS->glyphs[ID] : SDNEWSYMS->glyphs[ID - ninsyms];
                         /* SumatraPDF: fail on missing glyphs */
-                        if (rparams.reference == NULL) {
+                        if (rparams.GRREFERENCE == NULL) {
                             code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "missing glyph %d/%d", ID, ninsyms);
                             jbig2_image_release(ctx, image);
                             goto cleanup4;
                         }
-                        rparams.DX = RDX;
-                        rparams.DY = RDY;
+                        rparams.GRREFERENCEDX = RDX;
+                        rparams.GRREFERENCEDY = RDY;
                         rparams.TPGRON = 0;
                         memcpy(rparams.grat, params->sdrat, 4);
                         code = jbig2_decode_refinement_region(ctx, segment, &rparams, as, image, GR_stats);
@@ -777,16 +777,16 @@
         uint32_t k;
         int exflag = 0;
         uint32_t limit = params->SDNUMINSYMS + params->SDNUMNEWSYMS;
-        uint32_t exrunlength;
+        uint32_t EXRUNLENGTH;
         int zerolength = 0;
 
         while (i < limit) {
             if (params->SDHUFF)
-                exrunlength = jbig2_huffman_get(hs, SBHUFFRSIZE, &code);
+                EXRUNLENGTH = jbig2_huffman_get(hs, SBHUFFRSIZE, &code);
             else
-                code = jbig2_arith_int_decode(ctx, IAEX, as, (int32_t *) &exrunlength);
+                code = jbig2_arith_int_decode(ctx, IAEX, as, (int32_t *) &EXRUNLENGTH);
             if (code < 0) {
-                jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode exrunlength for exported symbols");
+                jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode runlength for exported symbols");
                 /* skip to the cleanup code and return SDEXSYMS = NULL */
                 jbig2_sd_release(ctx, SDEXSYMS);
                 SDEXSYMS = NULL;
@@ -801,19 +801,19 @@
             }
 
             /* prevent infinite loop */
-            zerolength = exrunlength > 0 ? 0 : zerolength + 1;
-            if (exrunlength > limit - i || zerolength > 4 || (exflag && (exrunlength + j > params->SDNUMEXSYMS))) {
-                if (exrunlength <= 0)
-                    jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "runlength too small in export symbol table (%d <= 0)", exrunlength);
+            zerolength = EXRUNLENGTH > 0 ? 0 : zerolength + 1;
+            if (EXRUNLENGTH > limit - i || zerolength > 4 || (exflag && (EXRUNLENGTH + j > params->SDNUMEXSYMS))) {
+                if (EXRUNLENGTH <= 0)
+                    jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "runlength too small in export symbol table (%d <= 0)", EXRUNLENGTH);
                 else
                     jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
-                                "runlength too large in export symbol table (%d > %d - %d)", exrunlength, params->SDNUMEXSYMS, j);
+                                "runlength too large in export symbol table (%d > %d - %d)", EXRUNLENGTH, params->SDNUMEXSYMS, j);
                 /* skip to the cleanup code and return SDEXSYMS = NULL */
                 jbig2_sd_release(ctx, SDEXSYMS);
                 SDEXSYMS = NULL;
                 break;
             }
-            for (k = 0; k < exrunlength; k++) {
+            for (k = 0; k < EXRUNLENGTH; k++) {
                 if (exflag) {
                     SDEXSYMS->glyphs[j++] = (i < params->SDNUMINSYMS) ?
                                             jbig2_image_reference(ctx, params->SDINSYMS->glyphs[i]) : jbig2_image_reference(ctx, SDNEWSYMS->glyphs[i - params->SDNUMINSYMS]);
--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -435,9 +435,9 @@
 
                 /* Table 12 */
                 rparams.GRTEMPLATE = params->SBRTEMPLATE;
-                rparams.reference = IBO;
-                rparams.DX = (RDW >> 1) + RDX;
-                rparams.DY = (RDH >> 1) + RDY;
+                rparams.GRREFERENCE = IBO;
+                rparams.GRREFERENCEDX = (RDW >> 1) + RDX;
+                rparams.GRREFERENCEDY = (RDH >> 1) + RDY;
                 rparams.TPGRON = 0;
                 memcpy(rparams.grat, params->sbrat, 4);
                 code = jbig2_decode_refinement_region(ctx, segment, &rparams, as, refimage, GR_stats);