2013-08-26 21:45:09 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2009-01-02 10:38:36 +00:00
|
|
|
|
|
|
|
use GD;
|
|
|
|
|
2013-08-26 21:45:09 +00:00
|
|
|
my ($out, $proto, $srcdir) = @ARGV;
|
|
|
|
defined($srcdir) or $srcdir = '.';
|
|
|
|
-d "$srcdir/icons" || die "$srcdir/icons/: directory not found";
|
|
|
|
|
2010-05-03 05:04:42 +00:00
|
|
|
open(OUT, ">$out") or die "$out: $!";
|
|
|
|
open(PROTO, ">$proto") or die "$proto: $!";
|
|
|
|
|
2013-08-26 21:45:09 +00:00
|
|
|
print OUT "/**** This is a generated file - do not edit ****/\n\n";
|
|
|
|
print PROTO "/**** This is a generated file - do not edit ****/\n\n";
|
|
|
|
|
|
|
|
for my $file (<$srcdir/icons/*.png>) {
|
|
|
|
next if $file =~ m#/char-[^/]+$#;
|
2010-05-09 01:20:02 +00:00
|
|
|
|
2013-08-26 21:45:09 +00:00
|
|
|
$file =~ m#/([^/]+)\.png$#;
|
|
|
|
my $base = "Icon_$1";
|
2009-01-02 10:38:36 +00:00
|
|
|
$base =~ y/-/_/;
|
|
|
|
|
|
|
|
open(PNG, $file) or die "$file: $!\n";
|
2013-08-26 21:45:09 +00:00
|
|
|
my $img = newFromPng GD::Image(\*PNG) or die;
|
2009-01-02 10:38:36 +00:00
|
|
|
$img->trueColor(1);
|
|
|
|
|
|
|
|
close PNG;
|
|
|
|
|
2013-08-26 21:45:09 +00:00
|
|
|
my ($width, $height) = $img->getBounds();
|
2009-01-02 10:38:36 +00:00
|
|
|
die "$file: $width, $height" if ($width != 24) or ($height != 24);
|
|
|
|
|
2013-08-26 21:45:09 +00:00
|
|
|
print PROTO "extern unsigned char $base\[24*24*3\];\n";
|
2010-05-03 05:04:42 +00:00
|
|
|
print OUT "unsigned char $base\[24*24*3] = {\n";
|
2009-01-02 10:38:36 +00:00
|
|
|
|
2013-08-26 21:45:09 +00:00
|
|
|
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);
|
2009-01-02 10:38:36 +00:00
|
|
|
if($r + $g + $b < 11) {
|
|
|
|
($r, $g, $b) = (30, 30, 30);
|
|
|
|
}
|
2010-05-03 05:04:42 +00:00
|
|
|
printf OUT " 0x%02x, 0x%02x, 0x%02x,\n", $r, $g, $b;
|
2009-01-02 10:38:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-03 05:04:42 +00:00
|
|
|
print OUT "};\n\n";
|
2009-01-02 10:38:36 +00:00
|
|
|
}
|
2013-08-26 21:45:09 +00:00
|
|
|
|
|
|
|
close PROTO;
|
|
|
|
close OUT;
|