API2/Resource/ColorSpace/Indexed.pm

filter: Statementstmt 55.7% 29 / 52 Branchbran 33.3% 2 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 7 / 10 Podpod 25.0% 1 / 4 totaltotal 50.6% 39 / 77 SCAR 25.5
CC
7
Cov
51%
enumColors
12.0
resolveNearestRGB
12.0
new
3.0
CRAP 12.8
« API2/Basic/PDF/String.pm ↑ Summary API2/Resource/ColorSpace/Indexed/Hue.pm »
1 package PDF::API2::Resource::ColorSpace::Indexed;
2  
3 2 ▶use base 'PDF::API2::Resource::ColorSpace';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '2.044'; # VERSION
9  
10 2 ▶use PDF::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use PDF::API2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub new {
15 1 ▶ my ($class, $pdf, $key, %opts) = @_;
Subroutine new: called CC=3 SCAR=11.1
Pod documented
16  
17 1 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 1 1
18 1 my $self = $class->SUPER::new($pdf, $key, %opts);
19 1 ▶ $pdf->new_obj($self) unless $self->is_obj($pdf);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_obj($pdf) 0 1 1
20 1 $self->{' apipdf'} = $pdf;
21 1 weaken $self->{' apipdf'};
22  
23 1 $self->add_elements(PDFName('Indexed'));
24 1 $self->type('Indexed');
25  
26 1 return $self;
27 }
28  
29 sub enumColors {
30 0 ▶ my $self = shift();
Subroutine enumColors: not called CC=3 SCAR=24.8
Pod undocumented
31 0 my %col;
32 0 my $stream = $self->{' csd'}->{' stream'};
33 0 foreach my $n (0..255) {
34 0 my $k = '#' . uc(unpack('H*', substr($stream, $n * 3, 3)));
35 0 ▶ $col{$k} //= $n;
Condition0%0/3
$col{$k} //= $n
l!l&&r!l&&!r
000
MC/DC0%0/2
$col{$k} //= $n
$col{$k} $n
Truth table0%0/3
A //= B
A= $col{$k}B= $n
ABresult
1X1
011
000
36 }
37 0 return %col;
38 }
39  
40 sub nameColor {
41 0 ▶ my ($self, $n) = @_;
Subroutine nameColor: not called CC=1 SCAR=6.9
Pod undocumented
42 0 my %col;
43 0 my $stream = $self->{' csd'}->{' stream'};
44 0 my $k = '#' . uc(unpack('H*', substr($stream, $n * 3, 3)));
45 0 return $k;
46 }
47  
48 # r, g, b need to be 0-255
49 sub resolveNearestRGB {
50 0 ▶ my ($self, $r, $g, $b) = @_;
Subroutine resolveNearestRGB: not called CC=3 SCAR=24.8
Pod undocumented
51 0 my $c = 0;
52 0 my $w = 768 ** 2;
53 0 my $stream = $self->{' csd'}->{' stream'};
54 0 foreach my $n (0..255) {
55 0 my @e = unpack('C*', substr($stream, $n * 3, 3));
56 0 my $d = ($e[0] - $r) ** 2 + ($e[1] - $g) ** 2 + ($e[2] - $b) ** 2;
57 0 ▶ if ($d < $w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d < $w) 0 0 0
58 0 $c = $n;
59 0 $w = $d;
60 }
61 }
62 0 return $c;
63 }
64  
65 2 1;
« API2/Basic/PDF/String.pm ↑ Summary API2/Resource/ColorSpace/Indexed/Hue.pm »