README.md edited online with Bitbucket
[swg-src.git] / tools / perllib / PaletteArgb.pm
blobfca7bbd00e321e90d67f9295dc1959105ad42adf
1 # ======================================================================
2 # PaletteArgb.pm
3 # Copyright 2003, Sony Online Entertainment
4 # All rights reserved.
5 # ======================================================================
7 package PaletteArgb;
8 use strict;
10 # ======================================================================
11 # Setup variables that can be imported by Exporter into user modules.
12 # ======================================================================
14 use vars qw(@ISA @EXPORT_OK $VERSION);
15 use Exporter;
16 $VERSION = 1.00;
17 @ISA = qw(Exporter);
19 # These symbols are okay to export if specifically requested.
20 @EXPORT_OK = qw(&getEntryCount);
22 # ======================================================================
24 my $debug = 0;
26 # ======================================================================
28 sub getEntryCount
30 # Get the full pathname for the palette.
31 my $fullPathName = shift;
32 die "Invalid fullPathName arg" unless defined($fullPathName);
34 # Open the file.
35 my $inputFile;
36 open($inputFile, '< ' . $fullPathName) or die "Failed to open palette file [$fullPathName] for reading: $!";
37 binmode($inputFile) or die "Failed to set file [$fullPathName] to binary mode: $!";
39 # Skip the first 22 bytes.
40 seek($inputFile, 22, 0) or die "Failed to seek to palette entry count position within [$fullPathName], bad palette file: $!";
42 # Collect the entry count (2 bytes starting 22 bytes in).
43 my $byteAsChar;
45 read($inputFile, $byteAsChar, 1) or die "Failed to read entry count byte from [$fullPathName]: $!";
46 my $entryCount = ord($byteAsChar);
48 read($inputFile, $byteAsChar, 1) or die "Failed to read entry count byte from [$fullPathName]: $!";
49 $entryCount += (ord($byteAsChar) << 8);
51 # Close the file.
52 close($inputFile) or die "Failed to close palette file [$fullPathName]: $!";
54 printf("palette entries: %5d; name=[%s]\n", $entryCount, $fullPathName) if $debug;
56 return $entryCount;
59 # ======================================================================