aboutsummaryrefslogtreecommitdiff
path: root/pgm.ino
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-03-23 18:09:32 +0100
committerJulian T <julian@jtle.dk>2020-03-23 18:09:32 +0100
commit7641384c1fc9827ac012caa6481ffd35b4369e47 (patch)
tree17ed94a78d77ceb0007433e67129b3ba7535422f /pgm.ino
parent83b552b622da561de047f798e5d50d59f724b1eb (diff)
Runs on arduino, output not testetarduino
Diffstat (limited to 'pgm.ino')
-rw-r--r--pgm.ino62
1 files changed, 62 insertions, 0 deletions
diff --git a/pgm.ino b/pgm.ino
new file mode 100644
index 0000000..eb0c101
--- /dev/null
+++ b/pgm.ino
@@ -0,0 +1,62 @@
+#include "pgm.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define COLOR_MAX 255
+
+int pgm_write_header(FILE *fp, unsigned int w, unsigned int h)
+{
+ return fprintf(fp, "P3\n%d %d\n%d\n", w, h, COLOR_MAX);
+}
+
+int pgm_write_pixel(FILE *fp, color_t *c)
+{
+ return fprintf(fp, "%.0lf %.0lf %.0lf\n", c->r * COLOR_MAX, c->g * COLOR_MAX, c->b * COLOR_MAX);
+}
+
+color_t *color_set(color_t *c, COORD_T r, COORD_T g, COORD_T b)
+{
+ c->r = r;
+ c->g = g;
+ c->b = b;
+
+ return c;
+}
+
+color_t *color_add(color_t *dest, color_t *a, color_t *b)
+{
+ COORD_T tmp = a->r + b->r;
+ dest->r = tmp > 1 ? 1 : tmp;
+
+ tmp = a->g + b->g;
+ dest->g = tmp > 1 ? 1 : tmp;
+
+ tmp = a->b + b->b;
+ dest->b = tmp > 1 ? 1 : tmp;
+
+ return dest;
+}
+
+color_t *color_scale(color_t *dest, color_t *a, COORD_T b)
+{
+ COORD_T tmp = a->r * b;
+ dest->r = tmp > 1 ? 1 : tmp;
+
+ tmp = a->g * b;
+ dest->g = tmp > 1 ? 1 : tmp;
+
+ tmp = a->b * b;
+ dest->b = tmp > 1 ? 1 : tmp;
+
+ return dest;
+}
+
+color_t *color_scale_vector(color_t *dest, color_t *a, vector_t *v)
+{
+ dest->r = a->r * v->x;
+ dest->g = a->g * v->y;
+ dest->b = a->b * v->z;
+
+ return dest;
+}