summaryrefslogtreecommitdiff
path: root/indra/llimagej2coj/llimagej2coj.cpp
diff options
context:
space:
mode:
authorJosh Bell <josh@lindenlab.com>2007-12-29 01:40:57 +0000
committerJosh Bell <josh@lindenlab.com>2007-12-29 01:40:57 +0000
commitd06e5e3519f13197dd62bfbabf76f7efcc3d7a79 (patch)
tree62b363ba11a3cc7dd78343e63ad440284f0252f3 /indra/llimagej2coj/llimagej2coj.cpp
parent79680891a73be074aa449a9ccdf695b0afd300d8 (diff)
svn merge -r 76642:76643 svn+ssh://svn.lindenlab.com/svn/linden/qa/maintenance-4-merge-76640
Redo of QAR-170, with correct range. Reviewed by CG.
Diffstat (limited to 'indra/llimagej2coj/llimagej2coj.cpp')
-rw-r--r--indra/llimagej2coj/llimagej2coj.cpp53
1 files changed, 42 insertions, 11 deletions
diff --git a/indra/llimagej2coj/llimagej2coj.cpp b/indra/llimagej2coj/llimagej2coj.cpp
index 7a323c8354..d7be118875 100644
--- a/indra/llimagej2coj/llimagej2coj.cpp
+++ b/indra/llimagej2coj/llimagej2coj.cpp
@@ -40,8 +40,10 @@
const char* fallbackEngineInfoLLImageJ2CImpl()
{
- return (std::string("OpenJPEG: " OPENJPEG_VERSION ", Runtime: ")
- + opj_version()).c_str();
+ static std::string version_string =
+ std::string("OpenJPEG: " OPENJPEG_VERSION ", Runtime: ")
+ + opj_version();
+ return version_string.c_str();
}
LLImageJ2CImpl* fallbackCreateLLImageJ2CImpl()
@@ -183,15 +185,25 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
for (S32 comp = first_channel, dest=0; comp < first_channel + channels;
comp++, dest++)
{
- S32 offset = dest;
- for (S32 y = (height - 1); y >= 0; y--)
+ if (image->comps[comp].data)
{
- for (S32 x = 0; x < width; x++)
+ S32 offset = dest;
+ for (S32 y = (height - 1); y >= 0; y--)
{
- rawp[offset] = image->comps[comp].data[y*comp_width + x];
- offset += channels;
+ for (S32 x = 0; x < width; x++)
+ {
+ rawp[offset] = image->comps[comp].data[y*comp_width + x];
+ offset += channels;
+ }
}
}
+ else // Some rare OpenJPEG versions have this bug.
+ {
+ fprintf(stderr, "ERROR -> decodeImpl: failed to decode image! (NULL comp data - OpenJPEG bug)\n");
+ opj_image_destroy(image);
+
+ return TRUE; // done
+ }
}
/* free image data structure */
@@ -219,10 +231,29 @@ BOOL LLImageJ2COJ::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, con
/* set encoding parameters to default values */
opj_set_default_encoder_parameters(&parameters);
- parameters.tcp_rates[0] = 0;
- parameters.tcp_numlayers++;
- parameters.cp_disto_alloc = 1;
parameters.cod_format = 0;
+ parameters.cp_disto_alloc = 1;
+
+ if (reversible)
+ {
+ parameters.tcp_numlayers = 1;
+ parameters.tcp_rates[0] = 0.0f;
+ }
+ else
+ {
+ parameters.tcp_numlayers = 5;
+ parameters.tcp_rates[0] = 1920.0f;
+ parameters.tcp_rates[1] = 480.0f;
+ parameters.tcp_rates[2] = 120.0f;
+ parameters.tcp_rates[3] = 30.0f;
+ parameters.tcp_rates[4] = 10.0f;
+ parameters.irreversible = 1;
+ if (raw_image.getComponents() >= 3)
+ {
+ parameters.tcp_mct = 1;
+ }
+ }
+
if (!comment_text)
{
parameters.cp_comment = "";
@@ -298,7 +329,7 @@ BOOL LLImageJ2COJ::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, con
cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
/* encode the image */
- bool bSuccess = opj_encode(cinfo, cio, image, parameters.index);
+ bool bSuccess = opj_encode(cinfo, cio, image, NULL);
if (!bSuccess)
{
opj_cio_close(cio);