Petitcom/BMP.pm

filter: Statementstmt 100% 136 / 136 Branchbran 60.4% 29 / 48 Conditioncond 48.6% 18 / 37 MC/DCmcdc 9.5% 2 / 21 Subroutinesub 100% 21 / 21 Podpod 0.0% 0 / 9 totaltotal 75.7% 206 / 272 CC 46 SCAR 19.9
CC
46
Cov
83%
_xy
16.0
DATA2BMP
8.9
Dump
7.3
CRAP 7.3
↑ Summary Petitcom.pm »
1 package Data::Petitcom::BMP;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 ▶use parent qw{Exporter};
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 our @EXPORT_OK = qw{ DATA2BMP BMP2DATA Load Dump RGB555toRGB888 RGB888toRGB555 };
8  
9 6 ▶use bytes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 ▶use constant CHR_WIDTH => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use constant CHR_SIZE => CHR_WIDTH * CHR_WIDTH;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 6 ▶use constant DEFAULT_COLORMAP => [
Subroutine BEGIN: called CC=1 SCAR=0.0
16 0x000000,0x383838,0xf81800,0xf858c0,0x0038f0,0x7838f8,0x00b8f8,0x905828,0xf8a000,0xf8c8a0,0x007800,0x00f018,0xf8e000,0xb8b8b8,0x000000,0xf8f8f8,
17 0x000000,0x282828,0x883028,0x985880,0x203880,0x604890,0x287088,0x584030,0x886028,0xa09080,0x104010,0x208030,0x887828,0x808080,0xf8f8f8,0x000000,
18 0xf8f8f8,0xf8f8c8,0xf8f898,0xf8f860,0xf8f830,0xf8f800,0xf8c8f8,0xf8c8c8,0xf8c898,0xf8c860,0xf8c830,0xf8c800,0xf898f8,0xf898c8,0xf89898,0xf89860,
19 0xf89830,0xf89800,0xf860f8,0xf860c8,0xf86098,0xf86060,0xf86030,0xf86000,0xf830f8,0xf830c8,0xf83098,0xf83060,0xf83030,0xf83000,0xf800f8,0xf800c8,
20 0xf80098,0xf80060,0xf80030,0xf80000,0xc8f8f8,0xc8f8c8,0xc8f898,0xc8f860,0xc8f830,0xc8f800,0xc8c8f8,0xc8c8c8,0xc8c898,0xc8c860,0xc8c830,0xc8c800,
21 0xc898f8,0xc898c8,0xc89898,0xc89860,0xc89830,0xc89800,0xc860f8,0xc860c8,0xc86098,0xc86060,0xc86030,0xc86000,0xc830f8,0xc830c8,0xc83098,0xc83060,
22 0xc83030,0xc83000,0xc800f8,0xc800c8,0xc80098,0xc80060,0xc80030,0xc80000,0x98f8f8,0x98f8c8,0x98f898,0x98f860,0x98f830,0x98f800,0x98c8f8,0x98c8c8,
23 0x98c898,0x98c860,0x98c830,0x98c800,0x9898f8,0x9898c8,0x989898,0x989860,0x989830,0x989800,0x9860f8,0x9860c8,0x986098,0x986060,0x986030,0x986000,
24 0x9830f8,0x9830c8,0x983098,0x983060,0x983030,0x983000,0x9800f8,0x9800c8,0x980098,0x980060,0x980030,0x980000,0x60f8f8,0x60f8c8,0x60f898,0x60f860,
25 0x60f830,0x60f800,0x60c8f8,0x60c8c8,0x60c898,0x60c860,0x60c830,0x60c800,0x6098f8,0x6098c8,0x609898,0x609860,0x609830,0x609800,0x6060f8,0x6060c8,
26 0x606098,0x606060,0x606030,0x606000,0x6030f8,0x6030c8,0x603098,0x603060,0x603030,0x603000,0x6000f8,0x6000c8,0x600098,0x600060,0x600030,0x600000,
27 0x30f8f8,0x30f8c8,0x30f898,0x30f860,0x30f830,0x30f800,0x30c8f8,0x30c8c8,0x30c898,0x30c860,0x30c830,0x30c800,0x3098f8,0x3098c8,0x309898,0x309860,
28 0x309830,0x309800,0x3060f8,0x3060c8,0x306098,0x306060,0x306030,0x306000,0x3030f8,0x3030c8,0x303098,0x303060,0x303030,0x303000,0x3000f8,0x3000c8,
29 0x300098,0x300060,0x300030,0x300000,0x00f8f8,0x00f8c8,0x00f898,0x00f860,0x00f830,0x00f800,0x00c8f8,0x00c8c8,0x00c898,0x00c860,0x00c830,0x00c800,
30 0x0098f8,0x0098c8,0x009898,0x009860,0x009830,0x009800,0x0060f8,0x0060c8,0x006098,0x006060,0x006030,0x006000,0x0030f8,0x0030c8,0x003098,0x003060,
31 0x003030,0x003000,0x0000f8,0x0000c8,0x000098,0x000060,0x000030,0xe8e8e8,0xd8d8d8,0xb8b8b8,0xa8a8a8,0x888888,0x707070,0x505050,0x404040,0x202020,
32 6 ];
33 6 ▶use constant SPRITE_SIZE => {
Subroutine BEGIN: called CC=1 SCAR=0.0
34 8 => [ 8, 16, 32 ],
35 16 => [ 8, 16, 32 ],
36 32 => [ 8, 16, 32, 64 ],
37 64 => [ 32, 64 ],
38 6 };
39  
40 27 ▶sub is_valid_width { $_[0] && $_[0] <= 256 && $_[0] % CHR_WIDTH == 0 }
Subroutine is_valid_width: called CC=3 SCAR=14.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] and $_[0] <= 256 and $_[0] % 8 == 0 27 0 27
Condition33%1/3
$_[0] and $_[0] <= 256
!ll&&!rl&&r
0027
MC/DC0%0/2
$_[0] and $_[0] <= 256
$_[0] $_[0] <= 256
Truth table33%1/3
A and B
A= $_[0]B= $_[0] <= 256
ABresult
0X0
100
111
41 27 ▶sub is_valid_height { $_[0] && $_[0] <= 192 && $_[0] % CHR_WIDTH == 0 }
Subroutine is_valid_height: called CC=3 SCAR=14.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$_[0] and $_[0] <= 192 and $_[0] % 8 == 0 27 0 27
Condition33%1/3
$_[0] and $_[0] <= 192
!ll&&!rl&&r
0027
MC/DC0%0/2
$_[0] and $_[0] <= 192
$_[0] $_[0] <= 192
Truth table33%1/3
A and B
A= $_[0]B= $_[0] <= 192
ABresult
0X0
100
111
42 14 ▶sub is_valid_spsize {
Subroutine is_valid_spsize: called CC=5 SCAR=16.1
Pod undocumented
43 14 my ($width, $height) = @_;
44 14 ▶ return unless ($width && $height);
Branch: 1 branch
BranchTrueFalseTotal
unless $width and $height 1 13 14
Condition66%2/3
$width and $height
!ll&&!rl&&r
1013
MC/DC50%1/2
$width and $height
$width $height
Truth table66%2/3
A and B
A= $widthB= $height
ABresult
0X0
100
111
45 13 ▶ for ( @{ SPRITE_SIZE->{$width} } ) { return 1 if ( $height == $_ ) }
Branch: 1 branch
BranchTrueFalseTotal
if $height == $_ 10 13 23
46 }
47  
48 10 ▶sub _xy(&;%) {
Subroutine _xy: called CC=14 SCAR=27.7
49 10 my $code = shift;
50  
51 10 my %opts = @_;
52 10 ▶ my $width = delete $opts{width} || 256;
Condition50%1/2
delete $opts{'width'} || 256
l!l
100
MC/DC0%0/1
delete $opts{'width'} || 256
delete $opts{'width'}
Truth table50%1/2
A
A= delete $opts{'width'}
Aresult
11
00
53 10 ▶ my $height = delete $opts{height} || 64;
Condition50%1/2
delete $opts{'height'} || 64
l!l
100
MC/DC0%0/1
delete $opts{'height'} || 64
delete $opts{'height'}
Truth table50%1/2
A
A= delete $opts{'height'}
Aresult
11
00
54 10 ▶ my $sp_width = delete $opts{sp_width} || 16;
Condition50%1/2
delete $opts{'sp_width'} || 16
l!l
100
MC/DC0%0/1
delete $opts{'sp_width'} || 16
delete $opts{'sp_width'}
Truth table50%1/2
A
A= delete $opts{'sp_width'}
Aresult
11
00
55 10 ▶ my $sp_height = delete $opts{sp_height} || 16;
Condition50%1/2
delete $opts{'sp_height'} || 16
l!l
100
MC/DC0%0/1
delete $opts{'sp_height'} || 16
delete $opts{'sp_height'}
Truth table50%1/2
A
A= delete $opts{'sp_height'}
Aresult
11
00
56 10 my $vflip = delete $opts{vflip};
57 10 my $debug = delete $opts{debug};
58 10 ▶ Carp::croak "invalid sp_width: $sp_width"
Branch: 1 branch
BranchTrueFalseTotal
if $sp_width > $width or $width % $sp_width 0 10 10
Condition33%1/3
$sp_width > $width or $width % $sp_width
l!l&&r!l&&!r
0010
MC/DC0%0/2
$sp_width > $width or $width % $sp_width
$sp_width > $width $width % $sp_width
Truth table33%1/3
A or B
A= $sp_width > $widthB= $width % $sp_width
ABresult
1X1
011
000
59 if ( $sp_width > $width || $width % $sp_width );
60 10 ▶ Carp::croak "invalid sp_height: $sp_height"
Branch: 1 branch
BranchTrueFalseTotal
if $sp_height > $height or $height % $sp_height 0 10 10
Condition33%1/3
$sp_height > $height or $height % $sp_height
l!l&&r!l&&!r
0010
MC/DC0%0/2
$sp_height > $height or $height % $sp_height
$sp_height > $height $height % $sp_height
Truth table33%1/3
A or B
A= $sp_height > $heightB= $height % $sp_height
ABresult
1X1
011
000
61 if ( $sp_height > $height || $height % $sp_height );
62  
63 10 my $sp_cols = $width / $sp_width;
64 10 my $sp_rows = $height / $sp_height;
65 10 my $sp_nums = $sp_cols * $sp_rows;
66 10 my $sp_size = $sp_width * $sp_height;
67  
68 10 my $chr_cols = $sp_width / CHR_WIDTH;
69 10 my $chr_rows = $sp_height / CHR_WIDTH;
70 10 my $chr_nums = $chr_cols * $chr_rows;
71  
72 10 ▶ my $flip_y = ($vflip) ? ($height - 1) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$vflip ? : 4 6 10
73 10 for my $i ( 0 .. ( $sp_nums - 1 ) ) {
74 100 my $sp_x = $i % $sp_cols * $sp_width;
75 100 my $sp_y = int( $i / $sp_cols ) * $sp_height;
76  
77 100 for my $j ( 0 .. ( $chr_nums - 1 ) ) {
78 3088 my $chr_x = $sp_x + ( $j % $chr_cols * CHR_WIDTH );
79 3088 my $chr_y = $sp_y + ( int( $j / $chr_cols ) * CHR_WIDTH );
80  
81 3088 for my $k ( 0 .. ( CHR_SIZE - 1 ) ) {
82 197632 my $x = $chr_x + ( $k % CHR_WIDTH );
83 197632 my $y = abs( $flip_y - ( $chr_y + ( int( $k / CHR_WIDTH ) ) ) );
84  
85 197632 ▶ print STDERR sprintf("(% 3d, % 3d)\n", $x, $y) if ($debug);
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 197632 197632
86  
87 197632 my $pixel = $code->( $x, $y, {
88 width => $width,
89 height => $height,
90 sp_width => $sp_width,
91 sp_height => $sp_height,
92 count => ( $sp_size * $i ) + ( CHR_SIZE * $j ) + $k,
93 } );
94 }
95  
96 }
97  
98 }
99 }
100  
101 3 ▶sub DATA2BMP {
Subroutine DATA2BMP: called CC=8 SCAR=21.9
Pod undocumented
102 3 my ($data, %opts) = @_;
103 3 ▶ my $width = delete $opts{width} || 256;
Condition50%1/2
delete $opts{'width'} || 256
l!l
30
MC/DC0%0/1
delete $opts{'width'} || 256
delete $opts{'width'}
Truth table50%1/2
A
A= delete $opts{'width'}
Aresult
11
00
104 3 ▶ Carp::croak "invalid width: $width"
Branch: 1 branch
BranchTrueFalseTotal
unless is_valid_width($width) 0 3 3
105 unless ( is_valid_width($width) );
106 3 ▶ my $height = delete $opts{height} || 64;
Condition50%1/2
delete $opts{'height'} || 64
l!l
30
MC/DC0%0/1
delete $opts{'height'} || 64
delete $opts{'height'}
Truth table50%1/2
A
A= delete $opts{'height'}
Aresult
11
00
107 3 ▶ Carp::croak "invalid height: $height"
Branch: 1 branch
BranchTrueFalseTotal
unless is_valid_height($height) 0 3 3
108 unless ( is_valid_height($height) );
109 3 ▶ my $sp_width = delete $opts{sp_width} || 16;
Condition50%1/2
delete $opts{'sp_width'} || 16
l!l
30
MC/DC0%0/1
delete $opts{'sp_width'} || 16
delete $opts{'sp_width'}
Truth table50%1/2
A
A= delete $opts{'sp_width'}
Aresult
11
00
110 3 ▶ my $sp_height = delete $opts{sp_height} || 16;
Condition50%1/2
delete $opts{'sp_height'} || 16
l!l
30
MC/DC0%0/1
delete $opts{'sp_height'} || 16
delete $opts{'sp_height'}
Truth table50%1/2
A
A= delete $opts{'sp_height'}
Aresult
11
00
111 3 ▶ Carp::croak "invalid sprite size: $sp_width x $sp_height "
Branch: 1 branch
BranchTrueFalseTotal
unless is_valid_spsize($sp_width, $sp_height) 0 3 3
112 unless( is_valid_spsize($sp_width, $sp_height ) );
113  
114 3 my @pixels;
115 65792 ▶ _xy {
Subroutine __ANON__: called CC=1 SCAR=0.0
116 65792 my ( $x, $y, $info ) = @_;
117 65792 my $index = $width * $y + $x;
118 65792 $pixels[$index] = bytes::substr $data, $info->{count}, 1;
119 }
120 3 width => $width,
121 height => $height,
122 sp_width => $sp_width,
123 sp_height => $sp_height,
124 vflip => 1,
125 debug => 0;
126  
127 return Dump(
128 width => $width,
129 height => $height,
130 3 pixels => [ map { unpack 'C', $_ } @pixels ],
131 );
132 }
133  
134 5 ▶sub BMP2DATA {
Subroutine BMP2DATA: called CC=4 SCAR=14.1
Pod undocumented
135 5 my ($raw_bmp, %opts) = @_;
136 5 ▶ my $sp_width = delete $opts{sp_width} || 16;
Condition50%1/2
delete $opts{'sp_width'} || 16
l!l
50
MC/DC0%0/1
delete $opts{'sp_width'} || 16
delete $opts{'sp_width'}
Truth table50%1/2
A
A= delete $opts{'sp_width'}
Aresult
11
00
137 5 ▶ my $sp_height = delete $opts{sp_height} || 16;
Condition50%1/2
delete $opts{'sp_height'} || 16
l!l
50
MC/DC0%0/1
delete $opts{'sp_height'} || 16
delete $opts{'sp_height'}
Truth table50%1/2
A
A= delete $opts{'sp_height'}
Aresult
11
00
138 5 ▶ Carp::croak "invalid sprite size: $sp_width x $sp_height "
Branch: 1 branch
BranchTrueFalseTotal
unless is_valid_spsize($sp_width, $sp_height) 0 5 5
139 unless( is_valid_spsize($sp_width, $sp_height ) );
140  
141 5 my $bmp = Load($raw_bmp);
142 5 my $data;
143 131328 ▶ _xy {
Subroutine __ANON__: called CC=1 SCAR=0.0
144 131328 my ( $x, $y ) = @_;
145 131328 my $offset = $bmp->{width} * ( ( $bmp->{height} - 1 ) - $y ) + $x;
146 131328 $data .= pack( 'C', $bmp->{pixels}->[$offset] );
147 }
148 width => $bmp->{width},
149 height => $bmp->{height},
150 5 sp_width => $sp_width,
151 sp_height => $sp_height,
152 debug => 0;
153  
154 5 return $data;
155 }
156  
157 19 ▶sub Load {
Subroutine Load: called CC=7 SCAR=19.7
Pod undocumented
158 19 my $raw_bmp = shift;
159  
160 19 my @file_header = unpack 'a2VvvV', bytes::substr( $raw_bmp, 0, 14 );
161 19 my $type = $file_header[0];
162 19 ▶ Carp::croak "invalid type: $type"
Branch: 1 branch
BranchTrueFalseTotal
if $type ne "BM" 0 19 19
163 if ( $type ne 'BM' );
164  
165 19 my @info_header = unpack 'VVVvvVVVVVV', bytes::substr( $raw_bmp, 0x0E, 40 );
166 19 my $width = $info_header[1];
167 19 ▶ Carp::croak "invalid width: $width"
Branch: 1 branch
BranchTrueFalseTotal
unless is_valid_width($width) 0 19 19
168 unless ( is_valid_width($width) );
169 19 my $height = $info_header[2];
170 19 ▶ Carp::croak "invalid height: $height"
Branch: 1 branch
BranchTrueFalseTotal
unless is_valid_height($height) 0 19 19
171 unless ( is_valid_height($height) );
172 19 my $bit = $info_header[4];
173 19 ▶ Carp::croak "invalid bit: $bit"
Branch: 1 branch
BranchTrueFalseTotal
if $bit != 8 0 19 19
174 if ( $bit != 8 );
175  
176 19 my @colormap = unpack 'V*', bytes::substr( $raw_bmp, 0x36, 256 * 4 );
177 19 my @pixels = unpack 'C*', bytes::substr( $raw_bmp, 0x0436, $width * $height );
178 19 ▶ if ( my $lack = ( $width * $height ) - @pixels ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lack = $width * $height - @pixels) 6 13 19
179 6 push @pixels, 0x00 for ( 1 .. $lack );
180 }
181  
182 return +{
183 19 width => $width,
184 height => $height,
185 colormap => \@colormap,
186 pixels => \@pixels,
187 };
188 }
189  
190 5 ▶sub Dump {
Subroutine Dump: called CC=7 SCAR=19.9
Pod undocumented
191 5 ▶ my $bmp = ( ref $_[0] eq 'HASH' ) ? shift : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 5 5
192  
193 5 my $width = delete $bmp->{width};
194 5 ▶ Carp::croak "invalid width: $width"
Branch: 1 branch
BranchTrueFalseTotal
unless is_valid_width($width) 0 5 5
195 unless ( is_valid_width($width) );
196 5 my $height = delete $bmp->{height};
197 5 ▶ Carp::croak "invalid height: $height"
Branch: 1 branch
BranchTrueFalseTotal
unless is_valid_height($height) 0 5 5
198 unless ( is_valid_height($height) );
199 5 ▶ my $colormap = delete $bmp->{colormap} || DEFAULT_COLORMAP;
Condition100%2/2
delete $bmp->{'colormap'} || [0, 3684408, 16259072, 16275648, 14576, 7878904, 47352, 9459752, 16293888, 16304288, 30720, 61464, 16310272, 12105912, 0, 16316664, 0, 2631720, 8925224, 9984128, 2111616, 6310032, 2650248, 5783600, 8937512, 10522752, 1064976, 2129968, 8943656, 8421504, 16316664, 0, 16316664, 16316616, 16316568, 16316512, 16316464, 16316416, 16304376, 16304328, 16304280, 16304224, 16304176, 16304128, 16292088, 16292040, 16291992, 16291936, 16291888, 16291840, 16277752, 16277704, 16277656, 16277600, 16277552, 16277504, 16265464, 16265416, 16265368, 16265312, 16265264, 16265216, 16253176, 16253128, 16253080, 16253024, 16252976, 16252928, 13170936, 13170888, 13170840, 13170784, 13170736, 13170688, 13158648, 13158600, 13158552, 13158496, 13158448, 13158400, 13146360, 13146312, 13146264, 13146208, 13146160, 13146112, 13132024, 13131976, 13131928, 13131872, 13131824, 13131776, 13119736, 13119688, 13119640, 13119584, 13119536, 13119488, 13107448, 13107400, 13107352, 13107296, 13107248, 13107200, 10025208, 10025160, 10025112, 10025056, 10025008, 10024960, 10012920, 10012872, 10012824, 10012768, 10012720, 10012672, 10000632, 10000584, 10000536, 10000480, 10000432, 10000384, 9986296, 9986248, 9986200, 9986144, 9986096, 9986048, 9974008, 9973960, 9973912, 9973856, 9973808, 9973760, 9961720, 9961672, 9961624, 9961568, 9961520, 9961472, 6355192, 6355144, 6355096, 6355040, 6354992, 6354944, 6342904, 6342856, 6342808, 6342752, 6342704, 6342656, 6330616, 6330568, 6330520, 6330464, 6330416, 6330368, 6316280, 6316232, 6316184, 6316128, 6316080, 6316032, 6303992, 6303944, 6303896, 6303840, 6303792, 6303744, 6291704, 6291656, 6291608, 6291552, 6291504, 6291456, 3209464, 3209416, 3209368, 3209312, 3209264, 3209216, 3197176, 3197128, 3197080, 3197024, 3196976, 3196928, 3184888, 3184840, 3184792, 3184736, 3184688, 3184640, 3170552, 3170504, 3170456, 3170400, 3170352, 3170304, 3158264, 3158216, 3158168, 3158112, 3158064, 3158016, 3145976, 3145928, 3145880, 3145824, 3145776, 3145728, 63736, 63688, 63640, 63584, 63536, 63488, 51448, 51400, 51352, 51296, 51248, 51200, 39160, 39112, 39064, 39008, 38960, 38912, 24824, 24776, 24728, 24672, 24624, 24576, 12536, 12488, 12440, 12384, 12336, 12288, 248, 200, 152, 96, 48, 15263976, 14211288, 12105912, 11053224, 8947848, 7368816, 5263440, 4210752, 2105376]
l!l
14
MC/DC100%1/1
delete $bmp->{'colormap'} || [0, 3684408, 16259072, 16275648, 14576, 7878904, 47352, 9459752, 16293888, 16304288, 30720, 61464, 16310272, 12105912, 0, 16316664, 0, 2631720, 8925224, 9984128, 2111616, 6310032, 2650248, 5783600, 8937512, 10522752, 1064976, 2129968, 8943656, 8421504, 16316664, 0, 16316664, 16316616, 16316568, 16316512, 16316464, 16316416, 16304376, 16304328, 16304280, 16304224, 16304176, 16304128, 16292088, 16292040, 16291992, 16291936, 16291888, 16291840, 16277752, 16277704, 16277656, 16277600, 16277552, 16277504, 16265464, 16265416, 16265368, 16265312, 16265264, 16265216, 16253176, 16253128, 16253080, 16253024, 16252976, 16252928, 13170936, 13170888, 13170840, 13170784, 13170736, 13170688, 13158648, 13158600, 13158552, 13158496, 13158448, 13158400, 13146360, 13146312, 13146264, 13146208, 13146160, 13146112, 13132024, 13131976, 13131928, 13131872, 13131824, 13131776, 13119736, 13119688, 13119640, 13119584, 13119536, 13119488, 13107448, 13107400, 13107352, 13107296, 13107248, 13107200, 10025208, 10025160, 10025112, 10025056, 10025008, 10024960, 10012920, 10012872, 10012824, 10012768, 10012720, 10012672, 10000632, 10000584, 10000536, 10000480, 10000432, 10000384, 9986296, 9986248, 9986200, 9986144, 9986096, 9986048, 9974008, 9973960, 9973912, 9973856, 9973808, 9973760, 9961720, 9961672, 9961624, 9961568, 9961520, 9961472, 6355192, 6355144, 6355096, 6355040, 6354992, 6354944, 6342904, 6342856, 6342808, 6342752, 6342704, 6342656, 6330616, 6330568, 6330520, 6330464, 6330416, 6330368, 6316280, 6316232, 6316184, 6316128, 6316080, 6316032, 6303992, 6303944, 6303896, 6303840, 6303792, 6303744, 6291704, 6291656, 6291608, 6291552, 6291504, 6291456, 3209464, 3209416, 3209368, 3209312, 3209264, 3209216, 3197176, 3197128, 3197080, 3197024, 3196976, 3196928, 3184888, 3184840, 3184792, 3184736, 3184688, 3184640, 3170552, 3170504, 3170456, 3170400, 3170352, 3170304, 3158264, 3158216, 3158168, 3158112, 3158064, 3158016, 3145976, 3145928, 3145880, 3145824, 3145776, 3145728, 63736, 63688, 63640, 63584, 63536, 63488, 51448, 51400, 51352, 51296, 51248, 51200, 39160, 39112, 39064, 39008, 38960, 38912, 24824, 24776, 24728, 24672, 24624, 24576, 12536, 12488, 12440, 12384, 12336, 12288, 248, 200, 152, 96, 48, 15263976, 14211288, 12105912, 11053224, 8947848, 7368816, 5263440, 4210752, 2105376]
delete $bmp->{'colormap'}
Truth table100%2/2
A
A= delete $bmp->{'colormap'}
Aresult
11
00
200 5 ▶ Carp::croak "invalid colormap: " . scalar @$colormap
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$colormap != 256 0 5 5
201 if ( scalar @$colormap != 256 );
202 5 my $pixels = delete $bmp->{pixels};
203 5 ▶ Carp::croak "pixels mismatch: " . scalar @$pixels
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$pixels != $width * $height 0 5 5
204 if ( scalar @$pixels != $width * $height );
205  
206 5 my $size = 14 + 40 + 256 * 4 + $width * $height;
207 5 my $raw_bmp = pack 'a2VvvV', "BM", $size, 0, 0, 14 + 40;
208 5 $raw_bmp .= pack "VVVvvVVVVVV", 40, $width, $height, 1, 8, 0, 0, 0, 0, 0, 0;
209 5 $raw_bmp .= pack 'V*', @$colormap;
210 5 $raw_bmp .= pack 'C*', @$pixels;
211  
212 5 return $raw_bmp;
213 }
214  
215 6 ▶sub RGB888toRGB555 {
Subroutine RGB888toRGB555: called CC=2 SCAR=6.9
Pod undocumented
216 6 ▶ my $rgb888 = (ref $_[0] eq 'ARRAY') ? shift : [ @_ ];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 1 5 6
217 my @rgb555 = map {
218 6 my $rgb = $_;
219 261 my ( $r, $g, $b ) = map { $_ >> 3 } (
220 ($rgb >> 16 ) & 0xFF,
221 ($rgb >> 8 ) & 0xFF,
222 $rgb & 0xFF,
223 );
224 # Unused(1), Blue(5), Green(5), Red(5)
225 261 ( $b << 10 ) | ( $g << 5 ) | $r;
226 } @$rgb888;
227 6 return \@rgb555;
228 }
229  
230 6 ▶sub RGB555toRGB888 {
Subroutine RGB555toRGB888: called CC=2 SCAR=7.0
Pod undocumented
231 6 ▶ my $rgb555 = (ref $_[0] eq 'ARRAY') ? shift : [ @_ ];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 0 6 6
232 my @rgb888 = map {
233 6 my $rgb = $_;
234 261 my ($r, $g, $b) = map { $_ << 3 | $_ >> 2 } (
235 $rgb & 0x1F,
236 ($rgb >> 5) & 0x1F,
237 ($rgb >> 10) & 0x1F,
238 );
239 # Reserved(8), Red(8), Green(8), Blue(8)
240 261 ($r << 16) | ($g << 8) | $b;
241 } @$rgb555;
242 6 return \@rgb888;
243 }
244  
245  
246  
247 6 1;
↑ Summary Petitcom.pm »