mirror of
https://github.com/simon987/fastimagehash.git
synced 2025-04-10 14:16:49 +00:00
Code style fixes
This commit is contained in:
parent
5ebbcf2845
commit
315335f38b
@ -20,7 +20,6 @@ void *load_test_file(size_t *buf_len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void BM_phash(benchmark::State &state) {
|
static void BM_phash(benchmark::State &state) {
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
void *buf = load_test_file(&size);
|
void *buf = load_test_file(&size);
|
||||||
|
|
||||||
@ -32,7 +31,6 @@ static void BM_phash(benchmark::State &state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void BM_whash(benchmark::State &state) {
|
static void BM_whash(benchmark::State &state) {
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
void *buf = load_test_file(&size);
|
void *buf = load_test_file(&size);
|
||||||
|
|
||||||
@ -44,7 +42,6 @@ static void BM_whash(benchmark::State &state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void BM_dhash(benchmark::State &state) {
|
static void BM_dhash(benchmark::State &state) {
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
void *buf = load_test_file(&size);
|
void *buf = load_test_file(&size);
|
||||||
|
|
||||||
@ -56,7 +53,6 @@ static void BM_dhash(benchmark::State &state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void BM_ahash(benchmark::State &state) {
|
static void BM_ahash(benchmark::State &state) {
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
void *buf = load_test_file(&size);
|
void *buf = load_test_file(&size);
|
||||||
|
|
||||||
@ -68,7 +64,6 @@ static void BM_ahash(benchmark::State &state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void BM_multi(benchmark::State &state) {
|
static void BM_multi(benchmark::State &state) {
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
void *buf = load_test_file(&size);
|
void *buf = load_test_file(&size);
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
//TODO: Error handling
|
//TODO: Error handling
|
||||||
//TODO: compute multiple hashes at once
|
|
||||||
|
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
|
|
||||||
@ -19,7 +18,6 @@ using namespace cv;
|
|||||||
|
|
||||||
__always_inline
|
__always_inline
|
||||||
double median(double *arr, size_t len) {
|
double median(double *arr, size_t len) {
|
||||||
|
|
||||||
std::sort(arr, arr + len);
|
std::sort(arr, arr + len);
|
||||||
|
|
||||||
if (len % 2 == 0) {
|
if (len % 2 == 0) {
|
||||||
@ -39,7 +37,6 @@ void hash_to_hex_string(const uchar *h, char *out, int hash_size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void hash_to_hex_string_reversed(const uchar *h, char *out, int hash_size) {
|
void hash_to_hex_string_reversed(const uchar *h, char *out, int hash_size) {
|
||||||
|
|
||||||
int hash_len = hash_size * hash_size / 4;
|
int hash_len = hash_size * hash_size / 4;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < hash_len; i += 2) {
|
for (unsigned int i = 0; i < hash_len; i += 2) {
|
||||||
@ -60,7 +57,6 @@ void hash_to_hex_string_reversed(const uchar *h, char *out, int hash_size) {
|
|||||||
|
|
||||||
__always_inline
|
__always_inline
|
||||||
void set_bit_at(uchar *buf, unsigned int offset, bool val) {
|
void set_bit_at(uchar *buf, unsigned int offset, bool val) {
|
||||||
|
|
||||||
unsigned int byte_offset = offset / 8;
|
unsigned int byte_offset = offset / 8;
|
||||||
unsigned int bit_offset = offset - byte_offset * 8;
|
unsigned int bit_offset = offset - byte_offset * 8;
|
||||||
|
|
||||||
@ -72,7 +68,6 @@ void set_bit_at(uchar *buf, unsigned int offset, bool val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *load_file_in_mem(const char *filepath, size_t *size) {
|
void *load_file_in_mem(const char *filepath, size_t *size) {
|
||||||
|
|
||||||
struct stat info{};
|
struct stat info{};
|
||||||
if (stat(filepath, &info) != 0) {
|
if (stat(filepath, &info) != 0) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -92,7 +87,6 @@ void *load_file_in_mem(const char *filepath, size_t *size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ahash_file(const char *filepath, uchar *out, int hash_size) {
|
int ahash_file(const char *filepath, uchar *out, int hash_size) {
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
void *buf = load_file_in_mem(filepath, &size);
|
void *buf = load_file_in_mem(filepath, &size);
|
||||||
|
|
||||||
@ -106,7 +100,6 @@ int ahash_file(const char *filepath, uchar *out, int hash_size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ahash_mem(void *buf, uchar *out, size_t buf_len, int hash_size) {
|
int ahash_mem(void *buf, uchar *out, size_t buf_len, int hash_size) {
|
||||||
|
|
||||||
Mat im;
|
Mat im;
|
||||||
try {
|
try {
|
||||||
im = imdecode(Mat(1, buf_len, CV_8UC1, buf), IMREAD_GRAYSCALE);
|
im = imdecode(Mat(1, buf_len, CV_8UC1, buf), IMREAD_GRAYSCALE);
|
||||||
@ -126,7 +119,6 @@ int ahash_mem(void *buf, uchar *out, size_t buf_len, int hash_size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int dhash_file(const char *filepath, uchar *out, int hash_size) {
|
int dhash_file(const char *filepath, uchar *out, int hash_size) {
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
void *buf = load_file_in_mem(filepath, &size);
|
void *buf = load_file_in_mem(filepath, &size);
|
||||||
if (buf == nullptr) {
|
if (buf == nullptr) {
|
||||||
@ -139,7 +131,6 @@ int dhash_file(const char *filepath, uchar *out, int hash_size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int dhash_mem(void *buf, uchar *out, size_t buf_len, int hash_size) {
|
int dhash_mem(void *buf, uchar *out, size_t buf_len, int hash_size) {
|
||||||
|
|
||||||
Mat im;
|
Mat im;
|
||||||
try {
|
try {
|
||||||
im = imdecode(Mat(1, buf_len, CV_8UC1, buf), IMREAD_GRAYSCALE);
|
im = imdecode(Mat(1, buf_len, CV_8UC1, buf), IMREAD_GRAYSCALE);
|
||||||
@ -160,7 +151,6 @@ int dhash_mem(void *buf, uchar *out, size_t buf_len, int hash_size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int whash_file(const char *filepath, uchar *out, int hash_size, int img_scale) {
|
int whash_file(const char *filepath, uchar *out, int hash_size, int img_scale) {
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
void *buf = load_file_in_mem(filepath, &size);
|
void *buf = load_file_in_mem(filepath, &size);
|
||||||
if (buf == nullptr) {
|
if (buf == nullptr) {
|
||||||
@ -173,7 +163,6 @@ int whash_file(const char *filepath, uchar *out, int hash_size, int img_scale) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int whash_mem(void *buf, uchar *out, size_t buf_len, int hash_size, int img_scale) {
|
int whash_mem(void *buf, uchar *out, size_t buf_len, int hash_size, int img_scale) {
|
||||||
|
|
||||||
Mat im;
|
Mat im;
|
||||||
try {
|
try {
|
||||||
im = imdecode(Mat(1, buf_len, CV_8UC1, buf), IMREAD_GRAYSCALE);
|
im = imdecode(Mat(1, buf_len, CV_8UC1, buf), IMREAD_GRAYSCALE);
|
||||||
@ -221,7 +210,6 @@ int whash_mem(void *buf, uchar *out, size_t buf_len, int hash_size, int img_scal
|
|||||||
wt2_object wt = wt2_init(w, "dwt", img_scale, img_scale, dwt_level);
|
wt2_object wt = wt2_init(w, "dwt", img_scale, img_scale, dwt_level);
|
||||||
|
|
||||||
double *coeffs = dwt2(wt, data);
|
double *coeffs = dwt2(wt, data);
|
||||||
free(data);
|
|
||||||
|
|
||||||
//TODO: hash size !
|
//TODO: hash size !
|
||||||
double sorted[64];
|
double sorted[64];
|
||||||
@ -232,11 +220,16 @@ int whash_mem(void *buf, uchar *out, size_t buf_len, int hash_size, int img_scal
|
|||||||
for (int i = 0; i < hash_size * hash_size; ++i) {
|
for (int i = 0; i < hash_size * hash_size; ++i) {
|
||||||
set_bit_at(out, i, coeffs[i] > med);
|
set_bit_at(out, i, coeffs[i] > med);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(data);
|
||||||
|
wt2_free(wt);
|
||||||
|
wave_free(w);
|
||||||
|
free(coeffs);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int phash_file(const char *filepath, uchar *out, int hash_size, int highfreq_factor) {
|
int phash_file(const char *filepath, uchar *out, int hash_size, int highfreq_factor) {
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
void *buf = load_file_in_mem(filepath, &size);
|
void *buf = load_file_in_mem(filepath, &size);
|
||||||
|
|
||||||
@ -250,7 +243,6 @@ int phash_file(const char *filepath, uchar *out, int hash_size, int highfreq_fac
|
|||||||
}
|
}
|
||||||
|
|
||||||
int phash_mem(void *buf, uchar *out, size_t buf_len, int hash_size, int highfreq_factor) {
|
int phash_mem(void *buf, uchar *out, size_t buf_len, int hash_size, int highfreq_factor) {
|
||||||
|
|
||||||
int img_size = hash_size * highfreq_factor;
|
int img_size = hash_size * highfreq_factor;
|
||||||
|
|
||||||
Mat im;
|
Mat im;
|
||||||
@ -321,7 +313,6 @@ void multi_hash_destroy(multi_hash_t *h) {
|
|||||||
|
|
||||||
int multi_hash_file(const char *filepath, multi_hash_t *out, int hash_size,
|
int multi_hash_file(const char *filepath, multi_hash_t *out, int hash_size,
|
||||||
int ph_highfreq_factor, int wh_img_scale) {
|
int ph_highfreq_factor, int wh_img_scale) {
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
void *buf = load_file_in_mem(filepath, &size);
|
void *buf = load_file_in_mem(filepath, &size);
|
||||||
|
|
||||||
@ -336,7 +327,6 @@ int multi_hash_file(const char *filepath, multi_hash_t *out, int hash_size,
|
|||||||
|
|
||||||
int multi_hash_mem(void *buf, multi_hash_t *out, size_t buf_len,
|
int multi_hash_mem(void *buf, multi_hash_t *out, size_t buf_len,
|
||||||
int hash_size, int ph_highfreq_factor, int wh_img_scale) {
|
int hash_size, int ph_highfreq_factor, int wh_img_scale) {
|
||||||
|
|
||||||
Mat im;
|
Mat im;
|
||||||
try {
|
try {
|
||||||
im = imdecode(Mat(1, buf_len, CV_8UC1, buf), IMREAD_GRAYSCALE);
|
im = imdecode(Mat(1, buf_len, CV_8UC1, buf), IMREAD_GRAYSCALE);
|
||||||
@ -385,7 +375,7 @@ int multi_hash_mem(void *buf, multi_hash_t *out, size_t buf_len,
|
|||||||
return FASTIMAGEHASH_ERR;
|
return FASTIMAGEHASH_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
double *pixels = new double[MAX(ph_img_scale, wh_img_scale) * MAX(ph_img_scale, wh_img_scale)];
|
auto pixels = new double[MAX(ph_img_scale, wh_img_scale) * MAX(ph_img_scale, wh_img_scale)];
|
||||||
|
|
||||||
// ahash
|
// ahash
|
||||||
double avg = mean(ahash_im).val[0];
|
double avg = mean(ahash_im).val[0];
|
||||||
@ -465,6 +455,9 @@ int multi_hash_mem(void *buf, multi_hash_t *out, size_t buf_len,
|
|||||||
set_bit_at(out->whash, i, coeffs[i] > med);
|
set_bit_at(out->whash, i, coeffs[i] > med);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wt2_free(wt);
|
||||||
|
wave_free(w);
|
||||||
|
free(coeffs);
|
||||||
delete[] pixels;
|
delete[] pixels;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
2
imhash.c
2
imhash.c
@ -66,6 +66,8 @@ int main(int argc, char *argv[]) {
|
|||||||
printf("%s\tmd:%s\n", argv[i], hashstr);
|
printf("%s\tmd:%s\n", argv[i], hashstr);
|
||||||
hash_to_hex_string_reversed(m->whash, hashstr, 8);
|
hash_to_hex_string_reversed(m->whash, hashstr, 8);
|
||||||
printf("%s\tmw:%s\n", argv[i], hashstr);
|
printf("%s\tmw:%s\n", argv[i], hashstr);
|
||||||
|
|
||||||
|
multi_hash_destroy(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user