From 3ca793491eb72138ca7fd8c48a52903e2a2ba95e Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Thu, 9 Apr 2015 14:53:30 +1000 Subject: [PATCH] * renamed sources --- src/Makefile | 9 +-- src/{imdb_1to2.c => imdb-1to2.c} | 0 src/sample.c | 97 ++++++++++++++++++++++++++++++ src/{sampler.h => sample.h} | 0 src/sampler-test.c | 25 -------- src/sampler.c | 100 +++++-------------------------- 6 files changed, 116 insertions(+), 115 deletions(-) rename src/{imdb_1to2.c => imdb-1to2.c} (100%) create mode 100644 src/sample.c rename src/{sampler.h => sample.h} (100%) delete mode 100644 src/sampler-test.c diff --git a/src/Makefile b/src/Makefile index 930fa97..e83a138 100644 --- a/src/Makefile +++ b/src/Makefile @@ -23,18 +23,19 @@ imdb-query: query.o libimgdup.so imdb-query-st: query.o libimgdup.a gcc $(CFLAGS) $(CPPFLAGS) -L. $^ -o $@ -static -imdb_1to2: imdb_1to2.c +imdb-1to2: imdb-1to2.c gcc $(CFLAGS) $(CPPFLAGS) -o $@ $^ -utils: imdb-query imdb-query-st imdb_1to2 +utils: imdb-query imdb-query-st imdb-sampler imdb-1to2 GMFLAGS=$(shell GraphicsMagickWand-config --cppflags --ldflags --libs) -sampler-test: sampler.c bitmap.c sampler-test.c +imdb-sampler: sampler.c sample.c bitmap.c gcc $(CFLAGS) $(CPPFLAGS) $(GMFLAGS) -o $@ $^ clean: rm -f *.o - rm -f imdb_?to? + rm -f imdb-1to2 rm -f imdb-query rm -f imdb-query-st + rm -f imdb-sampler rm -f libimgdup* diff --git a/src/imdb_1to2.c b/src/imdb-1to2.c similarity index 100% rename from src/imdb_1to2.c rename to src/imdb-1to2.c diff --git a/src/sample.c b/src/sample.c new file mode 100644 index 0000000..2078403 --- /dev/null +++ b/src/sample.c @@ -0,0 +1,97 @@ +#include "common.h" +#include "database.h" +#include "sample.h" + +#include + +int +imdb_sample(imdb_rec_t * const rec, + char * const source) +{ + MagickWand *wand = NULL; + MagickPassFail status = MagickPass; + ExceptionType severity = 0; + unsigned long w = 0, h = 0; + char *description = NULL; + size_t buf_size = 64 * sizeof(char); + unsigned char *buf = NULL; + + InitializeMagick("/"); /* FIXME */ + wand = NewMagickWand(); + if (status == MagickPass) + status = MagickReadImage(wand, source); + + if (status == MagickPass) + w = MagickGetImageHeight(wand); + + if (status == MagickPass) + h = MagickGetImageHeight(wand); + + /* 2 -> 160 : width, "cols" */ + /* 3 -> 160 : width, "rows" */ + if (status == MagickPass) + status = MagickSampleImage(wand, 160, 160); + + /* TODO: color maps */ + + /* 2 -> 256 : number of colors */ + /* 3 -> 0 : treedepth -> auto */ + /* 4 -> 0 : dither -> none */ + /* 5 -> 0 : measure_error -> none */ + if (status == MagickPass) + status = MagickQuantizeImage(wand, 256, GRAYColorspace, 0, 0, 0); + + /* 2 -> 3 : radius, in pixels */ + /* 3 -> 2 : "for reasonable results, radius should be larger than sigma" */ + if (status == MagickPass) + status = MagickBlurImage(wand, 3, 2); + + if (status == MagickPass) + status = MagickNormalizeImage(wand); + + if (status == MagickPass) + status = MagickEqualizeImage(wand); + + /* 2 -> 16 : width, "cols" */ + /* 3 -> 16 : width, "rows" */ + if (status == MagickPass) + status = MagickSampleImage(wand, 16, 16); + + /* 2 -> 50%, tuned by magick number, see 'magick/image.h' */ + if (status == MagickPass) + status = MagickThresholdImage(wand, 50.0 * (MaxRGB / 100)); + + if (status == MagickPass) + status = MagickSetImageType(wand, BilevelType); + + if (status == MagickPass) + status = MagickSetImageFormat(wand, "MONO"); + + if (status == MagickPass) + buf = MagickWriteImageBlob(wand, &buf_size); + +#ifdef DEBUG + fprintf(stderr, "sample H: %lu\n", MagickGetImageWidth(wand)); + fprintf(stderr, "sample W: %lu\n", MagickGetImageWidth(wand)); + fprintf(stderr, "buf size: %u\n", buf_size); + for (unsigned int i = 0; i < buf_size; i++) + fprintf(stderr, "%02X", buf[i]); +#endif + assert(buf_size == 32); + + if (status == MagickPass) { + memset(rec, 0x0, sizeof(imdb_rec_t)); + rec->data[REC_OFF_RU] = 0xFF; + *((uint16_t *) &rec->data[REC_OFF_IW]) = (uint16_t) w; + *((uint16_t *) &rec->data[REC_OFF_IH]) = (uint16_t) h; + memcpy(&rec->data[REC_OFF_BM], buf, 32); + } else { + description = MagickGetException(wand, &severity); + fprintf(stderr, "%03d %.1024s\n", severity, description); /* FIXME */ + } + + DestroyMagickWand(wand); + DestroyMagick(); + + return (status == MagickPass) ? 0 : -1; +} diff --git a/src/sampler.h b/src/sample.h similarity index 100% rename from src/sampler.h rename to src/sample.h diff --git a/src/sampler-test.c b/src/sampler-test.c deleted file mode 100644 index 852e861..0000000 --- a/src/sampler-test.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "common.h" -#include "database.h" -#include "bitmap.h" -#include "sampler.h" - -int main(int argc, char **argv) -{ - imdb_rec_t rec; - - if (argc < 2) { - puts("Usage: sampler-test "); - exit(EXIT_FAILURE); - } - - memset(&rec, 0x0, sizeof(imdb_rec_t)); - - if (imdb_sample(&rec, argv[1]) != 0) { - puts("sampler failure"); - exit(EXIT_FAILURE); - } - - bitmap_print(&rec.data[REC_OFF_BM]); - - exit(EXIT_SUCCESS); -} diff --git a/src/sampler.c b/src/sampler.c index a3b8472..6e025c2 100644 --- a/src/sampler.c +++ b/src/sampler.c @@ -1,97 +1,25 @@ #include "common.h" #include "database.h" -#include "sampler.h" +#include "bitmap.h" +#include "sample.h" -#include - -int -imdb_sample(imdb_rec_t * const rec, - char * const source) +int main(int argc, char **argv) { - MagickWand *wand = NULL; - MagickPassFail status = MagickPass; - ExceptionType severity = 0; - unsigned long w = 0, h = 0; - char *description = NULL; - size_t buf_size = 64 * sizeof(char); - unsigned char *buf = NULL; - - InitializeMagick("/"); /* FIXME */ - wand = NewMagickWand(); - if (status == MagickPass) - status = MagickReadImage(wand, source); - - if (status == MagickPass) - w = MagickGetImageHeight(wand); - - if (status == MagickPass) - h = MagickGetImageHeight(wand); - - /* 2 -> 160 : width, "cols" */ - /* 3 -> 160 : width, "rows" */ - if (status == MagickPass) - status = MagickSampleImage(wand, 160, 160); - - /* TODO: color maps */ - - /* 2 -> 256 : number of colors */ - /* 3 -> 0 : treedepth -> auto */ - /* 4 -> 0 : dither -> none */ - /* 5 -> 0 : measure_error -> none */ - if (status == MagickPass) - status = MagickQuantizeImage(wand, 256, GRAYColorspace, 0, 0, 0); - - /* 2 -> 3 : radius, in pixels */ - /* 3 -> 2 : "for reasonable results, radius should be larger than sigma" */ - if (status == MagickPass) - status = MagickBlurImage(wand, 3, 2); + imdb_rec_t rec; - if (status == MagickPass) - status = MagickNormalizeImage(wand); - - if (status == MagickPass) - status = MagickEqualizeImage(wand); - - /* 2 -> 16 : width, "cols" */ - /* 3 -> 16 : width, "rows" */ - if (status == MagickPass) - status = MagickSampleImage(wand, 16, 16); - - /* 2 -> 50%, tuned by magick number, see 'magick/image.h' */ - if (status == MagickPass) - status = MagickThresholdImage(wand, 50.0 * (MaxRGB / 100)); - - if (status == MagickPass) - status = MagickSetImageType(wand, BilevelType); - - if (status == MagickPass) - status = MagickSetImageFormat(wand, "MONO"); - - if (status == MagickPass) - buf = MagickWriteImageBlob(wand, &buf_size); + if (argc < 2) { + puts("Usage: sampler-test "); + exit(EXIT_FAILURE); + } -#ifdef DEBUG - fprintf(stderr, "sample H: %lu\n", MagickGetImageWidth(wand)); - fprintf(stderr, "sample W: %lu\n", MagickGetImageWidth(wand)); - fprintf(stderr, "buf size: %u\n", buf_size); - for (unsigned int i = 0; i < buf_size; i++) - fprintf(stderr, "%02X", buf[i]); -#endif - assert(buf_size == 32); + memset(&rec, 0x0, sizeof(imdb_rec_t)); - if (status == MagickPass) { - memset(rec, 0x0, sizeof(imdb_rec_t)); - rec->data[REC_OFF_RU] = 0xFF; - *((uint16_t *) &rec->data[REC_OFF_IW]) = (uint16_t) w; - *((uint16_t *) &rec->data[REC_OFF_IH]) = (uint16_t) h; - memcpy(&rec->data[REC_OFF_BM], buf, 32); - } else { - description = MagickGetException(wand, &severity); - fprintf(stderr, "%03d %.1024s\n", severity, description); /* FIXME */ + if (imdb_sample(&rec, argv[1]) != 0) { + puts("sampler failure"); + exit(EXIT_FAILURE); } - DestroyMagickWand(wand); - DestroyMagick(); + bitmap_print(&rec.data[REC_OFF_BM]); - return (status == MagickPass) ? 0 : -1; + exit(EXIT_SUCCESS); }