aboutsummaryrefslogtreecommitdiff
path: root/km-draw.c
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2019-02-03 04:54:10 -0500
committerPaul Duncan <pabs@pablotron.org>2019-02-03 04:54:10 -0500
commit1e3dc2401263a436a32377e207352ffbe6984e8f (patch)
treefc34de6b8d7a456d861d7534360073ad10d8c620 /km-draw.c
parenta3792d8769d2dc8ee0abae758c6fae3a35b5dfbc (diff)
downloadkmeans-1e3dc2401263a436a32377e207352ffbe6984e8f.tar.bz2
kmeans-1e3dc2401263a436a32377e207352ffbe6984e8f.zip
add outstanding changes
Diffstat (limited to 'km-draw.c')
-rw-r--r--km-draw.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/km-draw.c b/km-draw.c
new file mode 100644
index 0000000..7f59df3
--- /dev/null
+++ b/km-draw.c
@@ -0,0 +1,30 @@
+#include <stdint.h> // size_t
+#include "util.h"
+#include "km.h"
+
+void
+km_set_draw(
+ const km_set_t * const set,
+ uint8_t * const rgb,
+ const size_t width,
+ const size_t height,
+ const uint32_t color
+) {
+ for (size_t i = 0; i < set->num_rows; i++) {
+ const float *row = km_set_get_row(set, i);
+ const size_t x = (width - 1) * row[0],
+ y = (height - 1) * row[1],
+ ofs = 3 * (width * y + x);
+
+ if (x >= width || y >= height) {
+ die(
+ "km_set_draw(): point out of bounds (row: %zu, point: [%0.2f, %0.2f], pixel: %zux%zu, bounds: %zux%zu)",
+ i, row[0], row[1], x, y, width, height
+ );
+ }
+
+ rgb[ofs + 0] = (color & 0xff0000) >> 16;
+ rgb[ofs + 1] = (color & 0x00ff00) >> 8;
+ rgb[ofs + 2] = (color & 0x0000ff);
+ }
+}