Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pandatool/src/egg-palettize/textureImage.h

Go to the documentation of this file.
00001 // Filename: textureImage.h
00002 // Created by:  drose (28Nov00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef TEXTUREIMAGE_H
00020 #define TEXTUREIMAGE_H
00021 
00022 #include "pandatoolbase.h"
00023 
00024 #include "imageFile.h"
00025 #include "paletteGroups.h"
00026 #include "textureRequest.h"
00027 
00028 #include "namable.h"
00029 #include "filename.h"
00030 #include "pnmImage.h"
00031 #include "eggRenderMode.h"
00032 
00033 #include "pmap.h"
00034 #include "pset.h"
00035 
00036 class SourceTextureImage;
00037 class DestTextureImage;
00038 class TexturePlacement;
00039 class EggFile;
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //       Class : TextureImage
00043 // Description : This represents a single source texture that is
00044 //               referenced by one or more egg files.  It may be
00045 //               assigned to multiple PaletteGroups, and thus placed
00046 //               on multiple PaletteImages (up to one per
00047 //               PaletteGroup).
00048 //
00049 //               Since a TextureImage may be referenced by multiple
00050 //               egg files that are each assigned to a different set
00051 //               of groups, it tries to maximize sharing between egg
00052 //               files and minimize the number of different
00053 //               PaletteGroups it is assigned to.
00054 ////////////////////////////////////////////////////////////////////
00055 class TextureImage : public ImageFile, public Namable {
00056 public:
00057   TextureImage();
00058 
00059   void note_egg_file(EggFile *egg_file);
00060   void assign_groups();
00061 
00062   const PaletteGroups &get_groups() const;
00063   TexturePlacement *get_placement(PaletteGroup *group) const;
00064   void force_replace();
00065   void mark_eggs_stale();
00066 
00067   void pre_txa_file();
00068   void post_txa_file();
00069   bool got_txa_file() const;
00070   void determine_placement_size();
00071 
00072   bool get_omit() const;
00073   double get_coverage_threshold() const;
00074   int get_margin() const;
00075   bool is_surprise() const;
00076   bool is_used() const;
00077   EggRenderMode::AlphaMode get_alpha_mode() const;
00078 
00079   SourceTextureImage *get_source(const Filename &filename,
00080                                  const Filename &alpha_filename,
00081                                  int alpha_file_channel);
00082 
00083   SourceTextureImage *get_preferred_source();
00084   void clear_source_basic_properties();
00085 
00086   void copy_unplaced(bool redo_all);
00087 
00088   const PNMImage &read_source_image();
00089   void read_header();
00090   bool is_newer_than(const Filename &reference_filename);
00091 
00092   void write_source_pathnames(ostream &out, int indent_level = 0) const;
00093   void write_scale_info(ostream &out, int indent_level = 0);
00094 
00095 private:
00096   typedef pset<EggFile *> EggFiles;
00097   typedef pvector<EggFile *> WorkingEggs;
00098   typedef pmap<string, SourceTextureImage *> Sources;
00099   typedef pmap<string, DestTextureImage *> Dests;
00100 
00101   static int compute_egg_count(PaletteGroup *group,
00102                                const WorkingEggs &egg_files);
00103 
00104   void assign_to_groups(const PaletteGroups &groups);
00105   void consider_grayscale();
00106   void consider_alpha();
00107 
00108   void remove_old_dests(const Dests &a, const Dests &b);
00109   void copy_new_dests(const Dests &a, const Dests &b);
00110 
00111   string get_source_key(const Filename &filename,
00112                         const Filename &alpha_filename,
00113                         int alpha_file_channel);
00114 
00115 private:
00116   TextureRequest _request;
00117   TextureProperties _pre_txa_properties;
00118   EggRenderMode::AlphaMode _pre_txa_alpha_mode;
00119   SourceTextureImage *_preferred_source;
00120   bool _is_surprise;
00121 
00122   bool _ever_read_image;
00123   bool _forced_grayscale;
00124 
00125   enum AlphaBits {
00126     // consider_alpha() sets alpha_bits to the union of all of these
00127     // pixel values that might be found in the alpha channel.
00128     AB_one   = 0x01,
00129     AB_mid   = 0x02,
00130     AB_zero  = 0x04,
00131     AB_all   = 0x07 // == AB_zero | AB_mid | AB_one
00132   };
00133   int _alpha_bits;
00134   EggRenderMode::AlphaMode _alpha_mode;
00135 
00136   PaletteGroups _explicitly_assigned_groups;
00137   PaletteGroups _actual_assigned_groups;
00138 
00139   EggFiles _egg_files;
00140 
00141   typedef pmap<PaletteGroup *, TexturePlacement *> Placement;
00142   Placement _placement;
00143 
00144   Sources _sources;
00145   Dests _dests;
00146 
00147   bool _read_source_image;
00148   PNMImage _source_image;
00149   bool _got_txa_file;
00150 
00151 
00152   // The TypedWritable interface follows.
00153 public:
00154   static void register_with_read_factory();
00155   virtual void write_datagram(BamWriter *writer, Datagram &datagram);
00156   virtual int complete_pointers(TypedWritable **p_list,
00157                                 BamReader *manager);
00158 
00159 protected:
00160   static TypedWritable *make_TextureImage(const FactoryParams &params);
00161   void fillin(DatagramIterator &scan, BamReader *manager);
00162 
00163 private:
00164   // These values are only filled in while reading from the bam file;
00165   // don't use them otherwise.
00166   int _num_placement;
00167   int _num_sources;
00168   int _num_dests;
00169 
00170 public:
00171   static TypeHandle get_class_type() {
00172     return _type_handle;
00173   }
00174   static void init_type() {
00175     ImageFile::init_type();
00176     Namable::init_type();
00177     register_type(_type_handle, "TextureImage",
00178                   ImageFile::get_class_type(),
00179                   Namable::get_class_type());
00180   }
00181   virtual TypeHandle get_type() const {
00182     return get_class_type();
00183   }
00184 
00185 private:
00186   static TypeHandle _type_handle;
00187 
00188   friend class TxaLine;
00189 };
00190 
00191 #endif
00192 

Generated on Fri May 2 03:18:11 2003 for Panda-Tool by doxygen1.3