Author: esr
Date: Fri Mar 21 10:03:36 2008
New Revision: 24929
URL: http://svn.gna.org/viewcvs/wesnoth?rev=24929&view=rev
Log:
TeamColorsizer cleaned up and moves to Python.
Added:
trunk/data/tools/unit_tree/TeamColorizer
- copied, changed from r24908, trunk/data/tools/unit_tree/TeamColorizer.pl
Modified:
trunk/data/tools/unit_tree/units.pl
Copied: trunk/data/tools/unit_tree/TeamColorizer (from r24908,
trunk/data/tools/unit_tree/TeamColorizer.pl)
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/unit_tree/TeamColorizer?p2=trunk/data/tools/unit_tree/TeamColorizer&p1=trunk/data/tools/unit_tree/TeamColorizer.pl&r1=24908&r2=24929&rev=24929&view=diff
==============================================================================
--- trunk/data/tools/unit_tree/TeamColorizer.pl (original)
+++ trunk/data/tools/unit_tree/TeamColorizer Fri Mar 21 10:03:36 2008
@@ -1,68 +1,98 @@
-#!/usr/bin/perl -w
+#!/usr/bin/env python
+"""
+TeamColorizer
-if($#ARGV !=1){
- die"TeamColorizer.pl input-file output-file\n";
-}
-$infilename=shift(@ARGV);
-$outfilename=shift(@ARGV);
+TeamColorize input output
-$team_red=255;
-$team_green=0;
-$team_blue=0;
-$team_red_max=255;
-$team_green_max=255;
-$team_blue_max=255;
-$team_red_min=0;
-$team_green_min=0;
-$team_blue_min=0;
+Map the magenta team-color patches in the input image to red in the
+output image, copy the result to output.
+"""
-$flag_rgb="244,154,193,63,0,22,85,0,42,105,0,57,123,0,69,140,0,81,158,0,93,177,0,105,195,0,116,214,0,127,236,0,140,238,61,150,239,91,161,241,114,172,242,135,182,246,173,205,248,193,217,250,213,229,253,233,241";
-#$flag_rgb="236,0,140,244,154,193,63,0,22,85,0,42,105,0,57,123,0,69,140,0,81,158,0,93,177,0,105,195,0,116,214,0,127,238,61,150,239,91,161,241,114,172,242,135,182,246,173,205,248,193,217,250,213,229,253,233,241";
+import sys,getopt
[EMAIL PROTECTED](/,/,$flag_rgb);
+team_red=255
+team_green=0
+team_blue=0
+team_red_max=255
+team_green_max=255
+team_blue_max=255
+team_red_min=0
+team_green_min=0
+team_blue_min=0
-if($#flag<3){die "error, flag_rgb not well defined";}
+flag_rgb=((244,154,193),
+ (63,0,22),
+ (85,0,42),
+ (105,0,57),
+ (123,0,69),
+ (140,0,81),
+ (158,0,93),
+ (177,0,105),
+ (195,0,116),
+ (214,0,127),
+ (236,0,140),
+ (238,61,150),
+ (239,91,161),
+ (241,114,172),
+ (242,135,182),
+ (246,173,205),
+ (248,193,217),
+ (250,213,229),
+ #(253,233,241), # Perl version didn't use this
+ )
-$base_red=$flag[0];
-$base_green=$flag[1];
-$base_blue=$flag[2];
-$base_sum=$base_red+$base_green+$base_blue;
+base_red = flag_rgb[0][0]
+base_green = flag_rgb[0][1]
+base_blue = flag_rgb[0][2]
+base_sum = base_red+base_green+base_blue
-while($#flag>2){
- $red=shift(@flag);
- $green=shift(@flag);
- $blue=shift(@flag);
- $old_rgb=sprintf("%lx", $red*256*256+$green*256+$blue);
+convertor = "convert "
+for (red, green, blue) in flag_rgb:
+ sum=red+green+blue
+ if sum <= base_sum:
+ ratio = (sum * 1.0)/base_sum
+ new_red = int(team_red*ratio+team_red_min*(1-ratio))
+ new_green = int(team_green*ratio+team_green_min*(1-ratio))
+ new_blue = int(team_blue*ratio+team_blue_min*(1-ratio))
+ else:
+ ratio=(base_sum * 1.0)/sum
+ new_red = int(team_red*ratio+team_red_max*(1-ratio))
+ new_green = int(team_green*ratio+team_green_max*(1-ratio))
+ new_blue = int(team_blue*ratio+team_blue_max*(1-ratio))
- $sum=$red+$green+$blue;
- if($sum<=$base_sum){
- $ratio=$sum/$base_sum;
- $new_red=$team_red*$ratio+$team_red_min*(1-$ratio);
- $new_green=$team_green*$ratio+$team_green_min*(1-$ratio);
- $new_blue=$team_blue*$ratio+$team_blue_min*(1-$ratio);
- }else{
- $ratio=$base_sum/$sum;
- $new_red=$team_red*$ratio+$team_red_max*(1-$ratio);
- $new_green=$team_green*$ratio+$team_green_max*(1-$ratio);
- $new_blue=$team_blue*$ratio+$team_blue_max*(1-$ratio);
- }
- $new_red=sprintf("%d",$new_red);
- $new_green=sprintf("%d",$new_green);
- $new_blue=sprintf("%d",$new_blue);
- $new_rgb=sprintf("%lx", $new_red*256*256+$new_green*256+$new_blue);
+ # print "red: red\tgreen: green\tblue: blue\told_rgb\n"
+ # print "\tred: new_red\tgreen: new_green\tblue: new_blue\tnew_rgb\n"
+ convertor += " -fill \"#%02x%02x%02x\" -opaque \"#%02x%02x%02x\"" \
+ % (new_red, new_green, new_blue,
+ red, green, blue)
-# print "red: $red\tgreen: $green\tblue: $blue\t$old_rgb\n";
-# print "\tred: $new_red\tgreen: $new_green\tblue: $new_blue\t$new_rgb\n";
- $fill_cmd="-fill \"#$new_rgb\" -opaque \"#$old_rgb\"";
-# print "$fill_cmd\n";
- push(@fill,$fill_cmd);
-}
-$convert="convert ";
-foreach(@fill){
-# print "$_";
- $convert="$convert $_";
-}
-$convert = "$convert $infilename $outfilename";
-#print "$convert\n";
-system($convert);
+if __name__ == '__main__':
+ (options, arguments) = getopt.getopt(sys.argv[1:], "h?dv",
+ ['help', 'dryrun', 'verbose'])
+ verbose = 0
+ dryrun = False
+ exclude = []
+ for (opt, val) in options:
+ if opt in ('-?', '-h', '--help'):
+ print __doc__
+ sys.exit(0)
+ elif opt in ('-d', '--dryrun'):
+ dryrun = True
+ verbose += 1
+ elif opt in ('-v', '--verbose'):
+ verbose += 1
+
+ if len(arguments) != 2:
+ print "usage: TeamColorizer [-h] [-d] [-v] input-file output-file";
+ sys.exit(1)
+ else:
+ (infilename, outfilename) = arguments
+
+ convertor + " " + infilename + " " + outfilename
+ if verbose:
+ print convertor
+ if not dryrun:
+ os.system(convertor)
+
+# TeamColorizer ends here.
Modified: trunk/data/tools/unit_tree/units.pl
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/unit_tree/units.pl?rev=24929&r1=24928&r2=24929&view=diff
==============================================================================
--- trunk/data/tools/unit_tree/units.pl (original)
+++ trunk/data/tools/unit_tree/units.pl Fri Mar 21 10:03:36 2008
@@ -6,14 +6,14 @@
# anim_header.html: Template for the header of the report of animations made
# index_base.html: Index page that will be presented, in case translations
are not selected
# index_languages.html: Index page that will be presented, in case
translations are selected
-# TeamColorizer.pl: Script created by Darth Fool, to change the magenta
color of the units pngs
+# TeamColorizer: Script created by Darth Fool, to change the magenta color
of the units pngs
# tree_fact_header.html: Template for the header of the tree by faction
# tree_footer.html: Template for the footer of the unit trees
# tree_header.html: Template for the header of the unit trees, except the
ones by race of faction
# tree_race_header.html: Template for the header of the tree by race
# unit.html: Template for the unit page
# units.css: Style file for all the html pages
-# For converting the images using the TeamColorizer.pl script, ImageMagik must
be installed,
+# For converting the images using the TeamColorizer script, ImageMagik must be
installed,
# and the convert utility accessible from the console
# The Perl module Locale::Maketext::Gettext is required for the translations,
the latest version can be found at CPAN (http://cpan.org)
# If the translation is not going to be used, the line use
Locale::Maketext::Gettext; can be commented to avoid installing the module
@@ -600,7 +600,7 @@
}
# Unit images
open (UNITS, "$report_dir/units.txt") or die "Couldn't open units.txt:
$!\n";
- my $colorizer = "TeamColorizer.pl";
+ my $colorizer = "TeamColorizer";
$colorizer = './' . $colorizer unless $windows;
while (<UNITS>) {
chomp;
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits