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

pandatool/src/egg-palettize/paletteImage.h

Go to the documentation of this file.
00001 // Filename: paletteImage.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 PALETTEIMAGE_H
00020 #define PALETTEIMAGE_H
00021 
00022 #include <pandatoolbase.h>
00023 
00024 #include "imageFile.h"
00025 
00026 #include <pnmImage.h>
00027 
00028 class PalettePage;
00029 class TexturePlacement;
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //       Class : PaletteImage
00033 // Description : This is a single palette image, one of several within
00034 //               a PalettePage, which is in turn one of several pages
00035 //               within a PaletteGroup.  Each palette image is a
00036 //               collage of several different textures that were all
00037 //               assigned to the same PaletteGroup, and all share the
00038 //               same properties of the PalettePage.
00039 ////////////////////////////////////////////////////////////////////
00040 class PaletteImage : public ImageFile {
00041 private:
00042   PaletteImage();
00043 
00044 public:
00045   PaletteImage(PalettePage *page, int index);
00046 
00047   PalettePage *get_page() const;
00048 
00049   bool is_empty() const;
00050   double count_utilization() const;
00051   double count_coverage() const;
00052 
00053   bool place(TexturePlacement *placement);
00054   void unplace(TexturePlacement *placement);
00055   void check_solitary();
00056 
00057   void optimal_resize();
00058   bool resize_image(int x_size, int y_size);
00059 
00060   void write_placements(ostream &out, int indent_level = 0) const;
00061   void reset_image();
00062   void setup_shadow_image();
00063   void update_image(bool redo_all);
00064 
00065 private:
00066   bool find_hole(int &x, int &y, int x_size, int y_size) const;
00067   TexturePlacement *find_overlap(int x, int y, int x_size, int y_size) const;
00068   void get_image();
00069   void remove_image();
00070 
00071   // The ClearedRegion object keeps track of TexturePlacements that
00072   // were recently removed and thus need to be set to black.
00073   class ClearedRegion {
00074   public:
00075     ClearedRegion();
00076     ClearedRegion(TexturePlacement *placement);
00077     ClearedRegion(const ClearedRegion &copy);
00078     void operator = (const ClearedRegion &copy);
00079     void clear(PNMImage &image);
00080 
00081     void write_datagram(Datagram &datagram) const;
00082     void fillin(DatagramIterator &scan);
00083 
00084   private:
00085     int _x, _y;
00086     int _x_size, _y_size;
00087   };
00088 
00089   typedef pvector<ClearedRegion> ClearedRegions;
00090   ClearedRegions _cleared_regions;
00091 
00092   typedef pvector<TexturePlacement *> Placements;
00093   Placements _placements;
00094 
00095   PalettePage *_page;
00096   int _index;
00097   string _basename;
00098 
00099   bool _new_image;
00100   bool _got_image;
00101   PNMImage _image;
00102 
00103   ImageFile _shadow_image;
00104 
00105   // The TypedWritable interface follows.
00106 public:
00107   static void register_with_read_factory();
00108   virtual void write_datagram(BamWriter *writer, Datagram &datagram);
00109   virtual int complete_pointers(TypedWritable **p_list,
00110                                 BamReader *manager);
00111 
00112 protected:
00113   static TypedWritable *make_PaletteImage(const FactoryParams &params);
00114   void fillin(DatagramIterator &scan, BamReader *manager);
00115 
00116 private:
00117   // This value is only filled in while reading from the bam file;
00118   // don't use it otherwise.
00119   int _num_placements;
00120 
00121 public:
00122   static TypeHandle get_class_type() {
00123     return _type_handle;
00124   }
00125   static void init_type() {
00126     ImageFile::init_type();
00127     register_type(_type_handle, "PaletteImage",
00128                   ImageFile::get_class_type());
00129   }
00130   virtual TypeHandle get_type() const {
00131     return get_class_type();
00132   }
00133 
00134 private:
00135   static TypeHandle _type_handle;
00136 };
00137 
00138 #endif
00139 

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