Panda3D
eggListTextures.cxx
1 // Filename: eggListTextures.cxx
2 // Created by: drose (23May05)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "eggListTextures.h"
16 #include "eggTextureCollection.h"
17 #include "pnmImageHeader.h"
18 #include "pystub.h"
19 
20 ////////////////////////////////////////////////////////////////////
21 // Function: EggListTextures::Constructor
22 // Access: Public
23 // Description:
24 ////////////////////////////////////////////////////////////////////
25 EggListTextures::
26 EggListTextures() {
27  set_program_brief("list textures referenced by an .egg file");
28  set_program_description
29  ("egg-list-textures reads an egg file and writes a list of the "
30  "textures it references. It is particularly useful for building "
31  "up the textures.txa file used for egg-palettize, since the output "
32  "format is crafted to be compatible with that file's input format.");
33 }
34 
35 ////////////////////////////////////////////////////////////////////
36 // Function: EggListTextures::run
37 // Access: Public
38 // Description:
39 ////////////////////////////////////////////////////////////////////
40 void EggListTextures::
41 run() {
42  if (!do_reader_options()) {
43  exit(1);
44  }
45 
47  tc.find_used_textures(_data);
49  tc.collapse_equivalent_textures(EggTexture::E_complete_filename, treplace);
50  tc.sort_by_basename();
51 
52  EggTextureCollection::iterator ti;
53  for (ti = tc.begin(); ti != tc.end(); ++ti) {
54  Filename fullpath = (*ti)->get_fullpath();
55  PNMImageHeader header;
56  if (header.read_header(fullpath)) {
57  cout << fullpath.get_basename() << " : "
58  << header.get_x_size() << " " << header.get_y_size() << "\n";
59  } else {
60  cout << fullpath.get_basename() << " : unknown\n";
61  }
62  }
63 }
64 
65 
66 int main(int argc, char *argv[]) {
67  // A call to pystub() to force libpystub.so to be linked in.
68  pystub();
69 
70  EggListTextures prog;
71  prog.parse_command_line(argc, argv);
72  prog.run();
73  return 0;
74 }
string get_basename() const
Returns the basename part of the filename.
Definition: filename.I:436
int collapse_equivalent_textures(int eq, EggGroupNode *node)
Walks through the collection and collapses together any separate textures that are equivalent accordi...
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
string get_fullpath() const
Returns the entire filename: directory, basename, extension.
Definition: filename.I:398
virtual void parse_command_line(int argc, char **argv)
Dispatches on each of the options on the command line, and passes the remaining parameters to handle_...
This is a collection of textures by TRef name.
bool read_header(const Filename &filename, PNMFileType *type=NULL, bool report_unknown_type=true)
Opens up the image file and tries to read its header information to determine its size...
int get_y_size() const
Returns the number of pixels in the Y direction.
int get_x_size() const
Returns the number of pixels in the X direction.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
void sort_by_basename()
Sorts all the textures into alphabetical order by the basename part (including extension) of the file...
int find_used_textures(EggNode *node)
Walks the egg hierarchy beginning at the indicated node, looking for textures that are referenced by ...
This is the base class of PNMImage, PNMReader, and PNMWriter.
Reads an egg file and outputs the list of textures it uses.