| 1 | package Image::Compare::IMAGE; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Imager ':handy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Imager::Fountain; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use base qw/Image::Compare::Comparator/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use constant FILL_IMAGE_CACHE => {}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use constant FILL_IMAGE_WIDTH => 1000; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 8 | ▶ | use constant DEFAULT_COLOR_FOUNTAIN => Imager::Fountain->simple( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | positions => [ 0.0, 0.5, 1.0], | ||||||||||||||||||||||||||||
| 15 | colors => [NC(255, 0, 0), NC(0, 255, 0), NC(0, 0, 255)], | ||||||||||||||||||||||||||||
| 16 | 8 | ); | |||||||||||||||||||||||||||
| 17 | 8 | ▶ | use constant DEFAULT_GREYSCALE_FOUNTAIN => Imager::Fountain->simple( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | positions => [ 0.0, 1.0], | ||||||||||||||||||||||||||||
| 19 | colors => [NC(0, 0, 0), NC(255, 255, 255)], | ||||||||||||||||||||||||||||
| 20 | 8 | ); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 4 | ▶ | sub setup { | ||||||||||||||||||||||||||
|
Subroutine
setup: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 24 | 4 | $self->SUPER::setup(@_); | |||||||||||||||||||||||||||
| 25 | 4 | $self->{count} = 0; | |||||||||||||||||||||||||||
| 26 | 4 | $self->{img} = Imager->new( | |||||||||||||||||||||||||||
| 27 | xsize => $_[0]->getwidth(), | ||||||||||||||||||||||||||||
| 28 | ysize => $_[0]->getheight(), | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | # Now we build up our fill image; this is a 1000 x 1 image that is filled | ||||||||||||||||||||||||||||
| 31 | # using an Imager fountain. We'll pull pixels from it to put colors into | ||||||||||||||||||||||||||||
| 32 | # the generated image. | ||||||||||||||||||||||||||||
| 33 | 4 | my $fountain; | |||||||||||||||||||||||||||
| 34 | 4 | ▶ | if ($self->{args}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | # If there's an argument, it's either a fountain, or it's telling us to use | ||||||||||||||||||||||||||||
| 36 | # the default color fountain. | ||||||||||||||||||||||||||||
| 37 | 2 | ▶ | if (ref $self->{args} && $self->{args}->isa('Imager::Fountain')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $self->{"args"} and $self->{"args"}->isa("Imager::Fountain")
MC/DC50%1/2
ref $self->{"args"} and $self->{"args"}->isa("Imager::Fountain")
ref $self->{"args"}
$self->{"args"}->isa("Imager::Fountain")
Truth table66%2/3
A and B
A= ref $self->{"args"}B= $self->{"args"}->isa("Imager::Fountain")
| |||||||||||||||||||||||||||||
| 38 | 1 | $fountain = $self->{args}; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||||||||||
| 41 | 1 | $fountain = DEFAULT_COLOR_FOUNTAIN(); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||
| 45 | # In this case, we use the default greyscale fountain. | ||||||||||||||||||||||||||||
| 46 | 2 | $fountain = DEFAULT_GREYSCALE_FOUNTAIN(); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | # Using an object as a hash key stringifies it to its memory location and | ||||||||||||||||||||||||||||
| 49 | # uses that. This is suboptimal, but the Imager::Fountain class has no | ||||||||||||||||||||||||||||
| 50 | # "to_string", so we make do. | ||||||||||||||||||||||||||||
| 51 | 4 | ▶ | unless (FILL_IMAGE_CACHE()->{$fountain}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 4 | my $image = Imager->new(xsize => FILL_IMAGE_WIDTH(), ysize => 1); | |||||||||||||||||||||||||||
| 53 | 4 | $image->filter( | |||||||||||||||||||||||||||
| 54 | type => 'fountain', segments => $fountain, | ||||||||||||||||||||||||||||
| 55 | xa => 0, ya => 0, | ||||||||||||||||||||||||||||
| 56 | xb => FILL_IMAGE_WIDTH(), yb => 0, | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | 4 | FILL_IMAGE_CACHE()->{$fountain} = $image; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 4 | $self->{fill_image} = FILL_IMAGE_CACHE()->{$fountain}; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 15 | ▶ | sub accumulate { | ||||||||||||||||||||||||||
|
Subroutine
accumulate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 15 | my $self = shift; | |||||||||||||||||||||||||||
| 65 | 15 | my($pix1, $pix2, $x, $y) = @_; | |||||||||||||||||||||||||||
| 66 | 15 | my $diff = $self->color_distance($pix1, $pix2); | |||||||||||||||||||||||||||
| 67 | # We want to convert from our range of values for $diff (0 .. 441.7) to | ||||||||||||||||||||||||||||
| 68 | # the range of values of our fill image, which is defined by a constant. | ||||||||||||||||||||||||||||
| 69 | 15 | $diff *= FILL_IMAGE_WIDTH(); | |||||||||||||||||||||||||||
| 70 | 15 | $diff /= 441.7; | |||||||||||||||||||||||||||
| 71 | my $color = $self->{fill_image}->getpixel( | ||||||||||||||||||||||||||||
| 72 | 15 | x => $diff, | |||||||||||||||||||||||||||
| 73 | y => 0, | ||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||
| 75 | $self->{img}->setpixel( | ||||||||||||||||||||||||||||
| 76 | 15 | x => $x, | |||||||||||||||||||||||||||
| 77 | y => $y, | ||||||||||||||||||||||||||||
| 78 | color => $color, | ||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||
| 80 | 15 | return undef; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 4 | ▶ | sub get_result { | ||||||||||||||||||||||||||
|
Subroutine
get_result: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 85 | 4 | return $self->{img}; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 8 | 1; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||