about summary refs log tree commit diff
path: root/converter/other/jbig
diff options
context:
space:
mode:
Diffstat (limited to 'converter/other/jbig')
-rw-r--r--converter/other/jbig/jbigtopnm.c1
-rw-r--r--converter/other/jbig/libjbig/include/jbig.h54
-rw-r--r--converter/other/jbig/libjbig/include/jbig_ar.h6
-rw-r--r--converter/other/jbig/libjbig/jbig.c1812
-rw-r--r--converter/other/jbig/libjbig/jbig_ar.c138
-rw-r--r--converter/other/jbig/pnmtojbig.c46
6 files changed, 1055 insertions, 1002 deletions
diff --git a/converter/other/jbig/jbigtopnm.c b/converter/other/jbig/jbigtopnm.c
index 0d55ccc1..69767e11 100644
--- a/converter/other/jbig/jbigtopnm.c
+++ b/converter/other/jbig/jbigtopnm.c
@@ -198,6 +198,7 @@ diagnose_bie(FILE *f)
 }
 
 
+
 int main (int argc, const char **argv)
 {
     CmdlineInfo cmdline;
diff --git a/converter/other/jbig/libjbig/include/jbig.h b/converter/other/jbig/libjbig/include/jbig.h
index 67994107..3c991b08 100644
--- a/converter/other/jbig/libjbig/include/jbig.h
+++ b/converter/other/jbig/libjbig/include/jbig.h
@@ -39,7 +39,7 @@ struct jbg_buf {
   int len;                             /* length of the data in this block */
   struct jbg_buf *next;                           /* pointer to next block */
   struct jbg_buf *previous;                   /* pointer to previous block *
-					       * (unused in freelist)      */
+                                               * (unused in freelist)      */
   struct jbg_buf *last;     /* only used in list head: final block of list */
   struct jbg_buf **free_list;   /* pointer to pointer to head of free list */
 };
@@ -70,12 +70,12 @@ struct jbg_buf {
 /* encoding options that will not be indicated in the header */
 
 #define JBG_DELAY_AT   0x100  /* Delay ATMOVE until the first line of the next
-			       * stripe. Option available for compatibility
-			       * with conformance test example in clause 7.2. */
+                               * stripe. Option available for compatibility
+                               * with conformance test example in clause 7.2. */
 
 #define JBG_SDRST      0x200  /* Use SDRST instead of SDNORM. This option is
-			       * there for anyone who needs to generate
-			       * test data that covers the SDRST cases. */
+                               * there for anyone who needs to generate
+                               * test data that covers the SDRST cases. */
 
 /*
  * Possible error code return values
@@ -115,7 +115,7 @@ struct jbg_enc_state {
   char *dppriv;         /* optional private deterministic prediction table */
   char *res_tab;           /* table for the resolution reduction algorithm */
   struct jbg_buf ****sde;      /* array [stripe][layer][plane] pointers to *
-				* buffers for stored SDEs                  */
+                                * buffers for stored SDEs                  */
   struct jbg_arenc_state *s;  /* array [planes] for arithm. encoder status */
   struct jbg_buf *free_list; /* list of currently unused SDE block buffers */
   void (*data_out)(unsigned char *start, size_t len, void *file);
@@ -140,7 +140,7 @@ struct jbg_dec_state {
   unsigned long xd, yd;     /* size of the full image (resolution layer d) */
   int planes;                         /* number of different bitmap planes */
   unsigned long l0;                /* number of lines per stripe at lowest *
-				    * resolution layer 0                   */
+                                    * resolution layer 0                   */
   unsigned long stripes;    /* number of stripes required  (determ. by l0) */
   int order;                                    /* SDE ordering parameters */
   int options;                                      /* encoding parameters */
@@ -152,34 +152,34 @@ struct jbg_dec_state {
 
   /*
    * Pointers to array [planes] of lower/higher resolution images.
-   * lhp[d & 1] contains image of layer d. 
+   * lhp[d & 1] contains image of layer d.
    */
   unsigned char **lhp[2];
 
   /* status information */
   int **tx, **ty;   /* array [plane][layer-dl] with x,y-offset of AT pixel */
   struct jbg_ardec_state **s;    /* array [plane][layer-dl] for arithmetic *
-				  * decoder status */
+                                  * decoder status */
   int **reset;     /* array [plane][layer-dl] remembers if previous stripe *
-		    * in that plane/resolution ended with SDRST.           */
+                    * in that plane/resolution ended with SDRST.           */
   unsigned long bie_len;                    /* number of bytes read so far */
   unsigned char buffer[20]; /* used to store BIH or marker segments fragm. */
   int buf_len;                                /* number of bytes in buffer */
   unsigned long comment_skip;      /* remaining bytes of a COMMENT segment */
   unsigned long x;              /* x position of next pixel in current SDE */
-  unsigned long i; /* line in current SDE (first line of each stripe is 0) */ 
+  unsigned long i; /* line in current SDE (first line of each stripe is 0) */
   int at_moves;                /* number of AT moves in the current stripe */
   unsigned long at_line[JBG_ATMOVES_MAX];           /* lines at which an   *
-					             * AT move will happen */
+                                                     * AT move will happen */
   int at_tx[JBG_ATMOVES_MAX], at_ty[JBG_ATMOVES_MAX]; /* ATMOVE offsets in *
-						       * current stripe    */
+                                                       * current stripe    */
   unsigned long line_h1, line_h2, line_h3;     /* variables of decode_pscd */
   unsigned long line_l1, line_l2, line_l3;
   int pseudo;         /* flag for TPBON/TPDON:  next pixel is pseudo pixel */
   int **lntp;        /* flag [plane][layer-dl] for TP: line is not typical */
 
   unsigned long xmax, ymax;         /* if possible abort before image gets *
-				     * larger than this size */
+                                     * larger than this size */
   int dmax;                                      /* abort after this layer */
 };
 
@@ -192,31 +192,31 @@ struct jbg_dec_state {
 /* function prototypes */
 
 void jbg_enc_init(struct jbg_enc_state *s, unsigned long x, unsigned long y,
-		  int planes, unsigned char **p,
-		  void (*data_out)(unsigned char *start, size_t len,
-				   void *file),
-		  void *file);
+                  int planes, unsigned char **p,
+                  void (*data_out)(unsigned char *start, size_t len,
+                                   void *file),
+                  void *file);
 int jbg_enc_lrlmax(struct jbg_enc_state *s, unsigned long mwidth,
-		   unsigned long mheight);
+                   unsigned long mheight);
 void jbg_enc_layers(struct jbg_enc_state *s, int d);
 int  jbg_enc_lrange(struct jbg_enc_state *s, int dl, int dh);
 void jbg_enc_options(struct jbg_enc_state *s, int order, int options,
-		     unsigned long l0, int mx, int my);
+                     unsigned long l0, int mx, int my);
 void jbg_enc_out(struct jbg_enc_state *s);
 void jbg_enc_free(struct jbg_enc_state *s);
 
 void jbg_dec_init(struct jbg_dec_state *s);
 void jbg_dec_maxsize(struct jbg_dec_state *s, unsigned long xmax,
-		     unsigned long ymax);
+                     unsigned long ymax);
 int  jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len,
-		size_t *cnt);
+                size_t *cnt);
 unsigned long jbg_dec_getwidth(const struct jbg_dec_state *s);
 unsigned long jbg_dec_getheight(const struct jbg_dec_state *s);
 unsigned char *jbg_dec_getimage(const struct jbg_dec_state *s, int plane);
 unsigned long jbg_dec_getsize(const struct jbg_dec_state *s);
 void jbg_dec_merge_planes(const struct jbg_dec_state *s, int use_graycode,
-			  void (*data_out)(unsigned char *start, size_t len,
-					   void *file), void *file);
+                          void (*data_out)(unsigned char *start, size_t len,
+                                           void *file), void *file);
 unsigned long jbg_dec_getsize_merged(const struct jbg_dec_state *s);
 void jbg_dec_free(struct jbg_dec_state *s);
 
@@ -225,9 +225,9 @@ void jbg_int2dppriv(unsigned char *dptable, const char *internal);
 void jbg_dppriv2int(char *internal, const unsigned char *dptable);
 unsigned long jbg_ceil_half(unsigned long x, int n);
 void jbg_split_planes(unsigned long x, unsigned long y, int has_planes,
-		      int encode_planes,
-		      const unsigned char *src, unsigned char **dest,
-		      int use_graycode);
+                      int encode_planes,
+                      const unsigned char *src, unsigned char **dest,
+                      int use_graycode);
 int jbg_newlen(unsigned char *bie, size_t len);
 
 #endif /* JBG_H */
diff --git a/converter/other/jbig/libjbig/include/jbig_ar.h b/converter/other/jbig/libjbig/include/jbig_ar.h
index ed5f2f86..e3366aed 100644
--- a/converter/other/jbig/libjbig/include/jbig_ar.h
+++ b/converter/other/jbig/libjbig/include/jbig_ar.h
@@ -39,9 +39,9 @@ struct jbg_ardec_state {
               * special value -1 signals that zero-padding has started     */
   int startup;          /* boolean flag that controls initial fill of s->c */
   int nopadding;        /* boolean flag that triggers return -2 between
-			 * reaching PSCD end and decoding the first symbol
-			 * that might never have been encoded in the first
-			 * place */
+                         * reaching PSCD end and decoding the first symbol
+                         * that might never have been encoded in the first
+                         * place */
 };
 
 void arith_encode_init(struct jbg_arenc_state *s, int reuse_st);
diff --git a/converter/other/jbig/libjbig/jbig.c b/converter/other/jbig/libjbig/jbig.c
index cf24a93b..fcb39f5c 100644
--- a/converter/other/jbig/libjbig/jbig.c
+++ b/converter/other/jbig/libjbig/jbig.c
@@ -143,13 +143,14 @@ static void *checked_malloc(size_t nmemb, size_t size)
 
 #if 0
   fprintf(stderr, "%p = malloc(%lu * %lu)\n", p,
-	  (unsigned long) nmemb, (unsigned long) size);
+          (unsigned long) nmemb, (unsigned long) size);
 #endif
 
   return p;
 }
 
 
+
 static void *checked_realloc(void *ptr, size_t nmemb, size_t size)
 {
   void *p;
@@ -169,13 +170,14 @@ static void *checked_realloc(void *ptr, size_t nmemb, size_t size)
 
 #if 0
   fprintf(stderr, "%p = realloc(%p, %lu * %lu)\n", p, ptr,
-	  (unsigned long) nmemb, (unsigned long) size);
+          (unsigned long) nmemb, (unsigned long) size);
 #endif
 
   return p;
 }
 
 
