Revised the Perl scripts
* 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
This commit is contained in:
parent
0f7a34ccca
commit
398e09fe9e
39
png2c.pl
39
png2c.pl
@ -1,34 +1,43 @@
|
||||
#!/usr/bin/perl
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use GD;
|
||||
|
||||
my ($out, $proto) = @ARGV;
|
||||
my ($out, $proto, $srcdir) = @ARGV;
|
||||
defined($srcdir) or $srcdir = '.';
|
||||
-d "$srcdir/icons" || die "$srcdir/icons/: directory not found";
|
||||
|
||||
open(OUT, ">$out") or die "$out: $!";
|
||||
open(PROTO, ">$proto") or die "$proto: $!";
|
||||
|
||||
for $file (<icons/*.png>) {
|
||||
next if $file =~ /char-/;
|
||||
print OUT "/**** This is a generated file - do not edit ****/\n\n";
|
||||
print PROTO "/**** This is a generated file - do not edit ****/\n\n";
|
||||
|
||||
$file =~ m#.*/(.*)\.png#;
|
||||
$base = "Icon_$1";
|
||||
for my $file (<$srcdir/icons/*.png>) {
|
||||
next if $file =~ m#/char-[^/]+$#;
|
||||
|
||||
$file =~ m#/([^/]+)\.png$#;
|
||||
my $base = "Icon_$1";
|
||||
$base =~ y/-/_/;
|
||||
|
||||
open(PNG, $file) or die "$file: $!\n";
|
||||
$img = newFromPng GD::Image(\*PNG) or die;
|
||||
my $img = newFromPng GD::Image(\*PNG) or die;
|
||||
$img->trueColor(1);
|
||||
|
||||
close PNG;
|
||||
|
||||
($width, $height) = $img->getBounds();
|
||||
my ($width, $height) = $img->getBounds();
|
||||
die "$file: $width, $height" if ($width != 24) or ($height != 24);
|
||||
|
||||
print PROTO "extern unsigned char $base\[24*24*3\];";
|
||||
print PROTO "extern unsigned char $base\[24*24*3\];\n";
|
||||
print OUT "unsigned char $base\[24*24*3] = {\n";
|
||||
|
||||
for($y = 0; $y < 24; $y++) {
|
||||
for($x = 0; $x < 24; $x++) {
|
||||
$index = $img->getPixel($x, 23-$y);
|
||||
($r, $g, $b) = $img->rgb($index);
|
||||
for(my $y = 0; $y < 24; $y++) {
|
||||
for(my $x = 0; $x < 24; $x++) {
|
||||
my $index = $img->getPixel($x, 23-$y);
|
||||
my ($r, $g, $b) = $img->rgb($index);
|
||||
if($r + $g + $b < 11) {
|
||||
($r, $g, $b) = (30, 30, 30);
|
||||
}
|
||||
@ -37,5 +46,7 @@ for $file (<icons/*.png>) {
|
||||
}
|
||||
|
||||
print OUT "};\n\n";
|
||||
|
||||
}
|
||||
|
||||
close PROTO;
|
||||
close OUT;
|
||||
|
25
pngchar2c.pl
25
pngchar2c.pl
@ -1,20 +1,29 @@
|
||||
#!/usr/bin/perl
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use GD;
|
||||
|
||||
for $file (sort <icons/char-*.png>) {
|
||||
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";
|
||||
$img = newFromPng GD::Image(\*PNG) or die;
|
||||
my $img = newFromPng GD::Image(\*PNG) or die;
|
||||
$img->trueColor(1);
|
||||
close PNG;
|
||||
|
||||
($width, $height) = $img->getBounds();
|
||||
my ($width, $height) = $img->getBounds();
|
||||
die "$file: $width, $height" if ($width != 16) or ($height != 16);
|
||||
|
||||
for($x = 0; $x < 16; $x++) {
|
||||
for($y = 0; $y < 16; $y++) {
|
||||
$index = $img->getPixel($x, $y);
|
||||
($r, $g, $b) = $img->rgb($index);
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user