cae7291

stackoverflow Q:77928716

Feb 4th, 2024
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. /*
  2. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  3. ; esi -> edi, ecx = line width
  4. ; return = (4*Pxl(x,y)+3*Pxl(x-1,y)+3*Pxl(x+1,y)+3*Pxl(x,y+1)+3*Pxl(x,y-1))/16
  5. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  6. _WaveGetPixel:
  7. movzx eax,byte ptr [esi]
  8. shl eax,2
  9. movzx edx,byte ptr [esi+3]
  10. lea edx,[edx+2*edx]
  11. add eax,edx
  12. movzx edx,byte ptr [esi-3]
  13. lea edx,[edx+2*edx]
  14. add eax,edx
  15. movzx edx,byte ptr [esi+ecx]
  16. lea edx,[edx+2*edx]
  17. add eax,edx
  18. mov edx,esi
  19. sub edx,ecx
  20. movzx edx,byte ptr [edx]
  21. lea edx,[edx+2*edx]
  22. add eax,edx
  23. shr eax,4
  24. mov [edi],al
  25. inc esi
  26. inc edi
  27. ret
  28. */
  29.  
  30. typedef unsigned char byte;
  31. typedef unsigned int u32;
  32.  
  33. void
  34. WaveGetPixel_1(byte *dst,const byte *src,u32 stride)
  35. {
  36. u32 sum = 0;
  37. u32 pix;
  38.  
  39. // (4 * Pxl(x,y) +
  40. // 3 * Pxl(x-1,y) +
  41. // 3 * Pxl(x+1,y) +
  42. // 3 * Pxl(x,y+1) +
  43. // 3 * Pxl(x,y-1)) / 16
  44. //
  45. // convolution kernel:
  46. //
  47. // +----+----+----+
  48. // | | 3A | |
  49. // +----+----+----+
  50. // | 3L | 4C | 3R |
  51. // +----+----+----+
  52. // | | 3B | |
  53. // +----+----+----+
  54.  
  55. // 4 * Pxl(x,y)
  56. // current pixel (4C)
  57. pix = src[0];
  58. pix <<= 2;
  59. sum += pix;
  60.  
  61. // 3 * Pxl(x-1,y)
  62. // pixel to the left (3L)
  63. pix = src[-1];
  64. pix *= 3;
  65. sum += pix;
  66.  
  67. // 3 * Pxl(x+1,y)
  68. // pixel to the right (3R)
  69. pix = src[1];
  70. pix *= 3;
  71. sum += pix;
  72.  
  73. // 3 * Pxl(x,y+1)
  74. // pixel below (3B)
  75. pix = src[stride];
  76. pix *= 3;
  77. sum += pix;
  78.  
  79. // 3 * Pxl(x,y-1)
  80. // pixel above (3A)
  81. pix = src[-stride];
  82. pix *= 3;
  83. sum += pix;
  84.  
  85. // / 16
  86. sum >>= 4;
  87.  
  88. dst[0] = sum;
  89. }
  90.  
  91. void
  92. WaveGetPixel_3(byte *dst,const byte *src,u32 stride)
  93. {
  94.  
  95. // do red
  96. WaveGetPixel_1(dst++,src++,stride);
  97.  
  98. // do green
  99. WaveGetPixel_1(dst++,src++,stride);
  100.  
  101. // do blue
  102. WaveGetPixel_1(dst++,src++,stride);
  103. }
  104.  
Advertisement
Add Comment
Please, Sign In to add comment