[vlc-devel] Re: [PATCH] Gamma correction support for adjust video filter
Sigmund Augdal
sigmunau at stud.ntnu.no
Thu Jan 22 16:00:55 CET 2004
This patch seems good to me. Applied to cvs.
Sigmund
On Sat, Jan 10, 2004 at 05:55:04PM +0100, Arwed von Merkatz wrote:
> Hi,
>
> due to a very old monitor I need gamma correction for video output if I
> want to be able to see anything. vlc was lacking support for this so I
> added it to the adjust video filter. I also added it to the Extended Gui
> "Image adjust" part of the wxGTK interface, though i'm not sure if it
> needs to be there, that was mainly for testing purposes, normally you
> only need to set gamma once as the monitor gamma doesn't change that
> fast.
>
> --
> Arwed v. Merkatz
> Grimoire Guru for video
> Grimoire Guru for xfce
> Sourcemage GNU/Linux
> http://www.sourcemage.org
> ? modules/codec/faad/Makefile.am
> ? modules/codec/faad/Makefile.in
> Index: modules/gui/wxwindows/interface.cpp
> ===================================================================
> RCS file: /var/cvs/videolan/vlc/modules/gui/wxwindows/interface.cpp,v
> retrieving revision 1.83
> diff -u -r1.83 interface.cpp
> --- modules/gui/wxwindows/interface.cpp 5 Jan 2004 13:00:39 -0000 1.83
> +++ modules/gui/wxwindows/interface.cpp 10 Jan 2004 16:48:49 -0000
> @@ -145,6 +145,7 @@
> Contrast_Event,
> Brightness_Event,
> Saturation_Event,
> + Gamma_Event,
>
> Ratio_Event,
> Visual_Event,
> @@ -200,6 +201,7 @@
> EVT_COMMAND_SCROLL(Contrast_Event, Interface::OnContrastUpdate)
> EVT_COMMAND_SCROLL(Brightness_Event, Interface::OnBrightnessUpdate)
> EVT_COMMAND_SCROLL(Saturation_Event, Interface::OnSaturationUpdate)
> + EVT_COMMAND_SCROLL(Gamma_Event, Interface::OnGammaUpdate)
>
> END_EVENT_TABLE()
>
> @@ -546,11 +548,21 @@
> saturation_sizer->Add(saturation_slider,1,0,0);
> saturation_sizer->Layout();
>
> + wxBoxSizer *gamma_sizer = new wxBoxSizer( wxHORIZONTAL );
> + wxStaticText *gamma_text = new wxStaticText( extra_frame, -1,
> + wxU(_("Gamma")) );
> + gamma_slider = new wxSlider ( extra_frame, Gamma_Event, 0, 0,
> + 100, wxDefaultPosition, wxDefaultSize );
> + gamma_sizer->Add(gamma_text,1,0,0);
> + gamma_sizer->Add(gamma_slider,1,0,0);
> + gamma_sizer->Layout();
> +
> adjust_sizer->Add(adjust_check, 1, wxEXPAND, 0);
> adjust_sizer->Add(hue_sizer, 1, wxEXPAND, 0);
> adjust_sizer->Add(contrast_sizer, 1, wxEXPAND, 0);
> adjust_sizer->Add(brightness_sizer, 1, wxEXPAND, 0);
> adjust_sizer->Add(saturation_sizer, 1, wxEXPAND, 0);
> + adjust_sizer->Add(gamma_sizer, 1, wxEXPAND, 0);
>
> extra_sizer->Add(adjust_sizer,1,wxBOTTOM,5);
>
> @@ -637,6 +649,7 @@
> contrast_slider->Enable();
> brightness_slider->Enable();
> hue_slider->Enable();
> + gamma_slider->Enable();
> }
> else
> {
> @@ -645,6 +658,7 @@
> contrast_slider->Disable();
> brightness_slider->Disable();
> hue_slider->Disable();
> + gamma_slider->Disable();
> }
> if( psz_filters ) free( psz_filters );
>
> @@ -662,6 +676,9 @@
> f_value = config_GetFloat( p_intf, "brightness" );
> if( f_value > 0 && f_value < 2 )
> brightness_slider->SetValue( (int)(100 * f_value) );
> + f_value = config_GetFloat( p_intf, "gamma" );
> + if (f_value > 0 && f_value < 10 )
> + gamma_slider->SetValue( (int)(10 * f_value) );
>
> extra_frame->Hide();
> }
> @@ -983,6 +1000,7 @@
> saturation_slider->Enable();
> contrast_slider->Enable();
> hue_slider->Enable();
> + gamma_slider->Enable();
> }
> else
> {
> @@ -1025,6 +1043,7 @@
> saturation_slider->Disable();
> contrast_slider->Disable();
> hue_slider->Disable();
> + gamma_slider->Disable();
> }
> if(psz_filters) free(psz_filters);
> if(psz_new) free(psz_new);
> @@ -1051,6 +1070,11 @@
>
> }
>
> +void Interface::OnGammaUpdate(wxScrollEvent& event)
> +{
> + config_PutFloat( p_intf , "gamma" , (float)event.GetPosition()/10 );
> +}
> +
> void Interface::OnRatio( wxCommandEvent& event )
> {
> config_PutPsz( p_intf, "aspect-ratio", ratio_combo->GetValue().mb_str() );
> Index: modules/gui/wxwindows/wxwindows.h
> ===================================================================
> RCS file: /var/cvs/videolan/vlc/modules/gui/wxwindows/wxwindows.h,v
> retrieving revision 1.83
> diff -u -r1.83 wxwindows.h
> --- modules/gui/wxwindows/wxwindows.h 5 Jan 2004 13:00:39 -0000 1.83
> +++ modules/gui/wxwindows/wxwindows.h 10 Jan 2004 16:48:51 -0000
> @@ -178,6 +178,7 @@
> wxSlider *contrast_slider;
> wxSlider *saturation_slider;
> wxSlider *hue_slider;
> + wxSlider *gamma_slider;
>
> wxStaticBox *other_box;
> wxComboBox *ratio_combo;
> @@ -218,6 +219,7 @@
> void OnContrastUpdate( wxScrollEvent& event );
> void OnBrightnessUpdate( wxScrollEvent& event );
> void OnSaturationUpdate( wxScrollEvent& event );
> + void OnGammaUpdate( wxScrollEvent& event );
>
> void OnRatio( wxCommandEvent& event );
> void OnEnableVisual( wxCommandEvent& event );
> Index: modules/video_filter/adjust.c
> ===================================================================
> RCS file: /var/cvs/videolan/vlc/modules/video_filter/adjust.c,v
> retrieving revision 1.14
> diff -u -r1.14 adjust.c
> --- modules/video_filter/adjust.c 15 Oct 2003 22:49:48 -0000 1.14
> +++ modules/video_filter/adjust.c 10 Jan 2004 16:48:52 -0000
> @@ -65,6 +65,8 @@
> #define SAT_LONGTEXT N_("Set the image saturation, between 0 and 3. Defaults to 1")
> #define LUM_TEXT N_("Set image brightness")
> #define LUM_LONGTEXT N_("Set the image brightness, between 0 and 2. Defaults to 1")
> +#define GAMMA_TEXT N_("Set image gamma")
> +#define GAMMA_LONGTEXT N_("Set the image gamma, between 0.01 and 10. Defaults to 1")
>
>
> vlc_module_begin();
> @@ -73,7 +75,8 @@
> 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 );
> add_float_with_range( "saturation", 1.0, 0.0, 3.0, NULL, SAT_TEXT, SAT_LONGTEXT, VLC_FALSE );
> - set_description( _("contrast/hue/saturation/brightness filter") );
> + add_float_with_range( "gamma", 1.0, 0.01, 10.0, NULL, GAMMA_TEXT, GAMMA_LONGTEXT, VLC_FALSE );
> + set_description( _("contrast/hue/saturation/brightness/gamma filter") );
> set_capability( "video filter", 0 );
> add_shortcut( "adjust" );
> set_callbacks( Create, Destroy );
> @@ -204,12 +207,14 @@
> static void Render( vout_thread_t *p_vout, picture_t *p_pic )
> {
> int pi_luma[256];
> + int pi_gamma[256];
>
> picture_t *p_outpic;
> uint8_t *p_in, *p_in_v, *p_in_end, *p_line_end;
> uint8_t *p_out, *p_out_v;
>
> double f_hue;
> + double f_gamma;
> int32_t i_cont, i_lum;
> int i_sat, i_sin, i_cos, i_x, i_y;
> int i;
> @@ -233,15 +238,22 @@
> i_lum = (config_GetFloat( p_vout, "brightness" ) - 1.0) * 255;
> f_hue = config_GetInt( p_vout, "hue" ) * M_PI / 180;
> i_sat = config_GetFloat( p_vout, "saturation" ) * 256;
> + f_gamma = 1.0 / config_GetFloat( p_vout, "gamma" );
>
> /* Contrast is a fast but kludged function, so I put this gap to be
> * cleaner :) */
> i_lum += 128 - i_cont / 2;
>
> + /* 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 ] = clip( i_lum + i_cont * i / 256 );
> + pi_luma[ i ] = pi_gamma[clip( i_lum + i_cont * i / 256)];
> }
>
> /*
--
This is the vlc-devel mailing-list, see http://www.videolan.org/vlc/
To unsubscribe, please read http://developers.videolan.org/lists.html
If you are in trouble, please contact <postmaster at videolan.org>
More information about the vlc-devel
mailing list