Skip to content

Commit ac5d59b

Browse files
calcDataSizeJ2C Adjust curve for more than 6 layers (#4018, #4020)
KDU is uploading 2k files with 7 and 8 layers which is shifting the location of discard 1 and 2. To accommodate, this commit adds a max_layer check based on max_dimension and the MAX_BLOCK_SIZE to allow the extra layers for 2k. Also shifted the starting size to the MIN_LAYER_SIZE instead of MAX_BLOCK_SIZE's area to allow smaller files to be decoded at discard 5 completely. Finally able to walk around Fantasy Faire without any gray blobs!
1 parent 65d70a8 commit ac5d59b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

indra/llimage/llimagej2c.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,11 @@ S32 LLImageJ2C::calcDataSizeJ2C(S32 w, S32 h, S32 comp, S32 discard_level, F32 r
281281
S32 height = (h > 0) ? h : 2048;
282282
S32 max_dimension = llmax(width, height); // Find largest dimension
283283
S32 block_area = MAX_BLOCK_SIZE * MAX_BLOCK_SIZE; // Calculated initial block area from established max block size (currently 64)
284-
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
285-
S32 totalbytes = (S32) (block_area * max_components * precision); // First block layer computed before loop without compression rate
286-
S32 block_layers = 1; // Start at layer 1 since first block layer is computed outside loop
287-
while (block_layers < 6) // Walk five layers for the five discards in JPEG2000
284+
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
285+
block_area *= llmax(max_layers, 1); // Adjust initial block area by max number of layers
286+
S32 totalbytes = (S32) (MIN_LAYER_SIZE * max_components * precision); // Start estimation with a minimum reasonable size
287+
S32 block_layers = 0;
288+
while (block_layers <= max_layers) // Walk the layers
288289
{
289290
if (block_layers <= (5 - discard_level)) // Walk backwards from discard 5 to required discard layer.
290291
totalbytes += (S32) (block_area * max_components * precision * rate); // Add each block layer reduced by assumed compression rate

0 commit comments

Comments
 (0)