Browse Source

Merged in Lyrositor/cwe-ou/jpeg (pull request #15)

Fix various JPEG issues.

These three commits fix various issues with JPEG images in Uru.
avatar-spawn
Christian Walther 12 years ago
parent
commit
368d757bf8
  1. 2
      MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyVaultImageNode.cpp
  2. 39
      MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp

2
MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyVaultImageNode.cpp

@ -171,6 +171,8 @@ PyObject* pyVaultImageNode::Image_GetImage( void )
else else
fMipmapKey->RefObject(); fMipmapKey->RefObject();
} }
else
PYTHON_RETURN_NONE;
} }
return pyImage::New(fMipmap); return pyImage::New(fMipmap);

39
MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp

@ -328,11 +328,25 @@ plMipmap* plJPEG::ReadFromFile( const char *fileName )
plMipmap* plJPEG::ReadFromFile( const wchar *fileName ) plMipmap* plJPEG::ReadFromFile( const wchar *fileName )
{ {
// we use a stream because the IJL can't handle unicode // we use a stream because the IJL can't handle unicode
hsUNIXStream out; hsRAMStream tempstream;
if (!out.Open(fileName, L"rb")) hsUNIXStream in;
if (!in.Open(fileName, L"rb"))
return false; return false;
plMipmap* ret = IRead(&out);
out.Close(); // The stream reader for JPEGs expects a 32-bit size at the start,
// so insert that into the stream before passing it on
in.FastFwd();
UInt32 fsize = in.GetPosition();
UInt8 *tempbuffer = TRACKED_NEW UInt8[fsize];
in.Rewind();
in.Read(fsize, tempbuffer);
tempstream.WriteSwap32(fsize);
tempstream.Write(fsize, tempbuffer);
delete [] tempbuffer;
tempstream.Rewind();
plMipmap* ret = IRead(&tempstream);
in.Close();
return ret; return ret;
} }
@ -419,7 +433,7 @@ hsBool plJPEG::IWrite( plMipmap *source, hsStream *outStream )
jcProps.jquality = fWriteQuality; jcProps.jquality = fWriteQuality;
#else #else
cinfo.jpeg_width = source->GetWidth(); // default cinfo.jpeg_width = source->GetWidth(); // default
cinfo.jpeg_width = source->GetHeight(); // default cinfo.jpeg_height = source->GetHeight(); // default
cinfo.jpeg_color_space = JCS_YCbCr; // default cinfo.jpeg_color_space = JCS_YCbCr; // default
// not sure how to set 4:1:1 but supposedly it's the default // not sure how to set 4:1:1 but supposedly it's the default
jpeg_set_quality( &cinfo, fWriteQuality, TRUE ); jpeg_set_quality( &cinfo, fWriteQuality, TRUE );
@ -487,10 +501,23 @@ hsBool plJPEG::WriteToFile( const char *fileName, plMipmap *sourceData )
hsBool plJPEG::WriteToFile( const wchar *fileName, plMipmap *sourceData ) hsBool plJPEG::WriteToFile( const wchar *fileName, plMipmap *sourceData )
{ {
// we use a stream because the IJL can't handle unicode // we use a stream because the IJL can't handle unicode
hsRAMStream tempstream;
hsUNIXStream out; hsUNIXStream out;
if (!out.Open(fileName, L"wb")) if (!out.Open(fileName, L"wb"))
return false; return false;
hsBool ret = IWrite(sourceData, &out); hsBool ret = IWrite(sourceData, &tempstream);
if (ret)
{
// The stream writer for JPEGs prepends a 32-bit size,
// so remove that from the stream before saving to a file
tempstream.Rewind();
UInt32 fsize = tempstream.ReadSwap32();
UInt8 *tempbuffer = TRACKED_NEW UInt8[fsize];
tempstream.Read(fsize, tempbuffer);
out.Write(fsize, tempbuffer);
delete [] tempbuffer;
}
out.Close(); out.Close();
return ret; return ret;
} }

Loading…
Cancel
Save