]> git.sesse.net Git - vlc/commitdiff
Copy clip_uint8() function from ffmpeg and replace where applicable for video filters.
authorAntoine Cellerier <dionoea@videolan.org>
Fri, 2 Feb 2007 20:51:11 +0000 (20:51 +0000)
committerAntoine Cellerier <dionoea@videolan.org>
Fri, 2 Feb 2007 20:51:11 +0000 (20:51 +0000)
include/vlc_common.h
modules/video_filter/adjust.c
modules/video_filter/gradient.c
modules/video_filter/panoramix.c

index bf67cae618cb7a932369573cee2b299425c8ffa5..334b7bf84c6cec47150542c74a9137b9c0d2471e 100644 (file)
@@ -627,6 +627,13 @@ static int64_t GCD( int64_t a, int64_t b )
     else return a;
 }
 
+/* function imported from libavutil/common.h */
+static inline uint8_t clip_uint8_vlc( int32_t a )
+{
+    if( a&(~255) ) return (-a)>>31;
+    else           return a;
+}
+
 /* Malloc with automatic error */
 #define MALLOC_VOID( var, type ) { var = (type*)malloc( sizeof( type) ); \
                                    if( !var ) return; }
index 47121a6f9325a76396b68b6e28a3af934e42f264..ffa0d0fe0b63205c4afdab1fc7a0d62ebbc46aea 100644 (file)
@@ -106,11 +106,6 @@ struct filter_sys_t
 {
 };
 
-inline static int32_t clip( int32_t a )
-{
-    return (a > 255) ? 255 : (a < 0) ? 0 : a;
-}
-
 /*****************************************************************************
  * Create: allocates adjust video thread output method
  *****************************************************************************
@@ -259,13 +254,13 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
         /* Fill the gamma lookup table */
         for( i = 0 ; i < 256 ; i++ )
         {
-          pi_gamma[ i ] = clip( pow(i / 255.0, f_gamma) * 255.0);
+          pi_gamma[ i ] = clip_uint8_vlc( pow(i / 255.0, f_gamma) * 255.0);
         }
 
         /* Fill the luma lookup table */
         for( i = 0 ; i < 256 ; i++ )
         {
-            pi_luma[ i ] = pi_gamma[clip( i_lum + i_cont * i / 256)];
+            pi_luma[ i ] = pi_gamma[clip_uint8_vlc( i_lum + i_cont * i / 256)];
         }
     }
     else
