Fix size estimation
This commit is contained in:
@@ -363,8 +363,7 @@ S32 LLImageJ2C::calcHeaderSizeJ2C()
|
|||||||
return FIRST_PACKET_SIZE; // Hack. just needs to be >= actual header size...
|
return FIRST_PACKET_SIZE; // Hack. just needs to be >= actual header size...
|
||||||
}
|
}
|
||||||
|
|
||||||
//static
|
static S32 cald_data_size_help(S32 w, S32 h, S32 comp, S32 discard_level, F32 rate)
|
||||||
S32 LLImageJ2C::calcDataSizeJ2C(S32 w, S32 h, S32 comp, S32 discard_level, F32 rate)
|
|
||||||
{
|
{
|
||||||
if (rate <= 0.f) rate = .125f;
|
if (rate <= 0.f) rate = .125f;
|
||||||
while (discard_level > 0)
|
while (discard_level > 0)
|
||||||
@@ -376,10 +375,25 @@ S32 LLImageJ2C::calcDataSizeJ2C(S32 w, S32 h, S32 comp, S32 discard_level, F32 r
|
|||||||
discard_level--;
|
discard_level--;
|
||||||
}
|
}
|
||||||
S32 bytes = (S32)((F32)(w*h*comp)*rate);
|
S32 bytes = (S32)((F32)(w*h*comp)*rate);
|
||||||
//bytes = llmax(bytes, calcHeaderSizeJ2C());
|
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//static
|
||||||
|
S32 LLImageJ2C::calcDataSizeJ2C(S32 w, S32 h, S32 comp, S32 discard_level, F32 rate)
|
||||||
|
{
|
||||||
|
static const LLCachedControl<F32> exponent("SianaJ2CSizeExponent", 1.0f);
|
||||||
|
static const LLCachedControl<S32> offset("SianaJ2CSizeOffset", 0);
|
||||||
|
S32 size = cald_data_size_help(w, h, comp, discard_level, rate);
|
||||||
|
S32 size_d0 = cald_data_size_help(w, h, comp, 0, rate);
|
||||||
|
|
||||||
|
llassert_always(size_d0);
|
||||||
|
S32 bytes = pow(size/size_d0, exponent)*size_d0 + offset;
|
||||||
|
bytes = llmax (0, bytes - 600);
|
||||||
|
bytes = ((bytes + (1000 - 1))/1000)*1000 + 600;
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
S32 LLImageJ2C::calcHeaderSize()
|
S32 LLImageJ2C::calcHeaderSize()
|
||||||
{
|
{
|
||||||
return calcHeaderSizeJ2C();
|
return calcHeaderSizeJ2C();
|
||||||
@@ -392,15 +406,7 @@ S32 LLImageJ2C::calcDataSize(S32 discard_level)
|
|||||||
static const LLCachedControl<bool> legacy_size("SianaLegacyJ2CSize", false);
|
static const LLCachedControl<bool> legacy_size("SianaLegacyJ2CSize", false);
|
||||||
|
|
||||||
if (legacy_size) {
|
if (legacy_size) {
|
||||||
static const LLCachedControl<F32> exponent("SianaJ2CSizeExponent", 1.0f);
|
return calcDataSizeJ2C(getWidth(), getHeight(), getComponents(), discard_level, mRate);
|
||||||
static const LLCachedControl<S32> offset("SianaJ2CSizeOffset", 0);
|
|
||||||
|
|
||||||
S32 size = calcDataSizeJ2C(getWidth(), getHeight(), getComponents(), discard_level, mRate);
|
|
||||||
S32 size_d0 = calcDataSizeJ2C(getWidth(), getHeight(), getComponents(), 0, mRate);
|
|
||||||
llassert_always(size_d0);
|
|
||||||
S32 bytes = pow(size/size_d0, exponent)*size_d0 + offset;
|
|
||||||
bytes = llmax(bytes, calcHeaderSizeJ2C());
|
|
||||||
return bytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
discard_level = llclamp(discard_level, 0, MAX_DISCARD_LEVEL);
|
discard_level = llclamp(discard_level, 0, MAX_DISCARD_LEVEL);
|
||||||
|
|||||||
@@ -149,7 +149,14 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
|
|||||||
opj_setup_decoder(dinfo, ¶meters);
|
opj_setup_decoder(dinfo, ¶meters);
|
||||||
|
|
||||||
/* open a byte stream */
|
/* open a byte stream */
|
||||||
|
#if 0
|
||||||
|
std::vector<U8> data(base.getData(), base.getData()+base.getDataSize());
|
||||||
|
data.push_back((U8)0xFF);
|
||||||
|
data.push_back((U8)0xD9);
|
||||||
|
cio = opj_cio_open((opj_common_ptr)dinfo, &data[0], data.size());
|
||||||
|
#else
|
||||||
cio = opj_cio_open((opj_common_ptr)dinfo, base.getData(), base.getDataSize());
|
cio = opj_cio_open((opj_common_ptr)dinfo, base.getData(), base.getDataSize());
|
||||||
|
#endif
|
||||||
|
|
||||||
/* decode the stream and fill the image structure */
|
/* decode the stream and fill the image structure */
|
||||||
image = opj_decode(dinfo, cio);
|
image = opj_decode(dinfo, cio);
|
||||||
|
|||||||
@@ -287,7 +287,7 @@
|
|||||||
<key>Type</key>
|
<key>Type</key>
|
||||||
<string>F32</string>
|
<string>F32</string>
|
||||||
<key>Value</key>
|
<key>Value</key>
|
||||||
<real>0.5</real>
|
<real>1.0</real>
|
||||||
</map>
|
</map>
|
||||||
<key>SianaJ2CSizeOffset</key>
|
<key>SianaJ2CSizeOffset</key>
|
||||||
<map>
|
<map>
|
||||||
|
|||||||
Reference in New Issue
Block a user