Skip to content

Commit

Permalink
VideoColourSpace: Add alpha to the colourspace matrix
Browse files Browse the repository at this point in the history
- this initially just ensures we have a valid alpha value in each stage
of video processing and can thus just enable blending by default in
MythRenderOpengl
- but could be used for effects in the future
- needs more work as it is currently only applied to the YUV to RGB
stage - so will not apply where no colourspace conversion is in effect
(OpenGL RGBA output, hardware decoded frames)
- furthermore, we do not currently clear intermediate framebuffers so
applying an alpha of less than one introduces some interested temporal
blurring of anything that passes through more than one filter stage.
  • Loading branch information
mark-kendall committed Jan 25, 2019
1 parent 55ad2e3 commit c48979b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
20 changes: 13 additions & 7 deletions mythtv/libs/libmythtv/videocolourspace.cpp
Expand Up @@ -14,6 +14,7 @@ VideoColourSpace::VideoColourSpace(VideoCStd colour_std)
m_contrast(1.0f),
m_saturation(1.0f),
m_hue(0.0f),
m_alpha(1.0f),
m_colourSpace(colour_std)
{
m_db_settings[kPictureAttribute_Brightness] =
Expand Down Expand Up @@ -49,8 +50,7 @@ PictureAttributeSupported VideoColourSpace::SupportedAttributes(void) const
void VideoColourSpace::SetSupportedAttributes(PictureAttributeSupported supported)
{
m_supported_attributes = supported;
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("PictureAttributes: %1")
.arg(toString(m_supported_attributes)));
LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("PictureAttributes: %1").arg(toString(m_supported_attributes)));
}

int VideoColourSpace::GetPictureAttribute(PictureAttribute attribute)
Expand Down Expand Up @@ -116,15 +116,15 @@ void VideoColourSpace::Update(void)
1.000f, ( 1.5756f * uvsin), ( 1.5756f * uvcos) , 0.000f,
1.000f, (-0.2253f * uvcos) + ( 0.5000f * uvsin), ( 0.5000f * uvcos) - (-0.2253f * uvsin), 0.000f,
1.000f, ( 1.8270f * uvcos) , - ( 1.8270f * uvsin), 0.000f,
0.000f, 0.000f, 0.000f, 1.000f);
0.000f, 0.000f, 0.000f, m_alpha);
break;

case kCSTD_ITUR_BT_709:
csc = QMatrix4x4(
1.000f, ( 1.5701f * uvsin), ( 1.5701f * uvcos) , 0.000f,
1.000f, (-0.1870f * uvcos) + (-0.4664f * uvsin), (-0.4664f * uvcos) - (-0.1870f * uvsin), 0.000f,
1.000f, ( 1.8556f * uvcos) , - ( 1.8556f * uvsin), 0.000f,
0.000f, 0.000f, 0.000f, 1.000f);
0.000f, 0.000f, 0.000f, m_alpha);
break;

case kCSTD_ITUR_BT_601:
Expand All @@ -133,7 +133,7 @@ void VideoColourSpace::Update(void)
1.000f, ( 1.4030f * uvsin), ( 1.4030f * uvcos) , 0.000f,
1.000f, (-0.3440f * uvcos) + (-0.7140f * uvsin), (-0.7140f * uvcos) - (-0.3440f * uvsin), 0.000f,
1.000f, ( 1.7730f * uvcos) , - ( 1.7730f * uvsin), 0.000f,
0.000f, 0.000f, 0.000f, 1.000f);
0.000f, 0.000f, 0.000f, m_alpha);
}

setToIdentity();
Expand All @@ -150,12 +150,12 @@ void VideoColourSpace::Update(void)
void VideoColourSpace::Debug(void)
{
LOG(VB_PLAYBACK, LOG_DEBUG, LOC +
QString("Brightness: %1 Contrast: %2 Saturation: %3 Hue: %4 "
"StudioLevels: %5")
QString("Brightness: %1 Contrast: %2 Saturation: %3 Hue: %4 Alpha: %5 StudioLevels: %6")
.arg(m_brightness, 2, 'f', 4, QLatin1Char('0'))
.arg(m_contrast , 2, 'f', 4, QLatin1Char('0'))
.arg(m_saturation, 2, 'f', 4, QLatin1Char('0'))
.arg(m_hue , 2, 'f', 4, QLatin1Char('0'))
.arg(m_alpha , 2, 'f', 4, QLatin1Char('0'))
.arg(m_studioLevels));

if (VERBOSE_LEVEL_CHECK(VB_PLAYBACK, LOG_DEBUG))
Expand Down Expand Up @@ -203,6 +203,12 @@ void VideoColourSpace::SetSaturation(int value)
Update();
}

void VideoColourSpace::SetAlpha(int value)
{
m_alpha = 100.0f / value;
Update();
}

void VideoColourSpace::SaveValue(PictureAttribute attributeType, int value)
{
QString dbName;
Expand Down
2 changes: 2 additions & 0 deletions mythtv/libs/libmythtv/videocolourspace.h
Expand Up @@ -25,6 +25,7 @@ class VideoColourSpace : public QMatrix4x4
int GetPictureAttribute(PictureAttribute attribute);
int SetPictureAttribute(PictureAttribute attribute, int value);
void SetColourSpace(VideoCStd csp = kCSTD_Unknown);
void SetAlpha(int value);

private:
void SetStudioLevels(bool studio);
Expand All @@ -47,6 +48,7 @@ class VideoColourSpace : public QMatrix4x4
float m_contrast;
float m_saturation;
float m_hue;
float m_alpha;
VideoCStd m_colourSpace;
};

Expand Down
5 changes: 1 addition & 4 deletions mythtv/libs/libmythui/mythrender_opengl.cpp
Expand Up @@ -970,7 +970,6 @@ void MythRenderOpenGL::DrawBitmapPriv(MythGLTexture *Texture, const QRect &Sourc

SetShaderProgramParams(Program, m_projection, "u_projection");
SetShaderProgramParams(Program, m_transforms.top(), "u_transform");
SetBlend(true);

EnableTextures();
Program->setUniformValue("s_texture0", 0);
Expand Down Expand Up @@ -1028,7 +1027,6 @@ void MythRenderOpenGL::DrawBitmapPriv(MythGLTexture **Textures, uint TextureCoun

SetShaderProgramParams(Program, m_projection, "u_projection");
SetShaderProgramParams(Program, m_transforms.top(), "u_transform");
SetBlend(false);

EnableTextures();
uint active_tex = 0;
Expand Down Expand Up @@ -1106,7 +1104,6 @@ void MythRenderOpenGL::DrawRoundRectPriv(const QRect &area, int cornerRadius,
QRect bl(r.left(), r.top() + r.height() - rad, rad, rad);
QRect br(r.left() + r.width() - rad, r.top() + r.height() - rad, rad, rad);

SetBlend(true);
DisableTextures();

glEnableVertexAttribArray(VERTEX_INDEX);
Expand Down Expand Up @@ -1320,7 +1317,7 @@ void MythRenderOpenGL::DrawRoundRectPriv(const QRect &area, int cornerRadius,

void MythRenderOpenGL::Init2DState(void)
{
SetBlend(false);
SetBlend(true);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
Expand Down

0 comments on commit c48979b

Please sign in to comment.