# HG changeset patch # User John Tsiombikas # Date 1405646724 -10800 # Node ID c3b48cb2797f0f15cada0cef57a679f41e87b5ad # Parent e9ab4861536d11c0c38b722d8c85fe04a8c9964a forgot to add the new files diff -r e9ab4861536d -r c3b48cb2797f src/fblur.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fblur.cc Fri Jul 18 04:25:24 2014 +0300 @@ -0,0 +1,120 @@ +#include +#include +#include "fblur.h" + +#if defined(__i386__) || defined(__ia64__) || defined(WIN32) || \ + (defined(__alpha__) || defined(__alpha)) || \ + defined(__arm__) || \ + (defined(__mips__) && defined(__MIPSEL__)) || \ + defined(__SYMBIAN32__) || \ + defined(__x86_64__) || \ + defined(__LITTLE_ENDIAN__) +#define FBLUR_LITTLE_ENDIAN +#else +#define FBLUR_BIG_ENDIAN +#endif + +/* some color packing/unpacking macros */ +#ifdef FBLUR_BIG_ENDIAN +#define RSHIFT 24 +#define GSHIFT 16 +#define BSHIFT 8 +#else /* little endian */ +#define RSHIFT 0 +#define GSHIFT 8 +#define BSHIFT 16 +#endif + +#define RED(p) (((p) >> RSHIFT) & 0xff) +#define GREEN(p) (((p) >> GSHIFT) & 0xff) +#define BLUE(p) (((p) >> BSHIFT) & 0xff) +#define RGB(r, g, b) \ + ((((r) & 0xff) << RSHIFT) | \ + (((g) & 0xff) << GSHIFT) | \ + (((b) & 0xff) << BSHIFT)) + +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define MAX(a, b) ((a) > (b) ? (a) : (b)) + + +void fast_blur(int dir, int amount, uint32_t *buf, int x, int y) +{ + int i, j, half; + uint32_t *dptr, *sptr, *tmp_buf; + + int blur_len = dir == BLUR_HORIZ ? x : y; + int blur_times = dir == BLUR_HORIZ ? y : x; + + if(amount <= 1) return; + + dptr = buf; + half = amount / 2; + + tmp_buf = (uint32_t*)alloca(blur_len * sizeof(uint32_t)); + + for(i=0; i half) { + uint32_t out = *(sptr - half - 1); + ar -= RED(out); + ag -= GREEN(out); + ab -= BLUE(out); + divisor--; + } + + if(j < blur_len - half) { + uint32_t in = *(sptr + half); + ar += RED(in); + ag += GREEN(in); + ab += BLUE(in); + divisor++; + } + + r = ar / divisor; + g = ag / divisor; + b = ab / divisor; + + r = MAX(MIN(r, 255), 0); + g = MAX(MIN(g, 255), 0); + b = MAX(MIN(b, 255), 0); + + *dptr = RGB(r, g, b); + dptr += dir == BLUR_HORIZ ? 1 : x; + sptr++; + } + + } + + if(dir == BLUR_BOTH) { + fast_blur(BLUR_HORIZ, amount, buf, x, y); + } +} diff -r e9ab4861536d -r c3b48cb2797f src/fblur.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/fblur.h Fri Jul 18 04:25:24 2014 +0300 @@ -0,0 +1,14 @@ +#ifndef FBLUR_H_ +#define FBLUR_H_ + +#include + +enum { + BLUR_BOTH, /* blur in X and Y */ + BLUR_HORIZ, /* blur in X */ + BLUR_VERT /* blur in Y */ +}; + +void fast_blur(int dir, int amount, uint32_t *buf, int x, int y); + +#endif /* FBLUR_H_ */