From 90fde2df2d8c59b0b885e6e02b5e89dbe966a5e9 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 3 Feb 2017 15:43:51 -0800 Subject: sparkler: use fb.h put_pixel helpers discards draw_pixel(), introduces helpers.h and a convenience function for bounds checking and oob extermination. Move makergb to helpers.h, draw.h gets removed in a later commit. --- src/modules/sparkler/helpers.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/modules/sparkler/helpers.h (limited to 'src/modules/sparkler/helpers.h') diff --git a/src/modules/sparkler/helpers.h b/src/modules/sparkler/helpers.h new file mode 100644 index 0000000..e263d36 --- /dev/null +++ b/src/modules/sparkler/helpers.h @@ -0,0 +1,36 @@ +#ifndef _HELPERS_H +#define _HELPERS_H + +#include + +#include "fb.h" +#include "particle.h" +#include "particles.h" + + +/* helper for scaling rgb colors and packing them into an pixel */ +static inline uint32_t makergb(uint32_t r, uint32_t g, uint32_t b, float intensity) +{ + r = (((float)intensity) * r); + g = (((float)intensity) * g); + b = (((float)intensity) * b); + + return (((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)); +} + + +/* return if the particle should be drawn, and set *longevity to 0 if out of bounds */ +static inline int should_draw_expire_if_oob(particles_t *particles, particle_t *p, int x, int y, fb_fragment_t *f, int *longevity) +{ + if (!fb_fragment_contains(f, x, y)) { + /* offscreen */ + if (longevity) + *longevity = 0; + + return 0; + } + + return 1; +} + +#endif -- cgit v1.2.1