PageRenderTime 23ms CodeModel.GetById 17ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/xbmc/cores/VideoRenderers/legacy/yuv2rgb_6x6_d3d.fx

http://github.com/xbmc/xbmc
Unknown | 161 lines | 140 code | 21 blank | 0 comment | 0 complexity | 1e088a8d259f78208865c6f886dfccc8 MD5 | raw file
  1/*
  2 *      Copyright (C) 2010-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
 21texture g_YTexture;
 22texture g_UTexture;
 23texture g_VTexture;
 24texture g_KernelTexture;
 25
 26float2 g_YStep;
 27float2 g_UVStep;
 28
 29float4x4 g_ColorMatrix;
 30
 31sampler YSampler =
 32  sampler_state {
 33    Texture = <g_YTexture>;
 34    AddressU = CLAMP;
 35    AddressV = CLAMP;
 36    MipFilter = LINEAR;
 37    MinFilter = POINT;
 38    MagFilter = POINT;
 39  };
 40
 41sampler USampler = 
 42  sampler_state {
 43    Texture = <g_UTexture>;
 44    AddressU = CLAMP;
 45    AddressV = CLAMP;
 46    MipFilter = LINEAR;
 47    MinFilter = POINT;
 48    MagFilter = POINT;
 49  };
 50
 51sampler VSampler = 
 52  sampler_state
 53  {
 54    Texture = <g_VTexture>;
 55    AddressU = CLAMP;
 56    AddressV = CLAMP;
 57    MipFilter = LINEAR;
 58    MinFilter = POINT;
 59    MagFilter = POINT;
 60  };
 61  
 62sampler KernelSampler = 
 63  sampler_state
 64  {
 65    Texture = <g_KernelTexture>;
 66    AddressU = CLAMP;
 67    AddressV = CLAMP;
 68    MipFilter = LINEAR;
 69    MinFilter = LINEAR;
 70    MagFilter = LINEAR;
 71  };
 72
 73struct VS_OUTPUT
 74{
 75  float4 Position   : POSITION;
 76  float2 TextureY   : TEXCOORD0;
 77  float2 TextureU   : TEXCOORD1;
 78  float2 TextureV   : TEXCOORD2;
 79};
 80
 81struct PS_OUTPUT
 82{
 83  float4 RGBColor : COLOR0;
 84};
 85
 86float3 weight(float pos)
 87{
 88  return tex1D(KernelSampler, pos).rgb;
 89}
 90
 91float pixel(sampler tex, float xpos, float ypos)
 92{
 93  return tex2D(tex, float2(xpos, ypos)).r;
 94}
 95
 96float getLine(sampler tex, float ypos, float3 xpos1, float3 xpos2, float3 linetaps1, float3 linetaps2)
 97{
 98  float  pixels;
 99
100  pixels  = pixel(tex, xpos1.r, ypos) * linetaps1.r;
101  pixels += pixel(tex, xpos1.g, ypos) * linetaps2.r;
102  pixels += pixel(tex, xpos1.b, ypos) * linetaps1.g;
103  pixels += pixel(tex, xpos2.r, ypos) * linetaps2.g;
104  pixels += pixel(tex, xpos2.g, ypos) * linetaps1.b;
105  pixels += pixel(tex, xpos2.b, ypos) * linetaps2.b;
106
107  return pixels;
108}
109
110float getPixel(sampler tex, float2 texCoord, float2 step)
111{
112  float xf = frac(texCoord.x / step.x);
113  float yf = frac(texCoord.y / step.y);
114
115  float3 linetaps1   = weight((1.0 - xf) / 2.0);
116  float3 linetaps2   = weight((1.0 - xf) / 2.0 + 0.5);
117  float3 columntaps1 = weight((1.0 - yf) / 2.0);
118  float3 columntaps2 = weight((1.0 - yf) / 2.0 + 0.5);
119
120  float3 xpos1 = float3(
121      (-1.5 - xf) * step.x + texCoord.x,
122      (-0.5 - xf) * step.x + texCoord.x,
123      ( 0.5 - xf) * step.x + texCoord.x);
124  float3 xpos2 = float3(
125      ( 1.5 - xf) * step.x + texCoord.x,
126      ( 2.5 - xf) * step.x + texCoord.x,
127      ( 3.5 - xf) * step.x + texCoord.x);
128
129  float fragColor;
130  fragColor  = getLine(tex, (-1.5 - yf) * step.y + texCoord.y, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.r;
131  fragColor += getLine(tex, (-0.5 - yf) * step.y + texCoord.y, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.r;
132  fragColor += getLine(tex, ( 0.5 - yf) * step.y + texCoord.y, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.g;
133  fragColor += getLine(tex, ( 1.5 - yf) * step.y + texCoord.y, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.g;
134  fragColor += getLine(tex, ( 2.5 - yf) * step.y + texCoord.y, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.b;
135  fragColor += getLine(tex, ( 3.5 - yf) * step.y + texCoord.y, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.b;
136
137  return fragColor;
138}
139
140PS_OUTPUT YUV2RGB(VS_OUTPUT In)
141{
142  PS_OUTPUT OUT;
143  float4 YUV = float4(getPixel (YSampler, In.TextureY, g_YStep)
144                    , getPixel (USampler, In.TextureU, g_UVStep)
145                    , getPixel (VSampler, In.TextureV, g_UVStep)
146                    , 1.0);
147  OUT.RGBColor = mul(YUV, g_ColorMatrix);
148  OUT.RGBColor.a = 1.0;
149  return OUT;
150}
151
152technique YUV2RGB_T
153{
154  pass P0
155  {
156    PixelShader  = compile ps_3_0 YUV2RGB();
157    ZEnable = False;
158    FillMode = Solid;
159    FogEnable = False;
160  }
161};