Coverage Report

Created: 2026-02-14 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/apps/gdalalg_raster_blend.h
Line
Count
Source
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 "gdalalg_raster_pipeline.h"
17
18
//! @cond Doxygen_Suppress
19
20
/************************************************************************/
21
/*                           CompositionMode                            */
22
/************************************************************************/
23
24
//! Blend composition modes (aka: operators)
25
enum class CompositionMode : unsigned
26
{
27
    SRC_OVER = 0,
28
    HSV_VALUE,
29
    MULTIPLY,
30
    SCREEN,
31
    OVERLAY,
32
    HARD_LIGHT,
33
    DARKEN,
34
    LIGHTEN,
35
    COLOR_DODGE,
36
    COLOR_BURN,
37
};
38
39
//! Returns a map of all composition modes to their string identifiers
40
std::map<CompositionMode, std::string> CompositionModes();
41
42
//! Returns the text identifier of the composition mode
43
std::string CompositionModeToString(CompositionMode mode);
44
45
//! Returns a list of all modes string identifiers
46
std::vector<std::string> CompositionModesIdentifiers();
47
48
//! Parses a composition mode from its string identifier
49
CompositionMode CompositionModeFromString(const std::string &str);
50
51
//! Returns the minimum number of bands required for the given composition mode
52
int MinBandCountForCompositionMode(CompositionMode mode);
53
54
/**
55
 *  Returns the maximum number of bands allowed for the given composition mode
56
 *  (-1 means no limit)
57
 */
58
int MaxBandCountForCompositionMode(CompositionMode mode);
59
60
//! Checks whether the number of bands is compatible with the given composition mode
61
bool BandCountIsCompatibleWithCompositionMode(int bandCount,
62
                                              CompositionMode mode);
63
64
/************************************************************************/
65
/*                       GDALRasterBlendAlgorithm                       */
66
/************************************************************************/
67
68
class GDALRasterBlendAlgorithm /* non final*/
69
    : public GDALRasterPipelineStepAlgorithm
70
{
71
  public:
72
    explicit GDALRasterBlendAlgorithm(bool standaloneStep = false);
73
74
    static constexpr const char *NAME = "blend";
75
    static constexpr const char *DESCRIPTION =
76
        "Blend/compose two raster datasets";
77
    static constexpr const char *HELP_URL = "/programs/gdal_raster_blend.html";
78
79
  private:
80
    bool RunStep(GDALPipelineStepRunContext &ctxt) override;
81
    bool ValidateGlobal();
82
83
    GDALArgDatasetValue m_overlayDataset{};
84
    CompositionMode m_operator{};
85
    std::string m_operatorIdentifier{};
86
    static constexpr int OPACITY_INPUT_RANGE = 100;
87
    int m_opacity = OPACITY_INPUT_RANGE;
88
    std::unique_ptr<GDALDataset, GDALDatasetUniquePtrReleaser> m_poTmpSrcDS{};
89
    std::unique_ptr<GDALDataset, GDALDatasetUniquePtrReleaser>
90
        m_poTmpOverlayDS{};
91
};
92
93
/************************************************************************/
94
/*                  GDALRasterBlendAlgorithmStandalone                  */
95
/************************************************************************/
96
97
class GDALRasterBlendAlgorithmStandalone final : public GDALRasterBlendAlgorithm
98
{
99
  public:
100
    GDALRasterBlendAlgorithmStandalone()
101
0
        : GDALRasterBlendAlgorithm(/* standaloneStep = */ true)
102
0
    {
103
0
    }
104
105
    ~GDALRasterBlendAlgorithmStandalone() override;
106
};
107
108
//! @endcond
109
110
#endif /* GDALALG_RASTER_COLOR_MERGE_INCLUDED */