ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/adm/collect_images.pl
Revision: 1.2
Committed: Sun Oct 8 16:51:51 2006 UTC (17 years, 9 months ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-2_82, rel-2_81, rel-2_80, rel-3_1, rel-3_0, rel-2_6, rel-2_7, rel-2_4, rel-2_5, rel-2_2, rel-2_3, 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, rel-2_52, rel-2_53, rel-2_32, rel-2_90, rel-2_92, rel-2_93, rel-2_78, rel-2_61, rel-2_43, rel-2_42, rel-2_41, HEAD
Changes since 1.1: +3 -1 lines
Log Message:
considerably reduce size of crossfire.0 (~400k pngx, ~150k file format)

File Contents

# User Rev Content
1 root 1.1 #!/usr/bin/perl
2     #
3     # this script goes through and collects the various image sets into crossfire-x.png
4     # files, where x is the numbers from the image_info file. This
5     # collects all the images at once, whether or not they have
6     # been changed or not.
7    
8     # This script collects all the images. If given a -archive option, it
9     # does some additional work - checksumming the images, making a bmaps.client
10     # file, and then tarring that data up. This data can then be used on the
11     # client as a fast way to 'bootstrap' the clients images.
12    
13     use FileHandle;
14    
15     die("No arch directory - will not rebuild $mode image file") if (! -e "arch");
16    
17     $archive = 0;
18     $TMPDIR="/tmp";
19    
20     # What we will call the collection of images.
21     $ARCHNAME="crossfire-images";
22     $DESTDIR="$TMPDIR/$ARCHNAME";
23    
24     # Maximum expected file
25     $MAXFILESIZE=100000;
26    
27     if ($ARGV[0] eq "-archive") {
28     $archive =1;
29     print "Will generate appropriate files for image archive\n";
30     die("$DESTDIR already exists - remove if you really want to remake the images") if (-d $DESTDIR);
31     die("$0: unable to mkdir $DESTDIR: $1\n") if (!mkdir($DESTDIR, 0755));
32     }
33    
34     open(IMAGEINFO,"image_info") || die("Can't open image_info file: $!\n");
35     while (<IMAGEINFO>) {
36     # Ignore lines that start with comments or just empty lines
37     next if /^#/;
38     next if /^\s*$/;
39     ($setnum, $ext, @rest) = split /:/;
40     # We don't actually need that data in this script, but may as well do sanity
41     # checking.
42     if ($#rest != 4) {
43     print STDERR "image_info: line is corrupt:\n$_";
44     }
45     if ($extension[$setnum]) {
46     print STDERR "Warning: set $setnum is duplicated in image_info file\n";
47     }
48     $extension[$setnum] = $ext;
49     }
50     close(IMAGEINFO);
51    
52    
53     for ($count=0; $count<=$#extension; $count++) {
54     $ESRV[$count] = new FileHandle;
55     $fh = $ESRV[$count];
56     open($fh, ">crossfire.$count") ||
57     die("Can't open crossfire.$count for write: $!\n");
58     binmode( $fh );
59     }
60    
61     open(BMAPS,"bmaps.paths") || die("Can't open bmaps.paths: $!\n");
62     $_ = <BMAPS>;
63     while(<BMAPS>) {
64     chop;
65    
66     # we need to insert the extension for the images between the name
67     # and the number (.171 or whatever) extension, so split on that.
68    
69     die("Unknown line: '$_'\n") unless /^\\(\d{5})\s+(\S+)\.(\w\w\w)$/o;
70     $num = $1;
71     $file = $2;
72     $file1 = $3;
73    
74     print "$num $file\n" if ($num % 500) == 0 ;
75     # This probably isn't the most efficient way to do this if a
76     # large number of images are added, as we try to open each
77     # instance.
78     # OTOH, we are doing one directory
79     # at a time, so we should be hitting the DNLC at a very high
80     # rate.
81    
82     for ($count=0; $count<=$#extension; $count++) {
83     $filename = "$file.$extension[$count].$file1.png";
84     $fh = $ESRV[$count];
85    
86     $length = -s "$filename";
87     if (open(FILE,"$filename")) {
88     binmode( FILE );
89 root 1.2 my $path = "$file.$file1";
90     $path =~ s/.*\///;
91     printf $fh "IMAGE %d %d %s\n", $num, $length, $path;
92 root 1.1 print "Error reading file $filename" if (!read(FILE, $buf, $length));
93     $position = tell $fh;
94     print $fh $buf;
95     close(FILE);
96    
97     if ($archive) {
98     # Now figure out the checksum
99     # Same as what is used for the client/server - code basically
100     # taken write form that.
101     $sum = 0;
102     for ($i=0; $i<$length; $i++) {
103     if ($sum & 01) {
104     $sum = ($sum >> 1) | 0x80000000;
105     } else {
106     $sum >>= 1;
107     }
108     $sum += ord(substr $buf, $i, 1);
109     $sum &= 0xffffffff;
110     }
111     # Do some name translation to figure out our output file name.
112     @comps = split /\//, $file;
113     $destfile = $comps[$#comps];
114     push @csums, "$destfile.$file1 $sum crossfire.$extension[$count]\@$position:$length\n";
115     } # if archive
116     }
117     elsif ($count==0) {
118     # set 0 should have all the sets
119     print "Error: Image $filename not found for set 0!\n";
120     }
121    
122     }
123     }
124     for ($count=0; $count<=$#extension; $count++) {
125     close($ESRV[$count]);
126     }
127     close(BMAPS);
128    
129     if ($archive) {
130     open(OUT,">$DESTDIR/bmaps.client") || die("Can not open $DESTDIR/bmaps.paths\n");
131     print OUT sort @csums;
132     close(OUT);
133     open(OUT,">$DESTDIR/README") || die("Can not open $DESTDIR/README\n");
134     print OUT "These image files for the client should be located in\n";
135     print OUT "\$prefix/share/crossfire-client. \$prefix is the location given in the -prefix\n";
136     print OUT "option when configure is run to build the client. The default is /usr/local.\n";
137     print OUT "In that case these files should be put in /usr/local/share/crossfire-client\n";
138     print OUT "The client will print a messgae if it is unable to find the image information\n";
139     print OUT "with the location is looked for them.\n";
140     close(OUT);
141    
142     for ($count=0; $count<=$#extension; $count++) {
143     system("cp crossfire.$count $DESTDIR/crossfire.$extension[$count]");
144     }
145     system("cd $DESTDIR; tar cf $TMPDIR/$ARCHNAME.tar .");
146     system("mv $TMPDIR/$ARCHNAME.tar ../");
147     system("rm -rf $TMPDIR/$ARCHNAME");
148     }