Coverage Report

Created: 2026-02-14 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/alg/viewshed/combiner.cpp
Line
Count
Source
1
/******************************************************************************
2
 * (c) 2024 info@hobu.co
3
 *
4
 * SPDX-License-Identifier: MIT
5
 ****************************************************************************/
6
7
#include "combiner.h"
8
#include "util.h"
9
10
namespace gdal
11
{
12
namespace viewshed
13
{
14
15
/// Read viewshed executor output and sum it up in our owned memory raster.
16
void Combiner::run()
17
0
{
18
0
    DatasetPtr pTempDataset;
19
20
0
    while (m_inputQueue.pop(pTempDataset))
21
0
    {
22
0
        if (!m_dataset)
23
0
            m_dataset = std::move(pTempDataset);
24
0
        else
25
0
            sum(std::move(pTempDataset));
26
0
    }
27
    // Queue remaining summed rasters.
28
0
    queueOutputBuffer();
29
0
}
30
31
/// Add the values of the source dataset to those of the owned dataset.
32
/// @param src  Source dataset.
33
void Combiner::sum(DatasetPtr src)
34
0
{
35
0
    if (!m_dataset)
36
0
    {
37
0
        m_dataset = std::move(src);
38
0
        return;
39
0
    }
40
0
    size_t size = bandSize(*m_dataset->GetRasterBand(1));
41
42
0
    uint8_t *dstP =
43
0
        static_cast<uint8_t *>(m_dataset->GetInternalHandle("MEMORY1"));
44
0
    uint8_t *srcP = static_cast<uint8_t *>(src->GetInternalHandle("MEMORY1"));
45
0
    for (size_t i = 0; i < size; ++i)
46
0
        *dstP++ += *srcP++;
47
    // If we've seen 255 inputs, queue our raster for output and rollup since we might overflow
48
    // otherwise.
49
0
    if (++m_count == 255)
50
0
        queueOutputBuffer();
51
0
}
52
53
/// Queue the owned buffer as for output.
54
void Combiner::queueOutputBuffer()
55
0
{
56
0
    if (m_dataset)
57
0
        m_outputQueue.push(std::move(m_dataset));
58
0
    m_count = 0;
59
0
}
60
61
}  // namespace viewshed
62
}  // namespace gdal