[vlc-devel] [PATCH] introduce CLIP() macro to replace use pair of __MAX() and __MIN()

Can Wu wu.canus at gmail.com
Tue Nov 15 08:15:44 CET 2011


---
 include/vlc_common.h                   |    3 +++
 modules/codec/avcodec/encoder.c        |    2 +-
 modules/demux/image.c                  |    3 +--
 modules/demux/ps.c                     |    2 +-
 modules/lua/libs/volume.c              |    2 +-
 modules/stream_out/raop.c              |    2 +-
 modules/text_renderer/freetype.c       |   20 ++++++++++----------
 modules/text_renderer/quartztext.c     |    8 ++++----
 modules/text_renderer/win32text.c      |   10 +++++-----
 modules/video_filter/audiobargraph_v.c |    6 +++---
 modules/video_filter/bluescreen.c      |   10 +++++-----
 modules/video_filter/gradfun.c         |    6 +++---
 modules/video_filter/grain.c           |    8 ++++----
 modules/video_filter/logo.c            |    8 ++++----
 modules/video_filter/magnify.c         |    8 ++++----
 modules/video_filter/mosaic.c          |    6 +++---
 modules/video_filter/motionblur.c      |    2 +-
 modules/video_filter/panoramix.c       |    4 ++--
 modules/video_filter/sharpen.c         |    2 +-
 modules/video_filter/wall.c            |    4 ++--
 src/input/stream.c                     |    8 ++++----
 src/video_output/display.c             |   10 ++++------
 src/video_output/interlacing.c         |    2 +-
 src/video_output/video_epg.c           |    2 +-
 src/video_output/video_widgets.c       |    2 +-
 25 files changed, 70 insertions(+), 70 deletions(-)

diff --git a/include/vlc_common.h b/include/vlc_common.h
index 791762f..260f40f 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -579,6 +579,9 @@ VLC_API void vlc_release(gc_object_t *);
 #   define __MIN(a, b)   ( ((a) < (b)) ? (a) : (b) )
 #endif
 
