Skip to content

Commit

Permalink
gl: support <=16bit yuv in big endian
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Apr 18, 2014
1 parent 7f80cf4 commit 3092c9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/GLWidgetRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,11 @@ bool GLWidgetRendererPrivate::prepareShaderProgram(const VideoFormat &fmt)
if (frag.isEmpty())
return false;
if (!fmt.isRGB() && fmt.isPlanar() && fmt.bytesPerPixel(0) == 2) {
frag.prepend(QString("#define YUV16BITS_LE_LUMINANCE_ALPHA\n#define YUV%1PLE\n").arg(fmt.bitsPerPixel(0)));
if (fmt.isBigEndian())
frag.prepend("#define YUV16BITS_BE_LUMINANCE_ALPHA\n");
else
frag.prepend("#define YUV16BITS_LE_LUMINANCE_ALPHA\n");
frag.prepend(QString("#define YUV%1P\n").arg(fmt.bitsPerPixel(0)));
}
#if NO_QGL_SHADER
program = createProgram(kVertexShader, frag.toUtf8().constData());
Expand Down
26 changes: 14 additions & 12 deletions src/shaders/yuv_rgb.f.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,35 @@ const mat4 yuv2rgbMatrix = mat4(1, 1, 1, 0,
// 10, 16bit: http://msdn.microsoft.com/en-us/library/windows/desktop/bb970578%28v=vs.85%29.aspx
void main()
{
#if defined(YUV16BITS_LE_LUMINANCE_ALPHA)
#if defined(YUV16BITS_LE_LUMINANCE_ALPHA) || defined(YUV16BITS_BE_LUMINANCE_ALPHA)
// FFmpeg supports 9, 10, 12, 14, 16 bits
#if defined(YUV9PLE)
#if defined(YUV9P)
const float range = 511.0;
#elif defined(YUV10PLE)
#elif defined(YUV10P)
const float range = 1023.0;
#elif defined(YUV12PLE)
#elif defined(YUV12P)
const float range = 4095.0;
#elif defined(YUV14PLE)
#elif defined(YUV14P)
const float range = 16383.0;
#elif defined(YUV16PLE)
#elif defined(YUV16P)
const float range = 65535.0;
#endif
#endif //defined(YUV16BITS_LE_LUMINANCE_ALPHA)
// 10p in little endian: yyyyyyyy yy000000 => (L, L, L, A)
gl_FragColor = clamp(u_colorMatrix*yuv2rgbMatrix* vec4(
#if defined(YUV16BITS_LE_LUMINANCE_ALPHA)
(texture2D(u_Texture0, v_TexCoords).r + texture2D(u_Texture0, v_TexCoords).a*256.0)*255.0/range,
(texture2D(u_Texture1, v_TexCoords).r + texture2D(u_Texture1, v_TexCoords).a*256.0)*255.0/range,
(texture2D(u_Texture2, v_TexCoords).r + texture2D(u_Texture2, v_TexCoords).a*256.0)*255.0/range,
1)
, 0.0, 1.0);
#elif defined(YUV16BITS_BE_LUMINANCE_ALPHA)
(texture2D(u_Texture0, v_TexCoords).r*256.0 + texture2D(u_Texture0, v_TexCoords).a)*255.0/range,
(texture2D(u_Texture1, v_TexCoords).r*256.0 + texture2D(u_Texture1, v_TexCoords).a)*255.0/range,
(texture2D(u_Texture2, v_TexCoords).r*256.0 + texture2D(u_Texture2, v_TexCoords).a)*255.0/range,
#else
// use r, g, a to work for both yv12 and nv12
gl_FragColor = clamp(u_colorMatrix*yuv2rgbMatrix* vec4(
texture2D(u_Texture0, v_TexCoords).r,
texture2D(u_Texture1, v_TexCoords).g,
texture2D(u_Texture2, v_TexCoords).a,
#endif //defined(YUV16BITS_LE_LUMINANCE_ALPHA)
1)
, 0.0, 1.0);
#endif
, 0.0, 1.0);
}

0 comments on commit 3092c9e

Please sign in to comment.