|
@ -41,6 +41,13 @@ else: |
|
|
lib = cdll.LoadLibrary("libpihash.so") |
|
|
lib = cdll.LoadLibrary("libpihash.so") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PIHashes(Structure): |
|
|
|
|
|
_fields_ = [ |
|
|
|
|
|
("ahash", c_ulonglong), |
|
|
|
|
|
("dhash", c_ulonglong), |
|
|
|
|
|
("phash", c_ulonglong)] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Setting the ctypes return type references for the foreign functions |
|
|
# Setting the ctypes return type references for the foreign functions |
|
|
# returns a pointer to the library that we'll need to pass to all function calls |
|
|
# returns a pointer to the library that we'll need to pass to all function calls |
|
|
lib.ext_init.restype = c_void_p |
|
|
lib.ext_init.restype = c_void_p |
|
@ -51,6 +58,9 @@ lib.ext_get_dhash.restype = c_ulonglong |
|
|
lib.ext_get_dhash.argtypes = [c_void_p, c_char_p] |
|
|
lib.ext_get_dhash.argtypes = [c_void_p, c_char_p] |
|
|
lib.ext_get_phash.restype = c_ulonglong |
|
|
lib.ext_get_phash.restype = c_ulonglong |
|
|
lib.ext_get_phash.argtypes = [c_void_p, c_char_p] |
|
|
lib.ext_get_phash.argtypes = [c_void_p, c_char_p] |
|
|
|
|
|
lib.ext_get_phashes.restype = c_void_p |
|
|
|
|
|
lib.ext_get_phashes.argtypes = [c_void_p, c_char_p] |
|
|
|
|
|
lib.ext_free_phashes.argtypes = [c_void_p] |
|
|
# Takes a pointer and frees the struct at that memory location |
|
|
# Takes a pointer and frees the struct at that memory location |
|
|
lib.ext_free.argtypes = [c_void_p] |
|
|
lib.ext_free.argtypes = [c_void_p] |
|
|
|
|
|
|
|
@ -65,9 +75,15 @@ lib_struct = lib.ext_init("./.hash_cache".encode(encoding="utf-8")) |
|
|
|
|
|
|
|
|
for image in test_images: |
|
|
for image in test_images: |
|
|
print("Requesting hashes for: %s"% image) |
|
|
print("Requesting hashes for: %s"% image) |
|
|
print("ahash: %i"% unsigned64(lib.ext_get_ahash(lib_struct, image))) |
|
|
|
|
|
print("dhash: %i"% unsigned64(lib.ext_get_dhash(lib_struct, image))) |
|
|
|
|
|
print("phash: %i"% unsigned64(lib.ext_get_phash(lib_struct, image))) |
|
|
|
|
|
|
|
|
phashes = lib.ext_get_phashes(lib_struct, image) |
|
|
|
|
|
pihashes = PIHashes.from_address(phashes) |
|
|
|
|
|
lib.ext_free_phashes(phashes) |
|
|
|
|
|
print("ahash: %i"% unsigned64(pihashes.ahash)) |
|
|
|
|
|
print("dhash: %i"% unsigned64(pihashes.dhash)) |
|
|
|
|
|
print("phash: %i"% unsigned64(pihashes.phash)) |
|
|
|
|
|
# print("ahash: %i"% unsigned64(lib.ext_get_ahash(lib_struct, image))) |
|
|
|
|
|
# print("dhash: %i"% unsigned64(lib.ext_get_dhash(lib_struct, image))) |
|
|
|
|
|
# print("phash: %i"% unsigned64(lib.ext_get_phash(lib_struct, image))) |
|
|
|
|
|
|
|
|
# Do cleanup |
|
|
# Do cleanup |
|
|
# Makes sure that the heap is cleaned up |
|
|
# Makes sure that the heap is cleaned up |
|
|