LCOV - code coverage report
Current view: top level - apps - gdalalg_raster_blend.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 4 4 100.0 %
Date: 2026-06-03 12:46:18 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  "blend" step of "raster pipeline"
       5             :  * Author:   Even Rouault <even dot rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2025, Even Rouault <even dot rouault at spatialys.com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #ifndef GDALALG_RASTER_BLEND_INCLUDED
      14             : #define GDALALG_RASTER_BLEND_INCLUDED
      15             : 
      16             : #include "gdalrasterpipelinestepalgorithm.h"
      17             : 
      18             : #include "gdal_dataset.h"
      19             : 
      20             : //! @cond Doxygen_Suppress
      21             : 
      22             : /************************************************************************/
      23             : /*                           CompositionMode                            */
      24             : /************************************************************************/
      25             : 
      26             : //! Blend composition modes (aka: operators)
      27             : enum class CompositionMode : unsigned
      28             : {
      29             :     SRC_OVER = 0,
      30             :     HSV_VALUE,
      31             :     MULTIPLY,
      32             :     SCREEN,
      33             :     OVERLAY,
      34             :     HARD_LIGHT,
      35             :     DARKEN,
      36             :     LIGHTEN,
      37             :     COLOR_DODGE,
      38             :     COLOR_BURN,
      39             : };
      40             : 
      41             : //! Returns a map of all composition modes to their string identifiers
      42             : std::map<CompositionMode, std::string> CompositionModes();
      43             : 
      44             : //! Returns the text identifier of the composition mode
      45             : std::string CompositionModeToString(CompositionMode mode);
      46             : 
      47             : //! Returns a list of all modes string identifiers
      48             : std::vector<std::string> CompositionModesIdentifiers();
      49             : 
      50             : //! Parses a composition mode from its string identifier
      51             : CompositionMode CompositionModeFromString(const std::string &str);
      52             : 
      53             : //! Returns the minimum number of bands required for the given composition mode
      54             : int MinBandCountForCompositionMode(CompositionMode mode);
      55             : 
      56             : /**
      57             :  *  Returns the maximum number of bands allowed for the given composition mode
      58             :  *  (-1 means no limit)
      59             :  */
      60             : int MaxBandCountForCompositionMode(CompositionMode mode);
      61             : 
      62             : //! Checks whether the number of bands is compatible with the given composition mode
      63             : bool BandCountIsCompatibleWithCompositionMode(int bandCount,
      64             :                                               CompositionMode mode);
      65             : 
      66             : /************************************************************************/
      67             : /*                       GDALRasterBlendAlgorithm                       */
      68             : /************************************************************************/
      69             : 
      70             : class GDALRasterBlendAlgorithm /* non final*/
      71             :     : public GDALRasterPipelineStepAlgorithm
      72             : {
      73             :   public:
      74             :     explicit GDALRasterBlendAlgorithm(bool standaloneStep = false);
      75             : 
      76             :     static constexpr const char *NAME = "blend";
      77             :     static constexpr const char *DESCRIPTION =
      78             :         "Blend/compose two raster datasets";
      79             :     static constexpr const char *HELP_URL = "/programs/gdal_raster_blend.html";
      80             : 
      81             :   private:
      82             :     bool RunStep(GDALPipelineStepRunContext &ctxt) override;
      83             :     bool ValidateGlobal();
      84             : 
      85             :     GDALArgDatasetValue m_overlayDataset{};
      86             :     CompositionMode m_operator{};
      87             :     std::string m_operatorIdentifier{};
      88             :     static constexpr int OPACITY_INPUT_RANGE = 100;
      89             :     int m_opacity = OPACITY_INPUT_RANGE;
      90             :     std::unique_ptr<GDALDataset, GDALDatasetUniquePtrReleaser> m_poTmpSrcDS{};
      91             :     std::unique_ptr<GDALDataset, GDALDatasetUniquePtrReleaser>
      92             :         m_poTmpOverlayDS{};
      93             : };
      94             : 
      95             : /************************************************************************/
      96             : /*                  GDALRasterBlendAlgorithmStandalone                  */
      97             : /************************************************************************/
      98             : 
      99         442 : class GDALRasterBlendAlgorithmStandalone final : public GDALRasterBlendAlgorithm
     100             : {
     101             :   public:
     102         221 :     GDALRasterBlendAlgorithmStandalone()
     103         221 :         : GDALRasterBlendAlgorithm(/* standaloneStep = */ true)
     104             :     {
     105         221 :     }
     106             : 
     107             :     ~GDALRasterBlendAlgorithmStandalone() override;
     108             : };
     109             : 
     110             : //! @endcond
     111             : 
     112             : #endif /* GDALALG_RASTER_COLOR_MERGE_INCLUDED */

Generated by: LCOV version 1.14