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