aboutsummaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
Diffstat (limited to 'data')
-rw-r--r--data/compress.c56
-rw-r--r--data/render.c86
2 files changed, 0 insertions, 142 deletions
diff --git a/data/compress.c b/data/compress.c
deleted file mode 100644
index df61123..0000000
--- a/data/compress.c
+++ /dev/null
@@ -1,56 +0,0 @@
-void salis_deflate(z_stream *strm, size_t size, Bytef *in, Bytef *out) {
- assert(strm);
- assert(size);
- assert(in);
- assert(out);
-
- strm->zalloc = NULL;
- strm->zfree = NULL;
- strm->opaque = NULL;
-
- deflateInit(strm, Z_DEFAULT_COMPRESSION);
-
- strm->avail_in = size;
- strm->avail_out = size;
- strm->next_in = in;
- strm->next_out = out;
-
- deflate(strm, Z_FINISH);
-}
-
-void salis_deflate_end(z_stream *strm) {
- assert(strm);
-
- deflateEnd(strm);
-}
-
-void salis_inflate(z_stream *strm, size_t avail_in, size_t size, Bytef *in, Bytef *out) {
- assert(strm);
- assert(avail_in);
- assert(size);
- assert(in);
- assert(out);
-
- strm->next_in = in;
- strm->avail_in = avail_in;
- strm->zalloc = NULL;
- strm->zfree = NULL;
- strm->opaque = NULL;
-
- inflateInit(strm);
-
- strm->avail_out = size;
- strm->next_out = out;
-
-#if defined(NDEBUG)
- inflate(strm, Z_FINISH);
-#else
- assert(inflate(strm, Z_FINISH));
-#endif
-}
-
-void salis_inflate_end(z_stream *strm) {
- assert(strm);
-
- inflateEnd(strm);
-}
diff --git a/data/render.c b/data/render.c
deleted file mode 100644
index f9da65d..0000000
--- a/data/render.c
+++ /dev/null
@@ -1,86 +0,0 @@
-#include <sqlite3ext.h>
-SQLITE_EXTENSION_INIT1
-
-#include <assert.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <zlib.h>
-
-#include "compress.c"
-
-#define EVA_SIZE (sizeof(uint64_t) * MVEC_SIZE)
-
-void eva_render(sqlite3_context *context, int argc, sqlite3_value **argv) {
- assert(context);
- assert(argc == 4);
- assert(argv);
-
- (void)argc;
-
- size_t left = (size_t)sqlite3_value_int(argv[0]);
-#if defined(MVEC_LOOP)
- left %= MVEC_SIZE;
-#endif
-
- size_t px_count = (size_t)sqlite3_value_int(argv[1]);
- size_t px_pow = (size_t)sqlite3_value_int(argv[2]);
- size_t px_res = 1 << px_pow;
-#if !defined(MVEC_LOOP)
-#if !defined(NDEBUG)
- size_t right = left + px_res * px_count;
-#endif
- assert(left < MVEC_SIZE);
- assert(right <= MVEC_SIZE);
-#endif
-
- const void *blob = sqlite3_value_blob(argv[3]);
- size_t blob_size = (size_t)sqlite3_value_bytes(argv[3]);
-
- // Inflate blob
- size_t out_size = sizeof(uint64_t) * px_count;
- uint64_t *eva = sqlite3_malloc(EVA_SIZE);
- uint64_t *out = sqlite3_malloc(out_size);
- z_stream strm = { 0 };
- salis_inflate(&strm, blob_size, EVA_SIZE, (Bytef *)blob, (Bytef *)eva);
- salis_inflate_end(&strm);
-
- // Render image
- for (size_t i = 0; i < px_count; i++) {
- out[i] = 0;
-
- for (size_t j = 0; j < px_res; j++) {
- size_t in_coord = left + i * px_res + j;
-#if defined(MVEC_LOOP)
- in_coord %= MVEC_SIZE;
-#endif
- out[i] += eva[in_coord];
- }
- }
-
- sqlite3_free(eva);
-
- // Transform rendered image into textual representation
- // A comma-separated list of hexadecimal integers
- char *csv = sqlite3_malloc(px_count * 17 + 1);
- char *ptr = csv;
-
- for (size_t i = 0; i < px_count; i++) {
- ptr += sprintf(ptr, "%lx ", out[i]);
- }
-
- *(--ptr) = '\0';
- sqlite3_free(out);
-
- sqlite3_result_text(context, csv, -1, sqlite3_free);
-}
-
-int sqlite3_render_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi) {
- assert(db);
- assert(pzErrMsg);
- assert(pApi);
-
- (void)pzErrMsg;
-
- SQLITE_EXTENSION_INIT2(pApi);
- return sqlite3_create_function(db, "eva_render", 4, SQLITE_DETERMINISTIC | SQLITE_INNOCUOUS | SQLITE_UTF8, NULL, eva_render, NULL, NULL);
-}