aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.gitignore1
-rw-r--r--justfile8
-rw-r--r--setup.sql45
-rw-r--r--src/main.c55
4 files changed, 107 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index e0acd02..9fe3eec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
build/
compile_flags.txt
*.db
+*.ignore.*
diff --git a/justfile b/justfile
index 6c0f728..cb79843 100644
--- a/justfile
+++ b/justfile
@@ -1,6 +1,6 @@
set export
-CC := "gcc"
+CC := "cc"
CFLAGS := f"-std=c11 -O2 \
-Wall -Wextra -Wshadow -Wformat=2 -fsanitize=address,undefined \
{{shell('pkg-config --cflags --libs sqlite3')}}"
@@ -19,3 +19,9 @@ run: build
format:
find src/ -iname '*.h' -o -iname '*.c' | xargs clang-format -i
+setup-db:
+ rm fun.db
+ sqlite3 fun.db < setup.sql
+
+image:
+ just run | magick display -resize 500% -
diff --git a/setup.sql b/setup.sql
new file mode 100644
index 0000000..164e63d
--- /dev/null
+++ b/setup.sql
@@ -0,0 +1,45 @@
+CREATE TABLE pixels (
+ x INTEGER,
+ y INTEGER,
+ r INTEGER,
+ g INTEGER,
+ b INTEGER,
+ UNIQUE(x, y)
+);
+
+INSERT INTO pixels (x, y, r, g, b) VALUES (1, 1, 0, 255, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (2, 1, 0, 255, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (3, 1, 0, 255, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (4, 1, 0, 255, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (5, 1, 0, 255, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (6, 1, 0, 255, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (1, 2, 0, 255, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (2, 2, 0, 255, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (3, 2, 0, 255, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (4, 2, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (5, 2, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (6, 2, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (1, 3, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (2, 3, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (3, 3, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (4, 3, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (5, 3, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (6, 3, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (1, 4, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (2, 4, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (3, 4, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (4, 4, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (5, 4, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (6, 4, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (1, 5, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (2, 5, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (3, 5, 255, 0, 0);
+INSERT INTO pixels (x, y, r, g, b) VALUES (4, 5, 0, 0, 255);
+INSERT INTO pixels (x, y, r, g, b) VALUES (5, 5, 0, 0, 255);
+INSERT INTO pixels (x, y, r, g, b) VALUES (6, 5, 0, 0, 255);
+INSERT INTO pixels (x, y, r, g, b) VALUES (1, 6, 0, 0, 255);
+INSERT INTO pixels (x, y, r, g, b) VALUES (2, 6, 0, 0, 255);
+INSERT INTO pixels (x, y, r, g, b) VALUES (3, 6, 0, 0, 255);
+INSERT INTO pixels (x, y, r, g, b) VALUES (4, 6, 0, 0, 255);
+INSERT INTO pixels (x, y, r, g, b) VALUES (5, 6, 0, 0, 255);
+INSERT INTO pixels (x, y, r, g, b) VALUES (6, 6, 0, 0, 255);
diff --git a/src/main.c b/src/main.c
index 23d6e58..2da78b0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,5 +1,28 @@
#include <sqlite3.h>
#include <stdio.h>
+#include <string.h>
+
+typedef struct {
+ int x;
+ int y;
+ int r;
+ int g;
+ int b;
+} Pixel;
+
+void show_pixels(Pixel *pixels, int len) {
+ for (int i = 0; i < len; i++) {
+ Pixel p = pixels[i];
+ printf("%d %d %d\n", p.r, p.g, p.b);
+ }
+}
+
+void show_image(Pixel *pixels, int len) {
+ printf("P3\n");
+ printf("%d %d\n", 6, 6);
+ printf("%d\n", 255);
+ show_pixels(pixels, len);
+}
int main(void) {
sqlite3 *db;
@@ -10,8 +33,38 @@ int main(void) {
return 1;
}
- printf("Foobar\n");
+ sqlite3_stmt *stmt;
+ sqlite3_prepare_v2(db,
+ "select x, y, r, g, b from pixels ORDER BY y ASC, x ASC",
+ -1, &stmt, NULL);
+
+ Pixel pixels[200 * 200];
+ int index = 0;
+ while (sqlite3_step(stmt) != SQLITE_DONE) {
+ int num_cols = sqlite3_column_count(stmt);
+ Pixel pixel;
+ for (int col = 0; col < num_cols; col++) {
+ const char *name = sqlite3_column_name(stmt, col);
+ if (strcmp(name, "x") == 0)
+ pixel.x = sqlite3_column_int(stmt, col);
+ else if (strcmp(name, "y") == 0)
+ pixel.y = sqlite3_column_int(stmt, col);
+ else if (strcmp(name, "r") == 0)
+ pixel.r = sqlite3_column_int(stmt, col);
+ else if (strcmp(name, "g") == 0)
+ pixel.g = sqlite3_column_int(stmt, col);
+ else if (strcmp(name, "b") == 0)
+ pixel.b = sqlite3_column_int(stmt, col);
+ }
+ pixels[index++] = pixel;
+ }
+ int frames = 1;
+ for (int i = 0; i < frames; i++)
+ show_image(pixels, index);
+
+ sqlite3_finalize(stmt);
sqlite3_close(db);
+
return 0;
}