+
 static void checked_free(void *ptr)
 {
   free(ptr);
@@ -188,7 +190,6 @@ static void checked_free(void *ptr)
 
 
 
-
 /*
  * Memory management for buffers which are used for temporarily
  * storing SDEs by the encoder.
@@ -229,6 +230,7 @@ static struct jbg_buf *jbg_buf_init(struct jbg_buf **free_list)
 }
 
 
+
 /*
  * Return an entire free_list to the memory management of stdlib.
  * This is only done by jbg_enc_free().
@@ -247,6 +249,7 @@ static void jbg_buf_free(struct jbg_buf **free_list)
 }
 
 
+
 /*
  * Append a single byte to a single list that starts with the block
  * *(struct jbg_buf *) head. The type of *head is void here in order to
@@ -272,6 +275,7 @@ static void jbg_buf_write(int b, void *head)
 }
 
 
+
 /*
  * Remove any trailing zero bytes from the end of a linked jbg_buf list,
  * however make sure that no zero byte is removed which directly
@@ -311,6 +315,7 @@ static void jbg_buf_remove_zeros(struct jbg_buf *head)
 }
 
 
+
 /*
  * The jbg_buf list which starts with block *new_prefix is concatenated
  * with the list which starts with block **start and *start will then point
@@ -327,6 +332,7 @@ static void jbg_buf_prefix(struct jbg_buf *new_prefix, struct jbg_buf **start)
 }
 
 
+
 /*
  * Send the contents of a jbg_buf list that starts with block **head to
  * the call back function data_out and return the blocks of the jbg_buf
@@ -334,9 +340,9 @@ static void jbg_buf_prefix(struct jbg_buf *new_prefix, struct jbg_buf **start)
  * After the call, *head == NULL.
  */
 static void jbg_buf_output(struct jbg_buf **head,
-			void (*data_out)(unsigned char *start,
-					 size_t len, void *file),
-			void *file)
+                        void (*data_out)(unsigned char *start,
+                                         size_t len, void *file),
+                        void *file)
 {
   struct jbg_buf *tmp;
 
@@ -352,6 +358,7 @@ static void jbg_buf_output(struct jbg_buf **head,
 }
 
 
+
 /*
  * Calculate y = ceil(x/2) applied n times, which is equivalent to
  * y = ceil(x/(2^n)). This function is used to
@@ -369,6 +376,7 @@ unsigned long jbg_ceil_half(unsigned long x, int n)
 }
 
 
+
 /*
  * Set L0 (the number of lines in a stripe at lowest resolution)
  * to a default value, such that there are about 35 stripes, as
@@ -384,11 +392,12 @@ static void jbg_set_default_l0(struct jbg_enc_state *s)
 }
 
 
+
 /*
  * Calculate the number of stripes, as defined in clause 6.2.3 of T.82.
  */
 static unsigned long jbg_stripes(unsigned long l0, unsigned long yd,
-			  unsigned long d)
+                          unsigned long d)
 {
   unsigned long y0 = jbg_ceil_half(yd, d);
 
@@ -396,6 +405,7 @@ static unsigned long jbg_stripes(unsigned long l0, unsigned long yd,
 }
 
 
+
 /*
  * Resolution reduction table given by ITU-T T.82 Table 17
  */
@@ -767,8 +777,8 @@ static char jbg_dptable[256 + 512 + 2048 + 4096] = {
 void jbg_enc_init(struct jbg_enc_state *s, unsigned long x, unsigned long y,
                   int planes, unsigned char **p,
                   void (*data_out)(unsigned char *start, size_t len,
-				   void *file),
-		  void *file)
+                                   void *file),
+                  void *file)
 {
   unsigned long l, lx;
   int i;
@@ -818,6 +828,7 @@ void jbg_enc_init(struct jbg_enc_state *s, unsigned long x, unsigned long y,
 }
 
 
+
 /*
  * This function selects the number of differential layers based on
  * the maximum size requested for the lowest resolution layer. If
@@ -831,7 +842,7 @@ void jbg_enc_init(struct jbg_enc_state *s, unsigned long x, unsigned long y,
  * is returned.
  */
 int jbg_enc_lrlmax(struct jbg_enc_state *s, unsigned long x,
-		   unsigned long y)
+                   unsigned long y)
 {
   for (s->d = 0; s->d < 6; s->d++)
     if (jbg_ceil_half(s->xd, s->d) <= x && jbg_ceil_half(s->yd, s->d) <= y)
@@ -843,6 +854,7 @@ int jbg_enc_lrlmax(struct jbg_enc_state *s, unsigned long x,
 }
 
 
+
 /*
  * As an alternative to jbg_enc_lrlmax(), the following function allows the
  * user to specify the number of layers directly. The stripe height and layer
@@ -860,6 +872,7 @@ void jbg_enc_layers(struct jbg_enc_state *s, int d)
 }
 
 
+
 /*
  * Specify the highest and lowest resolution layers which will be
  * written to the output file. Call this function not before
@@ -876,13 +889,14 @@ int jbg_enc_lrange(struct jbg_enc_state *s, int dl, int dh)
 }
 
 
+
 /*
  * The following function allows the user to specify the bits describing the
  * options of the format as well as the maximum AT movement window and the
  * number of layer 0 lines per stripes.
  */
 void jbg_enc_options(struct jbg_enc_state *s, int order, int options,
-		     unsigned long l0, int mx, int my)
+                     unsigned long l0, int mx, int my)
 {
   if (order >= 0 && order <= 0x0f) s->order = order;
   if (options >= 0) s->options = options;
@@ -894,13 +908,14 @@ void jbg_enc_options(struct jbg_enc_state *s, int order, int options,
 }
 
 
+
 /*
  * This function actually does all the tricky work involved in producing
  * a SDE, which is stored in the appropriate s->sde[][][] element
  * for later output in the correct order.
  */
 static void encode_sde(struct jbg_enc_state *s,
-		       long stripe, int layer, int plane)
+                       long stripe, int layer, int plane)
 {
   unsigned char *hp, *lp1, *lp2, *p0, *p1, *q1, *q2;
   unsigned long hl, ll, hx, hy, lx, ly, hbpl, lbpl;
@@ -933,7 +948,7 @@ static void encode_sde(struct jbg_enc_state *s,
   if (stripe == 0)
     tp_lines = tp_exceptions = tp_pixels = dp_pixels = encoded_pixels = 0;
   fprintf(stderr, "encode_sde: s/d/p = %2ld/%2d/%2d\n",
-	  stripe, layer, plane);
+          stripe, layer, plane);
 #endif
 
   /* number of lines per stripe in highres image */
@@ -1001,59 +1016,59 @@ static void encode_sde(struct jbg_enc_state *s,
 
       /* check whether it is worth to perform an ATMOVE */
       if (!at_determined && c_all > 2048) {
-	cmin = clmin = 0xffffffffL;
-	cmax = clmax = 0;
-	tmax = 0;
-	for (t = (s->options & JBG_LRLTWO) ? 5 : 3; t <= s->mx; t++) {
-	  if (c[t] > cmax) cmax = c[t];
-	  if (c[t] < cmin) cmin = c[t];
-	  if (c[t] > c[tmax]) tmax = t;
-	}
-	clmin = (c[0] < cmin) ? c[0] : cmin;
-	clmax = (c[0] > cmax) ? c[0] : cmax;
-	if (c_all - cmax < (c_all >> 3) &&
-	    cmax - c[s->tx[plane]] > c_all - cmax &&
-	    cmax - c[s->tx[plane]] > (c_all >> 4) &&
-	    /*                     ^ T.82 said < here, fixed in Cor.1/25 */
-	    cmax - (c_all - c[s->tx[plane]]) > c_all - cmax &&
-	    cmax - (c_all - c[s->tx[plane]]) > (c_all >> 4) &&
-	    cmax - cmin > (c_all >> 2) &&
-	    (s->tx[plane] || clmax - clmin > (c_all >> 3))) {
-	  /* we have decided to perform an ATMOVE */
-	  new_tx = tmax;
-	  if (!(s->options & JBG_DELAY_AT)) {
-	    new_tx_line = i;
-	    s->tx[plane] = new_tx;
-	  }
+        cmin = clmin = 0xffffffffL;
+        cmax = clmax = 0;
+        tmax = 0;
+        for (t = (s->options & JBG_LRLTWO) ? 5 : 3; t <= s->mx; t++) {
+          if (c[t] > cmax) cmax = c[t];
+          if (c[t] < cmin) cmin = c[t];
+          if (c[t] > c[tmax]) tmax = t;
+        }
+        clmin = (c[0] < cmin) ? c[0] : cmin;
+        clmax = (c[0] > cmax) ? c[0] : cmax;
+        if (c_all - cmax < (c_all >> 3) &&
+            cmax - c[s->tx[plane]] > c_all - cmax &&
+            cmax - c[s->tx[plane]] > (c_all >> 4) &&
+            /*                     ^ T.82 said < here, fixed in Cor.1/25 */
+            cmax - (c_all - c[s->tx[plane]]) > c_all - cmax &&
+            cmax - (c_all - c[s->tx[plane]]) > (c_all >> 4) &&
+            cmax - cmin > (c_all >> 2) &&
+            (s->tx[plane] || clmax - clmin > (c_all >> 3))) {
+          /* we have decided to perform an ATMOVE */
+          new_tx = tmax;
+          if (!(s->options & JBG_DELAY_AT)) {
+            new_tx_line = i;
+            s->tx[plane] = new_tx;
+          }
 #ifdef DEBUG
-	  fprintf(stderr, "ATMOVE: line=%ld, tx=%d, c_all=%ld\n",
-		  i, new_tx, c_all);
+          fprintf(stderr, "ATMOVE: line=%ld, tx=%d, c_all=%ld\n",
+                  i, new_tx, c_all);
 #endif
-	}
-	at_determined = 1;
+        }
+        at_determined = 1;
       }
       assert(s->tx[plane] >= 0); /* i.e., tx can safely be cast to unsigned */
 
       /* typical prediction */
       if (s->options & JBG_TPBON) {
-	ltp = 1;
-	p1 = hp;
-	if (i > 0 || !reset) {
-	  q1 = hp - hbpl;
-	  while (q1 < hp && (ltp = (*p1++ == *q1++)) != 0) ;
-	} else
-	  while (p1 < hp + hbpl && (ltp = (*p1++ == 0)) != 0) ;
-	arith_encode(se, (s->options & JBG_LRLTWO) ? TPB2CX : TPB3CX,
-		     ltp == ltp_old);
+        ltp = 1;
+        p1 = hp;
+        if (i > 0 || !reset) {
+          q1 = hp - hbpl;
+          while (q1 < hp && (ltp = (*p1++ == *q1++)) != 0) ;
+        } else
+          while (p1 < hp + hbpl && (ltp = (*p1++ == 0)) != 0) ;
+        arith_encode(se, (s->options & JBG_LRLTWO) ? TPB2CX : TPB3CX,
+                     ltp == ltp_old);
 #ifdef DEBUG
-	tp_lines += ltp;
+        tp_lines += ltp;
 #endif
-	ltp_old = ltp;
-	if (ltp) {
-	  /* skip next line */
-	  hp += hbpl;
-	  continue;
-	}
+        ltp_old = ltp;
+        if (ltp) {
+          /* skip next line */
+          hp += hbpl;
+          continue;
+        }
       }
 
       /*
@@ -1071,102 +1086,102 @@ static void encode_sde(struct jbg_enc_state *s,
 
       /* encode line */
       for (j = 0; j < hx; hp++) {
-	line_h1 |= *hp;
-	if (j < hbpl * 8 - 8 && (i > 0 || !reset)) {
-	  line_h2 |= *(hp - hbpl + 1);
-	  if (i > 1 || !reset)
-	    line_h3 |= *(hp - hbpl - hbpl + 1);
-	}
-	if (s->options & JBG_LRLTWO) {
-	  /* two line template */
-	  do {
-	    line_h1 <<= 1;  line_h2 <<= 1;  line_h3 <<= 1;
-	    if (s->tx[plane]) {
-	      if ((unsigned) s->tx[plane] > j)
-		a = 0;
-	      else {
-		o = (j - s->tx[plane]) - (j & ~7L);
-		a = (hp[o >> 3] >> (7 - (o & 7))) & 1;
-		a <<= 4;
-	      }
-	      assert(s->tx[plane] > 23 ||
-		     a == ((line_h1 >> (4 + s->tx[plane])) & 0x010));
-	      arith_encode(se, (((line_h2 >> 10) & 0x3e0) | a |
-				((line_h1 >>  9) & 0x00f)),
-			   (line_h1 >> 8) & 1);
-	    }
-	    else
-	      arith_encode(se, (((line_h2 >> 10) & 0x3f0) |
-				((line_h1 >>  9) & 0x00f)),
-			   (line_h1 >> 8) & 1);
+        line_h1 |= *hp;
+        if (j < hbpl * 8 - 8 && (i > 0 || !reset)) {
+          line_h2 |= *(hp - hbpl + 1);
+          if (i > 1 || !reset)
+            line_h3 |= *(hp - hbpl - hbpl + 1);
+        }
+        if (s->options & JBG_LRLTWO) {
+          /* two line template */
+          do {
+            line_h1 <<= 1;  line_h2 <<= 1;  line_h3 <<= 1;
+            if (s->tx[plane]) {
+              if ((unsigned) s->tx[plane] > j)
+                a = 0;
+              else {
+                o = (j - s->tx[plane]) - (j & ~7L);
+                a = (hp[o >> 3] >> (7 - (o & 7))) & 1;
+                a <<= 4;
+              }
+              assert(s->tx[plane] > 23 ||
+                     a == ((line_h1 >> (4 + s->tx[plane])) & 0x010));
+              arith_encode(se, (((line_h2 >> 10) & 0x3e0) | a |
+                                ((line_h1 >>  9) & 0x00f)),
+                           (line_h1 >> 8) & 1);
+            }
+            else
+              arith_encode(se, (((line_h2 >> 10) & 0x3f0) |
+                                ((line_h1 >>  9) & 0x00f)),
+                           (line_h1 >> 8) & 1);
 #ifdef DEBUG
-	    encoded_pixels++;
+            encoded_pixels++;
 #endif
-	    /* statistics for adaptive template changes */
-	    if (!at_determined && j >= s->mx && j < hx-2) {
-	      p = (line_h1 & 0x100) != 0; /* current pixel value */
-	      c[0] += ((line_h2 & 0x4000) != 0) == p; /* default position */
-	      assert((!(((line_h2 >> 6) ^ line_h1) & 0x100)) ==
-		     (((line_h2 & 0x4000) != 0) == p));
-	      for (t = 5; t <= s->mx && t <= j; t++) {
-		o = (j - t) - (j & ~7L);
-		a = (hp[o >> 3] >> (7 - (o & 7))) & 1;
-		assert(t > 23 ||
-		       (a == p) == !(((line_h1 >> t) ^ line_h1) & 0x100));
-		c[t] += a == p;
-	      }
-	      for (; t <= s->mx; t++) {
-		c[t] += 0 == p;
-	      }
-	      ++c_all;
-	    }
-	  } while (++j & 7 && j < hx);
-	} else {
-	  /* three line template */
-	  do {
-	    line_h1 <<= 1;  line_h2 <<= 1;  line_h3 <<= 1;
-	    if (s->tx[plane]) {
-	      if ((unsigned) s->tx[plane] > j)
-		a = 0;
-	      else {
-		o = (j - s->tx[plane]) - (j & ~7L);
-		a = (hp[o >> 3] >> (7 - (o & 7))) & 1;
-		a <<= 2;
-	      }
-	      assert(s->tx[plane] > 23 ||
-		     a == ((line_h1 >> (6 + s->tx[plane])) & 0x004));
-	      arith_encode(se, (((line_h3 >>  8) & 0x380) |
-				((line_h2 >> 12) & 0x078) | a |
-				((line_h1 >>  9) & 0x003)),
-			   (line_h1 >> 8) & 1);
-	    } else
-	      arith_encode(se, (((line_h3 >>  8) & 0x380) |
-				((line_h2 >> 12) & 0x07c) |
-				((line_h1 >>  9) & 0x003)),
-			   (line_h1 >> 8) & 1);
+            /* statistics for adaptive template changes */
+            if (!at_determined && j >= s->mx && j < hx-2) {
+              p = (line_h1 & 0x100) != 0; /* current pixel value */
+              c[0] += ((line_h2 & 0x4000) != 0) == p; /* default position */
+              assert((!(((line_h2 >> 6) ^ line_h1) & 0x100)) ==
+                     (((line_h2 & 0x4000) != 0) == p));
+              for (t = 5; t <= s->mx && t <= j; t++) {
+                o = (j - t) - (j & ~7L);
+                a = (hp[o >> 3] >> (7 - (o & 7))) & 1;
+                assert(t > 23 ||
+                       (a == p) == !(((line_h1 >> t) ^ line_h1) & 0x100));
+                c[t] += a == p;
+              }
+              for (; t <= s->mx; t++) {
+                c[t] += 0 == p;
+              }
+              ++c_all;
+            }
+          } while (++j & 7 && j < hx);
+        } else {
+          /* three line template */
+          do {
+            line_h1 <<= 1;  line_h2 <<= 1;  line_h3 <<= 1;
+            if (s->tx[plane]) {
+              if ((unsigned) s->tx[plane] > j)
+                a = 0;
+              else {
+                o = (j - s->tx[plane]) - (j & ~7L);
+                a = (hp[o >> 3] >> (7 - (o & 7))) & 1;
+                a <<= 2;
+              }
+              assert(s->tx[plane] > 23 ||
+                     a == ((line_h1 >> (6 + s->tx[plane])) & 0x004));
+              arith_encode(se, (((line_h3 >>  8) & 0x380) |
+                                ((line_h2 >> 12) & 0x078) | a |
+                                ((line_h1 >>  9) & 0x003)),
+                           (line_h1 >> 8) & 1);
+            } else
+              arith_encode(se, (((line_h3 >>  8) & 0x380) |
+                                ((line_h2 >> 12) & 0x07c) |
+                                ((line_h1 >>  9) & 0x003)),
+                           (line_h1 >> 8) & 1);
 #ifdef DEBUG
-	    encoded_pixels++;
+            encoded_pixels++;
 #endif
-	    /* statistics for adaptive template changes */
-	    if (!at_determined && j >= s->mx && j < hx-2) {
-	      p = (line_h1 & 0x100) != 0; /* current pixel value */
-	      c[0] += ((line_h2 & 0x4000) != 0) == p; /* default position */
-	      assert((!(((line_h2 >> 6) ^ line_h1) & 0x100)) ==
-		     (((line_h2 & 0x4000) != 0) == p));
-	      for (t = 3; t <= s->mx && t <= j; t++) {
-		o = (j - t) - (j & ~7L);
-		a = (hp[o >> 3] >> (7 - (o & 7))) & 1;
-		assert(t > 23 ||
-		       (a == p) == !(((line_h1 >> t) ^ line_h1) & 0x100));
-		c[t] += a == p;
-	      }
-	      for (; t <= s->mx; t++) {
-		c[t] += 0 == p;
-	      }
-	      ++c_all;
-	    }
-	  } while (++j & 7 && j < hx);
-	} /* if (s->options & JBG_LRLTWO) */
+            /* statistics for adaptive template changes */
+            if (!at_determined && j >= s->mx && j < hx-2) {
+              p = (line_h1 & 0x100) != 0; /* current pixel value */
+              c[0] += ((line_h2 & 0x4000) != 0) == p; /* default position */
+              assert((!(((line_h2 >> 6) ^ line_h1) & 0x100)) ==
+                     (((line_h2 & 0x4000) != 0) == p));
+              for (t = 3; t <= s->mx && t <= j; t++) {
+                o = (j - t) - (j & ~7L);
+                a = (hp[o >> 3] >> (7 - (o & 7))) & 1;
+                assert(t > 23 ||
+                       (a == p) == !(((line_h1 >> t) ^ line_h1) & 0x100));
+                c[t] += a == p;
+              }
+              for (; t <= s->mx; t++) {
+                c[t] += 0 == p;
+              }
+              ++c_all;
+            }
+          } while (++j & 7 && j < hx);
+        } /* if (s->options & JBG_LRLTWO) */
       } /* for (j = ...) */
     } /* for (i = ...) */
 
@@ -1180,101 +1195,101 @@ static void encode_sde(struct jbg_enc_state *s,
 
       /* check whether it is worth to perform an ATMOVE */
       if (!at_determined && c_all > 2048) {
-	cmin = clmin = 0xffffffffL;
-	cmax = clmax = 0;
-	tmax = 0;
-	for (t = 3; t <= s->mx; t++) {
-	  if (c[t] > cmax) cmax = c[t];
-	  if (c[t] < cmin) cmin = c[t];
-	  if (c[t] > c[tmax]) tmax = t;
-	}
-	clmin = (c[0] < cmin) ? c[0] : cmin;
-	clmax = (c[0] > cmax) ? c[0] : cmax;
-	if (c_all - cmax < (c_all >> 3) &&
-	    cmax - c[s->tx[plane]] > c_all - cmax &&
-	    cmax - c[s->tx[plane]] > (c_all >> 4) &&
-	    /*                     ^ T.82 said < here, fixed in Cor.1/25 */
-	    cmax - (c_all - c[s->tx[plane]]) > c_all - cmax &&
-	    cmax - (c_all - c[s->tx[plane]]) > (c_all >> 4) &&
-	    cmax - cmin > (c_all >> 2) &&
-	    (s->tx[plane] || clmax - clmin > (c_all >> 3))) {
-	  /* we have decided to perform an ATMOVE */
-	  new_tx = tmax;
-	  if (!(s->options & JBG_DELAY_AT)) {
-	    new_tx_line = i;
-	    s->tx[plane] = new_tx;
-	  }
+        cmin = clmin = 0xffffffffL;
+        cmax = clmax = 0;
+        tmax = 0;
+        for (t = 3; t <= s->mx; t++) {
+          if (c[t] > cmax) cmax = c[t];
+          if (c[t] < cmin) cmin = c[t];
+          if (c[t] > c[tmax]) tmax = t;
+        }
+        clmin = (c[0] < cmin) ? c[0] : cmin;
+        clmax = (c[0] > cmax) ? c[0] : cmax;
+        if (c_all - cmax < (c_all >> 3) &&
+            cmax - c[s->tx[plane]] > c_all - cmax &&
+            cmax - c[s->tx[plane]] > (c_all >> 4) &&
+            /*                     ^ T.82 said < here, fixed in Cor.1/25 */
+            cmax - (c_all - c[s->tx[plane]]) > c_all - cmax &&
+            cmax - (c_all - c[s->tx[plane]]) > (c_all >> 4) &&
+            cmax - cmin > (c_all >> 2) &&
+            (s->tx[plane] || clmax - clmin > (c_all >> 3))) {
+          /* we have decided to perform an ATMOVE */
+          new_tx = tmax;
+          if (!(s->options & JBG_DELAY_AT)) {
+            new_tx_line = i;
+            s->tx[plane] = new_tx;
+          }
 #ifdef DEBUG
-	  fprintf(stderr, "ATMOVE: line=%ld, tx=%d, c_all=%ld\n",
-		  i, new_tx, c_all);
+          fprintf(stderr, "ATMOVE: line=%ld, tx=%d, c_all=%ld\n",
+                  i, new_tx, c_all);
 #endif
-	}
-	at_determined = 1;
+        }
+        at_determined = 1;
       }
 
       if ((i >> 1) >= ll - 1 || (y >> 1) >= ly - 1)
-	lp1 = lp2;
+        lp1 = lp2;
 
       /* typical prediction */
       if (s->options & JBG_TPDON && (i & 1) == 0) {
-	q1 = lp1; q2 = lp2;
-	p0 = p1 = hp;
-	if (i < hl - 1 && y < hy - 1)
-	  p0 = hp + hbpl;
-	if (i > 1 || !reset)
-	  line_l3 = (long)*(q2 - lbpl) << 8;
-	else
-	  line_l3 = 0;
-	line_l2 = (long)*q2 << 8;
-	line_l1 = (long)*q1 << 8;
-	ltp = 1;
-	for (j = 0; j < lx && ltp; q1++, q2++) {
-	  if (j < lbpl * 8 - 8) {
-	    if (i > 1 || !reset)
-	      line_l3 |= *(q2 - lbpl + 1);
-	    line_l2 |= *(q2 + 1);
-	    line_l1 |= *(q1 + 1);
-	  }
-	  do {
-	    if ((j >> 2) < hbpl) {
-	      line_h1 = *(p1++);
-	      line_h0 = *(p0++);
-	    }
-	    do {
-	      line_l3 <<= 1;
-	      line_l2 <<= 1;
-	      line_l1 <<= 1;
-	      line_h1 <<= 2;
-	      line_h0 <<= 2;
-	      cx = (((line_l3 >> 15) & 0x007) |
-		    ((line_l2 >> 12) & 0x038) |
-		    ((line_l1 >> 9)  & 0x1c0));
-	      if (cx == 0x000)
-		if ((line_h1 & 0x300) == 0 && (line_h0 & 0x300) == 0)
-		  s->tp[j] = 0;
-		else {
-		  ltp = 0;
+        q1 = lp1; q2 = lp2;
+        p0 = p1 = hp;
+        if (i < hl - 1 && y < hy - 1)
+          p0 = hp + hbpl;
+        if (i > 1 || !reset)
+          line_l3 = (long)*(q2 - lbpl) << 8;
+        else
+          line_l3 = 0;
+        line_l2 = (long)*q2 << 8;
+        line_l1 = (long)*q1 << 8;
+        ltp = 1;
+        for (j = 0; j < lx && ltp; q1++, q2++) {
+          if (j < lbpl * 8 - 8) {
+            if (i > 1 || !reset)
+              line_l3 |= *(q2 - lbpl + 1);
+            line_l2 |= *(q2 + 1);
+            line_l1 |= *(q1 + 1);
+          }
+          do {
+            if ((j >> 2) < hbpl) {
+              line_h1 = *(p1++);
+              line_h0 = *(p0++);
+            }
+            do {
+              line_l3 <<= 1;
+              line_l2 <<= 1;
+              line_l1 <<= 1;
+              line_h1 <<= 2;
+              line_h0 <<= 2;
+              cx = (((line_l3 >> 15) & 0x007) |
+                    ((line_l2 >> 12) & 0x038) |
+                    ((line_l1 >> 9)  & 0x1c0));
+              if (cx == 0x000)
+                if ((line_h1 & 0x300) == 0 && (line_h0 & 0x300) == 0)
+                  s->tp[j] = 0;
+                else {
+                  ltp = 0;
 #ifdef DEBUG
-		  tp_exceptions++;
+                  tp_exceptions++;
 #endif
-		}
-	      else if (cx == 0x1ff)
-		if ((line_h1 & 0x300) == 0x300 && (line_h0 & 0x300) == 0x300)
-		  s->tp[j] = 1;
-		else {
-		  ltp = 0;
+                }
+              else if (cx == 0x1ff)
+                if ((line_h1 & 0x300) == 0x300 && (line_h0 & 0x300) == 0x300)
+                  s->tp[j] = 1;
+                else {
+                  ltp = 0;
 #ifdef DEBUG
-		  tp_exceptions++;
+                  tp_exceptions++;
 #endif
-		}
-	      else
-		s->tp[j] = 2;
-	    } while (++j & 3 && j < lx);
-	  } while (j & 7 && j < lx);
-	} /* for (j = ...) */
-	arith_encode(se, TPDCX, !ltp);
+                }
+              else
+                s->tp[j] = 2;
+            } while (++j & 3 && j < lx);
+          } while (j & 7 && j < lx);
+        } /* for (j = ...) */
+        arith_encode(se, TPDCX, !ltp);
 #ifdef DEBUG
-	tp_lines += ltp;
+        tp_lines += ltp;
 #endif
       }
 
@@ -1302,158 +1317,158 @@ static void encode_sde(struct jbg_enc_state *s,
       line_h1 = line_h2 = line_h3 = line_l1 = line_l2 = line_l3 = 0;
       if (i > 0 || !reset) line_h2 = (long)*(hp - hbpl) << 8;
       if (i > 1 || !reset) {
-	line_h3 = (long)*(hp - hbpl - hbpl) << 8;
-	line_l3 = (long)*(lp2 - lbpl) << 8;
+        line_h3 = (long)*(hp - hbpl - hbpl) << 8;
+        line_l3 = (long)*(lp2 - lbpl) << 8;
       }
       line_l2 = (long)*lp2 << 8;
       line_l1 = (long)*lp1 << 8;
 
       /* encode line */
       for (j = 0; j < hx; lp1++, lp2++) {
-	if ((j >> 1) < lbpl * 8 - 8) {
-	  if (i > 1 || !reset)
-	    line_l3 |= *(lp2 - lbpl + 1);
-	  line_l2 |= *(lp2 + 1);
-	  line_l1 |= *(lp1 + 1);
-	}
-	do { /* ... while (j & 15 && j < hx) */
-
-	  assert(hp - (s->lhp[s->highres[plane]][plane] +
-		       (stripe * hl + i) * hbpl)
-		 == (ptrdiff_t) j >> 3);
-
-	  assert(lp2 - (s->lhp[1-s->highres[plane]][plane] +
-			(stripe * ll + (i>>1)) * lbpl)
-		 == (ptrdiff_t) j >> 4);
-
-	  line_h1 |= *hp;
-	  if (j < hbpl * 8 - 8) {
-	    if (i > 0 || !reset) {
-	      line_h2 |= *(hp - hbpl + 1);
-	      if (i > 1 || !reset)
-		line_h3 |= *(hp - hbpl - hbpl + 1);
-	    }
-	  }
-	  do { /* ... while (j & 7 && j < hx) */
-	    line_l1 <<= 1;  line_l2 <<= 1;  line_l3 <<= 1;
-	    if (ltp && s->tp[j >> 1] < 2) {
-	      /* pixel are typical and have not to be encoded */
-	      line_h1 <<= 2;  line_h2 <<= 2;  line_h3 <<= 2;
+        if ((j >> 1) < lbpl * 8 - 8) {
+          if (i > 1 || !reset)
+            line_l3 |= *(lp2 - lbpl + 1);
+          line_l2 |= *(lp2 + 1);
+          line_l1 |= *(lp1 + 1);
+        }
+        do { /* ... while (j & 15 && j < hx) */
+
+          assert(hp - (s->lhp[s->highres[plane]][plane] +
+                       (stripe * hl + i) * hbpl)
+                 == (ptrdiff_t) j >> 3);
+
+          assert(lp2 - (s->lhp[1-s->highres[plane]][plane] +
+                        (stripe * ll + (i>>1)) * lbpl)
+                 == (ptrdiff_t) j >> 4);
+
+          line_h1 |= *hp;
+          if (j < hbpl * 8 - 8) {
+            if (i > 0 || !reset) {
+              line_h2 |= *(hp - hbpl + 1);
+              if (i > 1 || !reset)
+                line_h3 |= *(hp - hbpl - hbpl + 1);
+            }
+          }
+          do { /* ... while (j & 7 && j < hx) */
+            line_l1 <<= 1;  line_l2 <<= 1;  line_l3 <<= 1;
+            if (ltp && s->tp[j >> 1] < 2) {
+              /* pixel are typical and have not to be encoded */
+              line_h1 <<= 2;  line_h2 <<= 2;  line_h3 <<= 2;
 #ifdef DEBUG
-	      do {
-		++tp_pixels;
-	      } while (++j & 1 && j < hx);
+              do {
+                ++tp_pixels;
+              } while (++j & 1 && j < hx);
 #else
-	      j += 2;
+              j += 2;
 #endif
-	    } else
-	      do { /* ... while (++j & 1 && j < hx) */
-		line_h1 <<= 1;  line_h2 <<= 1;  line_h3 <<= 1;
-
-		/* deterministic prediction */
-		if (s->options & JBG_DPON) {
-		  if ((y & 1) == 0) {
-		    if ((j & 1) == 0) {
-		      /* phase 0 */
-		      if (s->dppriv[((line_l3 >> 16) & 0x003) |
-				    ((line_l2 >> 14) & 0x00c) |
-				    ((line_h1 >> 5)  & 0x010) |
-				    ((line_h2 >> 10) & 0x0e0)] < 2) {
+            } else
+              do { /* ... while (++j & 1 && j < hx) */
+                line_h1 <<= 1;  line_h2 <<= 1;  line_h3 <<= 1;
+
+                /* deterministic prediction */
+                if (s->options & JBG_DPON) {
+                  if ((y & 1) == 0) {
+                    if ((j & 1) == 0) {
+                      /* phase 0 */
+                      if (s->dppriv[((line_l3 >> 16) & 0x003) |
+                                    ((line_l2 >> 14) & 0x00c) |
+                                    ((line_h1 >> 5)  & 0x010) |
+                                    ((line_h2 >> 10) & 0x0e0)] < 2) {
 #ifdef DEBUG
-			++dp_pixels;
+                        ++dp_pixels;
 #endif
-			continue;
-		      }
-		    } else {
-		      /* phase 1 */
-		      if (s->dppriv[(((line_l3 >> 16) & 0x003) |
-				     ((line_l2 >> 14) & 0x00c) |
-				     ((line_h1 >> 5)  & 0x030) |
-				     ((line_h2 >> 10) & 0x1c0)) + 256] < 2) {
+                        continue;
+                      }
+                    } else {
+                      /* phase 1 */
+                      if (s->dppriv[(((line_l3 >> 16) & 0x003) |
+                                     ((line_l2 >> 14) & 0x00c) |
+                                     ((line_h1 >> 5)  & 0x030) |
+                                     ((line_h2 >> 10) & 0x1c0)) + 256] < 2) {
 #ifdef DEBUG
-			++dp_pixels;
+                        ++dp_pixels;
 #endif
-			continue;
-		      }
-		    }
-		  } else {
-		    if ((j & 1) == 0) {
-		      /* phase 2 */
-		      if (s->dppriv[(((line_l3 >> 16) & 0x003) |
-				     ((line_l2 >> 14) & 0x00c) |
-				     ((line_h1 >> 5)  & 0x010) |
-				     ((line_h2 >> 10) & 0x0e0) |
-				     ((line_h3 >> 7) & 0x700)) + 768] < 2) {
+                        continue;
+                      }
+                    }
+                  } else {
+                    if ((j & 1) == 0) {
+                      /* phase 2 */
+                      if (s->dppriv[(((line_l3 >> 16) & 0x003) |
+                                     ((line_l2 >> 14) & 0x00c) |
+                                     ((line_h1 >> 5)  & 0x010) |
+                                     ((line_h2 >> 10) & 0x0e0) |
+                                     ((line_h3 >> 7) & 0x700)) + 768] < 2) {
 #ifdef DEBUG
-			++dp_pixels;
+                        ++dp_pixels;
 #endif
-			continue;
-		      }
-		    } else {
-		      /* phase 3 */
-		      if (s->dppriv[(((line_l3 >> 16) & 0x003) |
-				     ((line_l2 >> 14) & 0x00c) |
-				     ((line_h1 >> 5)  & 0x030) |
-				     ((line_h2 >> 10) & 0x1c0) |
-				     ((line_h3 >> 7)  & 0xe00)) + 2816] < 2) {
+                        continue;
+                      }
+                    } else {
+                      /* phase 3 */
+                      if (s->dppriv[(((line_l3 >> 16) & 0x003) |
+                                     ((line_l2 >> 14) & 0x00c) |
+                                     ((line_h1 >> 5)  & 0x030) |
+                                     ((line_h2 >> 10) & 0x1c0) |
+                                     ((line_h3 >> 7)  & 0xe00)) + 2816] < 2) {
 #ifdef DEBUG
-			++dp_pixels;
+                        ++dp_pixels;
 #endif
-			continue;
-		      }
-		    }
-		  }
-		}
-
-		/* determine context */
-		if (s->tx[plane]) {
-		  if ((unsigned) s->tx[plane] > j)
-		    a = 0;
-		  else {
-		    o = (j - s->tx[plane]) - (j & ~7L);
-		    a = (hp[o >> 3] >> (7 - (o & 7))) & 1;
-		    a <<= 4;
-		  }
-		  assert(s->tx[plane] > 23 ||
-			 a == ((line_h1 >> (4 + s->tx[plane])) & 0x010));
-		  cx = (((line_h1 >> 9)  & 0x003) | a |
-			((line_h2 >> 13) & 0x00c) |
-			((line_h3 >> 11) & 0x020));
-		} else
-		  cx = (((line_h1 >> 9)  & 0x003) |
-			((line_h2 >> 13) & 0x01c) |
-			((line_h3 >> 11) & 0x020));
-		if (j & 1)
-		  cx |= (((line_l2 >> 9)  & 0x0c0) |
-			 ((line_l1 >> 7)  & 0x300)) | (1UL << 10);
-		else
-		  cx |= (((line_l2 >> 10) & 0x0c0) |
-			 ((line_l1 >> 8)  & 0x300));
-		cx |= (y & 1) << 11;
-
-		arith_encode(se, cx, (line_h1 >> 8) & 1);
+                        continue;
+                      }
+                    }
+                  }
+                }
+
+                /* determine context */
+                if (s->tx[plane]) {
+                  if ((unsigned) s->tx[plane] > j)
+                    a = 0;
+                  else {
+                    o = (j - s->tx[plane]) - (j & ~7L);
+                    a = (hp[o >> 3] >> (7 - (o & 7))) & 1;
+                    a <<= 4;
+                  }
+                  assert(s->tx[plane] > 23 ||
+                         a == ((line_h1 >> (4 + s->tx[plane])) & 0x010));
+                  cx = (((line_h1 >> 9)  & 0x003) | a |
+                        ((line_h2 >> 13) & 0x00c) |
+                        ((line_h3 >> 11) & 0x020));
+                } else
+                  cx = (((line_h1 >> 9)  & 0x003) |
+                        ((line_h2 >> 13) & 0x01c) |
+                        ((line_h3 >> 11) & 0x020));
+                if (j & 1)
+                  cx |= (((line_l2 >> 9)  & 0x0c0) |
+                         ((line_l1 >> 7)  & 0x300)) | (1UL << 10);
+                else
+                  cx |= (((line_l2 >> 10) & 0x0c0) |
+                         ((line_l1 >> 8)  & 0x300));
+                cx |= (y & 1) << 11;
+
+                arith_encode(se, cx, (line_h1 >> 8) & 1);
 #ifdef DEBUG
-		encoded_pixels++;
+                encoded_pixels++;
 #endif
 
-		/* statistics for adaptive template changes */
-		if (!at_determined && j >= s->mx) {
-		  c[0] += !(((line_h2 >> 6) ^ line_h1) & 0x100);
-		  for (t = 3; t <= s->mx; t++)
-		    c[t] += !(((line_h1 >> t) ^ line_h1) & 0x100);
-		  ++c_all;
-		}
-
-	      } while (++j & 1 && j < hx);
-	  } while (j & 7 && j < hx);
-	  hp++;
-	} while (j & 15 && j < hx);
+                /* statistics for adaptive template changes */
+                if (!at_determined && j >= s->mx) {
+                  c[0] += !(((line_h2 >> 6) ^ line_h1) & 0x100);
+                  for (t = 3; t <= s->mx; t++)
+                    c[t] += !(((line_h1 >> t) ^ line_h1) & 0x100);
+                  ++c_all;
+                }
+
+              } while (++j & 1 && j < hx);
+          } while (j & 7 && j < hx);
+          hp++;
+        } while (j & 15 && j < hx);
       } /* for (j = ...) */
 
       /* low resolution pixels are used twice */
       if ((i & 1) == 0) {
-	lp1 -= lbpl;
-	lp2 -= lbpl;
+        lp1 -= lbpl;
+        lp2 -= lbpl;
       }
 
     } /* for (i = ...) */
@@ -1463,7 +1478,7 @@ static void encode_sde(struct jbg_enc_state *s,
   jbg_buf_remove_zeros(s->sde[stripe][layer][plane]);
   jbg_buf_write(MARKER_ESC, s->sde[stripe][layer][plane]);
   jbg_buf_write((s->options & JBG_SDRST) ? MARKER_SDRST : MARKER_SDNORM,
-		s->sde[stripe][layer][plane]);
+                s->sde[stripe][layer][plane]);
   if (s->options & JBG_SDRST)
     s->tx[plane] = 0;
 
@@ -1499,19 +1514,20 @@ static void encode_sde(struct jbg_enc_state *s,
 #if 0
   if (stripe == s->stripes - 1)
     fprintf(stderr, "tp_lines = %ld, tp_exceptions = %ld, tp_pixels = %ld, "
-	    "dp_pixels = %ld, encoded_pixels = %ld\n",
-	    tp_lines, tp_exceptions, tp_pixels, dp_pixels, encoded_pixels);
+            "dp_pixels = %ld, encoded_pixels = %ld\n",
+            tp_lines, tp_exceptions, tp_pixels, dp_pixels, encoded_pixels);
 #endif
 
   return;
 }
 
 
+
 /*
  * Create the next lower resolution version of an image
  */
 static void resolution_reduction(struct jbg_enc_state *s, int plane,
-				 int higher_layer)
+                                 int higher_layer)
 {
   unsigned long hl, ll, hx, hy, lx, ly, hbpl, lbpl;
   unsigned char *hp1, *hp2, *hp3, *lp;
@@ -1542,7 +1558,7 @@ static void resolution_reduction(struct jbg_enc_state *s, int plane,
 
 #ifdef DEBUG
   fprintf(stderr, "resolution_reduction: plane = %d, higher_layer = %d\n",
-	  plane, higher_layer);
+          plane, higher_layer);
 #endif
 
   /*
@@ -1566,34 +1582,34 @@ static void resolution_reduction(struct jbg_enc_state *s, int plane,
   for (y = 0; y < ly;) {
     for (i = 0; i < ll && y < ly; i++, y++) {
       if (2*y + 1 >= hy)
-	hp1 = hp2;
+        hp1 = hp2;
       pix = 0;
       line_h1 = line_h2 = line_h3 = line_l2 = 0;
       for (j = 0; j < lbpl * 8; j += 8) {
-	*lp = 0;
-	if (i > 0 || (y > 0 && !(s->options & JBG_SDRST)))
-	  line_l2 |= *(lp-lbpl);
-	for (k = 0; k < 8 && j + k < lx; k += 4) {
-	  if (((j + k) >> 2) < hbpl) {
-	    if (i > 0 || (y > 0 && !(s->options & JBG_SDRST)))
-	      line_h3 |= *hp3;
-	    ++hp3;
-	    line_h2 |= *(hp2++);
-	    line_h1 |= *(hp1++);
-	  }
-	  for (l = 0; l < 4 && j + k + l < lx; l++) {
-	    line_h3 <<= 2;
-	    line_h2 <<= 2;
-	    line_h1 <<= 2;
-	    line_l2 <<= 1;
-	    pix = s->res_tab[((line_h1 >> 8) & 0x007) |
-			     ((line_h2 >> 5) & 0x038) |
-			     ((line_h3 >> 2) & 0x1c0) |
-			     (pix << 9) | ((line_l2 << 2) & 0xc00)];
-	    *lp = (*lp << 1) | pix;
-	  }
-	}
-	++lp;
+        *lp = 0;
+        if (i > 0 || (y > 0 && !(s->options & JBG_SDRST)))
+          line_l2 |= *(lp-lbpl);
+        for (k = 0; k < 8 && j + k < lx; k += 4) {
+          if (((j + k) >> 2) < hbpl) {
+            if (i > 0 || (y > 0 && !(s->options & JBG_SDRST)))
+              line_h3 |= *hp3;
+            ++hp3;
+            line_h2 |= *(hp2++);
+            line_h1 |= *(hp1++);
+          }
+          for (l = 0; l < 4 && j + k + l < lx; l++) {
+            line_h3 <<= 2;
+            line_h2 <<= 2;
+            line_h1 <<= 2;
+            line_l2 <<= 1;
+            pix = s->res_tab[((line_h1 >> 8) & 0x007) |
+                             ((line_h2 >> 5) & 0x038) |
+                             ((line_h3 >> 2) & 0x1c0) |
+                             (pix << 9) | ((line_l2 << 2) & 0xc00)];
+            *lp = (*lp << 1) | pix;
+          }
+        }
+        ++lp;
       }
       *(lp - 1) <<= lbpl * 8 - lx;
       hp1 += hbpl;
@@ -1619,6 +1635,7 @@ static void resolution_reduction(struct jbg_enc_state *s, int plane,
 }
 
 
+
 /*
  * This function is called inside the three loops of jbg_enc_out() in
  * order to write the next SDE. It has first to generate the required
@@ -1635,7 +1652,7 @@ static void resolution_reduction(struct jbg_enc_state *s, int plane,
  * of doing it, but it minimizes the amount of temporary memory used.
  */
 static void output_sde(struct jbg_enc_state *s,
-		       unsigned long stripe, int layer, int plane)
+                       unsigned long stripe, int layer, int plane)
 {
   int lfcl;     /* lowest fully coded layer */
   long i;
@@ -1646,7 +1663,7 @@ static void output_sde(struct jbg_enc_state *s,
   if (s->sde[stripe][layer][plane] != SDE_TODO) {
 #ifdef DEBUG
     fprintf(stderr, "writing SDE: s/d/p = %2lu/%2d/%2d\n",
-	    stripe, layer, plane);
+            stripe, layer, plane);
 #endif
     jbg_buf_output(&s->sde[stripe][layer][plane], s->data_out, s->file);
     s->sde[stripe][layer][plane] = SDE_DONE;
@@ -1697,6 +1714,7 @@ static void output_sde(struct jbg_enc_state *s,
 }
 
 
+
 /*
  * Convert the table which controls the deterministic prediction
  * process from the internal format into the representation required
@@ -1748,6 +1766,7 @@ void jbg_int2dppriv(unsigned char *dptable, const char *internal)
 }
 
 
+
 /*
  * Convert the table which controls the deterministic prediction
  * process from the 1728 byte long DPTABLE format into the 6912 byte long
@@ -1779,6 +1798,7 @@ void jbg_dppriv2int(char *internal, const unsigned char *dptable)
 }
 
 
+
 /*
  * Encode one full BIE and pass the generated data to the specified
  * call-back function
@@ -1822,7 +1842,7 @@ void jbg_enc_out(struct jbg_enc_state *s)
     bpl = jbg_ceil_half(s->xd, 3);     /* bytes per line */
     for (plane = 0; plane < s->planes; plane++)
       for (y = 0; y < s->yd; y++)
-	s->lhp[0][plane][y * bpl + bpl - 1] &= ~((1 << (8 - (s->xd & 7))) - 1);
+        s->lhp[0][plane][y * bpl + bpl - 1] &= ~((1 << (8 - (s->xd & 7))) - 1);
   }
 
   /* prepare BIH */
@@ -1864,12 +1884,12 @@ void jbg_enc_out(struct jbg_enc_state *s)
       checked_malloc(s->stripes, sizeof(struct jbg_buf ***));
     for (stripe = 0; stripe < s->stripes; stripe++) {
       s->sde[stripe] = (struct jbg_buf ***)
-	checked_malloc(s->d + 1, sizeof(struct jbg_buf **));
+        checked_malloc(s->d + 1, sizeof(struct jbg_buf **));
       for (layer = 0; layer < s->d + 1; layer++) {
-	s->sde[stripe][layer] = (struct jbg_buf **)
-	  checked_malloc(s->planes, sizeof(struct jbg_buf *));
-	for (plane = 0; plane < s->planes; plane++)
-	  s->sde[stripe][layer][plane] = SDE_TODO;
+        s->sde[stripe][layer] = (struct jbg_buf **)
+          checked_malloc(s->planes, sizeof(struct jbg_buf *));
+        for (plane = 0; plane < s->planes; plane++)
+          s->sde[stripe][layer][plane] = SDE_TODO;
       }
     }
   }
