about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2012-02-12 20:40:29 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2012-02-12 20:40:29 +0000
commit47e6714f1bb9be3587d5c76d5638887b595e6355 (patch)
treea691961ad493be82b6c9b206304a458bd603a9e4
parent7270a56af11a9bf5ac18baa50dc8fedbd545af7f (diff)
downloadnetpbm-mirror-47e6714f1bb9be3587d5c76d5638887b595e6355.tar.gz
netpbm-mirror-47e6714f1bb9be3587d5c76d5638887b595e6355.tar.xz
netpbm-mirror-47e6714f1bb9be3587d5c76d5638887b595e6355.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1643 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/other/fiasco/binerror.c8
-rw-r--r--converter/other/fiasco/codec/coder.c159
-rw-r--r--converter/other/fiasco/codec/decoder.c26
-rw-r--r--converter/other/fiasco/codec/dfiasco.c5
-rw-r--r--converter/other/fiasco/codec/domain-pool.c6
-rw-r--r--converter/other/fiasco/codec/motion.c6
-rw-r--r--converter/other/fiasco/codec/mwfa.c10
-rw-r--r--converter/other/fiasco/codec/subdivide.c48
-rw-r--r--converter/other/fiasco/codec/tiling.c4
-rw-r--r--converter/other/fiasco/codec/wfalib.c6
-rw-r--r--converter/other/fiasco/fiascotopnm.c8
-rw-r--r--converter/other/fiasco/input/read.c2
-rw-r--r--converter/other/fiasco/input/weights.c204
-rw-r--r--converter/other/fiasco/lib/error.c24
-rw-r--r--converter/other/fiasco/lib/macros.h11
-rw-r--r--converter/other/fiasco/lib/misc.c6
-rw-r--r--converter/other/fiasco/output/matrices.c4
-rw-r--r--converter/other/fiasco/output/weights.c293
-rw-r--r--converter/other/fiasco/params.c9
-rw-r--r--converter/other/fiasco/pnmtofiasco.c23
20 files changed, 424 insertions, 438 deletions
diff --git a/converter/other/fiasco/binerror.c b/converter/other/fiasco/binerror.c
index 8a41a214..77243c64 100644
--- a/converter/other/fiasco/binerror.c
+++ b/converter/other/fiasco/binerror.c
@@ -92,11 +92,7 @@ _error (const char *format, ...)
 
    fprintf (stderr, "%s: %s: line %d:\nError: ",
 	    executable, error_file, error_line);
-#if HAVE_VPRINTF
    vfprintf (stderr, format, args);
-#elif HAVE_DOPRNT
-   _doprnt (format, args, stderr);
-#endif /* HAVE_DOPRNT */
    fputc ('\n', stderr);
    va_end(args);
 
@@ -132,11 +128,7 @@ _warning (const char *format, ...)
 
    fprintf (stderr, "%s: %s: line %d:\nWarning: ",
 	    executable, error_file, error_line);
-#if HAVE_VPRINTF
    vfprintf (stderr, format, args);
-#elif HAVE_DOPRNT
-   _doprnt (format, args, stderr);
-#endif /* HAVE_DOPRNT */
    fputc ('\n', stderr);
 
    va_end (args);
diff --git a/converter/other/fiasco/codec/coder.c b/converter/other/fiasco/codec/coder.c
index 927ebbda..f7abfd00 100644
--- a/converter/other/fiasco/codec/coder.c
+++ b/converter/other/fiasco/codec/coder.c
@@ -252,14 +252,14 @@ alloc_coder (char const * const * const inputname,
         lx = (unsigned) (log2 (wi->width - 1) + 1);
         ly = (unsigned) (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);
     }
    
     c = Calloc (1, sizeof (coding_t));
 
     c->options             = *options;
-    c->options.lc_min_level = max (options->lc_min_level, 3);
-    c->options.lc_max_level = min (options->lc_max_level, wi->level - 1);
+    c->options.lc_min_level = MAX(options->lc_min_level, 3);
+    c->options.lc_max_level = MIN(options->lc_max_level, wi->level - 1);
 
     c->tiling = alloc_tiling (options->tiling_method,
                               options->tiling_exponent, wi->level);
