Merge pull request #4357 from koying/fixfilemgrdoubleclick
[vuplus_xbmc] / system / shaders / yuv2rgb_d3d.fx
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
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/>.
18  *
19  */
20
21 texture g_YTexture;
22 texture g_UTexture;
23 texture g_VTexture;
24 float4x4 g_ColorMatrix;
25 float2  g_StepXY;
26
27 sampler YSampler =
28   sampler_state {
29     Texture = <g_YTexture>;
30     AddressU = CLAMP;
31     AddressV = CLAMP;
32     MinFilter = LINEAR;
33     MagFilter = LINEAR;
34   };
35
36 sampler USampler =
37   sampler_state {
38     Texture = <g_UTexture>;
39     AddressU = CLAMP;
40     AddressV = CLAMP;
41     MinFilter = LINEAR;
42     MagFilter = LINEAR;
43   };
44
45 sampler VSampler =
46   sampler_state
47   {
48     Texture = <g_VTexture>;
49     AddressU = CLAMP;
50     AddressV = CLAMP;
51     MinFilter = LINEAR;
52     MagFilter = LINEAR;
53   };
54
55 struct VS_OUTPUT
56 {
57   float4 Position   : POSITION;
58   float2 TextureY   : TEXCOORD0;
59   float2 TextureU   : TEXCOORD1;
60   float2 TextureV   : TEXCOORD2;
61 };
62
63 struct PS_OUTPUT
64 {
65   float4 RGBColor : COLOR0;
66 };
67
68 PS_OUTPUT YUV2RGB( VS_OUTPUT In)
69 {
70   PS_OUTPUT OUT;
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
75                     , 1.0);
76 #elif defined(XBMC_NV12)
77   float4 YUV = float4(tex2D (YSampler, In.TextureY).x
78                     , tex2D (USampler, In.TextureU).ra
79                     , 1.0);
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);
87
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));
92
93   /* each pixel has two Y subpixels and one UV subpixel
94       YUV  Y  YUV
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);
104   #endif
105     float  outY   = lerp(leftY, rightY, step(0.5, f.x));
106     float4 YUV    = float4(outY, outUV, 1.0);
107 #endif
108
109   OUT.RGBColor = mul(YUV, g_ColorMatrix);
110   OUT.RGBColor.a = 1.0;
111   return OUT;
112 }
113
114 technique YUV2RGB_T
115 {
116   pass P0
117   {
118     PixelShader  = compile ps_2_0 YUV2RGB();
119     ZEnable = False;
120     FillMode = Solid;
121     FogEnable = False;
122   }
123 };