@@ -1892,9 +1912,9 @@ void jbg_enc_out(struct jbg_enc_state *s)
   for (layer = s->dh; layer >= s->dl; layer--) {
     for (plane = 0; plane < s->planes; plane++) {
       if (layer > 0)
-	resolution_reduction(s, plane, layer);
+        resolution_reduction(s, plane, layer);
       for (stripe = 0; stripe < s->stripes; stripe++)
-	encode_sde(s, stripe, layer, plane);
+        encode_sde(s, stripe, layer, plane);
       s->highres[plane] ^= 1;
     }
   }
@@ -1917,55 +1937,55 @@ void jbg_enc_out(struct jbg_enc_state *s)
     for (ii[1] = is[1]; ii[1] <= ie[1]; ii[1]++)
       for (ii[2] = is[2]; ii[2] <= ie[2]; ii[2]++) {
 
-	stripe = ii[iindex[order][STRIPE]];
-	if (s->order & JBG_HITOLO)
-	  layer = s->dh - (ii[iindex[order][LAYER]] - s->dl);
-	else
-	  layer = ii[iindex[order][LAYER]];
-	plane = ii[iindex[order][PLANE]];
-
-	/* output comment marker segment if there is any pending */
-	if (s->comment) {
-	  buf[0] = MARKER_ESC;
-	  buf[1] = MARKER_COMMENT;
-	  buf[2] = s->comment_len >> 24;
-	  buf[3] = (s->comment_len >> 16) & 0xff;
-	  buf[4] = (s->comment_len >> 8) & 0xff;
-	  buf[5] = s->comment_len & 0xff;
-	  s->data_out(buf, 6, s->file);
-	  s->data_out(s->comment, s->comment_len, s->file);
-	  s->comment = NULL;
-	}
-
-	output_sde(s, stripe, layer, plane);
-
-	/*
-	 * When we generate a NEWLEN test case (s->yd1 > s->yd), output
-	 * NEWLEN after last stripe if we have only a single
-	 * resolution layer or plane (see ITU-T T.85 profile), otherwise
-	 * output NEWLEN before last stripe.
-	 */
-	if (s->yd1 > s->yd &&
-	    (stripe == s->stripes - 1 ||
-	     (stripe == s->stripes - 2 &&
-	      (s->dl != s->dh || s->planes > 1)))) {
-	  s->yd1 = s->yd;
-	  yd = jbg_ceil_half(s->yd, s->d - s->dh);
-	  buf[0] = MARKER_ESC;
-	  buf[1] = MARKER_NEWLEN;
-	  buf[2] = yd >> 24;
-	  buf[3] = (yd >> 16) & 0xff;
-	  buf[4] = (yd >> 8) & 0xff;
-	  buf[5] = yd & 0xff;
-	  s->data_out(buf, 6, s->file);
+        stripe = ii[iindex[order][STRIPE]];
+        if (s->order & JBG_HITOLO)
+          layer = s->dh - (ii[iindex[order][LAYER]] - s->dl);
+        else
+          layer = ii[iindex[order][LAYER]];
+        plane = ii[iindex[order][PLANE]];
+
+        /* output comment marker segment if there is any pending */
+        if (s->comment) {
+          buf[0] = MARKER_ESC;
+          buf[1] = MARKER_COMMENT;
+          buf[2] = s->comment_len >> 24;
+          buf[3] = (s->comment_len >> 16) & 0xff;
+          buf[4] = (s->comment_len >> 8) & 0xff;
+          buf[5] = s->comment_len & 0xff;
+          s->data_out(buf, 6, s->file);
+          s->data_out(s->comment, s->comment_len, s->file);
+          s->comment = NULL;
+        }
+
+        output_sde(s, stripe, layer, plane);
+
+        /*
+         * When we generate a NEWLEN test case (s->yd1 > s->yd), output
+         * NEWLEN after last stripe if we have only a single
+         * resolution layer or plane (see ITU-T T.85 profile), otherwise
+         * output NEWLEN before last stripe.
+         */
+        if (s->yd1 > s->yd &&
+            (stripe == s->stripes - 1 ||
+             (stripe == s->stripes - 2 &&
+              (s->dl != s->dh || s->planes > 1)))) {
+          s->yd1 = s->yd;
+          yd = jbg_ceil_half(s->yd, s->d - s->dh);
+          buf[0] = MARKER_ESC;
+          buf[1] = MARKER_NEWLEN;
+          buf[2] = yd >> 24;
+          buf[3] = (yd >> 16) & 0xff;
+          buf[4] = (yd >> 8) & 0xff;
+          buf[5] = yd & 0xff;
+          s->data_out(buf, 6, s->file);
 #ifdef DEBUG
-	  fprintf(stderr, "NEWLEN: yd=%lu\n", yd);
+          fprintf(stderr, "NEWLEN: yd=%lu\n", yd);
 #endif
-	  if (stripe == s->stripes - 1) {
-	    buf[1] = MARKER_SDNORM;
-	    s->data_out(buf, 2, s->file);
-	  }
-	}
+          if (stripe == s->stripes - 1) {
+            buf[1] = MARKER_SDNORM;
+            s->data_out(buf, 2, s->file);
+          }
+        }
 
       }
 