@@ -285,16 +285,16 @@ alloc_coder (char const * const * const inputname,
      *  p_min_level, p_max_level min and max level for ND/MC prediction
      *  [p_min_level, p_max_level] must be a subset of [min_level, max_level] !
      */
-    wi->p_min_level = max (options->p_min_level, c->options.lc_min_level);
-    wi->p_max_level = min (options->p_max_level, c->options.lc_max_level);
+    wi->p_min_level = MAX(options->p_min_level, c->options.lc_min_level);
+    wi->p_max_level = MIN(options->p_max_level, c->options.lc_max_level);
     if (wi->p_min_level > wi->p_max_level)
         wi->p_min_level = wi->p_max_level;
 
-    c->options.images_level = min (c->options.images_level,
-                                   c->options.lc_max_level - 1);
+    c->options.images_level = MIN(c->options.images_level,
+                                  c->options.lc_max_level - 1);
    
-    c->products_level  = max (0, ((signed int) c->options.lc_max_level
-                                  - (signed int) c->options.images_level - 1));
+    c->products_level  = MAX(0, ((signed int) c->options.lc_max_level
+                                 - (signed int) c->options.images_level - 1));
     c->pixels         = Calloc (size_of_level (c->options.lc_max_level),
                                 sizeof (real_t));
     c->images_of_state = Calloc (MAXSTATES, sizeof (real_t *));
@@ -324,8 +324,8 @@ alloc_coder (char const * const * const inputname,
     /*
      *  Max. number of states and edges
      */
-    wi->max_states         = max (min (options->max_states, MAXSTATES), 1);
-    c->options.max_elements = max (min (options->max_elements, MAXEDGES), 1);
+    wi->max_states          = MAX(MIN(options->max_states, MAXSTATES), 1);
+    c->options.max_elements = MAX(MIN(options->max_elements, MAXEDGES), 1);
 
     /*
      *  Title and comment strings
@@ -348,7 +348,7 @@ alloc_coder (char const * const * const inputname,
     /*
      *  Color image options ...
      */
-    wi->chroma_max_states = max (1, options->chroma_max_states);
+    wi->chroma_max_states = MAX(1, options->chroma_max_states);
 
     /*
     *  Set up motion compensation struct.
@@ -432,9 +432,9 @@ print_statistics (char c, real_t costs, const wfa_t *wfa, const image_t *image,
      
       if (lincomb)
       {
-     max_level = max (max_level,
+     max_level = MAX(max_level,
               (unsigned) (wfa->level_of_state [state] - 1));
-     min_level = min (min_level,
+     min_level = MIN(min_level,
               (unsigned) (wfa->level_of_state [state] - 1));
       }
    }
@@ -548,77 +548,78 @@ frame_coder (wfa_t *wfa, coding_t *c, bitfile_t *output)
    }
    else
    {
-      int     YCb_node = -1;
-      int     tree [3];         /* 3 root states of each color comp. */
-      color_e band;
+       int     YCb_node = -1;
+       int     tree [3];         /* 3 root states of each color comp. */
+       color_e band;
       
-      /*
-       *  When compressing color images, the three color components (YCbCr) 
-       *  are copied into a large image:
-       *  [  Y  Cr ]
-       *  [  Cb 0  ]
-       *  I.e. the color components of an image are processed in a row.
-       *  After all components are compressed, virtual states are generated
-       *  to describe the large image.
-       */
-      for (band = first_band (YES); band <= last_band (YES) ; band++)
-      {
-     debug_message ("Encoding color component %d", band);
-     tree [band] = RANGE;
-     if (band == Cb)
-     {
-        unsigned min_level;
-
-        c->domain_pool->chroma (wfa->wfainfo->chroma_max_states, wfa,
-                    c->domain_pool->model);
-        /*
-         *  Don't use a finer partioning for the chrominancy bands than for
-         *  the luminancy band.
-         */
-        for (min_level = MAXLEVEL, state = wfa->basis_states;
-         state < wfa->states; state++)
-        {
-           unsigned lincomb, label;
+       /*
+        *  When compressing color images, the three color components (YCbCr) 
+        *  are copied into a large image:
+        *  [  Y  Cr ]
+        *  [  Cb 0  ]
+        *  I.e. the color components of an image are processed in a row.
+        *  After all components are compressed, virtual states are generated
+        *  to describe the large image.
+        */
+       for (band = first_band (YES); band <= last_band (YES) ; band++)
+       {
+           debug_message ("Encoding color component %d", band);
+           tree [band] = RANGE;
+           if (band == Cb)
+           {
+               unsigned min_level;
+
+               c->domain_pool->chroma (wfa->wfainfo->chroma_max_states, wfa,
+                                       c->domain_pool->model);
+               /*
+                *  Don't use a finer partioning for the chrominancy bands than
+                *  for the luminancy band.
+                */
+               for (min_level = MAXLEVEL, state = wfa->basis_states;
+                    state < wfa->states; state++)
+               {
+                   unsigned lincomb, label;
            
-           for (lincomb = 0, label = 0; label < MAXLABELS; label++)
-          lincomb += isrange (wfa->tree [state][label]) ? 1 : 0;
-           if (lincomb)
-          min_level = min (min_level,
-                   (unsigned) (wfa->level_of_state [state]
-                           - 1));
-        }
-        c->options.lc_min_level = min_level;
-        if (c->mt->frame_type != I_FRAME) /* subtract mc of luminance */
-           subtract_mc (c->mt->original, c->mt->past, c->mt->future, wfa);
-     }
-
-     memset (&range, 0, sizeof (range_t));
-     range.level = wfa->wfainfo->level;
+                   for (lincomb = 0, label = 0; label < MAXLABELS; label++)
+                       lincomb += isrange (wfa->tree [state][label]) ? 1 : 0;
+                   if (lincomb)
+                       min_level = MIN(min_level,
+                                       (unsigned) (wfa->level_of_state [state]
+                                                   - 1));
+               }
+               c->options.lc_min_level = min_level;
+               if (c->mt->frame_type != I_FRAME) /* subtract mc of luminance */
+                   subtract_mc (c->mt->original, c->mt->past, c->mt->future,
+                                wfa);
+           }
+
+           memset (&range, 0, sizeof (range_t));
+           range.level = wfa->wfainfo->level;
      
-     costs = subdivide (MAXCOSTS, band, tree [Y], &range, wfa, c,
-                c->mt->frame_type != I_FRAME && band == Y, NO);
-     if (c->options.progress_meter != FIASCO_PROGRESS_NONE)
-        message ("");
-     {
-        char colors [] = {'Y', 'B', 'R'};
+           costs = subdivide (MAXCOSTS, band, tree [Y], &range, wfa, c,
+                              c->mt->frame_type != I_FRAME && band == Y, NO);
+           if (c->options.progress_meter != FIASCO_PROGRESS_NONE)
+               message ("");
+           {
+               char colors [] = {'Y', 'B', 'R'};
         
-        print_statistics (colors [band], costs, wfa,
-                  c->mt->original, &range);
-     }
+               print_statistics (colors [band], costs, wfa,
+                                 c->mt->original, &range);
+           }
      
-     if (isrange (range.tree))  /* whole image is approx. by a l.c. */
-        error ("No root state generated for color component %d!", band);
-     else
-        tree[band] = range.tree;
+           if (isrange (range.tree))  /* whole image is approx. by a l.c. */
+               error ("No root state generated for color component %d!", band);
+           else
+               tree[band] = range.tree;
      
-     if (band == Cb)
-     {
-        wfa->tree [wfa->states][0] = tree[Y];
-        wfa->tree [wfa->states][1] = tree[Cb];
-        YCb_node = wfa->states;
-        append_state (YES, compute_final_distribution (wfa->states, wfa),
-              wfa->wfainfo->level + 1, wfa, c);
-     }
+           if (band == Cb)
+           {
+               wfa->tree [wfa->states][0] = tree[Y];
+               wfa->tree [wfa->states][1] = tree[Cb];
+               YCb_node = wfa->states;
+               append_state (YES, compute_final_distribution(wfa->states, wfa),
+                             wfa->wfainfo->level + 1, wfa, c);
+           }
       }
       /*
        *  generate two virtual states (*) 
diff --git a/converter/other/fiasco/codec/decoder.c b/converter/other/fiasco/codec/decoder.c
index 253f23dc..26284596 100644
--- a/converter/other/fiasco/codec/decoder.c
+++ b/converter/other/fiasco/codec/decoder.c
@@ -20,6 +20,8 @@
 
 #include <string.h>
 
+#include "pm_c_util.h"
+
 #include "types.h"
 #include "macros.h"
 #include "error.h"
@@ -455,7 +457,7 @@ decode_image (unsigned orig_width, unsigned orig_height, format_e format,
     */
    for (max_level = 0, state = wfa->basis_states; state < wfa->states; state++)
       if (isedge (wfa->into [state][0][0]) || isedge (wfa->into [state][1][0]))
-     max_level = max (max_level, wfa->level_of_state [state]);
+     max_level = MAX(max_level, wfa->level_of_state [state]);
    
 
    /*
@@ -463,8 +465,8 @@ decode_image (unsigned orig_width, unsigned orig_height, format_e format,
     */
    compute_actual_size (format == FORMAT_4_2_0 ? root_state [Y] : MAXSTATES,
             &width, &height, wfa);
-   width  = max (width, orig_width);
-   height = max (height, orig_height);
+   width  = MAX(width, orig_width);
+   height = MAX(height, orig_height);
    frame = alloc_image (width, height, wfa->wfainfo->color, format);
    
    /*
@@ -720,7 +722,7 @@ smooth_image (unsigned sf, const wfa_t *wfa, image_t *image)
         + wfa->x [state][1];
      img2 = bptr + wfa->y [state][1] * img_width + wfa->x [state][1];
      
-     for (i = min (width, img_width - wfa->x [state][1]); i;
+     for (i = MIN(width, img_width - wfa->x [state][1]); i;
           i--, img1++, img2++)
      {
         int tmp = *img1;
@@ -747,7 +749,7 @@ smooth_image (unsigned sf, const wfa_t *wfa, image_t *image)
      img1 = bptr + wfa->y [state][1] * img_width + wfa->x [state][1] - 1;
      img2 = bptr + wfa->y [state][1] * img_width + wfa->x [state][1];
      
-     for (i = min (height, img_height - wfa->y [state][1]); i;
+     for (i = MIN(height, img_height - wfa->y [state][1]); i;
           i--, img1 += img_width, img2 += img_width)
      {
         int tmp = *img1;
@@ -807,7 +809,7 @@ enlarge_image (int enlarge_factor, format_e format, unsigned y_root,
      unsigned label, n;
      
      wfa->level_of_state [state]
-        = max (wfa->level_of_state [state] + enlarge_factor * 2, 0);
+        = MAX(wfa->level_of_state [state] + enlarge_factor * 2, 0);
 
      for (label = 0; label < MAXLABELS; label++)
         if (enlarge_factor > 0)
@@ -859,12 +861,12 @@ compute_actual_size (unsigned luminance_root,
    for (state = wfa->basis_states; state < wfa->states; state++)
       if (isedge (wfa->into [state][0][0]) || isedge (wfa->into [state][1][0]))
       {
-     unsigned mult = state > luminance_root ? 2 : 1;
-     
-     x = max ((wfa->x [state][0]
-           + width_of_level (wfa->level_of_state [state])) * mult, x);
-     y = max ((wfa->y [state][0]
-           + height_of_level (wfa->level_of_state [state])) * mult, y);
+          unsigned mult = state > luminance_root ? 2 : 1;
+          
+          x = MAX((wfa->x [state][0]
+                   + width_of_level (wfa->level_of_state [state])) * mult, x);
+          y = MAX((wfa->y [state][0]
+                   + height_of_level (wfa->level_of_state [state])) * mult, y);
       }
 
    if (x & 1)               /* ensure that image size is even */
diff --git a/converter/other/fiasco/codec/dfiasco.c b/converter/other/fiasco/codec/dfiasco.c
index 7d98f5f8..2fdec573 100644
--- a/converter/other/fiasco/codec/dfiasco.c
+++ b/converter/other/fiasco/codec/dfiasco.c
@@ -17,6 +17,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "pm_c_util.h"
 #include "nstring.h"
 
 #include "config.h"
@@ -115,7 +116,7 @@ fiasco_decoder_new (const char *filename, const fiasco_d_options_t *options)
 	    {
 	       set_error (_("Magnifaction factor `%d' is too large. "
 			    "Maximium value is %d."),
-			  dfiasco->enlarge_factor, max (0, n - 1));
+			  dfiasco->enlarge_factor, MAX(0, n - 1));
 	       fiasco_decoder_delete (decoder);
 	       return NULL;
 	    }
@@ -132,7 +133,7 @@ fiasco_decoder_new (const char *filename, const fiasco_d_options_t *options)
 	    {
 	       set_error (_("Magnifaction factor `%d' is too small. "
 			    "Minimum value is %d."),
-			  dfiasco->enlarge_factor, - max (0, n - 1));
+			  dfiasco->enlarge_factor, - MAX(0, n - 1));
 	       fiasco_decoder_delete (decoder);
 	       return NULL;
 	    }
diff --git a/converter/other/fiasco/codec/domain-pool.c b/converter/other/fiasco/codec/domain-pool.c
index d7c0602f..7cc3900e 100644
--- a/converter/other/fiasco/codec/domain-pool.c
+++ b/converter/other/fiasco/codec/domain-pool.c
@@ -20,6 +20,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "pm_c_util.h"
+
 #include "types.h"
 #include "macros.h"
 #include "error.h"
@@ -458,7 +460,7 @@ qac_chroma (unsigned max_domains, const wfa_t *wfa, void *model)
                                 max_domains, wfa);
         for (n = 0; n < max_domains && domains [n] >= 0; n++)
             states [n] = domains [n];
