Geglglessink: LSL: Optimize frag_YUY2_YVYU_UYVY_prog
authorReynaldo H. Verdejo Pinochet <reynaldo@collabora.com>
Wed, 10 Oct 2012 14:05:04 +0000 (11:05 -0300)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Thu, 18 Oct 2012 12:35:18 +0000 (14:35 +0200)
- Avoid repeatedly performing the texture lookup
- Use consts for the transform's offset and cofficients values
- Use the dot product instead of the explicit mult and add

ext/eglgles/gsteglglessink.c

index 7235b07..1949b79 100644 (file)
@@ -239,19 +239,20 @@ static const char *frag_YUY2_YVYU_UYVY_prog = {
       "precision mediump float;"
       "varying vec2 opos;"
       "uniform sampler2D Ytex, UVtex;"
+      "const vec3 offset = vec3(-0.0625, -0.5, -0.5);"
+      "const vec3 rcoeff = vec3(1.164, 0.000, 1.596);"
+      "const vec3 gcoeff = vec3(1.164,-0.391,-0.813);"
+      "const vec3 bcoeff = vec3(1.164, 2.018, 0.000);"
       "void main(void) {"
-      "  float fx, fy, y, u, v, r, g, b;"
-      "  fx = opos.x;"
-      "  fy = opos.y;"
-      "  y = texture2D(Ytex,vec2(fx,fy)).%c;"
-      "  u = texture2D(UVtex,vec2(fx,fy)).%c;"
-      "  v = texture2D(UVtex,vec2(fx,fy)).%c;"
-      "  y=1.1643*(y-0.0625);"
-      "  u=u-0.5;"
-      "  v=v-0.5;"
-      "  r=y+1.5958*v;"
-      "  g=y-0.39173*u-0.81290*v;"
-      "  b=y+2.017*u;"
+      "  float r, g, b;"
+      "  vec3 yuv;"
+      "  vec2 oposxy = vec2(opos.x, opos.y);"
+      "  yuv.x = texture2D(Ytex,oposxy).x;"
+      "  yuv.yz = texture2D(UVtex,oposxy).yz;"
+      "  yuv += offset;"
+      "  r = dot(yuv, rcoeff);"
+      "  g = dot(yuv, gcoeff);"
+      "  b = dot(yuv, bcoeff);"
       "  gl_FragColor=vec4(r,g,b,1.0);"
       "}"
 };