| 1 | package Game::Terminal::Kit::Pixels; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Game::Terminal::Kit::Screen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Game::Terminal::Kit::Shape; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | has [qw/width height/] => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | default => 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | has [qw/row column/] => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | default => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | has threshold => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | default => 64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | has [qw/buffer drawn depth codes/] => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | is => 'rw' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 16 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 16 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 16 | ▶ | die "Pixels: a width and a height are needed\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->width > 0 and $self->height > 0
MC/DC100%2/2
$self->width > 0 and $self->height > 0
$self->width > 0
$self->height > 0
Truth table100%3/3
A and B
A= $self->width > 0B= $self->height > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | unless $self->width > 0 && $self->height > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 13 | $self->codes({}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 13 | return $self->clear; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | sub columns { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
columns: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | return $self->width; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | ▶ | sub rows { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rows: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | return ($self->height + 1) >> 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 7 | ▶ | sub bytes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bytes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 7 | return ${ $self->buffer }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | ▶ | sub load { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 4 | my ($self, $bytes) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 4 | my $need = $self->width * $self->height * 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 4 | ▶ | die "Pixels: load needs $need bytes and was given " . (defined $bytes ? length $bytes : 'none') . "\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
defined $bytes and length $bytes == $need
MC/DC100%2/2
defined $bytes and length $bytes == $need
defined $bytes
length $bytes == $need
Truth table100%3/3
A and B
A= defined $bytesB= length $bytes == $need
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | unless defined $bytes && length $bytes == $need; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | $self->buffer(\$bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 23 | ▶ | sub clear { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 23 | my ($self, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 23 | ▶ | my $bytes = pack('N', ($colour // 0) << 8) x ($self->width * $self->height); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$colour // 0
MC/DC100%1/1
$colour // 0
$colour
Truth table100%2/2
A
A= $colour
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 23 | $self->buffer(\$bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 23 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 3 | ▶ | sub redraw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
redraw: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | $self->drawn(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 188 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 188 | my ($self, $x, $y) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 188 | ($x, $y) = (int $x, int $y); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 188 | my $width = $self->width; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 188 | ▶ | return undef if $x < 0 || $y < 0 || $x >= $width || $y >= $self->height; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$x < 0 or $y < 0 or $x >= $width or $y >= $self->height
$x < 0 or $y < 0 or $x >= $width
$x < 0 or $y < 0
MC/DC100%4/4
$x < 0 or $y < 0 or $x >= $width or $y >= $self->height
$x < 0
$y < 0
$x >= $width
$y >= $self->height
Truth table100%5/5
A or B or C or D
A= $x < 0B= $y < 0C= $x >= $widthD= $y >= $self->height
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 184 | return vec(${ $self->buffer }, $y * $width + $x, 32) >> 8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 27 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 27 | my ($self, $x, $y, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 27 | ($x, $y) = (int $x, int $y); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 27 | my $width = $self->width; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 27 | ▶ | return $self if $x < 0 || $y < 0 || $x >= $width || $y >= $self->height; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$x < 0 or $y < 0 or $x >= $width or $y >= $self->height
$x < 0 or $y < 0 or $x >= $width
$x < 0 or $y < 0
MC/DC100%4/4
$x < 0 or $y < 0 or $x >= $width or $y >= $self->height
$x < 0
$y < 0
$x >= $width
$y >= $self->height
Truth table100%5/5
A or B or C or D
A= $x < 0B= $y < 0C= $x >= $widthD= $y >= $self->height
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 23 | vec(${ $self->buffer }, $y * $width + $x, 32) = $colour << 8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 23 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 6 | ▶ | sub plot { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
plot: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 6 | my ($self, $points, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 6 | my ($width, $height, $buffer) = ($self->width, $self->height, $self->buffer); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 6 | my $value = $colour << 8; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 6 | for my $point (@{$points}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 61 | my ($x, $y) = @{$point}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 61 | ▶ | next if $x < 0 || $y < 0 || $x >= $width || $y >= $height; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$x < 0 or $y < 0 or $x >= $width or $y >= $height
$x < 0 or $y < 0 or $x >= $width
$x < 0 or $y < 0
MC/DC75%3/4
$x < 0 or $y < 0 or $x >= $width or $y >= $height
$x < 0
$y < 0
$x >= $width
$y >= $height
Truth table80%4/5
A or B or C or D
A= $x < 0B= $y < 0C= $x >= $widthD= $y >= $height
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 46 | vec(${$buffer}, $y * $width + $x, 32) = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 8 | ▶ | sub rect { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rect: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 8 | my ($self, $x, $y, $across, $down, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 8 | my ($width, $height, $buffer) = ($self->width, $self->height, $self->buffer); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 8 | my ($right, $bottom) = (int($x) + int($across), int($y) + int($down)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 8 | ($x, $y) = (int $x, int $y); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 8 | ▶ | $x = 0 if $x < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 8 | ▶ | $y = 0 if $y < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 8 | ▶ | $right = $width if $right > $width; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 8 | ▶ | $bottom = $height if $bottom > $height; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 8 | ▶ | return $self if $right <= $x || $bottom <= $y; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$right <= $x or $bottom <= $y
MC/DC100%2/2
$right <= $x or $bottom <= $y
$right <= $x
$bottom <= $y
Truth table100%3/3
A or B
A= $right <= $xB= $bottom <= $y
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 3 | my $run = pack('N', $colour << 8) x ($right - $x); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | for my $at ($y .. $bottom - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 5 | substr(${$buffer}, ($at * $width + $x) * 4, length $run) = $run; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | ▶ | sub line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | my ($self, $x, $y, $to_x, $to_y, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | return $self->plot([ Game::Terminal::Kit::Shape::line($x, $y, $to_x, $to_y) ], $colour); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | ▶ | sub outline { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
outline: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | my ($self, $x, $y, $across, $down, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | return $self->plot([ Game::Terminal::Kit::Shape::outline($x, $y, $across, $down) ], $colour); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | ▶ | sub disc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | my ($self, $x, $y, $radius, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | return $self->plot([ Game::Terminal::Kit::Shape::disc($x, $y, $radius) ], $colour); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | ▶ | sub ring { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ring: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | my ($self, $x, $y, $radius, $colour) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | return $self->plot([ Game::Terminal::Kit::Shape::ring($x, $y, $radius) ], $colour); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 9 | ▶ | sub pixel_at { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pixel_at: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 9 | my ($self, $column, $row) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 9 | ▶ | return () unless defined $column && defined $row; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $column and defined $row
MC/DC50%1/2
defined $column and defined $row
defined $column
defined $row
Truth table66%2/3
A and B
A= defined $columnB= defined $row
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 8 | my ($x, $y) = ($column - $self->column, ($row - $self->row) * 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 8 | ▶ | return () if $x < 0 || $y < 0 || $x >= $self->width || $y >= $self->height; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$x < 0 or $y < 0 or $x >= $self->width or $y >= $self->height
$x < 0 or $y < 0 or $x >= $self->width
$x < 0 or $y < 0
MC/DC100%4/4
$x < 0 or $y < 0 or $x >= $self->width or $y >= $self->height
$x < 0
$y < 0
$x >= $self->width
$y >= $self->height
Truth table100%5/5
A or B or C or D
A= $x < 0B= $y < 0C= $x >= $self->widthD= $y >= $self->height
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | return ($x, $y); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 40 | ▶ | sub _lit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lit: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 40 | my ($colour, $threshold) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 40 | return ((($colour >> 16 & 255) * 2 + ($colour >> 8 & 255) * 5 + ($colour & 255)) >> 3) >= $threshold; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 20018 | ▶ | sub _code { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_code: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 20018 | my ($colour, $depth) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 20018 | ▶ | return join ';', 2, $colour >> 16 & 255, $colour >> 8 & 255, $colour & 255 if $depth >= 24; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 2 | return '5;' . Game::Terminal::Kit::Screen::palette($colour); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 18 | ▶ | sub changes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
changes: called CC=30 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 18 | my ($self, $screen) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 18 | my ($width, $height) = ($self->width, $self->height); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 18 | ▶ | my $plain = $screen && $screen->ascii; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$screen && $screen->ascii
MC/DC100%2/2
$screen && $screen->ascii
$screen
$screen->ascii
Truth table100%3/3
A && B
A= $screenB= $screen->ascii
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 18 | ▶ | my $depth = !$screen ? 24 : $plain || !$screen->colour ? 0 : $screen->depth || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%5/5
$plain or not $screen->colour
$screen->depth or 0
MC/DC100%2/2
$plain or not $screen->colour
$plain
not $screen->colour
MC/DC100%1/1
$screen->depth or 0
$screen->depth
Truth table100%3/3
A or not(B)
A= $plainB= not $screen->colour
Truth table100%2/2
A
A= $screen->depth
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 18 | my $codes = $self->codes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 18 | ▶ | my $manner = $plain ? -1 : $depth; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 18 | ▶ | if (!defined $self->depth || $self->depth != $manner) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $self->depth or $self->depth != $manner
MC/DC100%2/2
not defined $self->depth or $self->depth != $manner
not defined $self->depth
$self->depth != $manner
Truth table100%3/3
not(A) or B
A= not defined $self->depthB= $self->depth != $manner
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 10 | %{$codes} = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 10 | $self->drawn(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 10 | $self->depth($manner); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | %{$codes} = () if keys %{$codes} > 8192; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 18 | ▶ | my @glyphs = $plain ? (' ', q{'}, '.', ':') : (' ', "\x{2580}", "\x{2584}", "\x{2588}"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 18 | my ($row, $column, $threshold) = ($self->row, $self->column, $self->threshold); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 18 | my $stride = $width * 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 18 | my $bytes = ${ $self->buffer }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 18 | my $drawn = $self->drawn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 18 | my $blank = "\0" x $stride; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 18 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 18 | ▶ | for (my $top = 0; $top < $height; $top += 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 123 | my $paired = $top + 1 < $height; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 123 | my $upper = substr $bytes, $top * $stride, $stride; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 123 | ▶ | my $lower = $paired ? substr($bytes, ($top + 1) * $stride, $stride) : $blank; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 123 | my ($from, $to) = (0, $width - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 123 | ▶ | if (defined $drawn) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 8 | my $was_upper = substr $drawn, $top * $stride, $stride; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 8 | ▶ | my $was_lower = $paired ? substr($drawn, ($top + 1) * $stride, $stride) : $blank; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 8 | ▶ | next if $upper eq $was_upper && $lower eq $was_lower; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$upper eq $was_upper and $lower eq $was_lower
MC/DC100%2/2
$upper eq $was_upper and $lower eq $was_lower
$upper eq $was_upper
$lower eq $was_lower
Truth table100%3/3
A and B
A= $upper eq $was_upperB= $lower eq $was_lower
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 4 | my $differs = ($upper ^ $was_upper) | ($lower ^ $was_lower); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 4 | $differs =~ m/[^\0]/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 4 | $from = $-[0] >> 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 4 | $differs =~ m/.*[^\0]/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | $to = ($+[0] - 1) >> 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 119 | $out .= "\e[" . ($row + ($top >> 1)) . ';' . ($column + $from) . 'H'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 119 | ▶ | if (!$depth) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 5 | for my $x ($from .. $to) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 20 | ▶ | $out .= $glyphs[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | (_lit(vec($upper, $x, 32) >> 8, $threshold) ? 1 : 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | | (_lit(vec($lower, $x, 32) >> 8, $threshold) ? 2 : 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 5 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 114 | my ($ink, $ground) = (-1, -1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 114 | for my $x ($from .. $to) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 10034 | my ($over, $under) = (vec($upper, $x, 32) >> 8, vec($lower, $x, 32) >> 8); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 10034 | my $set = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 10034 | ▶ | if ($ground != $under) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 10018 | ▶ | $set = '48;' . ($codes->{$under} //= _code($under, $depth)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$codes->{$under} //= _code($under, $depth)
MC/DC0%0/2
$codes->{$under} //= _code($under, $depth)
$codes->{$under}
_code($under, $depth)
Truth table66%2/3
A //= B
A= $codes->{$under}B= _code($under, $depth)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 10018 | $ground = $under; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 10034 | ▶ | if ($over == $under) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 18 | ▶ | $out .= length $set ? "\e[${set}m " : ' '; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 18 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 10016 | ▶ | if ($ink != $over) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 10014 | ▶ | $set .= (length $set ? ';' : '') . '38;' . ($codes->{$over} //= _code($over, $depth)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$codes->{$over} //= _code($over, $depth)
MC/DC0%0/2
$codes->{$over} //= _code($over, $depth)
$codes->{$over}
_code($over, $depth)
Truth table66%2/3
A //= B
A= $codes->{$over}B= _code($over, $depth)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 10014 | $ink = $over; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 10016 | ▶ | $out .= length $set ? "\e[${set}m\x{2580}" : "\x{2580}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 114 | $out .= "\e[0m"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 18 | $self->drawn($bytes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 18 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||