LCOV - code coverage report
Current view: top level - frmts/miramon - miramon_rasterband.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 26 26 100.0 %
Date: 2026-02-12 23:49:34 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  MiraMon Raster Driver
       4             :  * Purpose:  Implements MMRRasterBand class: responsible for converting the
       5             :  *           information stored in an MMRBand into a GDAL RasterBand
       6             :  * Author:   Abel Pau
       7             :  *
       8             :  ******************************************************************************
       9             :  * Copyright (c) 2025, Xavier Pons
      10             :  *
      11             :  * SPDX-License-Identifier: MIT
      12             :  ****************************************************************************/
      13             : 
      14             : #ifndef MMRRASTERBAND_H_INCLUDED
      15             : #define MMRRASTERBAND_H_INCLUDED
      16             : 
      17             : #include <cstddef>
      18             : #include <vector>
      19             : #include <optional>
      20             : #include <array>
      21             : 
      22             : #include "gdal_pam.h"
      23             : #include "gdal_rat.h"
      24             : 
      25             : #include "../miramon_common/mm_gdal_constants.h"  // For MM_EXT_DBF_N_FIELDS
      26             : #include "miramon_rel.h"                          // For MMDataType
      27             : #include "miramon_palettes.h"
      28             : 
      29             : class MMRDataset;
      30             : 
      31             : /* ==================================================================== */
      32             : /*                            MMRRasterBand                             */
      33             : /* ==================================================================== */
      34             : class MMRRasterBand final : public GDALPamRasterBand
      35             : {
      36             :   public:
      37             :     MMRRasterBand(MMRDataset *, int);
      38             : 
      39             :     MMRRasterBand(const MMRRasterBand &) =
      40             :         delete;  // I don't want to construct a MMRRasterBand from another MMRRasterBand (effc++)
      41             :     MMRRasterBand &operator=(const MMRRasterBand &) =
      42             :         delete;  // I don't want to assign a MMRRasterBand to another MMRRasterBand (effc++)
      43             :     ~MMRRasterBand() override;
      44             : 
      45             :     CPLErr IReadBlock(int, int, void *) override;
      46             :     GDALColorInterp GetColorInterpretation() override;
      47             :     GDALColorTable *GetColorTable() override;
      48             :     double GetMinimum(int *pbSuccess = nullptr) override;
      49             :     double GetMaximum(int *pbSuccess = nullptr) override;
      50             :     const char *GetUnitType() override;
      51             :     CPLErr SetUnitType(const char *pszNewValue) override;
      52             :     double GetNoDataValue(int *pbSuccess = nullptr) override;
      53             :     GDALRasterAttributeTable *GetDefaultRAT() override;
      54             : 
      55        7572 :     const std::vector<double> &GetPCT_Red() const
      56             :     {
      57        7572 :         return m_aadfPCT[0];
      58             :     }
      59             : 
      60        7525 :     const std::vector<double> &GetPCT_Green() const
      61             :     {
      62        7525 :         return m_aadfPCT[1];
      63             :     }
      64             : 
      65        7525 :     const std::vector<double> &GetPCT_Blue() const
      66             :     {
      67        7525 :         return m_aadfPCT[2];
      68             :     }
      69             : 
      70        7525 :     const std::vector<double> &GetPCT_Alpha() const
      71             :     {
      72        7525 :         return m_aadfPCT[3];
      73             :     }
      74             : 
      75          61 :     bool IsValid() const
      76             :     {
      77          61 :         return m_bIsValid;
      78             :     }
      79             : 
      80        1032 :     bool IsInteger() const
      81             :     {
      82        1032 :         if (m_eMMRDataTypeMiraMon == MMDataType::DATATYPE_AND_COMPR_BIT ||
      83        1032 :             m_eMMRDataTypeMiraMon == MMDataType::DATATYPE_AND_COMPR_BYTE ||
      84        1032 :             m_eMMRDataTypeMiraMon == MMDataType::DATATYPE_AND_COMPR_INTEGER ||
      85        1032 :             m_eMMRDataTypeMiraMon == MMDataType::DATATYPE_AND_COMPR_UINTEGER ||
      86         524 :             m_eMMRDataTypeMiraMon == MMDataType::DATATYPE_AND_COMPR_LONG ||
      87         508 :             m_eMMRDataTypeMiraMon ==
      88         508 :                 MMDataType::DATATYPE_AND_COMPR_INTEGER_ASCII ||
      89         508 :             m_eMMRDataTypeMiraMon == MMDataType::DATATYPE_AND_COMPR_BYTE_RLE ||
      90         508 :             m_eMMRDataTypeMiraMon ==
      91         508 :                 MMDataType::DATATYPE_AND_COMPR_INTEGER_RLE ||
      92         508 :             m_eMMRDataTypeMiraMon ==
      93         508 :                 MMDataType::DATATYPE_AND_COMPR_UINTEGER_RLE ||
      94         508 :             m_eMMRDataTypeMiraMon == MMDataType::DATATYPE_AND_COMPR_LONG_RLE)
      95         524 :             return true;
      96         508 :         return false;
      97             :     }
      98             : 
      99             :   private:
     100             :     void AssignRGBColor(int nIndexDstPalette, int nIndexSrcPalette);
     101             :     void AssignRGBColorDirectly(int nIndexDstPalette, double dfValue);
     102             :     void UpdateDataType();
     103             :     CPLErr FillRATFromPalette();
     104             :     CPLErr FromPaletteToAttributeTable();
     105             :     CPLErr FromPaletteToAttributeTableConstant();
     106             :     CPLErr FromPaletteToAttributeTableDirectAssig();
     107             :     CPLErr FromPaletteToAttributeTableLinear();
     108             :     void ConvertColorsFromPaletteToColorTable();
     109             :     CPLErr GetRATName(CPLString &osRELName, CPLString &osDBFName,
     110             :                       CPLString &osAssociateREL);
     111             :     CPLErr UpdateAttributeColorsFromPalette();
     112             :     CPLErr CreateRATFromDBF(const CPLString &osRELName,
     113             :                             const CPLString &osDBFName,
     114             :                             const CPLString &osAssociateRel);
     115             : 
     116             :     CPLErr AssignUniformColorTable();
     117             :     CPLErr FromPaletteToColorTableCategoricalMode();
     118             :     CPLErr FromPaletteToColorTableContinuousMode();
     119             :     CPLErr UpdateTableColorsFromPalette();
     120             : 
     121             :     bool m_bTriedLoadColorTable = false;
     122             :     bool m_bIsValid =
     123             :         false;  // Determines if the created object is valid or not.
     124             : 
     125             :     RAT_OR_CT nRatOrCT = RAT_OR_CT::ALL;
     126             : 
     127             :     std::array<std::vector<double>, 4> m_aadfPCT{};
     128             : 
     129             :     // Name of the band
     130             :     CPLString m_osBandSection = "";
     131             : 
     132             :     CPLString m_osUnitType = "";
     133             : 
     134             :     MMDataType m_eMMRDataTypeMiraMon = MMDataType::DATATYPE_AND_COMPR_UNDEFINED;
     135             :     MMBytesPerPixel m_eMMBytesPerPixel =
     136             :         MMBytesPerPixel::TYPE_BYTES_PER_PIXEL_UNDEFINED;
     137             : 
     138             :     MMRRel *m_pfRel = nullptr;  // Pointer to info from rel. Do not free.
     139             : 
     140             :     // Color table
     141             :     std::unique_ptr<GDALColorTable> m_poCT = nullptr;
     142             : 
     143             :     // Attributte table
     144             :     std::unique_ptr<GDALRasterAttributeTable> m_poDefaultRAT = nullptr;
     145             : 
     146             :     // Palettes
     147             :     std::unique_ptr<MMRPalettes> m_Palette = nullptr;
     148             : };
     149             : 
     150             : #endif  // MMRRASTERBAND_H_INCLUDED

Generated by: LCOV version 1.14