Skip to content

Commit

Permalink
Replaced unsigned int unpack template to used signed (per puzzle.h).
Browse files Browse the repository at this point in the history
RT-113716: signature_as_char_string was using the unsigned unpack
template to convert the signature to a character representation; the
reporter pointed out that the signature is actually a signed character
and that the resulting string representation was not correct.

https://rt.cpan.org/Ticket/Display.html?id=113716

The suggested fix was implemented; the unpack now uses the signed char
template (c); this results in an array of values that range -2..2; the
arrays is then iterated and 2 is added to each value; this shifts the
range to 0..4 (removes the minus sign), and therefore produces stringified
signatures that are of a consistent length from image to image. Now
this makes character string cvecs (and ngrams) usable for image indexing.

Minor unrelated change - removed the check for puzzle.h. In theory it is
nice to have; but it was causing issues on my dev machine, FreeBSD 10.3.
  • Loading branch information
estrabd committed May 25, 2016
1 parent 57607ef commit 43cdae1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
7 changes: 0 additions & 7 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
use 5.014004;
use ExtUtils::MakeMaker;

# Check that the local system has libpuzzle installed using
# Devel::CheckLib.

use lib 'inc';
use Devel::CheckLib;
check_lib_or_exit (lib => 'puzzle', header => 'puzzle.h');

# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
my $repo = 'https://github.com/estrabd/Image-Libpuzzle';
Expand Down
8 changes: 5 additions & 3 deletions lib/Image/Libpuzzle.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ our $PUZZLE_CVEC_SIMILARITY_HIGH_THRESHOLD = Image::Libpuzzle->PUZZLE_CVEC_SIMI
our $PUZZLE_CVEC_SIMILARITY_LOW_THRESHOLD = Image::Libpuzzle->PUZZLE_CVEC_SIMILARITY_LOW_THRESHOLD;
our $PUZZLE_CVEC_SIMILARITY_LOWER_THRESHOLD = Image::Libpuzzle->PUZZLE_CVEC_SIMILARITY_LOWER_THRESHOLD;

# uses unpack as bin to char and $self accessor to get signature directly from the internal cvec
# uses unpack as bin to insigned char, then add 2 to remove negative number; provides range of 0..4;
# and $self accessor to get signature directly from the internal cvec
sub signature_as_char_string {
my $self = shift;
my @sig = unpack("C*", $self->get_signature());
# take as
my @sig = unpack("c*", $self->get_signature());
my $sig = q{};
foreach my $i (@sig) {
$sig .= sprintf("%02d", $i);
$sig .= sprintf("%02d", $i+2);
}
return $sig;
}
Expand Down

0 comments on commit 43cdae1

Please sign in to comment.