shithub: jbig2

Download patch

ref: 4d4275d7db3676184bca4d9da8f843d27f0952f9
parent: f22c99da50fac552a8ca9df8ab5f9c9d12a9b752
author: Sebastian Rasmussen <sebras@gmail.com>
date: Tue Apr 24 21:57:52 EDT 2018

jbig2dec: Let symbol refinement Y offset use its own huffman table.

Previously both the symbol instances refinement X and Y offset reused
the same table SBHUFFRDX, but according to 6.4.11.3 and 6.4.11.4 in
the specification they ought to be using the independent SBHUFFRDX
and SBHUFFRDY tables. Let's make it so.

--- a/jbig2_symbol_dict.c
+++ b/jbig2_symbol_dict.c
@@ -240,6 +240,7 @@
     Jbig2WordStream *ws = NULL;
     Jbig2HuffmanState *hs = NULL;
     Jbig2HuffmanTable *SDHUFFRDX = NULL;
+    Jbig2HuffmanTable *SDHUFFRDY = NULL;
     Jbig2HuffmanTable *SBHUFFRSIZE = NULL;
     Jbig2ArithState *as = NULL;
     Jbig2ArithIntCtx *IADH = NULL;
@@ -296,8 +297,9 @@
         jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number, "huffman coded symbol dictionary");
         hs = jbig2_huffman_new(ctx, ws);
         SDHUFFRDX = jbig2_build_huffman_table(ctx, &jbig2_huffman_params_O);
+        SDHUFFRDY = jbig2_build_huffman_table(ctx, &jbig2_huffman_params_O);
         SBHUFFRSIZE = jbig2_build_huffman_table(ctx, &jbig2_huffman_params_A);
-        if (hs == NULL || SDHUFFRDX == NULL || SBHUFFRSIZE == NULL) {
+        if (hs == NULL || SDHUFFRDX == NULL || SDHUFFRDY == NULL || SBHUFFRSIZE == NULL) {
             jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate storage for symbol bitmap");
             goto cleanup2;
         }
@@ -557,7 +559,7 @@
                         if (params->SDHUFF) {
                             ID = jbig2_huffman_get_bits(hs, SBSYMCODELEN, &code1);
                             RDX = jbig2_huffman_get(hs, SDHUFFRDX, &code2);
-                            RDY = jbig2_huffman_get(hs, SDHUFFRDX, &code3);
+                            RDY = jbig2_huffman_get(hs, SDHUFFRDY, &code3);
                             BMSIZE = jbig2_huffman_get(hs, SBHUFFRSIZE, &code4);
                             code5 = jbig2_huffman_skip(hs);
                         } else {
@@ -858,6 +860,7 @@
     if (params->SDHUFF && !params->SDREFAGG) {
         jbig2_free(ctx->allocator, SDNEWSYMWIDTHS);
     }
+    jbig2_release_huffman_table(ctx, SDHUFFRDY);
     jbig2_release_huffman_table(ctx, SDHUFFRDX);
     jbig2_release_huffman_table(ctx, SBHUFFRSIZE);
     jbig2_huffman_free(ctx, hs);