LCOV - code coverage report
Current view: top level - frmts/kea - keadataset.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 19 19 100.0 %
Date: 2024-04-27 17:22:41 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :  * $Id$
       3             :  *  keadataset.h
       4             :  *
       5             :  *  Created by Pete Bunting on 01/08/2012.
       6             :  *  Copyright 2012 LibKEA. All rights reserved.
       7             :  *
       8             :  *  This file is part of LibKEA.
       9             :  *
      10             :  *  Permission is hereby granted, free of charge, to any person
      11             :  *  obtaining a copy of this software and associated documentation
      12             :  *  files (the "Software"), to deal in the Software without restriction,
      13             :  *  including without limitation the rights to use, copy, modify,
      14             :  *  merge, publish, distribute, sublicense, and/or sell copies of the
      15             :  *  Software, and to permit persons to whom the Software is furnished
      16             :  *  to do so, subject to the following conditions:
      17             :  *
      18             :  *  The above copyright notice and this permission notice shall be
      19             :  *  included in all copies or substantial portions of the Software.
      20             :  *
      21             :  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
      22             :  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
      23             :  *  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
      24             :  *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
      25             :  *  ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
      26             :  *  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
      27             :  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      28             :  *
      29             :  */
      30             : 
      31             : #ifndef KEADATASET_H
      32             : #define KEADATASET_H
      33             : 
      34             : #include "gdal_pam.h"
      35             : #include "cpl_multiproc.h"
      36             : #include "libkea_headers.h"
      37             : 
      38             : class LockedRefCount;
      39             : 
      40             : // class that implements a GDAL dataset
      41             : class KEADataset final : public GDALPamDataset
      42             : {
      43             :     static H5::H5File *CreateLL(const char *pszFilename, int nXSize, int nYSize,
      44             :                                 int nBands, GDALDataType eType,
      45             :                                 char **papszParamList);
      46             : 
      47             :   public:
      48             :     // constructor/destructor
      49             :     KEADataset(H5::H5File *keaImgH5File, GDALAccess eAccess);
      50             :     ~KEADataset();
      51             : 
      52             :     // static methods that handle open and creation
      53             :     // the driver class has pointers to these
      54             :     static GDALDataset *Open(GDALOpenInfo *);
      55             :     static int Identify(GDALOpenInfo *poOpenInfo);
      56             :     static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize,
      57             :                                int nBands, GDALDataType eType,
      58             :                                char **papszParamList);
      59             :     static GDALDataset *CreateCopy(const char *pszFilename, GDALDataset *pSrcDs,
      60             :                                    int bStrict, char **papszParamList,
      61             :                                    GDALProgressFunc pfnProgress,
      62             :                                    void *pProgressData);
      63             : 
      64             :     // virtual methods for dealing with transform and projection
      65             :     CPLErr GetGeoTransform(double *padfTransform) override;
      66             :     const OGRSpatialReference *GetSpatialRef() const override;
      67             : 
      68             :     CPLErr SetGeoTransform(double *padfTransform) override;
      69             :     CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
      70             : 
      71             :     // method to get a pointer to the imageio class
      72             :     void *GetInternalHandle(const char *) override;
      73             : 
      74             :     // virtual methods for dealing with metadata
      75             :     CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
      76             :                            const char *pszDomain = "") override;
      77             :     const char *GetMetadataItem(const char *pszName,
      78             :                                 const char *pszDomain = "") override;
      79             : 
      80             :     char **GetMetadata(const char *pszDomain = "") override;
      81             :     CPLErr SetMetadata(char **papszMetadata,
      82             :                        const char *pszDomain = "") override;
      83             : 
      84             :     // virtual method for adding new image bands
      85             :     CPLErr AddBand(GDALDataType eType, char **papszOptions = nullptr) override;
      86             : 
      87             :     // GCPs
      88             :     int GetGCPCount() override;
      89             :     const OGRSpatialReference *GetGCPSpatialRef() const override;
      90             :     const GDAL_GCP *GetGCPs() override;
      91             :     CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList,
      92             :                    const OGRSpatialReference *poSRS) override;
      93             : 
      94             :   protected:
      95             :     // this method builds overviews for the specified bands.
      96             :     virtual CPLErr IBuildOverviews(const char *pszResampling, int nOverviews,
      97             :                                    const int *panOverviewList, int nListBands,
      98             :                                    const int *panBandList,
      99             :                                    GDALProgressFunc pfnProgress,
     100             :                                    void *pProgressData,
     101             :                                    CSLConstList papszOptions) override;
     102             : 
     103             :     // internal method to update m_papszMetadataList
     104             :     void UpdateMetadataList();
     105             : 
     106             :     void DestroyGCPs();
     107             : 
     108             :   private:
     109             :     // pointer to KEAImageIO class and the refcount for it
     110             :     kealib::KEAImageIO *m_pImageIO;
     111             :     LockedRefCount *m_pRefcount;
     112             :     char **m_papszMetadataList;  // CSLStringList for metadata
     113             :     GDAL_GCP *m_pGCPs;
     114             :     mutable OGRSpatialReference m_oGCPSRS{};
     115             :     mutable CPLMutex *m_hMutex;
     116             :     mutable OGRSpatialReference m_oSRS{};
     117             : };
     118             : 
     119             : // conversion functions
     120             : GDALDataType KEA_to_GDAL_Type(kealib::KEADataType ekeaType);
     121             : kealib::KEADataType GDAL_to_KEA_Type(GDALDataType egdalType);
     122             : 
     123             : // For unloading the VFL
     124             : void KEADatasetDriverUnload(GDALDriver *);
     125             : 
     126             : // A thresafe reference count. Used to manage shared pointer to
     127             : // the kealib::KEAImageIO instance between bands and dataset.
     128             : class LockedRefCount
     129             : {
     130             :   private:
     131             :     int m_nRefCount;
     132             :     CPLMutex *m_hMutex;
     133             : 
     134             :     CPL_DISALLOW_COPY_ASSIGN(LockedRefCount)
     135             : 
     136             :   public:
     137         252 :     explicit LockedRefCount(int initCount = 1)
     138         252 :     {
     139         252 :         m_nRefCount = initCount;
     140         252 :         m_hMutex = CPLCreateMutex();
     141         252 :         CPLReleaseMutex(m_hMutex);
     142         252 :     }
     143             : 
     144         252 :     ~LockedRefCount()
     145         252 :     {
     146         252 :         CPLDestroyMutex(m_hMutex);
     147         252 :         m_hMutex = nullptr;
     148         252 :     }
     149             : 
     150         355 :     void IncRef()
     151             :     {
     152         355 :         CPLMutexHolderD(&m_hMutex);
     153         355 :         m_nRefCount++;
     154         355 :     }
     155             : 
     156             :     // returns true if reference count now 0
     157         607 :     bool DecRef()
     158             :     {
     159         607 :         CPLMutexHolderD(&m_hMutex);
     160         607 :         m_nRefCount--;
     161        1214 :         return m_nRefCount <= 0;
     162             :     }
     163             : };
     164             : 
     165             : #endif  // KEADATASET_H

Generated by: LCOV version 1.14