Browse Source

* merge sample.h to simdb.h

* refactor simdb_sample() -> simdb_record_create()
master
Alex 'AdUser' Z 8 years ago
parent
commit
3c5746e990
  1. 20
      src/sample.c
  2. 7
      src/sample.h
  3. 3
      src/simdb-write.c
  4. 7
      src/simdb.h

20
src/sample.c

@ -2,23 +2,18 @@
#include "bitmap.h" #include "bitmap.h"
#include "simdb.h" #include "simdb.h"
#include "record.h" #include "record.h"
#include "sample.h"
#include <wand/magick_wand.h> #include <wand/magick_wand.h>
int bool
simdb_sample(simdb_rec_t * const rec, simdb_record_create(simdb_rec_t * const rec, const char * const source) {
const char * const source)
{
MagickWand *wand = NULL; MagickWand *wand = NULL;
MagickPassFail status = MagickPass; MagickPassFail status = MagickPass;
ExceptionType severity = 0;
uint16_t w = 0, h = 0; uint16_t w = 0, h = 0;
char *description = NULL;
size_t buf_size = 64 * sizeof(char); size_t buf_size = 64 * sizeof(char);
unsigned char *buf = NULL; unsigned char *buf = NULL;
InitializeMagick("/"); /* FIXME */ InitializeMagick("/");
wand = NewMagickWand(); wand = NewMagickWand();
if (status == MagickPass) if (status == MagickPass)
status = MagickReadImage(wand, source); status = MagickReadImage(wand, source);
@ -34,7 +29,7 @@ simdb_sample(simdb_rec_t * const rec,
if (status == MagickPass) if (status == MagickPass)
status = MagickSampleImage(wand, 160, 160); status = MagickSampleImage(wand, 160, 160);
/* TODO: color maps */ /** TODO: color maps */
/* 2 -> 256 : number of colors */ /* 2 -> 256 : number of colors */
/* 4 -> 0 : treedepth -> auto */ /* 4 -> 0 : treedepth -> auto */
@ -91,13 +86,16 @@ simdb_sample(simdb_rec_t * const rec,
urec.image_h = h; urec.image_h = h;
memcpy(urec.bitmap, buf, SIMDB_BITMAP_SIZE); memcpy(urec.bitmap, buf, SIMDB_BITMAP_SIZE);
memcpy(rec->data, &urec, sizeof(rec->data)); memcpy(rec->data, &urec, sizeof(rec->data));
#ifdef DEBUG
} else { } else {
description = MagickGetException(wand, &severity); ExceptionType severity = 0;
char *description = MagickGetException(wand, &severity);
fprintf(stderr, "%03d %.1024s\n", severity, description); fprintf(stderr, "%03d %.1024s\n", severity, description);
#endif
} }
DestroyMagickWand(wand); DestroyMagickWand(wand);
DestroyMagick(); DestroyMagick();
return (status == MagickPass) ? 0 : -1; return (status == MagickPass) ? true : false;
} }

7
src/sample.h

@ -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 */

3
src/simdb-write.c

@ -1,7 +1,6 @@
#include "common.h" #include "common.h"
#include "bitmap.h" #include "bitmap.h"
#include "simdb.h" #include "simdb.h"
#include "sample.h"
#include <getopt.h> #include <getopt.h>
@ -82,7 +81,7 @@ int main(int argc, char **argv)
case add : case add :
if (rec.num == 0 || sample == NULL) if (rec.num == 0 || sample == NULL)
usage(EXIT_FAILURE); usage(EXIT_FAILURE);
if (simdb_sample(&rec, sample) != 0) { if (simdb_record_create(&rec, sample) != 0) {
fprintf(stderr, "sampler failure\n"); fprintf(stderr, "sampler failure\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }

7
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); 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 * @brief Read continious records block from database
* @param db Database handle * @param db Database handle

Loading…
Cancel
Save