LCOV - code coverage report
Current view: top level - frmts/ecw - gdal_ecw.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 83 120 69.2 %
Date: 2026-02-12 23:49:34 Functions: 13 14 92.9 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  ECW (ERDAS Wavelet Compression Format) Driver Definitions
       5             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2001-2011, Frank Warmerdam <warmerdam@pobox.com>
       9             :  * Copyright (c) 2013, Even Rouault <even dot rouault at spatialys.com>
      10             :  *
      11             :  * SPDX-License-Identifier: MIT
      12             :  ****************************************************************************/
      13             : 
      14             : #ifndef GDAL_ECW_H_INCLUDED
      15             : #define GDAL_ECW_H_INCLUDED
      16             : 
      17             : #include "gdaljp2abstractdataset.h"
      18             : #include "gdal_frmts.h"
      19             : #include "cpl_string.h"
      20             : #include "cpl_conv.h"
      21             : #include "cpl_multiproc.h"
      22             : #include "cpl_vsi.h"
      23             : #include "gdal_asyncreader.h"
      24             : 
      25             : #undef NOISY_DEBUG
      26             : 
      27             : #include "ecwsdk_headers.h"
      28             : 
      29             : #if ECWSDK_VERSION >= 55
      30             : #include "NCSIOStreamOptions.h"
      31             : #endif
      32             : 
      33             : void ECWInitialize(void);
      34             : GDALDataset *ECWDatasetOpenJPEG2000(GDALOpenInfo *poOpenInfo);
      35             : const char *ECWGetColorInterpretationName(GDALColorInterp eColorInterpretation,
      36             :                                           int nBandNumber);
      37             : GDALColorInterp ECWGetColorInterpretationByName(const char *pszName);
      38             : const char *ECWGetColorSpaceName(NCSFileColorSpace colorSpace);
      39             : #ifdef HAVE_COMPRESS
      40             : GDALDataset *ECWCreateCopyECW(const char *pszFilename, GDALDataset *poSrcDS,
      41             :                               int bStrict, CSLConstList papszOptions,
      42             :                               GDALProgressFunc pfnProgress,
      43             :                               void *pProgressData);
      44             : GDALDataset *ECWCreateCopyJPEG2000(const char *pszFilename,
      45             :                                    GDALDataset *poSrcDS, int bStrict,
      46             :                                    CSLConstList papszOptions,
      47             :                                    GDALProgressFunc pfnProgress,
      48             :                                    void *pProgressData);
      49             : 
      50             : GDALDataset *ECWCreateECW(const char *pszFilename, int nXSize, int nYSize,
      51             :                           int nBands, GDALDataType eType,
      52             :                           CSLConstList papszOptions);
      53             : GDALDataset *ECWCreateJPEG2000(const char *pszFilename, int nXSize, int nYSize,
      54             :                                int nBands, GDALDataType eType,
      55             :                                CSLConstList papszOptions);
      56             : #endif
      57             : 
      58             : void ECWReportError(CNCSError &oErr, const char *pszMsg = "");
      59             : 
      60             : /************************************************************************/
      61             : /* ==================================================================== */
      62             : /*                             JP2Userbox                               */
      63             : /* ==================================================================== */
      64             : /************************************************************************/
      65             : #ifdef HAVE_COMPRESS
      66             : #if ECWSDK_VERSION >= 50
      67             : class JP2UserBox final : public CNCSSDKBox
      68             : {
      69             : #else
      70             : class JP2UserBox final : public CNCSJP2Box
      71             : {
      72             : #endif
      73             :   private:
      74             :     int nDataLength;
      75             :     unsigned char *pabyData;
      76             : 
      77             :   public:
      78             :     JP2UserBox();
      79             : 
      80             :     ~JP2UserBox() override;
      81             : 
      82             : #if ECWSDK_VERSION >= 55
      83             :     CNCSError Parse(NCS::SDK::CFileBase &JP2File,
      84             :                     const NCS::CIOStreamPtr &Stream) override;
      85             :     CNCSError UnParse(NCS::SDK::CFileBase &JP2File,
      86             :                       const NCS::CIOStreamPtr &Stream) override;
      87             : #elif ECWSDK_VERSION >= 40
      88             :     virtual CNCSError Parse(NCS::SDK::CFileBase &JP2File,
      89             :                             NCS::CIOStream &Stream) override;
      90             :     virtual CNCSError UnParse(NCS::SDK::CFileBase &JP2File,
      91             :                               NCS::CIOStream &Stream) override;
      92             : #else
      93             : virtual CNCSError Parse(class CNCSJP2File &JP2File,
      94             :                         CNCSJPCIOStream &Stream) override;
      95             : virtual CNCSError UnParse(class CNCSJP2File &JP2File,
      96             :                           CNCSJPCIOStream &Stream) override;
      97             : #endif
      98             :     void UpdateXLBox() override;
      99             : 
     100             :     void SetData(int nDataLength, const unsigned char *pabyDataIn);
     101             : 
     102             :     int GetDataLength()
     103             :     {
     104             :         return nDataLength;
     105             :     }
     106             : 
     107             :     unsigned char *GetData()
     108             :     {
     109             :         return pabyData;
     110             :     }
     111             : };
     112             : #endif /* def HAVE_COMPRESS */
     113             : 
     114             : /************************************************************************/
     115             : /* ==================================================================== */
     116             : /*                             VSIIOStream                              */
     117             : /* ==================================================================== */
     118             : /************************************************************************/
     119             : 
     120             : class VSIIOStream final : public CNCSJPCIOStream
     121             : {
     122             :     VSIIOStream(const VSIIOStream &) = delete;
     123             :     VSIIOStream &operator=(const VSIIOStream &) = delete;
     124             :     VSIIOStream(VSIIOStream &&) = delete;
     125             :     VSIIOStream &operator=(VSIIOStream &&) = delete;
     126             : 
     127             :     char *m_Filename = nullptr;
     128             : 
     129             :   public:
     130             :     INT64 startOfJPData = 0;
     131             :     INT64 lengthOfJPData = -1;
     132             :     VSILFILE *fpVSIL = nullptr;
     133             :     BOOLEAN bWritable = false;
     134             :     BOOLEAN bSeekable = false;
     135             :     int nFileViewCount = 0;
     136             : 
     137             :     int nCOMState = 0;
     138             :     int nCOMLength = 0;
     139             :     GByte abyCOMType[2]{};
     140             : 
     141             :     /* To fix ‘virtual bool NCS::CIOStream::Read(INT64, void*, UINT32)’ was
     142             :      * hidden' with SDK 5 */
     143             :     using CNCSJPCIOStream::Read;
     144             : 
     145         122 :     VSIIOStream()
     146         122 :     {
     147         122 :         if (CSLTestBoolean(CPLGetConfigOption(
     148         122 :                 "GDAL_ECW_WRITE_COMPRESSION_SOFTWARE", "YES")))
     149         122 :             nCOMState = -1;
     150         122 :         abyCOMType[0] = 0;
     151         122 :         abyCOMType[1] = 0;
     152         122 :     }
     153             : 
     154         175 :     virtual ~VSIIOStream()
     155         122 :     {
     156         122 :         VSIIOStream::Close();
     157         122 :         if (m_Filename != nullptr)
     158             :         {
     159          84 :             CPLFree(m_Filename);
     160             :         }
     161         175 :     }
     162             : 
     163         240 :     CNCSError Close() override
     164             :     {
     165         240 :         CNCSError oErr = CNCSJPCIOStream::Close();
     166         240 :         if (fpVSIL != nullptr)
     167             :         {
     168          84 :             VSIFCloseL(fpVSIL);
     169          84 :             fpVSIL = nullptr;
     170             :         }
     171         240 :         return oErr;
     172             :     }
     173             : 
     174             : #if ECWSDK_VERSION >= 40
     175             :     VSIIOStream *Clone() override
     176             :     {
     177             :         CPLDebug("ECW", "VSIIOStream::Clone()");
     178             :         VSILFILE *fpNewVSIL = VSIFOpenL(m_Filename, "rb");
     179             :         if (fpNewVSIL == nullptr)
     180             :         {
     181             :             return nullptr;
     182             :         }
     183             : 
     184             :         VSIIOStream *pDst = new VSIIOStream();
     185             :         pDst->Access(fpNewVSIL, bWritable, bSeekable, m_Filename, startOfJPData,
     186             :                      lengthOfJPData);
     187             :         return pDst;
     188             :     }
     189             : #endif /* ECWSDK_VERSION >= 4 */
     190             : 
     191          84 :     CNCSError Access(VSILFILE *fpVSILIn, BOOLEAN bWrite, BOOLEAN bSeekableIn,
     192             :                      const char *pszFilename, INT64 start, INT64 size = -1)
     193             :     {
     194             : 
     195          84 :         fpVSIL = fpVSILIn;
     196          84 :         startOfJPData = start;
     197          84 :         lengthOfJPData = size;
     198          84 :         bWritable = bWrite;
     199          84 :         bSeekable = bSeekableIn;
     200          84 :         VSIFSeekL(fpVSIL, static_cast<vsi_l_offset>(startOfJPData), SEEK_SET);
     201          84 :         m_Filename = CPLStrdup(pszFilename);
     202             : 
     203             : #if ECWSDK_VERSION >= 55
     204             :         const std::string vsiStreamPrefix("STREAM=/vsi");
     205             :         const std::string vsiPrefix("/vsi");
     206             :         m_StreamOptions->SetIsRemoteStream(
     207             :             std::string(m_Filename).compare(0, vsiPrefix.length(), vsiPrefix) ==
     208             :                 0 ||
     209             :             std::string(m_Filename)
     210             :                     .compare(0, vsiStreamPrefix.length(), vsiStreamPrefix) ==
     211             :                 0);
     212             : #endif
     213             :         // the filename is used to establish where to put temporary files.
     214             :         // if it does not have a path to a real directory, we will
     215             :         // substitute something.
     216         168 :         CPLString osFilenameUsed = pszFilename;
     217             : 
     218             : #if ECWSDK_VERSION < 55
     219         168 :         CPLString osPath = CPLGetPathSafe(pszFilename);
     220             :         struct stat sStatBuf;
     221          84 :         if (!osPath.empty() && stat(osPath, &sStatBuf) != 0)
     222             :         {
     223          69 :             osFilenameUsed = CPLGenerateTempFilenameSafe(nullptr);
     224             :             // try to preserve the extension.
     225         138 :             const auto osExt = CPLGetExtensionSafe(pszFilename);
     226          69 :             if (!osExt.empty())
     227             :             {
     228          68 :                 osFilenameUsed += ".";
     229          68 :                 osFilenameUsed += osExt;
     230             :             }
     231          69 :             CPLDebug("ECW",
     232             :                      "Using filename '%s' for temporary directory "
     233             :                      "determination purposes.",
     234             :                      osFilenameUsed.c_str());
     235             :         }
     236             : #endif
     237             : 
     238             : #ifdef _WIN32
     239             :         if (CSLTestBoolean(CPLGetConfigOption("GDAL_FILENAME_IS_UTF8", "YES")))
     240             :         {
     241             :             wchar_t *pwszFilename = CPLRecodeToWChar(
     242             :                 osFilenameUsed.c_str(), CPL_ENC_UTF8, CPL_ENC_UCS2);
     243             :             CNCSError oError;
     244             :             oError = CNCSJPCIOStream::Open(pwszFilename, (bool)bWrite);
     245             :             CPLFree(pwszFilename);
     246             :             return oError;
     247             :         }
     248             :         else
     249             : #endif
     250             :         {
     251          84 :             return (CNCSJPCIOStream::Open((char *)osFilenameUsed.c_str(),
     252         168 :                                           (bool)bWrite));
     253             :         }
     254             :     }
     255             : 
     256         396 :     bool NCS_FASTCALL Seek() override
     257             :     {
     258         396 :         return bSeekable;
     259             :     }
     260             : 
     261        1589 :     virtual bool NCS_FASTCALL Seek(INT64 offset,
     262             :                                    Origin origin = CURRENT) override
     263             :     {
     264             : #ifdef DEBUG_VERBOSE
     265             :         CPLDebug("ECW", "VSIIOStream::Seek(" CPL_FRMT_GIB ",%d)",
     266             :                  static_cast<GIntBig>(offset), (int)origin);
     267             : #endif
     268        1589 :         bool success = false;
     269        1589 :         switch (origin)
     270             :         {
     271        1303 :             case START:
     272        2606 :                 success = (0 == VSIFSeekL(fpVSIL,
     273        1303 :                                           static_cast<vsi_l_offset>(offset) +
     274        1303 :                                               startOfJPData,
     275             :                                           SEEK_SET));
     276        1303 :                 break;
     277             : 
     278           0 :             case CURRENT:
     279           0 :                 success =
     280           0 :                     (0 == VSIFSeekL(fpVSIL, static_cast<vsi_l_offset>(offset),
     281             :                                     SEEK_CUR));
     282           0 :                 break;
     283             : 
     284         286 :             case END:
     285         286 :                 success =
     286         286 :                     (0 == VSIFSeekL(fpVSIL, static_cast<vsi_l_offset>(offset),
     287             :                                     SEEK_END));
     288         286 :                 break;
     289             :         }
     290        1589 :         if (!success)
     291           0 :             CPLDebug("ECW", "VSIIOStream::Seek(%d,%d) failed.", (int)offset,
     292             :                      (int)origin);
     293        1589 :         return (success);
     294             :     }
     295             : 
     296        6027 :     INT64 NCS_FASTCALL Tell() override
     297             :     {
     298        6027 :         return VSIFTellL(fpVSIL) - startOfJPData;
     299             :     }
     300             : 
     301         286 :     INT64 NCS_FASTCALL Size() override
     302             :     {
     303         286 :         if (lengthOfJPData != -1)
     304           0 :             return lengthOfJPData;
     305             :         else
     306             :         {
     307         286 :             INT64 curPos = Tell(), size;
     308             : 
     309         286 :             Seek(0, END);
     310         286 :             size = Tell();
     311         286 :             Seek(curPos, START);
     312             : #ifdef DEBUG_VERBOSE
     313             :             CPLDebug("ECW", "VSIIOStream::Size()=" CPL_FRMT_GIB,
     314             :                      static_cast<GIntBig>(size));
     315             : #endif
     316         286 :             return size;
     317             :         }
     318             :     }
     319             : 
     320             : #if ECWSDK_VERSION >= 40
     321             :     /* New, and needed, in ECW SDK 4 */
     322             :     bool Read(INT64 offset, void *buffer, UINT32 count) override
     323             :     {
     324             : #ifdef DEBUG_VERBOSE
     325             :         CPLDebug("ECW", "VSIIOStream::Read(" CPL_FRMT_GIB ",%u)",
     326             :                  static_cast<GIntBig>(offset), count);
     327             : #endif
     328             :         /* SDK 4.3 doc says it is not supposed to update the file pointer. */
     329             :         /* Later versions have no comment... */
     330             :         INT64 curPos = Tell();
     331             :         Seek(offset, START);
     332             :         bool ret = Read(buffer, count);
     333             :         Seek(curPos, START);
     334             :         return ret;
     335             :     }
     336             : #endif
     337             : 
     338       10038 :     bool NCS_FASTCALL Read(void *buffer, UINT32 count) override
     339             :     {
     340             : #ifdef DEBUG_VERBOSE
     341             :         CPLDebug("ECW", "VSIIOStream::Read(%u)", count);
     342             : #endif
     343       10038 :         if (count == 0)
     344         366 :             return true;
     345             : 
     346             :         //        return(1 == VSIFReadL( buffer, count, 1, fpVSIL ) );
     347             : 
     348             :         // The following is a hack
     349        9672 :         if (VSIFReadL(buffer, count, 1, fpVSIL) != 1)
     350             :         {
     351           0 :             CPLDebug("VSIIOSTREAM",
     352             :                      "Read(%d) failed @ " CPL_FRMT_GIB ", ignoring failure.",
     353           0 :                      count, (VSIFTellL(fpVSIL) - startOfJPData));
     354             :         }
     355             : 
     356        9672 :         return true;
     357             :     }
     358             : 
     359        5350 :     bool NCS_FASTCALL Write(void *buffer, UINT32 count) override
     360             :     {
     361        5350 :         if (count == 0)
     362           0 :             return true;
     363             : 
     364        5350 :         GByte *paby = (GByte *)buffer;
     365        5350 :         if (nCOMState == 0)
     366             :         {
     367           0 :             if (count == 2 && paby[0] == 0xff && paby[1] == 0x64)
     368             :             {
     369           0 :                 nCOMState++;
     370           0 :                 return true;
     371             :             }
     372             :         }
     373        5350 :         else if (nCOMState == 1)
     374             :         {
     375           0 :             if (count == 2)
     376             :             {
     377           0 :                 nCOMLength = (paby[0] << 8) | paby[1];
     378           0 :                 nCOMState++;
     379           0 :                 return true;
     380             :             }
     381             :             else
     382             :             {
     383           0 :                 GByte prevBuffer[] = {0xff, 0x64};
     384           0 :                 VSIFWriteL(prevBuffer, 2, 1, fpVSIL);
     385           0 :                 nCOMState = 0;
     386             :             }
     387             :         }
     388        5350 :         else if (nCOMState == 2)
     389             :         {
     390           0 :             if (count == 2)
     391             :             {
     392           0 :                 abyCOMType[0] = paby[0];
     393           0 :                 abyCOMType[1] = paby[1];
     394           0 :                 nCOMState++;
     395           0 :                 return true;
     396             :             }
     397             :             else
     398             :             {
     399           0 :                 GByte prevBuffer[] = {(GByte)(nCOMLength >> 8),
     400           0 :                                       (GByte)(nCOMLength & 0xff)};
     401           0 :                 VSIFWriteL(prevBuffer, 2, 1, fpVSIL);
     402           0 :                 nCOMState = 0;
     403             :             }
     404             :         }
     405        5350 :         else if (nCOMState == 3)
     406             :         {
     407           0 :             if (count == (UINT32)nCOMLength - 4)
     408             :             {
     409           0 :                 nCOMState = 0;
     410           0 :                 return true;
     411             :             }
     412             :             else
     413             :             {
     414           0 :                 VSIFWriteL(abyCOMType, 2, 1, fpVSIL);
     415           0 :                 nCOMState = 0;
     416             :             }
     417             :         }
     418             : 
     419        5350 :         if (1 != VSIFWriteL(buffer, count, 1, fpVSIL))
     420             :         {
     421           0 :             CPLDebug("ECW", "VSIIOStream::Write(%d) failed.", (int)count);
     422           0 :             return false;
     423             :         }
     424             :         else
     425        5350 :             return true;
     426             :     }
     427             : };
     428             : 
     429             : /************************************************************************/
     430             : /* ==================================================================== */
     431             : /*                            ECWAsyncReader                            */
     432             : /* ==================================================================== */
     433             : /************************************************************************/
     434             : class ECWDataset;
     435             : 
     436             : #if ECWSDK_VERSION >= 40
     437             : 
     438             : class ECWAsyncReader final : public GDALAsyncReader
     439             : {
     440             :   private:
     441             :     CNCSJP2FileView *poFileView = nullptr;
     442             :     CPLMutex *hMutex = nullptr;
     443             :     int bUsingCustomStream = false;
     444             : 
     445             :     int bUpdateReady = false;
     446             :     int bComplete = false;
     447             : 
     448             :     static NCSEcwReadStatus RefreshCB(NCSFileView *);
     449             :     NCSEcwReadStatus ReadToBuffer();
     450             : 
     451             :   public:
     452             :     ECWAsyncReader();
     453             :     ~ECWAsyncReader() override;
     454             :     virtual GDALAsyncStatusType
     455             :     GetNextUpdatedRegion(double dfTimeout, int *pnXBufOff, int *pnYBufOff,
     456             :                          int *pnXBufSize, int *pnYBufSize) override;
     457             : 
     458             :     friend class ECWDataset;
     459             : };
     460             : #endif /* ECWSDK_VERSION >= 40 */
     461             : 
     462             : /************************************************************************/
     463             : /* ==================================================================== */
     464             : /*                              ECWDataset                              */
     465             : /* ==================================================================== */
     466             : /************************************************************************/
     467             : 
     468             : class ECWRasterBand;
     469             : 
     470             : typedef struct
     471             : {
     472             :     int bEnabled;
     473             :     int nBandsTried;
     474             : 
     475             :     int nXOff;
     476             :     int nYOff;
     477             :     int nXSize;
     478             :     int nYSize;
     479             :     int nBufXSize;
     480             :     int nBufYSize;
     481             :     GDALDataType eBufType;
     482             :     GByte *pabyData;
     483             : } ECWCachedMultiBandIO;
     484             : 
     485             : class CPL_DLL ECWDataset final : public GDALJP2AbstractDataset
     486             : {
     487             :     friend class ECWRasterBand;
     488             :     friend class ECWAsyncReader;
     489             : 
     490             :     int bIsJPEG2000;
     491             : 
     492             :     CNCSJP2FileView *poFileView;
     493             :     NCSFileViewFileInfoEx *psFileInfo;
     494             : 
     495             :     GDALDataType eRasterDataType;
     496             :     NCSEcwCellType eNCSRequestDataType;
     497             : 
     498             :     int bUsingCustomStream;
     499             : 
     500             :     // Current view window.
     501             :     int bWinActive;
     502             :     int nWinXOff, nWinYOff, nWinXSize, nWinYSize;
     503             :     int nWinBufXSize, nWinBufYSize;
     504             :     int nWinBandCount;
     505             :     int *panWinBandList;
     506             :     int nWinBufLoaded;
     507             :     void **papCurLineBuf;
     508             : 
     509             :     // Deferred advise read parameters
     510             :     int m_nAdviseReadXOff;
     511             :     int m_nAdviseReadYOff;
     512             :     int m_nAdviseReadXSize;
     513             :     int m_nAdviseReadYSize;
     514             :     int m_nAdviseReadBufXSize;
     515             :     int m_nAdviseReadBufYSize;
     516             :     int m_nAdviseReadBandCount;
     517             :     int *m_panAdviseReadBandList;
     518             : 
     519             :     char **papszGMLMetadata;
     520             : 
     521             :     ECWCachedMultiBandIO sCachedMultiBandIO;
     522             : 
     523             :     void ECW2WKTProjection();
     524             : 
     525             :     void CleanupWindow();
     526             :     CPLErr RunDeferredAdviseRead();
     527             :     int TryWinRasterIO(GDALRWFlag, int, int, int, int, GByte *, int, int,
     528             :                        GDALDataType, int, const int *, GSpacing nPixelSpace,
     529             :                        GSpacing nLineSpace, GSpacing nBandSpace,
     530             :                        GDALRasterIOExtraArg *psExtraArg);
     531             :     CPLErr LoadNextLine();
     532             : 
     533             : #if ECWSDK_VERSION >= 50
     534             : 
     535             :     NCSFileStatistics *pStatistics;
     536             :     int bStatisticsDirty;
     537             :     int bStatisticsInitialized;
     538             :     NCS::CError StatisticsEnsureInitialized();
     539             :     NCS::CError StatisticsWrite();
     540             :     void CleanupStatistics();
     541             :     void ReadFileMetaDataFromFile();
     542             : 
     543             :     int bFileMetaDataDirty;
     544             :     void WriteFileMetaData(NCSFileMetaData *pFileMetaDataCopy);
     545             : 
     546             : #endif
     547             : 
     548             :     static CNCSJP2FileView *OpenFileView(const char *pszDatasetName,
     549             :                                          bool bProgressive,
     550             :                                          int &bUsingCustomStream,
     551             :                                          bool bWrite = false);
     552             : 
     553             :     int bHdrDirty;
     554             :     CPLString m_osDatumCode;
     555             :     CPLString m_osProjCode;
     556             :     CPLString m_osUnitsCode;
     557             :     int bGeoTransformChanged;
     558             :     int bProjectionChanged;
     559             :     int bProjCodeChanged;
     560             :     int bDatumCodeChanged;
     561             :     int bUnitsCodeChanged;
     562             :     void WriteHeader();
     563             : 
     564             :     int bUseOldBandRasterIOImplementation;
     565             : 
     566             :     int bPreventCopyingSomeMetadata;
     567             : 
     568             :     int nBandIndexToPromoteTo8Bit;
     569             : 
     570             :     CPLStringList oECWMetadataList;
     571             :     CPLErr ReadBands(void *pData, int nBufXSize, int nBufYSize,
     572             :                      GDALDataType eBufType, int nBandCount,
     573             :                      GSpacing nPixelSpace, GSpacing nLineSpace,
     574             :                      GSpacing nBandSpace, GDALRasterIOExtraArg *psExtraArg);
     575             :     CPLErr ReadBandsDirectly(void *pData, int nBufXSize, int nBufYSize,
     576             :                              GDALDataType eBufType, int nBandCount,
     577             :                              GSpacing nPixelSpace, GSpacing nLineSpace,
     578             :                              GSpacing nBandSpace,
     579             :                              GDALRasterIOExtraArg *psExtraArg);
     580             : 
     581             :   public:
     582             :     explicit ECWDataset(int bIsJPEG2000);
     583             :     ~ECWDataset() override;
     584             : 
     585             :     static GDALDataset *Open(GDALOpenInfo *, int bIsJPEG2000);
     586             :     static GDALDataset *OpenJPEG2000(GDALOpenInfo *);
     587             :     static GDALDataset *OpenECW(GDALOpenInfo *);
     588             : 
     589          64 :     void SetPreventCopyingSomeMetadata(int b)
     590             :     {
     591          64 :         bPreventCopyingSomeMetadata = b;
     592          64 :     }
     593             : 
     594             :     CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
     595             :                      GDALDataType, int, BANDMAP_TYPE, GSpacing nPixelSpace,
     596             :                      GSpacing nLineSpace, GSpacing nBandSpace,
     597             :                      GDALRasterIOExtraArg *psExtraArg) override;
     598             : 
     599             :     char **GetMetadataDomainList() override;
     600             :     virtual const char *GetMetadataItem(const char *pszName,
     601             :                                         const char *pszDomain = "") override;
     602             :     CSLConstList GetMetadata(const char *pszDomain = "") override;
     603             : 
     604             :     CPLErr SetGeoTransform(const GDALGeoTransform &gt) override;
     605             :     CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
     606             : 
     607             :     CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
     608             :                            const char *pszDomain = "") override;
     609             :     CPLErr SetMetadata(CSLConstList papszMetadata,
     610             :                        const char *pszDomain = "") override;
     611             : 
     612             :     CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
     613             :                       int nBufXSize, int nBufYSize, GDALDataType eDT,
     614             :                       int nBandCount, int *panBandList,
     615             :                       CSLConstList papszOptions) override;
     616             : 
     617             :     // progressive methods
     618             : #if ECWSDK_VERSION >= 40
     619             :     virtual GDALAsyncReader *
     620             :     BeginAsyncReader(int nXOff, int nYOff, int nXSize, int nYSize, void *pBuf,
     621             :                      int nBufXSize, int nBufYSize, GDALDataType eBufType,
     622             :                      int nBandCount, int *panBandMap, int nPixelSpace,
     623             :                      int nLineSpace, int nBandSpace,
     624             :                      CSLConstList papszOptions) override;
     625             : 
     626             :     void EndAsyncReader(GDALAsyncReader *) override;
     627             : #endif /* ECWSDK_VERSION > 40 */
     628             : #if ECWSDK_VERSION >= 50
     629             :     int GetFormatVersion() const
     630             :     {
     631             :         return psFileInfo->nFormatVersion;
     632             :     }
     633             : #endif
     634             : };
     635             : 
     636             : /************************************************************************/
     637             : /* ==================================================================== */
     638             : /*                            ECWRasterBand                             */
     639             : /* ==================================================================== */
     640             : /************************************************************************/
     641             : 
     642             : class ECWRasterBand final : public GDALPamRasterBand
     643             : {
     644             :     friend class ECWDataset;
     645             : 
     646             :     // NOTE: poDS may be altered for NITF/JPEG2000 files!
     647             :     ECWDataset *poGDS;
     648             : 
     649             :     GDALColorInterp eBandInterp;
     650             : 
     651             :     int iOverview;  // -1 for base.
     652             : 
     653             :     std::vector<ECWRasterBand *> apoOverviews;
     654             : 
     655             : #if ECWSDK_VERSION >= 50
     656             : 
     657             :     int nStatsBandIndex = 0;
     658             :     int nStatsBandCount = 0;
     659             : 
     660             : #endif
     661             : 
     662             :     int bPromoteTo8Bit;
     663             : 
     664             :     // #if !defined(SDK_CAN_DO_SUPERSAMPLING)
     665             :     CPLErr OldIRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
     666             :                         GDALDataType, GSpacing nPixelSpace, GSpacing nLineSpace,
     667             :                         GDALRasterIOExtraArg *psExtraArg);
     668             :     // #endif
     669             : 
     670             :     CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
     671             :                      GDALDataType, GSpacing nPixelSpace, GSpacing nLineSpace,
     672             :                      GDALRasterIOExtraArg *psExtraArg) override;
     673             : 
     674             :   public:
     675             :     ECWRasterBand(ECWDataset *, int, int iOverview, char **papszOpenOptions);
     676             :     ~ECWRasterBand() override;
     677             : 
     678             :     CPLErr IReadBlock(int, int, void *) override;
     679             : 
     680           0 :     int HasArbitraryOverviews() override
     681             :     {
     682           0 :         return apoOverviews.empty();
     683             :     }
     684             : 
     685           3 :     int GetOverviewCount() override
     686             :     {
     687           3 :         return (int)apoOverviews.size();
     688             :     }
     689             : 
     690             :     GDALRasterBand *GetOverview(int) override;
     691             : 
     692             :     GDALColorInterp GetColorInterpretation() override;
     693             :     CPLErr SetColorInterpretation(GDALColorInterp) override;
     694             : 
     695             :     CPLErr AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize,
     696             :                       int nBufXSize, int nBufYSize, GDALDataType eDT,
     697             :                       CSLConstList papszOptions) override;
     698             : #if ECWSDK_VERSION >= 50
     699             :     void GetBandIndexAndCountForStatistics(int &bandIndex,
     700             :                                            int &bandCount) const;
     701             :     CPLErr GetDefaultHistogram(double *pdfMin, double *pdfMax, int *pnBuckets,
     702             :                                GUIntBig **ppanHistogram, int bForce,
     703             :                                GDALProgressFunc, void *pProgressData) override;
     704             :     virtual CPLErr SetDefaultHistogram(double dfMin, double dfMax, int nBuckets,
     705             :                                        GUIntBig *panHistogram) override;
     706             :     double GetMinimum(int *pbSuccess) override;
     707             :     double GetMaximum(int *pbSuccess) override;
     708             :     virtual CPLErr GetStatistics(int bApproxOK, int bForce, double *pdfMin,
     709             :                                  double *pdfMax, double *pdfMean,
     710             :                                  double *padfStdDev) override;
     711             :     virtual CPLErr SetStatistics(double dfMin, double dfMax, double dfMean,
     712             :                                  double dfStdDev) override;
     713             : 
     714             :     CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
     715             :                            const char *pszDomain = "") override;
     716             : #endif
     717             : };
     718             : 
     719             : int ECWTranslateFromWKT(const OGRSpatialReference *poSRS, char *pszProjection,
     720             :                         int nProjectionLen, char *pszDatum, int nDatumLen,
     721             :                         char *pszUnits);
     722             : 
     723             : CellSizeUnits ECWTranslateToCellSizeUnits(const char *pszUnits);
     724             : const char *ECWTranslateFromCellSizeUnits(CellSizeUnits eUnits);
     725             : 
     726             : #endif /* ndef GDAL_ECW_H_INCLUDED */

Generated by: LCOV version 1.14