Skip to content

Commit

Permalink
gl: support xyz12le for gl3
Browse files Browse the repository at this point in the history
what about be?
  • Loading branch information
wang-bin committed Sep 28, 2016
1 parent 7ee2ac6 commit ab48666
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
20 changes: 19 additions & 1 deletion src/ColorTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@

namespace QtAV {

// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
static const QMatrix4x4 kXYZ2sRGB(3.2404542f, -1.5371385f, -0.4985314f, 0.0f,
-0.9692660f, 1.8760108f, 0.0415560f, 0.0f,
0.0556434f, -0.2040259f, 1.0572252f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
// http://www.cs.utah.edu/~halzahaw/CS7650/Project2/project2_index.html no gamma correction
static const QMatrix4x4 kXYZ_RGB(2.5623f, -1.1661f, -0.3962f, 0.0f,
-1.0215f, 1.9778f, 0.0437f, 0.0f,
0.0752f, -0.2562f, 1.1810f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);

static const QMatrix4x4 kGBR2RGB = QMatrix4x4(0, 0, 1, 0,
1, 0, 0, 0,
0, 1, 0, 0,
Expand Down Expand Up @@ -211,6 +222,9 @@ class ColorTransform::Private : public QSharedData
// M *= rgb_range_translate*rgb_range_scale
// TODO: transform to output color space other than RGB
switch (cs_out) {
case ColorSpace_XYZ:
M = kXYZ2sRGB.inverted() * M;
break;
case ColorSpace_RGB:
M *= ColorRangeRGB(ColorRange_Full, range_out);
break;
Expand All @@ -224,6 +238,9 @@ class ColorTransform::Private : public QSharedData
}

switch (cs_in) {
case ColorSpace_XYZ:
M *= kXYZ2sRGB;
break;
case ColorSpace_RGB:
break;
case ColorSpace_GBR:
Expand All @@ -233,7 +250,8 @@ class ColorTransform::Private : public QSharedData
M *= YUV2RGB(cs_in)*ColorRangeYUV(range_in, ColorRange_Full);
break;
}
if (bpc_scale != 1.0) {
if (bpc_scale != 1.0 && cs_in != ColorSpace_XYZ) { // why no range correction for xyz?
//qDebug("bpc scale: %f", bpc_scale);
M *= QMatrix4x4(bpc_scale, 0, 0, 0,
0, bpc_scale, 0, 0,
0, 0, bpc_scale, 0,
Expand Down
9 changes: 7 additions & 2 deletions src/opengl/VideoShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ const char* VideoShader::fragmentShader() const
} else {
if (has_alpha)
frag.prepend("#define HAS_ALPHA\n");
if (d.video_format.isXYZ())
frag.prepend("#define XYZ_GAMMA\n");
}

if (d.texture_target == GL_TEXTURE_RECTANGLE) {
Expand Down Expand Up @@ -524,6 +526,8 @@ void VideoMaterial::setCurrentFrame(const VideoFrame &frame)
cs = ColorSpace_GBR;
else
cs = ColorSpace_RGB;
} else if (fmt.isXYZ()) {
cs = ColorSpace_XYZ;
} else {
if (frame.width() >= 1280 || frame.height() > 576) //values from mpv
cs = ColorSpace_BT709;
Expand Down Expand Up @@ -564,12 +568,13 @@ VideoShader* VideoMaterial::createShader() const

QString VideoMaterial::typeName(qint32 value)
{
return QString("gl material 16to8bit: %1, planar: %2, has alpha: %3, 2d texture: %4, 2nd plane rg: %5")
return QString("gl material 16to8bit: %1, planar: %2, has alpha: %3, 2d texture: %4, 2nd plane rg: %5, xyz: %6")
.arg(!!(value&1))
.arg(!!(value&(1<<1)))
.arg(!!(value&(1<<2)))
.arg(!!(value&(1<<3)))
.arg(!!(value&(1<<4)))
.arg(!!(value&(1<<5)))
;
}

Expand All @@ -581,7 +586,7 @@ qint32 VideoMaterial::type() const
// 2d,alpha,planar,8bit
const int rg_biplane = fmt.planeCount()==2 && !OpenGLHelper::useDeprecatedFormats() && OpenGLHelper::hasRG();
const int channel16_to8 = d.bpc > 8 && (OpenGLHelper::depth16BitTexture() < 16 || !OpenGLHelper::has16BitTexture() || fmt.isBigEndian());
return (rg_biplane<<4)|(tex_2d<<3)|(fmt.hasAlpha()<<2)|(fmt.isPlanar()<<1)|(channel16_to8);
return (fmt.isXYZ()<<5)|(rg_biplane<<4)|(tex_2d<<3)|(fmt.hasAlpha()<<2)|(fmt.isPlanar()<<1)|(channel16_to8);
}

bool VideoMaterial::bind()
Expand Down
9 changes: 8 additions & 1 deletion src/shaders/packed.f.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ vec4 sample2d(sampler2D tex, vec2 pos, int plane)
void main() {
vec4 c = sample2d(u_Texture0, v_TexCoords0, 0);
c = u_c * c;
#ifdef XYZ_GAMMA
c.rgb = pow(c.rgb, vec3(2.6));
#endif // XYZ_GAMMA
c = u_colorMatrix * c;
#ifdef XYZ_GAMMA
c.rgb = pow(c.rgb, vec3(1.0/2.2));
#endif //XYZ_GAMMA
#ifndef HAS_ALPHA
c.a = 1.0;
#endif //HAS_ALPHA
gl_FragColor = clamp(u_colorMatrix * c, 0.0, 1.0) * u_opacity;
gl_FragColor = clamp(c, 0.0, 1.0) * u_opacity;
/***User post processing here***%userPostProcess%***/
}

0 comments on commit ab48666

Please sign in to comment.