Permalink
Browse files

VideoPlayer: add video settings for tone mapping

  • Loading branch information...
FernetMenta committed Jun 2, 2018
1 parent c2cee42 commit d692e5dda672500d3202bcefe408f635a0691046
@@ -19806,7 +19806,31 @@ msgctxt "#36552"
msgid "Defines the number of presentation buffers used by the graphics driver. Select 2 if the driver uses double buffering or 3 for triple buffering."
msgstr ""

#empty strings from id 36553 to 36559
#. label of a setting, allowing to specify tonemap method
#: xbmc/video/dialogs/GUIDialogVideoSettings.cpp
msgctxt "#36553"
msgid "Tone mapping"
msgstr ""

#. label of a setting, tone mapping method
#: xbmc/video/dialogs/GUIDialogVideoSettings.cpp
msgctxt "#36554"
msgid "off"
msgstr ""

#. label of a setting, tone mapping method
#: xbmc/video/dialogs/GUIDialogVideoSettings.cpp
msgctxt "#36555"
msgid "Reinhard"
msgstr ""

#. label of a setting, allowing to specify tone mapping parameter
#: xbmc/video/dialogs/GUIDialogVideoSettings.cpp
msgctxt "#36556"
msgid "Tone mapping parameter"
msgstr ""

#empty strings from id 36557 to 36559

#: system/settings/settings.xml
msgctxt "#36560"
@@ -89,7 +89,8 @@ enum ERENDERFEATURE
RENDERFEATURE_ZOOM,
RENDERFEATURE_VERTICAL_SHIFT,
RENDERFEATURE_PIXEL_RATIO,
RENDERFEATURE_POSTPROCESS
RENDERFEATURE_POSTPROCESS,
RENDERFEATURE_TONEMAP
};

class IPlayer
@@ -1060,8 +1060,12 @@ void CLinuxRendererGL::RenderSinglePass(int index, int field)
}

bool toneMap = false;
if (buf.hasLightMetadata || (buf.hasDisplayMetadata && buf.displayMetadata.has_luminance))
toneMap = true;
if (m_videoSettings.m_ToneMapMethod != VS_TONEMAPMETHOD_OFF)
{
if (buf.hasLightMetadata || (buf.hasDisplayMetadata && buf.displayMetadata.has_luminance))
toneMap = true;
}

if (toneMap != m_toneMap)
m_reloadShaders = true;
m_toneMap = toneMap;
@@ -1095,6 +1099,7 @@ void CLinuxRendererGL::RenderSinglePass(int index, int field)
m_pYUVShader->SetColParams(buf.m_srcColSpace, buf.m_srcBits, !buf.m_srcFullRange, buf.m_srcTextureBits);
m_pYUVShader->SetDisplayMetadata(buf.hasDisplayMetadata, buf.displayMetadata,
buf.hasLightMetadata, buf.lightMetadata);
m_pYUVShader->SetToneMapParam(m_videoSettings.m_ToneMapParam);

//disable non-linear stretch when a dvd menu is shown, parts of the menu are rendered through the overlay renderer
//having non-linear stretch on breaks the alignment
@@ -1221,8 +1226,12 @@ void CLinuxRendererGL::RenderToFBO(int index, int field, bool weave /*= false*/)
}

bool toneMap = false;
if (buf.hasLightMetadata || (buf.hasDisplayMetadata && buf.displayMetadata.has_luminance))
toneMap = true;
if (m_videoSettings.m_ToneMapMethod != VS_TONEMAPMETHOD_OFF)
{
if (buf.hasLightMetadata || (buf.hasDisplayMetadata && buf.displayMetadata.has_luminance))
toneMap = true;
}

if (toneMap != m_toneMap)
m_reloadShaders = true;
m_toneMap = toneMap;
@@ -1284,6 +1293,9 @@ void CLinuxRendererGL::RenderToFBO(int index, int field, bool weave /*= false*/)
m_pYUVShader->SetHeight(planes[0].texheight);
m_pYUVShader->SetNonLinStretch(1.0);
m_pYUVShader->SetColParams(buf.m_srcColSpace, buf.m_srcBits, !buf.m_srcFullRange, buf.m_srcTextureBits);
m_pYUVShader->SetDisplayMetadata(buf.hasDisplayMetadata, buf.displayMetadata,
buf.hasLightMetadata, buf.lightMetadata);
m_pYUVShader->SetToneMapParam(m_videoSettings.m_ToneMapParam);

