Skip to content

Commit

Permalink
Add GLSL 'onefield' and 'bob' hardware deinterlacers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Kendall committed Dec 20, 2010
1 parent 56dab84 commit 8cb1707
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 19 deletions.
76 changes: 57 additions & 19 deletions mythtv/libs/libmythtv/openglvideo.cpp
Expand Up @@ -1527,8 +1527,18 @@ QString OpenGLVideo::GetProgramString(OpenGLFilterType name,
break;
}

QString temp = textureRects ? "RECT" : "2D";
ret.replace("%1", temp);
CustomiseProgramString(ret);
ret += "END";

VERBOSE(VB_PLAYBACK, LOC + QString("Created %1 fragment program %2")
.arg(FilterToString(name)).arg(deint));

return ret;
}

void OpenGLVideo::CustomiseProgramString(QString &string)
{
string.replace("%1", textureRects ? "RECT" : "2D");

float lineHeight = 1.0f;
float colWidth = 1.0f;
Expand All @@ -1543,25 +1553,16 @@ QString OpenGLVideo::GetProgramString(OpenGLFilterType name,

float fieldSize = 1.0f / (lineHeight * 2.0);

ret.replace("%2", temp.setNum(fieldSize, 'f', 8));
ret.replace("%3", temp.setNum(lineHeight, 'f', 8));
ret.replace("%4", temp.setNum(lineHeight * 2.0, 'f', 8));
ret.replace("%5", temp.setNum(colWidth, 'f', 8));
ret.replace("%6", temp.setNum((float)fb_size.width(), 'f', 1));
ret.replace("%7", temp.setNum((float)fb_size.height(), 'f', 1));

ret += "END";

VERBOSE(VB_PLAYBACK|VB_EXTRA, "\n" + ret + "\n");
VERBOSE(VB_PLAYBACK, LOC + QString("Created %1 fragment program %2")
.arg(FilterToString(name)).arg(deint));

return ret;
string.replace("%2", QString::number(fieldSize, 'f', 8));
string.replace("%3", QString::number(lineHeight, 'f', 8));
string.replace("%4", QString::number(lineHeight * 2.0, 'f', 8));
string.replace("%5", QString::number(colWidth, 'f', 8));
string.replace("%6", QString::number((float)fb_size.width(), 'f', 1));
string.replace("%7", QString::number((float)fb_size.height(), 'f', 1));
}

static const QString YUV2RGBVertexShader =
"GLSL_DEFINES"
"attribute vec4 a_color;\n"
"attribute vec2 a_texcoord0;\n"
"varying vec2 v_texcoord0;\n"
"void main() {\n"
Expand All @@ -1581,12 +1582,49 @@ static const QString YUV2RGBFragmentShader =
" gl_FragColor = vec4(res.rgb, yuva.g);\n"
"}\n";

static const QString OneFieldShader[2] = {
"GLSL_DEFINES"
"uniform sampler2D s_texture0;\n"
"uniform mat4 m_colourMatrix;\n"
"varying vec2 v_texcoord0;\n"
"void main(void)\n"
"{\n"
" vec2 field = vec2(0.0, step(0.5, fract(v_texcoord0.y * %2)) * %3);\n"
" vec4 yuva = texture2D(s_texture0, v_texcoord0 + field);\n"
" vec4 res = vec4(yuva.arb, 1.0) * m_colourMatrix;\n"
" gl_FragColor = vec4(res.rgb, yuva.g);\n"
"}\n",

"GLSL_DEFINES"
"uniform sampler2D s_texture0;\n"
"uniform mat4 m_colourMatrix;\n"
"varying vec2 v_texcoord0;\n"
"void main(void)\n"
"{\n"
" vec2 field = vec2(0.0, step(0.5, 1 - fract(v_texcoord0.y * %2)) * %3);\n"
" vec4 yuva = texture2D(s_texture0, v_texcoord0 + field);\n"
" vec4 res = vec4(yuva.arb, 1.0) * m_colourMatrix;\n"
" gl_FragColor = vec4(res.rgb, yuva.g);\n"
"}\n"
};

void OpenGLVideo::GetProgramStrings(QString &vertex, QString &fragment,
OpenGLFilterType filter,
QString deint, FrameScanType field)
{
vertex = YUV2RGBVertexShader;
fragment = YUV2RGBFragmentShader;
uint bottom = field == kScan_Intr2ndField;
switch (filter)
{
default:
vertex = YUV2RGBVertexShader;
if (deint == "openglonefield" || deint == "openglbobdeint")
fragment = OneFieldShader[bottom];
else
fragment = YUV2RGBFragmentShader;
break;
}
CustomiseProgramString(vertex);
CustomiseProgramString(fragment);
}

uint OpenGLVideo::ParseOptions(QString options)
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythtv/openglvideo.h
Expand Up @@ -94,6 +94,7 @@ class OpenGLVideo
OpenGLFilterType filter,
QString deint = QString::null,
FrameScanType field = kScan_Progressive);
void CustomiseProgramString(QString &string);
static QString FilterToString(OpenGLFilterType filter);
static OpenGLFilterType StringToFilter(const QString &filter);
QSize GetTextureSize(const QSize &size);
Expand Down
3 changes: 3 additions & 0 deletions mythtv/libs/libmythui/mythrender_opengl.cpp
Expand Up @@ -807,7 +807,10 @@ bool MythRenderOpenGL::CreateFragmentProgram(const QString &program, uint &prog)
}

if (success)
{
VERBOSE(VB_PLAYBACK|VB_EXTRA, "\n" + program + "\n");
m_programs.push_back(glfp);
}
else
m_glDeleteProgramsARB(1, &glfp);

Expand Down

0 comments on commit 8cb1707

Please sign in to comment.