Guest User

Untitled

a guest
Apr 17th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define ARRLEN 1228800
  4. #define uchar unsigned char
  5. #define uint unsigned int
  6.  
  7. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  8. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  9.  
  10. #define BLEND(dst, src, i, op) \
  11. (dst)[(i)] = op(dst, src, (i), (src)[(i)+3], (dst)[(i)+3]); \
  12. (dst)[(i)+1] = op(dst, src, (i)+1, (src)[(i)+3], (dst)[(i)+3]); \
  13. (dst)[(i)+2] = op(dst, src, (i)+2, (src)[(i)+3], (dst)[(i)+3]); \
  14. (dst)[(i)+3] = MULTIPLY_A(dst, src, (i)+3)
  15.  
  16. #define MULTIPLY_A(dst, src, i) (((dst)[i] * (src)[i]) >> 8)
  17.  
  18. #define MULTIPLY(dst, src, i, sa, da) (((((da)*(dst)[i]) >> 8) * (((sa)*(src)[i]) >> 8)) >> 8)
  19.  
  20. #define OVER(dst, src, i, sa, da) (( ((sa) * (src)[i]) >> 8 ) + ( ((255-(sa)) * ((da) * (dst)[i])) >> 16 ))
  21.  
  22. #define SCREEN(dst, src, i, sa, da) ( 255 - ( ( (255-( ((sa)*(src)[i]) >> 8 )) * (255-( ((da)*(dst)[i]) >> 8 )) ) >> 8 ) );
  23.  
  24. #define LIGHTEN(dst, src, i, sa, da) MAX( (sa)*(src)[i], (da)*(dst)[i] )
  25.  
  26. #define DARKEN(dst, src, i, sa, da) MIN( (sa)*(src)[i], (da)*(dst)[i] )
  27.  
  28. void multiply(uchar *dst, const uchar *src, uint len)
  29. {
  30. uint i;
  31. for (i = 0; i<len; i+=4) {
  32. BLEND(dst, src, i, MULTIPLY);
  33. }
  34. }
  35.  
  36. void over(uchar *dst, const uchar *src, uint len)
  37. {
  38. uint i;
  39. for (i = 0; i<len; i+=4) {
  40. BLEND(dst, src, i, OVER);
  41. }
  42. }
  43.  
  44. void screen(uchar *dst, const uchar *src, uint len)
  45. {
  46. uint i;
  47. for (i = 0; i<len; i+=4) {
  48. BLEND(dst, src, i, SCREEN);
  49. }
  50. }
  51.  
  52. void darken(uchar *dst, const uchar *src, uint len)
  53. {
  54. uint i;
  55. for (i = 0; i<len; i+=4) {
  56. BLEND(dst, src, i, DARKEN);
  57. }
  58. }
  59.  
  60. void lighten(uchar *dst, const uchar *src, uint len)
  61. {
  62. uint i;
  63. for (i = 0; i<len; i+=4) {
  64. BLEND(dst, src, i, LIGHTEN);
  65. }
  66. }
  67.  
  68. int main(int argc, char** argv)
  69. {
  70. uchar a1[ARRLEN], a2[ARRLEN];
  71. uint i;
  72.  
  73. fread(a1, 1, ARRLEN, stdin);
  74. fread(a2, 1, ARRLEN, stdin);
  75.  
  76. for (i=0; i<20; i++) {
  77. multiply(a1, a2, ARRLEN);
  78. over(a1, a2, ARRLEN);
  79. lighten(a1, a2, ARRLEN);
  80. screen(a1, a2, ARRLEN);
  81. darken(a1, a2, ARRLEN);
  82. }
  83.  
  84. fwrite(a1, 1, ARRLEN, stdout);
  85.  
  86. return 0;
  87. }
Add Comment
Please, Sign In to add comment