Skip to content

Commit

Permalink
hash_size must be power of 2 for whash algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
lene committed Jan 12, 2024
1 parent 7ea40c0 commit 9fecdc4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions duplicate_images/parse_commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from duplicate_images.methods import ACTIONS_ON_EQUALITY, IMAGE_HASH_ALGORITHM


def is_power_of_2(n: int) -> bool:
# https://stackoverflow.com/questions/57025836/how-to-check-if-a-given-number-is-a-power-of-two
return (n != 0) and (n & (n - 1) == 0)


def parse_command_line(args: Optional[List[str]] = None) -> Namespace:
parser = ArgumentParser(description='Find pairs of equal or similar images.')

Expand Down Expand Up @@ -71,4 +76,6 @@ def parse_command_line(args: Optional[List[str]] = None) -> Namespace:
namespace = parser.parse_args(args)
if namespace.on_equal == 'exec' and not namespace.exec:
parser.error('--exec argument is required')
if namespace.algorithm == 'whash' and not is_power_of_2(namespace.hash_size):
parser.error('whash requires hash_size to be a power of 2')
return namespace

0 comments on commit 9fecdc4

Please sign in to comment.