| 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
| |||||||||||||||||||||
| 18 | 1 | my $self = $class->SUPER::new($pdf, $key, %opts); | |||||||||||||||||||
| 19 | 1 | ▶ | $pdf->new_obj($self) unless $self->is_obj($pdf); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
MC/DC0%0/2
$col{$k} //= $n
$col{$k}
$n
Truth table0%0/3
A //= B
A= $col{$k}B= $n
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 58 | 0 | $c = $n; | |||||||||||||||||||
| 59 | 0 | $w = $d; | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | 0 | return $c; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 2 | 1; | |||||||||||||||||||