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: 2025-09-10 17:48:50 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             :  * SPDX-License-Identifier: MIT
      13             :  ****************************************************************************/
      14             : 
      15             : #ifndef HFADATASET_H_INCLUDED
      16             : #define HFADATASET_H_INCLUDED
      17             : 
      18             : #include <cstddef>
      19             : #include <vector>
      20             : 
      21             : #include "gdal_frmts.h"
      22             : #include "gdal_pam.h"
      23             : #include "gdal_rat.h"
      24             : #include "hfa_p.h"
      25             : #include "ogr_spatialref.h"
      26             : #include "ogr_srs_api.h"
      27             : 
      28             : /************************************************************************/
      29             : /* ==================================================================== */
      30             : /*                              HFADataset                              */
      31             : /* ==================================================================== */
      32             : /************************************************************************/
      33             : 
      34             : class HFARasterBand;
      35             : 
      36             : class HFADataset final : public GDALPamDataset
      37             : {
      38             :     friend class HFARasterBand;
      39             : 
      40             :     HFAHandle hHFA = nullptr;
      41             : 
      42             :     bool bMetadataDirty = false;
      43             : 
      44             :     bool bGeoDirty = false;
      45             :     GDALGeoTransform m_gt{};
      46             :     OGRSpatialReference m_oSRS{};
      47             : 
      48             :     bool bIgnoreUTM = false;
      49             : 
      50             :     CPLErr ReadProjection();
      51             :     CPLErr WriteProjection();
      52             :     bool bForceToPEString = false;
      53             :     bool bDisablePEString = false;
      54             : 
      55             :     std::vector<gdal::GCP> m_aoGCPs{};
      56             : 
      57             :     void UseXFormStack(int nStepCount, Efga_Polynomial *pasPolyListForward,
      58             :                        Efga_Polynomial *pasPolyListReverse);
      59             : 
      60             :   protected:
      61             :     CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
      62             :                      GDALDataType, int, BANDMAP_TYPE, GSpacing nPixelSpace,
      63             :                      GSpacing nLineSpace, GSpacing nBandSpace,
      64             :                      GDALRasterIOExtraArg *psExtraArg) override;
      65             : 
      66             :   public:
      67             :     HFADataset();
      68             :     ~HFADataset() override;
      69             : 
      70             :     static int Identify(GDALOpenInfo *);
      71             :     static CPLErr Rename(const char *pszNewName, const char *pszOldName);
      72             :     static CPLErr CopyFiles(const char *pszNewName, const char *pszOldName);
      73             :     static GDALDataset *Open(GDALOpenInfo *);
      74             :     static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize,
      75             :                                int nBands, GDALDataType eType,
      76             :                                char **papszParamList);
      77             :     static GDALDataset *CreateCopy(const char *pszFilename,
      78             :                                    GDALDataset *poSrcDS, int bStrict,
      79             :                                    char **papszOptions,
      80             :                                    GDALProgressFunc pfnProgress,
      81             :                                    void *pProgressData);
      82             :     static CPLErr Delete(const char *pszFilename);
      83             : 
      84             :     char **GetFileList() override;
      85             : 
      86             :     const OGRSpatialReference *GetSpatialRef() const override;
      87             :     CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
      88             : 
      89             :     CPLErr GetGeoTransform(GDALGeoTransform &gt) const override;
      90             :     CPLErr SetGeoTransform(const GDALGeoTransform &gt) override;
      91             : 
      92             :     int GetGCPCount() override;
      93             :     const OGRSpatialReference *GetGCPSpatialRef() const override;
      94             :     const GDAL_GCP *GetGCPs() override;
      95             : 
      96             :     CPLErr SetMetadata(char **, const char * = "") override;
      97             :     CPLErr SetMetadataItem(const char *, const char *,
      98             :                            const char * = "") override;
      99             : 
     100             :     CPLErr FlushCache(bool bAtClosing) override;
     101             :     CPLErr IBuildOverviews(const char *pszResampling, int nOverviews,
     102             :                            const int *panOverviewList, int nListBands,
     103             :                            const int *panBandList, GDALProgressFunc pfnProgress,
     104             :                            void *pProgressData,
     105             :                            CSLConstList papszOptions) override;
     106             : };
     107             : 
     108             : /************************************************************************/
     109             : /* ==================================================================== */
     110             : /*                            HFARasterBand                             */
     111             : /* ==================================================================== */
     112             : /************************************************************************/
     113             : 
     114             : class HFARasterBand final : public GDALPamRasterBand
     115             : {
     116             :     friend class HFADataset;
     117             :     friend class HFARasterAttributeTable;
     118             : 
     119             :     GDALColorTable *poCT;
     120             : 
     121             :     EPTType eHFADataType;
     122             : 
     123             :     int nOverviews;
     124             :     int nThisOverview;
     125             :     HFARasterBand **papoOverviewBands;
     126             : 
     127             :     CPLErr CleanOverviews();
     128             : 
     129             :     HFAHandle hHFA;
     130             : 
     131             :     bool bMetadataDirty;
     132             : 
     133             :     GDALRasterAttributeTable *poDefaultRAT;
     134             : 
     135             :     void ReadAuxMetadata();
     136             :     void ReadHistogramMetadata();
     137             :     void EstablishOverviews();
     138             :     CPLErr WriteNamedRAT(const char *pszName,
     139             :                          const GDALRasterAttributeTable *poRAT);
     140             : 
     141             :   public:
     142             :     HFARasterBand(HFADataset *, int, int);
     143             :     ~HFARasterBand() override;
     144             : 
     145             :     CPLErr IReadBlock(int, int, void *) override;
     146             :     CPLErr IWriteBlock(int, int, void *) override;
     147             : 
     148             :     const char *GetDescription() const override;
     149             :     void SetDescription(const char *) override;
     150             : 
     151             :     GDALColorInterp GetColorInterpretation() override;
     152             :     GDALColorTable *GetColorTable() override;
     153             :     CPLErr SetColorTable(GDALColorTable *) override;
     154             :     int GetOverviewCount() override;
     155             :     GDALRasterBand *GetOverview(int) override;
     156             : 
     157             :     double GetMinimum(int *pbSuccess = nullptr) override;
     158             :     double GetMaximum(int *pbSuccess = nullptr) override;
     159             :     double GetNoDataValue(int *pbSuccess = nullptr) override;
     160             :     CPLErr SetNoDataValue(double dfValue) override;
     161             : 
     162             :     CPLErr SetMetadata(char **, const char * = "") override;
     163             :     CPLErr SetMetadataItem(const char *, const char *,
     164             :                            const char * = "") override;
     165             :     virtual CPLErr BuildOverviews(const char *, int, const int *,
     166             :                                   GDALProgressFunc, void *,
     167             :                                   CSLConstList papszOptions) override;
     168             : 
     169             :     CPLErr GetDefaultHistogram(double *pdfMin, double *pdfMax, int *pnBuckets,
     170             :                                GUIntBig **ppanHistogram, int bForce,
     171             :                                GDALProgressFunc, void *pProgressData) override;
     172             : 
     173             :     GDALRasterAttributeTable *GetDefaultRAT() override;
     174             :     CPLErr SetDefaultRAT(const GDALRasterAttributeTable *) override;
     175             : };
     176             : 
     177             : class HFAAttributeField
     178             : {
     179             :   public:
     180             :     CPLString sName;
     181             :     GDALRATFieldType eType;
     182             :     GDALRATFieldUsage eUsage;
     183             :     int nDataOffset;
     184             :     int nElementSize;
     185             :     HFAEntry *poColumn;
     186             :     bool bIsBinValues;    // Handled differently.
     187             :     bool bConvertColors;  // Map 0-1 floats to 0-255 ints.
     188             : };
     189             : 
     190             : class HFARasterAttributeTable final : public GDALRasterAttributeTable
     191             : {
     192             :   private:
     193             :     HFAHandle hHFA;
     194             :     HFAEntry *poDT;
     195             :     CPLString osName;
     196             :     int nBand;
     197             :     GDALAccess eAccess;
     198             : 
     199             :     std::vector<HFAAttributeField> aoFields;
     200             :     int nRows;
     201             : 
     202             :     bool bLinearBinning;
     203             :     double dfRow0Min;
     204             :     double dfBinSize;
     205             :     GDALRATTableType eTableType;
     206             : 
     207             :     CPLString osWorkingResult;
     208             : 
     209         278 :     void AddColumn(const char *pszName, GDALRATFieldType eType,
     210             :                    GDALRATFieldUsage eUsage, int nDataOffset, int nElementSize,
     211             :                    HFAEntry *poColumn, bool bIsBinValues = false,
     212             :                    bool bConvertColors = false)
     213             :     {
     214         556 :         HFAAttributeField aField;
     215         278 :         aField.sName = pszName;
     216         278 :         aField.eType = eType;
     217         278 :         aField.eUsage = eUsage;
     218         278 :         aField.nDataOffset = nDataOffset;
     219         278 :         aField.nElementSize = nElementSize;
     220         278 :         aField.poColumn = poColumn;
     221         278 :         aField.bIsBinValues = bIsBinValues;
     222         278 :         aField.bConvertColors = bConvertColors;
     223             : 
     224         278 :         aoFields.push_back(std::move(aField));
     225         278 :     }
     226             : 
     227           1 :     void CreateDT()
     228             :     {
     229           1 :         poDT = HFAEntry::New(hHFA->papoBand[nBand - 1]->psInfo, osName,
     230           1 :                              "Edsc_Table", hHFA->papoBand[nBand - 1]->poNode);
     231           1 :         poDT->SetIntField("numrows", nRows);
     232           1 :     }
     233             : 
     234             :   public:
     235             :     HFARasterAttributeTable(HFARasterBand *poBand, const char *pszName);
     236             :     ~HFARasterAttributeTable() override;
     237             : 
     238             :     GDALRasterAttributeTable *Clone() const override;
     239             : 
     240             :     int GetColumnCount() const override;
     241             : 
     242             :     const char *GetNameOfCol(int) const override;
     243             :     GDALRATFieldUsage GetUsageOfCol(int) const override;
     244             :     GDALRATFieldType GetTypeOfCol(int) const override;
     245             : 
     246             :     int GetColOfUsage(GDALRATFieldUsage) const override;
     247             : 
     248             :     int GetRowCount() const override;
     249             : 
     250             :     const char *GetValueAsString(int iRow, int iField) const override;
     251             :     int GetValueAsInt(int iRow, int iField) const override;
     252             :     double GetValueAsDouble(int iRow, int iField) const override;
     253             : 
     254             :     virtual CPLErr SetValue(int iRow, int iField,
     255             :                             const char *pszValue) override;
     256             :     CPLErr SetValue(int iRow, int iField, double dfValue) override;
     257             :     CPLErr SetValue(int iRow, int iField, int nValue) override;
     258             : 
     259             :     virtual CPLErr ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow,
     260             :                             int iLength, double *pdfData) override;
     261             :     virtual CPLErr ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow,
     262             :                             int iLength, int *pnData) override;
     263             :     virtual CPLErr ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow,
     264             :                             int iLength, char **papszStrList) override;
     265             : 
     266             :     int ChangesAreWrittenToFile() override;
     267             :     void SetRowCount(int iCount) override;
     268             : 
     269             :     int GetRowOfValue(double dfValue) const override;
     270             :     int GetRowOfValue(int nValue) const override;
     271             : 
     272             :     virtual CPLErr CreateColumn(const char *pszFieldName,
     273             :                                 GDALRATFieldType eFieldType,
     274             :                                 GDALRATFieldUsage eFieldUsage) override;
     275             :     virtual CPLErr SetLinearBinning(double dfRow0Min,
     276             :                                     double dfBinSize) override;
     277             :     virtual int GetLinearBinning(double *pdfRow0Min,
     278             :                                  double *pdfBinSize) const override;
     279             : 
     280             :     CPLXMLNode *Serialize() const override;
     281             : 
     282             :     CPLErr SetTableType(const GDALRATTableType eInTableType) override;
     283             :     GDALRATTableType GetTableType() const override;
     284             :     void RemoveStatistics() override;
     285             : 
     286             :   protected:
     287             :     CPLErr ColorsIO(GDALRWFlag eRWFlag, int iField, int iStartRow, int iLength,
     288             :                     int *pnData);
     289             : };
     290             : 
     291             : #endif  // HFADATASET_H_INCLUDED

Generated by: LCOV version 1.14