@@ -1973,6 +1993,7 @@ void jbg_enc_out(struct jbg_enc_state *s)
 }
 
 
+
 void jbg_enc_free(struct jbg_enc_state *s)
 {
   unsigned long stripe;
@@ -1986,11 +2007,11 @@ void jbg_enc_free(struct jbg_enc_state *s)
   if (s->sde) {
     for (stripe = 0; stripe < s->stripes; stripe++) {
       for (layer = 0; layer < s->d + 1; layer++) {
-	for (plane = 0; plane < s->planes; plane++)
-	  if (s->sde[stripe][layer][plane] != SDE_DONE &&
-	      s->sde[stripe][layer][plane] != SDE_TODO)
-	    jbg_buf_free(&s->sde[stripe][layer][plane]);
-	checked_free(s->sde[stripe][layer]);
+        for (plane = 0; plane < s->planes; plane++)
+          if (s->sde[stripe][layer][plane] != SDE_DONE &&
+              s->sde[stripe][layer][plane] != SDE_TODO)
+            jbg_buf_free(&s->sde[stripe][layer][plane]);
+        checked_free(s->sde[stripe][layer]);
       }
       checked_free(s->sde[stripe]);
     }
@@ -2023,6 +2044,7 @@ void jbg_enc_free(struct jbg_enc_state *s)
 }
 
 
+
 /*
  * Convert the error codes used by jbg_dec_in() into an English ASCII string
  */
@@ -2036,6 +2058,7 @@ const char *jbg_strerror(int errnum)
 }
 
 
