shithub: jbig2

Download patch

ref: f4a16df4d230a900f2068a268103184da90097e4
parent: a6820e140bc4b306fb7852ae4994bf6d38f2a906
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Wed Jul 3 15:54:43 EDT 2002

checkpoint compositor development


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

--- a/jbig2_image.c
+++ b/jbig2_image.c
@@ -8,7 +8,7 @@
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
-    $Id: jbig2_image.c,v 1.12 2002/07/03 19:43:21 giles Exp $
+    $Id: jbig2_image.c,v 1.13 2002/07/03 19:54:43 giles Exp $
 */
 
 #include <stdio.h>
@@ -75,9 +75,10 @@
     }
 
     /* clip */
-    // FIXME: this isn't sufficient
     w = src->width;
     h = src->height;
+    ss = src->data;
+    // FIXME: this isn't sufficient for the < 0 cases
     if (x < 0) { w += x; x = 0; }
     if (y < 0) { h += y; y = 0; } 
     w = (x + w < dst->width) ? w : dst->width - x;
@@ -93,7 +94,6 @@
         return 0;
     }
 
-    /* general OR case */
     leftbyte = x >> 3;
     leftbits = x & 7;
     rightbyte = (x + w) >> 3;
@@ -101,8 +101,9 @@
     fprintf(stderr, "left byte:bits %d:%d right byte:bits %d:%d\n",
         leftbyte, leftbits, rightbyte, rightbits);
 
-    s = ss = src->data;
-    d = dd = dst->data + y*dst->stride + leftbyte;    
+    /* general OR case */    
+    d = ss;
+    d = dd = dst->data + y*dst->stride + leftbyte;
     if (leftbyte == rightbyte) {
         mask = (1 << (w & 7)) - 1;
         for (j = 0; j < h; j++) {
@@ -112,6 +113,7 @@
         }
     } else {
         mask = 1 << (8 - leftbits) - 1;
+        highmask = (1 << rightbits) - 1;
         for (j = 0; j < h; j++) {
             *d++ |= (*s & mask) << leftbits;
             for(i = leftbyte; i < rightbyte; i++) {
@@ -118,7 +120,8 @@
                 *d |= (*s++ & ~mask) >> leftbits;
                 *d++ |= (*s & mask) << leftbits;
             }
-            *d |= (*++s & highmask) << (8 - rightbits);
+            *d |= (*s++ & ~mask) >> leftbits;
+            *d |= (*s & highmask) << leftbits;
             d = (dd += dst->stride);
             s = (ss += src->stride);
         }