about summary refs log tree commit diff
path: root/converter/other/jbig/libjbig/jbig_ar.c
diff options
context:
space:
mode:
Diffstat (limited to 'converter/other/jbig/libjbig/jbig_ar.c')
-rw-r--r--converter/other/jbig/libjbig/jbig_ar.c138
1 files changed, 73 insertions, 65 deletions
diff --git a/converter/other/jbig/libjbig/jbig_ar.c b/converter/other/jbig/libjbig/jbig_ar.c
index d23a317d..aad293f2 100644
--- a/converter/other/jbig/libjbig/jbig_ar.c
+++ b/converter/other/jbig/libjbig/jbig_ar.c
@@ -22,7 +22,7 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- * 
+ *
  *  If you want to use this program under different license conditions,
  *  then contact the author for an arrangement.
  */
@@ -106,7 +106,7 @@ static unsigned char nlpstab[113] = {
 void arith_encode_init(struct jbg_arenc_state *s, int reuse_st)
 {
   int i;
-  
+
   if (!reuse_st)
     for (i = 0; i < 4096; s->st[i++] = 0) ;
   s->c = 0;
@@ -114,11 +114,12 @@ void arith_encode_init(struct jbg_arenc_state *s, int reuse_st)
   s->sc = 0;
   s->ct = 11;
   s->buffer = -1;    /* empty */
-  
+
   return;
 }
 
 
+
 void arith_encode_flush(struct jbg_arenc_state *s)
 {
   unsigned long temp;
@@ -136,15 +137,15 @@ void arith_encode_flush(struct jbg_arenc_state *s)
     if (s->buffer >= 0) {
       s->byte_out(s->buffer + 1, s->file);
       if (s->buffer + 1 == MARKER_ESC)
-	s->byte_out(MARKER_STUFF, s->file);
+        s->byte_out(MARKER_STUFF, s->file);
     }
     /* output 0x00 bytes only when more non-0x00 will follow */
     if (s->c & 0x7fff800L)
       for (; s->sc; --s->sc)
-	s->byte_out(0x00, s->file);
+        s->byte_out(0x00, s->file);
   } else {
     if (s->buffer >= 0)
-      s->byte_out(s->buffer, s->file); 
+      s->byte_out(s->buffer, s->file);
     /* T.82 figure 30 says buffer+1 for the above line! Typo? */
     for (; s->sc; --s->sc) {
       s->byte_out(0xff, s->file);
@@ -159,7 +160,7 @@ void arith_encode_flush(struct jbg_arenc_state *s)
     if (s->c & 0x7f800L) {
       s->byte_out((s->c >> 11) & 0xff, s->file);
       if (((s->c >> 11) & 0xff) == MARKER_ESC)
-	s->byte_out(MARKER_STUFF, s->file);
+        s->byte_out(MARKER_STUFF, s->file);
     }
   }
 
@@ -167,7 +168,8 @@ void arith_encode_flush(struct jbg_arenc_state *s)
 }
 
 
-void arith_encode(struct jbg_arenc_state *s, int cx, int pix) 
+
+void arith_encode(struct jbg_arenc_state *s, int cx, int pix)
 {
   register unsigned lsz, ss;
   register unsigned char *st;
@@ -181,9 +183,9 @@ void arith_encode(struct jbg_arenc_state *s, int cx, int pix)
 
 #if 0
   fprintf(stderr, "pix = %d, cx = %d, mps = %d, st = %3d, lsz = 0x%04x, "
-	  "a = 0x%05lx, c = 0x%08lx, ct = %2d, buf = 0x%02x\n",
-	  pix, cx, !!(s->st[cx] & 0x80), ss, lsz, s->a, s->c, s->ct,
-	  s->buffer);
+          "a = 0x%05lx, c = 0x%08lx, ct = %2d, buf = 0x%02x\n",
+          pix, cx, !!(s->st[cx] & 0x80), ss, lsz, s->a, s->c, s->ct,
+          s->buffer);
 #endif
 
   if (((pix << 7) ^ s->st[cx]) & 0x80) {
@@ -225,44 +227,45 @@ void arith_encode(struct jbg_arenc_state *s, int cx, int pix)
       /* another byte is ready for output */
       temp = s->c >> 19;
       if (temp & 0xffffff00L) {
-	/* handle overflow over all buffered 0xff bytes */
-	if (s->buffer >= 0) {
-	  ++s->buffer;
-	  s->byte_out(s->buffer, s->file);
-	  if (s->buffer == MARKER_ESC)
-	    s->byte_out(MARKER_STUFF, s->file);
-	}
-	for (; s->sc; --s->sc)
-	  s->byte_out(0x00, s->file);
-	s->buffer = temp & 0xff;  /* new output byte, might overflow later */
-	assert(s->buffer != 0xff);
-	/* can s->buffer really never become 0xff here? */
+        /* handle overflow over all buffered 0xff bytes */
+        if (s->buffer >= 0) {
+          ++s->buffer;
+          s->byte_out(s->buffer, s->file);
+          if (s->buffer == MARKER_ESC)
+            s->byte_out(MARKER_STUFF, s->file);
+        }
+        for (; s->sc; --s->sc)
+          s->byte_out(0x00, s->file);
+        s->buffer = temp & 0xff;  /* new output byte, might overflow later */
+        assert(s->buffer != 0xff);
+        /* can s->buffer really never become 0xff here? */
       } else if (temp == 0xff) {
-	/* buffer 0xff byte (which might overflow later) */
-	++s->sc;
+        /* buffer 0xff byte (which might overflow later) */
+        ++s->sc;
       } else {
-	/* output all buffered 0xff bytes, they will not overflow any more */
-	if (s->buffer >= 0)
-	  s->byte_out(s->buffer, s->file);
-	for (; s->sc; --s->sc) {
-	  s->byte_out(0xff, s->file);
-	  s->byte_out(MARKER_STUFF, s->file);
-	}
-	s->buffer = temp;   /* buffer new output byte (can still overflow) */
+        /* output all buffered 0xff bytes, they will not overflow any more */
+        if (s->buffer >= 0)
+          s->byte_out(s->buffer, s->file);
+        for (; s->sc; --s->sc) {
+          s->byte_out(0xff, s->file);
+          s->byte_out(MARKER_STUFF, s->file);
+        }
+        s->buffer = temp;   /* buffer new output byte (can still overflow) */
       }
       s->c &= 0x7ffffL;
       s->ct = 8;
     }
   } while (s->a < 0x8000);