+
 /*
  * The constructor for a decoder
  */
@@ -2055,6 +2078,7 @@ void jbg_dec_init(struct jbg_dec_state *s)
 }
 
 
+
 /*
  * Specify a maximum image size for the decoder. If the JBIG file has
  * the order bit ILEAVE, but not the bit SEQ set, then the decoder
@@ -2063,7 +2087,7 @@ void jbg_dec_init(struct jbg_dec_state *s)
  * ymax.
  */
 void jbg_dec_maxsize(struct jbg_dec_state *s, unsigned long xmax,
-		     unsigned long ymax)
+                     unsigned long ymax)
 {
   if (xmax > 0) s->xmax = xmax;
   if (ymax > 0) s->ymax = ymax;
@@ -2072,6 +2096,7 @@ void jbg_dec_maxsize(struct jbg_dec_state *s, unsigned long xmax,
 }
 
 
+
 /*
  * Decode the new len PSDC bytes to which data points and add them to
  * the current stripe. Return the number of bytes which have actually
@@ -2080,7 +2105,7 @@ void jbg_dec_maxsize(struct jbg_dec_state *s, unsigned long xmax,
  * this code cannot determine whether we have a marker segment).
  */
 static size_t decode_pscd(struct jbg_dec_state *s, unsigned char *data,
-			  size_t len)
+                          size_t len)
 {
   unsigned long stripe;
   unsigned int layer, plane;
@@ -2139,7 +2164,7 @@ static size_t decode_pscd(struct jbg_dec_state *s, unsigned char *data,
 #ifdef DEBUG
   if (s->x == 0 && s->i == 0 && s->pseudo)
     fprintf(stderr, "decode_pscd(%p, %p, %ld): s/d/p = %2lu/%2u/%2u\n",
-	    (void *) s, (void *) data, (long) len, stripe, layer, plane);
+            (void *) s, (void *) data, (long) len, stripe, layer, plane);
 #endif
 
   if (s->x == 0 && s->i == 0 &&
@@ -2158,38 +2183,38 @@ static size_t decode_pscd(struct jbg_dec_state *s, unsigned char *data,
 
       /* adaptive template changes */
       if (x == 0 && s->pseudo)
-	for (n = 0; n < s->at_moves; n++)
-	  if (s->at_line[n] == s->i) {
-	    s->tx[plane][layer - s->dl] = s->at_tx[n];
-	    s->ty[plane][layer - s->dl] = s->at_ty[n];
+        for (n = 0; n < s->at_moves; n++)
+          if (s->at_line[n] == s->i) {
+            s->tx[plane][layer - s->dl] = s->at_tx[n];
+            s->ty[plane][layer - s->dl] = s->at_ty[n];
 #ifdef DEBUG
-	    fprintf(stderr, "ATMOVE: line=%lu, tx=%d, ty=%d.\n", s->i,
-		    s->tx[plane][layer - s->dl], s->ty[plane][layer - s->dl]);
+            fprintf(stderr, "ATMOVE: line=%lu, tx=%d, ty=%d.\n", s->i,
+                    s->tx[plane][layer - s->dl], s->ty[plane][layer - s->dl]);
 #endif
-	  }
+          }
       tx = s->tx[plane][layer - s->dl];
       assert(tx >= 0); /* i.e., tx can safely be cast to unsigned */
 
       /* typical prediction */
       if (s->options & JBG_TPBON && s->pseudo) {
-	slntp = arith_decode(se, (s->options & JBG_LRLTWO) ? TPB2CX : TPB3CX);
-	if (slntp < 0)
-	  goto leave;
-	s->lntp[plane][layer - s->dl] =
-	  !(slntp ^ s->lntp[plane][layer - s->dl]);
-	if (!s->lntp[plane][layer - s->dl]) {
-	  /* this line is 'typical' (i.e. identical to the previous one) */
-	  p1 = hp;
-	  if (s->i == 0 && (stripe == 0 || s->reset[plane][layer - s->dl]))
-	    while (p1 < hp + hbpl) *p1++ = 0;
-	  else {
-	    q1 = hp - hbpl;
-	    while (q1 < hp) *p1++ = *q1++;
-	  }
-	  hp += hbpl;
-	  continue;
-	}
-	/* this line is 'not typical' and has to be coded completely */
+        slntp = arith_decode(se, (s->options & JBG_LRLTWO) ? TPB2CX : TPB3CX);
+        if (slntp < 0)
+          goto leave;
+        s->lntp[plane][layer - s->dl] =
+          !(slntp ^ s->lntp[plane][layer - s->dl]);
+        if (!s->lntp[plane][layer - s->dl]) {
+          /* this line is 'typical' (i.e. identical to the previous one) */
+          p1 = hp;
+          if (s->i == 0 && (stripe == 0 || s->reset[plane][layer - s->dl]))
+            while (p1 < hp + hbpl) *p1++ = 0;
+          else {
+            q1 = hp - hbpl;
+            while (q1 < hp) *p1++ = *q1++;
+          }
+          hp += hbpl;
+          continue;
+        }
+        /* this line is 'not typical' and has to be coded completely */
       }
       s->pseudo = 0;
 
@@ -2203,11 +2228,11 @@ static size_t decode_pscd(struct jbg_dec_state *s, unsigned char *data,
        */
 
       if (x == 0) {
-	line_h1 = line_h2 = line_h3 = 0;
-	if (s->i > 0 || (y > 0 && !s->reset[plane][layer - s->dl]))
-	  line_h2 = (long)*(hp - hbpl) << 8;
-	if (s->i > 1 || (y > 1 && !s->reset[plane][layer - s->dl]))
-	  line_h3 = (long)*(hp - hbpl - hbpl) << 8;
+        line_h1 = line_h2 = line_h3 = 0;
+        if (s->i > 0 || (y > 0 && !s->reset[plane][layer - s->dl]))
+          line_h2 = (long)*(hp - hbpl) << 8;
+        if (s->i > 1 || (y > 1 && !s->reset[plane][layer - s->dl]))
+          line_h3 = (long)*(hp - hbpl - hbpl) << 8;
       }
 
       /*
@@ -2256,70 +2281,70 @@ static size_t decode_pscd(struct jbg_dec_state *s, unsigned char *data,
 
       /* decode line */
       while (x < hx) {
-	if ((x & 7) == 0) {
-	  if (x < hbpl * 8 - 8 &&
-	      (s->i > 0 || (y > 0 && !s->reset[plane][layer - s->dl]))) {
-	    line_h2 |= *(hp - hbpl + 1);
-	    if (s->i > 1 || (y > 1 && !s->reset[plane][layer - s->dl]))
-	      line_h3 |= *(hp - hbpl - hbpl + 1);
-	  }
-	}
-	if (s->options & JBG_LRLTWO) {
-	  /* two line template */
-	  do {
-	    if (tx) {
-	      if ((unsigned) tx > x)
-		a = 0;
-	      else if (tx < 8)
-		a = ((line_h1 >> (tx - 5)) & 0x010);
-	      else {
-		o = (x - tx) - (x & ~7L);
-		a = (hp[o >> 3] >> (7 - (o & 7))) & 1;
-		a <<= 4;
-	      }
-	      assert(tx > 31 ||
-		     a == ((line_h1 >> (tx - 5)) & 0x010));
-	      pix = arith_decode(se, (((line_h2 >> 9) & 0x3e0) | a |
-				      (line_h1 & 0x00f)));
-	    } else
-	      pix = arith_decode(se, (((line_h2 >> 9) & 0x3f0) |
-				      (line_h1 & 0x00f)));
-	    if (pix < 0)
-	      goto leave;
-	    line_h1 = (line_h1 << 1) | pix;
-	    line_h2 <<= 1;
-	  } while ((++x & 7) && x < hx);
-	} else {
-	  /* three line template */
-	  do {
-	    if (tx) {
-	      if ((unsigned) tx > x)
-		a = 0;
-	      else if (tx < 8)
-		a = ((line_h1 >> (tx - 3)) & 0x004);
-	      else {
-		o = (x - tx) - (x & ~7L);
-		a = (hp[o >> 3] >> (7 - (o & 7))) & 1;
-		a <<= 2;
-	      }
-	      assert(tx > 31 ||
-		     a == ((line_h1 >> (tx - 3)) & 0x004));
-	      pix = arith_decode(se, (((line_h3 >>  7) & 0x380) |
-				      ((line_h2 >> 11) & 0x078) | a |
-				      (line_h1 & 0x003)));
-	    } else
-	      pix = arith_decode(se, (((line_h3 >>  7) & 0x380) |
-				      ((line_h2 >> 11) & 0x07c) |
-				      (line_h1 & 0x003)));
-	    if (pix < 0)
-	      goto leave;
-
-	    line_h1 = (line_h1 << 1) | pix;
-	    line_h2 <<= 1;
-	    line_h3 <<= 1;
-	  } while ((++x & 7) && x < hx);
-	} /* if (s->options & JBG_LRLTWO) */
-	*hp++ = line_h1;
+        if ((x & 7) == 0) {
+          if (x < hbpl * 8 - 8 &&
+              (s->i > 0 || (y > 0 && !s->reset[plane][layer - s->dl]))) {
+            line_h2 |= *(hp - hbpl + 1);
+            if (s->i > 1 || (y > 1 && !s->reset[plane][layer - s->dl]))
+              line_h3 |= *(hp - hbpl - hbpl + 1);
+          }
+        }
+        if (s->options & JBG_LRLTWO) {
+          /* two line template */
+          do {
+            if (tx) {
+              if ((unsigned) tx > x)
+                a = 0;
+              else if (tx < 8)
+                a = ((line_h1 >> (tx - 5)) & 0x010);
+              else {
+                o = (x - tx) - (x & ~7L);
+                a = (hp[o >> 3] >> (7 - (o & 7))) & 1;
+                a <<= 4;
+              }
+              assert(tx > 31 ||
+                     a == ((line_h1 >> (tx - 5)) & 0x010));
+              pix = arith_decode(se, (((line_h2 >> 9) & 0x3e0) | a |
+                                      (line_h1 & 0x00f)));
+            } else
+              pix = arith_decode(se, (((line_h2 >> 9) & 0x3f0) |
+                                      (line_h1 & 0x00f)));
+            if (pix < 0)
+              goto leave;
+            line_h1 = (line_h1 << 1) | pix;
+            line_h2 <<= 1;
+          } while ((++x & 7) && x < hx);
+        } else {
+          /* three line template */
+          do {
+            if (tx) {
+              if ((unsigned) tx > x)
+                a = 0;
+              else if (tx < 8)
+                a = ((line_h1 >> (tx - 3)) & 0x004);
+              else {
+                o = (x - tx) - (x & ~7L);
+                a = (hp[o >> 3] >> (7 - (o & 7))) & 1;
+                a <<= 2;
+              }
+              assert(tx > 31 ||
+                     a == ((line_h1 >> (tx - 3)) & 0x004));
+              pix = arith_decode(se, (((line_h3 >>  7) & 0x380) |
+                                      ((line_h2 >> 11) & 0x078) | a |
+                                      (line_h1 & 0x003)));
+            } else
+              pix = arith_decode(se, (((line_h3 >>  7) & 0x380) |
+                                      ((line_h2 >> 11) & 0x07c) |
+                                      (line_h1 & 0x003)));
+            if (pix < 0)
+              goto leave;
+
+            line_h1 = (line_h1 << 1) | pix;
+            line_h2 <<= 1;
+            line_h3 <<= 1;
+          } while ((++x & 7) && x < hx);
+        } /* if (s->options & JBG_LRLTWO) */
+        *hp++ = line_h1;
       } /* while */
       *(hp - 1) <<= hbpl * 8 - hx;
       x = 0;
@@ -2336,25 +2361,25 @@ static size_t decode_pscd(struct jbg_dec_state *s, unsigned char *data,
 
       /* adaptive template changes */
       if (x == 0)
-	for (n = 0; n < s->at_moves; n++)
-	  if (s->at_line[n] == s->i) {
-	    s->tx[plane][layer - s->dl] = s->at_tx[n];
-	    s->ty[plane][layer - s->dl] = s->at_ty[n];
+        for (n = 0; n < s->at_moves; n++)
+          if (s->at_line[n] == s->i) {
+            s->tx[plane][layer - s->dl] = s->at_tx[n];
+            s->ty[plane][layer - s->dl] = s->at_ty[n];
 #ifdef DEBUG
-	    fprintf(stderr, "ATMOVE: line=%lu, tx=%d, ty=%d.\n", s->i,
-		    s->tx[plane][layer - s->dl], s->ty[plane][layer - s->dl]);
+            fprintf(stderr, "ATMOVE: line=%lu, tx=%d, ty=%d.\n", s->i,
+                    s->tx[plane][layer - s->dl], s->ty[plane][layer - s->dl]);
 #endif
-	  }
+          }
       tx = s->tx[plane][layer - s->dl];
 
       /* handle lower border of low-resolution image */
       if ((s->i >> 1) >= ll - 1 || (y >> 1) >= ly - 1)
-	lp1 = lp2;
+        lp1 = lp2;
 
       /* typical prediction */
       if ((s->options & JBG_TPDON) && s->pseudo) {
-	if ((s->lntp[plane][layer - s->dl] = arith_decode(se, TPDCX)) < 0)
-	  goto leave;
+        if ((s->lntp[plane][layer - s->dl] = arith_decode(se, TPDCX)) < 0)
+          goto leave;
       }
       s->pseudo = 0;
 
@@ -2379,135 +2404,135 @@ static size_t decode_pscd(struct jbg_dec_state *s, unsigned char *data,
 
 
       if (x == 0) {
-	line_h1 = line_h2 = line_h3 = line_l1 = line_l2 = line_l3 = 0;
-	if (s->i > 0 || (y > 0 && !s->reset[plane][layer - s->dl])) {
-	  line_h2 = (long)*(hp - hbpl) << 8;
-	  if (s->i > 1 || (y > 1 && !s->reset[plane][layer - s->dl]))
-	    line_h3 = (long)*(hp - hbpl - hbpl) << 8;
-	}
-	if (s->i > 1 || (y > 1 && !s->reset[plane][layer-s->dl]))
-	  line_l3 = (long)*(lp2 - lbpl) << 8;
-	line_l2 = (long)*lp2 << 8;
-	line_l1 = (long)*lp1 << 8;
+        line_h1 = line_h2 = line_h3 = line_l1 = line_l2 = line_l3 = 0;
+        if (s->i > 0 || (y > 0 && !s->reset[plane][layer - s->dl])) {
+          line_h2 = (long)*(hp - hbpl) << 8;
+          if (s->i > 1 || (y > 1 && !s->reset[plane][layer - s->dl]))
+            line_h3 = (long)*(hp - hbpl - hbpl) << 8;
+        }
+        if (s->i > 1 || (y > 1 && !s->reset[plane][layer-s->dl]))
+          line_l3 = (long)*(lp2 - lbpl) << 8;
+        line_l2 = (long)*lp2 << 8;
+        line_l1 = (long)*lp1 << 8;
       }
 
       /* decode line */
       while (x < hx) {
-	if ((x & 15) == 0)
-	  if ((x >> 1) < lbpl * 8 - 8) {
-	    line_l1 |= *(lp1 + 1);
-	    line_l2 |= *(lp2 + 1);
-	    if (s->i > 1 ||
-		(y > 1 && !s->reset[plane][layer - s->dl]))
-	      line_l3 |= *(lp2 - lbpl + 1);
-	  }
-	do {
-
-	  assert(hp  - (s->lhp[ layer     &1][plane] + (stripe * hl + s->i)
-			* hbpl) == (ptrdiff_t) x >> 3);
-	  assert(lp2 - (s->lhp[(layer-1) &1][plane] + (stripe * ll + (s->i>>1))
-			* lbpl) == (ptrdiff_t) x >> 4);
-
-	  if ((x & 7) == 0)
-	    if (x < hbpl * 8 - 8) {
-	      if (s->i > 0 || (y > 0 && !s->reset[plane][layer - s->dl])) {
-		line_h2 |= *(hp + 1 - hbpl);
-		if (s->i > 1 || (y > 1 && !s->reset[plane][layer - s->dl]))
-		  line_h3 |= *(hp + 1 - hbpl - hbpl);
-	      }
-	    }
-	  do {
-	    if (!s->lntp[plane][layer - s->dl])
+        if ((x & 15) == 0)
+          if ((x >> 1) < lbpl * 8 - 8) {
+            line_l1 |= *(lp1 + 1);
+            line_l2 |= *(lp2 + 1);
+            if (s->i > 1 ||
+                (y > 1 && !s->reset[plane][layer - s->dl]))
+              line_l3 |= *(lp2 - lbpl + 1);
+          }
+        do {
+
+          assert(hp  - (s->lhp[ layer     &1][plane] + (stripe * hl + s->i)
+                        * hbpl) == (ptrdiff_t) x >> 3);
+          assert(lp2 - (s->lhp[(layer-1) &1][plane] + (stripe * ll + (s->i>>1))
+                        * lbpl) == (ptrdiff_t) x >> 4);
+
+          if ((x & 7) == 0)
+            if (x < hbpl * 8 - 8) {
+              if (s->i > 0 || (y > 0 && !s->reset[plane][layer - s->dl])) {
+                line_h2 |= *(hp + 1 - hbpl);
+                if (s->i > 1 || (y > 1 && !s->reset[plane][layer - s->dl]))
+                  line_h3 |= *(hp + 1 - hbpl - hbpl);
+              }
+            }
+          do {
+            if (!s->lntp[plane][layer - s->dl])
               cx = (((line_l3 >> 14) & 0x007) |
                     ((line_l2 >> 11) & 0x038) |
                     ((line_l1 >> 8)  & 0x1c0));
-	    if (!s->lntp[plane][layer - s->dl] &&
-		(cx == 0x000 || cx == 0x1ff)) {
-	      /* pixels are typical and have not to be decoded */
-	      do {
-		line_h1 = (line_h1 << 1) | (cx & 1);
-	      } while ((++x & 1) && x < hx);
-	      line_h2 <<= 2;  line_h3 <<= 2;
-	    } else
-	      do {
-
-		/* deterministic prediction */
-		if (s->options & JBG_DPON)
-		  if ((y & 1) == 0)
-		    if ((x & 1) == 0)
-		      /* phase 0 */
-		      pix = s->dppriv[((line_l3 >> 15) & 0x003) |
-				      ((line_l2 >> 13) & 0x00c) |
-				      ((line_h1 <<  4) & 0x010) |
-				      ((line_h2 >>  9) & 0x0e0)];
-		    else
-		      /* phase 1 */
-		      pix = s->dppriv[(((line_l3 >> 15) & 0x003) |
-				       ((line_l2 >> 13) & 0x00c) |
-				       ((line_h1 <<  4) & 0x030) |
-				       ((line_h2 >>  9) & 0x1c0)) + 256];
-		  else
-		    if ((x & 1) == 0)
-		      /* phase 2 */
-		      pix = s->dppriv[(((line_l3 >> 15) & 0x003) |
-				       ((line_l2 >> 13) & 0x00c) |
-				       ((line_h1 <<  4) & 0x010) |
-				       ((line_h2 >>  9) & 0x0e0) |
-				       ((line_h3 >>  6) & 0x700)) + 768];
-		    else
-		      /* phase 3 */
-		      pix = s->dppriv[(((line_l3 >> 15) & 0x003) |
-				       ((line_l2 >> 13) & 0x00c) |
-				       ((line_h1 <<  4) & 0x030) |
-				       ((line_h2 >>  9) & 0x1c0) |
-				       ((line_h3 >>  6) & 0xe00)) + 2816];
-		else
-		  pix = 2;
-
-		if (pix & 2) {
-		  if (tx)
-		    cx = ((line_h1         & 0x003) |
-			  (((line_h1 << 2) >> (tx - 3)) & 0x010) |
-			  ((line_h2 >> 12) & 0x00c) |
-			  ((line_h3 >> 10) & 0x020));
-		  else
-		    cx = ((line_h1         & 0x003) |
-			  ((line_h2 >> 12) & 0x01c) |
-			  ((line_h3 >> 10) & 0x020));
-		  if (x & 1)
-		    cx |= (((line_l2 >> 8) & 0x0c0) |
-			   ((line_l1 >> 6) & 0x300)) | (1UL << 10);
-		  else
-		    cx |= (((line_l2 >> 9) & 0x0c0) |
-			   ((line_l1 >> 7) & 0x300));
-		  cx |= (y & 1) << 11;
-
-		  pix = arith_decode(se, cx);
-		  if (pix < 0)
-		    goto leave;
-		}
-
-		line_h1 = (line_h1 << 1) | pix;
-		line_h2 <<= 1;
-		line_h3 <<= 1;
-
-	      } while ((++x & 1) && x < hx);
-	    line_l1 <<= 1; line_l2 <<= 1;  line_l3 <<= 1;
-	  } while ((x & 7) && x < hx);
-	  *hp++ = line_h1;
-	} while ((x & 15) && x < hx);
-	++lp1;
-	++lp2;
+            if (!s->lntp[plane][layer - s->dl] &&
+                (cx == 0x000 || cx == 0x1ff)) {
+              /* pixels are typical and have not to be decoded */
+              do {
+                line_h1 = (line_h1 << 1) | (cx & 1);
+              } while ((++x & 1) && x < hx);
+              line_h2 <<= 2;  line_h3 <<= 2;
+            } else
+              do {
+
+                /* deterministic prediction */
+                if (s->options & JBG_DPON)
+                  if ((y & 1) == 0)
+                    if ((x & 1) == 0)
+                      /* phase 0 */
+                      pix = s->dppriv[((line_l3 >> 15) & 0x003) |
+                                      ((line_l2 >> 13) & 0x00c) |
+                                      ((line_h1 <<  4) & 0x010) |
+                                      ((line_h2 >>  9) & 0x0e0)];
+                    else
+                      /* phase 1 */
+                      pix = s->dppriv[(((line_l3 >> 15) & 0x003) |
+                                       ((line_l2 >> 13) & 0x00c) |
+                                       ((line_h1 <<  4) & 0x030) |
+                                       ((line_h2 >>  9) & 0x1c0)) + 256];
+                  else
+                    if ((x & 1) == 0)
+                      /* phase 2 */
+                      pix = s->dppriv[(((line_l3 >> 15) & 0x003) |
+                                       ((line_l2 >> 13) & 0x00c) |
+                                       ((line_h1 <<  4) & 0x010) |
+                                       ((line_h2 >>  9) & 0x0e0) |
+                                       ((line_h3 >>  6) & 0x700)) + 768];
+                    else
+                      /* phase 3 */
+                      pix = s->dppriv[(((line_l3 >> 15) & 0x003) |
+                                       ((line_l2 >> 13) & 0x00c) |
+                                       ((line_h1 <<  4) & 0x030) |
+                                       ((line_h2 >>  9) & 0x1c0) |
+                                       ((line_h3 >>  6) & 0xe00)) + 2816];
+                else
+                  pix = 2;
+
+                if (pix & 2) {
+                  if (tx)
+                    cx = ((line_h1         & 0x003) |
+                          (((line_h1 << 2) >> (tx - 3)) & 0x010) |
+                          ((line_h2 >> 12) & 0x00c) |
+                          ((line_h3 >> 10) & 0x020));
+                  else
+                    cx = ((line_h1         & 0x003) |
+                          ((line_h2 >> 12) & 0x01c) |
+                          ((line_h3 >> 10) & 0x020));
+                  if (x & 1)
+                    cx |= (((line_l2 >> 8) & 0x0c0) |
+                           ((line_l1 >> 6) & 0x300)) | (1UL << 10);
+                  else
+                    cx |= (((line_l2 >> 9) & 0x0c0) |
+                           ((line_l1 >> 7) & 0x300));
+                  cx |= (y & 1) << 11;
+
+                  pix = arith_decode(se, cx);
+                  if (pix < 0)
+                    goto leave;
+                }
+
+                line_h1 = (line_h1 << 1) | pix;
+                line_h2 <<= 1;
+                line_h3 <<= 1;
+
+              } while ((++x & 1) && x < hx);
+            line_l1 <<= 1; line_l2 <<= 1;  line_l3 <<= 1;
+          } while ((x & 7) && x < hx);
+          *hp++ = line_h1;
+        } while ((x & 15) && x < hx);
+        ++lp1;
+        ++lp2;
       } /* while */
       x = 0;
 
       *(hp - 1) <<= hbpl * 8 - hx;
       if ((s->i & 1) == 0) {
-	/* low resolution pixels are used twice */
-	lp1 -= lbpl;
-	lp2 -= lbpl;
+        /* low resolution pixels are used twice */
+        lp1 -= lbpl;
+        lp2 -= lbpl;
       } else
-	s->pseudo = 1;
+        s->pseudo = 1;
 
     } /* for (i = ...) */
 
@@ -2528,6 +2553,7 @@ static size_t decode_pscd(struct jbg_dec_state *s, unsigned char *data,
 }
 
 
+
 /*
  * Provide to the decoder a new BIE fragment of len bytes starting at data.
  *
@@ -2563,7 +2589,7 @@ static size_t decode_pscd(struct jbg_dec_state *s, unsigned char *data,
  * information by identifying which test exactly has failed.)
  */
 int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len,
-	       size_t *cnt)
+               size_t *cnt)
 {
   int i, j, required_length;
   unsigned long x, y;
@@ -2595,18 +2621,18 @@ int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len,
       s->planes = s->buffer[2];
     else
       if (s->planes != s->buffer[2])
-	return JBG_ENOCONT | 2;
+        return JBG_ENOCONT | 2;
     x = (((long) s->buffer[ 4] << 24) | ((long) s->buffer[ 5] << 16) |
-	 ((long) s->buffer[ 6] <<  8) | (long) s->buffer[ 7]);
+         ((long) s->buffer[ 6] <<  8) | (long) s->buffer[ 7]);
     y = (((long) s->buffer[ 8] << 24) | ((long) s->buffer[ 9] << 16) |
-	 ((long) s->buffer[10] <<  8) | (long) s->buffer[11]);
+         ((long) s->buffer[10] <<  8) | (long) s->buffer[11]);
     if (s->dl != 0 && ((s->xd << (s->d - s->dl + 1)) != x &&
-		       (s->yd << (s->d - s->dl + 1)) != y))
+                       (s->yd << (s->d - s->dl + 1)) != y))
       return JBG_ENOCONT | 3;
     s->xd = x;
     s->yd = y;
     s->l0 = (((long) s->buffer[12] << 24) | ((long) s->buffer[13] << 16) |
-	     ((long) s->buffer[14] <<  8) | (long) s->buffer[15]);
+             ((long) s->buffer[14] <<  8) | (long) s->buffer[15]);
     /* ITU-T T.85 trick not directly implemented by decoder; for full
      * T.85 compatibility with respect to all NEWLEN marker scenarios,
      * preprocess BIE with jbg_newlen() before passing it to the decoder,
@@ -2647,51 +2673,51 @@ int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len,
     s->ii[iindex[s->order & 7][PLANE]] = 0;
     if (s->dl == 0) {
       s->s      = (struct jbg_ardec_state **)
-	checked_malloc(s->planes, sizeof(struct jbg_ardec_state *));
+        checked_malloc(s->planes, sizeof(struct jbg_ardec_state *));
       s->tx     = (int **) checked_malloc(s->planes, sizeof(int *));
       s->ty     = (int **) checked_malloc(s->planes, sizeof(int *));
       s->reset  = (int **) checked_malloc(s->planes, sizeof(int *));
       s->lntp   = (int **) checked_malloc(s->planes, sizeof(int *));
       s->lhp[0] = (unsigned char **)
-	checked_malloc(s->planes, sizeof(unsigned char *));
+        checked_malloc(s->planes, sizeof(unsigned char *));
       s->lhp[1] = (unsigned char **)
-	checked_malloc(s->planes, sizeof(unsigned char *));
+        checked_malloc(s->planes, sizeof(unsigned char *));
       for (i = 0; i < s->planes; i++) {
-	s->s[i]     = (struct jbg_ardec_state *)
-	  checked_malloc(s->d - s->dl + 1, sizeof(struct jbg_ardec_state));
-	s->tx[i]    = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int));
-	s->ty[i]    = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int));
-	s->reset[i] = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int));
-	s->lntp[i]  = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int));
-	s->lhp[ s->d    & 1][i] = (unsigned char *)
-	  checked_malloc(s->yd, jbg_ceil_half(s->xd, 3));
-	s->lhp[(s->d-1) & 1][i] = (unsigned char *)
-	  checked_malloc(jbg_ceil_half(s->yd, 1), jbg_ceil_half(s->xd, 1+3));
+        s->s[i]     = (struct jbg_ardec_state *)
+          checked_malloc(s->d - s->dl + 1, sizeof(struct jbg_ardec_state));
+        s->tx[i]    = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int));
+        s->ty[i]    = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int));
+        s->reset[i] = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int));
+        s->lntp[i]  = (int *) checked_malloc(s->d - s->dl + 1, sizeof(int));
+        s->lhp[ s->d    & 1][i] = (unsigned char *)
+          checked_malloc(s->yd, jbg_ceil_half(s->xd, 3));
+        s->lhp[(s->d-1) & 1][i] = (unsigned char *)
+          checked_malloc(jbg_ceil_half(s->yd, 1), jbg_ceil_half(s->xd, 1+3));
       }
     } else {
       for (i = 0; i < s->planes; i++) {
-	s->s[i]     = (struct jbg_ardec_state *)
-	  checked_realloc(s->s[i], s->d - s->dl + 1,
-			  sizeof(struct jbg_ardec_state));
-	s->tx[i]    = (int *) checked_realloc(s->tx[i],
-					      s->d - s->dl + 1, sizeof(int));
-	s->ty[i]    = (int *) checked_realloc(s->ty[i],
-					      s->d - s->dl + 1, sizeof(int));
-	s->reset[i] = (int *) checked_realloc(s->reset[i],
-					      s->d - s->dl + 1, sizeof(int));
-	s->lntp[i]  = (int *) checked_realloc(s->lntp[i],
-					      s->d - s->dl + 1, sizeof(int));
-	s->lhp[ s->d    & 1][i] = (unsigned char *)
-	  checked_realloc(s->lhp[ s->d    & 1][i],
-			  s->yd, jbg_ceil_half(s->xd, 3));
-	s->lhp[(s->d-1) & 1][i] = (unsigned char *)
-	  checked_realloc(s->lhp[(s->d-1) & 1][i],
-			  jbg_ceil_half(s->yd, 1), jbg_ceil_half(s->xd, 1+3));
+        s->s[i]     = (struct jbg_ardec_state *)
+          checked_realloc(s->s[i], s->d - s->dl + 1,
+                          sizeof(struct jbg_ardec_state));
+        s->tx[i]    = (int *) checked_realloc(s->tx[i],
+                                              s->d - s->dl + 1, sizeof(int));
+        s->ty[i]    = (int *) checked_realloc(s->ty[i],
+                                              s->d - s->dl + 1, sizeof(int));
+        s->reset[i] = (int *) checked_realloc(s->reset[i],
+                                              s->d - s->dl + 1, sizeof(int));
+        s->lntp[i]  = (int *) checked_realloc(s->lntp[i],
+                                              s->d - s->dl + 1, sizeof(int));
+        s->lhp[ s->d    & 1][i] = (unsigned char *)
+          checked_realloc(s->lhp[ s->d    & 1][i],
+                          s->yd, jbg_ceil_half(s->xd, 3));
+        s->lhp[(s->d-1) & 1][i] = (unsigned char *)
+          checked_realloc(s->lhp[(s->d-1) & 1][i],
+                          jbg_ceil_half(s->yd, 1), jbg_ceil_half(s->xd, 1+3));
       }
     }
     for (i = 0; i < s->planes; i++)
       for (j = 0; j <= s->d - s->dl; j++)
-	arith_decode_init(s->s[i] + j, 0);
+        arith_decode_init(s->s[i] + j, 0);
     if (s->dl == 0 || (s->options & JBG_DPON && !(s->options & JBG_DPPRIV)))
       s->dppriv = jbg_dptable;
     s->comment_skip = 0;
@@ -2730,11 +2756,11 @@ int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len,
     /* skip COMMENT contents */
     if (s->comment_skip) {
       if (s->comment_skip <= len - *cnt) {
-	*cnt += s->comment_skip;
-	s->comment_skip = 0;
+        *cnt += s->comment_skip;
+        s->comment_skip = 0;
       } else {
-	s->comment_skip -= len - *cnt;
-	*cnt = len;
+        s->comment_skip -= len - *cnt;
+        *cnt = len;
       }
       continue;
     }
