shithub: jbig2

Download patch

ref: 652011d10a8d33b92bd81b933261e3cdabd09256
parent: 438be64652d4921ce6ef38b204ab3a8e993ea052
author: Sebastian Rasmussen <sebras@gmail.com>
date: Fri Jun 1 06:36:53 EDT 2018

jbig2dec: Rename jbig2_image_clone() to jbig2_image_reference().

This more accurately explains what the function does, and
mirrors jbig2_image_release() quite well.

--- a/jbig2_image.c
+++ b/jbig2_image.c
@@ -75,9 +75,9 @@
     return image;
 }
 
-/* clone an image pointer by bumping its reference count */
+/* bump the reference count for an image pointer */
 Jbig2Image *
-jbig2_image_clone(Jbig2Ctx *ctx, Jbig2Image *image)
+jbig2_image_reference(Jbig2Ctx *ctx, Jbig2Image *image)
 {
     if (image)
         image->refcount++;
--- a/jbig2_image.h
+++ b/jbig2_image.h
@@ -30,7 +30,7 @@
 
 Jbig2Image *jbig2_image_new(Jbig2Ctx *ctx, uint32_t width, uint32_t height);
 void jbig2_image_release(Jbig2Ctx *ctx, Jbig2Image *image);
-Jbig2Image *jbig2_image_clone(Jbig2Ctx *ctx, Jbig2Image *image);
+Jbig2Image *jbig2_image_reference(Jbig2Ctx *ctx, Jbig2Image *image);
 void jbig2_image_free(Jbig2Ctx *ctx, Jbig2Image *image);
 void jbig2_image_clear(Jbig2Ctx *ctx, Jbig2Image *image, int value);
 Jbig2Image *jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, uint32_t width, uint32_t height);
--- a/jbig2_page.c
+++ b/jbig2_page.c
@@ -311,7 +311,7 @@
             ctx->pages[index].state = JBIG2_PAGE_RETURNED;
             if (img != NULL) {
                 jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "page %d returned to the client", page_number);
-                return jbig2_image_clone(ctx, img);
+                return jbig2_image_reference(ctx, img);
             } else {
                 jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "page %d returned with no associated image", page_number);
                 ;               /* continue */
--- a/jbig2_refinement.c
+++ b/jbig2_refinement.c
@@ -451,17 +451,17 @@
         /* the reference bitmap is the result of a previous
            intermediate region segment; the reference selection
            rules say to use the first one available, and not to
-           reuse any intermediate result, so we simply clone it
-           and free the original to keep track of this. */
-        params.reference = jbig2_image_clone(ctx, (Jbig2Image *) ref->result);
+           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);
         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);
     } else {
         /* the reference is just (a subset of) the page buffer */
-        params.reference = jbig2_image_clone(ctx, ctx->pages[ctx->current_page].image);
+        params.reference = jbig2_image_reference(ctx, ctx->pages[ctx->current_page].image);
         if (params.reference == NULL)
-            return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "could not clone reference bitmap");
+            return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "could not take reference to reference bitmap");
         /* TODO: subset the image if appropriate */
     }
 
@@ -510,7 +510,7 @@
 
         if ((segment->flags & 63) == 40) {
             /* intermediate region. save the result for later */
-            segment->result = jbig2_image_clone(ctx, image);
+            segment->result = jbig2_image_reference(ctx, image);
         } else {
             /* immediate region. composite onto the page */
             jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
--- a/jbig2_symbol_dict.c
+++ b/jbig2_symbol_dict.c
@@ -206,13 +206,13 @@
     for (i = 0; i < n_dicts; i++)
         symbols += dicts[i]->n_symbols;
 
-    /* fill a new array with cloned glyph pointers */
+    /* fill a new array with new references to glyph pointers */
     new_dict = jbig2_sd_new(ctx, symbols);
     if (new_dict != NULL) {
         k = 0;
         for (i = 0; i < n_dicts; i++)
             for (j = 0; j < dicts[i]->n_symbols; j++)
-                new_dict->glyphs[k++] = jbig2_image_clone(ctx, dicts[i]->glyphs[j]);
+                new_dict->glyphs[k++] = jbig2_image_reference(ctx, dicts[i]->glyphs[j]);
     } else {
         jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to allocate new symbol dictionary");
     }
@@ -461,7 +461,7 @@
                                 goto cleanup4;
                             }
                             for (i = 0; i < params->SDNUMINSYMS; i++) {
-                                refagg_dicts[0]->glyphs[i] = jbig2_image_clone(ctx, params->SDINSYMS->glyphs[i]);
+                                refagg_dicts[0]->glyphs[i] = jbig2_image_reference(ctx, params->SDINSYMS->glyphs[i]);
                             }
 
                             tparams = jbig2_new(ctx, Jbig2TextRegionParams, 1);
@@ -535,7 +535,7 @@
                         }
 
                         SDNEWSYMS->glyphs[NSYMSDECODED] = image;
-                        refagg_dicts[0]->glyphs[params->SDNUMINSYMS + NSYMSDECODED] = jbig2_image_clone(ctx, SDNEWSYMS->glyphs[NSYMSDECODED]);
+                        refagg_dicts[0]->glyphs[params->SDNUMINSYMS + NSYMSDECODED] = jbig2_image_reference(ctx, SDNEWSYMS->glyphs[NSYMSDECODED]);
                     } else {
                         /* 6.5.8.2.2 */
                         /* bool SBHUFF = params->SDHUFF; */
@@ -784,7 +784,7 @@
             for (k = 0; k < exrunlength; k++) {
                 if (exflag) {
                     SDEXSYMS->glyphs[j++] = (i < params->SDNUMINSYMS) ?
-                                            jbig2_image_clone(ctx, params->SDINSYMS->glyphs[i]) : jbig2_image_clone(ctx, SDNEWSYMS->glyphs[i - params->SDNUMINSYMS]);
+                                            jbig2_image_reference(ctx, params->SDINSYMS->glyphs[i]) : jbig2_image_reference(ctx, SDNEWSYMS->glyphs[i - params->SDNUMINSYMS]);
                 }
                 i++;
             }
--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -316,7 +316,7 @@
                 index = 0;
                 while (id >= dicts[index]->n_symbols)
                     id -= dicts[index++]->n_symbols;
-                IB = jbig2_image_clone(ctx, dicts[index]->glyphs[id]);
+                IB = jbig2_image_reference(ctx, dicts[index]->glyphs[id]);
                 /* SumatraPDF: fail on missing glyphs */
                 if (!IB) {
                     code = jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "missing glyph %d/%d", index, id);
@@ -905,7 +905,7 @@
 
     if ((segment->flags & 63) == 4) {
         /* we have an intermediate region here. save it for later */
-        segment->result = jbig2_image_clone(ctx, image);
+        segment->result = jbig2_image_reference(ctx, image);
     } else {
         /* otherwise composite onto the page */
         jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,