shithub: jbig2

Download patch

ref: b4c9f4c43bb969875ad842658e269646abaeb96e
parent: 2c22eeab4e9a67bb218cb4e03df9ed9bad3b6647
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Wed Nov 17 14:29:25 EST 2004

Promote the debugging get/set pixel routines to general availability. 
Also, fix a bit order bug: we follow the pbm convention, where MSb is 
leftmost, not rightmost.


git-svn-id: http://svn.ghostscript.com/jbig2dec/trunk@329 ded80894-8fb9-0310-811b-c03f3676ab4d

--- a/jbig2_image.c
+++ b/jbig2_image.c
@@ -167,3 +167,47 @@
             
     return 0;
 }
+
+/* look up a pixel value in an image.
+   returns 0 outside the image frame for the convenience of
+   the template code
+*/
+int jbig2_image_get_pixel(Jbig2Image *image, int x, int y)
+{
+  const int w = image->width;
+  const int h = image->height;
+  const int byte = (x >> 3) + y*image->stride;
+  const int bit = 7 - (x & 7);
+
+  if ((x < 0) || (x > w)) return 0;
+  if ((y < 0) || (y > h)) return 0;
+  
+  return ((image->data[byte]>>bit) & 1);
+}
+
+/* set an individual pixel value in an image */
+int jbig2_image_set_pixel(Jbig2Image *image, int x, int y, bool value)
+{
+  const int w = image->width;
+  const int h = image->height;
+  int i, scratch, mask;
+  int bit, byte;
+
+  if ((x < 0) || (x > w)) return 0;
+  if ((y < 0) || (y > h)) return 0;
+
+  fprintf(stderr, "set pixel called for image 0x%x (%d x %d) stride %d\n",
+    image, w, h, image->stride);
+
+  byte = (x >> 3) + y*image->stride;
+  bit = 7 - (x & 7);
+  mask = (1 << bit) ^ 0xff;
+
+  fprintf(stderr, "set pixel mask for bit %d of byte %d (%d,%d) is 0x%02x\n", 
+    bit, byte, x, y, mask);
+
+  scratch = image->data[byte] & mask;
+  image->data[byte] = scratch | (value << bit);
+
+  return 1;
+}
--- a/jbig2_image.h
+++ b/jbig2_image.h
@@ -13,7 +13,7 @@
     Artifex Software, Inc.,  101 Lucas Valley Road #110,
     San Rafael, CA  94903, U.S.A., +1(415)492-9861.
 
-    $Id: jbig2_image.h,v 1.5 2002/06/18 13:40:29 giles Exp $
+    $Id$
 */
 
 
@@ -32,5 +32,10 @@
 int jbig2_image_write_png_file(Jbig2Image *image, char *filename);
 int jbig2_image_write_png(Jbig2Image *image, FILE *out);
 #endif
+
+int jbig2_image_get_pixel(Jbig2Image *image, int x, int y);
+int jbig2_image_set_pixel(Jbig2Image *image, int x, int y, int value);
+
+
 
 #endif /* _JBIG2_IMAGE_H */
--- a/jbig2_refinement.c
+++ b/jbig2_refinement.c
@@ -38,6 +38,7 @@
 #include "jbig2_arith.h"
 #include "jbig2_generic.h"
 #include "jbig2_mmr.h"
+#include "jbig2_image.h"
 
 static int
 jbig2_decode_refinement_template0(Jbig2Ctx *ctx,
@@ -51,50 +52,6 @@
     "refinement region template 0 NYI");
 }
 
-/* look up a pixel value in an image.
-   returns 0 outside the image frame for the convenience of
-   the template code
-*/
-static int
-jbig2_image_get_pixel(Jbig2Image *image, int x, int y)
-{
-  const int w = image->width;
-  const int h = image->height;
-  const int byte = (x >> 3) + y*image->stride;
-  const int bit = x & 7;
-
-  if ((x < 0) || (x > w)) return 0;
-  if ((y < 0) || (y > h)) return 0;
-  
-  return ((image->data[byte]>>bit) & 1);
-}
-
-static int
-jbig2_image_set_pixel(Jbig2Image *image, int x, int y, bool value)
-{
-  const int w = image->width;
-  const int h = image->height;
-  int i, scratch, mask;
-  int bit, byte;
-
-  if ((x < 0) || (x > w)) return 0;
-  if ((y < 0) || (y > h)) return 0;
-
-  fprintf(stderr, "set pixel called for image 0x%x (%d x %d) stride %d\n",
-    image, w, h, image->stride);
-
-  byte = (x >> 3) + y*image->stride;
-  bit = x & 7;
-  mask = (1 << bit) ^ 0xff;
-
-  fprintf(stderr, "set pixel mask for bit %d of byte %d (%d,%d) is 0x%02x\n", 
-    bit, byte, x, y, mask);
-
-  scratch = image->data[byte] & mask;
-  image->data[byte] = scratch | (value << bit);
-
-  return 1;
-}
 
 static int
 jbig2_decode_refinement_template1_unopt(Jbig2Ctx *ctx,