if (field == FIELD_TOP)
m_pYUVShader->SetField(1);
@@ -2555,7 +2567,8 @@ bool CLinuxRendererGL::Supports(ERENDERFEATURE feature)
feature == RENDERFEATURE_POSTPROCESS ||
feature == RENDERFEATURE_ROTATION ||
feature == RENDERFEATURE_BRIGHTNESS ||
feature == RENDERFEATURE_CONTRAST)
feature == RENDERFEATURE_CONTRAST ||
feature == RENDERFEATURE_TONEMAP)
return true;

return false;
@@ -176,6 +176,8 @@ bool BaseYUV2RGBGLSLShader::OnEnabled()
else if (m_hasDisplayMetadata && m_displayMetadata.has_luminance)
param = log10(100) / log10(m_displayMetadata.max_luminance.num/m_displayMetadata.max_luminance.den);

param *= m_toneMappingParam;

float coefs[3];
CConvertMatrix::GetRGBYuvCoefs(AVColorSpace::AVCOL_SPC_BT709, coefs);
glUniform3f(m_hCoefsDst, coefs[0], coefs[1], coefs[2]);
@@ -55,6 +55,7 @@ class BaseYUV2RGBGLSLShader : public CGLSLShaderProgram
void SetNonLinStretch(float stretch) { m_stretch = stretch; }
void SetDisplayMetadata(bool hasDisplayMetadata, AVMasteringDisplayMetadata displayMetadata,
bool hasLightMetadata, AVContentLightMetadata lightMetadata);
void SetToneMapParam(float param) { m_toneMappingParam = param; }

void SetConvertFullColorRange(bool convertFullRange) { m_convertFullRange = convertFullRange; }

@@ -83,6 +84,7 @@ class BaseYUV2RGBGLSLShader : public CGLSLShaderProgram
bool m_hasLightMetadata = false;
AVContentLightMetadata m_lightMetadata;
bool m_toneMapping = false;
float m_toneMappingParam = 1.0;

float m_black;
float m_contrast;
@@ -74,6 +74,8 @@ bool CVideoSettings::operator!=(const CVideoSettings &right) const
if (m_StereoMode != right.m_StereoMode) return true;
if (m_StereoInvert != right.m_StereoInvert) return true;
if (m_VideoStream != right.m_VideoStream) return true;
if (m_ToneMapMethod != right.m_ToneMapMethod) return true;
if (m_ToneMapParam != right.m_ToneMapParam) return true;
return false;
}

@@ -69,6 +69,13 @@ enum ESCALINGMETHOD
VS_SCALINGMETHOD_MAX // do not use and keep as last enum value.
};

enum ETONEMAPMETHOD
{
VS_TONEMAPMETHOD_OFF=0,
VS_TONEMAPMETHOD_REINHARD,
VS_TONEMAPMETHOD_MAX
};

enum ViewMode
{
ViewModeNormal = 0,
@@ -115,6 +122,8 @@ class CVideoSettings
int m_StereoMode;
bool m_StereoInvert;
int m_VideoStream;
int m_ToneMapMethod = VS_TONEMAPMETHOD_REINHARD;
float m_ToneMapParam = 1.0;
};

class CCriticalSection;
@@ -125,6 +125,8 @@ bool CMediaSettings::Load(const TiXmlNode *settings)
if (!XMLUtils::GetInt(pElement, "stereomode", m_defaultVideoSettings.m_StereoMode))
m_defaultVideoSettings.m_StereoMode = 0;

m_defaultVideoSettings.m_ToneMapMethod = 1;
m_defaultVideoSettings.m_ToneMapParam = 1.0f;
m_defaultVideoSettings.m_SubtitleCached = false;
}

@@ -102,7 +102,8 @@ void CVideoDatabase::CreateTables()
"SubtitleDelay float, SubtitlesOn bool, Brightness float, Contrast float, Gamma float,"
"VolumeAmplification float, AudioDelay float, ResumeTime integer,"
"Sharpness float, NoiseReduction float, NonLinStretch bool, PostProcess bool,"
"ScalingMethod integer, DeinterlaceMode integer, StereoMode integer, StereoInvert bool, VideoStream integer)\n");
"ScalingMethod integer, DeinterlaceMode integer, StereoMode integer, StereoInvert bool, VideoStream integer,"
"TonemapMethod integer, TonemapParam float)\n");

