From b2725867eabc8e872bd7de183c315427631311d1 Mon Sep 17 00:00:00 2001 From: cvs Date: Tue, 16 Jan 2001 05:35:49 +0000 Subject: [PATCH] Added file - script will split png images. MSW 2000-1-15 git-svn-id: svn+ssh://svn.code.sf.net/p/crossfire/code/trunk/arch@715 282e977c-c81d-0410-88c4-b93c2d0d6712 --- dev/splitter-png.pl | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100755 dev/splitter-png.pl diff --git a/dev/splitter-png.pl b/dev/splitter-png.pl new file mode 100755 index 000000000..c4689354d --- /dev/null +++ b/dev/splitter-png.pl @@ -0,0 +1,69 @@ +#!/usr/bin/perl + +# File by mwedel@scruz.net to deal with splitting png's. +# Takes any number of files on the command line, but all the split images +# are dumped in the current directory. +# does preserve alpha channel. Tested on skree images. + +$PNGSIZE=32; + +for ($i=0; $i <= $#ARGV; $i++) { + @name = split(m#/#, $ARGV[$i]); + $source = $name[$#name]; + $#name--; + $destdir=join(m#/#, @name); + + if ($source =~ /(\w+)\.(\d)(\d)(\d)\.png/ ) { + $base = $1; + $facing = $3; + $animation = $4; + } else { + print STDERR "filename $source does not follow proper naming conventions - don't know how to name files - skipping\n"; + next; + } + + if (!open(DESC,"pngtopnm $ARGV[$i] | pnmfile |")) { + print STDERR "Could not run pngtopnm $source | pnmfile\n"; + next; + } + $desc = ; + close(DESC); + $desc =~ /(\d+) by (\d+)/; + if ($1 == 0 || $2 == 0) { + print STDERR "File $ARGV[$i] - file not described properly\n"; + next; + } + if (($1 % 32) || ($2 % 32)) { + print STDERR "File $ARGV[$i] not an increment of 32x32 size - size is $1x$2\n"; + next; + } + $destx = $1/32; + $desty = $2/32; + print "File $ARGV[$i] will be split into $destx X $desty pieces\n"; + + $piece = 0; + # The order of the for loops of x and y seem non intuitive, but believe + # me, this does left to right, top to bottom (ie, as you read and + # english language book) in terms of part numbering. + + for ($y=0; $y < $desty; $y++) { + for ($x=0; $x < $destx; $x++) { + $piece ++; + # Deal with naming convention. piece 10 should be A, A ascii + # code starts at 65. + if ($piece > 9 ) { + $np = chr($piece + 55); + } else { + $np = $piece; + } + $cutx = $x * 32; + $cuty = $y * 32; + system("pngtopnm -alpha $ARGV[$i] | pnmcut -left $cutx -top $cuty -width 32 -height 32 > /tmp/alpha.$$"); + system("pngtopnm $ARGV[$i] | pnmcut -left $cutx -top $cuty -width 32 -height 32 > /tmp/png.$$"); + system("pnmtopng -alpha /tmp/alpha.$$ /tmp/png.$$ > $base.$np$facing$animation.png"); + } + } + # do a little cleanup + unlink("/tmp/alpha.$$"); + unlink("/tmp/png.$$"); +}