Bladeren bron

*** empty log message ***

David Rose 25 jaren geleden
bovenliggende
commit
ce29a01449

+ 40 - 1
pandatool/src/egg-palettize/paletteImage.cxx

@@ -223,7 +223,9 @@ count_utilization() const {
   for (pi = _placements.begin(); pi != _placements.end(); ++pi) {
     TexturePlacement *placement = (*pi);
 
-    int texture_pixels = placement->get_x_size() * placement->get_y_size();
+    int texture_pixels = 
+      placement->get_placed_x_size() * 
+      placement->get_placed_y_size();
     used_pixels += texture_pixels;
   }
 
@@ -232,6 +234,43 @@ count_utilization() const {
   return (double)used_pixels / (double)total_pixels;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PaletteImage::count_coverage
+//       Access: Public
+//  Description: Returns the a weighted average of the fraction of
+//               coverage represented by all of the textures placed on
+//               the palette.  This number represents the fraction of
+//               wasted pixels in the palette image consumed by
+//               copying the same pixels multiple times into the
+//               palette, or if the number is negative, it represents
+//               the fraction of pixels saved by not having to copy
+//               the entire texture into the palette.
+////////////////////////////////////////////////////////////////////
+double PaletteImage::
+count_coverage() const {
+  int coverage_pixels = 0;
+
+  Placements::const_iterator pi;
+  for (pi = _placements.begin(); pi != _placements.end(); ++pi) {
+    TexturePlacement *placement = (*pi);
+    TextureImage *texture = placement->get_texture();
+    nassertr(texture != (TextureImage *)NULL, 0.0);
+
+    int orig_pixels = 
+      texture->get_x_size() *
+      texture->get_y_size();
+    int placed_pixels = 
+      placement->get_placed_x_size() * 
+      placement->get_placed_y_size();
+
+    coverage_pixels += placed_pixels - orig_pixels;
+  }
+
+  int total_pixels = get_x_size() * get_y_size();
+
+  return (double)coverage_pixels / (double)total_pixels;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PaletteImage::place
 //       Access: Public

+ 1 - 0
pandatool/src/egg-palettize/paletteImage.h

@@ -35,6 +35,7 @@ public:
 
   bool is_empty() const;
   double count_utilization() const;
+  double count_coverage() const;
 
   bool place(TexturePlacement *placement);
   void unplace(TexturePlacement *placement);

+ 39 - 9
pandatool/src/egg-palettize/textureMemoryCounter.cxx

@@ -38,6 +38,7 @@ reset() {
   _bytes = 0;
   _unused_bytes = 0;
   _duplicate_bytes = 0;
+  _coverage_bytes = 0;
   _textures.clear();
   _palettes.clear();
 }
@@ -90,19 +91,45 @@ report(ostream &out, int indent_level) {
     << (_bytes + 512) / 1024 << "k estimated texture memory required.\n";
 
   if (_bytes != 0) {
-    indent(out, indent_level + 2)
-      << "Of this, "
-      << floor(1000.0 * (double)_unused_bytes / (double)_bytes + 0.5) / 10.0
-      << "% is wasted because of unused palette space.\n";
+    if (_unused_bytes != 0) {
+      indent(out, indent_level + 2);
+      format_memory_fraction(out, _unused_bytes, _bytes)
+	<< " is wasted because of unused palette space.\n";
+    }
+    
+    if (_coverage_bytes > 0) {
+      indent(out, indent_level + 2);
+      format_memory_fraction(out, _coverage_bytes, _bytes)
+	<< " is wasted for repeating textures and margins.\n";
+
+    } else if (_coverage_bytes < 0) {
+      indent(out, indent_level + 2);
+      format_memory_fraction(out, -_coverage_bytes, _bytes)
+	<< " is *saved* for palettizing partial textures.\n";
+    }
     
     if (_duplicate_bytes != 0) {
-      indent(out, indent_level + 2)
-	<< "And " << 100.0 * (double)_duplicate_bytes / (double)_bytes
-	<< "% is wasted because of a texture appearing in multiple places.\n";
+      indent(out, indent_level + 2);
+      format_memory_fraction(out, _duplicate_bytes, _bytes)
+	<< " is wasted because of a texture appearing in multiple groups.\n";
     }
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: TextureMemoryCounter::format_memory_fraction
+//       Access: Private, Static
+//  Description: Writes to the indicated ostream an indication of the
+//               fraction of the total memory usage that is
+//               represented by fraction_bytes.
+////////////////////////////////////////////////////////////////////
+ostream &TextureMemoryCounter::
+format_memory_fraction(ostream &out, int fraction_bytes, int palette_bytes) {
+  out << floor(1000.0 * (double)fraction_bytes / (double)palette_bytes + 0.5) / 10.0
+      << "% (" << (fraction_bytes + 512) / 1024 << "k)";
+  return out;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: TextureMemoryCounter::add_palette
 //       Access: Private
@@ -119,10 +146,13 @@ add_palette(PaletteImage *image) {
   }
 
   int bytes = count_bytes(image);
-  double wasted = 1.0 - image->count_utilization();
+  double unused = 1.0 - image->count_utilization();
+  double coverage = image->count_coverage();
 
   _bytes += bytes;
-  _unused_bytes += (int)(wasted * bytes);
+  _unused_bytes += (int)(unused * bytes);
+  _coverage_bytes += (int)(coverage * bytes);
+  
   _num_palettes++;
 }
 

+ 3 - 0
pandatool/src/egg-palettize/textureMemoryCounter.h

@@ -34,6 +34,8 @@ public:
   void report(ostream &out, int indent_level);
 
 private:
+  static ostream &format_memory_fraction(ostream &out, int fraction_bytes,
+					 int palette_bytes);
   void add_palette(PaletteImage *image);
   void add_texture(TextureImage *texture, int bytes);
   int count_bytes(ImageFile *image);
@@ -47,6 +49,7 @@ private:
   int _bytes;
   int _unused_bytes;
   int _duplicate_bytes;
+  int _coverage_bytes;
 
   typedef map<TextureImage *, int> Textures;
   Textures _textures;