From f766b1e8f3f5b7d1726739499a5451559a18150a Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Mon, 9 Jan 2017 18:00:45 +1000 Subject: [PATCH] * use simdb_write() instead simdb_record_write() --- src/samplers/dummy.c | 3 ++- src/samplers/magick.c | 17 ++++++++--------- src/simdb-write.c | 18 ++++++++++-------- src/simdb.h | 2 +- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/samplers/dummy.c b/src/samplers/dummy.c index d60af77..bfc8488 100644 --- a/src/samplers/dummy.c +++ b/src/samplers/dummy.c @@ -1,8 +1,9 @@ #include "../common.h" +#include "../record.h" #include "../simdb.h" bool -simdb_record_create(simdb_rec_t * const rec, const char * const source) { +simdb_record_create(void *rec, const char * const source) { assert(rec != NULL); assert(source != NULL); diff --git a/src/samplers/magick.c b/src/samplers/magick.c index 379b7a5..83c1c89 100644 --- a/src/samplers/magick.c +++ b/src/samplers/magick.c @@ -1,17 +1,18 @@ #include "../common.h" #include "../bitmap.h" -#include "../simdb.h" #include "../record.h" +#include "../simdb.h" #include bool -simdb_record_create(simdb_rec_t * const rec, const char * const source) { +simdb_record_create(void * r, const char * const source) { MagickWand *wand = NULL; MagickPassFail status = MagickPass; uint16_t w = 0, h = 0; size_t buf_size = 64 * sizeof(char); unsigned char *buf = NULL; + simdb_urec_t *rec = r; assert(rec != NULL); assert(source != NULL); @@ -81,14 +82,12 @@ simdb_record_create(simdb_rec_t * const rec, const char * const source) { #endif if (status == MagickPass) { - simdb_urec_t urec; assert(buf_size == SIMDB_BITMAP_SIZE); - memset(&urec, 0x0, sizeof(urec)); - urec.used = 0xFF; - urec.image_w = w; - urec.image_h = h; - memcpy(urec.bitmap, buf, SIMDB_BITMAP_SIZE); - memcpy(rec->data, &urec, sizeof(rec->data)); + memset(rec, 0x0, sizeof(simdb_urec_t)); + rec->used = 0xFF; + rec->image_w = w; + rec->image_h = h; + memcpy(rec->bitmap, buf, SIMDB_BITMAP_SIZE); #ifdef DEBUG } else { ExceptionType severity = 0; diff --git a/src/simdb-write.c b/src/simdb-write.c index fd34835..fb3d3a5 100644 --- a/src/simdb-write.c +++ b/src/simdb-write.c @@ -1,5 +1,7 @@ #include "common.h" #include "bitmap.h" +#include "record.h" +#include "io.h" #include "simdb.h" #include @@ -25,10 +27,10 @@ int main(int argc, char **argv) const char *sample = NULL; const char *c = NULL; simdb_t *db = NULL; - simdb_rec_t rec; - int err; + simdb_urec_t rec; + int num = 0, err = 0; - memset(&rec, 0x0, sizeof(simdb_rec_t)); + memset(&rec, 0x0, sizeof(simdb_urec_t)); if (argc < 3) usage(EXIT_FAILURE); @@ -45,12 +47,12 @@ int main(int argc, char **argv) mode = add; if ((c = strchr(optarg, ',')) == NULL) usage(EXIT_FAILURE); - rec.num = atoll(optarg); + num = atoll(optarg); sample = c + 1; break; case 'D' : mode = del; - rec.num = atoll(optarg); + num = atoll(optarg); break; case 'I' : mode = init; @@ -79,19 +81,19 @@ int main(int argc, char **argv) switch (mode) { case add : - if (rec.num == 0 || sample == NULL) + if (num == 0 || sample == NULL) usage(EXIT_FAILURE); if (!simdb_record_create(&rec, sample)) { fprintf(stderr, "sampler failure\n"); exit(EXIT_FAILURE); } - if ((err = simdb_record_write(db, &rec)) < 1) { + if ((err = simdb_write(db, num, 1, (void *) &rec)) < 1) { fprintf(stderr, "%s\n", simdb_error(err)); exit(EXIT_FAILURE); } break; case del : - if ((err = simdb_record_write(db, &rec)) < 1) { + if ((err = simdb_write(db, num, 1, (void *) &rec)) < 1) { fprintf(stderr, "%s\n", simdb_error(err)); exit(EXIT_FAILURE); } diff --git a/src/simdb.h b/src/simdb.h index f55f2ae..214a09f 100644 --- a/src/simdb.h +++ b/src/simdb.h @@ -136,7 +136,7 @@ int simdb_record_write(simdb_t *db, simdb_rec_t *rec); * @param path Path to source image * @returns Pointer to newly created record or NULL on error */ -bool simdb_record_create(simdb_rec_t * const rec, const char *path); +bool simdb_record_create(void * rec, const char *path); /** * @brief Get database capacity