Panda3D
|
00001 // Filename: paletteImage.h 00002 // Created by: drose (28Nov00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef PALETTEIMAGE_H 00016 #define PALETTEIMAGE_H 00017 00018 #include "pandatoolbase.h" 00019 00020 #include "imageFile.h" 00021 00022 #include "pnmImage.h" 00023 00024 class PalettePage; 00025 class TexturePlacement; 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Class : PaletteImage 00029 // Description : This is a single palette image, one of several within 00030 // a PalettePage, which is in turn one of several pages 00031 // within a PaletteGroup. Each palette image is a 00032 // collage of several different textures that were all 00033 // assigned to the same PaletteGroup, and all share the 00034 // same properties of the PalettePage. 00035 //////////////////////////////////////////////////////////////////// 00036 class PaletteImage : public ImageFile { 00037 private: 00038 PaletteImage(); 00039 00040 public: 00041 PaletteImage(PalettePage *page, int index); 00042 PaletteImage(PalettePage *page, int index, unsigned swapIndex); 00043 00044 PalettePage *get_page() const; 00045 00046 bool is_empty() const; 00047 double count_utilization() const; 00048 double count_coverage() const; 00049 00050 bool place(TexturePlacement *placement); 00051 void unplace(TexturePlacement *placement); 00052 void check_solitary(); 00053 00054 void optimal_resize(); 00055 bool resize_image(int x_size, int y_size); 00056 void resize_swapped_image(int x_size, int y_size); 00057 00058 void write_placements(ostream &out, int indent_level = 0) const; 00059 void reset_image(); 00060 void setup_shadow_image(); 00061 void update_image(bool redo_all); 00062 00063 bool update_filename(); 00064 00065 private: 00066 bool setup_filename(); 00067 bool find_hole(int &x, int &y, int x_size, int y_size) const; 00068 TexturePlacement *find_overlap(int x, int y, int x_size, int y_size) const; 00069 void get_image(); 00070 void release_image(); 00071 void remove_image(); 00072 void get_swapped_image(int index); 00073 void get_swapped_images(); 00074 00075 // The ClearedRegion object keeps track of TexturePlacements that 00076 // were recently removed and thus need to be set to black. 00077 class ClearedRegion { 00078 public: 00079 ClearedRegion(); 00080 ClearedRegion(TexturePlacement *placement); 00081 ClearedRegion(const ClearedRegion ©); 00082 void operator = (const ClearedRegion ©); 00083 void clear(PNMImage &image); 00084 00085 void write_datagram(Datagram &datagram) const; 00086 void fillin(DatagramIterator &scan); 00087 00088 private: 00089 int _x, _y; 00090 int _x_size, _y_size; 00091 }; 00092 00093 typedef pvector<ClearedRegion> ClearedRegions; 00094 ClearedRegions _cleared_regions; 00095 00096 typedef pvector<TexturePlacement *> Placements; 00097 Placements _placements; 00098 00099 Placements *_masterPlacements; 00100 00101 PalettePage *_page; 00102 int _index; 00103 string _basename; 00104 00105 bool _new_image; 00106 bool _got_image; 00107 PNMImage _image; 00108 00109 unsigned _swapped_image; // 0 for non swapped image 00110 00111 ImageFile _shadow_image; 00112 00113 typedef pvector<PaletteImage *> SwappedImages; 00114 SwappedImages _swappedImages; 00115 00116 // The TypedWritable interface follows. 00117 public: 00118 static void register_with_read_factory(); 00119 virtual void write_datagram(BamWriter *writer, Datagram &datagram); 00120 virtual int complete_pointers(TypedWritable **p_list, 00121 BamReader *manager); 00122 00123 protected: 00124 static TypedWritable *make_PaletteImage(const FactoryParams ¶ms); 00125 void fillin(DatagramIterator &scan, BamReader *manager); 00126 00127 private: 00128 // This value is only filled in while reading from the bam file; 00129 // don't use it otherwise. 00130 int _num_placements; 00131 00132 public: 00133 static TypeHandle get_class_type() { 00134 return _type_handle; 00135 } 00136 static void init_type() { 00137 ImageFile::init_type(); 00138 register_type(_type_handle, "PaletteImage", 00139 ImageFile::get_class_type()); 00140 } 00141 virtual TypeHandle get_type() const { 00142 return get_class_type(); 00143 } 00144 00145 private: 00146 static TypeHandle _type_handle; 00147 }; 00148 00149 #endif 00150