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 : double GetNoDataValue(int *pbSuccess = nullptr) override; 51 : GDALRasterAttributeTable *GetDefaultRAT() override; 52 : 53 67602 : const std::vector<double> &GetPCT_Red() const 54 : { 55 67602 : return m_aadfPCT[0]; 56 : } 57 : 58 67591 : const std::vector<double> &GetPCT_Green() const 59 : { 60 67591 : return m_aadfPCT[1]; 61 : } 62 : 63 67591 : const std::vector<double> &GetPCT_Blue() const 64 : { 65 67591 : return m_aadfPCT[2]; 66 : } 67 : 68 67591 : const std::vector<double> &GetPCT_Alpha() const 69 : { 70 67591 : return m_aadfPCT[3]; 71 : } 72 : 73 63 : bool IsValid() const 74 : { 75 63 : return m_bIsValid; 76 : } 77 : 78 1032 : bool IsInteger() const 79 : { 80 1032 : if (m_eMMRDataTypeMiraMon == MMDataType::DATATYPE_AND_COMPR_BIT || 81 1032 : m_eMMRDataTypeMiraMon == MMDataType::DATATYPE_AND_COMPR_BYTE || 82 1032 : m_eMMRDataTypeMiraMon == MMDataType::DATATYPE_AND_COMPR_INTEGER || 83 1032 : m_eMMRDataTypeMiraMon == MMDataType::DATATYPE_AND_COMPR_UINTEGER || 84 524 : m_eMMRDataTypeMiraMon == MMDataType::DATATYPE_AND_COMPR_LONG || 85 508 : m_eMMRDataTypeMiraMon == 86 508 : MMDataType::DATATYPE_AND_COMPR_INTEGER_ASCII || 87 508 : m_eMMRDataTypeMiraMon == MMDataType::DATATYPE_AND_COMPR_BYTE_RLE || 88 508 : m_eMMRDataTypeMiraMon == 89 508 : MMDataType::DATATYPE_AND_COMPR_INTEGER_RLE || 90 508 : m_eMMRDataTypeMiraMon == 91 508 : MMDataType::DATATYPE_AND_COMPR_UINTEGER_RLE || 92 508 : m_eMMRDataTypeMiraMon == MMDataType::DATATYPE_AND_COMPR_LONG_RLE) 93 524 : return true; 94 508 : return false; 95 : } 96 : 97 : private: 98 : void AssignRGBColor(int nIndexDstPalette, int nIndexSrcPalette); 99 : void AssignRGBColorDirectly(int nIndexDstPalette, double dfValue); 100 : void UpdateDataType(); 101 : CPLErr FillRATFromPalette(); 102 : CPLErr FromPaletteToAttributeTable(); 103 : CPLErr FromPaletteToAttributeTableConstant(); 104 : CPLErr FromPaletteToAttributeTableDirectAssig(); 105 : CPLErr FromPaletteToAttributeTableLinear(); 106 : void ConvertColorsFromPaletteToColorTable(); 107 : CPLErr GetRATName(CPLString aosToken, CPLString &osRELName, 108 : CPLString &osDBFName, CPLString &osAssociateREL); 109 : CPLErr UpdateAttributeColorsFromPalette(); 110 : CPLErr CreateRATFromDBF(const CPLString &osRELName, 111 : const CPLString &osDBFName, 112 : const CPLString &osAssociateRel); 113 : 114 : CPLErr AssignUniformColorTable(); 115 : CPLErr FromPaletteToColorTableCategoricalMode(); 116 : CPLErr FromPaletteToColorTableContinuousMode(); 117 : CPLErr UpdateTableColorsFromPalette(); 118 : 119 : bool m_bTriedLoadColorTable = false; 120 : bool m_bIsValid = 121 : false; // Determines if the created object is valid or not. 122 : 123 : std::array<std::vector<double>, 4> m_aadfPCT{}; 124 : 125 : CPLString m_osBandSection = ""; // Name of the band 126 : 127 : MMDataType m_eMMRDataTypeMiraMon = MMDataType::DATATYPE_AND_COMPR_UNDEFINED; 128 : MMBytesPerPixel m_eMMBytesPerPixel = 129 : MMBytesPerPixel::TYPE_BYTES_PER_PIXEL_UNDEFINED; 130 : 131 : MMRRel *m_pfRel = nullptr; // Pointer to info from rel. Do not free. 132 : 133 : // Color table 134 : std::unique_ptr<GDALColorTable> m_poCT = nullptr; 135 : 136 : // Attributte table 137 : std::unique_ptr<GDALRasterAttributeTable> m_poDefaultRAT = nullptr; 138 : 139 : // Palettes 140 : std::unique_ptr<MMRPalettes> m_Palette = nullptr; 141 : }; 142 : 143 : #endif // MMRRASTERBAND_H_INCLUDED