From a87b691e337c3198e3bd69f478d0889796f8cfee Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sun, 10 Apr 2011 14:27:10 -0700 Subject: [PATCH 1/3] Fix output height in plJPEG writer --- .../Plasma20/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp index e979e512..af714daa 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp @@ -419,7 +419,7 @@ hsBool plJPEG::IWrite( plMipmap *source, hsStream *outStream ) jcProps.jquality = fWriteQuality; #else 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 // not sure how to set 4:1:1 but supposedly it's the default jpeg_set_quality( &cinfo, fWriteQuality, TRUE ); From c3657d20a4b43a932c2362175afdd0c0b4b1f72a Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Tue, 10 May 2011 02:56:28 -0700 Subject: [PATCH 2/3] Fix incorrect JPEG file IO. --- .../Plasma/PubUtilLib/plJPEG/plJPEG.cpp | 37 ++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp index af714daa..7bb457d8 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/PubUtilLib/plJPEG/plJPEG.cpp @@ -328,11 +328,25 @@ plMipmap* plJPEG::ReadFromFile( const char *fileName ) plMipmap* plJPEG::ReadFromFile( const wchar *fileName ) { // we use a stream because the IJL can't handle unicode - hsUNIXStream out; - if (!out.Open(fileName, L"rb")) + hsRAMStream tempstream; + hsUNIXStream in; + if (!in.Open(fileName, L"rb")) 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; } @@ -487,10 +501,23 @@ hsBool plJPEG::WriteToFile( const char *fileName, plMipmap *sourceData ) hsBool plJPEG::WriteToFile( const wchar *fileName, plMipmap *sourceData ) { // we use a stream because the IJL can't handle unicode + hsRAMStream tempstream; hsUNIXStream out; if (!out.Open(fileName, L"wb")) 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(); return ret; } From 1cac4f85daa273f2e4685988ebb513b8740bfd09 Mon Sep 17 00:00:00 2001 From: Joseph Davies Date: Thu, 9 Feb 2012 23:47:22 -0800 Subject: [PATCH 3/3] Fix a potential crash in pyVaultImageNode. Fixes a crash which can occur when attempting to fetch an unsupported image type. --- .../Sources/Plasma/FeatureLib/pfPython/pyVaultImageNode.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyVaultImageNode.cpp b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyVaultImageNode.cpp index a771f122..3d463e8c 100644 --- a/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyVaultImageNode.cpp +++ b/MOULOpenSourceClientPlugin/Plasma20/Sources/Plasma/FeatureLib/pfPython/pyVaultImageNode.cpp @@ -171,6 +171,8 @@ PyObject* pyVaultImageNode::Image_GetImage( void ) else fMipmapKey->RefObject(); } + else + PYTHON_RETURN_NONE; } return pyImage::New(fMipmap);