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

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  MiraMon Raster Driver
       4             :  * Purpose:  Implements MMRPalettes class: handles access to a DBF file
       5             :  *           containing color information, which is then converted into
       6             :  *           either a color table or an attribute table, depending on the
       7             :  *           context.
       8             :  * Author:   Abel Pau
       9             :  *
      10             :  ******************************************************************************
      11             :  * Copyright (c) 2025, Xavier Pons
      12             :  *
      13             :  * SPDX-License-Identifier: MIT
      14             :  ****************************************************************************/
      15             : 
      16             : #ifndef MMRPALETTES_H_INCLUDED
      17             : #define MMRPALETTES_H_INCLUDED
      18             : 
      19             : #include <array>
      20             : 
      21             : #include "../miramon_common/mm_gdal_constants.h"  // For MM_EXT_DBF_N_FIELDS
      22             : 
      23             : class MMRRel;
      24             : 
      25             : enum class ColorTreatment
      26             : {
      27             :     DEFAULT_SCALING = 0,
      28             :     DIRECT_ASSIGNATION = 1,
      29             :     ORIGIN_DISPLACEMENT = 2,
      30             :     LINEAR_SCALING = 3,
      31             :     LOG_10_SCALING = 4,
      32             :     USER_INTERVALS = 5
      33             : };
      34             : 
      35             : /* ==================================================================== */
      36             : /*                            MMRPalettes                             */
      37             : /* ==================================================================== */
      38             : 
      39             : class MMRPalettes
      40             : {
      41             :   public:
      42             :     MMRPalettes(MMRRel &fRel, const CPLString &osBandSectionIn);
      43             :     MMRPalettes(const MMRPalettes &) =
      44             :         delete;  // I don't want to construct a MMRPalettes from another MMRBand (effc++)
      45             :     MMRPalettes &operator=(const MMRPalettes &) =
      46             :         delete;  // I don't want to assign a MMRPalettes to another MMRBand (effc++)
      47             :     ~MMRPalettes();
      48             : 
      49          63 :     bool IsValid() const
      50             :     {
      51          63 :         return m_bIsValid;
      52             :     }
      53             : 
      54          55 :     bool IsCategorical() const
      55             :     {
      56          55 :         return m_bIsCategorical;
      57             :     }
      58             : 
      59          27 :     void SetIsCategorical(bool bIsCategoricalIn)
      60             :     {
      61          27 :         m_bIsCategorical = bIsCategoricalIn;
      62          27 :     }
      63             : 
      64          55 :     bool IsConstantColor() const
      65             :     {
      66          55 :         return m_bIsConstantColor;
      67             :     }
      68             : 
      69        5692 :     GDALColorEntry GetDefaultColorRGB() const
      70             :     {
      71        5692 :         return m_sDefaultColorRGB;
      72             :     }
      73             : 
      74         768 :     GDALColorEntry GetConstantColorRGB() const
      75             :     {
      76         768 :         return m_sConstantColorRGB;
      77             :     }
      78             : 
      79             :     void SetConstantColorRGB(GDALColorEntry sConstantColorRGBIn)
      80             :     {
      81             :         m_sConstantColorRGB = sConstantColorRGBIn;
      82             :     }
      83             : 
      84           2 :     void SetConstantColorRGB(short c1, short c2, short c3)
      85             :     {
      86           2 :         m_sConstantColorRGB.c1 = c1;
      87           2 :         m_sConstantColorRGB.c2 = c2;
      88           2 :         m_sConstantColorRGB.c3 = c3;
      89           2 :     }
      90             : 
      91             :     void SetConstantColorRGB(short c1, short c2, short c3, short c4)
      92             :     {
      93             :         m_sConstantColorRGB.c1 = c1;
      94             :         m_sConstantColorRGB.c2 = c2;
      95             :         m_sConstantColorRGB.c3 = c3;
      96             :         m_sConstantColorRGB.c4 = c4;
      97             :     }
      98             : 
      99         536 :     bool HasNodata() const
     100             :     {
     101         536 :         return m_bHasNodata;
     102             :     }
     103             : 
     104             :     void SetHasNodata(bool bHasNodataIn)
     105             :     {
     106             :         m_bHasNodata = bHasNodataIn;
     107             :     }
     108             : 
     109          23 :     int GetNoDataPaletteIndex() const
     110             :     {
     111          23 :         return m_nNoDataPaletteIndex;
     112             :     }
     113             : 
     114             :     void SetNoDataPaletteIndex(bool nNoDataPaletteIndexIn)
     115             :     {
     116             :         m_nNoDataPaletteIndex = nNoDataPaletteIndexIn;
     117             :     }
     118             : 
     119           3 :     GDALColorEntry GetNoDataDefaultColor() const
     120             :     {
     121           3 :         return m_sNoDataColorRGB;
     122             :     }
     123             : 
     124      266276 :     double GetPaletteColorsValue(int nIComponent, int nIColor) const
     125             :     {
     126      266276 :         return m_aadfPaletteColors[nIComponent][nIColor];
     127             :     }
     128             : 
     129          19 :     int GetSizeOfPaletteColors() const
     130             :     {
     131          19 :         return static_cast<int>(m_aadfPaletteColors[0].size());
     132             :     }
     133             : 
     134       66085 :     int GetNumberOfColors() const
     135             :     {
     136       66085 :         return m_nNPaletteColors;
     137             :     }
     138             : 
     139             :     // Real means with no nodata.
     140           7 :     int GetNumberOfColorsIncludingNodata() const
     141             :     {
     142           7 :         return m_nRealNPaletteColors;
     143             :     }
     144             : 
     145             :     void UpdateColorInfo();
     146             : 
     147             :     ColorTreatment ColorScaling = ColorTreatment::DEFAULT_SCALING;
     148             : 
     149             :   private:
     150             :     static CPLErr GetPaletteColors_DBF_Indexes(
     151             :         struct MM_DATA_BASE_XP &oColorTable, MM_EXT_DBF_N_FIELDS &nClauSimbol,
     152             :         MM_EXT_DBF_N_FIELDS &nRIndex, MM_EXT_DBF_N_FIELDS &nGIndex,
     153             :         MM_EXT_DBF_N_FIELDS &nBIndex);
     154             :     CPLErr GetPaletteColors_DBF(const CPLString &os_Color_Paleta_DBF);
     155             :     CPLErr GetPaletteColors_PAL_P25_P65(const CPLString &os_Color_Paleta_DBF);
     156             :     void AssignColorFromDBF(struct MM_DATA_BASE_XP &oColorTable,
     157             :                             char *pzsRecord, char *pszField,
     158             :                             MM_EXT_DBF_N_FIELDS &nRIndex,
     159             :                             MM_EXT_DBF_N_FIELDS &nGIndex,
     160             :                             MM_EXT_DBF_N_FIELDS &nBIndex, int nIPaletteIndex);
     161             :     CPLErr UpdateConstantColor();
     162             : 
     163             :     std::array<std::vector<double>, 4> m_aadfPaletteColors{};
     164             :     bool m_bIsCategorical = false;
     165             : 
     166             :     // Palette info
     167             :     GDALColorEntry m_sDefaultColorRGB = {0, 0, 0, 127};
     168             : 
     169             :     bool m_bHasNodata = false;
     170             :     // index in the DBF that gives nodata color
     171             :     int m_nNoDataPaletteIndex = 0;
     172             :     // Default color for nodata
     173             :     GDALColorEntry m_sNoDataColorRGB = {0, 0, 0, 0};
     174             : 
     175             :     bool m_bIsConstantColor = false;
     176             :     GDALColorEntry m_sConstantColorRGB = {0, 0, 0, 0};
     177             : 
     178             :     int m_nNPaletteColors = 0;
     179             :     int m_nRealNPaletteColors = 0;  // Without nodata
     180             : 
     181             :     MMRRel *m_pfRel = nullptr;  // Rel where metadata is read from
     182             :     CPLString m_osBandSection;
     183             : 
     184             :     bool m_bIsValid =
     185             :         false;  // Determines if the created object is valid or not.
     186             : };
     187             : 
     188             : #endif  // MMRPALETTES_H_INCLUDED

Generated by: LCOV version 1.14