summaryrefslogtreecommitdiff
path: root/src/modules/snow
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2019-11-14 23:06:52 -0800
committerVito Caputo <vcaputo@pengaru.com>2019-11-14 23:06:52 -0800
commit350f89859501fbe759634e77733ecba2c97fd06d (patch)
treeca03bff696e25b3c437590b2de107c4698ce0721 /src/modules/snow
parentc3c3f2d9098911bc76694aa90f182d6bd5050eb3 (diff)
snow: add a simple tv snow / white noise module
I wanted to add some noise to the rtv module and figured why not just add a snow module and make rtv pass through it briefly when switching modules. It's not interesting by itself, but as more composite/meta modules like rtv get made it might be handy beyond rtv.
Diffstat (limited to 'src/modules/snow')
-rw-r--r--src/modules/snow/Makefile.am3
-rw-r--r--src/modules/snow/snow.c51
2 files changed, 54 insertions, 0 deletions
diff --git a/src/modules/snow/Makefile.am b/src/modules/snow/Makefile.am
new file mode 100644
index 0000000..73f767d
--- /dev/null
+++ b/src/modules/snow/Makefile.am
@@ -0,0 +1,3 @@
+noinst_LIBRARIES = libsnow.a
+libsnow_a_SOURCES = snow.c
+libsnow_a_CPPFLAGS = -I@top_srcdir@/src
diff --git a/src/modules/snow/snow.c b/src/modules/snow/snow.c
new file mode 100644
index 0000000..f3c20d5
--- /dev/null
+++ b/src/modules/snow/snow.c
@@ -0,0 +1,51 @@
+#include <stdint.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include "fb.h"
+#include "rototiller.h"
+
+/* Copyright (C) 2019 - Vito Caputo <vcaputo@pengaru.com> */
+
+/* This implements white noise / snow just using rand() */
+
+/* To avoid the contention around rand() I'm just using rand_r()
+ * in an entirely racy fashion with a single seed from the threaded
+ * render_fragment(). It should really be per-cpu but the module
+ * api doesn't currently send down a cpu identifier to the render
+ * function, so TODO in the future add that.
+ */
+static int snow_seed;
+
+static int snow_fragmenter(void *context, const fb_fragment_t *fragment, unsigned num, fb_fragment_t *res_fragment)
+{
+ return fb_fragment_slice_single(fragment, 32, num, res_fragment);
+}
+
+
+static void snow_prepare_frame(void *context, unsigned n_cpus, fb_fragment_t *fragment, rototiller_fragmenter_t *res_fragmenter)
+{
+ *res_fragmenter = snow_fragmenter;
+}
+
+
+static void snow_render_fragment(void *context, fb_fragment_t *fragment)
+{
+ for (unsigned y = fragment->y; y < fragment->y + fragment->height; y++) {
+ for (unsigned x = fragment->x; x < fragment->x + fragment->width; x++) {
+ uint32_t pixel = rand_r(&snow_seed) % 256;
+
+ fb_fragment_put_pixel_unchecked(fragment, x, y, pixel << 16 | pixel << 8 | pixel);
+ }
+ }
+}
+
+
+rototiller_module_t snow_module = {
+ .prepare_frame = snow_prepare_frame,
+ .render_fragment = snow_render_fragment,
+ .name = "snow",
+ .description = "TV snow / white noise",
+ .author = "Vito Caputo <vcaputo@pengaru.com>",
+ .license = "GPLv2",
+};
© All Rights Reserved