about summary refs log tree commit diff
path: root/converter/other/fiasco/input
diff options
context:
space:
mode:
Diffstat (limited to 'converter/other/fiasco/input')
-rw-r--r--converter/other/fiasco/input/basis.c2
-rw-r--r--converter/other/fiasco/input/read.c8
-rw-r--r--converter/other/fiasco/input/weights.c204
3 files changed, 111 insertions, 103 deletions
diff --git a/converter/other/fiasco/input/basis.c b/converter/other/fiasco/input/basis.c
index cef075e6..4a748f61 100644
--- a/converter/other/fiasco/input/basis.c
+++ b/converter/other/fiasco/input/basis.c
@@ -16,6 +16,8 @@
 
 #include "config.h"
 
+#include "nstring.h"
+
 #include "types.h"
 #include "macros.h"
 #include "error.h"
diff --git a/converter/other/fiasco/input/read.c b/converter/other/fiasco/input/read.c
index 26bae7e4..e6e2d7e8 100644
--- a/converter/other/fiasco/input/read.c
+++ b/converter/other/fiasco/input/read.c
@@ -23,6 +23,8 @@
 
 #include <string.h>
 
+#include "nstring.h"
+
 #include "types.h"
 #include "macros.h"
 #include "error.h"
@@ -155,7 +157,7 @@ open_wfa (const char *filename, wfa_info_t *wi)
 	 unsigned lx = log2 (wi->width - 1) + 1;
 	 unsigned ly = log2 (wi->height - 1) + 1;
       
-	 wi->level = max (lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0);
+	 wi->level = MAX(lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0);
       }
       wi->chroma_max_states = wi->color ? read_rice_code (rice_k, input) : -1;
       wi->p_min_level       = read_rice_code (rice_k, input);
@@ -275,7 +277,7 @@ read_basis (const char *filename, wfa_t *wfa)
     *   string		|MAGIC Number "Wfa"
     *	int		|Number of basis states 'N'
     *	bool_t-array[N]	|use vector in linear combinations,
-    *			|0: don't use vector (auxilliary state)
+    *			|0: don't use vector (auxiliary state)
     *			|1: use vector in linear combinations
     *	float-array[N]	|final distribution of every state
     *
