shithub: jbig2

Download patch

ref: 7ea64ae21664e0752401a53dfda9b601691275a5
parent: 36db5a62d5a170ef91c9e7f0805c71c5af5593ca
author: Sebastian Rasmussen <sebras@gmail.com>
date: Mon Apr 23 23:48:35 EDT 2018

jbig2dec: When extending image use default page color.

--- a/jbig2_image.c
+++ b/jbig2_image.c
@@ -107,7 +107,7 @@
 
 /* resize a Jbig2Image */
 Jbig2Image *
-jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, uint32_t width, uint32_t height)
+jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, uint32_t width, uint32_t height, int value)
 {
     if (width == image->width) {
         /* check for integer multiplication overflow */
@@ -124,7 +124,8 @@
             return NULL;
         }
         if (height > image->height) {
-            memset(image->data + image->height * image->stride, 0, (height - image->height) * image->stride);
+            const uint8_t fill = value ? 0xFF : 0x00;
+            memset(image->data + image->height * image->stride, fill, (height - image->height) * image->stride);
         }
         image->height = height;
 
--- a/jbig2_image.h
+++ b/jbig2_image.h
@@ -33,7 +33,7 @@
 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);
+Jbig2Image *jbig2_image_resize(Jbig2Ctx *ctx, Jbig2Image *image, uint32_t width, uint32_t height, int value);
 int jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int y, Jbig2ComposeOp op);
 
 int jbig2_image_get_pixel(Jbig2Image *image, int x, int y);
--- a/jbig2_page.c
+++ b/jbig2_page.c
@@ -270,7 +270,7 @@
             Jbig2Image *resized_image = NULL;
 
             jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, -1, "growing page buffer to %d rows to accommodate new stripe", new_height);
-            resized_image = jbig2_image_resize(ctx, page->image, page->image->width, new_height);
+            resized_image = jbig2_image_resize(ctx, page->image, page->image->width, new_height, page->flags & 4);
             if (resized_image == NULL) {
                 return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, -1, "unable to resize image to accommodate new stripe");
             }