GDAL
gdalalg_raster_blend.h
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
19
20/************************************************************************/
21/* CompositionMode */
22/************************************************************************/
23
25enum 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
40std::map<CompositionMode, std::string> CompositionModes();
41
43std::string CompositionModeToString(CompositionMode mode);
44
46std::vector<std::string> CompositionModesIdentifiers();
47
49CompositionMode CompositionModeFromString(const std::string &str);
50
52int MinBandCountForCompositionMode(CompositionMode mode);
53
58int MaxBandCountForCompositionMode(CompositionMode mode);
59
61bool BandCountIsCompatibleWithCompositionMode(int bandCount,
62 CompositionMode mode);
63
64/************************************************************************/
65/* GDALRasterBlendAlgorithm */
66/************************************************************************/
67
68class 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
97class GDALRasterBlendAlgorithmStandalone final : public GDALRasterBlendAlgorithm
98{
99 public:
100 GDALRasterBlendAlgorithmStandalone()
101 : GDALRasterBlendAlgorithm(/* standaloneStep = */ true)
102 {
103 }
104
105 ~GDALRasterBlendAlgorithmStandalone() override;
106};
107
109
110#endif /* GDALALG_RASTER_COLOR_MERGE_INCLUDED */
Value for an argument that points to a GDALDataset.
Definition gdalalgorithm_cpp.h:163