@@ -395,7 +397,7 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input)
 
    /*
     *  Compute domain pool.
-    *  Large images have not been used due to image tiling.
+    *  Large images have not been used because of image tiling.
     */
    {
       unsigned state;
diff --git a/converter/other/fiasco/input/weights.c b/converter/other/fiasco/input/weights.c
index 55339980..15c35731 100644
--- a/converter/other/fiasco/input/weights.c
+++ b/converter/other/fiasco/input/weights.c
@@ -1,8 +1,8 @@
 /*
- *  weights.c:		Input of weights
+ *  weights.c:          Input of weights
  *
- *  Written by:		Ullrich Hafner
- *		
+ *  Written by:         Ullrich Hafner
+ *              
  *  This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec)
  *  Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de>
  */
@@ -16,6 +16,8 @@
 
 #include "config.h"
 
+#include "pm_c_util.h"
+
 #include "types.h"
 #include "macros.h"
 #include "error.h"
@@ -29,7 +31,7 @@
 
 /*****************************************************************************
 
-				public code
+                                public code
   
 *****************************************************************************/
 
@@ -42,17 +44,17 @@ read_weights (unsigned total, wfa_t *wfa, bitfile_t *input)
  *  No return value.
  *
  *  Side effects:
- *	'wfa->weights' are filled with the decoded values
+ *      'wfa->weights' are filled with the decoded values
  */
 {
-   unsigned	    state;
-   unsigned	    label;
-   unsigned	    edge;		/* current edge */
-   unsigned	   *weights_array;	/* array of weights to encode */
-   unsigned	   *level_array;	/* array of corresponding levels */
-   unsigned	    offset1, offset2;	/* prob. model offsets. */
-   unsigned	    offset3, offset4;	/* prob. model offsets. */
-   bool_t	    delta_approx = NO; 	/* true if delta has been used */
+   unsigned         state;
+   unsigned         label;
+   unsigned         edge;               /* current edge */
+   unsigned        *weights_array;      /* array of weights to encode */
+   unsigned        *level_array;        /* array of corresponding levels */
+   unsigned         offset1, offset2;   /* prob. model offsets. */
+   unsigned         offset3, offset4;   /* prob. model offsets. */
+   bool_t           delta_approx = NO;  /* true if delta has been used */
    
    /*
     *  Check whether delta approximation has been used
@@ -60,52 +62,54 @@ read_weights (unsigned total, wfa_t *wfa, bitfile_t *input)
    for (state = wfa->basis_states; state < wfa->states; state++)
       if (wfa->delta_state [state])
       {
-	 delta_approx = YES;
-	 break;
+         delta_approx = YES;
+         break;
       }
   
    /*
     *  Generate array of corresponding levels (context of probability model)
     */
    {
-      int 	min_level, max_level; 	/* min and max range level */
-      int 	d_min_level, d_max_level; /* min and max range level (delta) */
-      unsigned *lptr;			/* pointer to current corresp. level */
-      int	domain;			/* current domain */
-      bool_t	dc, d_dc;		/* indicates whether DC is used */
+      int       min_level, max_level;   /* min and max range level */
+      int       d_min_level, d_max_level; /* min and max range level (delta) */
+      unsigned *lptr;                   /* pointer to current corresp. level */
+      int       domain;                 /* current domain */
+      bool_t    dc, d_dc;               /* indicates whether DC is used */
 
       /*
        *  Compute minimum and maximum level of delta and normal approximations
        */
       min_level = d_min_level = MAXLEVEL;
       max_level = d_max_level = 0;
-      dc 	= d_dc	   = NO;
+      dc        = d_dc     = NO;
    
       for (state = wfa->basis_states; state < wfa->states; state++)
-	 for (label = 0; label < MAXLABELS; label++)
-	    if (isrange (wfa->tree [state][label]))
-	    {
-	       if (delta_approx && wfa->delta_state [state])
-	       {
-		  d_min_level = min (d_min_level,
-				     wfa->level_of_state [state] - 1);
-		  d_max_level = max (d_max_level,
-				     wfa->level_of_state [state] - 1);
-		  if (wfa->into [state][label][0] == 0)
-		     d_dc = YES;
-	       }
-	       else
-	       {
-		  min_level = min (min_level, wfa->level_of_state [state] - 1);
-		  max_level = max (max_level, wfa->level_of_state [state] - 1);
-		  if (wfa->into [state][label][0] == 0)
-		     dc = YES;
-	       }
-	    }
-      if (min_level > max_level)		/* no lc found */
-	 max_level = min_level - 1;
+          for (label = 0; label < MAXLABELS; label++)
+              if (isrange (wfa->tree [state][label]))
+              {
+                  if (delta_approx && wfa->delta_state [state])
+                  {
+                      d_min_level =
+                          MIN(d_min_level, wfa->level_of_state [state] - 1);
+                      d_max_level =
+                          MAX(d_max_level, wfa->level_of_state [state] - 1);
+                      if (wfa->into [state][label][0] == 0)
+                          d_dc = YES;
+                  }
+                  else
+                  {
+                      min_level =
+                          MIN(min_level, wfa->level_of_state [state] - 1);
+                      max_level =
+                          MAX(max_level, wfa->level_of_state [state] - 1);
+                      if (wfa->into [state][label][0] == 0)
+                          dc = YES;
+                  }
+              }
+      if (min_level > max_level)                /* no lc found */
+         max_level = min_level - 1;
       if (d_min_level > d_max_level)
-	 d_max_level = d_min_level - 1;
+         d_max_level = d_min_level - 1;
 
       offset1 = dc ? 1 : 0;
       offset2 = offset1 + (d_dc ? 1 : 0);
@@ -114,47 +118,47 @@ read_weights (unsigned total, wfa_t *wfa, bitfile_t *input)
 
       lptr = level_array = Calloc (total, sizeof (int));
       for (state = wfa->basis_states; state < wfa->states; state++)
-	 for (label = 0; label < MAXLABELS; label++)
-	    if (isrange (wfa->tree[state][label]))
-	       for (edge = 0; isedge (domain = wfa->into[state][label][edge]);
-		    edge++)
-	       {
-		  if ((unsigned) (lptr - level_array) >= total)
-		     error ("Can't read more than %d weights.", total);
-		  if (domain)
-		  {
-		     if (delta_approx && wfa->delta_state [state])
-			*lptr++ = offset3 + wfa->level_of_state [state]
-				  - 1 - d_min_level;
-		     else
-			*lptr++ = offset2 + wfa->level_of_state [state]
-				  - 1 - min_level;
-		  }
-		  else
-		     *lptr++ = delta_approx && wfa->delta_state [state]
-			       ? offset1 : 0;
-	       }
+         for (label = 0; label < MAXLABELS; label++)
+            if (isrange (wfa->tree[state][label]))
+               for (edge = 0; isedge (domain = wfa->into[state][label][edge]);
+                    edge++)
+               {
+                  if ((unsigned) (lptr - level_array) >= total)
+                     error ("Can't read more than %d weights.", total);
+                  if (domain)
+                  {
+                     if (delta_approx && wfa->delta_state [state])
+                        *lptr++ = offset3 + wfa->level_of_state [state]
+                                  - 1 - d_min_level;
+                     else
+                        *lptr++ = offset2 + wfa->level_of_state [state]
+                                  - 1 - min_level;
+                  }
+                  else
+                     *lptr++ = delta_approx && wfa->delta_state [state]
+                               ? offset1 : 0;
+               }
    }
 
    /*
     *  Decode the list of weights with an arithmetic decoder
     */
    {
-      unsigned	      i;
-      unsigned	     *c_symbols = Calloc (offset4, sizeof (unsigned));
-      const unsigned  scale 	= 500; 	/* scaling of probability model */
+      unsigned        i;
+      unsigned       *c_symbols = Calloc (offset4, sizeof (unsigned));
+      const unsigned  scale     = 500;  /* scaling of probability model */
 
       c_symbols [0] = 1 << (wfa->wfainfo->dc_rpf->mantissa_bits + 1);
       if (offset1 != offset2)
-	 c_symbols [offset1] = 1 << (wfa->wfainfo->d_dc_rpf->mantissa_bits
-				     + 1);
+         c_symbols [offset1] = 1 << (wfa->wfainfo->d_dc_rpf->mantissa_bits
+                                     + 1);
       for (i = offset2; i < offset3; i++)
-	 c_symbols [i] = 1 << (wfa->wfainfo->rpf->mantissa_bits + 1);
+         c_symbols [i] = 1 << (wfa->wfainfo->rpf->mantissa_bits + 1);
       for (; i < offset4; i++)
-	 c_symbols [i] = 1 << (wfa->wfainfo->d_rpf->mantissa_bits + 1);
+         c_symbols [i] = 1 << (wfa->wfainfo->d_rpf->mantissa_bits + 1);
       
       weights_array = decode_array (input, level_array, c_symbols,
-				    offset4, total, scale);
+                                    offset4, total, scale);
       Free (c_symbols);
    }
    Free (level_array);
@@ -163,36 +167,36 @@ read_weights (unsigned total, wfa_t *wfa, bitfile_t *input)
     *  Update transitions with decoded weights
     */
    {
-      unsigned *wptr = weights_array;	/* pointer to current weight */
-      int	domain;			/* current domain */
+      unsigned *wptr = weights_array;   /* pointer to current weight */
+      int       domain;                 /* current domain */
 
       for (state = wfa->basis_states; state < wfa->states; state++)
-	 for (label = 0; label < MAXLABELS; label++)
-	    if (isrange (wfa->tree[state][label]))
-	       for (edge = 0; isedge (domain = wfa->into[state][label][edge]);
-		    edge++)
-	       {
-		  if (domain)		/* not DC component */
-		  {
-		     if (delta_approx && wfa->delta_state [state])
-			wfa->weight [state][label][edge]
-			   = btor (*wptr++, wfa->wfainfo->d_rpf);
-		     else
-			wfa->weight [state][label][edge]
-			   = btor (*wptr++, wfa->wfainfo->rpf);
-		  }
-		  else
-		  {
-		     if (delta_approx && wfa->delta_state [state])
-			wfa->weight [state][label][edge]
-			   = btor (*wptr++, wfa->wfainfo->d_dc_rpf);
-		     else
-			wfa->weight [state][label][edge]
-			   = btor (*wptr++, wfa->wfainfo->dc_rpf);
-		  }
-		  wfa->int_weight [state][label][edge]
-		     = wfa->weight [state][label][edge] * 512 + 0.5;
-	       }
+         for (label = 0; label < MAXLABELS; label++)
+            if (isrange (wfa->tree[state][label]))
+               for (edge = 0; isedge (domain = wfa->into[state][label][edge]);
+                    edge++)
+               {
+                  if (domain)           /* not DC component */
+                  {
+                     if (delta_approx && wfa->delta_state [state])
+                        wfa->weight [state][label][edge]
+                           = btor (*wptr++, wfa->wfainfo->d_rpf);
+                     else
+                        wfa->weight [state][label][edge]
+                           = btor (*wptr++, wfa->wfainfo->rpf);
+                  }
+                  else
+                  {
+                     if (delta_approx && wfa->delta_state [state])
+                        wfa->weight [state][label][edge]
+                           = btor (*wptr++, wfa->wfainfo->d_dc_rpf);
+                     else
+                        wfa->weight [state][label][edge]
+                           = btor (*wptr++, wfa->wfainfo->dc_rpf);
+                  }
+                  wfa->int_weight [state][label][edge]
+                     = wfa->weight [state][label][edge] * 512 + 0.5;
+               }
    }
    
    Free (weights_array);