00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef PALETTIZER_H
00020 #define PALETTIZER_H
00021
00022 #include "pandatoolbase.h"
00023
00024 #include "txaFile.h"
00025
00026 #include "typedWritable.h"
00027
00028 #include "pvector.h"
00029 #include "pset.h"
00030 #include "pmap.h"
00031
00032 class PNMFileType;
00033 class EggFile;
00034 class PaletteGroup;
00035 class TextureImage;
00036 class TexturePlacement;
00037 class FactoryParams;
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 class Palettizer : public TypedWritable {
00048 public:
00049 Palettizer();
00050
00051 void report_pi() const;
00052 void report_statistics() const;
00053
00054 void read_txa_file(const Filename &txa_filename);
00055 void all_params_set();
00056 void process_command_line_eggs(bool force_texture_read, const Filename &state_filename);
00057 void process_all(bool force_texture_read, const Filename &state_filename);
00058 void optimal_resize();
00059 void reset_images();
00060 void generate_images(bool redo_all);
00061 bool read_stale_eggs(bool redo_all);
00062 bool write_eggs();
00063
00064 EggFile *get_egg_file(const string &name);
00065 bool remove_egg_file(const string &name);
00066
00067 PaletteGroup *get_palette_group(const string &name);
00068 PaletteGroup *test_palette_group(const string &name) const;
00069 PaletteGroup *get_default_group();
00070 TextureImage *get_texture(const string &name);
00071
00072 private:
00073 static const char *yesno(bool flag);
00074
00075 public:
00076 static int _pi_version;
00077 static int _min_pi_version;
00078 static int _read_pi_version;
00079
00080 enum RemapUV {
00081 RU_never,
00082 RU_group,
00083 RU_poly,
00084 RU_invalid
00085 };
00086
00087 static RemapUV string_remap(const string &str);
00088
00089
00090
00091 TxaFile _txa_file;
00092 string _default_groupname;
00093 string _default_groupdir;
00094
00095
00096
00097
00098 string _map_dirname;
00099 Filename _shadow_dirname;
00100 Filename _rel_dirname;
00101 int _pal_x_size, _pal_y_size;
00102 int _margin;
00103 bool _omit_solitary;
00104 double _coverage_threshold;
00105 bool _force_power_2;
00106 bool _aggressively_clean_mapdir;
00107 bool _round_uvs;
00108 double _round_unit;
00109 double _round_fuzz;
00110 RemapUV _remap_uv, _remap_char_uv;
00111 PNMFileType *_color_type;
00112 PNMFileType *_alpha_type;
00113 PNMFileType *_shadow_color_type;
00114 PNMFileType *_shadow_alpha_type;
00115
00116 private:
00117 typedef pvector<TexturePlacement *> Placements;
00118 void compute_statistics(ostream &out, int indent_level,
00119 const Placements &placements) const;
00120
00121 typedef pmap<string, EggFile *> EggFiles;
00122 EggFiles _egg_files;
00123
00124 typedef pvector<EggFile *> CommandLineEggs;
00125 CommandLineEggs _command_line_eggs;
00126
00127 typedef pset<TextureImage *> CommandLineTextures;
00128 CommandLineTextures _command_line_textures;
00129
00130 typedef pmap<string, PaletteGroup *> Groups;
00131 Groups _groups;
00132
00133 typedef pmap<string, TextureImage *> Textures;
00134 Textures _textures;
00135
00136
00137
00138 public:
00139 static void register_with_read_factory();
00140 virtual void write_datagram(BamWriter *writer, Datagram &datagram);
00141 virtual int complete_pointers(TypedWritable **p_list,
00142 BamReader *manager);
00143
00144 protected:
00145 static TypedWritable *make_Palettizer(const FactoryParams ¶ms);
00146 void fillin(DatagramIterator &scan, BamReader *manager);
00147
00148 private:
00149
00150
00151 int _num_egg_files;
00152 int _num_groups;
00153 int _num_textures;
00154
00155 public:
00156 static TypeHandle get_class_type() {
00157 return _type_handle;
00158 }
00159 static void init_type() {
00160 TypedWritable::init_type();
00161 register_type(_type_handle, "Palettizer",
00162 TypedWritable::get_class_type());
00163 }
00164 virtual TypeHandle get_type() const {
00165 return get_class_type();
00166 }
00167
00168 private:
00169 static TypeHandle _type_handle;
00170
00171 friend class EggPalettize;
00172 friend class TxaLine;
00173 };
00174
00175 extern Palettizer *pal;
00176
00177 #endif