From 13f4229ee540e22a5f3ede4d345ae1269cd708d3 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Fri, 9 Feb 2018 03:03:47 +0200 Subject: [PATCH] adding fast blur function --- src/fract.c | 3 --- src/gfxutil.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/gfxutil.h | 9 ++++++++- src/greets.c | 10 +++++++--- 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/fract.c b/src/fract.c index a17550b..e082620 100644 --- a/src/fract.c +++ b/src/fract.c @@ -43,9 +43,6 @@ static void destroy(void) { } -#define PACK_RGB16(r, g, b) \ - (((((r) >> 3) & 0x1f) << 11) | ((((g) >> 2) & 0x3f) << 5) | (((b) >> 3) & 0x1f)) - static void draw(void) { int i, j; diff --git a/src/gfxutil.c b/src/gfxutil.c index 0257f79..811915e 100644 --- a/src/gfxutil.c +++ b/src/gfxutil.c @@ -142,3 +142,47 @@ void draw_line(int x0, int y0, int x1, int y1, unsigned short color) } } } + + +/* TODO bound blur rad to image size to avoid inner loop conditionals */ +/* TODO make version with pow2 (rad*2+1) to avoid div with count everywhere */ +void blur_grey_horiz(uint16_t *dest, uint16_t *src, int xsz, int ysz, int rad) +{ + int i, j; + + for(i=0; i> 3) & 0x1f) << 11) | ((((g) >> 2) & 0x3f) << 5) | (((b) >> 3) & 0x1f)) + (((((uint16_t)(r) >> 3) & 0x1f) << 11) | \ + ((((uint16_t)(g) >> 2) & 0x3f) << 5) | \ + (((uint16_t)(b) >> 3) & 0x1f)) #define UNPACK_R16(c) (((c) >> 8) & 0xf8) #define UNPACK_G16(c) (((c) >> 3) & 0xfc) @@ -14,4 +18,7 @@ int clip_line(int *x0, int *y0, int *x1, int *y1, int xmin, int ymin, int xmax, int ymax); void draw_line(int x0, int y0, int x1, int y1, unsigned short color); +void blur_grey_horiz(uint16_t *dest, uint16_t *src, int xsz, int ysz, int radius); +void blur_grey_vert(uint16_t *dest, uint16_t *src, int xsz, int ysz, int radius); + #endif /* GFXUTIL_H_ */ diff --git a/src/greets.c b/src/greets.c index 0876b60..9fa14df 100644 --- a/src/greets.c +++ b/src/greets.c @@ -30,7 +30,7 @@ struct vec3 { struct particle { float x, y, z; float vx, vy, vz; /* velocity */ - float r, g, b; + int r, g, b; float life; }; @@ -203,7 +203,9 @@ int init_emitter(struct emitter *em, int num, unsigned char *map, int xsz, int y p->x = (float)x / (float)xsz - 0.5; p->y = -(float)y / (float)xsz + 0.5 / aspect; p->z = ((float)i / (float)num * 2.0 - 1.0) * 0.005; - p->r = p->g = p->b = 0.9; + p->r = 0; + p->g = 0x1f; + p->b = 255; p->vx = p->vy = p->vz = 0.0f; p->life = MAX_LIFE; ++p; @@ -233,7 +235,9 @@ void update_particles(struct emitter *em, float dt) v->y = p->y; v->z = p->z; v->w = 1.0f; - v->r = v->g = v->b = 200; + v->r = p->r; + v->g = p->g; + v->b = p->b; v->a = cround64(p->life * 255.0 / MAX_LIFE); ++v; -- 1.7.10.4