MCPcopy Create free account
hub / github.com/Panzerschrek/Chasm-Reverse / UpdateBrightness

Method UpdateBrightness

PanzerChasm/system_window.cpp:751–777  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

749}
750
751void SystemWindow::UpdateBrightness()
752{
753 float new_brightness= settings_.GetFloat( SettingsKeys::brightness, 0.5f );
754 if( new_brightness < 0.0f ) new_brightness= 0.0f;
755 if( new_brightness > 1.0f ) new_brightness= 1.0f;
756 settings_.SetSetting( SettingsKeys::brightness, new_brightness );
757
758 if( previous_brightness_ <= 0.0f || previous_brightness_ != new_brightness )
759 {
760 previous_brightness_= new_brightness;
761
762 Uint16 gamma_ramp[256];
763
764 const float c_min_gamma= 0.4f;
765 const float c_max_gamma= 1.5f;
766 const float gamma= c_max_gamma - new_brightness * ( c_max_gamma - c_min_gamma );
767 for( unsigned int i= 0u; i < 256u; i++ )
768 {
769 float p= std::pow( ( float(i) + 0.5f ) / 255.5f, gamma ) * 65535.0f;
770 int p_i= int(std::round(p));
771 if( p_i < 0 ) p_i= 0;
772 if( p_i > 65535 ) p_i= 65535;
773 gamma_ramp[i]= p_i;
774 }
775 SDL_SetWindowGammaRamp( window_, gamma_ramp, gamma_ramp, gamma_ramp );
776 }
777}
778
779} // namespace PanzerChasm

Callers

nothing calls this directly

Calls 2

GetFloatMethod · 0.80
SetSettingMethod · 0.80

Tested by

no test coverage detected