From 7d5d742070a9ae0f5f4e1e0a437c6f703cf6649e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 7 Feb 2012 10:33:09 +0000 Subject: [PATCH] From Sukender, "I just fixed using UTF8 paths in JP2 readerwriter under Windows. Jpeg2000 plugin could not handle UTF8 paths as it was using an Japser open() function which seems to be based on the standard fopen(). The fix simply opens the file beforehand and only gives a FILE* to the Jasper lib (and then closes the file, of course). " --- src/osgPlugins/jp2/ReaderWriterJP2.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/osgPlugins/jp2/ReaderWriterJP2.cpp b/src/osgPlugins/jp2/ReaderWriterJP2.cpp index 6078d8078..2e1a3e9de 100644 --- a/src/osgPlugins/jp2/ReaderWriterJP2.cpp +++ b/src/osgPlugins/jp2/ReaderWriterJP2.cpp @@ -189,7 +189,7 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter jas_cleanup(); } - virtual const char* className() const { return "RGB Image Reader/Writer"; } + virtual const char* className() const { return "JPEG 2000 Image Reader/Writer"; } virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const { @@ -217,7 +217,15 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter return img; } - jas_stream_t* in = jas_stream_fopen(fileName.c_str(), "rb"); + FILE * fileHandle = osgDB::fopen(fileName.c_str(), "rb"); + if (!fileHandle) { + return ReadResult::ERROR_IN_READING_FILE; + } + jas_stream_t* in = jas_stream_freopen(fileName.c_str(), "rb", fileHandle); // Replacement for jas_stream_fopen() to be able to support UTF8 + if (!in) { + fclose(fileHandle); + return ReadResult::ERROR_IN_READING_FILE; + } char* opt = 0; if(options) @@ -242,6 +250,7 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter jas_image_destroy(jimage); jas_stream_close(in); + fclose(fileHandle); unsigned int pixelFormat = internalFormat == 1 ? GL_LUMINANCE : @@ -412,9 +421,15 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter getdata(mem, jimage); - jas_stream_t* out = jas_stream_fopen(fileName.c_str(), "wb"); - if (!out) + FILE * fileHandle = osgDB::fopen(fileName.c_str(), "wb"); + if (!fileHandle) { return WriteResult::ERROR_IN_WRITING_FILE; + } + jas_stream_t* out = jas_stream_freopen(fileName.c_str(), "wb", fileHandle); // Replacement for jas_stream_fopen() to be able to support UTF8 + if (!out) { + fclose(fileHandle); + return WriteResult::ERROR_IN_WRITING_FILE; + } char* opt = 0; if(options) @@ -429,6 +444,7 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter jas_stream_close(out); jas_image_destroy(jimage); + fclose(fileHandle); return WriteResult::FILE_SAVED; } @@ -495,7 +511,6 @@ class ReaderWriterJP2 : public osgDB::ReaderWriter getdata(mem, jimage); jas_stream_t* out = jas_stream_memopen(0, 0); -// jas_stream_t* out = jas_stream_fopen(fileName.c_str(), "wb"); if (!out) return WriteResult::ERROR_IN_WRITING_FILE;