Algorithms as values¶
Any algorithm through one call, selected by a ph_algorithm_t or its name.
| Types | |
|---|---|
ph_ |
Every hash algorithm, as a value – for code that picks the algorithm at run time (a binding, a configuration file, a database column) instead of calling one of the ph_compute_* functions by name. |
| Constants | |
|---|---|
PH_ |
| Functions | |
|---|---|
ph_ |
Computes any algorithm's hash into a digest. |
ph_ |
Tells what digest an algorithm produces, without an image and without computing anything: its size in bytes and its kind (which decides the comparison metric). |
ph_ |
The algorithm's stable lowercase name: "ahash", "dhash", "phash", "whash", "bmh", "mhash", "radial", "color_hash", "color_moments". |
ph_ |
The inverse of ph_algorithm_name(): exact, lowercase match. |
Types¶
ph_algorithm_t¶
Every hash algorithm, as a value – for code that picks the algorithm at run time (a binding, a configuration file, a database column) instead of calling one of the ph_compute_* functions by name.
The values are contiguous from 0 to PH_ALGORITHM_COUNT - 1, so for (a = 0; a <PH_ALGORITHM_COUNT; a++) visits every algorithm. For the four uint64_t algorithms the matching ph_hash_flags_t bit is 1u << value: PH_HASH_DHASH == 1u \<\< PH_ALGO_DHASH. New algorithms are appended; existing values never change.
| Name | Value | Description |
|---|---|---|
PH_ |
0 |
ph_compute_ahash(); "ahash". |
PH_ |
1 |
ph_compute_dhash(); "dhash". |
PH_ |
2 |
ph_compute_phash(); "phash". |
PH_ |
3 |
ph_compute_whash(); "whash". |
PH_ |
4 |
ph_compute_bmh(); "bmh". |
PH_ |
5 |
ph_compute_mhash(); "mhash". |
PH_ |
6 |
ph_compute_radial_hash(); "radial". |
PH_ |
7 |
ph_compute_color_hash(); "color_hash". |
PH_ |
8 |
ph_compute_color_moments_hash(); "color_moments". |
PH_ |
PH_ |
Not an algorithm – see "Enum width". |
Constants¶
PH_ALGORITHM_COUNT¶
Number of ph_algorithm_t values: every algorithm is in [0, PH_ALGORITHM_COUNT).
Functions¶
ph_compute_digest()¶
Computes any algorithm's hash into a digest.
Exactly the result of the algorithm's own ph_compute_* function, same errors included (PH_ERR_EMPTY_IMAGE, PH_ERR_REQUIRES_COLOR, ...). The four uint64_t algorithms come back as an 8-byte PH_DIGEST_KIND_BITS digest holding the hash most significant byte first – the order ph_hash_to_hex() writes – so ph_hamming_distance_digest() on two of them equals ph_hamming_distance() on the two hashes, and every algorithm can be stored and compared through the digest functions alone.
Parameters
| Parameter | Direction | Description |
|---|---|---|
ctx |
in | The context, with an image loaded. |
algo |
in | The algorithm. |
out_digest |
out | Receives the digest; its size and kind are what ph_digest_info() reports for this context and algorithm. Untouched on error. |
Returns As the algorithm's ph_compute_* function – PH_SUCCESS, PH_ERR_INVALID_ARGUMENT, PH_ERR_EMPTY_IMAGE, PH_ERR_REQUIRES_COLOR or PH_ERR_ALLOCATION_FAILED – and PH_ERR_INVALID_ARGUMENT for an algo that is not a ph_algorithm_t value.
ph_digest_info()¶
ph_error_t ph_digest_info(
const ph_context_t *ctx,
ph_algorithm_t algo,
size_t *out_size,
ph_digest_kind_t *out_kind);
Tells what digest an algorithm produces, without an image and without computing anything: its size in bytes and its kind (which decides the comparison metric).
The answer comes from the same code that sets the size and kind of every computed digest, so it cannot disagree with ph_compute_digest() or the ph_compute_* functions. Only BMH's size depends on the configuration (ph_context_set_block_params()); the others are fixed.
Parameters
| Parameter | Direction | Description |
|---|---|---|
ctx |
in | The configuration to answer for, or NULL for the defaults. Its image, if any, is not looked at. |
algo |
in | The algorithm. |
out_size |
out | Receives the digest size in bytes (8 for the uint64_t algorithms, as ph_compute_digest() returns them). May be NULL. |
out_kind |
out | Receives the digest kind. May be NULL. |
Returns PH_SUCCESS, or PH_ERR_INVALID_ARGUMENT for an algo that is not a ph_algorithm_t value (nothing is written then).
ph_algorithm_name()¶
The algorithm's stable lowercase name: "ahash", "dhash", "phash", "whash", "bmh", "mhash", "radial", "color_hash", "color_moments".
Returns A static string, never NULL; "unknown" for a value that is not an algorithm.
ph_algorithm_from_name()¶
The inverse of ph_algorithm_name(): exact, lowercase match.
Parameters
| Parameter | Direction | Description |
|---|---|---|
name |
in | The name. |
out_algo |
out | Receives the algorithm. Untouched on error. |
Returns PH_SUCCESS, or PH_ERR_INVALID_ARGUMENT for a NULL argument or a name that is not one ph_algorithm_name() returns.