Commit 1360a812 authored by Antoine Cellerier's avatar Antoine Cellerier

Copy clip_uint8() function from ffmpeg and replace where applicable for video filters.

parent 0a40fae1
...@@ -627,6 +627,13 @@ static int64_t GCD( int64_t a, int64_t b ) ...@@ -627,6 +627,13 @@ static int64_t GCD( int64_t a, int64_t b )
else return a; 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 */ /* Malloc with automatic error */
#define MALLOC_VOID( var, type ) { var = (type*)malloc( sizeof( type) ); \ #define MALLOC_VOID( var, type ) { var = (type*)malloc( sizeof( type) ); \
if( !var ) return; } if( !var ) return; }
......
...@@ -106,11 +106,6 @@ struct filter_sys_t ...@@ -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 * Create: allocates adjust video thread output method
***************************************************************************** *****************************************************************************
...@@ -259,13 +254,13 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -259,13 +254,13 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
/* Fill the gamma lookup table */ /* Fill the gamma lookup table */
for( i = 0 ; i < 256 ; i++ ) 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 */ /* Fill the luma lookup table */
for( i = 0 ; i < 256 ; i++ ) 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 else
...@@ -343,9 +338,9 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) ...@@ -343,9 +338,9 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
{ {
#define WRITE_UV_CLIP() \ #define WRITE_UV_CLIP() \
i_u = *p_in++ ; i_v = *p_in_v++ ; \ 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); \ * 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) * i_sat) >> 8) + 128)
uint8_t i_u, i_v; uint8_t i_u, i_v;
......
...@@ -418,10 +418,7 @@ static void FilterGradient( filter_t *p_filter, picture_t *p_inpic, ...@@ -418,10 +418,7 @@ static void FilterGradient( filter_t *p_filter, picture_t *p_inpic,
else else
{ {
FOR FOR
if( a>>8 ) p_outpix[y*i_dst_pitch+x] = clip_uint8( a );
p_outpix[y*i_dst_pitch+x] = 255;
else
p_outpix[y*i_dst_pitch+x] = (uint8_t)a;
}} }}
} }
} }
......
...@@ -40,8 +40,8 @@ ...@@ -40,8 +40,8 @@
// OS CODE DEPENDANT to get display dimensions // OS CODE DEPENDANT to get display dimensions
#ifdef SYS_MINGW32 #ifdef SYS_MINGW32
#include <windows.h> #include <windows.h>
#else #else
#include <X11/Xlib.h> #include <X11/Xlib.h>
#endif #endif
#define GAMMA 1 #define GAMMA 1
// #define PACKED_YUV 1 // #define PACKED_YUV 1
...@@ -367,7 +367,7 @@ case VLC_FOURCC('c','y','u','v'): // packed by 2 ...@@ -367,7 +367,7 @@ case VLC_FOURCC('c','y','u','v'): // packed by 2
#ifdef OVERLAP #ifdef OVERLAP
p_vout->p_sys->i_offset_x = var_CreateGetInteger( p_vout, "offset-x" ); 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); 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" ); 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"); 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 ...@@ -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; 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_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->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_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_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; 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 ...@@ -498,13 +498,6 @@ static double Gamma_Correction(int i_plane, float f_component, float f_BlackCrus
} }
#ifdef PACKED_YUV #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 * F: Function to calculate Gamma correction
...@@ -516,9 +509,9 @@ static uint8_t F(uint8_t i, float gamma) ...@@ -516,9 +509,9 @@ static uint8_t F(uint8_t i, float gamma)
// return clip(255 * pow(input, 1.0 / gamma)); // return clip(255 * pow(input, 1.0 / gamma));
if (input < 0.5) if (input < 0.5)
return clip((255 * pow(2 * input, gamma)) / 2); return clip_uint8((255 * pow(2 * input, gamma)) / 2);
else else
return clip(255 * (1 - pow(2 * (1 - input), gamma) / 2)); return clip_uint8(255 * (1 - pow(2 * (1 - input), gamma) / 2));
} }
#endif #endif
...@@ -543,7 +536,7 @@ static int AdjustHeight( vout_thread_t *p_vout ) ...@@ -543,7 +536,7 @@ static int AdjustHeight( vout_thread_t *p_vout )
#ifdef SYS_MINGW32 #ifdef SYS_MINGW32
i_window_width = GetSystemMetrics(SM_CXSCREEN); i_window_width = GetSystemMetrics(SM_CXSCREEN);
i_window_height = GetSystemMetrics(SM_CYSCREEN); i_window_height = GetSystemMetrics(SM_CYSCREEN);
#else #else
Display *p_display = XOpenDisplay( "" ); Display *p_display = XOpenDisplay( "" );
if (p_vout->p_sys->b_xinerama) if (p_vout->p_sys->b_xinerama)
{ {
...@@ -554,9 +547,9 @@ static int AdjustHeight( vout_thread_t *p_vout ) ...@@ -554,9 +547,9 @@ static int AdjustHeight( vout_thread_t *p_vout )
{ {
i_window_width = DisplayWidth(p_display, 0); i_window_width = DisplayWidth(p_display, 0);
i_window_height = DisplayHeight(p_display, 0); i_window_height = DisplayHeight(p_display, 0);
} }
XCloseDisplay( p_display ); XCloseDisplay( p_display );
free(p_display); free(p_display);
#endif #endif
var_SetInteger( p_vout, "width", i_window_width); var_SetInteger( p_vout, "width", i_window_width);
var_SetInteger( p_vout, "height", i_window_height); var_SetInteger( p_vout, "height", i_window_height);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment