| 1 | package Image::Caa; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | our $VERSION = '1.01'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # dark colors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use constant CAA_COLOR_BLACK => 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use constant CAA_COLOR_RED => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use constant CAA_COLOR_GREEN => 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use constant CAA_COLOR_YELLOW => 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use constant CAA_COLOR_BLUE => 4; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use constant CAA_COLOR_MAGENTA => 5; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use constant CAA_COLOR_CYAN => 6; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use constant CAA_COLOR_LIGHTGRAY => 7; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # light colors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use constant CAA_COLOR_DARKGRAY => 8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use constant CAA_COLOR_LIGHTRED => 9; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use constant CAA_COLOR_LIGHTGREEN => 10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use constant CAA_COLOR_BROWN => 11; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | use constant CAA_COLOR_LIGHTBLUE => 12; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | ▶ | use constant CAA_COLOR_LIGHTMAGENTA => 13; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | ▶ | use constant CAA_COLOR_LIGHTCYAN => 14; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | ▶ | use constant CAA_COLOR_WHITE => 15; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | ▶ | use constant CAA_LOOKUP_VAL => 32; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | use constant CAA_LOOKUP_SAT => 32; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | use constant CAA_LOOKUP_HUE => 16; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | ▶ | use constant CAA_HSV_XRATIO => 6; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | ▶ | use constant CAA_HSV_YRATIO => 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | ▶ | use constant CAA_HSV_HRATIO => 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 15 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 15 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 15 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 15 | my $opts = \%opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 15 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 15 | ▶ | $self->{driver} = $self->load_submodule($opts->{driver} || 'DriverANSI', $opts); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{'driver'} || 'DriverANSI'
MC/DC100%1/1
$opts->{'driver'} || 'DriverANSI'
$opts->{'driver'}
Truth table100%2/2
A
A= $opts->{'driver'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 14 | ▶ | $self->{dither} = $self->load_submodule($opts->{dither} || 'DitherNone', $opts); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{'dither'} || 'DitherNone'
MC/DC100%1/1
$opts->{'dither'} || 'DitherNone'
$opts->{'dither'}
Truth table100%2/2
A
A= $opts->{'dither'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 14 | ▶ | $self->{solid_background} = $opts->{black_bg} ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | $self->{hsv_palette} = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # weight, hue, saturation, value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 14 | 4, 0x0, 0x0, 0x0, # black | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 5, 0x0, 0x0, 0x5ff, # 30% | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 5, 0x0, 0x0, 0x9ff, # 70% | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 4, 0x0, 0x0, 0xfff, # white | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 3, 0x1000, 0xfff, 0x5ff, # dark yellow | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 2, 0x1000, 0xfff, 0xfff, # light yellow | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 3, 0x0, 0xfff, 0x5ff, # dark red | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 2, 0x0, 0xfff, 0xfff # light red | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 14 | $self->init(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 14 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 14 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 14 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 14 | $self->{hsv_distances} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 14 | ▶ | for (my $v = 0; $v < CAA_LOOKUP_VAL; $v++){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 448 | ▶ | for (my $s = 0; $s < CAA_LOOKUP_SAT; $s++){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 14336 | ▶ | for (my $h = 0; $h < CAA_LOOKUP_HUE; $h++){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 229376 | my $val = 0xfff * $v / (CAA_LOOKUP_VAL - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 229376 | my $sat = 0xfff * $s / (CAA_LOOKUP_SAT - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 229376 | my $hue = 0xfff * $h / (CAA_LOOKUP_HUE - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # Initialise distances to the distance between pure black HSV | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # coordinates and our white colour (3) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 229376 | my $outbg = 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 229376 | my $outfg = 3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 229376 | my $distbg = $self->HSV_DISTANCE(0, 0, 0, 3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 229376 | my $distfg = $self->HSV_DISTANCE(0, 0, 0, 3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Calculate distances to eight major colour values and store the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # two nearest points in our lookup table. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 229376 | ▶ | for (my $i = 0; $i < 8; $i++){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1835008 | my $dist = $self->HSV_DISTANCE($hue, $sat, $val, $i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1835008 | ▶ | if ($dist <= $distbg){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 651252 | $outfg = $outbg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 651252 | $distfg = $distbg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 651252 | $outbg = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 651252 | $distbg = $dist; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | }elsif ($dist <= $distfg){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 286846 | $outfg = $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 286846 | $distfg = $dist; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 229376 | $self->{hsv_distances}->[$v]->[$s]->[$h] = ($outfg << 4) | $outbg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 5 | ▶ | sub init_instance { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_instance: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 5 | $self->{lookup_colors} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # These ones are constant | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 5 | $self->{lookup_colors}->[0] = CAA_COLOR_BLACK; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 5 | $self->{lookup_colors}->[1] = CAA_COLOR_DARKGRAY; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 5 | $self->{lookup_colors}->[2] = CAA_COLOR_LIGHTGRAY; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 5 | $self->{lookup_colors}->[3] = CAA_COLOR_WHITE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # These ones will be overwritten | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 5 | $self->{lookup_colors}->[4] = CAA_COLOR_MAGENTA; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 5 | $self->{lookup_colors}->[5] = CAA_COLOR_LIGHTMAGENTA; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 5 | $self->{lookup_colors}->[6] = CAA_COLOR_RED; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 5 | $self->{lookup_colors}->[7] = CAA_COLOR_LIGHTRED; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # Draw a bitmap on the screen. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # Draw a bitmap at the given coordinates. The bitmap can be of any size and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # will be stretched to the text area. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # x1 X coordinate of the upper-left corner of the drawing area. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # y1 Y coordinate of the upper-left corner of the drawing area. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # x2 X coordinate of the lower-right corner of the drawing area. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # y2 Y coordinate of the lower-right corner of the drawing area. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # image Image Magick picture object to be drawn. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 5 | ▶ | sub draw_bitmap{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
draw_bitmap: called CC=19 SCAR=37.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 5 | my ($self, $x1, $y1, $x2, $y2, $image) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 5 | my $w = $x2-$x1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 5 | my $h = $y2-$y1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 5 | my $iw = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 5 | my $ih = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 5 | my $h_pad = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 5 | my $v_pad = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 5 | ▶ | if (defined $image){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # resize to fit in the box | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $image->Scale('100%,67%'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | my $x = $image->Resize(geometry => ($w-2).'x'.($h-2)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | warn "$x" if "$x"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ($iw, $ih) = $image->Get('columns', 'rows'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $h_pad = 1 + int(($w - $iw) / 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $v_pad = 1 + int(($h - $ih) / 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 5 | $self->init_instance(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 5 | $self->{driver}->init(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # Only used when background is black | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 5 | my $white_colors = [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | CAA_COLOR_BLACK, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | CAA_COLOR_DARKGRAY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | CAA_COLOR_LIGHTGRAY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | CAA_COLOR_WHITE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 5 | my $light_colors = [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | CAA_COLOR_LIGHTMAGENTA, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | CAA_COLOR_LIGHTRED, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | CAA_COLOR_YELLOW, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | CAA_COLOR_LIGHTGREEN, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | CAA_COLOR_LIGHTCYAN, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | CAA_COLOR_LIGHTBLUE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | CAA_COLOR_LIGHTMAGENTA, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 5 | my $dark_colors = [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | CAA_COLOR_MAGENTA, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | CAA_COLOR_RED, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | CAA_COLOR_BROWN, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | CAA_COLOR_GREEN, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | CAA_COLOR_CYAN, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | CAA_COLOR_BLUE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | CAA_COLOR_MAGENTA, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # FIXME: choose better characters! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 5 | my $density_chars = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | " ". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | ". ". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | ".. ". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | "....". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | "::::". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | ";=;=". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | "tftf". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | '%$%$'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | "&KSZ". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | "WXGM". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | '@@@@'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | "8888". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | "####". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | "????"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 5 | my @density_chars = split //, $density_chars; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 5 | $density_chars = \@density_chars; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 5 | my $density_chars_size = scalar(@{$density_chars}) - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 5 | my $x = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 5 | my $y = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 5 | my $deltax = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 5 | my $deltay = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | my $tmp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if ($x1 > $x2){ $tmp = $x2; $x2 = $x1; $x1 = $tmp; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | if ($y1 > $y2){ $tmp = $y2; $y2 = $y1; $y1 = $tmp; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 5 | $deltax = $x2 - $x1 + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 5 | $deltay = $y2 - $y1 + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 5 | ▶ | for ($y = $y1 > 0 ? $y1 : 0; $y <= $y2; $y++){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 10 | $self->{dither}->init($y); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 10 | ▶ | for ($x = $x1 > 0 ? $x1 : 0; $x <= $x2; $x++){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 20 | my $ch = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 20 | my $r = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 20 | my $g = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 20 | my $b = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 20 | my $a = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 20 | my $hue = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 20 | my $sat = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 20 | my $val = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 20 | my $fromx = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 20 | my $fromy = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 20 | my $tox = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 20 | my $toy = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 20 | my $myx = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 20 | my $myy = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 20 | my $dots = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 20 | my $outfg = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 20 | my $outbg = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 20 | my $outch = chr 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # First get RGB | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 20 | ▶ | if (defined $image){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my $px = ($x - $x1) - $h_pad; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $py = ($y - $y1) - $v_pad; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my $to_l = $px < 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | my $to_t = $py < 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $to_r = $px >= $iw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my $to_b = $py >= $ih; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | if ($to_l || $to_t || $to_r || $to_b){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$to_l or $to_t or $to_r or $to_b
$to_l or $to_t or $to_r
$to_l or $to_t
MC/DC0%0/4
$to_l or $to_t or $to_r or $to_b
$to_l
$to_t
$to_r
$to_b
Truth table0%0/5
A or B or C or D
A= $to_lB= $to_tC= $to_rD= $to_b
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $r = 0xfff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $g = 0xfff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $b = 0xfff; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ($r, $g, $b, $a) = split /,/, $image->Get("pixel[$px,$py]"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $r >>= 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $g >>= 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $b >>= 4; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | #if (bitmap->has_alpha && a < 0x800) continue; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # Now get HSV from RGB | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ($hue, $sat, $val) = $self->rgb2hsv_default($r, $g, $b); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 20 | $hue = int(0x5fff * (($x-$x1) / ($x2-$x1))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 20 | $sat = int(0xfff * (($y-$y1) / ($y2-$y1))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 20 | $val = int(0xfff * (($y-$y1) / ($y2-$y1))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 20 | $val = 0x777; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # The hard work: calculate foreground and background colours, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # as well as the most appropriate character to output. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 20 | ▶ | if ($self->{solid_background}){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 20 | my $point = chr 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 20 | my $distfg = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 20 | my $distbg = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 20 | $self->{lookup_colors}->[4] = $dark_colors->[1 + $hue / 0x1000]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 20 | $self->{lookup_colors}->[5] = $light_colors->[1 + $hue / 0x1000]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 20 | $self->{lookup_colors}->[6] = $dark_colors->[$hue / 0x1000]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 20 | $self->{lookup_colors}->[7] = $light_colors->[$hue / 0x1000]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 20 | my $idx_v = ($val + $self->{dither}->get() * (0x1000 / CAA_LOOKUP_VAL) / 0x100) * (CAA_LOOKUP_VAL - 1) / 0x1000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 20 | my $idx_s = ($sat + $self->{dither}->get() * (0x1000 / CAA_LOOKUP_SAT) / 0x100) * (CAA_LOOKUP_SAT - 1) / 0x1000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 20 | my $idx_h = (($hue & 0xfff) + $self->{dither}->get() * (0x1000 / CAA_LOOKUP_HUE) / 0x100) * (CAA_LOOKUP_HUE - 1) / 0x1000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 20 | $point = $self->{hsv_distances}->[$idx_v]->[$idx_s]->[$idx_h]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 20 | $distfg = $self->HSV_DISTANCE($hue % 0xfff, $sat, $val, ($point >> 4)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 20 | $distbg = $self->HSV_DISTANCE($hue % 0xfff, $sat, $val, ($point & 0xf)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | # Sanity check due to the lack of precision in hsv_distances, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # and distbg can be > distfg because of dithering fuzziness. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | if ($distbg > $distfg){ $distbg = $distfg; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 20 | $outfg = $self->{lookup_colors}->[($point >> 4)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 20 | $outbg = $self->{lookup_colors}->[($point & 0xf)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 20 | $ch = $distbg * 2 * ($density_chars_size - 1) / ($distbg + $distfg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 20 | $ch = 4 * $ch + $self->{dither}->get() / 0x40; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 20 | ▶ | if ($ch >= scalar(@{$density_chars})){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 15 | $ch = scalar(@{$density_chars}) - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 20 | $outch = $density_chars->[$ch]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | $outbg = CAA_COLOR_BLACK; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | if ($sat < 0x200 + $self->{dither}->get() * 0x8){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | $outfg = $white_colors->[1 + ($val * 2 + $self->{dither}->get() * 0x10) / 0x1000]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | }elsif ($val > 0x800 + $self->{dither}->get() * 0x4){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $outfg = $light_colors->[($hue + $self->{dither}->get() * 0x10) / 0x1000]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $outfg = $dark_colors->[($hue + $self->{dither}->get() * 0x10) / 0x1000]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | $ch = ($val + 0x2 * $self->{dither}->get()) * 10 / 0x1000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | $ch = 4 * $ch + $self->{dither}->get() / 0x40; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $outch = $density_chars->[$ch]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | # Now output the character | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 20 | $self->{driver}->set_color($outfg, $outbg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 20 | $self->{driver}->putchar($x, $y, $outch); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 20 | $self->{dither}->increment(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 5 | $self->{driver}->fini(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | sub rgb2hsv_default { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rgb2hsv_default: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | my ($self, $r, $g, $b) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | my ($hue, $sat, $val) = (0, 0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | my $min = $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | my $max = $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | $min = $g if $min > $g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | $max = $g if $max < $g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | $min = $b if $min > $b; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | $max = $b if $max < $b; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | my $delta = $max - $min; # 0 - 0xfff | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | $val = $max; # 0 - 0xfff | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | if ($delta){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $sat = 0xfff * $delta / $max; # 0 - 0xfff | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | # Generate *hue between 0 and 0x5fff | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | if ($r == $max){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | $hue = 0x1000 + 0x1000 * ($g - $b) / $delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | }elsif ($g == $max){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $hue = 0x3000 + 0x1000 * ($b - $r) / $delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | $hue = 0x5000 + 0x1000 * ($r - $g) / $delta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | $sat = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $hue = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | return ($hue, $sat, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 2293800 | ▶ | sub HSV_DISTANCE{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
HSV_DISTANCE: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 2293800 | my ($self, $h, $s, $v, $index) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 2293800 | my $v1 = $v - $self->{hsv_palette}->[$index * 4 + 3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 2293800 | my $s1 = $s - $self->{hsv_palette}->[$index * 4 + 2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 2293800 | my $h1 = $h - $self->{hsv_palette}->[$index * 4 + 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 2293800 | ▶ | my $s2 = $self->{hsv_palette}->[$index * 4 + 3] ? CAA_HSV_YRATIO * $s1 * $s1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 2293800 | ▶ | my $h2 = $self->{hsv_palette}->[$index * 4 + 2] ? CAA_HSV_HRATIO * $h1 * $h1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 2293800 | return $self->{hsv_palette}->[$index * 4] * ((CAA_HSV_XRATIO * $v1 * $v1) + $s2 + $h2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 29 | ▶ | sub load_submodule { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_submodule: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 29 | my ($self, $module, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 29 | eval "require Image::Caa::$module"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 29 | ▶ | warn $@ if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 29 | my $obj = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 29 | eval "\$obj = new Image::Caa::$module(\$args)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 29 | ▶ | warn $@ if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 29 | ▶ | if (!$@ && defined $obj){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $@ and defined $obj
MC/DC50%1/2
not $@ and defined $obj
not $@
defined $obj
Truth table66%2/3
not(A) and B
A= not $@B= defined $obj
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 28 | return $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 1 | die "Image::Caa - Couldn't load 'Image::Caa::$module'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||