[jbig2-cvs] rev 329 - trunk

giles at ghostscript.com giles at ghostscript.com
Wed Nov 17 11:29:26 PST 2004


Author: giles
Date: 2004-11-17 11:29:25 -0800 (Wed, 17 Nov 2004)
New Revision: 329

Modified:
   trunk/jbig2_image.c
   trunk/jbig2_image.h
   trunk/jbig2_refinement.c
Log:
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.


Modified: trunk/jbig2_image.c
===================================================================
--- trunk/jbig2_image.c	2004-10-22 22:28:07 UTC (rev 328)
+++ trunk/jbig2_image.c	2004-11-17 19:29:25 UTC (rev 329)
@@ -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;
+}

Modified: trunk/jbig2_image.h
===================================================================
--- trunk/jbig2_image.h	2004-10-22 22:28:07 UTC (rev 328)
+++ trunk/jbig2_image.h	2004-11-17 19:29:25 UTC (rev 329)
@@ -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$
 */
 
 
@@ -33,4 +33,9 @@
 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 */

Modified: trunk/jbig2_refinement.c
===================================================================
--- trunk/jbig2_refinement.c	2004-10-22 22:28:07 UTC (rev 328)
+++ trunk/jbig2_refinement.c	2004-11-17 19:29:25 UTC (rev 329)
@@ -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,52 +52,8 @@
     "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,
                               Jbig2Segment *segment,
                               const Jbig2RefinementRegionParams *params,



More information about the jbig2-cvs mailing list