diff options
author | Vito Caputo <vcaputo@gnugeneration.com> | 2017-01-09 00:53:57 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-09 00:53:57 -0800 |
commit | 6e284f6cfda2b436e7871d34367c3478aa211942 (patch) | |
tree | c84a80e4252291882dc0dc972dd1e42f222a2ede /modules/stars/draw.h | |
parent | bc0ea63460100f61e6c6b73abe20c1f4ffae5db4 (diff) | |
parent | c8b77543492c56b747394e2a460074febeaaeab5 (diff) |
Merge pull request #4 from ph1l/stars
stars: add starfield simulator from ph1l/stars
Diffstat (limited to 'modules/stars/draw.h')
-rw-r--r-- | modules/stars/draw.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/modules/stars/draw.h b/modules/stars/draw.h new file mode 100644 index 0000000..58a4a36 --- /dev/null +++ b/modules/stars/draw.h @@ -0,0 +1,32 @@ +#ifndef _DRAW_H +#define _DRAW_H + +#include <stdint.h> + +#include "fb.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)); +} + +static inline int draw_pixel(fb_fragment_t *f, int x, int y, uint32_t pixel) +{ + uint32_t *pixels = f->buf; + + if (y < 0 || y >= f->height || x < 0 || x >= f->width) { + return 0; + } + + /* FIXME this assumes stride is aligned to 4 */ + pixels[(y * f->width + (f->stride >> 2)) + x] = pixel; + + return 1; +} + +#endif |