| 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # read only store of a single color: name + values in default and original space | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | package Graphics::Toolkit::Color::Values; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use v5.12; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use Graphics::Toolkit::Color::Name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use Graphics::Toolkit::Color::Space::Hub; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | my $RGB = Graphics::Toolkit::Color::Space::Hub::default_space(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | #### constructor ####################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 172 | ▶ | sub new_from_any_input { # values => %space_name => tuple , ~origin_space, ~color_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_any_input: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 172 | my ($pkg, $color_def, $space_name, $range_def, $raw) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 172 | ▶ | return "Can not create color value object without color definition!" unless defined $color_def; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 170 | ▶ | if (not ref $color_def) { # try to resolve color name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 74 | my $rgb = Graphics::Toolkit::Color::Name::get_values( $color_def ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 74 | ▶ | if (ref $rgb){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 43 | $rgb = $RGB->clamp( $RGB->normalize( $rgb ), 'normal' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 43 | return bless { color_name => $color_def, rgb_tuple => $rgb, source_tuple => '', source_space_name => ''}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 127 | ▶ | my ($tuple, $found_space_name, $format) = (defined $space_name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ? Graphics::Toolkit::Color::Space::Hub::deformat( $color_def, $space_name ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | : Graphics::Toolkit::Color::Space::Hub::deformat_search( $color_def ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 127 | ▶ | return $tuple unless ref $tuple; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 78 | new_from_tuple( '', $tuple, $found_space_name, $range_def, $raw); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 522 | ▶ | sub new_from_tuple { # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_from_tuple: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 522 | my ($pkg, $tuple, $space_name, $range_def, $raw) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 522 | my $color_space = Graphics::Toolkit::Color::Space::Hub::try_get_space( $space_name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 522 | ▶ | return $color_space unless ref $color_space; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 522 | ▶ | return "Need ARRAY of ".$color_space->axis_count." ".$color_space->name." values as first argument!" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | unless $color_space->is_value_tuple( $tuple ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 521 | $tuple = $color_space->normalize( $tuple, $range_def ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 521 | ▶ | $tuple = $color_space->clamp( $tuple, 'normal' ) unless defined $raw and $raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $raw and $raw
MC/DC100%2/2
defined $raw and $raw
defined $raw
$raw
Truth table100%3/3
A and B
A= defined $rawB= $raw
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 521 | my $source_tuple = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 521 | my $source_space_name = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 521 | ▶ | if ($color_space->name ne $RGB->name){ # convert into RGB if needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 189 | $source_tuple = $tuple; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 189 | $source_space_name = $color_space->name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 189 | $tuple = Graphics::Toolkit::Color::Space::Hub::deconvert( $tuple, $color_space->name, 'normal' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 521 | my $name = Graphics::Toolkit::Color::Name::from_values( $RGB->round( $RGB->denormalize( $tuple ) ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 521 | bless { rgb_tuple => $tuple, source_tuple => $source_tuple, source_space_name => $source_space_name, color_name => $name }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | #### getter ############################################################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 444 | ▶ | sub normalized { # normalized (0..1) value tuple in any color space | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalized: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 444 | my ($self, $space_name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | Graphics::Toolkit::Color::Space::Hub::convert( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 444 | $self->{'rgb_tuple'}, $space_name, 'normal', $self->{'source_tuple'}, $self->{'source_space_name'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 360 | ▶ | sub shaped { # in any color space, range and precision | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shaped: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 360 | my ($self, $space_name, $range_def, $precision_def, $raw) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 360 | my $color_space = Graphics::Toolkit::Color::Space::Hub::try_get_space( $space_name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 360 | ▶ | return $color_space unless ref $color_space; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 360 | my $tuple = $self->normalized( $color_space->name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 360 | ▶ | return $tuple if not ref $tuple; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 360 | $tuple = $color_space->denormalize( $tuple, $range_def ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 360 | ▶ | $tuple = $color_space->clamp( $tuple, $range_def ) unless $raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 360 | ▶ | $tuple = $color_space->round( $tuple, $precision_def ) unless ($raw and not defined $precision_def) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$raw and not defined $precision_def or defined $range_def and not defined $precision_def
$raw and not defined $precision_def
defined $range_def and not defined $precision_def
MC/DC75%3/4
$raw and not defined $precision_def or defined $range_def and not defined $precision_def
$raw
not defined $precision_def
defined $range_def
not defined $precision_def
Truth table57%4/7
A and not(B) or C and not(D)
A= $rawB= not defined $precision_defC= defined $range_defD= not defined $precision_def
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | or (defined $range_def and not defined $precision_def); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 360 | return $tuple; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 92 | ▶ | sub formatted { # in shape values in any format # _ -- ~space, @~|~format, @~|~range, @~|~suffix --> @|%|$ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
formatted: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 92 | my ($self, $space_name, $format_name, $suffix_def, $range_def, $precision_def, $raw) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 92 | my $color_space = Graphics::Toolkit::Color::Space::Hub::try_get_space( $space_name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 92 | ▶ | return \$color_space unless ref $color_space; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 92 | my $tuple = $self->shaped( $color_space->name, $range_def, $precision_def, $raw ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 92 | ▶ | return \$tuple unless ref $tuple; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 92 | return $color_space->format( $tuple, $format_name, $suffix_def ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 72 | ▶ | sub name { $_[0]->{'color_name'} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 16 | ▶ | sub is_in_gamut { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_in_gamut: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 16 | my ($self, $space_name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 16 | ▶ | $space_name = $self->{'source_space_name'} if not defined $space_name and $self->{'source_space_name'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $space_name and $self->{"source_space_name"}
MC/DC100%2/2
not defined $space_name and $self->{"source_space_name"}
not defined $space_name
$self->{"source_space_name"}
Truth table100%3/3
not(A) and B
A= not defined $space_nameB= $self->{"source_space_name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 16 | my $color_space = Graphics::Toolkit::Color::Space::Hub::try_get_space( $space_name ); # default to RGB | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 16 | ▶ | return 0 unless ref $color_space; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 16 | my $tuple = $self->normalized( $space_name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 16 | ▶ | return 0 unless ref $tuple; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 16 | return $color_space->is_in_linear_bounds( $tuple, 'normal' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||