line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PDF::Builder::Resource::ColorSpace::Indexed; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1033
|
use base 'PDF::Builder::Resource::ColorSpace'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
621
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
15
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
42
|
|
6
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
97
|
|
7
|
|
|
|
|
|
|
#no warnings qw[ deprecated recursion uninitialized ]; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '3.023'; # VERSION |
10
|
|
|
|
|
|
|
our $LAST_UPDATE = '3.021'; # manually update whenever code is changed |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
13
|
use PDF::Builder::Basic::PDF::Utils; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
211
|
|
13
|
2
|
|
|
2
|
|
14
|
use PDF::Builder::Util; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
270
|
|
14
|
2
|
|
|
2
|
|
15
|
use Scalar::Util qw(weaken); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
981
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
PDF::Builder::Resource::ColorSpace::Indexed - base colorspace support for indexed color models. Inherits from L |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
1
|
|
|
1
|
1
|
3
|
my ($class, $pdf, $key, %opts) = @_; |
24
|
|
|
|
|
|
|
|
25
|
1
|
50
|
|
|
|
3
|
$class = ref $class if ref $class; |
26
|
1
|
|
|
|
|
7
|
my $self = $class->SUPER::new($pdf,$key,%opts); |
27
|
1
|
50
|
|
|
|
3
|
$pdf->new_obj($self) unless $self->is_obj($pdf); |
28
|
1
|
|
|
|
|
2
|
$self->{' apipdf'} = $pdf; |
29
|
1
|
|
|
|
|
4
|
weaken $self->{' apipdf'}; |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
3
|
$self->add_elements(PDFName('Indexed')); |
32
|
1
|
|
|
|
|
6
|
$self->type('Indexed'); |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
3
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub enumColors { |
38
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my %col = (); |
41
|
0
|
|
|
|
|
|
foreach my $n (0..255) { |
42
|
0
|
|
|
|
|
|
my $k = '#'.uc(unpack('H*', substr($self->{' csd'}->{' stream'}, $n*3, 3))); |
43
|
0
|
0
|
|
|
|
|
$col{$k} = $n unless defined $col{$k}; |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
return %col; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub nameColor { |
49
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
50
|
0
|
|
|
|
|
|
my $n = shift; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my %col = (); |
53
|
0
|
|
|
|
|
|
my $k = '#'.uc(unpack('H*', substr($self->{' csd'}->{' stream'}, $n*3, 3))); |
54
|
0
|
|
|
|
|
|
return $k; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub resolveNearestRGB { |
58
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
59
|
0
|
|
|
|
|
|
my ($r,$g,$b) = @_; # need to be in 0-255 |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $c = 0; |
62
|
0
|
|
|
|
|
|
my $w = 768**2; |
63
|
0
|
|
|
|
|
|
foreach my $n (0..255) { |
64
|
0
|
|
|
|
|
|
my @e = unpack('C*', substr($self->{' csd'}->{' stream'}, $n*3, 3)); |
65
|
0
|
|
|
|
|
|
my $d = ($e[0]-$r)**2 + ($e[1]-$g)**2 + ($e[2]-$b)**2; |
66
|
0
|
0
|
|
|
|
|
if ($d < $w) { |
67
|
0
|
|
|
|
|
|
$c = $n; |
68
|
0
|
|
|
|
|
|
$w = $d; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
0
|
|
|
|
|
|
return $c; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |