ExifOrientation.pm

filter: Statementstmt 68.8% 31 / 45 Branchbran 50.0% 6 / 12 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 2 totaltotal 59.4% 44 / 74 CC 8 SCAR 21.0
CC
8
Cov
61%
rotate
20.0
get_orientation_by_exiftool
12.0
_rotate
3.0
CRAP 8.2
« Filter/ExifOrientation.pm ↑ Summary
1 package Imager::ExifOrientation;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 our $VERSION = '0.07';
5  
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Imager;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Image::ExifTool 'ImageInfo';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Image::ExifTool::Exif;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 my $orientation_revers = {};
12 2 ▶while (my($k, $v) = each %Image::ExifTool::Exif::orientation) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %Image::ExifTool::Exif::orientation) 16 2 18
13 16 $orientation_revers->{$v} = $k;
14 }
15  
16 0 ▶sub rotate {
Subroutine rotate: not called CC=4 SCAR=30.0
Pod undocumented
17 0 my($class, %opts) = @_;
18  
19 0 my $img = Imager->new;
20 0 my $exif;
21 0 ▶ if ($opts{data}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts{'data'}) { } 0 0 0
elsif ($opts{'path'}) { } 0 0 0
22 0 $exif = ImageInfo(\$opts{data});
23 0 $img->read( data => $opts{data}, type => 'jpeg' );
24 } elsif ($opts{path}) {
25 0 $exif = ImageInfo($opts{path});
26 0 $img->read( file => $opts{path}, type => 'jpeg' );
27 } else {
28 0 croak "usage:
29 Imager::ExifOrientation->rotate( path => '/foo/bar/baz.jpg' )
30 Imager::ExifOrientation->rotate( data => \$jpeg_data )
31 ";
32 }
33  
34 0 ▶ my $orientation = $class->get_orientation_by_exiftool($exif || {});
Condition0%0/2
$exif || {}
l!l
00
MC/DC0%0/1
$exif || {}
$exif
Truth table0%0/2
A
A= $exif
Aresult
11
00
35 0 $class->_rotate($img, $orientation);
36 }
37  
38 0 ▶sub get_orientation_by_exiftool {
Subroutine get_orientation_by_exiftool: not called CC=3 SCAR=24.8
Pod undocumented
39 0 my($class, $exif) = @_;
40 0 ▶ return 1 unless $exif->{Orientation};
Branch: 1 branch
BranchTrueFalseTotal
unless $exif->{"Orientation"} 0 0 0
41 0 ▶ return $orientation_revers->{$exif->{Orientation}} || 1;
Condition0%0/2
$$orientation_revers{$exif->{'Orientation'}} || 1
l!l
00
MC/DC0%0/1
$$orientation_revers{$exif->{'Orientation'}} || 1
$$orientation_revers{$exif->{'Orientation'}}
Truth table0%0/2
A
A= $$orientation_revers{$exif->{'Orientation'}}
Aresult
11
00
42 }
43  
44 2 my $rotate_maps = {
45 1 => { right => 0, mirror => undef }, # Horizontal (normal)
46 2 => { right => 0, mirror => 'h' }, # Mirror horizontal
47 3 => { right => 0, mirror => 'hv' }, # Rotate 180 (rotate is too noisy)
48 4 => { right => 0, mirror => 'v' }, # Mirror vertical
49 5 => { right => 270, mirror => 'h' }, # Mirror horizontal and rotate 270 CW
50 6 => { right => 90, mirror => undef }, # Rotate 90 CW
51 7 => { right => 90, mirror => 'h' }, # Mirror horizontal and rotate 90 CW
52 8 => { right => 270, mirror => undef }, # Rotate 270 CW
53 };
54  
55 16 ▶sub _rotate {
Subroutine _rotate: called CC=3 SCAR=11.0
56 16 my($class, $img, $orientation) = @_;
57 16 my $map = $rotate_maps->{$orientation};
58  
59 16 ▶ if ($map->{mirror}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map->{"mirror"}) 10 6 16
60 10 $img->flip( dir => $map->{mirror} );
61 }
62  
63 16 ▶ if ($map->{right}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map->{"right"}) 8 8 16
64 8 return $img->rotate( right => $map->{right} );
65 }
66  
67 8 $img;
68 }
69  
70 2 1;
71 __END__
« Filter/ExifOrientation.pm ↑ Summary