@@ -2743,7 +2769,7 @@ int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len,
     if (s->buf_len > 0) {
       assert(s->buffer[0] == MARKER_ESC);
       while (s->buf_len < 2 && *cnt < len)
-	s->buffer[s->buf_len++] = data[(*cnt)++];
+        s->buffer[s->buf_len++] = data[(*cnt)++];
       if (s->buf_len < 2) continue;
       switch (s->buffer[1]) {
       case MARKER_COMMENT: required_length = 6; break;
@@ -2753,120 +2779,120 @@ int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len,
       case MARKER_SDNORM:
       case MARKER_SDRST:   required_length = 2; break;
       case MARKER_STUFF:
-	/* forward stuffed 0xff to arithmetic decoder */
-	s->buf_len = 0;
-	decode_pscd(s, s->buffer, 2);
-	continue;
+        /* forward stuffed 0xff to arithmetic decoder */
+        s->buf_len = 0;
+        decode_pscd(s, s->buffer, 2);
+        continue;
       default:
-	return JBG_EMARKER;
+        return JBG_EMARKER;
       }
       while (s->buf_len < required_length && *cnt < len)
-	s->buffer[s->buf_len++] = data[(*cnt)++];
+        s->buffer[s->buf_len++] = data[(*cnt)++];
       if (s->buf_len < required_length) continue;
       /* now the buffer is filled with exactly one marker segment */
       switch (s->buffer[1]) {
       case MARKER_COMMENT:
-	s->comment_skip =
-	  (((long) s->buffer[2] << 24) | ((long) s->buffer[3] << 16) |
-	   ((long) s->buffer[4] <<  8) | (long) s->buffer[5]);
-	break;
+        s->comment_skip =
+          (((long) s->buffer[2] << 24) | ((long) s->buffer[3] << 16) |
+           ((long) s->buffer[4] <<  8) | (long) s->buffer[5]);
+        break;
       case MARKER_ATMOVE:
-	if (s->at_moves < JBG_ATMOVES_MAX) {
-	  s->at_line[s->at_moves] =
-	    (((long) s->buffer[2] << 24) | ((long) s->buffer[3] << 16) |
-	     ((long) s->buffer[4] <<  8) | (long) s->buffer[5]);
-	  s->at_tx[s->at_moves] = (signed char) s->buffer[6];
-	  s->at_ty[s->at_moves] = s->buffer[7];
-	  if (s->at_tx[s->at_moves] < - (int) s->mx ||
-	      s->at_tx[s->at_moves] >   (int) s->mx ||
-	      s->at_ty[s->at_moves] >   (int) s->my ||
-	      (s->at_ty[s->at_moves] == 0 && s->at_tx[s->at_moves] < 0))
-	    return JBG_EINVAL | 11;
-	  if (s->at_ty[s->at_moves] != 0)
-	    return JBG_EIMPL | 6;
-	  s->at_moves++;
-	} else
-	  return JBG_EIMPL | 7; /* more than JBG_ATMOVES_MAX ATMOVES */
-	break;
+        if (s->at_moves < JBG_ATMOVES_MAX) {
+          s->at_line[s->at_moves] =
+            (((long) s->buffer[2] << 24) | ((long) s->buffer[3] << 16) |
+             ((long) s->buffer[4] <<  8) | (long) s->buffer[5]);
+          s->at_tx[s->at_moves] = (signed char) s->buffer[6];
+          s->at_ty[s->at_moves] = s->buffer[7];
+          if (s->at_tx[s->at_moves] < - (int) s->mx ||
+              s->at_tx[s->at_moves] >   (int) s->mx ||
+              s->at_ty[s->at_moves] >   (int) s->my ||
+              (s->at_ty[s->at_moves] == 0 && s->at_tx[s->at_moves] < 0))
+            return JBG_EINVAL | 11;
+          if (s->at_ty[s->at_moves] != 0)
+            return JBG_EIMPL | 6;
+          s->at_moves++;
+        } else
+          return JBG_EIMPL | 7; /* more than JBG_ATMOVES_MAX ATMOVES */
+        break;
       case MARKER_NEWLEN:
-	y = (((long) s->buffer[2] << 24) | ((long) s->buffer[3] << 16) |
-	     ((long) s->buffer[4] <<  8) | (long) s->buffer[5]);
-	if (y > s->yd)                   return JBG_EINVAL | 12;
-	if (!(s->options & JBG_VLENGTH)) return JBG_EINVAL | 13;
-	s->yd = y;
-	/* calculate again number of stripes that will be required */
-	s->stripes = jbg_stripes(s->l0, s->yd, s->d);
-	break;
+        y = (((long) s->buffer[2] << 24) | ((long) s->buffer[3] << 16) |
+             ((long) s->buffer[4] <<  8) | (long) s->buffer[5]);
+        if (y > s->yd)                   return JBG_EINVAL | 12;
+        if (!(s->options & JBG_VLENGTH)) return JBG_EINVAL | 13;
+        s->yd = y;
+        /* calculate again number of stripes that will be required */
+        s->stripes = jbg_stripes(s->l0, s->yd, s->d);
+        break;
       case MARKER_ABORT:
-	return JBG_EABORT;
+        return JBG_EABORT;
 
       case MARKER_SDNORM:
       case MARKER_SDRST:
-	/* decode final pixels based on trailing zero bytes */
-	decode_pscd(s, s->buffer, 2);
-
-	arith_decode_init(s->s[s->ii[iindex[s->order & 7][PLANE]]] +
-			  s->ii[iindex[s->order & 7][LAYER]] - s->dl,
-			  s->ii[iindex[s->order & 7][STRIPE]] != s->stripes - 1
-			  && s->buffer[1] != MARKER_SDRST);
-
-	s->reset[s->ii[iindex[s->order & 7][PLANE]]]
-	  [s->ii[iindex[s->order & 7][LAYER]] - s->dl] =
-	    (s->buffer[1] == MARKER_SDRST);
-
-	/* prepare for next SDE */
-	s->x = 0;
-	s->i = 0;
-	s->pseudo = 1;
-	s->at_moves = 0;
-
-	/* increment layer/stripe/plane loop variables */
-	/* start and end value for each loop: */
-	is[iindex[s->order & 7][STRIPE]] = 0;
-	ie[iindex[s->order & 7][STRIPE]] = s->stripes - 1;
-	is[iindex[s->order & 7][LAYER]] = s->dl;
-	ie[iindex[s->order & 7][LAYER]] = s->d;
-	is[iindex[s->order & 7][PLANE]] = 0;
-	ie[iindex[s->order & 7][PLANE]] = s->planes - 1;
-	i = 2;  /* index to innermost loop */
-	do {
-	  j = 0;  /* carry flag */
-	  if (++s->ii[i] > ie[i]) {
-	    /* handling overflow of loop variable */
-	    j = 1;
-	    if (i > 0)
-	      s->ii[i] = is[i];
-	  }
-	} while (--i >= 0 && j);
-
-	s->buf_len = 0;
-
-	/* check whether this have been all SDEs */
-	if (j) {
+        /* decode final pixels based on trailing zero bytes */
+        decode_pscd(s, s->buffer, 2);
+
+        arith_decode_init(s->s[s->ii[iindex[s->order & 7][PLANE]]] +
+                          s->ii[iindex[s->order & 7][LAYER]] - s->dl,
+                          s->ii[iindex[s->order & 7][STRIPE]] != s->stripes - 1
+                          && s->buffer[1] != MARKER_SDRST);
+
+        s->reset[s->ii[iindex[s->order & 7][PLANE]]]
+          [s->ii[iindex[s->order & 7][LAYER]] - s->dl] =
+            (s->buffer[1] == MARKER_SDRST);
+
+        /* prepare for next SDE */
+        s->x = 0;
+        s->i = 0;
+        s->pseudo = 1;
+        s->at_moves = 0;
+
+        /* increment layer/stripe/plane loop variables */
+        /* start and end value for each loop: */
+        is[iindex[s->order & 7][STRIPE]] = 0;
+        ie[iindex[s->order & 7][STRIPE]] = s->stripes - 1;
+        is[iindex[s->order & 7][LAYER]] = s->dl;
+        ie[iindex[s->order & 7][LAYER]] = s->d;
+        is[iindex[s->order & 7][PLANE]] = 0;
+        ie[iindex[s->order & 7][PLANE]] = s->planes - 1;
+        i = 2;  /* index to innermost loop */
+        do {
+          j = 0;  /* carry flag */
+          if (++s->ii[i] > ie[i]) {
+            /* handling overflow of loop variable */
+            j = 1;
+            if (i > 0)
+              s->ii[i] = is[i];
+          }
+        } while (--i >= 0 && j);
+
+        s->buf_len = 0;
+
+        /* check whether this have been all SDEs */
+        if (j) {
 #ifdef DEBUG
-	  fprintf(stderr, "This was the final SDE in this BIE, "
-		  "%ld bytes left.\n", (long) (len - *cnt));
+          fprintf(stderr, "This was the final SDE in this BIE, "
+                  "%ld bytes left.\n", (long) (len - *cnt));
 #endif
-	  s->bie_len = 0;
-	  return JBG_EOK;
-	}
-
-	/* check whether we have to abort because of xmax/ymax */
-	if (iindex[s->order & 7][LAYER] == 0 && i < 0) {
-	  /* LAYER is the outermost loop and we have just gone to next layer */
-	  if (jbg_ceil_half(s->xd, s->d - s->ii[0]) > s->xmax ||
-	      jbg_ceil_half(s->yd, s->d - s->ii[0]) > s->ymax) {
-	    s->xmax = 4294967295UL;
-	    s->ymax = 4294967295UL;
-	    return JBG_EOK_INTR;
-	  }
-	  if (s->ii[0] > (unsigned long) s->dmax) {
-	    s->dmax = 256;
-	    return JBG_EOK_INTR;
-	  }
-	}
-
-	break;
+          s->bie_len = 0;
+          return JBG_EOK;
+        }
+
+        /* check whether we have to abort because of xmax/ymax */
+        if (iindex[s->order & 7][LAYER] == 0 && i < 0) {
+          /* LAYER is the outermost loop and we have just gone to next layer */
+          if (jbg_ceil_half(s->xd, s->d - s->ii[0]) > s->xmax ||
+              jbg_ceil_half(s->yd, s->d - s->ii[0]) > s->ymax) {
+            s->xmax = 4294967295UL;
+            s->ymax = 4294967295UL;
+            return JBG_EOK_INTR;
+          }
+          if (s->ii[0] > (unsigned long) s->dmax) {
+            s->dmax = 256;
+            return JBG_EOK_INTR;
+          }
+        }
+
+        break;
       }
       s->buf_len = 0;
 
@@ -2879,11 +2905,11 @@ int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len,
       *cnt += decode_pscd(s, data + *cnt, len - *cnt);
       if (*cnt < len && data[*cnt] != 0xff) {
 #ifdef DEBUG
-	fprintf(stderr, "PSCD was longer than expected, unread bytes "
-		"%02x %02x %02x %02x ...\n", data[*cnt], data[*cnt+1],
-		data[*cnt+2], data[*cnt+3]);
+        fprintf(stderr, "PSCD was longer than expected, unread bytes "
+                "%02x %02x %02x %02x ...\n", data[*cnt], data[*cnt+1],
+                data[*cnt+2], data[*cnt+3]);
 #endif
-	return JBG_EINVAL | 14;
+        return JBG_EINVAL | 14;
       }
 
     }
