about summary refs log tree commit diff
path: root/converter/other/fiasco/codec
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 /converter/other/fiasco/codec
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
Diffstat (limited to 'converter/other/fiasco/codec')
-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
9 files changed, 143 insertions, 127 deletions
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);