From 9820906682a80865f297c92e2f9f7ce04050901b Mon Sep 17 00:00:00 2001 From: peterm Date: Fri, 2 Feb 2001 00:02:54 +0000 Subject: [PATCH] new png splitter by peterm, works on linux. git-svn-id: svn+ssh://svn.code.sf.net/p/crossfire/code/trunk/arch@769 282e977c-c81d-0410-88c4-b93c2d0d6712 --- dev/split-png-linux.pl | 80 ++++++++++++++++++++++++++++++++++++++++++ dev/splitter.pl | 2 +- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100755 dev/split-png-linux.pl diff --git a/dev/split-png-linux.pl b/dev/split-png-linux.pl new file mode 100755 index 000000000..7af3d78cd --- /dev/null +++ b/dev/split-png-linux.pl @@ -0,0 +1,80 @@ +#!/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. + +# Modification by PeterM +# Notes: I don't really know how this script was supposed to work +# I use it like this: +# > mkdir out (makes an output directory so I don't clobber my input) +# > split-png-linux.pl file.111.png +# +# The results end up in the directory "out" + +$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 $cutx $cuty 32 32 > /tmp/alpha.$$"); + system("pngtopnm $ARGV[$i] | pnmcut $cutx $cuty 32 32 > /tmp/png.$$"); + system("pnmtopng -alpha /tmp/alpha.$$ /tmp/png.$$ > out/$base.$np$facing$animation.png"); + } + } + # do a little cleanup + unlink("/tmp/alpha.$$"); + unlink("/tmp/png.$$"); +} + +# 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.$$"); diff --git a/dev/splitter.pl b/dev/splitter.pl index 44259f8b5..2514edd1b 100644 --- a/dev/splitter.pl +++ b/dev/splitter.pl @@ -1,4 +1,4 @@ -#!/usr/local/bin/perl +#!/usr/bin/perl # by peterm@langmuir.eecs.berkeley.edu