| 1 | package ICC::Profile::Generic; | ||||||||||||||||||||||||||||
| 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.21; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # revised 2016-05-17 | ||||||||||||||||||||||||||||
| 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 generic tag object | ||||||||||||||||||||||||||||
| 19 | # parameters: () | ||||||||||||||||||||||||||||
| 20 | # parameters: (ref_to_attribute_hash) | ||||||||||||||||||||||||||||
| 21 | # returns: (ref_to_object) | ||||||||||||||||||||||||||||
| 22 | sub new { | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # get object class | ||||||||||||||||||||||||||||
| 25 | 1 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # create empty generic object | ||||||||||||||||||||||||||||
| 28 | 1 | my $self = [ | |||||||||||||||||||||||||||
| 29 | {}, # object header | ||||||||||||||||||||||||||||
| 30 | '' # data | ||||||||||||||||||||||||||||
| 31 | ]; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # if single parameter is a scalar | ||||||||||||||||||||||||||||
| 34 | 1 | ▶ | if (@_ == 1 && ! ref($_[0])) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 and not ref $_[0]
MC/DC0%0/2
@_ == 1 and not ref $_[0]
@_ == 1
not ref $_[0]
Truth table33%1/3
A and not(B)
A= @_ == 1B= not ref $_[0]
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # set object data | ||||||||||||||||||||||||||||
| 37 | 0 | $self->[1] = shift(); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # bless object | ||||||||||||||||||||||||||||
| 42 | 1 | bless($self, $class); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # return object reference | ||||||||||||||||||||||||||||
| 45 | 1 | return($self); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # create generic tag object from ICC profile | ||||||||||||||||||||||||||||
| 50 | # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 51 | # returns: (ref_to_object) | ||||||||||||||||||||||||||||
| 52 | sub new_fh { | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # get object class | ||||||||||||||||||||||||||||
| 55 | 12 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||
|
Subroutine
new_fh: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # create empty generic object | ||||||||||||||||||||||||||||
| 58 | 12 | my $self = [ | |||||||||||||||||||||||||||
| 59 | {}, # object header | ||||||||||||||||||||||||||||
| 60 | '' # data | ||||||||||||||||||||||||||||
| 61 | ]; | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # verify 3 parameters | ||||||||||||||||||||||||||||
| 64 | 12 | ▶ | (@_ == 3) || croak('wrong number of parameters'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # read generic data from profile | ||||||||||||||||||||||||||||
| 67 | 12 | _readICCgeneric($self, @_); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # bless object | ||||||||||||||||||||||||||||
| 70 | 12 | bless($self, $class); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # return object reference | ||||||||||||||||||||||||||||
| 73 | 12 | return($self); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | # writes generic tag object to ICC profile | ||||||||||||||||||||||||||||
| 78 | # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 79 | sub write_fh { | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # get tag reference | ||||||||||||||||||||||||||||
| 82 | 12 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
write_fh: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # verify 3 parameters | ||||||||||||||||||||||||||||
| 85 | 12 | ▶ | (@_ == 3) || croak('wrong number of parameters'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # write generic data to profile | ||||||||||||||||||||||||||||
| 88 | 12 | _writeICCgeneric($self, @_); | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # get tag size (for writing to profile) | ||||||||||||||||||||||||||||
| 93 | # returns: (tag_size) | ||||||||||||||||||||||||||||
| 94 | sub size { | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | # get parameters | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
size: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # return size | ||||||||||||||||||||||||||||
| 100 | 0 | return(length($self->[1])); | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # get/set data string | ||||||||||||||||||||||||||||
| 105 | # parameters: ([data]) | ||||||||||||||||||||||||||||
| 106 | # returns: (data) | ||||||||||||||||||||||||||||
| 107 | sub data { | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | # get object reference | ||||||||||||||||||||||||||||
| 110 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
data: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # if parameter supplied | ||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | # save it | ||||||||||||||||||||||||||||
| 116 | 0 | $self->[1] = shift(); | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # return text string | ||||||||||||||||||||||||||||
| 121 | 0 | return($self->[1]); | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # print object contents to string | ||||||||||||||||||||||||||||
| 126 | # format is an array structure | ||||||||||||||||||||||||||||
| 127 | # parameter: ([format]) | ||||||||||||||||||||||||||||
| 128 | # returns: (string) | ||||||||||||||||||||||||||||
| 129 | sub sdump { | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | # get parameters | ||||||||||||||||||||||||||||
| 132 | 0 | ▶ | my ($self, $p) = @_; | ||||||||||||||||||||||||||
|
Subroutine
sdump: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | # local variables | ||||||||||||||||||||||||||||
| 135 | 0 | my ($s, $fmt); | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | # resolve parameter to an array reference | ||||||||||||||||||||||||||||
| 138 | 0 | ▶ | $p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : []; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | # get format string | ||||||||||||||||||||||||||||
| 141 | 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]
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | # set string to object ID | ||||||||||||||||||||||||||||
| 144 | 0 | $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self); | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # return | ||||||||||||||||||||||||||||
| 147 | 0 | return($s); | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | # read generic tag from ICC profile | ||||||||||||||||||||||||||||
| 152 | # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 153 | sub _readICCgeneric { | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # get parameters | ||||||||||||||||||||||||||||
| 156 | 12 | ▶ | my ($self, $parent, $fh, $tag) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_readICCgeneric: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | # save tag signature | ||||||||||||||||||||||||||||
| 159 | 12 | $self->[0]{'signature'} = $tag->[0]; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | # seek start of tag | ||||||||||||||||||||||||||||
| 162 | 12 | seek($fh, $tag->[1], 0); | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | # read tag | ||||||||||||||||||||||||||||
| 165 | 12 | read($fh, $self->[1], $tag->[2]); | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # write generic tag to ICC profile | ||||||||||||||||||||||||||||
| 170 | # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 171 | sub _writeICCgeneric { | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | # get parameters | ||||||||||||||||||||||||||||
| 174 | 12 | ▶ | my ($self, $parent, $fh, $tag) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_writeICCgeneric: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | # seek start of tag | ||||||||||||||||||||||||||||
| 177 | 12 | seek($fh, $tag->[1], 0); | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | # write tag | ||||||||||||||||||||||||||||
| 180 | 12 | print $fh $self->[1]; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 2 | 1; | |||||||||||||||||||||||||||