/* Stop libjpeg from printing to stderr - Do Nothing */
}
+ /**
+ * LibJPEG Turbo tjDecompress2 API doesn't distinguish between errors that still allow
+ * the JPEG to be displayed and fatal errors.
+ */
+ bool IsJpegErrorFatal( const std::string& errorMessage )
+ {
+ if( ( errorMessage.find("Corrupt JPEG data") != std::string::npos ) ||
+ ( errorMessage.find("Invalid SOS parameters") != std::string::npos ) )
+ {
+ return false;
+ }
+ return true;
+ }
+
+
/** Simple struct to ensure xif data is deleted. */
struct ExifAutoPtr
{
Vector<unsigned char> jpegBuffer;
try
{
- jpegBuffer.Reserve( jpegBufferSize );
+ jpegBuffer.Resize( jpegBufferSize );
}
catch(...)
{
// Pull the compressed JPEG image bytes out of a file and into memory:
if( fread( jpegBufferPtr, 1, jpegBufferSize, fp ) != jpegBufferSize )
{
- DALI_LOG_WARNING("Error on image file read.");
+ DALI_LOG_WARNING("Error on image file read.\n");
return false;
}
if(preXformImageWidth == 0 || preXformImageHeight == 0)
{
- DALI_LOG_WARNING("Invalid Image!");
+ DALI_LOG_WARNING("Invalid Image!\n");
return false;
}
{
std::string errorString = tjGetErrorStr();
- if( errorString.find("Corrupt JPEG data") == std::string::npos )
+ if( IsJpegErrorFatal( errorString ) )
{
DALI_LOG_ERROR("%s\n", errorString.c_str());
return false;
{
DALI_LOG_WARNING("%s\n", errorString.c_str());
}
-
- //TurboJPEG API functions will now return an error code if a warning is triggered in the underlying libjpeg API.
- //So, we need to distinguish return of tjGetErrorStr() is warning or error.
- //If the return string has 'Corrupt JPEG data' prefix, it means warning.
}
const unsigned int bufferWidth = GetTextureDimension( scaledPreXformWidth );
iw = width;
ih = height;
Vector<unsigned char> data;
- data.Reserve(width * height * bpp);
+ data.Resize(width * height * bpp);
unsigned char *dataPtr = data.Begin();
memcpy(dataPtr, buffer, width * height * bpp);
w = ih;
iw = width;
ih = height;
Vector<unsigned char> data;
- data.Reserve(width * height * bpp);
+ data.Resize(width * height * bpp);
unsigned char *dataPtr = data.Begin();
memcpy(dataPtr, buffer, width * height * bpp);
w = ih;
bool EncodeToJpeg( const unsigned char* const pixelBuffer, Vector< unsigned char >& encodedPixels,
const std::size_t width, const std::size_t height, const Pixel::Format pixelFormat, unsigned quality )
{
+
if( !pixelBuffer )
{
DALI_LOG_ERROR("Null input buffer\n");
}
default:
{
- DALI_LOG_ERROR( "Unsupported pixel format for encoding to JPEG." );
+ DALI_LOG_ERROR( "Unsupported pixel format for encoding to JPEG.\n" );
return false;
}
}
// save the pixels to a persistent buffer that we own and let our cleaner
// class clean up the buffer as it goes out of scope:
AutoJpgMem cleaner( dstBuffer );
- encodedPixels.Reserve( dstBufferSize );
+ encodedPixels.Resize( dstBufferSize );
memcpy( encodedPixels.Begin(), dstBuffer, dstBufferSize );
}
return true;
default:
{
// Try to keep loading the file, but let app developer know there was something fishy:
- DALI_LOG_WARNING( "Incorrect/Unknown Orientation setting found in EXIF header of JPEG image (%x). Orientation setting will be ignored.", entry );
+ DALI_LOG_WARNING( "Incorrect/Unknown Orientation setting found in EXIF header of JPEG image (%x). Orientation setting will be ignored.\n", entry );
break;
}
}
tjscalingfactor* factors = tjGetScalingFactors( &numFactors );
if( factors == NULL )
{
- DALI_LOG_WARNING("TurboJpeg tjGetScalingFactors error!");
+ DALI_LOG_WARNING("TurboJpeg tjGetScalingFactors error!\n");
success = false;
}
else