-        max_domains = min (max_domains, n);
+        max_domains = MIN(max_domains, n);
         Free (domains);
 
         for (old = 0, new = 0; new < max_domains && old < qac_model->n; old++)
@@ -846,7 +848,7 @@ rle_chroma (unsigned max_domains, const wfa_t *wfa, void *model)
             states [n] = domains [n];
 
         assert (states [0] == 0);
-        max_domains = min (max_domains, n);
+        max_domains = MIN(max_domains, n);
         Free (domains);
 
         Free (rle_model->states);
diff --git a/converter/other/fiasco/codec/motion.c b/converter/other/fiasco/codec/motion.c
index 1a1c78aa..876a2998 100644
--- a/converter/other/fiasco/codec/motion.c
+++ b/converter/other/fiasco/codec/motion.c
@@ -19,6 +19,8 @@
 
 #include <string.h>
 
+#include "pm_c_util.h"
+
 #include "types.h"
 #include "macros.h"
 #include "error.h"
@@ -50,10 +52,10 @@ restore_mc (int enlarge_factor, image_t *image, const image_t *past,
 
 #define FX(v) ((image->format == FORMAT_4_2_0) && band != Y ? ((v) / 2) : v)
    
-   mcblock1 = Calloc (size_of_level (max ((int) wfa->wfainfo->p_max_level
+   mcblock1 = Calloc (size_of_level (MAX((int) wfa->wfainfo->p_max_level
 					  + 2 * enlarge_factor, 0)),
 		      sizeof (word_t));
-   mcblock2 = Calloc (size_of_level (max ((int) wfa->wfainfo->p_max_level
+   mcblock2 = Calloc (size_of_level (MAX((int) wfa->wfainfo->p_max_level
 					  + 2 * enlarge_factor, 0)),
 		      sizeof (word_t));
 
diff --git a/converter/other/fiasco/codec/mwfa.c b/converter/other/fiasco/codec/mwfa.c
index e0d7c99e..c695f6bf 100644
--- a/converter/other/fiasco/codec/mwfa.c
+++ b/converter/other/fiasco/codec/mwfa.c
@@ -20,6 +20,8 @@
 #include <ctype.h>
 #include <string.h>
 
+#include "pm_c_util.h"
+
 #include "types.h"
 #include "macros.h"
 #include "error.h"
@@ -808,10 +810,10 @@ find_second_mv (real_t price, const image_t *original,
 
    sr = wi->search_range;
 
-   y0 = max ((int) -sr, *my - (int) local_range);
-   y1 = min ((int) sr, *my + (int) local_range);
-   x0 = max ((int) -sr, *mx - (int) local_range);
-   x1 = min ((int) sr, *mx + (int) local_range);
+   y0 = MAX((int) -sr, *my - (int) local_range);
+   y1 = MIN((int) sr, *my + (int) local_range);
+   x0 = MAX((int) -sr, *mx - (int) local_range);
+   x1 = MIN((int) sr, *mx + (int) local_range);
 
    *mx = *my = 0;
 
diff --git a/converter/other/fiasco/codec/subdivide.c b/converter/other/fiasco/codec/subdivide.c
index 059aa477..2ace18e4 100644
--- a/converter/other/fiasco/codec/subdivide.c
+++ b/converter/other/fiasco/codec/subdivide.c
@@ -18,6 +18,8 @@
 
 #include <string.h>
 
+#include "pm_c_util.h"
+
 #include "types.h"
 #include "macros.h"
 #include "error.h"
@@ -300,7 +302,7 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range,
 	  *  Abort the recursion if 'subdivide_costs' exceed 'lincomb_costs'
 	  *  or 'max_costs'.
 	  */
-	 remaining_costs = min (lincomb_costs, max_costs) - subdivide_costs;
+	 remaining_costs = MIN(lincomb_costs, max_costs) - subdivide_costs;
 
 	 if (remaining_costs > 0)	/* still a way for improvement */
 	 {
@@ -352,7 +354,7 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range,
 	  *  If costs of subdivision exceed costs of linear combination 
 	  *  then abort recursion.
 	  */
-	 if (subdivide_costs >= min (lincomb_costs, max_costs)) 
+	 if (subdivide_costs >= MIN(lincomb_costs, max_costs)) 
 	 {
 	    subdivide_costs = MAXCOSTS;
 	    break; 
@@ -382,28 +384,28 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range,
     */
    if (try_mc || try_nd)		/* try prediction */
    {
-      real_t prediction_costs;	/* Costs arising from approx. the current
-				   range with prediction */
-
-      prediction_costs
-	 = predict_range (min (min (lincomb_costs, subdivide_costs),
-			       max_costs),
-			  price, range, wfa, c, band, y_state, states,
-			  &tree_model, &p_tree_model, domain_model,
-			  d_domain_model, coeff_model, d_coeff_model);
-      if (prediction_costs < MAXCOSTS)	/* prediction has smallest costs */
-      {
-	 c->domain_pool->model_free (domain_model);
-	 c->d_domain_pool->model_free (d_domain_model);
-	 c->domain_pool->model_free (lc_domain_model);
-	 c->d_domain_pool->model_free (lc_d_domain_model);
-	 c->coeff->model_free (coeff_model);
-	 c->d_coeff->model_free (d_coeff_model);
-	 c->coeff->model_free (lc_coeff_model);
-	 c->d_coeff->model_free (lc_d_coeff_model);
+       real_t prediction_costs;	/* Costs arising from approx. the current
+                                   range with prediction */
+
+       prediction_costs
+           = predict_range (MIN(MIN(lincomb_costs, subdivide_costs),
+                                max_costs),
+                            price, range, wfa, c, band, y_state, states,
+                            &tree_model, &p_tree_model, domain_model,
+                            d_domain_model, coeff_model, d_coeff_model);
+       if (prediction_costs < MAXCOSTS)	/* prediction has smallest costs */
+       {
+           c->domain_pool->model_free (domain_model);
+           c->d_domain_pool->model_free (d_domain_model);
+           c->domain_pool->model_free (lc_domain_model);
+           c->d_domain_pool->model_free (lc_d_domain_model);
+           c->coeff->model_free (coeff_model);
+           c->d_coeff->model_free (d_coeff_model);
+           c->coeff->model_free (lc_coeff_model);
+           c->d_coeff->model_free (lc_d_coeff_model);
 	 
-	 return prediction_costs;
-      }
+           return prediction_costs;
+       }
    }
 
    if (lincomb_costs >= MAXCOSTS && subdivide_costs >= MAXCOSTS)
diff --git a/converter/other/fiasco/codec/tiling.c b/converter/other/fiasco/codec/tiling.c
index ea030c9a..83eb8b29 100644
--- a/converter/other/fiasco/codec/tiling.c
+++ b/converter/other/fiasco/codec/tiling.c
@@ -18,6 +18,8 @@
 
 #include <stdlib.h>
 
+#include "pm_c_util.h"
+
 #include "types.h"
 #include "macros.h"
 #include "error.h"
@@ -144,7 +146,7 @@ perform_tiling (const image_t *image, tiling_t *tiling)
 	 unsigned    number;		/* number of image tiles */
 	 unsigned    lx       = log2 (image->width - 1) + 1; /* x level */
 	 unsigned    ly       = log2 (image->height - 1) + 1; /* y level */
-	 unsigned    level    = max (lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0);
+	 unsigned    level    = MAX(lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0);
 	 var_list_t *var_list = Calloc (tiles, sizeof (var_list_t));
 	 
 	 /*
diff --git a/converter/other/fiasco/codec/wfalib.c b/converter/other/fiasco/codec/wfalib.c
index bc7c35ef..61d64d2f 100644
--- a/converter/other/fiasco/codec/wfalib.c
+++ b/converter/other/fiasco/codec/wfalib.c
@@ -22,6 +22,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "pm_c_util.h"
+
 #include "types.h"
 #include "macros.h"
 #include "error.h"
@@ -215,7 +217,7 @@ compute_hits (unsigned from, unsigned to, unsigned n, const wfa_t *wfa)
 
    qsort (hits + 1, to - 1, sizeof (pair_t), sort_desc_pair);
 
-   n       = min (to, n);
+   n       = MIN(to, n);
    domains = Calloc (n + 1, sizeof (word_t));
 
    for (domain = 0; domain < (int) n && (!domain || hits [domain].key);
@@ -483,7 +485,7 @@ compute_spiral (int *vorder, unsigned image_width, unsigned image_height,
    
    lx     = log2 (image_width - 1) + 1;
    ly     = log2 (image_height - 1) + 1;
-   level  = max (lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0);
+   level  = MAX(lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0);
    tiles  = 1 << tiling_exp;		/* Number of image tiles */
    width  = width_of_level (level - tiling_exp);
    height = height_of_level (level - tiling_exp);
diff --git a/converter/other/fiasco/fiascotopnm.c b/converter/other/fiasco/fiascotopnm.c
index 43340b06..dfba2256 100644
--- a/converter/other/fiasco/fiascotopnm.c
+++ b/converter/other/fiasco/fiascotopnm.c
@@ -178,21 +178,21 @@ checkargs (int argc, char **argv, bool_t *double_resolution, bool_t *panel,
     *options = fiasco_d_options_new ();
 
     {
-        int n = *((int *) parameter_value (params, "smoothing"));
+        int const n = *((int *) parameter_value (params, "smoothing"));
       
-        if (!fiasco_d_options_set_smoothing (*options, max (-1, n)))
+        if (!fiasco_d_options_set_smoothing (*options, MAX(-1, n)))
             error (fiasco_get_error_message ());
     }
 
     {
-        int n = *((int *) parameter_value (params, "magnify"));
+        int const n = *((int *) parameter_value (params, "magnify"));
       
         if (!fiasco_d_options_set_magnification (*options, n))
             error (fiasco_get_error_message ());
     }
    
     {
-        bool_t n = *((bool_t *) parameter_value (params, "fast"));
+        bool_t const n = *((bool_t *) parameter_value (params, "fast"));
       
         if (!fiasco_d_options_set_4_2_0_format (*options, n > 0 ? YES : NO))
             error (fiasco_get_error_message ());
diff --git a/converter/other/fiasco/input/read.c b/converter/other/fiasco/input/read.c
index 9690a6c5..9ac204f6 100644
--- a/converter/other/fiasco/input/read.c
+++ b/converter/other/fiasco/input/read.c
@@ -157,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);
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);
diff --git a/converter/other/fiasco/lib/error.c b/converter/other/fiasco/lib/error.c
index 13cec99a..ee3afe1f 100644
--- a/converter/other/fiasco/lib/error.c
+++ b/converter/other/fiasco/lib/error.c
@@ -108,11 +108,7 @@ set_error (const char *format, ...)
       Free (error_message);
    error_message = Calloc (len, sizeof (char));
    
-#if HAVE_VPRINTF
    vsprintf (error_message, format, args);
-#elif HAVE_DOPRNT
-   _doprnt (format, args, stderr);
-#endif /* HAVE_DOPRNT */
 
    va_end (args);
 }
@@ -169,11 +165,7 @@ error (const char *format, ...)
       Free (error_message);
    error_message = Calloc (len, sizeof (char));
    
-#if HAVE_VPRINTF
    vsprintf (error_message, format, args);
-#elif HAVE_DOPRNT
-   _doprnt (format, args, stderr);
-#endif /* HAVE_DOPRNT */
 
    va_end (args);
    
@@ -227,11 +219,7 @@ warning (const char *format, ...)
       return;
 	
    fprintf (stderr, "Warning: ");
-#if HAVE_VPRINTF
    vfprintf (stderr, format, args);
-#elif HAVE_DOPRNT
-   _doprnt (format, args, stderr);
-#endif /* HAVE_DOPRNT */
    fputc ('\n', stderr);
 
    va_end (args);
@@ -250,11 +238,7 @@ message (const char *format, ...)
    if (verboselevel == FIASCO_NO_VERBOSITY)
       return;
 
-#if HAVE_VPRINTF
    vfprintf (stderr, format, args);
-#elif HAVE_DOPRNT
-   _doprnt (format, args, stderr);
-#endif /* HAVE_DOPRNT */
    fputc ('\n', stderr);
    va_end (args);
 }
@@ -273,11 +257,7 @@ debug_message (const char *format, ...)
       return;
 
    fprintf (stderr, "*** ");
-#if HAVE_VPRINTF
    vfprintf (stderr, format, args);
-#elif HAVE_DOPRNT
-   _doprnt (format, args, stderr);
-#endif /* HAVE_DOPRNT */
    fputc ('\n', stderr);
    va_end (args);
 }
@@ -295,11 +275,7 @@ info (const char *format, ...)
    if (verboselevel == FIASCO_NO_VERBOSITY)
       return;
 
-#if HAVE_VPRINTF
    vfprintf (stderr, format, args);
-#elif HAVE_DOPRNT
-   _doprnt (format, args, stderr);
-#endif /* HAVE_DOPRNT */
    fflush (stderr);
    va_end (args);
 }
diff --git a/converter/other/fiasco/lib/macros.h b/converter/other/fiasco/lib/macros.h
index 877abeea..9968110a 100644
--- a/converter/other/fiasco/lib/macros.h
+++ b/converter/other/fiasco/lib/macros.h
@@ -28,11 +28,6 @@
 #   define SEEK_CUR	1
 #endif /* not SEEK_CUR */
 
-#ifdef WIN32
-#undef max
-#undef min
-#endif /* not WIN32 */
-
 /*****************************************************************************
 
 				Various macros
@@ -50,12 +45,6 @@
 #define address_of_level(l)	((unsigned) (size_of_level (l) - 1))
 #define size_of_tree(l)		((unsigned) (address_of_level ((l) + 1)))
 #define is_odd(n)		(abs (n) % 2)
-#ifndef max
-#define max(a,b)		((a) < (b) ? (b) : (a))
-#endif
-#ifndef min
-#define min(a,b)	        ((a) > (b) ? (b) : (a))
-#endif
 #define _(x) (x) 
 
 
diff --git a/converter/other/fiasco/lib/misc.c b/converter/other/fiasco/lib/misc.c
index dd9f0bb2..11e2da54 100644
--- a/converter/other/fiasco/lib/misc.c
+++ b/converter/other/fiasco/lib/misc.c
@@ -36,6 +36,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "pm_c_util.h"
+
 #include "types.h"
 #include "macros.h"
 #include "error.h"
@@ -445,13 +447,13 @@ variance (const word_t *pixels, unsigned x0, unsigned y0,
    assert (pixels);
    
    for (average = 0, n = 0, y = y0; y < y0 + height; y++)
-      for (x = x0; x < min (x0 + width, cols); x++, n++)
+      for (x = x0; x < MIN(x0 + width, cols); x++, n++)
 	 average += pixels [y * cols + x] / 16;
 
    average /= n;
 
    for (variance = 0, y = y0; y < y0 + height; y++)
-      for (x = x0; x < min (x0 + width, cols); x++)
+      for (x = x0; x < MIN(x0 + width, cols); x++)
 	 variance += square ((pixels [y * cols + x] / 16) - average);
 
    return variance;
diff --git a/converter/other/fiasco/output/matrices.c b/converter/other/fiasco/output/matrices.c
index bbe3ca0e..01189669 100644
--- a/converter/other/fiasco/output/matrices.c
+++ b/converter/other/fiasco/output/matrices.c
@@ -22,6 +22,8 @@
 
 #include <stdlib.h>
 
+#include "pm_c_util.h"
+
 #include "types.h"
 #include "macros.h"
 #include "error.h"
@@ -142,7 +144,7 @@ delta_encoding (bool_t use_normal_domains, bool_t use_delta_domains,
 		  ;
 	       count [edge]++;
 	       edges++;
-	       M = max (edge, M);
+	       M = MAX(edge, M);
 	    }
       write_rice_code (M, 3, output);
       for (n = 0; n <= M; n++)
diff --git a/converter/other/fiasco/output/weights.c b/converter/other/fiasco/output/weights.c
index 085a1f00..5aa17674 100644
--- a/converter/other/fiasco/output/weights.c
+++ b/converter/other/fiasco/output/weights.c
@@ -16,6 +16,8 @@
 
 #include "config.h"
 
+#include "pm_c_util.h"
+
 #include "types.h"
 #include "macros.h"
 #include "error.h"
@@ -43,158 +45,159 @@ write_weights (unsigned total, const wfa_t *wfa, bitfile_t *output)
  *  No return value.
  */
 {
-   unsigned  state, label;		/* current label */
-   unsigned  offset1, offset2;		/* model offsets. */
-   unsigned  offset3, offset4;		/* model offsets. */
-   unsigned *weights_array;		/* array of weights to encode */
-   unsigned *wptr;			/* pointer to current weight */
-   unsigned *level_array;		/* array of corresponding levels */
-   unsigned *lptr;			/* pointer to current corr. level */
-   int	     min_level, max_level;	/* min and max range level */
-   int	     d_min_level, d_max_level; 	/* min and max delta range level */
-   bool_t    dc, d_dc;			/* true if dc or delta dc are used */
-   bool_t    delta_approx = NO;		/* true if delta has been used */
-   unsigned  delta_count  = 0;		/* number of delta ranges */
-   unsigned  bits 	  = bits_processed (output);
+    unsigned  state, label;		/* current label */
+    unsigned  offset1, offset2;		/* model offsets. */
+    unsigned  offset3, offset4;		/* model offsets. */
+    unsigned *weights_array;		/* array of weights to encode */
+    unsigned *wptr;			/* pointer to current weight */
+    unsigned *level_array;		/* array of corresponding levels */
+    unsigned *lptr;			/* pointer to current corr. level */
+    int	     min_level, max_level;	/* min and max range level */
+    int	     d_min_level, d_max_level; 	/* min and max delta range level */
+    bool_t    dc, d_dc;			/* true if dc or delta dc are used */
+    bool_t    delta_approx = NO;		/* true if delta has been used */
+    unsigned  delta_count  = 0;		/* number of delta ranges */
+    unsigned  bits 	  = bits_processed (output);
    
-   /*
-    *  Check whether delta approximation has been used
-    */
-   for (state = wfa->basis_states; state < wfa->states; state++)
-      if (wfa->delta_state [state])
-      {
-	 delta_approx = YES;
-	 break;
-      }
+    /*
+     *  Check whether delta approximation has been used
+     */
+    for (state = wfa->basis_states; state < wfa->states; state++)
+        if (wfa->delta_state [state])
+        {
+            delta_approx = YES;
+            break;
+        }
    
-   /*
-    *  Generate array of corresponding levels (context of probability model)
-    */
-   min_level = d_min_level = MAXLEVEL;
-   max_level = d_max_level = 0;
-   dc 	     = d_dc	   = NO;
+    /*
+     *  Generate array of corresponding levels (context of probability model)
+     */
+    min_level = d_min_level = MAXLEVEL;
+    max_level = d_max_level = 0;
+    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]) /* delta approx. */
-	    {
-	       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;
-
-   /*
-    *  Context model:
-    *		0		DC weight
-    *		1		Delta DC weight
-    *		2-k		normal weights per level
-    *		k+1 - m		Delta weights per level
-    */
-
-   offset1 = dc ? 1 : 0;
-   offset2 = offset1 + (d_dc ? 1 : 0);
-   offset3 = offset2 + (max_level - min_level + 1);
-   offset4 = offset3 + (d_max_level - d_min_level + 1);
+    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]) /* delta approx. */
+                {
+                    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;
+
+    /*
+     *  Context model:
+     *		0		DC weight
+     *		1		Delta DC weight
+     *		2-k		normal weights per level
+     *		k+1 - m		Delta weights per level
+     */
+
+    offset1 = dc ? 1 : 0;
+    offset2 = offset1 + (d_dc ? 1 : 0);
+    offset3 = offset2 + (max_level - min_level + 1);
+    offset4 = offset3 + (d_max_level - d_min_level + 1);
    
-   /*
-    *  Weights are encoded as follows:
-    *  all weights of state n
-    *     sorted by label
-    *        sorted by domain number
-    */
-
-   wptr = weights_array = Calloc (total, sizeof (unsigned));
-   lptr = level_array   = Calloc (total, sizeof (unsigned));
-
-   for (state = wfa->basis_states; state < wfa->states; state++)
-      for (label = 0; label < MAXLABELS; label++)
-         if (isrange (wfa->tree [state][label]))
-	 {
-	    int	edge;			/* current edge */
-	    int	domain;			/* current domain (context of model) */
-	    
-            for (edge = 0; isedge (domain = wfa->into [state][label][edge]);
-		 edge++)
+    /*
+     *  Weights are encoded as follows:
+     *  all weights of state n
+     *     sorted by label
+     *        sorted by domain number
+     */
+
+    wptr = weights_array = Calloc (total, sizeof (unsigned));
+    lptr = level_array   = Calloc (total, sizeof (unsigned));
+
+    for (state = wfa->basis_states; state < wfa->states; state++)
+        for (label = 0; label < MAXLABELS; label++)
+            if (isrange (wfa->tree [state][label]))
             {
-	       if (wptr - weights_array >= (int) total)
-		  error ("Can't write more than %d weights.", total);
-	       if (domain)		/* not DC component */
-	       {
-		  if (delta_approx && wfa->delta_state [state]) /* delta */
-		  {
-		     *wptr++ = rtob (wfa->weight [state][label][edge],
-				     wfa->wfainfo->d_rpf);
-		     *lptr++ = offset3
-			       + wfa->level_of_state [state] - 1 - d_min_level;
-		     delta_count++;
-		  }
-		  else
-		  {
-		     *wptr++ = rtob (wfa->weight [state][label][edge],
-				     wfa->wfainfo->rpf);
-		     *lptr++ = offset2
-			       + wfa->level_of_state [state] - 1 - min_level;
-		  }
-	       }
-	       else			/* DC component */
-	       {
-		  if (delta_approx && wfa->delta_state [state]) /* delta */
-		  {
-		     *wptr++ = rtob (wfa->weight [state][label][edge],
-				     wfa->wfainfo->d_dc_rpf);
-		     *lptr++ = offset1;
-		  }
-		  else
-		  {
-		     *wptr++ = rtob (wfa->weight [state][label][edge],
-				     wfa->wfainfo->dc_rpf);
-		     *lptr++ = 0;
-		  }
-	       }
+                int	edge;			/* current edge */
+                int	domain;			/* current domain (context of model) */
+	    
+                for (edge = 0; isedge (domain = wfa->into [state][label][edge]);
+                     edge++)
+                {
+                    if (wptr - weights_array >= (int) total)
+                        error ("Can't write more than %d weights.", total);
+                    if (domain)		/* not DC component */
+                    {
+                        if (delta_approx && wfa->delta_state [state]) /* delta */
+                        {
+                            *wptr++ = rtob (wfa->weight [state][label][edge],
+                                            wfa->wfainfo->d_rpf);
+                            *lptr++ = offset3
+                                + wfa->level_of_state [state] - 1 - d_min_level;
+                            delta_count++;
+                        }
+                        else
+                        {
+                            *wptr++ = rtob (wfa->weight [state][label][edge],
+                                            wfa->wfainfo->rpf);
+                            *lptr++ = offset2
+                                + wfa->level_of_state [state] - 1 - min_level;
+                        }
+                    }
+                    else			/* DC component */
+                    {
+                        if (delta_approx && wfa->delta_state [state]) /* delta */
+                        {
+                            *wptr++ = rtob (wfa->weight [state][label][edge],
+                                            wfa->wfainfo->d_dc_rpf);
+                            *lptr++ = offset1;
+                        }
+                        else
+                        {
+                            *wptr++ = rtob (wfa->weight [state][label][edge],
+                                            wfa->wfainfo->dc_rpf);
+                            *lptr++ = 0;
+                        }
+                    }
+                }
             }
-	 }
-
-   {
-      unsigned	 i;
-      unsigned	*c_symbols = Calloc (offset4, sizeof (int));
-      const int	 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);
-      for (i = offset2; i < offset3; i++)
-	 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);
+
+    {
+        unsigned	 i;
+        unsigned	*c_symbols = Calloc (offset4, sizeof (int));
+        const int	 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);
+        for (i = offset2; i < offset3; i++)
+            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);
       
-      encode_array (output, weights_array, level_array, c_symbols, offset4,
-		    total, scale);
-      Free (c_symbols);
-   }
+        encode_array (output, weights_array, level_array, c_symbols, offset4,
+                      total, scale);
+        Free (c_symbols);
+    }
    
-   debug_message ("%d delta weights out of %d.", delta_count, total);
-   debug_message ("weights:      %5d bits. (%5d symbols => %5.2f bps)",
-		  bits_processed (output) - bits, total,
-		  (bits_processed (output) - bits) / (double) total);
+    debug_message ("%d delta weights out of %d.", delta_count, total);
+    debug_message ("weights:      %5d bits. (%5d symbols => %5.2f bps)",
+                   bits_processed (output) - bits, total,
+                   (bits_processed (output) - bits) / (double) total);
 
-   Free (weights_array);
-   Free (level_array);
+    Free (weights_array);
+    Free (level_array);
 }
