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_unscale.cpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  GDAL
4
 * Purpose:  "unscale" 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
#include "gdalalg_raster_unscale.h"
14
15
#include "gdal_priv.h"
16
#include "gdal_utils.h"
17
18
//! @cond Doxygen_Suppress
19
20
#ifndef _
21
#define _(x) (x)
22
#endif
23
24
/************************************************************************/
25
/*       GDALRasterUnscaleAlgorithm::GDALRasterUnscaleAlgorithm()       */
26
/************************************************************************/
27
28
GDALRasterUnscaleAlgorithm::GDALRasterUnscaleAlgorithm(bool standaloneStep)
29
0
    : GDALRasterPipelineStepAlgorithm(NAME, DESCRIPTION, HELP_URL,
30
0
                                      standaloneStep)
31
0
{
32
0
    AddOutputDataTypeArg(&m_type);
33
0
}
34
35
/************************************************************************/
36
/*                GDALRasterUnscaleAlgorithm::RunStep()                 */
37
/************************************************************************/
38
39
bool GDALRasterUnscaleAlgorithm::RunStep(GDALPipelineStepRunContext &)
40
0
{
41
0
    auto poSrcDS = m_inputDataset[0].GetDatasetRef();
42
0
    CPLAssert(poSrcDS);
43
0
    CPLAssert(m_outputDataset.GetName().empty());
44
0
    CPLAssert(!m_outputDataset.GetDatasetRef());
45
46
0
    CPLStringList aosOptions;
47
0
    aosOptions.AddString("-of");
48
0
    aosOptions.AddString("VRT");
49
0
    aosOptions.AddString("-unscale");
50
0
    aosOptions.AddString("-ot");
51
0
    if (!m_type.empty())
52
0
    {
53
0
        aosOptions.AddString(m_type.c_str());
54
0
    }
55
0
    else
56
0
    {
57
0
        const auto eSrcDT = poSrcDS->GetRasterCount() > 0
58
0
                                ? poSrcDS->GetRasterBand(1)->GetRasterDataType()
59
0
                                : GDT_Unknown;
60
0
        if (GDALGetNonComplexDataType(eSrcDT) != GDT_Float64)
61
0
        {
62
0
            aosOptions.AddString(GDALDataTypeIsComplex(eSrcDT) ? "CFloat32"
63
0
                                                               : "Float32");
64
0
        }
65
0
        else
66
0
        {
67
0
            aosOptions.AddString(GDALDataTypeIsComplex(eSrcDT) ? "CFloat64"
68
0
                                                               : "Float64");
69
0
        }
70
0
    }
71
72
0
    GDALTranslateOptions *psOptions =
73
0
        GDALTranslateOptionsNew(aosOptions.List(), nullptr);
74
75
0
    auto poOutDS = std::unique_ptr<GDALDataset>(GDALDataset::FromHandle(
76
0
        GDALTranslate("", GDALDataset::ToHandle(poSrcDS), psOptions, nullptr)));
77
0
    GDALTranslateOptionsFree(psOptions);
78
0
    const bool bRet = poOutDS != nullptr;
79
0
    if (poOutDS)
80
0
    {
81
0
        m_outputDataset.Set(std::move(poOutDS));
82
0
    }
83
84
0
    return bRet;
85
0
}
86
87
0
GDALRasterUnscaleAlgorithmStandalone::~GDALRasterUnscaleAlgorithmStandalone() =
88
    default;
89
90
//! @endcond