00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00033
00034
00035
00036
00037
00038
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
00072
00073 class ClearedRegion {
00074 public:
00075 ClearedRegion();
00076 ClearedRegion(TexturePlacement *placement);
00077 ClearedRegion(const ClearedRegion ©);
00078 void operator = (const ClearedRegion ©);
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
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 ¶ms);
00114 void fillin(DatagramIterator &scan, BamReader *manager);
00115
00116 private:
00117
00118
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