LCOV - code coverage report
Current view: top level - frmts/raw - ehdrdataset.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 4 4 100.0 %
Date: 2025-09-10 17:48:50 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  ESRI .hdr Driver
       4             :  * Purpose:  Implementation of EHdrDataset
       5             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 1999, Frank Warmerdam <warmerdam@pobox.com>
       9             :  * Copyright (c) 2007-2013, Even Rouault <even dot rouault at spatialys.com>
      10             :  *
      11             :  * SPDX-License-Identifier: MIT
      12             :  ****************************************************************************/
      13             : 
      14             : #ifndef GDAL_FRMTS_RAW_EHDRDATASET_H_INCLUDED
      15             : #define GDAL_FRMTS_RAW_EHDRDATASET_H_INCLUDED
      16             : 
      17             : #include "cpl_port.h"
      18             : #include "rawdataset.h"
      19             : 
      20             : #include <cctype>
      21             : #include <cerrno>
      22             : #include <climits>
      23             : #include <cmath>
      24             : #include <cstddef>
      25             : #include <cstdio>
      26             : #include <cstdlib>
      27             : #include <cstring>
      28             : 
      29             : #include <limits>
      30             : #include <memory>
      31             : 
      32             : #include "cpl_conv.h"
      33             : #include "cpl_error.h"
      34             : #include "cpl_progress.h"
      35             : #include "cpl_string.h"
      36             : #include "cpl_vsi.h"
      37             : #include "gdal.h"
      38             : #include "gdal_frmts.h"
      39             : #include "gdal_pam.h"
      40             : #include "gdal_priv.h"
      41             : #include "gdal_rat.h"
      42             : #include "ogr_core.h"
      43             : #include "ogr_spatialref.h"
      44             : 
      45             : /************************************************************************/
      46             : /* ==================================================================== */
      47             : /*                       EHdrDataset                                    */
      48             : /* ==================================================================== */
      49             : /************************************************************************/
      50             : 
      51             : class EHdrRasterBand;
      52             : 
      53             : class EHdrDataset final : public RawDataset
      54             : {
      55             :     friend class EHdrRasterBand;
      56             : 
      57             :     VSILFILE *fpImage;  // image data file.
      58             : 
      59             :     CPLString osHeaderExt{};
      60             : 
      61             :     bool bGotTransform{};
      62             :     GDALGeoTransform m_gt{};
      63             :     OGRSpatialReference m_oSRS{};
      64             : 
      65             :     bool bHDRDirty{};
      66             :     char **papszHDR{};
      67             : 
      68             :     bool bCLRDirty{};
      69             :     std::shared_ptr<GDALColorTable> m_poColorTable{};
      70             :     std::shared_ptr<GDALRasterAttributeTable> m_poRAT{};
      71             : 
      72             :     CPLErr ReadSTX() const;
      73             :     CPLErr RewriteSTX() const;
      74             :     CPLErr RewriteHDR();
      75             :     void ResetKeyValue(const char *pszKey, const char *pszValue);
      76             :     const char *GetKeyValue(const char *pszKey, const char *pszDefault = "");
      77             :     void RewriteCLR(GDALRasterBand *) const;
      78             : 
      79             :     CPL_DISALLOW_COPY_ASSIGN(EHdrDataset)
      80             : 
      81             :     CPLErr Close() override;
      82             : 
      83             :   public:
      84             :     EHdrDataset();
      85             :     ~EHdrDataset() override;
      86             : 
      87             :     CPLErr GetGeoTransform(GDALGeoTransform &gt) const override;
      88             :     CPLErr SetGeoTransform(const GDALGeoTransform &gt) override;
      89             : 
      90          10 :     const OGRSpatialReference *GetSpatialRef() const override
      91             :     {
      92          10 :         return m_oSRS.IsEmpty() ? RawDataset::GetSpatialRef() : &m_oSRS;
      93             :     }
      94             : 
      95             :     CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
      96             : 
      97             :     char **GetFileList() override;
      98             : 
      99             :     static GDALDataset *Open(GDALOpenInfo *);
     100             :     static GDALDataset *Open(GDALOpenInfo *, bool bFileSizeCheck);
     101             :     static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize,
     102             :                                int nBands, GDALDataType eType,
     103             :                                char **papszParamList);
     104             :     static GDALDataset *CreateCopy(const char *pszFilename,
     105             :                                    GDALDataset *poSrcDS, int bStrict,
     106             :                                    char **papszOptions,
     107             :                                    GDALProgressFunc pfnProgress,
     108             :                                    void *pProgressData);
     109             :     static CPLString GetImageRepFilename(const char *pszFilename);
     110             : };
     111             : 
     112             : /************************************************************************/
     113             : /* ==================================================================== */
     114             : /*                          EHdrRasterBand                              */
     115             : /* ==================================================================== */
     116             : /************************************************************************/
     117             : 
     118             : class EHdrRasterBand final : public RawRasterBand
     119             : {
     120             :     friend class EHdrDataset;
     121             : 
     122             :     std::shared_ptr<GDALColorTable> m_poColorTable{};
     123             :     std::shared_ptr<GDALRasterAttributeTable> m_poRAT{};
     124             : 
     125             :     bool m_bValid = false;
     126             :     int nBits{};
     127             :     vsi_l_offset nStartBit{};
     128             :     int nPixelOffsetBits{};
     129             :     vsi_l_offset nLineOffsetBits{};
     130             : 
     131             :     int bNoDataSet{};  // TODO(schwehr): Convert to bool.
     132             :     double dfNoData{};
     133             :     double dfMin{};
     134             :     double dfMax{};
     135             :     double dfMean{};
     136             :     double dfStdDev{};
     137             : 
     138             :     int minmaxmeanstddev{};
     139             : 
     140             :     CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
     141             :                      GDALDataType, GSpacing nPixelSpace, GSpacing nLineSpace,
     142             :                      GDALRasterIOExtraArg *psExtraArg) override;
     143             : 
     144             :     CPL_DISALLOW_COPY_ASSIGN(EHdrRasterBand)
     145             : 
     146             :   public:
     147             :     EHdrRasterBand(GDALDataset *poDS, int nBand, VSILFILE *fpRaw,
     148             :                    vsi_l_offset nImgOffset, int nPixelOffset, int nLineOffset,
     149             :                    GDALDataType eDataType,
     150             :                    RawRasterBand::ByteOrder eByteOrderIn, int nBits);
     151             : 
     152         188 :     bool IsValid() const
     153             :     {
     154         188 :         return m_bValid;
     155             :     }
     156             : 
     157             :     CPLErr IReadBlock(int, int, void *) override;
     158             :     CPLErr IWriteBlock(int, int, void *) override;
     159             : 
     160             :     double GetNoDataValue(int *pbSuccess = nullptr) override;
     161             :     double GetMinimum(int *pbSuccess = nullptr) override;
     162             :     double GetMaximum(int *pbSuccess = nullptr) override;
     163             :     CPLErr GetStatistics(int bApproxOK, int bForce, double *pdfMin,
     164             :                          double *pdfMax, double *pdfMean,
     165             :                          double *pdfStdDev) override;
     166             :     CPLErr SetStatistics(double dfMin, double dfMax, double dfMean,
     167             :                          double dfStdDev) override;
     168             :     CPLErr SetColorTable(GDALColorTable *poNewCT) override;
     169             :     GDALColorTable *GetColorTable() override;
     170             : 
     171             :     GDALRasterAttributeTable *GetDefaultRAT() override;
     172             :     CPLErr SetDefaultRAT(const GDALRasterAttributeTable *poRAT) override;
     173             : };
     174             : 
     175             : #endif  // GDAL_FRMTS_RAW_EHDRDATASET_H_INCLUDED

Generated by: LCOV version 1.14