Index: modules/video_filter/adjust.c =================================================================== --- modules/video_filter/adjust.c (revision 13784) +++ modules/video_filter/adjust.c (working copy) @@ -57,6 +57,8 @@ * Module descriptor *****************************************************************************/ +#define THRES_TEXT N_("Enable threshold") +#define THRES_LONGTEXT N_("Show black and white pixels with brightness as threshold value") #define CONT_TEXT N_("Image contrast (0-2)") #define CONT_LONGTEXT N_("Set the image contrast, between 0 and 2. Defaults to 1") #define HUE_TEXT N_("Image hue (0-360)") @@ -76,6 +78,7 @@ set_subcategory( SUBCAT_VIDEO_VFILTER ); set_capability( "video filter", 0 ); + add_bool( "threshold", 0, NULL, THRES_TEXT, THRES_LONGTEXT, VLC_FALSE ); add_float_with_range( "contrast", 1.0, 0.0, 2.0, NULL, CONT_TEXT, CONT_LONGTEXT, VLC_FALSE ); add_float_with_range( "brightness", 1.0, 0.0, 2.0, NULL, LUM_TEXT, LUM_LONGTEXT, VLC_FALSE ); add_integer_with_range( "hue", 0, 0, 360, NULL, HUE_TEXT, HUE_LONGTEXT, VLC_FALSE ); @@ -133,7 +136,8 @@ p_vout->pf_render = Render; p_vout->pf_display = NULL; p_vout->pf_control = Control; - + + var_Create( p_vout, "threshold", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); var_Create( p_vout, "contrast", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT ); var_Create( p_vout, "brightness", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT ); var_Create( p_vout, "hue", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); @@ -242,6 +246,7 @@ uint8_t *p_in, *p_in_v, *p_in_end, *p_line_end; uint8_t *p_out, *p_out_v; + vlc_bool_t b_thres; double f_hue; double f_gamma; int32_t i_cont, i_lum; @@ -264,10 +269,19 @@ vout_LinkPicture( p_vout->p_sys->p_vout, p_outpic ); /* Getvariables */ + var_Get( p_vout, "threshold", &val ); + b_thres = (vlc_bool_t) ( val.b_bool ); var_Get( p_vout, "contrast", &val ); i_cont = (int) ( val.f_float * 255 ); var_Get( p_vout, "brightness", &val ); - i_lum = (int) (( val.f_float - 1.0 ) * 255 ); + /* + * This to avoid default value setting to zero, making all screen + * white (in threshold mode). + */ + if( b_thres != VLC_TRUE ) + i_lum = (int) (( val.f_float - 1.0 ) * 255 ); + else + i_lum = (int) ( val.f_float * 128 ); var_Get( p_vout, "hue", &val ); f_hue = (float) ( val.i_int * M_PI / 180 ); var_Get( p_vout, "saturation", &val ); @@ -275,22 +289,45 @@ var_Get( p_vout, "gamma", &val ); f_gamma = 1.0 / val.f_float; - /* Contrast is a fast but kludged function, so I put this gap to be - * cleaner :) */ - i_lum += 128 - i_cont / 2; + /* + * Threshold mode drops out everything about contrast and gamma. + * Also luma behaviour is slightly modified. + */ + if( b_thres != VLC_TRUE ) { - /* Fill the gamma lookup table */ - for( i = 0 ; i < 256 ; i++ ) - { - pi_gamma[ i ] = clip( pow(i / 255.0, f_gamma) * 255.0); - } + /* Contrast is a fast but kludged function, so I put this gap to be + * cleaner :) */ + i_lum += 128 - i_cont / 2; - /* Fill the luma lookup table */ - for( i = 0 ; i < 256 ; i++ ) - { - pi_luma[ i ] = pi_gamma[clip( i_lum + i_cont * i / 256)]; - } + /* Fill the gamma lookup table */ + for( i = 0 ; i < 256 ; i++ ) + { + pi_gamma[ i ] = clip( 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)]; + } + } + else + { + /* + * We get luma as threshold value: the higher it is, the darker is + * the image. Should I reverse this? + */ + for( i = 0 ; i < 256 ; i++ ) + { + pi_luma[ i ] = (i < i_lum) ? 0 : 255; + } + + /* + * Desaturates image to avoid that strange yellow halo... + */ + i_sat = 0; + } + /* * Do the Y plane */