- 
+
   return;
 }
 
 
+
 void arith_decode_init(struct jbg_ardec_state *s, int reuse_st)
 {
   int i;
-  
+
   if (!reuse_st)
     for (i = 0; i < 4096; s->st[i++] = 0) ;
   s->c = 0;
@@ -273,6 +276,8 @@ void arith_decode_init(struct jbg_ardec_state *s, int reuse_st)
   return;
 }
 
+
+
 /*
  * Decode and return one symbol from the provided PSCD byte stream
  * that starts in s->pscd_ptr and ends in the byte before s->pscd_end.
@@ -295,7 +300,7 @@ void arith_decode_init(struct jbg_ardec_state *s, int reuse_st)
  *   decoded.
  *
  * s->pscd_ptr == s->pscd_end - 1:
- * 
+ *
  *   The decoder has used up all provided PSCD bytes except for the
  *   very last byte, because that has the value 0xff. The decoder can
  *   at this point not yet tell whether this 0xff belongs to a
@@ -336,27 +341,27 @@ int arith_decode(struct jbg_ardec_state *s, int cx)
     while (s->ct <= 8 && s->ct >= 0) {
       /* first we can move a new byte into s->c */
       if (s->pscd_ptr >= s->pscd_end) {
-	return -1;  /* more bytes needed */
+        return -1;  /* more bytes needed */
       }
-      if (*s->pscd_ptr == 0xff) 
-	if (s->pscd_ptr + 1 >= s->pscd_end) {
-	  return -1; /* final 0xff byte not processed */
-	} else {
-	  if (*(s->pscd_ptr + 1) == MARKER_STUFF) {
-	    s->c |= 0xffL << (8 - s->ct);
-	    s->ct += 8;
-	    s->pscd_ptr += 2;
-	  } else {
-	    s->ct = -1; /* start padding with zero bytes */
-	    if (s->nopadding) {
-	      s->nopadding = 0;
-	      return -2; /* subsequent symbols might depend on zero padding */
-	    }
-	  }
-	}
+      if (*s->pscd_ptr == 0xff)
+        if (s->pscd_ptr + 1 >= s->pscd_end) {
+          return -1; /* final 0xff byte not processed */
+        } else {
+          if (*(s->pscd_ptr + 1) == MARKER_STUFF) {
+            s->c |= 0xffL << (8 - s->ct);
+            s->ct += 8;
+            s->pscd_ptr += 2;
+          } else {
+            s->ct = -1; /* start padding with zero bytes */
+            if (s->nopadding) {
+              s->nopadding = 0;
+              return -2; /* subsequent symbols might depend on zero padding */
+            }
+          }
+        }
       else {
-	s->c |= (long)*(s->pscd_ptr++) << (8 - s->ct);
-	s->ct += 8;
+        s->c |= (long)*(s->pscd_ptr++) << (8 - s->ct);
+        s->ct += 8;
       }
     }
     s->c <<= 1;
@@ -373,8 +378,8 @@ int arith_decode(struct jbg_ardec_state *s, int cx)
 
 #if 0
   fprintf(stderr, "cx = %d, mps = %d, st = %3d, lsz = 0x%04x, a = 0x%05lx, "
-	  "c = 0x%08lx, ct = %2d\n",
-	  cx, !!(s->st[cx] & 0x80), ss, lsz, s->a, s->c, s->ct);
+          "c = 0x%08lx, ct = %2d\n",
+          cx, !!(s->st[cx] & 0x80), ss, lsz, s->a, s->c, s->ct);
 #endif
 
   if ((s->c >> 16) < (s->a -= lsz))
@@ -383,15 +388,15 @@ int arith_decode(struct jbg_ardec_state *s, int cx)
     else {
       /* MPS_EXCHANGE */
       if (s->a < lsz) {
-	pix = 1 - (*st >> 7);
-	/* Check whether MPS/LPS exchange is necessary
-	 * and chose next probability estimator status */
-	*st &= 0x80;
-	*st ^= nlpstab[ss];
+        pix = 1 - (*st >> 7);
+        /* Check whether MPS/LPS exchange is necessary
+         * and chose next probability estimator status */
+        *st &= 0x80;
+        *st ^= nlpstab[ss];
       } else {
-	pix = *st >> 7;
-	*st &= 0x80;
-	*st |= nmpstab[ss];
+        pix = *st >> 7;
+        *st &= 0x80;
+        *st |= nmpstab[ss];
       }
     }
   else {
@@ -415,3 +420,6 @@ int arith_decode(struct jbg_ardec_state *s, int cx)
 
   return pix;
 }
+
+
+