@@ -343,9 +338,9 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
     {
 #define WRITE_UV_CLIP() \
     i_u = *p_in++ ; i_v = *p_in_v++ ; \
-    *p_out++ = clip( (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \
+    *p_out++ = clip_uint8_vlc( (( ((i_u * i_cos + i_v * i_sin - i_x) >> 8) \
                            * i_sat) >> 8) + 128); \
-    *p_out_v++ = clip( (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \
+    *p_out_v++ = clip_uint8_vlc( (( ((i_v * i_cos - i_u * i_sin - i_y) >> 8) \
                            * i_sat) >> 8) + 128)
 
         uint8_t i_u, i_v;
index c3457487b12bef62ae24d37d6497a5555b73cec7..93a320fb6c0ce58524511bf2b9332719c1368bb7 100644 (file)
@@ -418,10 +418,7 @@ static void FilterGradient( filter_t *p_filter, picture_t *p_inpic,
         else
         {
             FOR
-            if( a>>8 )
-                p_outpix[y*i_dst_pitch+x] = 255;
-            else
-                p_outpix[y*i_dst_pitch+x] = (uint8_t)a;
+            p_outpix[y*i_dst_pitch+x] = clip_uint8( a );
             }}
         }
     }
index c7ee0bebb442dd077bae091288599555ecfbf970..62f74afcee86f0f036aeb4949196feeafa4c54a0 100644 (file)
@@ -40,8 +40,8 @@
     // OS CODE DEPENDANT to get display dimensions
     #ifdef SYS_MINGW32
         #include <windows.h>
-    #else 
-        #include <X11/Xlib.h>   
+    #else
+        #include <X11/Xlib.h>
     #endif
     #define GAMMA        1
 //  #define PACKED_YUV    1
@@ -367,7 +367,7 @@ case VLC_FOURCC('c','y','u','v'):    // packed by 2
 
 #ifdef OVERLAP
     p_vout->p_sys->i_offset_x = var_CreateGetInteger( p_vout, "offset-x" );
-    if (p_vout->p_sys->i_col > 2) p_vout->p_sys->i_offset_x = 0; // offset-x is used in case of 2x1 wall & autocrop    
+    if (p_vout->p_sys->i_col > 2) p_vout->p_sys->i_offset_x = 0; // offset-x is used in case of 2x1 wall & autocrop
     p_vout->p_sys->b_autocrop = !(var_CreateGetInteger( p_vout, "crop-ratio" ) == 0);
     if (!p_vout->p_sys->b_autocrop) p_vout->p_sys->b_autocrop = var_CreateGetInteger( p_vout, "autocrop" );            
     p_vout->p_sys->b_attenuate = var_CreateGetInteger( p_vout, "panoramix-attenuate");
@@ -383,7 +383,7 @@ case VLC_FOURCC('c','y','u','v'):    // packed by 2
     double d_p = 100.0 / p_vout->p_sys->bz_middle_pos;
     p_vout->p_sys->i_ratio_max = var_CreateGetInteger( p_vout, "autocrop-ratio-max" ); // in crop module with autocrop ...
     p_vout->p_sys->i_ratio = var_CreateGetInteger( p_vout, "crop-ratio" ); // in crop module with manual ratio ...     
-    
+
     p_vout->p_sys->a_2 = d_p * p_vout->p_sys->bz_begin - (double)(d_p * d_p / (d_p - 1)) * p_vout->p_sys->bz_middle + (double)(d_p / (d_p - 1)) * p_vout->p_sys->bz_end;
     p_vout->p_sys->a_1 = -(d_p + 1) * p_vout->p_sys->bz_begin + (double)(d_p * d_p / (d_p - 1)) * p_vout->p_sys->bz_middle - (double)(1 / (d_p - 1)) * p_vout->p_sys->bz_end;
     p_vout->p_sys->a_0 =  p_vout->p_sys->bz_begin;
@@ -498,13 +498,6 @@ static double Gamma_Correction(int i_plane, float f_component, float f_BlackCrus
 }
 
 #ifdef PACKED_YUV
-/*****************************************************************************
- * Clip: clip an 32 bits int in 8 bits
- *****************************************************************************/
-inline static int32_t clip( int32_t a )
-{
-    return (a > 255) ? 255 : (a < 0) ? 0 : a;
-}
 
 /*****************************************************************************
  * F: Function to calculate Gamma correction
@@ -516,9 +509,9 @@ static uint8_t F(uint8_t i, float gamma)
 // return clip(255 * pow(input, 1.0 / gamma));
 
  if (input < 0.5)
-     return clip((255 * pow(2 * input, gamma)) / 2);
+     return clip_uint8((255 * pow(2 * input, gamma)) / 2);
  else
-     return clip(255 * (1 - pow(2 * (1 - input), gamma) / 2));
+     return clip_uint8(255 * (1 - pow(2 * (1 - input), gamma) / 2));
 
 }
 #endif
@@ -543,7 +536,7 @@ static int AdjustHeight( vout_thread_t *p_vout )
 #ifdef SYS_MINGW32
             i_window_width  = GetSystemMetrics(SM_CXSCREEN);
             i_window_height = GetSystemMetrics(SM_CYSCREEN);
-#else            
+#else
             Display *p_display = XOpenDisplay( "" );
                if (p_vout->p_sys->b_xinerama)
                {
@@ -554,9 +547,9 @@ static int AdjustHeight( vout_thread_t *p_vout )
                {
                    i_window_width = DisplayWidth(p_display, 0);
                    i_window_height = DisplayHeight(p_display, 0);
-               } 
-               XCloseDisplay( p_display );     
-               free(p_display);  
+               }
+               XCloseDisplay( p_display );
+               free(p_display);
 #endif
         var_SetInteger( p_vout, "width", i_window_width);
         var_SetInteger( p_vout, "height", i_window_height);