home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 May / CMCD0505.ISO / Software / Freeware / Multimedia / mplayerclassicXP / mplayerc.exe / 1033 / FILE / 407 < prev   
Text File  |  2005-03-20  |  2KB  |  78 lines

  1. sampler s0 : register(s0);
  2.  
  3. float4 p0  : register(c0);
  4. float2 dxdy : register(c1);
  5. float2 dx : register(c2);
  6. float2 dy : register(c3);
  7.  
  8. #define size (p0.xy)
  9. #define    A _The_Value_Of_A_Is_Set_Here_
  10.  
  11. float4 main_bilinear(float2 tex : TEXCOORD0) : COLOR
  12. {
  13.     // not usable for 1:1 mapping! 
  14.     // tex * size won't be 0, 1, 2, 3, .. as you might expect, but something like 0, 0.999, 2.001, 2.999, ...
  15.     // this means when the fractional part becomes 0.999 we will be interpolating with the wrong value!!!
  16.     
  17.     tex -= 0.5*dxdy;
  18.     
  19.     float2 dd = frac(tex * size); 
  20.  
  21.     float4 c = lerp(
  22.         lerp(tex2D(s0, tex), tex2D(s0, tex + dx), dd.x),
  23.         lerp(tex2D(s0, tex + dy), tex2D(s0, tex + dxdy), dd.x),
  24.         dd.y);
  25.         
  26.     return c;
  27. }
  28.  
  29. static float4x4    tco =
  30. {
  31.     0, A, -2*A, A,
  32.     1, 0, -A-3, A+2,
  33.     0, -A, 2*A+3, -A-2,
  34.     0, 0, A, -A
  35. };
  36.  
  37. float4 taps(float x)
  38. {
  39.     return mul(tco, float4(1, x, x*x, x*x*x));
  40. }
  41.  
  42. float4 c3sample(float4 taps, float2 t)
  43. {
  44.     return
  45.         mul(taps,
  46.             float4x4(
  47.                 tex2D(s0, t-dx),
  48.                 tex2D(s0, t),
  49.                 tex2D(s0, t+dx),
  50.                 tex2D(s0, t+dx+dx)
  51.             )
  52.         );
  53. }
  54.  
  55. float4 main_bicubic(float2 tex : TEXCOORD0) : COLOR
  56. {
  57.     // not usable for 1:1 mapping! 
  58.     // tex * size won't be 0, 1, 2, 3, .. as you might expect, but something like 0, 0.999, 2.001, 2.999, ...
  59.     // this means when the fractional part becomes 0.999 we will be interpolating with the wrong value!!!
  60.     
  61.     tex -= 0.5*dxdy;
  62.     
  63.     float2 dd = frac(tex * size);
  64.  
  65.     float4 tx = taps(dd.x);
  66.     float4 c = mul(
  67.         taps(dd.y),
  68.         float4x4(
  69.             c3sample(tx, tex-dy),
  70.             c3sample(tx, tex),
  71.             c3sample(tx, tex+dy),
  72.             c3sample(tx, tex+dy+dy)
  73.         )
  74.     );
  75.  
  76.     return c;
  77. }
  78.