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 )
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; }
......
......@@ -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;
......
......@@ -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 );
}}
}
}
......
......@@ -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
......
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