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: 2024-05-04 12:52:34 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             :  * Permission is hereby granted, free of charge, to any person obtaining a
      12             :  * copy of this software and associated documentation files (the "Software"),
      13             :  * to deal in the Software without restriction, including without limitation
      14             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15             :  * and/or sell copies of the Software, and to permit persons to whom the
      16             :  * Software is furnished to do so, subject to the following conditions:
      17             :  *
      18             :  * The above copyright notice and this permission notice shall be included
      19             :  * in all copies or substantial portions of the Software.
      20             :  *
      21             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27             :  * DEALINGS IN THE SOFTWARE.
      28             :  ****************************************************************************/
      29             : 
      30             : #ifndef GDAL_FRMTS_RAW_EHDRDATASET_H_INCLUDED
      31             : #define GDAL_FRMTS_RAW_EHDRDATASET_H_INCLUDED
      32             : 
      33             : #include "cpl_port.h"
      34             : #include "rawdataset.h"
      35             : 
      36             : #include <cctype>
      37             : #include <cerrno>
      38             : #include <climits>
      39             : #include <cmath>
      40             : #include <cstddef>
      41             : #include <cstdio>
      42             : #include <cstdlib>
      43             : #include <cstring>
      44             : #if HAVE_FCNTL_H
      45             : #include <fcntl.h>
      46             : #endif
      47             : 
      48             : #include <limits>
      49             : #include <memory>
      50             : 
      51             : #include "cpl_conv.h"
      52             : #include "cpl_error.h"
      53             : #include "cpl_progress.h"
      54             : #include "cpl_string.h"
      55             : #include "cpl_vsi.h"
      56             : #include "gdal.h"
      57             : #include "gdal_frmts.h"
      58             : #include "gdal_pam.h"
      59             : #include "gdal_priv.h"
      60             : #include "gdal_rat.h"
      61             : #include "ogr_core.h"
      62             : #include "ogr_spatialref.h"
      63             : 
      64             : /************************************************************************/
      65             : /* ==================================================================== */
      66             : /*                       EHdrDataset                                    */
      67             : /* ==================================================================== */
      68             : /************************************************************************/
      69             : 
      70             : class EHdrRasterBand;
      71             : 
      72             : class EHdrDataset final : public RawDataset
      73             : {
      74             :     friend class EHdrRasterBand;
      75             : 
      76             :     VSILFILE *fpImage;  // image data file.
      77             : 
      78             :     CPLString osHeaderExt{};
      79             : 
      80             :     bool bGotTransform{};
      81             :     double adfGeoTransform[6]{0, 1, 0, 0, 0, 1};
      82             :     OGRSpatialReference m_oSRS{};
      83             : 
      84             :     bool bHDRDirty{};
      85             :     char **papszHDR{};
      86             : 
      87             :     bool bCLRDirty{};
      88             :     std::shared_ptr<GDALColorTable> m_poColorTable{};
      89             :     std::shared_ptr<GDALRasterAttributeTable> m_poRAT{};
      90             : 
      91             :     CPLErr ReadSTX() const;
      92             :     CPLErr RewriteSTX() const;
      93             :     CPLErr RewriteHDR();
      94             :     void ResetKeyValue(const char *pszKey, const char *pszValue);
      95             :     const char *GetKeyValue(const char *pszKey, const char *pszDefault = "");
      96             :     void RewriteCLR(GDALRasterBand *) const;
      97             : 
      98             :     CPL_DISALLOW_COPY_ASSIGN(EHdrDataset)
      99             : 
     100             :     CPLErr Close() override;
     101             : 
     102             :   public:
     103             :     EHdrDataset();
     104             :     ~EHdrDataset() override;
     105             : 
     106             :     CPLErr GetGeoTransform(double *padfTransform) override;
     107             :     CPLErr SetGeoTransform(double *padfTransform) override;
     108             : 
     109          10 :     const OGRSpatialReference *GetSpatialRef() const override
     110             :     {
     111          10 :         return m_oSRS.IsEmpty() ? RawDataset::GetSpatialRef() : &m_oSRS;
     112             :     }
     113             : 
     114             :     CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
     115             : 
     116             :     char **GetFileList() override;
     117             : 
     118             :     static GDALDataset *Open(GDALOpenInfo *);
     119             :     static GDALDataset *Open(GDALOpenInfo *, bool bFileSizeCheck);
     120             :     static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize,
     121             :                                int nBands, GDALDataType eType,
     122             :                                char **papszParamList);
     123             :     static GDALDataset *CreateCopy(const char *pszFilename,
     124             :                                    GDALDataset *poSrcDS, int bStrict,
     125             :                                    char **papszOptions,
     126             :                                    GDALProgressFunc pfnProgress,
     127             :                                    void *pProgressData);
     128             :     static CPLString GetImageRepFilename(const char *pszFilename);
     129             : };
     130             : 
     131             : /************************************************************************/
     132             : /* ==================================================================== */
     133             : /*                          EHdrRasterBand                              */
     134             : /* ==================================================================== */
     135             : /************************************************************************/
     136             : 
     137             : class EHdrRasterBand final : public RawRasterBand
     138             : {
     139             :     friend class EHdrDataset;
     140             : 
     141             :     std::shared_ptr<GDALColorTable> m_poColorTable{};
     142             :     std::shared_ptr<GDALRasterAttributeTable> m_poRAT{};
     143             : 
     144             :     bool m_bValid = false;
     145             :     int nBits{};
     146             :     vsi_l_offset nStartBit{};
     147             :     int nPixelOffsetBits{};
     148             :     vsi_l_offset nLineOffsetBits{};
     149             : 
     150             :     int bNoDataSet{};  // TODO(schwehr): Convert to bool.
     151             :     double dfNoData{};
     152             :     double dfMin{};
     153             :     double dfMax{};
     154             :     double dfMean{};
     155             :     double dfStdDev{};
     156             : 
     157             :     int minmaxmeanstddev{};
     158             : 
     159             :     CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
     160             :                      GDALDataType, GSpacing nPixelSpace, GSpacing nLineSpace,
     161             :                      GDALRasterIOExtraArg *psExtraArg) override;
     162             : 
     163             :     CPL_DISALLOW_COPY_ASSIGN(EHdrRasterBand)
     164             : 
     165             :   public:
     166             :     EHdrRasterBand(GDALDataset *poDS, int nBand, VSILFILE *fpRaw,
     167             :                    vsi_l_offset nImgOffset, int nPixelOffset, int nLineOffset,
     168             :                    GDALDataType eDataType,
     169             :                    RawRasterBand::ByteOrder eByteOrderIn, int nBits);
     170             : 
     171         186 :     bool IsValid() const
     172             :     {
     173         186 :         return m_bValid;
     174             :     }
     175             : 
     176             :     CPLErr IReadBlock(int, int, void *) override;
     177             :     CPLErr IWriteBlock(int, int, void *) override;
     178             : 
     179             :     double GetNoDataValue(int *pbSuccess = nullptr) override;
     180             :     double GetMinimum(int *pbSuccess = nullptr) override;
     181             :     double GetMaximum(int *pbSuccess = nullptr) override;
     182             :     CPLErr GetStatistics(int bApproxOK, int bForce, double *pdfMin,
     183             :                          double *pdfMax, double *pdfMean,
     184             :                          double *pdfStdDev) override;
     185             :     CPLErr SetStatistics(double dfMin, double dfMax, double dfMean,
     186             :                          double dfStdDev) override;
     187             :     CPLErr SetColorTable(GDALColorTable *poNewCT) override;
     188             :     GDALColorTable *GetColorTable() override;
     189             : 
     190             :     GDALRasterAttributeTable *GetDefaultRAT() override;
     191             :     CPLErr SetDefaultRAT(const GDALRasterAttributeTable *poRAT) override;
     192             : };
     193             : 
     194             : #endif  // GDAL_FRMTS_RAW_EHDRDATASET_H_INCLUDED

Generated by: LCOV version 1.14