--- a/qtmobility/src/multimedia/qpaintervideosurface.cpp Fri Apr 16 15:51:22 2010 +0300
+++ b/qtmobility/src/multimedia/qpaintervideosurface.cpp Mon May 03 13:18:40 2010 +0300
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include <qpaintervideosurface_p.h>
+#include "qpaintervideosurface_p.h"
#include <qmath.h>
@@ -360,23 +360,23 @@
{
const qreal b = brightness / 200.0;
const qreal c = contrast / 100.0 + 1.0;
- const qreal h = hue / 200.0;
+ const qreal h = hue / 100.0;
const qreal s = saturation / 100.0 + 1.0;
const qreal cosH = qCos(M_PI * h);
const qreal sinH = qSin(M_PI * h);
- const qreal h11 = -0.4728 * cosH + 0.7954 * sinH + 1.4728;
- const qreal h21 = -0.9253 * cosH - 0.0118 * sinH + 0.9523;
- const qreal h31 = 0.4525 * cosH + 0.8072 * sinH - 0.4524;
+ const qreal h11 = 0.787 * cosH - 0.213 * sinH + 0.213;
+ const qreal h21 = -0.213 * cosH + 0.143 * sinH + 0.213;
+ const qreal h31 = -0.213 * cosH - 0.787 * sinH + 0.213;
- const qreal h12 = 1.4728 * cosH - 1.3728 * sinH - 1.4728;
- const qreal h22 = 1.9253 * cosH + 0.5891 * sinH - 0.9253;
- const qreal h32 = -0.4525 * cosH - 1.9619 * sinH + 0.4525;
+ const qreal h12 = -0.715 * cosH - 0.715 * sinH + 0.715;
+ const qreal h22 = 0.285 * cosH + 0.140 * sinH + 0.715;
+ const qreal h32 = -0.715 * cosH + 0.715 * sinH + 0.715;
- const qreal h13 = 1.4728 * cosH - 0.2181 * sinH - 1.4728;
- const qreal h23 = 0.9253 * cosH + 1.1665 * sinH - 0.9253;
- const qreal h33 = 0.5475 * cosH - 1.3846 * sinH + 0.4525;
+ const qreal h13 = -0.072 * cosH + 0.928 * sinH + 0.072;
+ const qreal h23 = -0.072 * cosH - 0.283 * sinH + 0.072;
+ const qreal h33 = 0.928 * cosH + 0.072 * sinH + 0.072;
const qreal sr = (1.0 - s) * 0.3086;
const qreal sg = (1.0 - s) * 0.6094;
@@ -529,6 +529,32 @@
"DP4 result.color.z, yuv, matrix[2];\n"
"END";
+// Paints a YUV444 frame.
+static const char *qt_arbfp_xyuvShaderProgram =
+ "!!ARBfp1.0\n"
+ "PARAM matrix[4] = { program.local[0..2],"
+ "{ 0.0, 0.0, 0.0, 1.0 } };\n"
+ "TEMP ayuv;\n"
+ "TEX ayuv, fragment.texcoord[0], texture[0], 2D;\n"
+ "MOV ayuv.x, matrix[3].w;\n"
+ "DP4 result.color.x, ayuv.yzwx, matrix[0];\n"
+ "DP4 result.color.y, ayuv.yzwx, matrix[1];\n"
+ "DP4 result.color.z, ayuv.yzwx, matrix[2];\n"
+ "END";
+
+// Paints a AYUV444 frame.
+static const char *qt_arbfp_ayuvShaderProgram =
+ "!!ARBfp1.0\n"
+ "PARAM matrix[4] = { program.local[0..2],"
+ "{ 0.0, 0.0, 0.0, 1.0 } };\n"
+ "TEMP ayuv;\n"
+ "TEX ayuv, fragment.texcoord[0], texture[0], 2D;\n"
+ "MOV ayuv.x, matrix[3].w;\n"
+ "DP4 result.color.x, ayuv.yzwx, matrix[0];\n"
+ "DP4 result.color.y, ayuv.yzwx, matrix[1];\n"
+ "DP4 result.color.z, ayuv.yzwx, matrix[2];\n"
+ "TEX result.color.w, fragment.texcoord[0], texture, 2D;\n"
+ "END";
class QVideoSurfaceArbFpPainter : public QVideoSurfaceGLPainter
{
@@ -577,9 +603,13 @@
m_imagePixelFormats
<< QVideoFrame::Format_RGB32
+ << QVideoFrame::Format_BGR32
<< QVideoFrame::Format_ARGB32
<< QVideoFrame::Format_RGB24
+ << QVideoFrame::Format_BGR24
<< QVideoFrame::Format_RGB565
+ << QVideoFrame::Format_AYUV444
+ << QVideoFrame::Format_YUV444
<< QVideoFrame::Format_YV12
<< QVideoFrame::Format_YUV420P;
m_glPixelFormats
@@ -603,18 +633,36 @@
initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
program = qt_arbfp_xrgbShaderProgram;
break;
+ case QVideoFrame::Format_BGR32:
+ initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
+ program = qt_arbfp_rgbShaderProgram;
+ break;
case QVideoFrame::Format_ARGB32:
initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
program = qt_arbfp_argbShaderProgram;
break;
case QVideoFrame::Format_RGB24:
initRgbTextureInfo(GL_RGB8, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
- program = qt_arbfp_argbShaderProgram;
+ program = qt_arbfp_rgbShaderProgram;
+ break;
+ case QVideoFrame::Format_BGR24:
+ initRgbTextureInfo(GL_RGB8, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
+ program = qt_arbfp_xrgbShaderProgram;
break;
case QVideoFrame::Format_RGB565:
initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, format.frameSize());
program = qt_arbfp_rgbShaderProgram;
break;
+ case QVideoFrame::Format_YUV444:
+ initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize());
+ program = qt_arbfp_xyuvShaderProgram;
+ m_yuv = true;
+ break;
+ case QVideoFrame::Format_AYUV444:
+ initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
+ program = qt_arbfp_ayuvShaderProgram;
+ m_yuv = true;
+ break;
case QVideoFrame::Format_YV12:
initYv12TextureInfo(format.frameSize());
program = qt_arbfp_yuvPlanarShaderProgram;
@@ -704,6 +752,9 @@
if (m_frame.isValid()) {
painter->beginNativePainting();
+ glEnable(GL_STENCIL_TEST);
+ glEnable(GL_SCISSOR_TEST);
+
const float txLeft = source.left() / m_frameSize.width();
const float txRight = source.right() / m_frameSize.width();
const float txTop = m_scanLineDirection == QVideoSurfaceFormat::TopToBottom
@@ -784,6 +835,9 @@
glDisableClientState(GL_VERTEX_ARRAY);
glDisable(GL_FRAGMENT_PROGRAM_ARB);
+ glDisable(GL_STENCIL_TEST);
+ glDisable(GL_SCISSOR_TEST);
+
painter->endNativePainting();
}
return QAbstractVideoSurface::NoError;
@@ -854,6 +908,28 @@
" gl_FragColor = colorMatrix * color;\n"
"}\n";
+// Paints a YUV444 frame.
+static const char *qt_glsl_xyuvShaderProgram =
+ "uniform sampler2D texRgb;\n"
+ "uniform mediump mat4 colorMatrix;\n"
+ "varying highp vec2 textureCoord;\n"
+ "void main(void)\n"
+ "{\n"
+ " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).gba, 1.0);\n"
+ " gl_FragColor = colorMatrix * color;\n"
+ "}\n";
+
+// Paints a AYUV444 frame.
+static const char *qt_glsl_ayuvShaderProgram =
+ "uniform sampler2D texRgb;\n"
+ "uniform mediump mat4 colorMatrix;\n"
+ "varying highp vec2 textureCoord;\n"
+ "void main(void)\n"
+ "{\n"
+ " highp vec4 color = vec4(texture2D(texRgb, textureCoord.st).gba, 1.0);\n"
+ " color = colorMatrix * color;\n"
+ " gl_FragColor = vec4(color.rgb, texture2D(texRgb, textureCoord.st).r);\n"
+ "}\n";
class QVideoSurfaceGlslPainter : public QVideoSurfaceGLPainter
{
@@ -877,11 +953,15 @@
{
m_imagePixelFormats
<< QVideoFrame::Format_RGB32
+ << QVideoFrame::Format_BGR32
<< QVideoFrame::Format_ARGB32
#ifndef QT_OPENGL_ES
<< QVideoFrame::Format_RGB24
+ << QVideoFrame::Format_BGR24
#endif
<< QVideoFrame::Format_RGB565
+ << QVideoFrame::Format_YUV444
+ << QVideoFrame::Format_AYUV444
<< QVideoFrame::Format_YV12
<< QVideoFrame::Format_YUV420P;
m_glPixelFormats
@@ -905,6 +985,10 @@
initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
fragmentProgram = qt_glsl_xrgbShaderProgram;
break;
+ case QVideoFrame::Format_BGR32:
+ initRgbTextureInfo(GL_RGB, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
+ fragmentProgram = qt_glsl_rgbShaderProgram;
+ break;
case QVideoFrame::Format_ARGB32:
initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
fragmentProgram = qt_glsl_argbShaderProgram;
@@ -914,11 +998,25 @@
initRgbTextureInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize());
fragmentProgram = qt_glsl_rgbShaderProgram;
break;
+ case QVideoFrame::Format_BGR24:
+ initRgbTextureInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize());
+ fragmentProgram = qt_glsl_argbShaderProgram;
+ break;
#endif
case QVideoFrame::Format_RGB565:
initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, format.frameSize());
fragmentProgram = qt_glsl_rgbShaderProgram;
break;
+ case QVideoFrame::Format_YUV444:
+ initRgbTextureInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize());
+ fragmentProgram = qt_glsl_xyuvShaderProgram;
+ m_yuv = true;
+ break;
+ case QVideoFrame::Format_AYUV444:
+ initRgbTextureInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, format.frameSize());
+ fragmentProgram = qt_glsl_ayuvShaderProgram;
+ m_yuv = true;
+ break;
case QVideoFrame::Format_YV12:
initYv12TextureInfo(format.frameSize());
fragmentProgram = qt_glsl_yuvPlanarShaderProgram;
@@ -987,6 +1085,9 @@
if (m_frame.isValid()) {
painter->beginNativePainting();
+ glEnable(GL_STENCIL_TEST);
+ glEnable(GL_SCISSOR_TEST);
+
const int width = QGLContext::currentContext()->device()->width();
const int height = QGLContext::currentContext()->device()->height();
@@ -1085,6 +1186,9 @@
m_program.release();
+
+ glDisable(GL_SCISSOR_TEST);
+ glDisable(GL_STENCIL_TEST);
painter->endNativePainting();
}
return QAbstractVideoSurface::NoError;