
* Use "#!/usr/bin/env perl" instead of "#!/usr/bin/perl", as this is better practice (it allows e.g. /usr/local/bin/perl to work when executing via the shebang) * Use "use strict" and "use warnings" * Declare variables with "my" as required by "use strict" * Take an optional "srcdir" argument so that the scripts can find the icon files in a location other than ./icons/ -- this will make building outside of the source tree possible in the future * Add a "this is a generated file" banner to the output, so that it can be clearly recognized as a machine-generated file that should not be hand-edited * Minor regex tweaks
38 lines
907 B
Perl
38 lines
907 B
Perl
#!/usr/bin/env perl
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use GD;
|
|
|
|
my ($srcdir) = @ARGV;
|
|
defined($srcdir) or $srcdir = '.';
|
|
-d "$srcdir/icons" || die "$srcdir/icons/: directory not found";
|
|
|
|
print "/**** This is a generated file - do not edit ****/\n\n";
|
|
|
|
for my $file (sort <$srcdir/icons/char-*.png>) {
|
|
open(PNG, $file) or die "$file: $!\n";
|
|
my $img = newFromPng GD::Image(\*PNG) or die;
|
|
$img->trueColor(1);
|
|
close PNG;
|
|
|
|
my ($width, $height) = $img->getBounds();
|
|
die "$file: $width, $height" if ($width != 16) or ($height != 16);
|
|
|
|
for(my $x = 0; $x < 16; $x++) {
|
|
for(my $y = 0; $y < 16; $y++) {
|
|
my $index = $img->getPixel($x, $y);
|
|
my ($r, $g, $b) = $img->rgb($index);
|
|
if($r + $g + $b < 11) {
|
|
print " 0, ";
|
|
} else {
|
|
print "255, ";
|
|
}
|
|
}
|
|
print "\n";
|
|
}
|
|
print "\n";
|
|
}
|
|
|