Coverage Report

Created: 2025-06-09 08:44

/src/gdal/frmts/pcidsk/sdk/blockdir/blocktiledir.cpp
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Purpose:  Block directory API.
4
 *
5
 ******************************************************************************
6
 * Copyright (c) 2011
7
 * PCI Geomatics, 90 Allstate Parkway, Markham, Ontario, Canada.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 ****************************************************************************/
11
12
#include "blockdir/blocktiledir.h"
13
#include "blockdir/blocktilelayer.h"
14
#include "blockdir/blockfile.h"
15
#include "core/pcidsk_utils.h"
16
#include <cassert>
17
18
using namespace PCIDSK;
19
20
/************************************************************************/
21
/*                              BlockTileDir()                          */
22
/************************************************************************/
23
24
/**
25
 * Constructor.
26
 *
27
 * @param poFile The associated file object.
28
 * @param nSegment The segment of the block directory.
29
 */
30
BlockTileDir::BlockTileDir(BlockFile * poFile, uint16 nSegment)
31
87
    : BlockDir(poFile, nSegment)
32
87
{
33
87
}
34
35
/************************************************************************/
36
/*                              BlockTileDir()                          */
37
/************************************************************************/
38
39
/**
40
 * Constructor.
41
 *
42
 * @param poFile The associated file object.
43
 * @param nSegment The segment of the block directory.
44
 * @param nVersion The version of the block directory.
45
 */
46
BlockTileDir::BlockTileDir(BlockFile * poFile, uint16 nSegment, uint16 nVersion)
47
0
    : BlockDir(poFile, nSegment, nVersion)
48
0
{
49
0
}
50
51
/************************************************************************/
52
/*                             ~BlockTileDir()                          */
53
/************************************************************************/
54
55
/**
56
 * Destructor.
57
 */
58
BlockTileDir::~BlockTileDir(void)
59
87
{
60
87
    assert(moLayerInfoList.size() == moTileLayerInfoList.size());
61
62
87
    for (auto poIter : moLayerInfoList)
63
133
        delete poIter;
64
65
87
    for (auto poIter : moTileLayerInfoList)
66
133
        delete poIter;
67
87
}
68
69
/************************************************************************/
70
/*                              GetTileLayer()                          */
71
/************************************************************************/
72
73
/**
74
 * Gets the block tile layer at the specified index.
75
 *
76
 * @param iLayer The index of the block tile layer.
77
 *
78
 * @return The block tile layer at the specified index.
79
 */
80
BlockTileLayer * BlockTileDir::GetTileLayer(uint32 iLayer)
81
65
{
82
65
    return dynamic_cast<BlockTileLayer *>(GetLayer(iLayer));
83
65
}
84
85
/************************************************************************/
86
/*                                                                      */
87
/************************************************************************/
88
89
/**
90
 * Gets the number of new blocks to create.
91
 *
92
 * @return The number of new blocks to create.
93
 */
94
uint32 BlockTileDir::GetNewBlockCount(void) const
95
0
{
96
0
    return (uint32) ((unsigned long long)(mpoFile->GetImageFileSize() / GetBlockSize()) * 0.01);
97
0
}
98
99
/************************************************************************/
100
/*                             SwapBlockLayer()                         */
101
/************************************************************************/
102
103
/**
104
 * Swaps the specified block layer info.
105
 *
106
 * @param psBlockLayer The block layer info to swap.
107
 */
108
void BlockTileDir::SwapBlockLayer(BlockLayerInfo * psBlockLayer)
109
33
{
110
33
    if (!mbNeedsSwap)
111
33
        return;
112
113
0
    SwapData(&psBlockLayer->nLayerType, 2, 1);
114
0
    SwapData(&psBlockLayer->nStartBlock, 4, 1);
115
0
    SwapData(&psBlockLayer->nBlockCount, 4, 1);
116
0
    SwapData(&psBlockLayer->nLayerSize, 8, 1);
117
0
}
118
119
/************************************************************************/
120
/*                             SwapTileLayer()                          */
121
/************************************************************************/
122
123
/**
124
 * Swaps the specified tile layer info.
125
 *
126
 * @param psTileLayer The tile layer info to swap.
127
 */
128
void BlockTileDir::SwapTileLayer(TileLayerInfo * psTileLayer)
129
76
{
130
76
    if (!mbNeedsSwap)
131
76
        return;
132
133
0
    SwapData(&psTileLayer->nXSize, 4, 1);
134
0
    SwapData(&psTileLayer->nYSize, 4, 1);
135
0
    SwapData(&psTileLayer->nTileXSize, 4, 1);
136
0
    SwapData(&psTileLayer->nTileYSize, 4, 1);
137
0
    SwapData(&psTileLayer->bNoDataValid, 2, 1);
138
0
    SwapData(&psTileLayer->dfNoDataValue, 8, 1);
139
0
}
140
141
/************************************************************************/
142
/*                               SwapBlock()                            */
143
/************************************************************************/
144
145
/**
146
 * Swaps the specified block info array.
147
 *
148
 * @param psBlock The block info array to swap.
149
 * @param nCount The number of block info.
150
 */
151
void BlockTileDir::SwapBlock(BlockInfo * psBlock, size_t nCount)
152
9
{
153
9
    if (!mbNeedsSwap)
154
9
        return;
155
156
0
    for (BlockInfo * psEnd = psBlock + nCount;
157
0
         psBlock < psEnd; psBlock++)
158
0
    {
159
0
        SwapData(&psBlock->nSegment, 2, 1);
160
0
        SwapData(&psBlock->nStartBlock, 4, 1);
161
0
    }
162
0
}