From 28f183b98a6159e111de55b283f6ed35e6046847 Mon Sep 17 00:00:00 2001 From: Drons Date: Wed, 7 Oct 2015 17:48:26 +0300 Subject: [PATCH 1/2] Fix access to ECW files with names in UTF-8 Conflicts: gdal/frmts/ecw/ecwdataset.cpp Conflicts: gdal/frmts/ecw/ecwdataset.cpp --- gdal/frmts/ecw/ecwcreatecopy.cpp | 18 ++++++++++++++++-- gdal/frmts/ecw/ecwdataset.cpp | 12 +++++++++++- gdal/frmts/ecw/gdal_ecw.h | 16 ++++++++++++++-- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/gdal/frmts/ecw/ecwcreatecopy.cpp b/gdal/frmts/ecw/ecwcreatecopy.cpp index 40a075ac13e5..3488028667e8 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,23 @@ CPLErr GDALECWCompressor::Initialize( if( oError.GetErrorNumber() == NCS_SUCCESS ) { if( fpVSIL == NULL ) - oError = Open( (char *) pszFilename, false, true ); + { + 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 + { + 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..90c55a83eccb 100644 --- a/gdal/frmts/ecw/ecwdataset.cpp +++ b/gdal/frmts/ecw/ecwdataset.cpp @@ -2388,7 +2388,17 @@ 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( 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 + { + 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..47b0bc6774a9 100644 --- a/gdal/frmts/ecw/gdal_ecw.h +++ b/gdal/frmts/ecw/gdal_ecw.h @@ -266,8 +266,20 @@ 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( 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 + { + return(CNCSJPCIOStream::Open((char *)osFilenameUsed.c_str(), + (bool) bWrite)); + } } virtual bool NCS_FASTCALL Seek() { From f1d18cc1c6fe404941c2bbb2134b892b75747a49 Mon Sep 17 00:00:00 2001 From: Drons Date: Thu, 8 Oct 2015 18:43:06 +0300 Subject: [PATCH 2/2] Fix compilation with libecwj2. Fix tab sizes --- gdal/frmts/ecw/ecwcreatecopy.cpp | 18 ++++++++++-------- gdal/frmts/ecw/ecwdataset.cpp | 24 +++++++++++++----------- gdal/frmts/ecw/gdal_ecw.h | 29 +++++++++++++++-------------- 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/gdal/frmts/ecw/ecwcreatecopy.cpp b/gdal/frmts/ecw/ecwcreatecopy.cpp index 3488028667e8..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 ); } @@ -1070,14 +1070,16 @@ CPLErr GDALECWCompressor::Initialize( { if( fpVSIL == NULL ) { - if( CSLTestBoolean( CPLGetConfigOption( "GDAL_FILENAME_IS_UTF8", "YES" ) ) ) - { - wchar_t *pwszFilename = CPLRecodeToWChar( pszFilename, CPL_ENC_UTF8, CPL_ENC_UCS2 ); +#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 + oError = Open( pwszFilename, false, true ); + CPLFree( pwszFilename ); + } + else +#endif//ECWSDK_VERSION>=40 { oError = Open( (char *) pszFilename, false, true ); } diff --git a/gdal/frmts/ecw/ecwdataset.cpp b/gdal/frmts/ecw/ecwdataset.cpp index 90c55a83eccb..b87b68d92ad3 100644 --- a/gdal/frmts/ecw/ecwdataset.cpp +++ b/gdal/frmts/ecw/ecwdataset.cpp @@ -2388,17 +2388,19 @@ CNCSJP2FileView *ECWDataset::OpenFileView( const char *pszDatasetName, //we always open in read only mode. This should be improved in the future. try { - 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 - { - 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 47b0bc6774a9..18acedc0921d 100644 --- a/gdal/frmts/ecw/gdal_ecw.h +++ b/gdal/frmts/ecw/gdal_ecw.h @@ -266,20 +266,21 @@ class VSIIOStream : public CNCSJPCIOStream } CPLDebug( "ECW", "Using filename '%s' for temporary directory determination purposes.", osFilenameUsed.c_str() ); } - - 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 - { - 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() {