Browse Source

* use simdb_write() instead simdb_record_write()

master
Alex 'AdUser' Z 8 years ago
parent
commit
f766b1e8f3
  1. 3
      src/samplers/dummy.c
  2. 17
      src/samplers/magick.c
  3. 18
      src/simdb-write.c
  4. 2
      src/simdb.h

3
src/samplers/dummy.c

@ -1,8 +1,9 @@
#include "../common.h" #include "../common.h"
#include "../record.h"
#include "../simdb.h" #include "../simdb.h"
bool 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(rec != NULL);
assert(source != NULL); assert(source != NULL);

17
src/samplers/magick.c

@ -1,17 +1,18 @@
#include "../common.h" #include "../common.h"
#include "../bitmap.h" #include "../bitmap.h"
#include "../simdb.h"
#include "../record.h" #include "../record.h"
#include "../simdb.h"
#include <wand/magick_wand.h> #include <wand/magick_wand.h>
bool 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; MagickWand *wand = NULL;
MagickPassFail status = MagickPass; MagickPassFail status = MagickPass;
uint16_t w = 0, h = 0; uint16_t w = 0, h = 0;
size_t buf_size = 64 * sizeof(char); size_t buf_size = 64 * sizeof(char);
unsigned char *buf = NULL; unsigned char *buf = NULL;
simdb_urec_t *rec = r;
assert(rec != NULL); assert(rec != NULL);
assert(source != NULL); assert(source != NULL);
@ -81,14 +82,12 @@ simdb_record_create(simdb_rec_t * const rec, const char * const source) {
#endif #endif
if (status == MagickPass) { if (status == MagickPass) {
simdb_urec_t urec;
assert(buf_size == SIMDB_BITMAP_SIZE); assert(buf_size == SIMDB_BITMAP_SIZE);
memset(&urec, 0x0, sizeof(urec)); memset(rec, 0x0, sizeof(simdb_urec_t));
urec.used = 0xFF; rec->used = 0xFF;
urec.image_w = w; rec->image_w = w;
urec.image_h = h; rec->image_h = h;
memcpy(urec.bitmap, buf, SIMDB_BITMAP_SIZE); memcpy(rec->bitmap, buf, SIMDB_BITMAP_SIZE);
memcpy(rec->data, &urec, sizeof(rec->data));
#ifdef DEBUG #ifdef DEBUG
} else { } else {
ExceptionType severity = 0; ExceptionType severity = 0;

18
src/simdb-write.c

@ -1,5 +1,7 @@
#include "common.h" #include "common.h"
#include "bitmap.h" #include "bitmap.h"
#include "record.h"
#include "io.h"
#include "simdb.h" #include "simdb.h"
#include <getopt.h> #include <getopt.h>
@ -25,10 +27,10 @@ int main(int argc, char **argv)
const char *sample = NULL; const char *sample = NULL;
const char *c = NULL; const char *c = NULL;
simdb_t *db = NULL; simdb_t *db = NULL;
simdb_rec_t rec; simdb_urec_t rec;
int err; int num = 0, err = 0;
memset(&rec, 0x0, sizeof(simdb_rec_t)); memset(&rec, 0x0, sizeof(simdb_urec_t));
if (argc < 3) if (argc < 3)
usage(EXIT_FAILURE); usage(EXIT_FAILURE);
@ -45,12 +47,12 @@ int main(int argc, char **argv)
mode = add; mode = add;
if ((c = strchr(optarg, ',')) == NULL) if ((c = strchr(optarg, ',')) == NULL)
usage(EXIT_FAILURE); usage(EXIT_FAILURE);
rec.num = atoll(optarg); num = atoll(optarg);
sample = c + 1; sample = c + 1;
break; break;
case 'D' : case 'D' :
mode = del; mode = del;
rec.num = atoll(optarg); num = atoll(optarg);
break; break;
case 'I' : case 'I' :
mode = init; mode = init;
@ -79,19 +81,19 @@ int main(int argc, char **argv)
switch (mode) { switch (mode) {
case add : case add :
if (rec.num == 0 || sample == NULL) if (num == 0 || sample == NULL)
usage(EXIT_FAILURE); usage(EXIT_FAILURE);
if (!simdb_record_create(&rec, sample)) { if (!simdb_record_create(&rec, sample)) {
fprintf(stderr, "sampler failure\n"); fprintf(stderr, "sampler failure\n");
exit(EXIT_FAILURE); 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)); fprintf(stderr, "%s\n", simdb_error(err));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
break; break;
case del : 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)); fprintf(stderr, "%s\n", simdb_error(err));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

2
src/simdb.h

@ -136,7 +136,7 @@ int simdb_record_write(simdb_t *db, simdb_rec_t *rec);
* @param path Path to source image * @param path Path to source image
* @returns Pointer to newly created record or NULL on error * @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 * @brief Get database capacity

Loading…
Cancel
Save