@@ -2893,6 +2919,7 @@ int jbg_dec_in(struct jbg_dec_state *s, unsigned char *data, size_t len,
 }
 
 
+
 /*
  * After jbg_dec_in() returned JBG_EOK or JBG_EOK_INTR, you can call this
  * function in order to find out the width of the image. Returns 0 if
@@ -2913,6 +2940,7 @@ unsigned long jbg_dec_getwidth(const struct jbg_dec_state *s)
 }
 
 
+
 /*
  * After jbg_dec_in() returned JBG_EOK or JBG_EOK_INTR, you can call this
  * function in order to find out the height of the image. Returns 0 if
@@ -2933,6 +2961,7 @@ unsigned long jbg_dec_getheight(const struct jbg_dec_state *s)
 }
 
 
+
 /*
  * After jbg_dec_in() returned JBG_EOK or JBG_EOK_INTR, you can call this
  * function in order to get a pointer to the image. Returns NULL if
@@ -2953,6 +2982,7 @@ unsigned char *jbg_dec_getimage(const struct jbg_dec_state *s, int plane)
 }
 
 
+
 /*
  * After jbg_dec_in() returned JBG_EOK or JBG_EOK_INTR, you can call
  * this function in order to find out the size in bytes of one
@@ -2967,14 +2997,15 @@ unsigned long jbg_dec_getsize(const struct jbg_dec_state *s)
       return 0;
     else
       return
-	jbg_ceil_half(s->xd, s->d - (s->ii[0] - 1) + 3) * /* overflow risk? */
-	jbg_ceil_half(s->yd, s->d - (s->ii[0] - 1));
+        jbg_ceil_half(s->xd, s->d - (s->ii[0] - 1) + 3) * /* overflow risk? */
+        jbg_ceil_half(s->yd, s->d - (s->ii[0] - 1));
   }
 
   return jbg_ceil_half(s->xd, 3) * s->yd;
 }
 
 
