home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Software / Utils / SPlayer / SPlayerSetup.exe / splayer.exe / 2052 / FILE / 723 < prev   
Encoding:
Text File  |  2009-12-01  |  3.6 KB  |  107 lines

  1. //////////////////////////////////////////////////// 
  2. // Sharpen complex v2 (nΘcessite ps >=2a)
  3. //////////////////////////////////////////////////// 
  4. sampler s0 : register(s0); 
  5. float4 p0 : register(c0); 
  6. float4 p1 : register(c1); 
  7.  
  8. // rΘsolution de l'image
  9. #define width (p0[0]) 
  10. #define height (p0[1]) 
  11. // "largeur" d'un pixel
  12. #define px (p1[0])
  13. #define py (p1[1])
  14.  
  15.  
  16. //////////////////////////////////////////////////// 
  17. // ParamΦtres
  18. //////////////////////////////////////////////////// 
  19.   // pour le calcul du flou
  20. #define moyenne 0.6
  21. #define dx (moyenne*px)
  22. #define dy (moyenne*py)
  23.  
  24. #define CoefFlou 2
  25. #define CoefOri (1+ CoefFlou)
  26.  
  27.   // pour le sharpen
  28. #define SharpenEdge       0.2
  29. #define Sharpen_val0       2 
  30. #define Sharpen_val1       ((Sharpen_val0-1) / 8.0)
  31.  
  32.  
  33. //////////////////////////////////////////////////// 
  34. float4 main( float2 tex : TEXCOORD0 ) : COLOR 
  35.   // recup du pixel original
  36.                 float4 ori = tex2D(s0, tex); ; 
  37.  
  38. //////////////////////////////////////////////////// 
  39. // calcul image floue (filtre gaussien) 
  40. //////////////////////////////////////////////////// 
  41.                 float4 c1 = tex2D(s0, tex + float2(-dx,-dy)); 
  42.                 float4 c2 = tex2D(s0, tex + float2(0,-dy)); 
  43.                 float4 c3 = tex2D(s0, tex + float2(dx,-dy)); 
  44.                 float4 c4 = tex2D(s0, tex + float2(-dx,0)); 
  45.                 float4 c5 = tex2D(s0, tex + float2(dx,0)); 
  46.                 float4 c6 = tex2D(s0, tex + float2(-dx,dy)); 
  47.                 float4 c7 = tex2D(s0, tex + float2(0,dy)); 
  48.                 float4 c8 = tex2D(s0, tex + float2(dx,dy)); 
  49.  
  50.   // filtre gaussien
  51.   //   [ 1, 2 , 1 ] 
  52.   //   [ 2, 4 , 2 ] 
  53.   //   [ 1, 2 , 1 ] 
  54.   // pour normaliser les valeurs, il faut diviser par la somme des coef 
  55.   // 1 / (1+2+1+2+4+2+1+2+1) = 1 / 16 = .0625 
  56.                 float4 flou = (c1+c3+c6+c8 + 2*(c2+c4+c5+c7)+ 4*ori)*0.0625; 
  57.  
  58.   // soustraction de l'image flou α l'image originale 
  59.                 float4 cori = CoefOri*ori - CoefFlou*flou; 
  60.  
  61. //////////////////////////////////////////////////// 
  62. // dΘtection des contours 
  63. //////////////////////////////////////////////////// 
  64.   // rΘcuppΘration des 9 voisins 
  65.   //   [ c1, c2 , c3 ] 
  66.   //   [ c4,ori , c5 ] 
  67.   //   [ c6, c7 , c8 ] 
  68.                 c1 = tex2D(s0, tex + float2(-px,-py)); 
  69.                 c2 = tex2D(s0, tex + float2(0,-py)); 
  70.                 c3 = tex2D(s0, tex + float2(px,-py)); 
  71.                 c4 = tex2D(s0, tex + float2(-px,0)); 
  72.                 c5 = tex2D(s0, tex + float2(px,0)); 
  73.                 c6 = tex2D(s0, tex + float2(-px,py)); 
  74.                 c7 = tex2D(s0, tex + float2(0,py)); 
  75.                 c8 = tex2D(s0, tex + float2(px,py)); 
  76.  
  77. // par filtre de sobel 
  78.    // Gradient horizontal 
  79.    //   [ -1, 0 ,1 ] 
  80.    //   [ -2, 0, 2 ] 
  81.    //   [ -1, 0 ,1 ] 
  82.                 float delta1 =  (c3 + 2*c5 + c8)-(c1 + 2*c4 + c6); 
  83.  
  84.    // Gradient vertical 
  85.    //   [ -1,- 2,-1 ] 
  86.    //   [  0,  0, 0 ] 
  87.    //   [  1,  2, 1 ] 
  88.                 float delta2 = (c6 + 2*c7 + c8)-(c1 + 2*c2 + c3); 
  89.  
  90.    // calcul 
  91.                 if( sqrt( mul(delta1,delta1) + mul(delta2,delta2) ) >SharpenEdge ) 
  92.                 { 
  93. //////////////////////////////////////////////////// 
  94. // si contour, sharpen 
  95.                                //            return  float4(1,0,0,0);
  96.                                return ori*Sharpen_val0 - (c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8 ) * Sharpen_val1 ;  
  97.                 } 
  98.                 else 
  99.                 { 
  100. //////////////////////////////////////////////////// 
  101. // sinon, image corrigΘe 
  102.                                return cori; 
  103.                 } 
  104. }
  105.  
  106.