eqemu

changeset 8:c3b48cb2797f

forgot to add the new files
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 18 Jul 2014 04:25:24 +0300
parents e9ab4861536d
children fca1f126d23b
files src/fblur.cc src/fblur.h
diffstat 2 files changed, 134 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/fblur.cc	Fri Jul 18 04:25:24 2014 +0300
     1.3 @@ -0,0 +1,120 @@
     1.4 +#include <string.h>
     1.5 +#include <alloca.h>
     1.6 +#include "fblur.h"
     1.7 +
     1.8 +#if  defined(__i386__) || defined(__ia64__) || defined(WIN32) || \
     1.9 +    (defined(__alpha__) || defined(__alpha)) || \
    1.10 +     defined(__arm__) || \
    1.11 +    (defined(__mips__) && defined(__MIPSEL__)) || \
    1.12 +     defined(__SYMBIAN32__) || \
    1.13 +     defined(__x86_64__) || \
    1.14 +     defined(__LITTLE_ENDIAN__)
    1.15 +#define FBLUR_LITTLE_ENDIAN
    1.16 +#else
    1.17 +#define FBLUR_BIG_ENDIAN
    1.18 +#endif
    1.19 +
    1.20 +/* some color packing/unpacking macros */
    1.21 +#ifdef FBLUR_BIG_ENDIAN
    1.22 +#define RSHIFT		24
    1.23 +#define GSHIFT		16
    1.24 +#define BSHIFT		8
    1.25 +#else	/* little endian */
    1.26 +#define RSHIFT		0
    1.27 +#define GSHIFT		8
    1.28 +#define BSHIFT		16
    1.29 +#endif
    1.30 +
    1.31 +#define RED(p)			(((p) >> RSHIFT) & 0xff)
    1.32 +#define GREEN(p)		(((p) >> GSHIFT) & 0xff)
    1.33 +#define BLUE(p)			(((p) >> BSHIFT) & 0xff)
    1.34 +#define RGB(r, g, b)	\
    1.35 +	((((r) & 0xff) << RSHIFT) | \
    1.36 +	 (((g) & 0xff) << GSHIFT) | \
    1.37 +	 (((b) & 0xff) << BSHIFT))
    1.38 +
    1.39 +#define MIN(a, b)	((a) < (b) ? (a) : (b))
    1.40 +#define MAX(a, b)	((a) > (b) ? (a) : (b))
    1.41 +
    1.42 +
    1.43 +void fast_blur(int dir, int amount, uint32_t *buf, int x, int y)
    1.44 +{
    1.45 +	int i, j, half;
    1.46 +	uint32_t *dptr, *sptr, *tmp_buf;
    1.47 +
    1.48 +	int blur_len = dir == BLUR_HORIZ ? x : y;
    1.49 +	int blur_times = dir == BLUR_HORIZ ? y : x;
    1.50 +
    1.51 +	if(amount <= 1) return;
    1.52 +
    1.53 +	dptr = buf;
    1.54 +	half = amount / 2;
    1.55 +
    1.56 +	tmp_buf = (uint32_t*)alloca(blur_len * sizeof(uint32_t));
    1.57 +
    1.58 +	for(i=0; i<blur_times; i++) {
    1.59 +		int ar = 0, ag = 0, ab = 0;
    1.60 +		int divisor = 0;
    1.61 +
    1.62 +		if(dir == BLUR_HORIZ) {
    1.63 +			sptr = tmp_buf;
    1.64 +			memcpy(sptr, dptr, x * sizeof(uint32_t));
    1.65 +		} else {
    1.66 +			dptr = buf + i;
    1.67 +
    1.68 +			sptr = tmp_buf;
    1.69 +			for(j=0; j<y; j++) {
    1.70 +				*sptr++ = *dptr;
    1.71 +				dptr += x;
    1.72 +			}
    1.73 +			dptr = buf + i;
    1.74 +			sptr = tmp_buf;
    1.75 +		}
    1.76 +
    1.77 +
    1.78 +		for(j=0; j<half; j++) {
    1.79 +			uint32_t pixel = tmp_buf[j];
    1.80 +			ar += RED(pixel);
    1.81 +			ag += GREEN(pixel);
    1.82 +			ab += BLUE(pixel);
    1.83 +			divisor++;
    1.84 +		}
    1.85 +
    1.86 +		for(j=0; j<blur_len; j++) {
    1.87 +			int r, g, b;
    1.88 +
    1.89 +			if(j > half) {
    1.90 +				uint32_t out = *(sptr - half - 1);
    1.91 +				ar -= RED(out);
    1.92 +				ag -= GREEN(out);
    1.93 +				ab -= BLUE(out);
    1.94 +				divisor--;
    1.95 +			}
    1.96 +
    1.97 +			if(j < blur_len - half) {
    1.98 +				uint32_t in = *(sptr + half);
    1.99 +				ar += RED(in);
   1.100 +				ag += GREEN(in);
   1.101 +				ab += BLUE(in);
   1.102 +				divisor++;
   1.103 +			}
   1.104 +
   1.105 +			r = ar / divisor;
   1.106 +			g = ag / divisor;
   1.107 +			b = ab / divisor;
   1.108 +
   1.109 +			r = MAX(MIN(r, 255), 0);
   1.110 +			g = MAX(MIN(g, 255), 0);
   1.111 +			b = MAX(MIN(b, 255), 0);
   1.112 +
   1.113 +			*dptr = RGB(r, g, b);
   1.114 +			dptr += dir == BLUR_HORIZ ? 1 : x;
   1.115 +			sptr++;
   1.116 +		}
   1.117 +
   1.118 +	}
   1.119 +
   1.120 +	if(dir == BLUR_BOTH) {
   1.121 +		fast_blur(BLUR_HORIZ, amount, buf, x, y);
   1.122 +	}
   1.123 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/fblur.h	Fri Jul 18 04:25:24 2014 +0300
     2.3 @@ -0,0 +1,14 @@
     2.4 +#ifndef FBLUR_H_
     2.5 +#define FBLUR_H_
     2.6 +
     2.7 +#include <inttypes.h>
     2.8 +
     2.9 +enum {
    2.10 +	BLUR_BOTH,	/* blur in X and Y */
    2.11 +	BLUR_HORIZ,	/* blur in X */
    2.12 +	BLUR_VERT	/* blur in Y */
    2.13 +};
    2.14 +
    2.15 +void fast_blur(int dir, int amount, uint32_t *buf, int x, int y);
    2.16 +
    2.17 +#endif	/* FBLUR_H_ */