ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/arch/dev/splitter-png.pl
Revision: 1.1.1.1 (vendor branch)
Committed: Mon Feb 6 20:26:07 2006 UTC (18 years, 3 months ago) by root
Content type: text/plain
Branch: UPSTREAM, MAIN
CVS Tags: pre_first_cfarch_normalize_run, pre_second_normalise_run, post_second_normalise_run, post_normalise_revert, rel-2_82, rel-2_81, rel-2_80, UPSTREAM_2006_03_15, rel-3_0, rel-2_6, rel-2_7, rel-2_4, rel-2_5, rel-2_2, rel-2_0, rel-2_1, rel-2_72, rel-2_73, rel-2_71, rel-2_76, rel-2_77, rel-2_74, rel-2_75, rel-2_54, rel-2_55, rel-2_56, rel-2_79, UPSTREAM_2006_02_01, rel-2_53, rel-2_32, post_first_cfarch_normalize_run, UPSTREAM_2006_02_22, rel-2_90, rel-2_92, rel-2_93, rel-2_78, rel-2_61, pre_normalise_revert, rel-2_43, rel-2_42, rel-2_41, HEAD
Changes since 1.1: +0 -0 lines
Log Message:
Initial Import

File Contents

# Content
1 #!/usr/bin/perl
2
3 # File by mwedel@scruz.net to deal with splitting png's.
4 # Takes any number of files on the command line, but all the split images
5 # are dumped in the current directory.
6 # does preserve alpha channel. Tested on skree images.
7
8 $PNGSIZE=32;
9
10 for ($i=0; $i <= $#ARGV; $i++) {
11 @name = split(m#/#, $ARGV[$i]);
12 $source = $name[$#name];
13 $#name--;
14 $destdir=join(m#/#, @name);
15
16 if ($source =~ /(\w+)\.(\d)(\d)(\d)\.png/ ) {
17 $base = $1;
18 $facing = $3;
19 $animation = $4;
20 } else {
21 print STDERR "filename $source does not follow proper naming conventions - don't know how to name files - skipping\n";
22 next;
23 }
24
25 if (!open(DESC,"pngtopnm $ARGV[$i] | pnmfile |")) {
26 print STDERR "Could not run pngtopnm $source | pnmfile\n";
27 next;
28 }
29 $desc = <DESC>;
30 close(DESC);
31 $desc =~ /(\d+) by (\d+)/;
32 if ($1 == 0 || $2 == 0) {
33 print STDERR "File $ARGV[$i] - file not described properly\n";
34 next;
35 }
36 if (($1 % 32) || ($2 % 32)) {
37 print STDERR "File $ARGV[$i] not an increment of 32x32 size - size is $1x$2\n";
38 next;
39 }
40 $destx = $1/32;
41 $desty = $2/32;
42 print "File $ARGV[$i] will be split into $destx X $desty pieces\n";
43
44 $piece = 0;
45 # The order of the for loops of x and y seem non intuitive, but believe
46 # me, this does left to right, top to bottom (ie, as you read and
47 # english language book) in terms of part numbering.
48
49 for ($y=0; $y < $desty; $y++) {
50 for ($x=0; $x < $destx; $x++) {
51 $piece ++;
52 # Deal with naming convention. piece 10 should be A, A ascii
53 # code starts at 65.
54 if ($piece > 9 ) {
55 $np = chr($piece + 55);
56 } else {
57 $np = $piece;
58 }
59 $cutx = $x * 32;
60 $cuty = $y * 32;
61 system("pngtopnm -alpha $ARGV[$i] | pnmcut -left $cutx -top $cuty -width 32 -height 32 > /tmp/alpha.$$");
62 system("pngtopnm $ARGV[$i] | pnmcut -left $cutx -top $cuty -width 32 -height 32 > /tmp/png.$$");
63 system("pnmtopng -alpha /tmp/alpha.$$ /tmp/png.$$ > $base.$np$facing$animation.png");
64 }
65 }
66 # do a little cleanup
67 unlink("/tmp/alpha.$$");
68 unlink("/tmp/png.$$");
69 }