7 use Time::HiRes qw(sleep alarm);
9 use constant {DEBUG => 0};
11 our $VERSION = '2.00';
114 my ($r, $g, $b) = @_;
121 35 0 0 rgb 46 0 0 rgb ifp
123 constants => {r => $r, g => $g, b => $b},
124 }, $input)->convert(preset => 'red')->rotate(right => 90);
130 my @output; # line => cols_ascii
131 for my $y (reverse 0 .. $input->getheight-1) {
132 my $colors = $input->getsamples(y => $y);
133 for (my $x = 0; length $colors; $x++) {
134 my $pixel = substr $colors, 0, 3, '';
137 $pixel eq $_ and $match = '#', last;
139 $output[$x] .= $match;
147 my ($charmap, $width, $y1, $y2) = @_;
149 for my $y ($y1 .. $y2) {
150 # my $row = scalar $input->getsamples(y => $y);
151 my $row = $input->[$y];
152 if ($row eq '.' x $width) {
153 push @chars => ''; # next character
155 $chars[-1] .= $row; # add line
159 map { defined $charmap->{$_} ? $charmap->{$_} : '?' }
160 grep { $_ ne '' } @chars;
164 my $input = shift; # (452,6)-(639,13)
165 $input->write(file => sprintf "tests%05d.png", $i) or warn $input->errstr
167 my $stats = filter_color($input,
168 "\020\377\030", "\317\030\030", # CF1818/C81818
169 "\310\030\030", # ?/10FF18
171 my $min = getchars($stats, \%digitgreen, 7, 0, 39);
172 my $gas = getchars($stats, \%digitgreen, 7, 68, 107);
173 my $unit = getchars($stats, \%digitgreen, 7, 136, 181);
174 my @unit = split /:/, $unit, 2;
175 @unit == 2 or @unit = ('?') x 2;
176 return ($min, $gas, @unit);
180 my $input = shift; # (587,396)-(621,402)
181 $input->write(file => sprintf "testt%05d.png", $i) or warn $input->errstr
183 my $play = filter_color($input,
184 "\276\272\357", # BEBAEF
186 my $time = getchars($play, \%digittime, 6, 0, 33);
188 $time =~ /^(?:(\d):)?(\d\d):(\d\d)$/ ?
189 (defined $1 ? $1*3600 : 0) + $2*60 + $3 :
195 open my $outstats, '>', 'map.txt' or die $!;
196 my $outmap = 'map%05d.png';
199 my $map = screenshot(right=>134, left=>6, top=>348, bottom=>476);
200 $map->write(file => sprintf $outmap, $i) or warn $map->errstr;
204 my @stats = parsestats(
205 screenshot(left=>452, top=>6, right=>639, bottom=>13)
207 my ($sec, $time) = parsetimer(
208 screenshot(left=>587, right=>621, top=>396, bottom=>402)
210 $time ne '?' or next;
211 printf {$outstats} "%d:\t%s\t%s\t%s\t%s\t%s\n",
212 $i, defined $sec ? $sec : "($time)", @stats;
216 my $filename = $ARGV[0] || 's%05d.png';
218 my (@stats, $sec, $time, $map);
220 my $img = Imager->new;
221 $img->read(file => sprintf $filename, $i)
222 or warn($img->errstr), next;
225 $img->crop(left=>452, width=>187, top=>6, height=>7)
227 ($sec, $time) = parsetimer(
228 $img->crop(left=>587, width=>34, top=>396, height=>6),
230 $map = $img->crop(width=>128, height=>128, left=>6, top=>348);
232 printf {$outstats} "%d:\t%s\t%s\t%s\t%s\t%s\n",
233 $i, defined $sec ? $sec : "($time)", @stats;
234 $map->write(file => sprintf $outmap, $i) or warn $map->errstr;
238 require Imager::Screenshot;
239 import Imager::Screenshot qw(screenshot);
241 local $SIG{ALRM} = \&capturemap;
256 '-mf' => 'type=png:fps=2',
258 '-lavcopts' => 'vcodec=mpeg4:mbd=1:v4mv:vbitrate=64',
259 '-info' => 'artist=Shiar:name="StarCraft game progress"',
260 '-msglevel' => 'all=3',