diff --git a/gdal/frmts/ecw/ecwcreatecopy.cpp b/gdal/frmts/ecw/ecwcreatecopy.cpp index 40a075ac13e5..0cc873968fd4 100644 --- a/gdal/frmts/ecw/ecwcreatecopy.cpp +++ b/gdal/frmts/ecw/ecwcreatecopy.cpp @@ -993,7 +993,7 @@ CPLErr GDALECWCompressor::Initialize( return CE_Failure; } - m_OStream.Access( fpVSIL, TRUE, (BOOLEAN) bSeekable, pszFilename, + m_OStream.Access( fpVSIL, TRUE, (BOOLEAN) bSeekable, pszFilename, 0, -1 ); } @@ -1069,9 +1069,25 @@ CPLErr GDALECWCompressor::Initialize( if( oError.GetErrorNumber() == NCS_SUCCESS ) { if( fpVSIL == NULL ) - oError = Open( (char *) pszFilename, false, true ); + { +#if ECWSDK_VERSION>=40 + if( CSLTestBoolean( CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) ) + { + wchar_t *pwszFilename = CPLRecodeToWChar( pszFilename, CPL_ENC_UTF8, CPL_ENC_UCS2 ); + + oError = Open( pwszFilename, false, true ); + CPLFree( pwszFilename ); + } + else +#endif//ECWSDK_VERSION>=40 + { + oError = Open( (char *) pszFilename, false, true ); + } + } else + { oError = CNCSJP2FileView::Open( &(m_OStream) ); + } } if( oError.GetErrorNumber() == NCS_SUCCESS ) diff --git a/gdal/frmts/ecw/ecwdataset.cpp b/gdal/frmts/ecw/ecwdataset.cpp index f1f0f150b149..b87b68d92ad3 100644 --- a/gdal/frmts/ecw/ecwdataset.cpp +++ b/gdal/frmts/ecw/ecwdataset.cpp @@ -2388,7 +2388,19 @@ CNCSJP2FileView *ECWDataset::OpenFileView( const char *pszDatasetName, //we always open in read only mode. This should be improved in the future. try { - oErr = poFileView->Open( (char *) pszDatasetName, bProgressive, false ); +#if ECWSDK_VERSION>=40 + if( CSLTestBoolean( CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) ) + { + wchar_t *pwszDatasetName = CPLRecodeToWChar( pszDatasetName, CPL_ENC_UTF8, CPL_ENC_UCS2 ); + + oErr = poFileView->Open( pwszDatasetName, bProgressive, false ); + CPLFree( pwszDatasetName ); + } + else +#endif //#if ECWSDK_VERSION>=40 + { + oErr = poFileView->Open( (char *) pszDatasetName, bProgressive, false ); + } } catch(...) { diff --git a/gdal/frmts/ecw/gdal_ecw.h b/gdal/frmts/ecw/gdal_ecw.h index 99c3b18582de..18acedc0921d 100644 --- a/gdal/frmts/ecw/gdal_ecw.h +++ b/gdal/frmts/ecw/gdal_ecw.h @@ -266,8 +266,21 @@ class VSIIOStream : public CNCSJPCIOStream } CPLDebug( "ECW", "Using filename '%s' for temporary directory determination purposes.", osFilenameUsed.c_str() ); } - return(CNCSJPCIOStream::Open((char *)osFilenameUsed.c_str(), - (bool) bWrite)); +#if ECWSDK_VERSION>=40 + if( CSLTestBoolean( CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) ) + { + wchar_t *pwszFilename = CPLRecodeToWChar( pszFilename, CPL_ENC_UTF8, CPL_ENC_UCS2 ); + CNCSError oError; + oError = CNCSJPCIOStream::Open( pwszFilename, (bool) bWrite ); + CPLFree( pwszFilename ); + return oError; + } + else +#endif//ECWSDK_VERSION>=40 + { + return(CNCSJPCIOStream::Open((char *)osFilenameUsed.c_str(), + (bool) bWrite)); + } } virtual bool NCS_FASTCALL Seek() {