| 1 | package ICC::Profile::clro; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = 0.12; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # revised 2018-08-07 | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # Copyright © 2004-2018 by William B. Birkett | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # add development directory | ||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use lib 'lib'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # inherit from Shared | ||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use parent qw(ICC::Shared); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # create new clro tag object | ||||||||||||||||||||||||||||
| 19 | # parameters: ([ref_to_seq_array]) | ||||||||||||||||||||||||||||
| 20 | # returns: (ref_to_object) | ||||||||||||||||||||||||||||
| 21 | sub new { | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # get object class | ||||||||||||||||||||||||||||
| 24 | 2 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # create empty clro object | ||||||||||||||||||||||||||||
| 27 | 2 | my $self = [ | |||||||||||||||||||||||||||
| 28 | {}, # object header | ||||||||||||||||||||||||||||
| 29 | [] # colorant sequence array | ||||||||||||||||||||||||||||
| 30 | ]; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # if parameter supplied | ||||||||||||||||||||||||||||
| 33 | 2 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # make new clro tag from colorant sequence array | ||||||||||||||||||||||||||||
| 36 | 1 | _newICCclro($self, @_); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # bless object | ||||||||||||||||||||||||||||
| 41 | 2 | bless($self, $class); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # return object reference | ||||||||||||||||||||||||||||
| 44 | 2 | return($self); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # create clro tag object from ICC profile | ||||||||||||||||||||||||||||
| 49 | # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 50 | # returns: (ref_to_object) | ||||||||||||||||||||||||||||
| 51 | sub new_fh { | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # get object class | ||||||||||||||||||||||||||||
| 54 | 1 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||
|
Subroutine
new_fh: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # create empty clro object | ||||||||||||||||||||||||||||
| 57 | 1 | my $self = [ | |||||||||||||||||||||||||||
| 58 | {}, # object header | ||||||||||||||||||||||||||||
| 59 | [] # colorant sequence array | ||||||||||||||||||||||||||||
| 60 | ]; | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # verify 3 parameters | ||||||||||||||||||||||||||||
| 63 | 1 | ▶ | (@_ == 3) or croak('wrong number of parameters'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # read clro data from profile | ||||||||||||||||||||||||||||
| 66 | 1 | _readICCclro($self, @_); | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # bless object | ||||||||||||||||||||||||||||
| 69 | 1 | bless($self, $class); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # return object reference | ||||||||||||||||||||||||||||
| 72 | 1 | return($self); | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # writes clro tag object to ICC profile | ||||||||||||||||||||||||||||
| 77 | # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 78 | sub write_fh { | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # verify 4 parameters | ||||||||||||||||||||||||||||
| 81 | 1 | ▶ | (@_ == 4) or croak('wrong number of parameters'); | ||||||||||||||||||||||||||
|
Subroutine
write_fh: called CC=2 SCAR=7.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | # write clro data to profile | ||||||||||||||||||||||||||||
| 84 | 1 | goto &_writeICCclro; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # get tag size (for writing to profile) | ||||||||||||||||||||||||||||
| 89 | # returns: (tag_size) | ||||||||||||||||||||||||||||
| 90 | sub size { | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # get parameters | ||||||||||||||||||||||||||||
| 93 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
size: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # return size | ||||||||||||||||||||||||||||
| 96 | 1 | return(12 + @{$self->[1]}); | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # get/set colorant sequence | ||||||||||||||||||||||||||||
| 101 | # parameters: ([ref_to_seq_array]) | ||||||||||||||||||||||||||||
| 102 | # returns: (ref_to_seq_array) | ||||||||||||||||||||||||||||
| 103 | sub sequence { | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # get object reference | ||||||||||||||||||||||||||||
| 106 | 2 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
sequence: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # if parameter supplied | ||||||||||||||||||||||||||||
| 109 | 2 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # get ref to sequence array | ||||||||||||||||||||||||||||
| 112 | 1 | my $seq = shift(); | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # initialize counter | ||||||||||||||||||||||||||||
| 115 | 1 | my $i = 0; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | # verify sequence array | ||||||||||||||||||||||||||||
| 118 | 1 | ▶ | (@{$seq} == grep {$_ == $i++} sort {$a <=> $b} @{$seq}) or croak('bad sequence array'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # save array | ||||||||||||||||||||||||||||
| 121 | 1 | $self->[1] = $seq; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # return text string | ||||||||||||||||||||||||||||
| 126 | 2 | return($self->[1]); | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # print object contents to string | ||||||||||||||||||||||||||||
| 131 | # format is an array structure | ||||||||||||||||||||||||||||
| 132 | # parameter: ([format]) | ||||||||||||||||||||||||||||
| 133 | # returns: (string) | ||||||||||||||||||||||||||||
| 134 | sub sdump { | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | # get parameters | ||||||||||||||||||||||||||||
| 137 | 0 | ▶ | my ($self, $p) = @_; | ||||||||||||||||||||||||||
|
Subroutine
sdump: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | # local variables | ||||||||||||||||||||||||||||
| 140 | 0 | my ($s, $fmt); | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | # resolve parameter to an array reference | ||||||||||||||||||||||||||||
| 143 | 0 | ▶ | $p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : []; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | # get format string | ||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 'undef'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $p->[0] and not ref $p->[0]
MC/DC0%0/2
defined $p->[0] and not ref $p->[0]
defined $p->[0]
not ref $p->[0]
Truth table0%0/3
A and not(B)
A= defined $p->[0]B= not ref $p->[0]
| |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | # set string to object ID | ||||||||||||||||||||||||||||
| 149 | 0 | $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self); | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | # return | ||||||||||||||||||||||||||||
| 152 | 0 | return($s); | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | # make new clro tag from colorant sequence array | ||||||||||||||||||||||||||||
| 157 | # parameters: (ref_to_object, ref_to_seq_array) | ||||||||||||||||||||||||||||
| 158 | sub _newICCclro { | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | # get parameters | ||||||||||||||||||||||||||||
| 161 | 1 | ▶ | my ($self, $seq) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_newICCclro: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | # initialize counter | ||||||||||||||||||||||||||||
| 164 | 1 | my $i = 0; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # verify sequence array | ||||||||||||||||||||||||||||
| 167 | 1 | ▶ | (@{$seq} == grep {$_ == $i++} sort {$a <=> $b} @{$seq}) or croak('bad sequence array'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # copy array | ||||||||||||||||||||||||||||
| 170 | 1 | $self->[1] = [@{$seq}]; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | # read clro tag from ICC profile | ||||||||||||||||||||||||||||
| 175 | # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 176 | sub _readICCclro { | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | # get parameters | ||||||||||||||||||||||||||||
| 179 | 1 | ▶ | my ($self, $parent, $fh, $tag) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_readICCclro: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | # local variables | ||||||||||||||||||||||||||||
| 182 | 1 | my ($buf, $cnt); | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | # save tag signature | ||||||||||||||||||||||||||||
| 185 | 1 | $self->[0]{'signature'} = $tag->[0]; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | # seek start of tag | ||||||||||||||||||||||||||||
| 188 | 1 | seek($fh, $tag->[1], 0); | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | # read tag type signature and colorant count | ||||||||||||||||||||||||||||
| 191 | 1 | read($fh, $buf, 12); | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | # unpack colorant count | ||||||||||||||||||||||||||||
| 194 | 1 | $cnt = unpack('x8 N', $buf); | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | # read colorant array | ||||||||||||||||||||||||||||
| 197 | 1 | read($fh, $buf, $cnt); | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | # unpack colorant array | ||||||||||||||||||||||||||||
| 200 | 1 | $self->[1] = [unpack('C*', $buf)]; | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | # write clro tag to ICC profile | ||||||||||||||||||||||||||||
| 205 | # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 206 | sub _writeICCclro { | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | # get parameters | ||||||||||||||||||||||||||||
| 209 | 1 | ▶ | my ($self, $parent, $fh, $tag) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_writeICCclro: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | # seek start of tag | ||||||||||||||||||||||||||||
| 212 | 1 | seek($fh, $tag->[1], 0); | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | # write tag | ||||||||||||||||||||||||||||
| 215 | 1 | print $fh pack('a4 x4 N C*', 'clro', scalar(@{$self->[1]}), @{$self->[1]}); | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | 2 | 1; | |||||||||||||||||||||||||||