+
 /*
  * After jbg_dec_in() returned JBG_EOK or JBG_EOK_INTR, you can call
  * this function in order to find out the size of the image that you
@@ -2989,15 +3020,16 @@ unsigned long jbg_dec_getsize_merged(const struct jbg_dec_state *s)
       return 0;
     else
       return
-	jbg_ceil_half(s->xd, s->d - (s->ii[0] - 1)) * /* overflow risk? */
-	jbg_ceil_half(s->yd, s->d - (s->ii[0] - 1)) *
-	((s->planes + 7) / 8);
+        jbg_ceil_half(s->xd, s->d - (s->ii[0] - 1)) * /* overflow risk? */
+        jbg_ceil_half(s->yd, s->d - (s->ii[0] - 1)) *
+        ((s->planes + 7) / 8);
   }
 
   return s->xd * s->yd * ((s->planes + 7) / 8);
 }
 
 
+
 /*
  * The destructor function which releases any resources obtained by the
  * other decoder functions.
@@ -3036,6 +3068,7 @@ void jbg_dec_free(struct jbg_dec_state *s)
 }
 
 
+
 /*
  * Split bigendian integer pixel field into separate bit planes. In the
  * src array, every pixel is represented by a ((has_planes + 7) / 8) byte
@@ -3045,9 +3078,9 @@ void jbg_dec_free(struct jbg_dec_state *s)
  * actually transfer to dest.
  */
 void jbg_split_planes(unsigned long x, unsigned long y, int has_planes,
-		      int encode_planes,
-		      const unsigned char *src, unsigned char **dest,
-		      int use_graycode)
+                      int encode_planes,
+                      const unsigned char *src, unsigned char **dest,
+                      int use_graycode)
 {
   unsigned long bpl = jbg_ceil_half(x, 3);  /* bytes per line in dest plane */
   unsigned long line, i;
@@ -3068,29 +3101,29 @@ void jbg_split_planes(unsigned long x, unsigned long y, int has_planes,
   for (line = 0; line < y; line++) {                 /* lines loop */
     for (i = 0; i * 8 < x; i++) {                    /* dest bytes loop */
       for (k = 0; k < 8 && i * 8 + k < x; k++) {     /* pixel loop */
-	prev = 0;
-	for (p = 0; p < encode_planes; p++) {        /* bit planes loop */
-	  /* calculate which bit in *src do we want */
-	  bitno = (msb - p) & 7;
-	  /* put this bit with its left neighbor right adjusted into bits */
-	  bits = (prev | *src) >> bitno;
-	  /* go to next *src byte, but keep old */
-	  if (bitno == 0)
-	    prev = *src++ << 8;
-	  /* make space for inserting new bit */
-	  dest[p][bpl * line + i] <<= 1;
-	  /* insert bit, if requested apply Gray encoding */
-	  dest[p][bpl * line + i] |= (bits ^ (use_graycode & (bits>>1))) & 1;
-	  /*
-	   * Theorem: Let b(n),...,b(1),b(0) be the digits of a
-	   * binary word and let g(n),...,g(1),g(0) be the digits of the
-	   * corresponding Gray code word, then g(i) = b(i) xor b(i+1).
-	   */
-	}
-	/* skip unused *src bytes */
-	for (;p < has_planes; p++)
-	  if (((msb - p) & 7) == 0)
-	    src++;
+        prev = 0;
+        for (p = 0; p < encode_planes; p++) {        /* bit planes loop */
+          /* calculate which bit in *src do we want */
+          bitno = (msb - p) & 7;
+          /* put this bit with its left neighbor right adjusted into bits */
+          bits = (prev | *src) >> bitno;
+          /* go to next *src byte, but keep old */
+          if (bitno == 0)
+            prev = *src++ << 8;
+          /* make space for inserting new bit */
+          dest[p][bpl * line + i] <<= 1;
+          /* insert bit, if requested apply Gray encoding */
+          dest[p][bpl * line + i] |= (bits ^ (use_graycode & (bits>>1))) & 1;
+          /*
+           * Theorem: Let b(n),...,b(1),b(0) be the digits of a
+           * binary word and let g(n),...,g(1),g(0) be the digits of the
+           * corresponding Gray code word, then g(i) = b(i) xor b(i+1).
+           */
+        }
+        /* skip unused *src bytes */
+        for (;p < has_planes; p++)
+          if (((msb - p) & 7) == 0)
+            src++;
       }
     }
     for (p = 0; p < encode_planes; p++)              /* right padding loop */
@@ -3100,14 +3133,16 @@ void jbg_split_planes(unsigned long x, unsigned long y, int has_planes,
   return;
 }
 
+
+
 /*
  * Merge the separate bit planes decoded by the JBIG decoder into an
  * integer pixel field. This is essentially the counterpart to
  * jbg_split_planes().
  */
 void jbg_dec_merge_planes(const struct jbg_dec_state *s, int use_graycode,
-			  void (*data_out)(unsigned char *start, size_t len,
-					   void *file), void *file)
+                          void (*data_out)(unsigned char *start, size_t len,
+                                           void *file), void *file)
 {
 #define BUFLEN 4096
   unsigned long bpl, line, i;
@@ -3139,19 +3174,19 @@ void jbg_dec_merge_planes(const struct jbg_dec_state *s, int use_graycode,
   for (line = 0; line < y; line++) {                    /* lines loop */
     for (i = 0; i * 8 < x; i++) {                       /* src bytes loop */
       for (k = 0; k < 8 && i * 8 + k < x; k++) {        /* pixel loop */
-	v = 0;
-	for (p = 0; p < s->planes;) {                   /* dest bytes loop */
-	  do {
-	    v = (v << 1) |
-	      (((src[p][bpl * line + i] >> (7 - k)) & 1) ^
-	       (use_graycode & v));
-	  } while ((s->planes - ++p) & 7);
-	  *bp++ = v;
-	  if (bp - buf == BUFLEN) {
-	    data_out(buf, BUFLEN, file);
-	    bp = buf;
-	  }
-	}
+        v = 0;
+        for (p = 0; p < s->planes;) {                   /* dest bytes loop */
+          do {
+            v = (v << 1) |
+              (((src[p][bpl * line + i] >> (7 - k)) & 1) ^
+               (use_graycode & v));
+          } while ((s->planes - ++p) & 7);
+          *bp++ = v;
+          if (bp - buf == BUFLEN) {
+            data_out(buf, BUFLEN, file);
+            bp = buf;
+          }
+        }
       }
     }
   }
@@ -3163,6 +3198,7 @@ void jbg_dec_merge_planes(const struct jbg_dec_state *s, int use_graycode,
 }
 
 
+
 /*
  * Given a pointer p to the first byte of either a marker segment or a
  * PSCD, as well as the length len of the remaining data, return
@@ -3186,15 +3222,15 @@ static unsigned char *jbg_next_pscdms(unsigned char *p, size_t len)
   if (p[0] != MARKER_ESC || p[1] == MARKER_STUFF) {
     do {
       while (p[0] == MARKER_ESC && p[1] == MARKER_STUFF) {
-	p += 2;
-	len -= 2;
-	if (len < 2)
-	  return NULL; /* not enough bytes left for complete marker segment */
+        p += 2;
+        len -= 2;
+        if (len < 2)
+          return NULL; /* not enough bytes left for complete marker segment */
       }
       assert(len >= 2);
       pp = (unsigned char *) memchr(p, MARKER_ESC, len - 1);
       if (!pp)
-	return NULL; /* no marker segment terminates the PSCD */
+        return NULL; /* no marker segment terminates the PSCD */
       l = pp - p;
       assert(l < len);
       p += l;
@@ -3208,19 +3244,19 @@ static unsigned char *jbg_next_pscdms(unsigned char *p, size_t len)
       return p + 2;
     case MARKER_NEWLEN:
       if (len < 6)
-	return NULL; /* not enough bytes left for complete marker segment */
+        return NULL; /* not enough bytes left for complete marker segment */
       return p + 6;
     case MARKER_ATMOVE:
       if (len < 8)
-	return NULL; /* not enough bytes left for complete marker segment */
+        return NULL; /* not enough bytes left for complete marker segment */
       return p + 8;
     case MARKER_COMMENT:
       if (len < 6)
-	return NULL; /* not enough bytes left for complete marker segment */
+        return NULL; /* not enough bytes left for complete marker segment */
       l = (((long) p[2] << 24) | ((long) p[3] << 16) |
-	   ((long) p[4] <<  8) |  (long) p[5]);
+           ((long) p[4] <<  8) |  (long) p[5]);
       if (len - 6 < l)
-	return NULL; /* not enough bytes left for complete marker segment */
+        return NULL; /* not enough bytes left for complete marker segment */
       return p + 6 + l;
     default:
       /* unknown marker sequence encountered */
@@ -3232,6 +3268,7 @@ static unsigned char *jbg_next_pscdms(unsigned char *p, size_t len)
 }
 
 
+
 /*
  * Scan a complete BIE for a NEWLEN marker segment, then read the new
  * YD value found in it and use it to overwrite the one in the BIE
@@ -3265,19 +3302,22 @@ int jbg_newlen(unsigned char *bie, size_t len)
     else if (p[0] == MARKER_ESC)
       switch (p[1]) {
       case MARKER_NEWLEN:
-	y = (((long) bie[ 8] << 24) | ((long) bie[ 9] << 16) |
-	     ((long) bie[10] <<  8) |  (long) bie[11]);
-	yn = (((long) p[2] << 24) | ((long) p[3] << 16) |
-	      ((long) p[4] <<  8) |  (long) p[5]);
-	if (yn > y) return JBG_EINVAL | 12;
-	/* overwrite YD in BIH with YD from NEWLEN */
-	for (i = 0; i < 4; i++) {
-	  bie[8+i] = p[2+i];
-	}
-	return JBG_EOK;
+        y = (((long) bie[ 8] << 24) | ((long) bie[ 9] << 16) |
+             ((long) bie[10] <<  8) |  (long) bie[11]);
+        yn = (((long) p[2] << 24) | ((long) p[3] << 16) |
+              ((long) p[4] <<  8) |  (long) p[5]);
+        if (yn > y) return JBG_EINVAL | 12;
+        /* overwrite YD in BIH with YD from NEWLEN */
+        for (i = 0; i < 4; i++) {
+          bie[8+i] = p[2+i];
+        }
+        return JBG_EOK;
       case MARKER_ABORT:
-	return JBG_EABORT;
+        return JBG_EABORT;
       }
   }
   return JBG_EINVAL | 0;
 }
+
+
+
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;
 }
+
+
+
diff --git a/converter/other/jbig/pnmtojbig.c b/converter/other/jbig/pnmtojbig.c
index f5188c7b..ebdb4993 100644
--- a/converter/other/jbig/pnmtojbig.c
+++ b/converter/other/jbig/pnmtojbig.c
@@ -1,6 +1,6 @@
 /*
     pnmtojbig - PNM to JBIG converter
-  
+
     This program was derived from pbmtojbg.c in Markus Kuhn's
     JBIG-KIT package by Bryan Henderson on 2000.05.11
 
@@ -34,7 +34,7 @@
      bits in it.
 
 */
-  
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
@@ -44,7 +44,7 @@
 #include "mallocvar.h"
 #include "pnm.h"
 
-static unsigned long total_length = 0;  
+static unsigned long total_length = 0;
   /* used for determining output file length */
 
 /*
@@ -54,16 +54,17 @@ static void
 *checkedmalloc(size_t n)
 {
   void *p;
-  
+
   if ((p = malloc(n)) == NULL) {
     fprintf(stderr, "Sorry, not enough memory available!\n");
     exit(1);
   }
-  
+
   return p;
 }
 
 
+
 /*
  * Callback procedure which is used by JBIG encoder to deliver the
  * encoded data. It simply sends the bytes to the output file.
@@ -92,13 +93,13 @@ readPbm(FILE *            const fin,
     int row;
     bitmap = (unsigned char **) checkedmalloc(sizeof(unsigned char *));
     bitmap[0] = (unsigned char *) checkedmalloc(bytes_per_line * rows);
-    
+
     for (row = 0; row < rows; row++)
         pbm_readpbmrow_packed(fin, &bitmap[0][row*bytes_per_line],
                               cols, RPBM_FORMAT);
 
     *bitmapP = bitmap;
-} 
+}
 
 
 
@@ -121,7 +122,7 @@ readImage(FILE * const fin,
            pixel.  The 'bpp' bytes for each pixel are arranged MSB first
            and its numerical value is the value from the PNM input.
            The pixels are laid out in row-major format in this rectangle.
-           
+
            The point of this data structure is it is what jbg_split_planes()
            wants for input.
         */
@@ -130,7 +131,7 @@ readImage(FILE * const fin,
 
     pnm_row = pnm_allocrow(cols);  /* row buffer */
     MALLOCARRAY_NOFAIL(image, cols * rows * bpp);
-    
+
     for (row = 0; row < rows; ++row) {
         unsigned int col;
         pnm_readpnmrow(fin, pnm_row, cols, maxval, format);
@@ -145,7 +146,7 @@ readImage(FILE * const fin,
     pnm_freerow(pnm_row);
     *imageP = image;
 }
-      
+
 
 
 static void
@@ -154,12 +155,12 @@ convertImageToBitmap(unsigned char *   const image,
                      unsigned int      const encode_planes,
                      unsigned int      const bytes_per_line,
                      unsigned int      const lines) {
-    
+
     /* Convert image[] into bitmap[]  */
-    
+
     unsigned char ** bitmap;
     unsigned int i;
-    
+
     MALLOCARRAY_NOFAIL(bitmap, encode_planes);
     for (i = 0; i < encode_planes; ++i)
         MALLOCARRAY_NOFAIL(bitmap[i], bytes_per_line * lines);
@@ -193,10 +194,10 @@ readPnm(FILE *            const fin,
     jbg_split_planes(cols, rows, planes, encode_planes, image, bitmap,
                      use_graycode);
     free(image);
-    
+
     /* Invert the image if it is just one plane.  See top of this file
        for an explanation why.  Because of the separate handling of PBM,
-       this is for exceptional PGM files.  
+       this is for exceptional PGM files.
     */
 
     if (encode_planes == 1) {
@@ -206,7 +207,7 @@ readPnm(FILE *            const fin,
             for (i = 0; i < bytes_per_line; i++)
                 bitmap[0][(row*bytes_per_line) + i] ^= 0xff;
 
-            if (cols % 8 > 0) {   
+            if (cols % 8 > 0) {
                 bitmap[0][ (row+1)*bytes_per_line  -1] >>= 8-cols%8;
                 bitmap[0][ (row+1)*bytes_per_line  -1] <<= 8-cols%8;
             }
@@ -230,7 +231,7 @@ main(int argc, char **argv) {
     unsigned char **bitmap;
     /* This is an array of the planes of the image.  Each plane is a
        two-dimensional array of pixels laid out in row-major format.
-       format with each pixel being one bit.  A byte in the array 
+       format with each pixel being one bit.  A byte in the array
        contains 8 pixels left to right, msb to lsb.
     */
 
@@ -372,8 +373,8 @@ main(int argc, char **argv) {
     /* In a JBIG file, maxvals are determined only by the number of planes,
        so must be a power of 2 minus 1
     */
-  
-    if ((1UL << planes)-1 != maxval) 
+
+    if ((1UL << planes)-1 != maxval)
         pm_error("Input image has unacceptable maxval: %d.  JBIG files must "
                  "have a maxval which is a power of 2 minus 1.  Use "
                  "Ppmdepth to adjust the image's maxval", maxval);
@@ -386,8 +387,8 @@ main(int argc, char **argv) {
     if (bpp == 1 && PNM_FORMAT_TYPE(format) == PBM_TYPE)
         readPbm(fin, cols, rows, &bitmap);
     else
-        readPnm(fin, cols, rows, maxval, format, bpp, 
-                planes, encode_planes, use_graycode, 
+        readPnm(fin, cols, rows, maxval, format, bpp,
+                planes, encode_planes, use_graycode,
                 &bitmap);
 
     /* Apply JBIG algorithm and write BIE to output file */
@@ -461,3 +462,6 @@ main(int argc, char **argv) {
 
     return 0;
 }
+
+
+