Builder/Resource/ColorSpace/Indexed.pm

filter: Statementstmt 55.5% 30 / 54 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% 40 / 79 CC 7 SCAR 17.2
CC
7
Cov
51%
enumColors
12.0
resolveNearestRGB
12.0
new
3.0
CRAP 5.6
« Builder/Resource/ColorSpace/Indexed/WebColor.pm ↑ Summary Builder/Basic/PDF/Objind.pm »
1 package PDF::Builder::Resource::ColorSpace::Indexed;
2  
3 2 ▶use base 'PDF::Builder::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 = '3.028'; # VERSION
9 2 our $LAST_UPDATE = '3.027'; # manually update whenever code is changed
10  
11 2 ▶use PDF::Builder::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use PDF::Builder::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 PDF::Builder::Resource::ColorSpace::Indexed - Base colorspace support for indexed color models
18  
19 Inherits from L<PDF::Builder::Resource::ColorSpace>
20  
21 =head2 new
22  
23 PDF::Builder::Resource::ColorSpace::Indexed->new($pdf, $key, %opts)
24  
25 =over
26  
27 Create a new Indexed ColorSpace object.
28  
29 =back
30  
31 =cut
32  
33 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.1
Pod documented
34 1 my ($class, $pdf, $key, %opts) = @_;
35  
36 1 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 1 1
37 1 my $self = $class->SUPER::new($pdf, $key, %opts);
38 1 ▶ $pdf->new_obj($self) unless $self->is_obj($pdf);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_obj($pdf) 0 1 1
39 1 $self->{' apipdf'} = $pdf;
40 1 weaken $self->{' apipdf'};
41  
42 1 $self->add_elements(PDFName('Indexed'));
43 1 $self->type('Indexed');
44  
45 1 return $self;
46 }
47  
48 # unknown -- not used anywhere
49  
50 0 ▶sub enumColors {
Subroutine enumColors: not called CC=3 SCAR=24.8
Pod undocumented
51 0 my $self = shift;
52  
53 0 my %col;
54 0 my $stream = $self->{' csd'}->{' stream'};
55 0 foreach my $n (0..255) {
56 0 my $k = '#' . uc(unpack('H*', substr($stream, $n*3, 3)));
57 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
58 }
59 0 return %col;
60 }
61  
62 # unknown -- not used anywhere
63  
64 0 ▶sub nameColor {
Subroutine nameColor: not called CC=1 SCAR=6.9
Pod undocumented
65 0 my ($self, $n) = @_;
66  
67 0 my %col;
68 0 my $stream = $self->{' csd'}->{' stream'};
69 0 my $k = '#' . uc(unpack('H*', substr($stream, $n*3, 3)));
70 0 return $k;
71 }
72  
73 # unknown -- not used anywhere
74  
75 0 ▶sub resolveNearestRGB {
Subroutine resolveNearestRGB: not called CC=3 SCAR=24.8
Pod undocumented
76 0 my $self = shift;
77 0 my ($r, $g, $b) = @_; # need to be in 0-255
78  
79 0 my $c = 0;
80 0 my $w = 768**2;
81 0 my $stream = $self->{' csd'}->{' stream'};
82 0 foreach my $n (0..255) {
83 0 my @e = unpack('C*', substr($stream, $n*3, 3));
84 0 my $d = ($e[0]-$r)**2 + ($e[1]-$g)**2 + ($e[2]-$b)**2;
85 0 ▶ if ($d < $w) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d < $w) 0 0 0
86 0 $c = $n;
87 0 $w = $d;
88 }
89 }
90 0 return $c;
91 }
92  
93 2 1;
« Builder/Resource/ColorSpace/Indexed/WebColor.pm ↑ Summary Builder/Basic/PDF/Objind.pm »