summaryrefslogtreecommitdiff
path: root/indra/llimage/llimagej2c.cpp
diff options
context:
space:
mode:
authorJonathan "Geenz" Goodman <geenz@lindenlab.com>2025-06-27 23:58:12 -0400
committerGitHub <noreply@github.com>2025-06-27 23:58:12 -0400
commit06a9e45fa371365f56549fe1c1628bf7cf8589d1 (patch)
tree601bfe8f31052620321811582244d12a29d6d7a1 /indra/llimage/llimagej2c.cpp
parent895db142ee9224e1b8e4d2fc6348dc1801bea0dc (diff)
parenta50a0e1277386de3456f478127f774fa01cdb578 (diff)
Merge pull request #4308 from secondlife/geenz/develop-to-gltf-mesh
Geenz/develop to gltf mesh
Diffstat (limited to 'indra/llimage/llimagej2c.cpp')
-rw-r--r--indra/llimage/llimagej2c.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/indra/llimage/llimagej2c.cpp b/indra/llimage/llimagej2c.cpp
index aa161709a1..5a941dc958 100644
--- a/indra/llimage/llimagej2c.cpp
+++ b/indra/llimage/llimagej2c.cpp
@@ -281,10 +281,11 @@ S32 LLImageJ2C::calcDataSizeJ2C(S32 w, S32 h, S32 comp, S32 discard_level, F32 r
S32 height = (h > 0) ? h : 2048;
S32 max_dimension = llmax(width, height); // Find largest dimension
S32 block_area = MAX_BLOCK_SIZE * MAX_BLOCK_SIZE; // Calculated initial block area from established max block size (currently 64)
- block_area *= llmax((max_dimension / MAX_BLOCK_SIZE / max_components), 1); // Adjust initial block area by ratio of largest dimension to block size per component
- S32 totalbytes = (S32) (block_area * max_components * precision); // First block layer computed before loop without compression rate
- S32 block_layers = 1; // Start at layer 1 since first block layer is computed outside loop
- while (block_layers < 6) // Walk five layers for the five discards in JPEG2000
+ S32 max_layers = (S32)llmax(llround(log2f((float)max_dimension) - log2f((float)MAX_BLOCK_SIZE)), 4); // Find number of powers of two between extents and block size to a minimum of 4
+ block_area *= llmax(max_layers, 1); // Adjust initial block area by max number of layers
+ S32 totalbytes = (S32) (MIN_LAYER_SIZE * max_components * precision); // Start estimation with a minimum reasonable size
+ S32 block_layers = 0;
+ while (block_layers <= max_layers) // Walk the layers
{
if (block_layers <= (5 - discard_level)) // Walk backwards from discard 5 to required discard layer.
totalbytes += (S32) (block_area * max_components * precision * rate); // Add each block layer reduced by assumed compression rate