aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llimage/llimagej2c.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llimage/llimagej2c.cpp')
-rw-r--r--linden/indra/llimage/llimagej2c.cpp141
1 files changed, 100 insertions, 41 deletions
diff --git a/linden/indra/llimage/llimagej2c.cpp b/linden/indra/llimage/llimagej2c.cpp
index 510b303..95abbae 100644
--- a/linden/indra/llimage/llimagej2c.cpp
+++ b/linden/indra/llimage/llimagej2c.cpp
@@ -219,32 +219,54 @@ LLImageJ2C::~LLImageJ2C()
219} 219}
220 220
221// virtual 221// virtual
222void LLImageJ2C::resetLastError()
223{
224 mLastError.clear();
225}
226
227//virtual
228void LLImageJ2C::setLastError(const std::string& message, const std::string& filename)
229{
230 mLastError = message;
231 if (!filename.empty())
232 mLastError += std::string(" FILE: ") + filename;
233}
234
235// virtual
222S8 LLImageJ2C::getRawDiscardLevel() 236S8 LLImageJ2C::getRawDiscardLevel()
223{ 237{
224 return mRawDiscardLevel; 238 return mRawDiscardLevel;
225} 239}
226 240
227BOOL LLImageJ2C::updateData() 241BOOL LLImageJ2C::updateData()
228{ 242{
243 BOOL res = TRUE;
229 resetLastError(); 244 resetLastError();
230 245
231 // Check to make sure that this instance has been initialized with data 246 // Check to make sure that this instance has been initialized with data
232 if (!getData() || (getDataSize() < 16)) 247 if (!getData() || (getDataSize() < 16))
233 { 248 {
234 setLastError("LLImageJ2C uninitialized"); 249 setLastError("LLImageJ2C uninitialized");
235 return FALSE; 250 res = FALSE;
251 }
252 else
253 {
254 res = mImpl->getMetadata(*this);
236 } 255 }
237 256
238 if (!mImpl->getMetadata(*this)) 257 if (res)
239 { 258 {
240 return FALSE; 259 // SJB: override discard based on mMaxBytes elsewhere
260 S32 max_bytes = getDataSize(); // mMaxBytes ? mMaxBytes : getDataSize();
261 S32 discard = calcDiscardLevelBytes(max_bytes);
262 setDiscardLevel(discard);
241 } 263 }
242 // SJB: override discard based on mMaxBytes elsewhere
243 S32 max_bytes = getDataSize(); // mMaxBytes ? mMaxBytes : getDataSize();
244 S32 discard = calcDiscardLevelBytes(max_bytes);
245 setDiscardLevel(discard);
246 264
247 return TRUE; 265 if (!mLastError.empty())
266 {
267 LLImage::setLastError(mLastError);
268 }
269 return res;
248} 270}
249 271
250 272
@@ -258,20 +280,24 @@ BOOL LLImageJ2C::decodeChannels(LLImageRaw *raw_imagep, F32 decode_time, S32 fir
258{ 280{
259 LLMemType mt1((LLMemType::EMemType)mMemType); 281 LLMemType mt1((LLMemType::EMemType)mMemType);
260 282
283 BOOL res = TRUE;
284
261 resetLastError(); 285 resetLastError();
262 286
263 // Check to make sure that this instance has been initialized with data 287 // Check to make sure that this instance has been initialized with data
264 if (!getData() || (getDataSize() < 16)) 288 if (!getData() || (getDataSize() < 16))
265 { 289 {
266 setLastError("LLImageJ2C uninitialized"); 290 setLastError("LLImageJ2C uninitialized");
267 return FALSE; 291 res = FALSE;
268 } 292 }
269 293 else
270 // Update the raw discard level 294 {
271 updateRawDiscardLevel(); 295 // Update the raw discard level
272 296 updateRawDiscardLevel();
273 mDecoding = TRUE; 297 mDecoding = TRUE;
274 BOOL res = mImpl->decodeImpl(*this, *raw_imagep, decode_time, first_channel, max_channel_count); 298 res = mImpl->decodeImpl(*this, *raw_imagep, decode_time, first_channel, max_channel_count);
299 }
300
275 if (res) 301 if (res)
276 { 302 {
277 if (!mDecoding) 303 if (!mDecoding)
@@ -283,9 +309,14 @@ BOOL LLImageJ2C::decodeChannels(LLImageRaw *raw_imagep, F32 decode_time, S32 fir
283 { 309 {
284 mDecoding = FALSE; 310 mDecoding = FALSE;
285 } 311 }
286 return TRUE; // done
287 } 312 }
288 return FALSE; 313
314 if (!mLastError.empty())
315 {
316 LLImage::setLastError(mLastError);
317 }
318
319 return res;
289} 320}
290 321
291 322
@@ -298,7 +329,13 @@ BOOL LLImageJ2C::encode(const LLImageRaw *raw_imagep, F32 encode_time)
298BOOL LLImageJ2C::encode(const LLImageRaw *raw_imagep, const char* comment_text, F32 encode_time) 329BOOL LLImageJ2C::encode(const LLImageRaw *raw_imagep, const char* comment_text, F32 encode_time)
299{ 330{
300 LLMemType mt1((LLMemType::EMemType)mMemType); 331 LLMemType mt1((LLMemType::EMemType)mMemType);
301 return mImpl->encodeImpl(*this, *raw_imagep, comment_text, encode_time, mReversible); 332 resetLastError();
333 BOOL res = mImpl->encodeImpl(*this, *raw_imagep, comment_text, encode_time, mReversible);
334 if (!mLastError.empty())
335 {
336 LLImage::setLastError(mLastError);
337 }
338 return res;
302} 339}
303 340
304//static 341//static
@@ -376,6 +413,8 @@ void LLImageJ2C::setReversible(const BOOL reversible)
376 413
377BOOL LLImageJ2C::loadAndValidate(const std::string &filename) 414BOOL LLImageJ2C::loadAndValidate(const std::string &filename)
378{ 415{
416 BOOL res = TRUE;
417
379 resetLastError(); 418 resetLastError();
380 419
381 S32 file_size = 0; 420 S32 file_size = 0;
@@ -383,27 +422,38 @@ BOOL LLImageJ2C::loadAndValidate(const std::string &filename)
383 if (!apr_file) 422 if (!apr_file)
384 { 423 {
385 setLastError("Unable to open file for reading", filename); 424 setLastError("Unable to open file for reading", filename);
386 return FALSE; 425 res = FALSE;
387 } 426 }
388 if (file_size == 0) 427 else if (file_size == 0)
389 { 428 {
390 setLastError("File is empty",filename); 429 setLastError("File is empty",filename);
391 apr_file_close(apr_file); 430 apr_file_close(apr_file);
392 return FALSE; 431 res = FALSE;
393 } 432 }
394 433 else
395 U8 *data = new U8[file_size];
396 apr_size_t bytes_read = file_size;
397 apr_status_t s = apr_file_read(apr_file, data, &bytes_read); // modifies bytes_read
398 if (s != APR_SUCCESS || (S32)bytes_read != file_size)
399 { 434 {
400 delete[] data; 435 U8 *data = new U8[file_size];
401 setLastError("Unable to read entire file"); 436 apr_size_t bytes_read = file_size;
402 return FALSE; 437 apr_status_t s = apr_file_read(apr_file, data, &bytes_read); // modifies bytes_read
438 apr_file_close(apr_file);
439 if (s != APR_SUCCESS || (S32)bytes_read != file_size)
440 {
441 delete[] data;
442 setLastError("Unable to read entire file");
443 res = FALSE;
444 }
445 else
446 {
447 res = validate(data, file_size);
448 }
403 } 449 }
404 apr_file_close(apr_file);
405 450
406 return validate(data, file_size); 451 if (!mLastError.empty())
452 {
453 LLImage::setLastError(mLastError);
454 }
455
456 return res;
407} 457}
408 458
409 459
@@ -411,21 +461,30 @@ BOOL LLImageJ2C::validate(U8 *data, U32 file_size)
411{ 461{
412 LLMemType mt1((LLMemType::EMemType)mMemType); 462 LLMemType mt1((LLMemType::EMemType)mMemType);
413 463
464 resetLastError();
465
414 setData(data, file_size); 466 setData(data, file_size);
467
415 BOOL res = updateData(); 468 BOOL res = updateData();
416 if ( !res ) 469 if ( res )
417 { 470 {
418 return FALSE; 471 // Check to make sure that this instance has been initialized with data
472 if (!getData() || (0 == getDataSize()))
473 {
474 setLastError("LLImageJ2C uninitialized");
475 res = FALSE;
476 }
477 else
478 {
479 res = mImpl->getMetadata(*this);
480 }
419 } 481 }
420 482
421 // Check to make sure that this instance has been initialized with data 483 if (!mLastError.empty())
422 if (!getData() || (0 == getDataSize()))
423 { 484 {
424 setLastError("LLImageJ2C uninitialized"); 485 LLImage::setLastError(mLastError);
425 return FALSE;
426 } 486 }
427 487 return res;
428 return mImpl->getMetadata(*this);
429} 488}
430 489
431void LLImageJ2C::decodeFailed() 490void LLImageJ2C::decodeFailed()