CLog::Log(LOGINFO, "create stacktimes table");
m_pDS->exec("CREATE TABLE stacktimes (idFile integer, times text)\n");
@@ -4287,7 +4288,15 @@ bool CVideoDatabase::GetVideoSettings(int idFile, CVideoSettings &settings)
settings.m_StereoInvert = m_pDS->fv("StereoInvert").get_asBool();
settings.m_SubtitleCached = false;
settings.m_VideoStream = m_pDS->fv("VideoStream").get_asInt();
settings.m_ToneMapMethod = m_pDS->fv("TonemapMethod").get_asInt();
settings.m_ToneMapParam = m_pDS->fv("TonemapParam").get_asFloat();
m_pDS->close();

if (settings.m_ToneMapParam == 0.0)
{
settings.m_ToneMapMethod = VS_TONEMAPMETHOD_REINHARD;
settings.m_ToneMapParam = 1.0;
}
return true;
}
m_pDS->close();
@@ -4329,8 +4338,10 @@ void CVideoDatabase::SetVideoSettings(int idFile, const CVideoSettings &setting)
setting.m_Brightness, setting.m_Contrast, setting.m_Gamma, setting.m_VolumeAmplification, setting.m_AudioDelay,
setting.m_Sharpness,setting.m_NoiseReduction,setting.m_CustomNonLinStretch,setting.m_PostProcess,setting.m_ScalingMethod);
std::string strSQL2;
strSQL2=PrepareSQL("ResumeTime=%i,StereoMode=%i,StereoInvert=%i, VideoStream=%i where idFile=%i\n", setting.m_ResumeTime, setting.m_StereoMode,
setting.m_StereoInvert, setting.m_VideoStream, idFile);

strSQL2=PrepareSQL("ResumeTime=%i,StereoMode=%i,StereoInvert=%i,VideoStream=%i,TonemapMethod=%i,TonemapParam=%f where idFile=%i\n",
setting.m_ResumeTime, setting.m_StereoMode, setting.m_StereoInvert, setting.m_VideoStream,
setting.m_ToneMapMethod, setting.m_ToneMapParam, idFile);
strSQL += strSQL2;
m_pDS->exec(strSQL);
return ;
@@ -4342,15 +4353,15 @@ void CVideoDatabase::SetVideoSettings(int idFile, const CVideoSettings &setting)
"AudioStream,SubtitleStream,SubtitleDelay,SubtitlesOn,Brightness,"
"Contrast,Gamma,VolumeAmplification,AudioDelay,"
"ResumeTime,"
"Sharpness,NoiseReduction,NonLinStretch,PostProcess,ScalingMethod,StereoMode,StereoInvert,VideoStream) "
"Sharpness,NoiseReduction,NonLinStretch,PostProcess,ScalingMethod,StereoMode,StereoInvert,VideoStream,TonemapMethod,TonemapParam) "
"VALUES ";
strSQL += PrepareSQL("(%i,%i,%i,%f,%f,%f,%i,%i,%f,%i,%f,%f,%f,%f,%f,%i,%f,%f,%i,%i,%i,%i,%i,%i)",
strSQL += PrepareSQL("(%i,%i,%i,%f,%f,%f,%i,%i,%f,%i,%f,%f,%f,%f,%f,%i,%f,%f,%i,%i,%i,%i,%i,%i,%i,%f)",
idFile, setting.m_InterlaceMethod, setting.m_ViewMode, setting.m_CustomZoomAmount, setting.m_CustomPixelRatio, setting.m_CustomVerticalShift,
setting.m_AudioStream, setting.m_SubtitleStream, setting.m_SubtitleDelay, setting.m_SubtitleOn, setting.m_Brightness,
setting.m_Contrast, setting.m_Gamma, setting.m_VolumeAmplification, setting.m_AudioDelay,
setting.m_ResumeTime,
setting.m_Sharpness, setting.m_NoiseReduction, setting.m_CustomNonLinStretch, setting.m_PostProcess, setting.m_ScalingMethod,
setting.m_StereoMode, setting.m_StereoInvert, setting.m_VideoStream);
setting.m_StereoMode, setting.m_StereoInvert, setting.m_VideoStream, setting.m_ToneMapMethod, setting.m_ToneMapParam);
m_pDS->exec(strSQL);
}
}
@@ -5286,11 +5297,17 @@ void CVideoDatabase::UpdateTables(int iVersion)
m_pDS->exec("DROP TABLE settings");
m_pDS->exec("ALTER TABLE settingsnew RENAME TO settings");
}

