summaryrefslogtreecommitdiff
path: root/indra/llimage/llimagejpeg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llimage/llimagejpeg.cpp')
-rw-r--r--indra/llimage/llimagejpeg.cpp80
1 files changed, 49 insertions, 31 deletions
diff --git a/indra/llimage/llimagejpeg.cpp b/indra/llimage/llimagejpeg.cpp
index aebe87d626..b70f84efc8 100644
--- a/indra/llimage/llimagejpeg.cpp
+++ b/indra/llimage/llimagejpeg.cpp
@@ -1,30 +1,25 @@
/**
* @file llimagejpeg.cpp
*
- * $LicenseInfo:firstyear=2002&license=viewergpl$
- *
- * Copyright (c) 2002-2007, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlife.com/developers/opensource/gplv2
+ * Copyright (C) 2010, Linden Research, Inc.
*
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at http://secondlife.com/developers/opensource/flossexception
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
*
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -35,12 +30,13 @@
#include "llerror.h"
-LLImageJPEG::LLImageJPEG()
+jmp_buf LLImageJPEG::sSetjmpBuffer ;
+LLImageJPEG::LLImageJPEG(S32 quality)
:
LLImageFormatted(IMG_CODEC_JPEG),
mOutputBuffer( NULL ),
mOutputBufferSize( 0 ),
- mEncodeQuality( 75 ) // on a scale from 1 to 100
+ mEncodeQuality( quality ) // on a scale from 1 to 100
{
}
@@ -76,7 +72,16 @@ BOOL LLImageJPEG::updateData()
jerr.error_exit = &LLImageJPEG::errorExit; // Error exit handler: does not return to caller
jerr.emit_message = &LLImageJPEG::errorEmitMessage; // Conditionally emit a trace or warning message
jerr.output_message = &LLImageJPEG::errorOutputMessage; // Routine that actually outputs a trace or error message
-
+
+ //
+ //try/catch will crash on Mac and Linux if LLImageJPEG::errorExit throws an error
+ //so as instead, we use setjmp/longjmp to avoid this crash, which is the best we can get. --bao
+ //
+ if(setjmp(sSetjmpBuffer))
+ {
+ jpeg_destroy_decompress(&cinfo);
+ return FALSE;
+ }
try
{
// Now we can initialize the JPEG decompression object.
@@ -177,6 +182,7 @@ void LLImageJPEG::decodeTermSource (j_decompress_ptr cinfo)
}
+// Returns true when done, whether or not decode was successful.
BOOL LLImageJPEG::decode(LLImageRaw* raw_image, F32 decode_time)
{
llassert_always(raw_image);
@@ -187,7 +193,7 @@ BOOL LLImageJPEG::decode(LLImageRaw* raw_image, F32 decode_time)
if (!getData() || (0 == getDataSize()))
{
setLastError("LLImageJPEG trying to decode an image with no data!");
- return FALSE;
+ return TRUE; // done
}
S32 row_stride = 0;
@@ -208,7 +214,15 @@ BOOL LLImageJPEG::decode(LLImageRaw* raw_image, F32 decode_time)
jerr.emit_message = &LLImageJPEG::errorEmitMessage; // Conditionally emit a trace or warning message
jerr.output_message = &LLImageJPEG::errorOutputMessage; // Routine that actually outputs a trace or error message
-
+ //
+ //try/catch will crash on Mac and Linux if LLImageJPEG::errorExit throws an error
+ //so as instead, we use setjmp/longjmp to avoid this crash, which is the best we can get. --bao
+ //
+ if(setjmp(sSetjmpBuffer))
+ {
+ jpeg_destroy_decompress(&cinfo);
+ return TRUE; // done
+ }
try
{
// Now we can initialize the JPEG decompression object.
@@ -301,7 +315,7 @@ BOOL LLImageJPEG::decode(LLImageRaw* raw_image, F32 decode_time)
catch (int)
{
jpeg_destroy_decompress(&cinfo);
- return FALSE;
+ return TRUE; // done
}
// Check to see whether any corrupt-data warnings occurred
@@ -309,7 +323,7 @@ BOOL LLImageJPEG::decode(LLImageRaw* raw_image, F32 decode_time)
{
// TODO: extract the warning to find out what went wrong.
setLastError( "Unable to decode JPEG image.");
- return FALSE;
+ return TRUE; // done
}
return TRUE;
@@ -402,7 +416,7 @@ void LLImageJPEG::errorExit( j_common_ptr cinfo )
jpeg_destroy(cinfo);
// Return control to the setjmp point
- throw 1;
+ longjmp(sSetjmpBuffer, 1) ;
}
// Decide whether to emit a trace or warning message.
@@ -447,7 +461,8 @@ void LLImageJPEG::errorOutputMessage( j_common_ptr cinfo )
char buffer[JMSG_LENGTH_MAX]; /* Flawfinder: ignore */
(*cinfo->err->format_message) (cinfo, buffer);
- ((LLImageJPEG*) cinfo->client_data)->setLastError( buffer );
+ std::string error = buffer ;
+ LLImage::setLastError(error);
BOOL is_decode = (cinfo->is_decompressor != 0);
llwarns << "LLImageJPEG " << (is_decode ? "decode " : "encode ") << " failed: " << buffer << llendl;
@@ -500,8 +515,11 @@ BOOL LLImageJPEG::encode( const LLImageRaw* raw_image, F32 encode_time )
jerr.emit_message = &LLImageJPEG::errorEmitMessage; // Conditionally emit a trace or warning message
jerr.output_message = &LLImageJPEG::errorOutputMessage; // Routine that actually outputs a trace or error message
- // Establish the setjmp return context mSetjmpBuffer. Used by library to abort.
- if( setjmp(mSetjmpBuffer) )
+ //
+ //try/catch will crash on Mac and Linux if LLImageJPEG::errorExit throws an error
+ //so as instead, we use setjmp/longjmp to avoid this crash, which is the best we can get. --bao
+ //
+ if( setjmp(sSetjmpBuffer) )
{
// If we get here, the JPEG code has signaled an error.
// We need to clean up the JPEG object, close the input file, and return.