#!/usr/bin/perl -w use strict; # S'assurer qu'il y a bien 4 argument my $num_args = $#ARGV + 1; if ($num_args != 4) { print "\nUsage: extractor tga_file txt_file tga_width tga_height\n"; exit; } my $tgafile=$ARGV[0]; # nom du fichier tga de texture my $txtfile=$ARGV[1]; # nom du fichier txt listant les icones my $w=$ARGV[2]; # largeur de l'image tga ( normalement 1024 ) my $h=$ARGV[3]; # hauteur de l'image tga ( normalement 1024 ) # fonction qui arrondit un nombre à la valeur entière la plus proche sub round { $_[0] > 0 ? int($_[0] + .5) : -int(-$_[0] + .5) } # Ouvrir le fichier txt pour lister les icones open(TXT, $txtfile) or die ("Coud not open the '$txtfile' file\n"); my $line ; foreach $line () { chomp $line ; # spliter une ligne en éléments séparés par des espaces my @array = split(/\s+/, $line); if ( scalar @array == 5 ) { my $iconname = $array[0]; # premier élément de la ligne, nom de l'icone my $x1 = round($array[1]*$w); # coin supérieur gauche ( x ) my $y1 = round($array[2]*$h); # coin supérieur gauche ( y ) my $x2 = round($array[3]*$w); # coin inférieur droit ( x ) my $y2 = round($array[4]*$h); # coin inférieur droit ( y ) my $ww = $x2-$x1+1 ; # largeur de l'image icone my $hh = $y2-$y1+1 ; # hauteur de l'image icone print "extraction de l'icone '$iconname' en ${ww}x${hh}+${x1}+${y1}\n" ; system ("convert -extract ${ww}x${hh}+${x1}+${y1} $tgafile $iconname") ; } else { print "invalid line : \"$line\"\n" ; } }