2 * Copyright (C) 2010-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #if(XBMC_texture_rectangle)
22 # extension GL_ARB_texture_rectangle : enable
23 # define texture2D texture2DRect
24 # define sampler2D sampler2DRect
27 uniform sampler2D m_sampY;
28 uniform sampler2D m_sampU;
29 uniform sampler2D m_sampV;
36 uniform mat4 m_yuvmat;
38 uniform float m_stretch;
40 vec2 stretch(vec2 pos)
43 // our transform should map [0..1] to itself, with f(0) = 0, f(1) = 1, f(0.5) = 0.5, and f'(0.5) = b.
44 // a simple curve to do this is g(x) = b(x-0.5) + (1-b)2^(n-1)(x-0.5)^n + 0.5
45 // where the power preserves sign. n = 2 is the simplest non-linear case (required when b != 1)
46 #if(XBMC_texture_rectangle)
47 float x = (pos.x * m_step.x) - 0.5;
48 return vec2((mix(2.0 * x * abs(x), x, m_stretch) + 0.5) / m_step.x, pos.y);
50 float x = pos.x - 0.5;
51 return vec2(mix(2.0 * x * abs(x), x, m_stretch) + 0.5, pos.y);
60 #if defined(XBMC_YV12) || defined(XBMC_NV12)
63 yuv.rgba = vec4( texture2D(m_sampY, stretch(m_cordY)).r
64 , texture2D(m_sampU, stretch(m_cordU)).g
65 , texture2D(m_sampV, stretch(m_cordV)).a
72 #elif defined(XBMC_VDPAU_NV12)
75 yuv.rgba = vec4( texture2D(m_sampY, stretch(m_cordY)).r
76 , texture2D(m_sampU, stretch(m_cordU)).r
77 , texture2D(m_sampV, stretch(m_cordV)).g
84 #elif defined(XBMC_YUY2) || defined(XBMC_UYVY)
86 #if(XBMC_texture_rectangle)
87 vec2 stepxy = vec2(1.0, 1.0);
88 vec2 pos = stretch(m_cordY);
89 pos = vec2(pos.x - 0.25, pos.y);
93 vec2 pos = stretch(m_cordY);
94 pos = vec2(pos.x - stepxy.x * 0.25, pos.y);
95 vec2 f = fract(pos / stepxy);
98 //y axis will be correctly interpolated by opengl
99 //x axis will not, so we grab two pixels at the center of two columns and interpolate ourselves
100 vec4 c1 = texture2D(m_sampY, vec2(pos.x + (0.5 - f.x) * stepxy.x, pos.y));
101 vec4 c2 = texture2D(m_sampY, vec2(pos.x + (1.5 - f.x) * stepxy.x, pos.y));
103 /* each pixel has two Y subpixels and one UV subpixel
105 check if we're left or right of the middle Y subpixel and interpolate accordingly*/
106 #ifdef XBMC_YUY2 //BGRA = YUYV
107 float leftY = mix(c1.b, c1.r, f.x * 2.0);
108 float rightY = mix(c1.r, c2.b, f.x * 2.0 - 1.0);
109 vec2 outUV = mix(c1.ga, c2.ga, f.x);
111 float leftY = mix(c1.g, c1.a, f.x * 2.0);
112 float rightY = mix(c1.a, c2.g, f.x * 2.0 - 1.0);
113 vec2 outUV = mix(c1.br, c2.br, f.x);
116 float outY = mix(leftY, rightY, step(0.5, f.x));
118 vec4 yuv = vec4(outY, outUV, 1.0);
119 vec4 rgb = m_yuvmat * yuv;
122 gl_FragColor.a = gl_Color.a;