+
+
+
diff --git a/converter/other/fiasco/params.c b/converter/other/fiasco/params.c
index a5aefbd6..a4d843a8 100644
--- a/converter/other/fiasco/params.c
+++ b/converter/other/fiasco/params.c
@@ -30,6 +30,7 @@
  
 #include <getopt.h>			/* system or ../lib */
 
+#include "pm_c_util.h"
 #include "nstring.h"
 
 #include "types.h"
@@ -664,13 +665,13 @@ usage (const param_t *params, const char *progname, const char *synopsis,
         if (params [i].optchar != '\0' || show_all_options)
         {
             if (params [i].type == POSTR)
-                width = max (width, (strlen (params [i].name)
+                width = MAX(width, (strlen (params [i].name)
                                      + strlen (params [i].argument_name) + 2));
             else if (params [i].type != PFLAG)
-                width = max (width, (strlen (params [i].name)
+                width = MAX(width, (strlen (params [i].name)
                                      + strlen (params [i].argument_name)));
             else
-                width = max (width, (strlen (params [i].name)) - 1);
+                width = MAX(width, (strlen (params [i].name)) - 1);
         }
    
     for (i = 0; params [i].name != NULL; i++)
@@ -685,7 +686,7 @@ usage (const param_t *params, const char *progname, const char *synopsis,
                 fprintf (stderr, "%s=[%s]%-*s  ", params [i].name,
                          params [i].argument_name,
                          (unsigned)
-                         max(0, (width - 2 - strlen (params [i].name)
+                         MAX(0, (width - 2 - strlen (params [i].name)
                                  - strlen (params [i].argument_name))), "");
             else if (params [i].type != PFLAG)
                 fprintf (stderr, "%s=%-*s  ", params [i].name,
diff --git a/converter/other/fiasco/pnmtofiasco.c b/converter/other/fiasco/pnmtofiasco.c
index f62d876e..d78ff6b1 100644
--- a/converter/other/fiasco/pnmtofiasco.c
+++ b/converter/other/fiasco/pnmtofiasco.c
@@ -15,6 +15,7 @@
  */
 
 #include "config.h"
+#include "pm_c_util.h"
 #include "pnm.h"
 
 #include <stdlib.h>
@@ -278,14 +279,14 @@ checkargs (int argc, char **argv, char const ***image_template,
             int   n = * (int *) parameter_value (params, "chroma-dictionary");
             float q = * (float *) parameter_value (params, "chroma-qfactor");
       
-            if (!fiasco_c_options_set_chroma_quality (*options, q, max (0, n)))
+            if (!fiasco_c_options_set_chroma_quality (*options, q, MAX(0, n)))
                 error (fiasco_get_error_message ());
         }
       
         {
             int n = *((int *) parameter_value (params, "smooth"));
      
-            if (!fiasco_c_options_set_smoothing (*options, max (0, n)))
+            if (!fiasco_c_options_set_smoothing (*options, MAX(0, n)))
                 error (fiasco_get_error_message ());
         }
       
@@ -328,7 +329,7 @@ checkargs (int argc, char **argv, char const ***image_template,
             else
                 error (_("Invalid tiling method `%s' specified."), m);
 
-            if (!fiasco_c_options_set_tiling (*options, method, max (0, e)))
+            if (!fiasco_c_options_set_tiling (*options, method, MAX(0, e)))
                 error (fiasco_get_error_message ());
         }
       
@@ -355,7 +356,7 @@ checkargs (int argc, char **argv, char const ***image_template,
             }
      
             if (!fiasco_c_options_set_optimizations (*options, m, M, N,
-                                                     max (0, D), o))
+                                                     MAX(0, D), o))
                 error (fiasco_get_error_message ());
         }
         {
@@ -364,14 +365,14 @@ checkargs (int argc, char **argv, char const ***image_template,
             int p = * (int *) parameter_value (params, "prediction");
      
             if (!fiasco_c_options_set_prediction (*options,
-                                                  p, max (0, m), max (0, M)))
+                                                  p, MAX(0, m), MAX(0, M)))
                 error (fiasco_get_error_message ());
         }
         {
-            float r    = * (float *) parameter_value (params, "rpf-range");
-            float dc_r = * (float *) parameter_value (params, "dc-rpf-range");
-            int   m    = * (int *)   parameter_value (params, "rpf-mantissa");
-            int   dc_m = * (int *)   parameter_value (params, "dc-rpf-mantissa");
+            float r    = * (float *)parameter_value(params, "rpf-range");
+            float dc_r = * (float *)parameter_value(params, "dc-rpf-range");
+            int   m    = * (int *)  parameter_value(params, "rpf-mantissa");
+            int   dc_m = * (int *)  parameter_value(params, "dc-rpf-mantissa");
             fiasco_rpf_range_e range, dc_range;
      
             if (r < 1)
@@ -393,8 +394,8 @@ checkargs (int argc, char **argv, char const ***image_template,
                 dc_range = FIASCO_RPF_RANGE_2_00;
         
             if (!fiasco_c_options_set_quantization (*options,
-                                                    max (0, m), range,
-                                                    max (0, dc_m), dc_range))
+                                                    MAX(0, m), range,
+                                                    MAX(0, dc_m), dc_range))
                 error (fiasco_get_error_message ());
         }