summaryrefslogtreecommitdiff
path: root/indra/llimage/llimagej2c.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llimage/llimagej2c.cpp')
-rw-r--r--indra/llimage/llimagej2c.cpp29
1 files changed, 11 insertions, 18 deletions
diff --git a/indra/llimage/llimagej2c.cpp b/indra/llimage/llimagej2c.cpp
index 0058b91b0f..4ec95bbcc3 100644
--- a/indra/llimage/llimagej2c.cpp
+++ b/indra/llimage/llimagej2c.cpp
@@ -31,7 +31,6 @@
#include "llmath.h"
#include "llmemory.h"
#include "llsd.h"
-#include <boost/scoped_ptr.hpp>
// Declare the prototype for this factory function here. It is implemented in
// other files which define a LLImageJ2CImpl subclass, but only ONE static
@@ -275,30 +274,24 @@ S32 LLImageJ2C::calcDataSizeJ2C(S32 w, S32 h, S32 comp, S32 discard_level, F32 r
// For details about the equation used here, see https://wiki.lindenlab.com/wiki/THX1138_KDU_Improvements#Byte_Range_Study
// Estimate the number of layers. This is consistent with what's done for j2c encoding in LLImageJ2CKDU::encodeImpl().
+ constexpr S32 precision = 8; // assumed bitrate per component channel, might change in future for HDR support
+ constexpr S32 max_components = 4; // assumed the file has four components; three color and alpha
S32 nb_layers = 1;
- S32 surface = w*h;
+ const S32 surface = w*h;
S32 s = 64*64;
+ S32 totalbytes = (S32)(s * max_components * precision * rate); // first level computed before loop
while (surface > s)
{
+ if (nb_layers <= (5 - discard_level))
+ totalbytes += (S32)(s * max_components * precision * rate);
nb_layers++;
s *= 4;
}
- F32 layer_factor = 3.0f * (7 - llclamp(nb_layers,1,6));
-
- // Compute w/pow(2,discard_level) and h/pow(2,discard_level)
- w >>= discard_level;
- h >>= discard_level;
- w = llmax(w, 1);
- h = llmax(h, 1);
-
- // Temporary: compute both new and old range and pick one according to the settings TextureNewByteRange
- // *TODO: Take the old code out once we have enough tests done
- S32 bytes;
- S32 new_bytes = (S32) (sqrt((F32)(w*h))*(F32)(comp)*rate*1000.f/layer_factor);
- S32 old_bytes = (S32)((F32)(w*h*comp)*rate);
- bytes = (LLImage::useNewByteRange() && (new_bytes < old_bytes) ? new_bytes : old_bytes);
- bytes = llmax(bytes, calcHeaderSizeJ2C());
- return bytes;
+
+ totalbytes /= 8; // to bytes
+ totalbytes += calcHeaderSizeJ2C(); // header
+
+ return totalbytes;
}
S32 LLImageJ2C::calcHeaderSize()