LCOV - code coverage report
Current view: top level - frmts/hfa - hfadataset.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 17 17 100.0 %
Date: 2024-05-06 11:10:03 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Name:     hfadataset.cpp
       4             :  * Project:  Erdas Imagine Driver
       5             :  * Purpose:  Main driver for Erdas Imagine format.
       6             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 1999, Frank Warmerdam
      10             :  * Copyright (c) 2008-2013, Even Rouault <even dot rouault at spatialys.com>
      11             :  *
      12             :  * Permission is hereby granted, free of charge, to any person obtaining a
      13             :  * copy of this software and associated documentation files (the "Software"),
      14             :  * to deal in the Software without restriction, including without limitation
      15             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      16             :  * and/or sell copies of the Software, and to permit persons to whom the
      17             :  * Software is furnished to do so, subject to the following conditions:
      18             :  *
      19             :  * The above copyright notice and this permission notice shall be included
      20             :  * in all copies or substantial portions of the Software.
      21             :  *
      22             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      23             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      24             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      25             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      26             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      27             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      28             :  * DEALINGS IN THE SOFTWARE.
      29             :  ****************************************************************************/
      30             : 
      31             : #ifndef HFADATASET_H_INCLUDED
      32             : #define HFADATASET_H_INCLUDED
      33             : 
      34             : #include <cstddef>
      35             : #include <vector>
      36             : 
      37             : #include "gdal_frmts.h"
      38             : #include "gdal_pam.h"
      39             : #include "gdal_rat.h"
      40             : #include "hfa_p.h"
      41             : #include "ogr_spatialref.h"
      42             : #include "ogr_srs_api.h"
      43             : 
      44             : /************************************************************************/
      45             : /* ==================================================================== */
      46             : /*                              HFADataset                              */
      47             : /* ==================================================================== */
      48             : /************************************************************************/
      49             : 
      50             : class HFARasterBand;
      51             : 
      52             : class HFADataset final : public GDALPamDataset
      53             : {
      54             :     friend class HFARasterBand;
      55             : 
      56             :     HFAHandle hHFA = nullptr;
      57             : 
      58             :     bool bMetadataDirty = false;
      59             : 
      60             :     bool bGeoDirty = false;
      61             :     double adfGeoTransform[6];
      62             :     OGRSpatialReference m_oSRS{};
      63             : 
      64             :     bool bIgnoreUTM = false;
      65             : 
      66             :     CPLErr ReadProjection();
      67             :     CPLErr WriteProjection();
      68             :     bool bForceToPEString = false;
      69             :     bool bDisablePEString = false;
      70             : 
      71             :     std::vector<gdal::GCP> m_aoGCPs{};
      72             : 
      73             :     void UseXFormStack(int nStepCount, Efga_Polynomial *pasPolyListForward,
      74             :                        Efga_Polynomial *pasPolyListReverse);
      75             : 
      76             :   protected:
      77             :     virtual CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
      78             :                              GDALDataType, int, int *, GSpacing nPixelSpace,
      79             :                              GSpacing nLineSpace, GSpacing nBandSpace,
      80             :                              GDALRasterIOExtraArg *psExtraArg) override;
      81             : 
      82             :   public:
      83             :     HFADataset();
      84             :     virtual ~HFADataset();
      85             : 
      86             :     static int Identify(GDALOpenInfo *);
      87             :     static CPLErr Rename(const char *pszNewName, const char *pszOldName);
      88             :     static CPLErr CopyFiles(const char *pszNewName, const char *pszOldName);
      89             :     static GDALDataset *Open(GDALOpenInfo *);
      90             :     static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize,
      91             :                                int nBands, GDALDataType eType,
      92             :                                char **papszParamList);
      93             :     static GDALDataset *CreateCopy(const char *pszFilename,
      94             :                                    GDALDataset *poSrcDS, int bStrict,
      95             :                                    char **papszOptions,
      96             :                                    GDALProgressFunc pfnProgress,
      97             :                                    void *pProgressData);
      98             :     static CPLErr Delete(const char *pszFilename);
      99             : 
     100             :     virtual char **GetFileList() override;
     101             : 
     102             :     const OGRSpatialReference *GetSpatialRef() const override;
     103             :     CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
     104             : 
     105             :     virtual CPLErr GetGeoTransform(double *) override;
     106             :     virtual CPLErr SetGeoTransform(double *) override;
     107             : 
     108             :     virtual int GetGCPCount() override;
     109             :     const OGRSpatialReference *GetGCPSpatialRef() const override;
     110             :     virtual const GDAL_GCP *GetGCPs() override;
     111             : 
     112             :     virtual CPLErr SetMetadata(char **, const char * = "") override;
     113             :     virtual CPLErr SetMetadataItem(const char *, const char *,
     114             :                                    const char * = "") override;
     115             : 
     116             :     virtual CPLErr FlushCache(bool bAtClosing) override;
     117             :     virtual CPLErr IBuildOverviews(const char *pszResampling, int nOverviews,
     118             :                                    const int *panOverviewList, int nListBands,
     119             :                                    const int *panBandList,
     120             :                                    GDALProgressFunc pfnProgress,
     121             :                                    void *pProgressData,
     122             :                                    CSLConstList papszOptions) override;
     123             : };
     124             : 
     125             : /************************************************************************/
     126             : /* ==================================================================== */
     127             : /*                            HFARasterBand                             */
     128             : /* ==================================================================== */
     129             : /************************************************************************/
     130             : 
     131             : class HFARasterBand final : public GDALPamRasterBand
     132             : {
     133             :     friend class HFADataset;
     134             :     friend class HFARasterAttributeTable;
     135             : 
     136             :     GDALColorTable *poCT;
     137             : 
     138             :     EPTType eHFADataType;
     139             : 
     140             :     int nOverviews;
     141             :     int nThisOverview;
     142             :     HFARasterBand **papoOverviewBands;
     143             : 
     144             :     CPLErr CleanOverviews();
     145             : 
     146             :     HFAHandle hHFA;
     147             : 
     148             :     bool bMetadataDirty;
     149             : 
     150             :     GDALRasterAttributeTable *poDefaultRAT;
     151             : 
     152             :     void ReadAuxMetadata();
     153             :     void ReadHistogramMetadata();
     154             :     void EstablishOverviews();
     155             :     CPLErr WriteNamedRAT(const char *pszName,
     156             :                          const GDALRasterAttributeTable *poRAT);
     157             : 
     158             :   public:
     159             :     HFARasterBand(HFADataset *, int, int);
     160             :     virtual ~HFARasterBand();
     161             : 
     162             :     virtual CPLErr IReadBlock(int, int, void *) override;
     163             :     virtual CPLErr IWriteBlock(int, int, void *) override;
     164             : 
     165             :     virtual const char *GetDescription() const override;
     166             :     virtual void SetDescription(const char *) override;
     167             : 
     168             :     virtual GDALColorInterp GetColorInterpretation() override;
     169             :     virtual GDALColorTable *GetColorTable() override;
     170             :     virtual CPLErr SetColorTable(GDALColorTable *) override;
     171             :     virtual int GetOverviewCount() override;
     172             :     virtual GDALRasterBand *GetOverview(int) override;
     173             : 
     174             :     virtual double GetMinimum(int *pbSuccess = nullptr) override;
     175             :     virtual double GetMaximum(int *pbSuccess = nullptr) override;
     176             :     virtual double GetNoDataValue(int *pbSuccess = nullptr) override;
     177             :     virtual CPLErr SetNoDataValue(double dfValue) override;
     178             : 
     179             :     virtual CPLErr SetMetadata(char **, const char * = "") override;
     180             :     virtual CPLErr SetMetadataItem(const char *, const char *,
     181             :                                    const char * = "") override;
     182             :     virtual CPLErr BuildOverviews(const char *, int, const int *,
     183             :                                   GDALProgressFunc, void *,
     184             :                                   CSLConstList papszOptions) override;
     185             : 
     186             :     virtual CPLErr GetDefaultHistogram(double *pdfMin, double *pdfMax,
     187             :                                        int *pnBuckets, GUIntBig **ppanHistogram,
     188             :                                        int bForce, GDALProgressFunc,
     189             :                                        void *pProgressData) override;
     190             : 
     191             :     virtual GDALRasterAttributeTable *GetDefaultRAT() override;
     192             :     virtual CPLErr SetDefaultRAT(const GDALRasterAttributeTable *) override;
     193             : };
     194             : 
     195             : class HFAAttributeField
     196             : {
     197             :   public:
     198             :     CPLString sName;
     199             :     GDALRATFieldType eType;
     200             :     GDALRATFieldUsage eUsage;
     201             :     int nDataOffset;
     202             :     int nElementSize;
     203             :     HFAEntry *poColumn;
     204             :     bool bIsBinValues;    // Handled differently.
     205             :     bool bConvertColors;  // Map 0-1 floats to 0-255 ints.
     206             : };
     207             : 
     208             : class HFARasterAttributeTable final : public GDALRasterAttributeTable
     209             : {
     210             :   private:
     211             :     HFAHandle hHFA;
     212             :     HFAEntry *poDT;
     213             :     CPLString osName;
     214             :     int nBand;
     215             :     GDALAccess eAccess;
     216             : 
     217             :     std::vector<HFAAttributeField> aoFields;
     218             :     int nRows;
     219             : 
     220             :     bool bLinearBinning;
     221             :     double dfRow0Min;
     222             :     double dfBinSize;
     223             :     GDALRATTableType eTableType;
     224             : 
     225             :     CPLString osWorkingResult;
     226             : 
     227         269 :     void AddColumn(const char *pszName, GDALRATFieldType eType,
     228             :                    GDALRATFieldUsage eUsage, int nDataOffset, int nElementSize,
     229             :                    HFAEntry *poColumn, bool bIsBinValues = false,
     230             :                    bool bConvertColors = false)
     231             :     {
     232         538 :         HFAAttributeField aField;
     233         269 :         aField.sName = pszName;
     234         269 :         aField.eType = eType;
     235         269 :         aField.eUsage = eUsage;
     236         269 :         aField.nDataOffset = nDataOffset;
     237         269 :         aField.nElementSize = nElementSize;
     238         269 :         aField.poColumn = poColumn;
     239         269 :         aField.bIsBinValues = bIsBinValues;
     240         269 :         aField.bConvertColors = bConvertColors;
     241             : 
     242         269 :         aoFields.push_back(aField);
     243         269 :     }
     244             : 
     245           1 :     void CreateDT()
     246             :     {
     247           1 :         poDT = HFAEntry::New(hHFA->papoBand[nBand - 1]->psInfo, osName,
     248           1 :                              "Edsc_Table", hHFA->papoBand[nBand - 1]->poNode);
     249           1 :         poDT->SetIntField("numrows", nRows);
     250           1 :     }
     251             : 
     252             :   public:
     253             :     HFARasterAttributeTable(HFARasterBand *poBand, const char *pszName);
     254             :     virtual ~HFARasterAttributeTable();
     255             : 
     256             :     GDALRasterAttributeTable *Clone() const override;
     257             : 
     258             :     virtual int GetColumnCount() const override;
     259             : 
     260             :     virtual const char *GetNameOfCol(int) const override;
     261             :     virtual GDALRATFieldUsage GetUsageOfCol(int) const override;
     262             :     virtual GDALRATFieldType GetTypeOfCol(int) const override;
     263             : 
     264             :     virtual int GetColOfUsage(GDALRATFieldUsage) const override;
     265             : 
     266             :     virtual int GetRowCount() const override;
     267             : 
     268             :     virtual const char *GetValueAsString(int iRow, int iField) const override;
     269             :     virtual int GetValueAsInt(int iRow, int iField) const override;
     270             :     virtual double GetValueAsDouble(int iRow, int iField) const override;
     271             : 
     272             :     virtual void SetValue(int iRow, int iField, const char *pszValue) override;
     273             :     virtual void SetValue(int iRow, int iField, double dfValue) override;
     274             :     virtual void SetValue(int iRow, int iField, int nValue) override;
     275             : 
     276             :     virtual CPLErr ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow,
     277             :                             int iLength, double *pdfData) override;
     278             :     virtual CPLErr ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow,
     279             :                             int iLength, int *pnData) override;
     280             :     virtual CPLErr ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow,
     281             :                             int iLength, char **papszStrList) override;
     282             : 
     283             :     virtual int ChangesAreWrittenToFile() override;
     284             :     virtual void SetRowCount(int iCount) override;
     285             : 
     286             :     virtual int GetRowOfValue(double dfValue) const override;
     287             :     virtual int GetRowOfValue(int nValue) const override;
     288             : 
     289             :     virtual CPLErr CreateColumn(const char *pszFieldName,
     290             :                                 GDALRATFieldType eFieldType,
     291             :                                 GDALRATFieldUsage eFieldUsage) override;
     292             :     virtual CPLErr SetLinearBinning(double dfRow0Min,
     293             :                                     double dfBinSize) override;
     294             :     virtual int GetLinearBinning(double *pdfRow0Min,
     295             :                                  double *pdfBinSize) const override;
     296             : 
     297             :     virtual CPLXMLNode *Serialize() const override;
     298             : 
     299             :     virtual CPLErr SetTableType(const GDALRATTableType eInTableType) override;
     300             :     virtual GDALRATTableType GetTableType() const override;
     301             :     virtual void RemoveStatistics() override;
     302             : 
     303             :   protected:
     304             :     CPLErr ColorsIO(GDALRWFlag eRWFlag, int iField, int iStartRow, int iLength,
     305             :                     int *pnData);
     306             : };
     307             : 
     308             : #endif  // HFADATASET_H_INCLUDED

Generated by: LCOV version 1.14