15 #include "textureMemoryCounter.h" 16 #include "paletteImage.h" 17 #include "textureImage.h" 18 #include "destTextureImage.h" 19 #include "omitReason.h" 20 #include "texturePlacement.h" 30 TextureMemoryCounter::
31 TextureMemoryCounter() {
72 add_texture(texture, bytes);
78 int bytes = count_bytes(dest);
79 add_texture(texture, bytes);
93 report(ostream &out,
int indent_level) {
94 indent(out, indent_level)
95 << _num_placed <<
" of " << _num_textures <<
" textures appear on " 96 << _num_palettes <<
" palette images with " << _num_unplaced
99 indent(out, indent_level)
100 << (_bytes + 512) / 1024 <<
"k estimated texture memory required.\n";
103 if (_unused_bytes != 0) {
104 indent(out, indent_level + 2);
105 format_memory_fraction(out, _unused_bytes, _bytes)
106 <<
" is wasted because of unused palette space.\n";
109 if (_coverage_bytes > 0) {
110 indent(out, indent_level + 2);
111 format_memory_fraction(out, _coverage_bytes, _bytes)
112 <<
" is wasted for repeating textures and margins.\n";
114 }
else if (_coverage_bytes < 0) {
115 indent(out, indent_level + 2);
116 format_memory_fraction(out, -_coverage_bytes, _bytes)
117 <<
" is *saved* for palettizing partial textures.\n";
120 if (_duplicate_bytes != 0) {
121 indent(out, indent_level + 2);
122 format_memory_fraction(out, _duplicate_bytes, _bytes)
123 <<
" is wasted because of a texture appearing in multiple groups.\n";
135 ostream &TextureMemoryCounter::
136 format_memory_fraction(ostream &out,
int fraction_bytes,
int palette_bytes) {
137 out << floor(1000.0 * (
double)fraction_bytes / (
double)palette_bytes + 0.5) / 10.0
138 <<
"% (" << (fraction_bytes + 512) / 1024 <<
"k)";
149 void TextureMemoryCounter::
151 bool inserted = _palettes.insert(image).second;
157 int bytes = count_bytes(image);
162 _unused_bytes += (int)(unused * bytes);
163 _coverage_bytes += (int)(coverage * bytes);
175 void TextureMemoryCounter::
177 pair<Textures::iterator, bool> result;
178 result = _textures.insert(Textures::value_type(texture, bytes));
186 Textures::iterator ti = result.first;
188 _duplicate_bytes += min(bytes, (*ti).second);
189 (*ti).second = max(bytes, (*ti).second);
198 int TextureMemoryCounter::
209 int TextureMemoryCounter::
210 count_bytes(
ImageFile *image,
int x_size,
int y_size) {
211 int pixels = x_size * y_size;
219 case EggTexture::F_rgba12:
223 case EggTexture::F_rgba:
224 case EggTexture::F_rgbm:
225 case EggTexture::F_rgba8:
229 case EggTexture::F_rgb:
230 case EggTexture::F_rgb12:
234 case EggTexture::F_rgba4:
235 case EggTexture::F_rgba5:
236 case EggTexture::F_rgb8:
237 case EggTexture::F_rgb5:
238 case EggTexture::F_luminance_alpha:
239 case EggTexture::F_luminance_alphamask:
243 case EggTexture::F_rgb332:
244 case EggTexture::F_red:
245 case EggTexture::F_green:
246 case EggTexture::F_blue:
247 case EggTexture::F_alpha:
248 case EggTexture::F_luminance:
256 int bytes = pixels * bpp;
260 case EggTexture::FT_nearest_mipmap_nearest:
261 case EggTexture::FT_linear_mipmap_nearest:
262 case EggTexture::FT_nearest_mipmap_linear:
263 case EggTexture::FT_linear_mipmap_linear:
264 bytes = (bytes * 4) / 3;
void reset()
Resets the count to zero.
This represents a texture filename as it has been resized and copied to the map directory (e...
double count_utilization() const
Returns the fraction of the PaletteImage that is actually used by any textures.
int get_placed_x_size() const
Returns the size in the X dimension, in pixels, of the texture image as it has been placed within the...
double count_coverage() const
Returns the a weighted average of the fraction of coverage represented by all of the textures placed ...
int get_y_size() const
Returns the size of the image file in pixels in the Y direction.
PaletteImage * get_image() const
Returns the particular PaletteImage on which the texture has been placed.
void report(ostream &out, int indent_level)
Reports the measured texture memory usage.
const TextureProperties & get_properties() const
Returns the grouping properties of the image.
int get_x_size() const
Returns the size of the image file in pixels in the X direction.
This is the base class of both TextureImage and PaletteImage.
int get_num_channels() const
Returns the number of channels of the image.
void add_placement(TexturePlacement *placement)
Adds the indicated TexturePlacement to the counter.
This corresponds to a particular assignment of a TextureImage with a PaletteGroup, and specifically describes which PaletteImage (if any), and where on the PaletteImage, the TextureImage has been assigned to.
OmitReason get_omit_reason() const
Returns the reason the texture has been omitted from a palette image, or OR_none if it has not...
TextureImage * get_texture() const
Returns the texture that this placement represents.
DestTextureImage * get_dest() const
Returns the DestTextureImage that corresponds to this texture as it was copied to the install directo...
This is a single palette image, one of several within a PalettePage, which is in turn one of several ...
This represents a single source texture that is referenced by one or more egg files.
int get_placed_y_size() const
Returns the size in the Y dimension, in pixels, of the texture image as it has been placed within the...