LCOV - code coverage report
Current view: top level - alg - gdal_alg_priv.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 7 7 100.0 %
Date: 2025-03-28 21:34:50 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  * $Id$
       3             :  *
       4             :  * Project:  GDAL Image Processing Algorithms
       5             :  * Purpose:  Prototypes and definitions for various GDAL based algorithms:
       6             :  *           private declarations.
       7             :  * Author:   Andrey Kiselev, dron@ak4719.spb.edu
       8             :  *
       9             :  ******************************************************************************
      10             :  * Copyright (c) 2008, Andrey Kiselev <dron@ak4719.spb.edu>
      11             :  * Copyright (c) 2010-2013, Even Rouault <even dot rouault at spatialys.com>
      12             :  *
      13             :  * SPDX-License-Identifier: MIT
      14             :  ****************************************************************************/
      15             : 
      16             : #ifndef GDAL_ALG_PRIV_H_INCLUDED
      17             : #define GDAL_ALG_PRIV_H_INCLUDED
      18             : 
      19             : #ifndef DOXYGEN_SKIP
      20             : 
      21             : #include <cstdint>
      22             : 
      23             : #include <set>
      24             : 
      25             : #include "gdal_alg.h"
      26             : #include "ogr_spatialref.h"
      27             : 
      28             : CPL_C_START
      29             : 
      30             : /** Source of the burn value */
      31             : typedef enum
      32             : {
      33             :     /*! Use value from padfBurnValue */ GBV_UserBurnValue = 0,
      34             :     /*! Use value from the Z coordinate */ GBV_Z = 1,
      35             :     /*! Use value form the M value */ GBV_M = 2
      36             : } GDALBurnValueSrc;
      37             : 
      38             : typedef enum
      39             : {
      40             :     GRMA_Replace = 0,
      41             :     GRMA_Add = 1,
      42             : } GDALRasterMergeAlg;
      43             : 
      44             : typedef struct
      45             : {
      46             :     unsigned char *pabyChunkBuf;
      47             :     int nXSize;
      48             :     int nYSize;
      49             :     int nBands;
      50             :     GDALDataType eType;
      51             :     int nPixelSpace;
      52             :     GSpacing nLineSpace;
      53             :     GSpacing nBandSpace;
      54             :     GDALDataType eBurnValueType;
      55             : 
      56             :     union
      57             :     {
      58             :         const std::int64_t *int64_values;
      59             :         const double *double_values;
      60             :     } burnValues;
      61             : 
      62             :     GDALBurnValueSrc eBurnValueSource;
      63             :     GDALRasterMergeAlg eMergeAlg;
      64             :     bool bFillSetVisitedPoints;
      65             :     std::set<uint64_t> *poSetVisitedPoints;
      66             : } GDALRasterizeInfo;
      67             : 
      68             : typedef enum
      69             : {
      70             :     GRO_Raster = 0,
      71             :     GRO_Vector = 1,
      72             :     GRO_Auto = 2,
      73             : } GDALRasterizeOptim;
      74             : 
      75             : /************************************************************************/
      76             : /*      Low level rasterizer API.                                       */
      77             : /************************************************************************/
      78             : 
      79             : typedef void (*llScanlineFunc)(GDALRasterizeInfo *, int, int, int, double);
      80             : typedef void (*llPointFunc)(GDALRasterizeInfo *, int, int, double);
      81             : 
      82             : void GDALdllImagePoint(int nRasterXSize, int nRasterYSize, int nPartCount,
      83             :                        const int *panPartSize, const double *padfX,
      84             :                        const double *padfY, const double *padfVariant,
      85             :                        llPointFunc pfnPointFunc, GDALRasterizeInfo *pCBData);
      86             : 
      87             : void GDALdllImageLine(int nRasterXSize, int nRasterYSize, int nPartCount,
      88             :                       const int *panPartSize, const double *padfX,
      89             :                       const double *padfY, const double *padfVariant,
      90             :                       llPointFunc pfnPointFunc, GDALRasterizeInfo *pCBData);
      91             : 
      92             : void GDALdllImageLineAllTouched(
      93             :     int nRasterXSize, int nRasterYSize, int nPartCount, const int *panPartSize,
      94             :     const double *padfX, const double *padfY, const double *padfVariant,
      95             :     llPointFunc pfnPointFunc, GDALRasterizeInfo *pCBData,
      96             :     bool bAvoidBurningSamePoints, bool bIntersectOnly);
      97             : 
      98             : void GDALdllImageFilledPolygon(int nRasterXSize, int nRasterYSize,
      99             :                                int nPartCount, const int *panPartSize,
     100             :                                const double *padfX, const double *padfY,
     101             :                                const double *padfVariant,
     102             :                                llScanlineFunc pfnScanlineFunc,
     103             :                                GDALRasterizeInfo *pCBData,
     104             :                                bool bAvoidBurningSamePoints);
     105             : 
     106             : CPL_C_END
     107             : 
     108             : /************************************************************************/
     109             : /*                          Polygon Enumerator                          */
     110             : /************************************************************************/
     111             : 
     112             : #define GP_NODATA_MARKER -51502112
     113             : 
     114             : template <class DataType, class EqualityTest> class GDALRasterPolygonEnumeratorT
     115             : 
     116             : {
     117             :   private:
     118             :     void MergePolygon(int nSrcId, int nDstId);
     119             :     int NewPolygon(DataType nValue);
     120             : 
     121             :     CPL_DISALLOW_COPY_ASSIGN(GDALRasterPolygonEnumeratorT)
     122             : 
     123             :   public:  // these are intended to be readonly.
     124             :     GInt32 *panPolyIdMap = nullptr;
     125             :     DataType *panPolyValue = nullptr;
     126             : 
     127             :     int nNextPolygonId = 0;
     128             :     int nPolyAlloc = 0;
     129             : 
     130             :     int nConnectedness = 0;
     131             : 
     132             :   public:
     133             :     explicit GDALRasterPolygonEnumeratorT(int nConnectedness = 4);
     134             :     ~GDALRasterPolygonEnumeratorT();
     135             : 
     136             :     bool ProcessLine(DataType *panLastLineVal, DataType *panThisLineVal,
     137             :                      GInt32 *panLastLineId, GInt32 *panThisLineId, int nXSize);
     138             : 
     139             :     void CompleteMerges();
     140             : 
     141             :     void Clear();
     142             : };
     143             : 
     144             : struct IntEqualityTest
     145             : {
     146     1536900 :     bool operator()(std::int64_t a, std::int64_t b) const
     147             :     {
     148     1536900 :         return a == b;
     149             :     }
     150             : };
     151             : 
     152             : typedef GDALRasterPolygonEnumeratorT<std::int64_t, IntEqualityTest>
     153             :     GDALRasterPolygonEnumerator;
     154             : 
     155             : constexpr const char *GDAL_APPROX_TRANSFORMER_CLASS_NAME =
     156             :     "GDALApproxTransformer";
     157             : constexpr const char *GDAL_GEN_IMG_TRANSFORMER_CLASS_NAME =
     158             :     "GDALGenImgProjTransformer";
     159             : constexpr const char *GDAL_RPC_TRANSFORMER_CLASS_NAME = "GDALRPCTransformer";
     160             : 
     161             : bool GDALIsTransformer(void *hTransformerArg, const char *pszClassName);
     162             : 
     163             : typedef void *(*GDALTransformDeserializeFunc)(CPLXMLNode *psTree);
     164             : 
     165             : void CPL_DLL *GDALRegisterTransformDeserializer(
     166             :     const char *pszTransformName, GDALTransformerFunc pfnTransformerFunc,
     167             :     GDALTransformDeserializeFunc pfnDeserializeFunc);
     168             : void CPL_DLL GDALUnregisterTransformDeserializer(void *pData);
     169             : 
     170             : void GDALCleanupTransformDeserializerMutex();
     171             : 
     172             : /* Transformer cloning */
     173             : 
     174             : void *GDALCreateTPSTransformerInt(int nGCPCount, const GDAL_GCP *pasGCPList,
     175             :                                   int bReversed, CSLConstList papszOptions);
     176             : 
     177             : void CPL_DLL *GDALCloneTransformer(void *pTransformerArg);
     178             : 
     179             : void GDALRefreshGenImgProjTransformer(void *hTransformArg);
     180             : void GDALRefreshApproxTransformer(void *hTransformArg);
     181             : 
     182             : int GDALTransformLonLatToDestGenImgProjTransformer(void *hTransformArg,
     183             :                                                    double *pdfX, double *pdfY);
     184             : int GDALTransformLonLatToDestApproxTransformer(void *hTransformArg,
     185             :                                                double *pdfX, double *pdfY);
     186             : 
     187             : bool GDALTransformIsTranslationOnPixelBoundaries(
     188             :     GDALTransformerFunc pfnTransformer, void *pTransformerArg);
     189             : 
     190             : bool GDALTransformIsAffineNoRotation(GDALTransformerFunc pfnTransformer,
     191             :                                      void *pTransformerArg);
     192             : 
     193             : bool GDALTransformHasFastClone(void *pTransformerArg);
     194             : 
     195             : typedef struct _CPLQuadTree CPLQuadTree;
     196             : 
     197             : typedef struct
     198             : {
     199             :     GDALTransformerInfo sTI;
     200             : 
     201             :     bool bReversed;
     202             :     double dfOversampleFactor;
     203             : 
     204             :     // Map from target georef coordinates back to geolocation array
     205             :     // pixel line coordinates.  Built only if needed.
     206             :     int nBackMapWidth;
     207             :     int nBackMapHeight;
     208             :     double adfBackMapGeoTransform[6];  // Maps georef to pixel/line.
     209             : 
     210             :     bool bUseArray;
     211             :     void *pAccessors;
     212             : 
     213             :     // Geolocation bands.
     214             :     GDALDatasetH hDS_X;
     215             :     GDALRasterBandH hBand_X;
     216             :     GDALDatasetH hDS_Y;
     217             :     GDALRasterBandH hBand_Y;
     218             :     int bSwapXY;
     219             : 
     220             :     // Located geolocation data.
     221             :     int nGeoLocXSize;
     222             :     int nGeoLocYSize;
     223             :     double dfMinX;
     224             :     double dfYAtMinX;
     225             :     double dfMinY;
     226             :     double dfXAtMinY;
     227             :     double dfMaxX;
     228             :     double dfYAtMaxX;
     229             :     double dfMaxY;
     230             :     double dfXAtMaxY;
     231             : 
     232             :     int bHasNoData;
     233             :     double dfNoDataX;
     234             : 
     235             :     // Geolocation <-> base image mapping.
     236             :     double dfPIXEL_OFFSET;
     237             :     double dfPIXEL_STEP;
     238             :     double dfLINE_OFFSET;
     239             :     double dfLINE_STEP;
     240             : 
     241             :     bool bOriginIsTopLeftCorner;
     242             :     bool bGeographicSRSWithMinus180Plus180LongRange;
     243             :     CPLQuadTree *hQuadTree;
     244             : 
     245             :     char **papszGeolocationInfo;
     246             : 
     247             : } GDALGeoLocTransformInfo;
     248             : 
     249             : /************************************************************************/
     250             : /* ==================================================================== */
     251             : /*                       GDALReprojectionTransformer                    */
     252             : /* ==================================================================== */
     253             : /************************************************************************/
     254             : 
     255             : struct GDALReprojectionTransformInfo
     256             : {
     257             :     GDALTransformerInfo sTI;
     258             :     char **papszOptions = nullptr;
     259             :     double dfTime = 0.0;
     260             : 
     261             :     OGRCoordinateTransformation *poForwardTransform = nullptr;
     262             :     OGRCoordinateTransformation *poReverseTransform = nullptr;
     263             : 
     264         886 :     GDALReprojectionTransformInfo() : sTI()
     265             :     {
     266         886 :         memset(&sTI, 0, sizeof(sTI));
     267         886 :     }
     268             : 
     269             :     GDALReprojectionTransformInfo(const GDALReprojectionTransformInfo &) =
     270             :         delete;
     271             :     GDALReprojectionTransformInfo &
     272             :     operator=(const GDALReprojectionTransformInfo &) = delete;
     273             : };
     274             : 
     275             : /************************************************************************/
     276             : /* ==================================================================== */
     277             : /*                       GDALGenImgProjTransformer                      */
     278             : /* ==================================================================== */
     279             : /************************************************************************/
     280             : 
     281             : struct GDALGenImgProjTransformPart
     282             : {
     283             :     double adfGeoTransform[6];
     284             :     double adfInvGeoTransform[6];
     285             : 
     286             :     void *pTransformArg;
     287             :     GDALTransformerFunc pTransformer;
     288             : };
     289             : 
     290             : typedef struct
     291             : {
     292             : 
     293             :     GDALTransformerInfo sTI;
     294             : 
     295             :     GDALGenImgProjTransformPart sSrcParams;
     296             : 
     297             :     void *pReprojectArg;
     298             :     GDALTransformerFunc pReproject;
     299             : 
     300             :     GDALGenImgProjTransformPart sDstParams;
     301             : 
     302             :     // Memorize the value of the CHECK_WITH_INVERT_PROJ at the time we
     303             :     // instantiated the object, to be able to decide if
     304             :     // GDALRefreshGenImgProjTransformer() must do something or not.
     305             :     bool bCheckWithInvertPROJ;
     306             : 
     307             :     // Set to TRUE when the transformation pipline is a custom one.
     308             :     bool bHasCustomTransformationPipeline;
     309             : 
     310             : } GDALGenImgProjTransformInfo;
     311             : 
     312             : /************************************************************************/
     313             : /*      Color table related                                             */
     314             : /************************************************************************/
     315             : 
     316             : // Definitions exists for T = GUInt32 and T = GUIntBig.
     317             : template <class T>
     318             : int GDALComputeMedianCutPCTInternal(
     319             :     GDALRasterBandH hRed, GDALRasterBandH hGreen, GDALRasterBandH hBlue,
     320             :     GByte *pabyRedBand, GByte *pabyGreenBand, GByte *pabyBlueBand,
     321             :     int (*pfnIncludePixel)(int, int, void *), int nColors, int nBits,
     322             :     T *panHistogram, GDALColorTableH hColorTable, GDALProgressFunc pfnProgress,
     323             :     void *pProgressArg);
     324             : 
     325             : int GDALDitherRGB2PCTInternal(GDALRasterBandH hRed, GDALRasterBandH hGreen,
     326             :                               GDALRasterBandH hBlue, GDALRasterBandH hTarget,
     327             :                               GDALColorTableH hColorTable, int nBits,
     328             :                               GInt16 *pasDynamicColorMap, int bDither,
     329             :                               GDALProgressFunc pfnProgress, void *pProgressArg);
     330             : 
     331             : #define PRIME_FOR_65536 98317
     332             : 
     333             : // See HashHistogram structure in gdalmediancut.cpp and ColorIndex structure in
     334             : // gdaldither.cpp 6 * sizeof(int) should be the size of the largest of both
     335             : // structures.
     336             : #define MEDIAN_CUT_AND_DITHER_BUFFER_SIZE_65536                                \
     337             :     (6 * sizeof(int) * PRIME_FOR_65536)
     338             : 
     339             : /************************************************************************/
     340             : /*      Float comparison function.                                      */
     341             : /************************************************************************/
     342             : 
     343             : /**
     344             :  * Units in the Last Place. This specifies how big an error we are willing to
     345             :  * accept in terms of the value of the least significant digit of the floating
     346             :  * point number’s representation. MAX_ULPS can also be interpreted in terms of
     347             :  * how many representable floats we are willing to accept between A and B.
     348             :  */
     349             : #define MAX_ULPS 10
     350             : 
     351             : GBool GDALFloatEquals(float A, float B);
     352             : 
     353             : struct FloatEqualityTest
     354             : {
     355          88 :     bool operator()(float a, float b)
     356             :     {
     357          88 :         return GDALFloatEquals(a, b) == TRUE;
     358             :     }
     359             : };
     360             : 
     361             : bool GDALComputeAreaOfInterest(OGRSpatialReference *poSRS, double adfGT[6],
     362             :                                int nXSize, int nYSize,
     363             :                                double &dfWestLongitudeDeg,
     364             :                                double &dfSouthLatitudeDeg,
     365             :                                double &dfEastLongitudeDeg,
     366             :                                double &dfNorthLatitudeDeg);
     367             : 
     368             : bool GDALComputeAreaOfInterest(OGRSpatialReference *poSRS, double dfX1,
     369             :                                double dfY1, double dfX2, double dfY2,
     370             :                                double &dfWestLongitudeDeg,
     371             :                                double &dfSouthLatitudeDeg,
     372             :                                double &dfEastLongitudeDeg,
     373             :                                double &dfNorthLatitudeDeg);
     374             : 
     375             : CPLStringList GDALCreateGeolocationMetadata(GDALDatasetH hBaseDS,
     376             :                                             const char *pszGeolocationDataset,
     377             :                                             bool bIsSource);
     378             : 
     379             : void *GDALCreateGeoLocTransformerEx(GDALDatasetH hBaseDS,
     380             :                                     CSLConstList papszGeolocationInfo,
     381             :                                     int bReversed, const char *pszSourceDataset,
     382             :                                     CSLConstList papszTransformOptions);
     383             : 
     384             : #endif /* #ifndef DOXYGEN_SKIP */
     385             : 
     386             : #endif /* ndef GDAL_ALG_PRIV_H_INCLUDED */

Generated by: LCOV version 1.14