Skip to content

Commit

Permalink
Merge pull request xbmc#26052 from thexai/tonemap-GL-GLES
Browse files Browse the repository at this point in the history
LinuxRendererGL/GLES: improve conditions to enable HDR to SDR tone mapping
  • Loading branch information
thexai authored Dec 9, 2024
2 parents 6b0234c + f0497da commit 4dfebcf
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 57 deletions.
19 changes: 10 additions & 9 deletions xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ void CLinuxRendererGL::AddVideoPicture(const VideoPicture &picture, int index)
buf.loaded = false;
buf.m_srcPrimaries = picture.color_primaries;
buf.m_srcColSpace = picture.color_space;
buf.m_srcColTransfer = picture.color_transfer;
buf.m_srcFullRange = picture.color_range == 1;
buf.m_srcBits = picture.colorBits;

Expand Down Expand Up @@ -2776,7 +2777,7 @@ void CLinuxRendererGL::DeleteCLUT()
void CLinuxRendererGL::CheckVideoParameters(int index)
{
const CPictureBuffer& buf = m_buffers[index];
ETONEMAPMETHOD method = m_videoSettings.m_ToneMapMethod;
const ETONEMAPMETHOD& toneMapMethod = m_videoSettings.m_ToneMapMethod;

if (buf.m_srcPrimaries != m_srcPrimaries)
{
Expand All @@ -2785,20 +2786,20 @@ void CLinuxRendererGL::CheckVideoParameters(int index)
}

bool toneMap = false;
if (method != VS_TONEMAPMETHOD_OFF)
const bool streamIsHDRPQ =
(buf.m_srcColTransfer == AVCOL_TRC_SMPTE2084 && buf.m_srcPrimaries == AVCOL_PRI_BT2020);

if (streamIsHDRPQ && toneMapMethod != VS_TONEMAPMETHOD_OFF)
{
if (buf.hasLightMetadata || (buf.hasDisplayMetadata && buf.displayMetadata.has_luminance))
{
toneMap = true;
}
toneMap = true;
}

if (toneMap != m_toneMap || (m_toneMapMethod != method))
if (toneMap != m_toneMap || toneMapMethod != m_toneMapMethod)
{
m_reloadShaders = true;
m_toneMap = toneMap;
m_toneMapMethod = toneMapMethod;
}
m_toneMap = toneMap;
m_toneMapMethod = method;
}

CRenderCapture* CLinuxRendererGL::GetRenderCapture()
Expand Down
2 changes: 2 additions & 0 deletions xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ class CLinuxRendererGL : public CBaseRenderer

AVColorPrimaries m_srcPrimaries;
AVColorSpace m_srcColSpace;
AVColorTransferCharacteristic m_srcColTransfer;

int m_srcBits = 8;
int m_srcTextureBits = 8;
bool m_srcFullRange;
Expand Down
79 changes: 31 additions & 48 deletions xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void CLinuxRendererGLES::AddVideoPicture(const VideoPicture &picture, int index)
buf.loaded = false;
buf.m_srcPrimaries = picture.color_primaries;
buf.m_srcColSpace = picture.color_space;
buf.m_srcColTransfer = picture.color_transfer;
buf.m_srcFullRange = picture.color_range == 1;
buf.m_srcBits = picture.colorBits;

Expand Down Expand Up @@ -920,30 +921,7 @@ void CLinuxRendererGLES::RenderSinglePass(int index, int field)
CPictureBuffer &buf = m_buffers[index];
CYuvPlane (&planes)[YuvImage::MAX_PLANES] = m_buffers[index].fields[field];

if (buf.m_srcPrimaries != m_srcPrimaries)
{
m_srcPrimaries = buf.m_srcPrimaries;
m_reloadShaders = true;
}

bool toneMap = false;
ETONEMAPMETHOD toneMapMethod = m_videoSettings.m_ToneMapMethod;

if (!m_passthroughHDR && toneMapMethod != VS_TONEMAPMETHOD_OFF)
{
if (buf.hasLightMetadata || (buf.hasDisplayMetadata && buf.displayMetadata.has_luminance))
{
toneMap = true;
}
}

if (toneMap != m_toneMap || toneMapMethod != m_toneMapMethod)
{
m_reloadShaders = true;
}

m_toneMap = toneMap;
m_toneMapMethod = toneMapMethod;
CheckVideoParameters(index);

if (m_reloadShaders)
{
Expand Down Expand Up @@ -1052,30 +1030,7 @@ void CLinuxRendererGLES::RenderToFBO(int index, int field)
CPictureBuffer &buf = m_buffers[index];
CYuvPlane (&planes)[YuvImage::MAX_PLANES] = m_buffers[index].fields[field];

if (buf.m_srcPrimaries != m_srcPrimaries)
{
m_srcPrimaries = buf.m_srcPrimaries;
m_reloadShaders = true;
}

bool toneMap = false;
ETONEMAPMETHOD toneMapMethod = m_videoSettings.m_ToneMapMethod;

if (toneMapMethod != VS_TONEMAPMETHOD_OFF)
{
if (buf.hasLightMetadata || (buf.hasDisplayMetadata && buf.displayMetadata.has_luminance))
{
toneMap = true;
}
}

if (toneMap != m_toneMap || m_toneMapMethod != toneMapMethod)
{
m_reloadShaders = true;
}

m_toneMap = toneMap;
m_toneMapMethod = toneMapMethod;
CheckVideoParameters(index);

if (m_reloadShaders)
{
Expand Down Expand Up @@ -1850,3 +1805,31 @@ CRenderCapture* CLinuxRendererGLES::GetRenderCapture()
{
return new CRenderCaptureGLES;
}

void CLinuxRendererGLES::CheckVideoParameters(int index)
{
const CPictureBuffer& buf = m_buffers[index];
const ETONEMAPMETHOD& toneMapMethod = m_videoSettings.m_ToneMapMethod;

if (buf.m_srcPrimaries != m_srcPrimaries)
{
m_srcPrimaries = buf.m_srcPrimaries;
m_reloadShaders = true;
}

bool toneMap = false;
const bool streamIsHDRPQ =
(buf.m_srcColTransfer == AVCOL_TRC_SMPTE2084 && buf.m_srcPrimaries == AVCOL_PRI_BT2020);

if (streamIsHDRPQ && !m_passthroughHDR && toneMapMethod != VS_TONEMAPMETHOD_OFF)
{
toneMap = true;
}

if (toneMap != m_toneMap || toneMapMethod != m_toneMapMethod)
{
m_reloadShaders = true;
m_toneMap = toneMap;
m_toneMapMethod = toneMapMethod;
}
}
3 changes: 3 additions & 0 deletions xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class CLinuxRendererGLES : public CBaseRenderer
virtual void ReleaseShaders();
void SetTextureFilter(GLenum method);
void UpdateVideoFilter();
void CheckVideoParameters(int index);
AVColorPrimaries GetSrcPrimaries(AVColorPrimaries srcPrimaries, unsigned int width, unsigned int height);

// textures
Expand Down Expand Up @@ -176,6 +177,8 @@ class CLinuxRendererGLES : public CBaseRenderer

AVColorPrimaries m_srcPrimaries;
AVColorSpace m_srcColSpace;
AVColorTransferCharacteristic m_srcColTransfer;

int m_srcBits{8};
int m_srcTextureBits{8};
bool m_srcFullRange;
Expand Down

0 comments on commit 4dfebcf

Please sign in to comment.