2 * Copyright (C) 2005-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/>.
24 float4x4 g_ColorMatrix;
29 Texture = <g_YTexture>;
38 Texture = <g_UTexture>;
48 Texture = <g_VTexture>;
57 float4 Position : POSITION;
58 float2 TextureY : TEXCOORD0;
59 float2 TextureU : TEXCOORD1;
60 float2 TextureV : TEXCOORD2;
65 float4 RGBColor : COLOR0;
68 PS_OUTPUT YUV2RGB( VS_OUTPUT In)
71 #if defined(XBMC_YV12)
72 float4 YUV = float4(tex2D (YSampler, In.TextureY).x
73 , tex2D (USampler, In.TextureU).x
74 , tex2D (VSampler, In.TextureV).x
76 #elif defined(XBMC_NV12)
77 float4 YUV = float4(tex2D (YSampler, In.TextureY).x
78 , tex2D (USampler, In.TextureU).ra
80 #elif defined(XBMC_YUY2) || defined(XBMC_UYVY)
81 // The HLSL compiler is smart enough to optimize away these redundant assignments.
82 // That way the code is almost identical to the OGL shader.
83 float2 stepxy = g_StepXY;
84 float2 pos = In.TextureY;
85 pos = float2(pos.x - (stepxy.x * 0.25), pos.y);
86 float2 f = frac(pos / stepxy);
88 //y axis will be correctly interpolated by opengl
89 //x axis will not, so we grab two pixels at the center of two columns and interpolate ourselves
90 float4 c1 = tex2D(YSampler, float2(pos.x + ((0.5 - f.x) * stepxy.x), pos.y));
91 float4 c2 = tex2D(YSampler, float2(pos.x + ((1.5 - f.x) * stepxy.x), pos.y));
93 /* each pixel has two Y subpixels and one UV subpixel
95 check if we're left or right of the middle Y subpixel and interpolate accordingly*/
96 #if defined(XBMC_YUY2) // BGRA = YUYV
97 float leftY = lerp(c1.b, c1.r, f.x * 2.0);
98 float rightY = lerp(c1.r, c2.b, f.x * 2.0 - 1.0);
99 float2 outUV = lerp(c1.ga, c2.ga, f.x);
100 #elif defined(XBMC_UYVY) // BGRA = UYVY
101 float leftY = lerp(c1.g, c1.a, f.x * 2.0);
102 float rightY = lerp(c1.a, c2.g, f.x * 2.0 - 1.0);
103 float2 outUV = lerp(c1.br, c2.br, f.x);
105 float outY = lerp(leftY, rightY, step(0.5, f.x));
106 float4 YUV = float4(outY, outUV, 1.0);
109 OUT.RGBColor = mul(YUV, g_ColorMatrix);
110 OUT.RGBColor.a = 1.0;
118 PixelShader = compile ps_2_0 YUV2RGB();