Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define ARRLEN 1228800
- #define uchar unsigned char
- #define uint unsigned int
- #define MIN(a, b) ((a) < (b) ? (a) : (b))
- #define MAX(a, b) ((a) > (b) ? (a) : (b))
- #define BLEND(dst, src, i, op) \
- (dst)[(i)] = op(dst, src, (i), (src)[(i)+3], (dst)[(i)+3]); \
- (dst)[(i)+1] = op(dst, src, (i)+1, (src)[(i)+3], (dst)[(i)+3]); \
- (dst)[(i)+2] = op(dst, src, (i)+2, (src)[(i)+3], (dst)[(i)+3]); \
- (dst)[(i)+3] = MULTIPLY_A(dst, src, (i)+3)
- #define MULTIPLY_A(dst, src, i) (((dst)[i] * (src)[i]) >> 8)
- #define MULTIPLY(dst, src, i, sa, da) (((((da)*(dst)[i]) >> 8) * (((sa)*(src)[i]) >> 8)) >> 8)
- #define OVER(dst, src, i, sa, da) (( ((sa) * (src)[i]) >> 8 ) + ( ((255-(sa)) * ((da) * (dst)[i])) >> 16 ))
- #define SCREEN(dst, src, i, sa, da) ( 255 - ( ( (255-( ((sa)*(src)[i]) >> 8 )) * (255-( ((da)*(dst)[i]) >> 8 )) ) >> 8 ) );
- #define LIGHTEN(dst, src, i, sa, da) MAX( (sa)*(src)[i], (da)*(dst)[i] )
- #define DARKEN(dst, src, i, sa, da) MIN( (sa)*(src)[i], (da)*(dst)[i] )
- void multiply(uchar *dst, const uchar *src, uint len)
- {
- uint i;
- for (i = 0; i<len; i+=4) {
- BLEND(dst, src, i, MULTIPLY);
- }
- }
- void over(uchar *dst, const uchar *src, uint len)
- {
- uint i;
- for (i = 0; i<len; i+=4) {
- BLEND(dst, src, i, OVER);
- }
- }
- void screen(uchar *dst, const uchar *src, uint len)
- {
- uint i;
- for (i = 0; i<len; i+=4) {
- BLEND(dst, src, i, SCREEN);
- }
- }
- void darken(uchar *dst, const uchar *src, uint len)
- {
- uint i;
- for (i = 0; i<len; i+=4) {
- BLEND(dst, src, i, DARKEN);
- }
- }
- void lighten(uchar *dst, const uchar *src, uint len)
- {
- uint i;
- for (i = 0; i<len; i+=4) {
- BLEND(dst, src, i, LIGHTEN);
- }
- }
- int main(int argc, char** argv)
- {
- uchar a1[ARRLEN], a2[ARRLEN];
- uint i;
- fread(a1, 1, ARRLEN, stdin);
- fread(a2, 1, ARRLEN, stdin);
- for (i=0; i<20; i++) {
- multiply(a1, a2, ARRLEN);
- over(a1, a2, ARRLEN);
- lighten(a1, a2, ARRLEN);
- screen(a1, a2, ARRLEN);
- darken(a1, a2, ARRLEN);
- }
- fwrite(a1, 1, ARRLEN, stdout);
- return 0;
- }
Add Comment
Please, Sign In to add comment