Add command line tool for testing, more work on the API

This commit is contained in:
2019-12-26 11:50:15 -05:00
parent cf309f71ae
commit 364e7257de
5 changed files with 301 additions and 67 deletions

59
imhash.c Normal file
View File

@@ -0,0 +1,59 @@
#include "fastimagehash.h"
#include <stdio.h>
#include <string.h>
void print_usage() {
printf("Using fastimagehash library v%s\n", FASTIMAGEHASH_VERSION);
printf("Usage: imhash [FILE]...\n");
}
int main(int argc, char *argv[]) {
if (argc < 3) {
print_usage();
return 0;
}
int do_phash = 0, do_ahash = 0, do_whash = 0, do_dhash = 0;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--phash") == 0) {
do_phash = 1;
} else if (strcmp(argv[i], "--ahash") == 0) {
do_ahash = 1;
} else if (strcmp(argv[i], "--whash") == 0) {
do_whash = 1;
} else if (strcmp(argv[i], "--dhash") == 0) {
do_dhash = 1;
} else {
uchar hash[9];
char hashstr[17];
if (do_phash) {
if (phash_file(argv[i], hash, 8, 4) == 0) {
hash_to_hex_string_reversed(hash, hashstr, 8);
printf("%s\tp:%s\n", argv[i], hashstr);
}
}
if (do_ahash) {
if (ahash_file(argv[i], hash, 8) == 0) {
hash_to_hex_string_reversed(hash, hashstr, 8);
printf("%s\ta:%s\n", argv[i], hashstr);
}
}
if (do_dhash) {
if (dhash_file(argv[i], hash, 8) == 0) {
hash_to_hex_string_reversed(hash, hashstr, 8);
printf("%s\td:%s\n", argv[i], hashstr);
}
}
if (do_whash) {
if (whash_file(argv[i], hash, 8, 0) == 0) {
hash_to_hex_string_reversed(hash, hashstr, 8);
printf("%s\tw:%s\n", argv[i], hashstr);
}
}
}
}
}