From 3c5746e990016ad5eeb752b23861a2405b132219 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Fri, 30 Dec 2016 12:13:40 +1000 Subject: [PATCH] * merge sample.h to simdb.h * refactor simdb_sample() -> simdb_record_create() --- src/sample.c | 20 +++++++++----------- src/sample.h | 7 ------- src/simdb-write.c | 3 +-- src/simdb.h | 7 +++++++ 4 files changed, 17 insertions(+), 20 deletions(-) delete mode 100644 src/sample.h diff --git a/src/sample.c b/src/sample.c index ff8dfc6..c9e20a5 100644 --- a/src/sample.c +++ b/src/sample.c @@ -2,23 +2,18 @@ #include "bitmap.h" #include "simdb.h" #include "record.h" -#include "sample.h" #include -int -simdb_sample(simdb_rec_t * const rec, - const char * const source) -{ +bool +simdb_record_create(simdb_rec_t * const rec, const char * const source) { MagickWand *wand = NULL; MagickPassFail status = MagickPass; - ExceptionType severity = 0; uint16_t w = 0, h = 0; - char *description = NULL; size_t buf_size = 64 * sizeof(char); unsigned char *buf = NULL; - InitializeMagick("/"); /* FIXME */ + InitializeMagick("/"); wand = NewMagickWand(); if (status == MagickPass) status = MagickReadImage(wand, source); @@ -34,7 +29,7 @@ simdb_sample(simdb_rec_t * const rec, if (status == MagickPass) status = MagickSampleImage(wand, 160, 160); - /* TODO: color maps */ + /** TODO: color maps */ /* 2 -> 256 : number of colors */ /* 4 -> 0 : treedepth -> auto */ @@ -91,13 +86,16 @@ simdb_sample(simdb_rec_t * const rec, urec.image_h = h; memcpy(urec.bitmap, buf, SIMDB_BITMAP_SIZE); memcpy(rec->data, &urec, sizeof(rec->data)); +#ifdef DEBUG } else { - description = MagickGetException(wand, &severity); + ExceptionType severity = 0; + char *description = MagickGetException(wand, &severity); fprintf(stderr, "%03d %.1024s\n", severity, description); +#endif } DestroyMagickWand(wand); DestroyMagick(); - return (status == MagickPass) ? 0 : -1; + return (status == MagickPass) ? true : false; } diff --git a/src/sample.h b/src/sample.h deleted file mode 100644 index 3078b20..0000000 --- a/src/sample.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef HAS_SAMPLER_H -#define HAS_SAMPLER_H 1 - -int -simdb_sample(simdb_rec_t * const rec, const char * const source); - -#endif /* HAS_SAMPLER_H */ diff --git a/src/simdb-write.c b/src/simdb-write.c index 5bade4b..7c14de9 100644 --- a/src/simdb-write.c +++ b/src/simdb-write.c @@ -1,7 +1,6 @@ #include "common.h" #include "bitmap.h" #include "simdb.h" -#include "sample.h" #include @@ -82,7 +81,7 @@ int main(int argc, char **argv) case add : if (rec.num == 0 || sample == NULL) usage(EXIT_FAILURE); - if (simdb_sample(&rec, sample) != 0) { + if (simdb_record_create(&rec, sample) != 0) { fprintf(stderr, "sampler failure\n"); exit(EXIT_FAILURE); } diff --git a/src/simdb.h b/src/simdb.h index 72a7dee..63cf57f 100644 --- a/src/simdb.h +++ b/src/simdb.h @@ -142,6 +142,13 @@ int simdb_record_read(simdb_t *db, simdb_rec_t *rec); */ int simdb_record_write(simdb_t *db, simdb_rec_t *rec); +/** + * @brief Create record from image file + * @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); + /** * @brief Read continious records block from database * @param db Database handle