aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llimagej2coj
diff options
context:
space:
mode:
authorthickbrick2011-04-13 16:57:48 +0300
committerMcCabe Maxsted2011-04-19 16:47:55 -0700
commit9e298c771994224df3c40104eeb4347da17aab84 (patch)
treebccf1b1c7137ea60f712ce8be4f9ad9b7f5d5ac2 /linden/indra/llimagej2coj
parentAdded custom nametag coloring for Imprudence tags (local only) (diff)
downloadmeta-impy-9e298c771994224df3c40104eeb4347da17aab84.zip
meta-impy-9e298c771994224df3c40104eeb4347da17aab84.tar.gz
meta-impy-9e298c771994224df3c40104eeb4347da17aab84.tar.bz2
meta-impy-9e298c771994224df3c40104eeb4347da17aab84.tar.xz
Bug #869 Related: revert 721c25d8 (and d3741625). It wasn't doing anything for us without a modified OpenJPEG.
Diffstat (limited to 'linden/indra/llimagej2coj')
-rw-r--r--linden/indra/llimagej2coj/llimagej2coj.cpp45
1 files changed, 10 insertions, 35 deletions
diff --git a/linden/indra/llimagej2coj/llimagej2coj.cpp b/linden/indra/llimagej2coj/llimagej2coj.cpp
index fd92370..b7a1b82 100644
--- a/linden/indra/llimagej2coj/llimagej2coj.cpp
+++ b/linden/indra/llimagej2coj/llimagej2coj.cpp
@@ -152,13 +152,8 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
152 /* open a byte stream */ 152 /* open a byte stream */
153 cio = opj_cio_open((opj_common_ptr)dinfo, base.getData(), base.getDataSize()); 153 cio = opj_cio_open((opj_common_ptr)dinfo, base.getData(), base.getDataSize());
154 154
155 /* decode the stream and fill the image structure, also fill in an additional 155 /* decode the stream and fill the image structure */
156 structure to get the decoding result. This structure is a bit unusual in that 156 image = opj_decode(dinfo, cio);
157 it is not received through opj, but still has some dynamically allocated fields
158 that need to be cleared up at the end by calling a destroy function. */
159 opj_codestream_info_t cinfo;
160 memset(&cinfo, 0, sizeof(opj_codestream_info_t));
161 image = opj_decode_with_info(dinfo, cio, &cinfo);
162 157
163 /* close the byte stream */ 158 /* close the byte stream */
164 opj_cio_close(cio); 159 opj_cio_close(cio);
@@ -185,7 +180,6 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
185 LL_DEBUGS("Openjpeg") << "ERROR -> decodeImpl: failed to decode image wrong number of components: " << img_components << LL_ENDL; 180 LL_DEBUGS("Openjpeg") << "ERROR -> decodeImpl: failed to decode image wrong number of components: " << img_components << LL_ENDL;
186 if (image) 181 if (image)
187 { 182 {
188 opj_destroy_cstr_info(&cinfo);
189 opj_image_destroy(image); 183 opj_image_destroy(image);
190 } 184 }
191 185
@@ -193,40 +187,23 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
193 } 187 }
194 188
195 // sometimes we get bad data out of the cache - check to see if the decode succeeded 189 // sometimes we get bad data out of the cache - check to see if the decode succeeded
196 int decompdifference = 0; 190 for (S32 i = 0; i < img_components; i++)
197 if (cinfo.numdecompos) // sanity
198 { 191 {
199 for (int comp = 0; comp < image->numcomps; comp++) 192 if (image->comps[i].factor != base.getRawDiscardLevel())
200 { /* get maximum decomposition level difference, first field is from the COD header and the second
201 is what is actually met in the codestream, NB: if everything was ok, this calculation will
202 return what was set in the cp_reduce value! */
203 decompdifference = llmax(decompdifference, cinfo.numdecompos[comp] - image->comps[comp].resno_decoded);
204 }
205 if (decompdifference < 0) // sanity
206 { 193 {
207 decompdifference = 0; 194 // if we didn't get the discard level we're expecting, fail
195 if (image) //anyway somthing odd with the image, better check than crash
196 opj_image_destroy(image);
197 base.mDecoding = FALSE;
198 return TRUE;
208 } 199 }
209 } 200 }
210 201
211
212 /* if OpenJPEG failed to decode all requested decomposition levels
213 the difference will be greater than this level */
214 if (decompdifference > base.getRawDiscardLevel())
215 {
216 llwarns << "not enough data for requested discard level, setting mDecoding to FALSE, difference: " << (decompdifference - base.getRawDiscardLevel()) << llendl;
217 opj_destroy_cstr_info(&cinfo);
218 opj_image_destroy(image);
219 base.mDecoding = FALSE;
220 return TRUE;
221 }
222
223 if(img_components <= first_channel) 202 if(img_components <= first_channel)
224 { 203 {
225 // sanity
226 LL_DEBUGS("Openjpeg") << "trying to decode more channels than are present in image: numcomps: " << img_components << " first_channel: " << first_channel << LL_ENDL; 204 LL_DEBUGS("Openjpeg") << "trying to decode more channels than are present in image: numcomps: " << img_components << " first_channel: " << first_channel << LL_ENDL;
227 if (image) 205 if (image)
228 { 206 {
229 opj_destroy_cstr_info(&cinfo);
230 opj_image_destroy(image); 207 opj_image_destroy(image);
231 } 208 }
232 209
@@ -275,17 +252,15 @@ BOOL LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decod
275 else // Some rare OpenJPEG versions have this bug. 252 else // Some rare OpenJPEG versions have this bug.
276 { 253 {
277 llwarns << "ERROR -> decodeImpl: failed to decode image! (NULL comp data - OpenJPEG bug)" << llendl; 254 llwarns << "ERROR -> decodeImpl: failed to decode image! (NULL comp data - OpenJPEG bug)" << llendl;
278 opj_destroy_cstr_info(&cinfo);
279 opj_image_destroy(image); 255 opj_image_destroy(image);
280 256
281 return TRUE; // done 257 return TRUE; // done
282 } 258 }
283 } 259 }
284 260
285 /* free opj data structures */ 261 /* free image data structure */
286 if (image) 262 if (image)
287 { 263 {
288 opj_destroy_cstr_info(&cinfo);
289 opj_image_destroy(image); 264 opj_image_destroy(image);
290 } 265 }
291 266