if (iVersion < 110)
{
m_pDS->exec("ALTER TABLE settings ADD TonemapMethod integer");
m_pDS->exec("ALTER TABLE settings ADD TonemapParam float");
}
}

int CVideoDatabase::GetSchemaVersion() const
{
return 109;
return 110;
}

bool CVideoDatabase::LookupByFolders(const std::string &path, bool shows)
@@ -51,6 +51,8 @@
#define SETTING_VIDEO_NONLIN_STRETCH "video.nonlinearstretch"
#define SETTING_VIDEO_POSTPROCESS "video.postprocess"
#define SETTING_VIDEO_VERTICAL_SHIFT "video.verticalshift"
#define SETTING_VIDEO_TONEMAP_METHOD "video.tonemapmethod"
#define SETTING_VIDEO_TONEMAP_PARAM "video.tonemapparam"

#define SETTING_VIDEO_VDPAU_NOISE "vdpau.noise"
#define SETTING_VIDEO_VDPAU_SHARPNESS "vdpau.sharpness"
@@ -177,6 +179,18 @@ void CGUIDialogVideoSettings::OnSettingChanged(std::shared_ptr<const CSetting> s
vs.m_Sharpness = static_cast<float>(std::static_pointer_cast<const CSettingNumber>(setting)->GetValue());
g_application.GetAppPlayer().SetVideoSettings(vs);
}
else if (settingId == SETTING_VIDEO_TONEMAP_METHOD)
{
CVideoSettings vs = g_application.GetAppPlayer().GetVideoSettings();
vs.m_ToneMapMethod = static_cast<int>(std::static_pointer_cast<const CSettingInt>(setting)->GetValue());
g_application.GetAppPlayer().SetVideoSettings(vs);
}
else if (settingId == SETTING_VIDEO_TONEMAP_PARAM)
{
CVideoSettings vs = g_application.GetAppPlayer().GetVideoSettings();
vs.m_ToneMapParam = static_cast<float>(std::static_pointer_cast<const CSettingNumber>(setting)->GetValue());
g_application.GetAppPlayer().SetVideoSettings(vs);
}
else if (settingId == SETTING_VIDEO_STEREOSCOPICMODE)
{
CVideoSettings vs = g_application.GetAppPlayer().GetVideoSettings();
@@ -387,6 +401,16 @@ void CGUIDialogVideoSettings::InitializeSettings()
if (g_application.GetAppPlayer().Supports(RENDERFEATURE_NONLINSTRETCH))
AddToggle(groupVideo, SETTING_VIDEO_NONLIN_STRETCH, 659, SettingLevel::Basic, videoSettings.m_CustomNonLinStretch);

// tone mapping
if (g_application.GetAppPlayer().Supports(RENDERFEATURE_TONEMAP))
{
entries.clear();
entries.push_back(std::make_pair(36554, VS_TONEMAPMETHOD_OFF));
entries.push_back(std::make_pair(36555, VS_TONEMAPMETHOD_REINHARD));
AddSpinner(groupVideo, SETTING_VIDEO_TONEMAP_METHOD, 36553, SettingLevel::Basic, videoSettings.m_ToneMapMethod, entries);
AddSlider(groupVideo, SETTING_VIDEO_TONEMAP_PARAM, 36556, SettingLevel::Basic, videoSettings.m_ToneMapParam, "%2.2f", 0.1f, 0.1f, 5.0f, 36556, usePopup);
}

// stereoscopic settings
entries.clear();
entries.push_back(std::make_pair(16316, RENDER_STEREO_MODE_OFF));

0 comments on commit d692e5d

Please sign in to comment.