+/* clip v in [min, max] */
+#define CLIP(v, min, max)    __MIN(__MAX((v), (min)), (max))
+
 VLC_USED
 static inline int64_t GCD ( int64_t a, int64_t b )
 {
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 7ccb78f..1cca176 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -459,7 +459,7 @@ int OpenEncoder( vlc_object_t *p_this )
         if( p_sys->i_key_int > 0 )
             p_context->gop_size = p_sys->i_key_int;
         p_context->max_b_frames =
-            __MAX( __MIN( p_sys->i_b_frames, FF_MAX_B_FRAMES ), 0 );
+            CLIP( p_sys->i_b_frames, 0, FF_MAX_B_FRAMES );
         p_context->b_frame_strategy = 0;
         if( !p_context->max_b_frames  &&
             (  p_enc->fmt_out.i_codec == VLC_CODEC_MPGV ||
diff --git a/modules/demux/image.c b/modules/demux/image.c
index 4d899ad..96dc321 100644
--- a/modules/demux/image.c
+++ b/modules/demux/image.c
@@ -244,8 +244,7 @@ static int Control(demux_t *demux, int query, va_list args)
         if (sys->duration < 0 || sys->is_realtime)
             return VLC_EGENERIC;
         int64_t time = va_arg(args, int64_t);
-        date_Set(&sys->pts, __MIN(__MAX(time - sys->pts_origin, 0),
-                                  sys->duration));
+        date_Set(&sys->pts, CLIP(time - sys->pts_origin, 0, sys->duration));
         return VLC_SUCCESS;
     }
     case DEMUX_SET_NEXT_DEMUX_TIME: {
diff --git a/modules/demux/ps.c b/modules/demux/ps.c
index e675e80..7501b1a 100644
--- a/modules/demux/ps.c
+++ b/modules/demux/ps.c
@@ -252,7 +252,7 @@ static void FindLength( demux_t *p_demux )
 
         /* Check end */
         i_size = stream_Size( p_demux->s );
-        i_end = __MAX( 0, __MIN( 200000, i_size ) );
+        i_end = CLIP( i_size, 0, 200000 );
         stream_Seek( p_demux->s, i_size - i_end );
 
         i = 0;
diff --git a/modules/lua/libs/volume.c b/modules/lua/libs/volume.c
index 1f21ed0..33681cd 100644
--- a/modules/lua/libs/volume.c
+++ b/modules/lua/libs/volume.c
@@ -52,7 +52,7 @@
 static int vlclua_volume_set( lua_State *L )
 {
     playlist_t *p_this = vlclua_get_playlist_internal( L );
-    int i_volume = __MAX(__MIN(luaL_checkint( L, 1 ), AOUT_VOLUME_MAX), 0);
+    int i_volume = CLIP( luaL_checkint( L, 1 ), 0, AOUT_VOLUME_MAX );
     int i_ret = aout_VolumeSet( p_this, i_volume );
     return vlclua_push_ret( L, i_ret );
 }
diff --git a/modules/stream_out/raop.c b/modules/stream_out/raop.c
index a9e51fa..b037c09 100644
--- a/modules/stream_out/raop.c
+++ b/modules/stream_out/raop.c
@@ -1215,7 +1215,7 @@ static int UpdateVolume( vlc_object_t *p_this )
     /* Our volume is 0..255, RAOP is -144..0 (-144 off, -30..0 on) */
 
     /* Limit range */
-    p_sys->i_volume = __MAX( 0, __MIN( p_sys->i_volume, 255 ) );
+    p_sys->i_volume = CLIP( p_sys->i_volume, 0, 255 );
 
     if ( p_sys->i_volume == 0 )
         d_volume = -144.0;
diff --git a/modules/text_renderer/freetype.c b/modules/text_renderer/freetype.c
index 3d7291e..64a276a 100644
--- a/modules/text_renderer/freetype.c
+++ b/modules/text_renderer/freetype.c
@@ -2516,30 +2516,30 @@ static int Create( vlc_object_t *p_this )
     psz_fontfamily = var_InheritString( p_filter, "freetype-font" );
     p_sys->i_default_font_size = var_InheritInteger( p_filter, "freetype-fontsize" );
     p_sys->i_font_opacity = var_InheritInteger( p_filter,"freetype-opacity" );
-    p_sys->i_font_opacity = __MAX( __MIN( p_sys->i_font_opacity, 255 ), 0 );
+    p_sys->i_font_opacity = CLIP( p_sys->i_font_opacity, 0, 255 );
     p_sys->i_font_color = var_InheritInteger( p_filter, "freetype-color" );
-    p_sys->i_font_color = __MAX( __MIN( p_sys->i_font_color , 0xFFFFFF ), 0 );
+    p_sys->i_font_color = CLIP( p_sys->i_font_color, 0, 0xFFFFFF );
     p_sys->b_font_bold = var_InheritBool( p_filter, "freetype-bold" );
 
     p_sys->i_background_opacity = var_InheritInteger( p_filter,"freetype-background-opacity" );;
-    p_sys->i_background_opacity = __MAX( __MIN( p_sys->i_background_opacity, 255 ), 0 );
+    p_sys->i_background_opacity = CLIP( p_sys->i_background_opacity, 0, 255 );
     p_sys->i_background_color = var_InheritInteger( p_filter, "freetype-background-color" );
-    p_sys->i_background_color = __MAX( __MIN( p_sys->i_background_color, 0xFFFFFF ), 0 );
+    p_sys->i_background_color = CLIP( p_sys->i_background_color, 0, 0xFFFFFF );
 
     p_sys->f_outline_thickness = var_InheritInteger( p_filter, "freetype-outline-thickness" ) / 100.0;
-    p_sys->f_outline_thickness = __MAX( __MIN( p_sys->f_outline_thickness, 0.5 ), 0.0 );
+    p_sys->f_outline_thickness = CLIP( p_sys->f_outline_thickness, 0.0, 0.5 );
     p_sys->i_outline_opacity = var_InheritInteger( p_filter, "freetype-outline-opacity" );
-    p_sys->i_outline_opacity = __MAX( __MIN( p_sys->i_outline_opacity, 255 ), 0 );
+    p_sys->i_outline_opacity = CLIP( p_sys->i_outline_opacity, 0, 255 );
     p_sys->i_outline_color = var_InheritInteger( p_filter, "freetype-outline-color" );
-    p_sys->i_outline_color = __MAX( __MIN( p_sys->i_outline_color, 0xFFFFFF ), 0 );
+    p_sys->i_outline_color = CLIP( p_sys->i_outline_color, 0, 0xFFFFFF );
 
     p_sys->i_shadow_opacity = var_InheritInteger( p_filter, "freetype-shadow-opacity" );
-    p_sys->i_shadow_opacity = __MAX( __MIN( p_sys->i_shadow_opacity, 255 ), 0 );
+    p_sys->i_shadow_opacity = CLIP( p_sys->i_shadow_opacity, 0, 255 );
     p_sys->i_shadow_color = var_InheritInteger( p_filter, "freetype-shadow-color" );
-    p_sys->i_shadow_color = __MAX( __MIN( p_sys->i_shadow_color, 0xFFFFFF ), 0 );
+    p_sys->i_shadow_color = CLIP( p_sys->i_shadow_color, 0, 0xFFFFFF );
     float f_shadow_angle = var_InheritFloat( p_filter, "freetype-shadow-angle" );
     float f_shadow_distance = var_InheritFloat( p_filter, "freetype-shadow-distance" );
-    f_shadow_distance = __MAX( __MIN( f_shadow_distance, 1 ), 0 );
+    f_shadow_distance = CLIP( f_shadow_distance, 0, 1 );
     p_sys->f_shadow_vector_x = f_shadow_distance * cos(2 * M_PI * f_shadow_angle / 360);
     p_sys->f_shadow_vector_y = f_shadow_distance * sin(2 * M_PI * f_shadow_angle / 360);
 
diff --git a/modules/text_renderer/quartztext.c b/modules/text_renderer/quartztext.c
index a800c91..413a504 100644
--- a/modules/text_renderer/quartztext.c
+++ b/modules/text_renderer/quartztext.c
@@ -197,7 +197,7 @@ static int Create( vlc_object_t *p_this )
         return VLC_ENOMEM;
     p_sys->psz_font_name  = var_CreateGetString( p_this, "quartztext-font" );
     p_sys->i_font_opacity = 255;
-    p_sys->i_font_color = __MAX( __MIN( var_CreateGetInteger( p_this, "quartztext-color" ) , 0xFFFFFF ), 0 );
+    p_sys->i_font_color = CLIP( var_CreateGetInteger( p_this, "quartztext-color" ) , 0, 0xFFFFFF );
     p_sys->i_font_size    = GetFontSize( p_filter );
 
     p_filter->pf_render_text = RenderText;
@@ -330,9 +330,9 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
 
     if( p_region_in->p_style )
     {
-        i_font_color = __MAX( __MIN( p_region_in->p_style->i_font_color, 0xFFFFFF ), 0 );
-        i_font_alpha = __MAX( __MIN( p_region_in->p_style->i_font_alpha, 255 ), 0 );
-        i_font_size  = __MAX( __MIN( p_region_in->p_style->i_font_size, 255 ), 0 );
+        i_font_color = CLIP( p_region_in->p_style->i_font_color, 0, 0xFFFFFF );
+        i_font_alpha = CLIP( p_region_in->p_style->i_font_alpha, 0, 255 );
+        i_font_size  = CLIP( p_region_in->p_style->i_font_size, 0, 255 );
         if( p_region_in->p_style->i_style_flags )
         {
             if( p_region_in->p_style->i_style_flags & STYLE_BOLD )
diff --git a/modules/text_renderer/win32text.c b/modules/text_renderer/win32text.c
index 460a945..1948ab4 100644
--- a/modules/text_renderer/win32text.c
+++ b/modules/text_renderer/win32text.c
@@ -166,11 +166,11 @@ static int Create( vlc_object_t *p_this )
     var_Create( p_filter, "win32text-opacity",
                 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
     var_Get( p_filter, "win32text-opacity", &val );
-    p_sys->i_font_opacity = __MAX( __MIN( val.i_int, 255 ), 0 );
+    p_sys->i_font_opacity = CLIP( val.i_int, 0, 255 );
     var_Create( p_filter, "win32text-color",
                 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
     var_Get( p_filter, "win32text-color", &val );
-    p_sys->i_font_color = __MAX( __MIN( val.i_int, 0xFFFFFF ), 0 );
+    p_sys->i_font_color = CLIP( val.i_int, 0, 0xFFFFFF );
 
     p_sys->hfont = p_sys->hfont_bak = 0;
     hdc = GetDC( NULL );
@@ -335,9 +335,9 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
 
     if( p_region_in->p_style )
     {
-        i_font_color = __MAX( __MIN( p_region_in->p_style->i_font_color, 0xFFFFFF ), 0 );
-        i_font_alpha = __MAX( __MIN( p_region_in->p_style->i_font_alpha, 255 ), 0 );
-        i_font_size  = __MAX( __MIN( p_region_in->p_style->i_font_size, 255 ), 0 );
+        i_font_color = CLIP( p_region_in->p_style->i_font_color, 0, 0xFFFFFF );
+        i_font_alpha = CLIP( p_region_in->p_style->i_font_alpha, 0, 255 );
+        i_font_size  = CLIP( p_region_in->p_style->i_font_size, 0, 255 );
     }
     else
     {
diff --git a/modules/video_filter/audiobargraph_v.c b/modules/video_filter/audiobargraph_v.c
index 84ff77a..fe14e99 100644
--- a/modules/video_filter/audiobargraph_v.c
+++ b/modules/video_filter/audiobargraph_v.c
@@ -238,7 +238,7 @@ static int OpenCommon( vlc_object_t *p_this, bool b_sub )
     p_sys->i_pos_y = var_CreateGetIntegerCommand( p_filter, "audiobargraph_v-y" );
     p_BarGraph->i_alpha = var_CreateGetIntegerCommand( p_filter,
                                                         "audiobargraph_v-transparency" );
-    p_BarGraph->i_alpha = __MAX( __MIN( p_BarGraph->i_alpha, 255 ), 0 );
+    p_BarGraph->i_alpha = CLIP( p_BarGraph->i_alpha, 0, 255 );
     i_values = var_CreateGetStringCommand( p_filter, "audiobargraph_v-i_values" );
     //p_BarGraph->nbChannels = 0;
     //p_BarGraph->i_values = NULL;
@@ -479,7 +479,7 @@ static int BarGraphCallback( vlc_object_t *p_this, char const *psz_var,
     }
     else if ( !strcmp( psz_var, "audiobargraph_v-transparency" ) )
     {
-        p_BarGraph->i_alpha = __MAX( __MIN( newval.i_int, 255 ), 0 );
+        p_BarGraph->i_alpha = CLIP( newval.i_int, 0, 255 );
     }
     else if ( !strcmp( psz_var, "audiobargraph_v-i_values" ) )
     {
@@ -939,7 +939,7 @@ void parse_i_values( BarGraph_t *p_BarGraph, char *i_values)
         p_BarGraph->nbChannels++;
         p_BarGraph->i_values = xrealloc(p_BarGraph->i_values,
                                           p_BarGraph->nbChannels*sizeof(int));
-        p_BarGraph->i_values[p_BarGraph->nbChannels-1] = __MAX( __MIN( atof(res)*p_BarGraph->scale, p_BarGraph->scale ), 0 );
+        p_BarGraph->i_values[p_BarGraph->nbChannels-1] = CLIP( atof(res)*p_BarGraph->scale, 0, p_BarGraph->scale );
         res = strtok_r(NULL, delim, &tok);
     }
 
diff --git a/modules/video_filter/bluescreen.c b/modules/video_filter/bluescreen.c
index 86ffea9..a117257 100644
--- a/modules/video_filter/bluescreen.c
+++ b/modules/video_filter/bluescreen.c
@@ -133,7 +133,7 @@ static int Create( vlc_object_t *p_this )
     vlc_mutex_init( &p_sys->lock );
 #define GET_VAR( name, min, max )                                           \
     val = var_CreateGetIntegerCommand( p_filter, CFG_PREFIX #name );        \
-    p_sys->i_##name = __MIN( max, __MAX( min, val ) );                      \
+    p_sys->i_##name = CLIP( val, min, max );                                \
     var_AddCallback( p_filter, CFG_PREFIX #name, BluescreenCallback, p_sys );
 
     GET_VAR( u, 0x00, 0xff );
@@ -267,13 +267,13 @@ static int BluescreenCallback( vlc_object_t *p_this, char const *psz_var,
     vlc_mutex_lock( &p_sys->lock );
 #define VAR_IS( a ) !strcmp( psz_var, CFG_PREFIX a )
     if( VAR_IS( "u" ) )
-        p_sys->i_u = __MAX( 0, __MIN( 255, newval.i_int ) );
+        p_sys->i_u = CLIP( newval.i_int, 0, 255 );
     else if( VAR_IS( "v" ) )
-        p_sys->i_v = __MAX( 0, __MIN( 255, newval.i_int ) );
+        p_sys->i_v = CLIP( newval.i_int, 0, 255 );
     else if( VAR_IS( "ut" ) )
-        p_sys->i_ut = __MAX( 0, __MIN( 255, newval.i_int ) );
+        p_sys->i_ut = CLIP( newval.i_int, 0, 255 );
     else if( VAR_IS( "vt" ) )
-        p_sys->i_vt = __MAX( 0, __MIN( 255, newval.i_int ) );
+        p_sys->i_vt = CLIP( newval.i_int, 0, 255 );
     vlc_mutex_unlock( &p_sys->lock );
 
     return VLC_SUCCESS;
diff --git a/modules/video_filter/gradfun.c b/modules/video_filter/gradfun.c
index 4db3d1d..2c4078e 100644
--- a/modules/video_filter/gradfun.c
+++ b/modules/video_filter/gradfun.c
@@ -177,8 +177,8 @@ static picture_t *Filter(filter_t *filter, picture_t *src)
     }
 
     vlc_mutex_lock(&sys->lock);
-    float strength = __MIN(__MAX(sys->strength, STRENGTH_MIN), STRENGTH_MAX);
-    int   radius   = __MIN(__MAX((sys->radius + 1) & ~1, RADIUS_MIN), RADIUS_MAX);
+    float strength = CLIP(sys->strength, STRENGTH_MIN, STRENGTH_MAX);
+    int   radius   = CLIP((sys->radius + 1) & ~1, RADIUS_MIN, RADIUS_MAX);
     vlc_mutex_unlock(&sys->lock);
 
     const video_format_t *fmt = &filter->fmt_in.video;
@@ -200,7 +200,7 @@ static picture_t *Filter(filter_t *filter, picture_t *src)
         int h = fmt->i_height * chroma->p[i].h.num / chroma->p[i].h.den;
         int r = (cfg->radius  * chroma->p[i].w.num / chroma->p[i].w.den +
                  cfg->radius  * chroma->p[i].h.num / chroma->p[i].h.den) / 2;
-        r = __MIN(__MAX((r + 1) & ~1, RADIUS_MIN), RADIUS_MAX);
+        r = CLIP((r + 1) & ~1, RADIUS_MIN, RADIUS_MAX);
         if (__MIN(w, h) > 2 * r && cfg->buf) {
             filter_plane(cfg, dstp->p_pixels, srcp->p_pixels,
                          w, h, dstp->i_pitch, srcp->i_pitch, r);
diff --git a/modules/video_filter/grain.c b/modules/video_filter/grain.c
index cbdb133..e659413 100644
--- a/modules/video_filter/grain.c
+++ b/modules/video_filter/grain.c
@@ -258,7 +258,7 @@ static picture_t *Filter(filter_t *filter, picture_t *src)
     }
 
     vlc_mutex_lock(&sys->cfg.lock);
-    const double variance = __MIN(__MAX(sys->cfg.variance, VARIANCE_MIN), VARIANCE_MAX);
+    const double variance = CLIP(sys->cfg.variance, VARIANCE_MIN, VARIANCE_MAX);
     vlc_mutex_unlock(&sys->cfg.lock);
 
     const int scale = 256 * sqrt(variance);
@@ -352,7 +352,7 @@ static int Generate(int16_t *bank, int h_min, int h_max, int v_min, int v_max)
                 vq =  (int)( v * correction * 127 + 0.5);
             else
                 vq = -(int)(-v * correction * 127 + 0.5);
-            bank[i * N + j] = __MIN(__MAX(vq, INT16_MIN), INT16_MAX);
+            bank[i * N + j] = CLIP(vq, INT16_MIN, INT16_MAX);
         }
     }
     //mtime_t mul_duration = mdate() - tmul_0;
@@ -397,8 +397,8 @@ static int Open(vlc_object_t *object)
 
     int cutoff_low = BANK_SIZE - var_InheritInteger(filter, CFG_PREFIX "period-max");
     int cutoff_high= BANK_SIZE - var_InheritInteger(filter, CFG_PREFIX "period-min");
-    cutoff_low  = __MIN(__MAX(cutoff_low,  1), BANK_SIZE - 1);
-    cutoff_high = __MIN(__MAX(cutoff_high, 1), BANK_SIZE - 1);
+    cutoff_low  = CLIP(cutoff_low, 1, BANK_SIZE - 1);
+    cutoff_high = CLIP(cutoff_high, 1, BANK_SIZE - 1);
     if (Generate(sys->bank, cutoff_low, cutoff_high, cutoff_low, cutoff_high)) {
         free(sys);
         return VLC_EGENERIC;
diff --git a/modules/video_filter/logo.c b/modules/video_filter/logo.c
index 9174e5f..039be85 100644
--- a/modules/video_filter/logo.c
+++ b/modules/video_filter/logo.c
@@ -269,7 +269,7 @@ static int OpenCommon( vlc_object_t *p_this, bool b_sub )
         msg_Warn( p_this, "no logo file specified" );
 
     p_list->i_alpha = var_CreateGetIntegerCommand( p_filter, "logo-opacity");
-    p_list->i_alpha = __MAX( __MIN( p_list->i_alpha, 255 ), 0 );
+    p_list->i_alpha = CLIP( p_list->i_alpha, 0, 255 );
     p_list->i_delay = var_CreateGetIntegerCommand( p_filter, "logo-delay" );
     p_list->i_repeat = var_CreateGetIntegerCommand( p_filter, "logo-repeat" );
 
@@ -529,9 +529,9 @@ static int Mouse( filter_t *p_filter, vlc_mouse_t *p_mouse,
         {
             int i_dx, i_dy;
             vlc_mouse_GetMotion( &i_dx, &i_dy, p_old, p_new );
-            p_sys->i_pos_x = __MIN( __MAX( p_sys->i_pos_x + i_dx, 0 ),
+            p_sys->i_pos_x = CLIP( p_sys->i_pos_x + i_dx, 0,
                                     p_filter->fmt_in.video.i_width  - i_logo_w );
-            p_sys->i_pos_y = __MIN( __MAX( p_sys->i_pos_y + i_dy, 0 ),
+            p_sys->i_pos_y = CLIP( p_sys->i_pos_y + i_dy, 0,
                                     p_filter->fmt_in.video.i_height - i_logo_h );
 
             /* object under mouse has moved */
@@ -585,7 +585,7 @@ static int LogoCallback( vlc_object_t *p_this, char const *psz_var,
     }
     else if ( !strcmp( psz_var, "logo-opacity" ) )
     {
-        p_list->i_alpha = __MAX( __MIN( newval.i_int, 255 ), 0 );
+        p_list->i_alpha = CLIP( newval.i_int, 0, 255 );
     }
     else if ( !strcmp( psz_var, "logo-repeat" ) )
     {
diff --git a/modules/video_filter/magnify.c b/modules/video_filter/magnify.c
index 2ddbc8b..34dfdea 100644
--- a/modules/video_filter/magnify.c
+++ b/modules/video_filter/magnify.c
@@ -356,9 +356,9 @@ static int Mouse( filter_t *p_filter, vlc_mouse_t *p_mouse, const vlc_mouse_t *p
                 const int v_w = p_fmt->i_width  * ZOOM_FACTOR / p_sys->i_zoom;
                 const int v_h = p_fmt->i_height * ZOOM_FACTOR / p_sys->i_zoom;
 
-                p_sys->i_x = __MIN( __MAX( p_new->i_x * VIS_ZOOM - v_w/2, 0 ),
+                p_sys->i_x = CLIP( p_new->i_x * VIS_ZOOM - v_w/2, 0,
                                            (int)p_fmt->i_width  - v_w - 1);
-                p_sys->i_y = __MIN( __MAX( p_new->i_y * VIS_ZOOM - v_h/2, 0 ),
+                p_sys->i_y = CLIP( p_new->i_y * VIS_ZOOM - v_h/2, 0,
                                            (int)p_fmt->i_height - v_h - 1);
 
                 b_grab = true;
@@ -390,8 +390,8 @@ static int Mouse( filter_t *p_filter, vlc_mouse_t *p_mouse, const vlc_mouse_t *p
 
                 const int v_w = p_fmt->i_width  * ZOOM_FACTOR / p_sys->i_zoom;
                 const int v_h = p_fmt->i_height * ZOOM_FACTOR / p_sys->i_zoom;
-                p_sys->i_x = __MAX( __MIN( p_sys->i_x, (int)p_fmt->i_width  - v_w - 1 ), 0 );
-                p_sys->i_y = __MAX( __MIN( p_sys->i_y, (int)p_fmt->i_height - v_h - 1 ), 0 );
+                p_sys->i_x = CLIP( p_sys->i_x, 0, (int)p_fmt->i_width  - v_w - 1 );
+                p_sys->i_y = CLIP( p_sys->i_y, 0, (int)p_fmt->i_height - v_h - 1 );
 
                 b_grab = true;
             }
diff --git a/modules/video_filter/mosaic.c b/modules/video_filter/mosaic.c
index ed73a7b..3059231 100644
--- a/modules/video_filter/mosaic.c
+++ b/modules/video_filter/mosaic.c
@@ -299,7 +299,7 @@ static int CreateFilter( vlc_object_t *p_this )
 
 #define GET_VAR( name, min, max )                                           \
     i_command = var_CreateGetIntegerCommand( p_filter, CFG_PREFIX #name );  \
-    p_sys->i_##name = __MIN( max, __MAX( min, i_command ) );                \
+    p_sys->i_##name = CLIP( i_command, min, max );                \
     var_AddCallback( p_filter, CFG_PREFIX #name, MosaicCallback, p_sys );
 
     GET_VAR( width, 0, INT_MAX );
@@ -738,7 +738,7 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
         vlc_mutex_lock( &p_sys->lock );
         msg_Dbg( p_this, "changing alpha from %d/255 to %d/255",
                          p_sys->i_alpha, (int)newval.i_int);
-        p_sys->i_alpha = __MIN( __MAX( newval.i_int, 0 ), 255 );
+        p_sys->i_alpha = CLIP( newval.i_int, 0, 255 );
         vlc_mutex_unlock( &p_sys->lock );
     }
     else if( VAR_IS( "height" ) )
@@ -777,7 +777,7 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
     {
         int i_old = 0, i_new = 0;
         vlc_mutex_lock( &p_sys->lock );
-        newval.i_int = __MIN( __MAX( newval.i_int, 0 ), 10 );
+        newval.i_int = CLIP( newval.i_int, 0, 10 );
         if( newval.i_int == 3 || newval.i_int == 7 )
             newval.i_int = 5;
         while( pi_align_values[i_old] != p_sys->i_align ) i_old++;
diff --git a/modules/video_filter/motionblur.c b/modules/video_filter/motionblur.c
index 8cec59b..5e0ed59 100644
--- a/modules/video_filter/motionblur.c
+++ b/modules/video_filter/motionblur.c
@@ -215,7 +215,7 @@ static int MotionBlurCallback( vlc_object_t *p_this, char const *psz_var,
     if( !strcmp( psz_var, FILTER_PREFIX "factor" ) )
     {
         vlc_spin_lock( &p_sys->lock );
-        p_sys->i_factor = __MIN( 127, __MAX( 1, newval.i_int ) );
+        p_sys->i_factor = CLIP( newval.i_int, 1, 127 );
         vlc_spin_unlock( &p_sys->lock );
     }
     return VLC_SUCCESS;
diff --git a/modules/video_filter/panoramix.c b/modules/video_filter/panoramix.c
index 430e9be..9e94642 100644
--- a/modules/video_filter/panoramix.c
+++ b/modules/video_filter/panoramix.c
@@ -499,8 +499,8 @@ static int Open( vlc_object_t *p_this )
     p_sys->a_0 =  p_sys->bz_begin;
 
     /* */
-    p_sys->i_col = __MAX( 1, __MIN( COL_MAX, p_sys->i_col ) );
-    p_sys->i_row = __MAX( 1, __MIN( ROW_MAX, p_sys->i_row ) );
+    p_sys->i_col = CLIP( COL_MAX, 1, p_sys->i_col );
+    p_sys->i_row = CLIP( ROW_MAX, 1, p_sys->i_row );
     msg_Dbg( p_splitter, "opening a %i x %i wall",
              p_sys->i_col, p_sys->i_row );
 
diff --git a/modules/video_filter/sharpen.c b/modules/video_filter/sharpen.c
index f9445a1..6265f9e 100644
--- a/modules/video_filter/sharpen.c
+++ b/modules/video_filter/sharpen.c
@@ -236,7 +236,7 @@ static int SharpenCallback( vlc_object_t *p_this, char const *psz_var,
     filter_sys_t *p_sys = (filter_sys_t *)p_data;
 
     vlc_mutex_lock( &p_sys->lock );
-    init_precalc_table(p_sys,  __MIN( 2., __MAX( 0., newval.f_float ) ));
+    init_precalc_table( p_sys,  CLIP( newval.f_float, 0., 2. ) );
     vlc_mutex_unlock( &p_sys->lock );
     return VLC_SUCCESS;
 }
diff --git a/modules/video_filter/wall.c b/modules/video_filter/wall.c
index a1329bb..38fa304 100644
--- a/modules/video_filter/wall.c
+++ b/modules/video_filter/wall.c
@@ -129,10 +129,10 @@ static int Open( vlc_object_t *p_this )
 
     /* */
     p_sys->i_col = var_CreateGetInteger( p_splitter, CFG_PREFIX "cols" );
-    p_sys->i_col = __MAX( 1, __MIN( COL_MAX, p_sys->i_col ) );
+    p_sys->i_col = CLIP( COL_MAX, 1, p_sys->i_col );
 
     p_sys->i_row = var_CreateGetInteger( p_splitter, CFG_PREFIX "rows" );
-    p_sys->i_row = __MAX( 1, __MIN( ROW_MAX, p_sys->i_row ) );
+    p_sys->i_row = CLIP( ROW_MAX, 1, p_sys->i_row );
 
     msg_Dbg( p_splitter, "opening a %i x %i wall",
              p_sys->i_col, p_sys->i_row );
diff --git a/src/input/stream.c b/src/input/stream.c
index 1a92b6b..53b4fa1 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -738,7 +738,7 @@ static int AStreamReadBlock( stream_t *s, void *p_read, unsigned int i_read )
     {
         int i_current =
             p_sys->block.p_current->i_buffer - p_sys->block.i_offset;
-        unsigned int i_copy = __MIN( (unsigned int)__MAX(i_current,0), i_read - i_data);
+        unsigned int i_copy = CLIP( (unsigned int)i_current, 0, i_read - i_data);
 
         /* Copy data */
         if( p_data )
@@ -1312,9 +1312,9 @@ static int AStreamReadNoSeekStream( stream_t *s, void *p_read, unsigned int i_re
 
         if( tk->i_end + i_data <= tk->i_start + p_sys->stream.i_offset + i_read )
         {
-            const unsigned i_read_requested = __MAX( __MIN( i_read - i_data,
-                                                            STREAM_READ_ATONCE * 10 ),
-                                                     STREAM_READ_ATONCE / 2 );
+            const unsigned i_read_requested = CLIP( i_read - i_data,
+                                                    STREAM_READ_ATONCE / 2,
+                                                    STREAM_READ_ATONCE * 10 );
 
             if( p_sys->stream.i_used < i_read_requested )
                 p_sys->stream.i_used = i_read_requested;
diff --git a/src/video_output/display.c b/src/video_output/display.c
index c743836..ff6a958 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -992,28 +992,26 @@ void vout_ManageDisplay(vout_display_t *vd, bool allow_reset_pictures)
             }
             const int right_max  = osys->source.i_x_offset + osys->source.i_visible_width;
             const int bottom_max = osys->source.i_y_offset + osys->source.i_visible_height;
-#define __CLIP(v, a, b) __MAX(__MIN(v, b), a)
-            int left   = __CLIP((int)osys->source.i_x_offset + osys->crop.left,
+            int left   = CLIP((int)osys->source.i_x_offset + osys->crop.left,
                                 0, right_max - 1);
-            int top    = __CLIP((int)osys->source.i_y_offset + osys->crop.top,
+            int top    = CLIP((int)osys->source.i_y_offset + osys->crop.top,
                                 0, bottom_max - 1);
             int right, bottom;
             if (osys->crop.right <= 0)
                 right = (int)(osys->source.i_x_offset + osys->source.i_visible_width) + osys->crop.right;
             else
                 right = (int)osys->source.i_x_offset + osys->crop.right;
-            right = __CLIP(right, left + 1, right_max);
+            right = CLIP(right, left + 1, right_max);
             if (osys->crop.bottom <= 0)
                 bottom = (int)(osys->source.i_y_offset + osys->source.i_visible_height) + osys->crop.bottom;
             else
                 bottom = (int)osys->source.i_y_offset + osys->crop.bottom;
-            bottom = __CLIP(bottom, top + 1, bottom_max);
+            bottom = CLIP(bottom, top + 1, bottom_max);
 
             source.i_x_offset       = left;
             source.i_y_offset       = top;
             source.i_visible_width  = right - left;
             source.i_visible_height = bottom - top;
-#undef __CLIP
             video_format_Print(VLC_OBJECT(vd), "SOURCE ", &osys->source);
             video_format_Print(VLC_OBJECT(vd), "CROPPED", &source);
             if (vout_display_Control(vd, VOUT_DISPLAY_CHANGE_SOURCE_CROP, &source)) {
diff --git a/src/video_output/interlacing.c b/src/video_output/interlacing.c
index a5dec23..1dada8e 100644
--- a/src/video_output/interlacing.c
+++ b/src/video_output/interlacing.c
@@ -175,7 +175,7 @@ void vout_InitInterlacingSupport(vout_thread_t *vout, bool is_interlaced)
     /* */
     var_Create(vout, "deinterlace", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT | VLC_VAR_HASCHOICE);
     int deinterlace_state = var_GetInteger(vout, "deinterlace");
-    deinterlace_state = __MAX(__MIN(deinterlace_state, 1), -1);
+    deinterlace_state = CLIP(deinterlace_state, -1, 1);
 
     text.psz_string = _("Deinterlace");
     var_Change(vout, "deinterlace", VLC_VAR_SETTEXT, &text, NULL);
diff --git a/src/video_output/video_epg.c b/src/video_output/video_epg.c
index d25ced1..5917038 100644
--- a/src/video_output/video_epg.c
+++ b/src/video_output/video_epg.c
@@ -71,7 +71,7 @@ static subpicture_region_t * vout_OSDEpgSlider(int x, int y,
 
     picture_t *picture = region->p_picture;
 
-    ratio = __MIN(__MAX(ratio, 0), 1);
+    ratio = CLIP(ratio, 0, 1);
     int filled_part_width = ratio * width;
 
     for (int j = 0; j < height; j++) {
diff --git a/src/video_output/video_widgets.c b/src/video_output/video_widgets.c
index a03aaf7..38f0034 100644
--- a/src/video_output/video_widgets.c
+++ b/src/video_output/video_widgets.c
@@ -293,7 +293,7 @@ static void OSDWidget(vout_thread_t *vout, int channel, int type, int position)
     if (!var_InheritBool(vout, "osd"))
         return;
     if (type == OSD_HOR_SLIDER || type == OSD_VERT_SLIDER)
-        position = __MIN(__MAX(position, 0), 100);
+        position = CLIP(position, 0, 100);
 
     subpicture_updater_sys_t *sys = malloc(sizeof(*sys));
     if (!sys)
-- 
1.7.7.3




More information about the vlc-devel mailing list