Repository navigation
Expand file tree
/
Copy pathz_offset_data.cc
More file actions
214 lines (187 loc) · 5.67 KB
/
Copy pathz_offset_data.cc
File metadata and controls
214 lines (187 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include "z_offset_data.h"
namespace rsvp
{
ZOffsetData::ZOffsetData(const std::shared_ptr<rsvp::ImageData> &inImg) :
img(inImg)
{
if (inImg != nullptr)
{
const size_t bands = static_cast<size_t>(img->get_bands());
scales.assign(bands, 1.0);
offsets.assign(bands, 0.0);
}
}
ZOffsetData::~ZOffsetData() = default;
void
ZOffsetData::set_offset_and_scale(int band, double _offset, double _scale)
{
if (band < 0)
{
return;
}
if (!has_band(band))
{
// Either the stored image has gained bands since the tables were
// sized, or this is a band it does not have. Only the first grows
// the tables: `band_in_range` takes a band with an entry to be
// one the stored image has, so an entry must never be made for a
// band it does not.
if (band >= get_bands())
{
return;
}
const size_t bands = static_cast<size_t>(get_bands());
scales.resize(bands, 1.0);
offsets.resize(bands, 0.0);
}
offsets[band] = _offset;
scales[band] = _scale;
}
bool ZOffsetData::get_pixel_double(double &value,
const int x,
const int y,
const int band) const
{
double raw_result = 0.0;
if (!img || !band_in_range(band) ||
!img->get_pixel_double(raw_result, x, y, band))
{
return false;
}
value = transform(raw_result, band);
return true;
}
bool ZOffsetData::get_interpolated_pixel_double(double &value,
const double x,
const double y,
const int band) const
{
double raw_result = 0.0;
if (!img || !band_in_range(band) ||
!img->get_interpolated_pixel_double(raw_result, x, y, band))
{
return false;
}
value = transform(raw_result, band);
return true;
}
bool ZOffsetData::get_interpolated_bands_double(double *values,
const int *bands,
const int count,
const double x,
const double y) const
{
if (!img)
{
return false;
}
for (int i = 0; i < count; i++)
{
if (!band_in_range(bands[i]))
{
return false;
}
}
if (!img->get_interpolated_bands_double(values, bands, count, x, y))
{
return false;
}
for (int i = 0; i < count; i++)
{
values[i] = transform(values[i], bands[i]);
}
return true;
}
bool ZOffsetData::get_clamped_pixel_double(double &value,
double &weight,
const double x,
const double y,
const int band) const
{
double raw_result = 0.0;
if (!img || !band_in_range(band) ||
!img->get_clamped_pixel_double(raw_result, weight, x, y, band))
{
return false;
}
value = transform(raw_result, band);
return true;
}
bool ZOffsetData::get_pixel_int(int &value,
const int x,
const int y,
const int band) const
{
int raw_result = 0;
if (!img || !band_in_range(band) ||
!img->get_pixel_int(raw_result, x, y, band))
{
return false;
}
value = round_to_int(transform(raw_result, band));
return true;
}
bool ZOffsetData::get_interpolated_pixel_int(int &value,
const double x,
const double y,
const int band) const
{
int raw_result = 0;
if (!img || !band_in_range(band) ||
!img->get_interpolated_pixel_int(raw_result, x, y, band))
{
return false;
}
value = round_to_int(transform(raw_result, band));
return true;
}
int ZOffsetData::get_bands() const
{
if (img != nullptr)
{
return img->get_bands();
}
else
{
return 0;
}
}
void ZOffsetData::set_alpha_band(int band)
{
ImageData::set_alpha_band(band);
if (img != nullptr)
{
img->set_alpha_band(band);
}
}
int ZOffsetData::get_alpha_band() const
{
if (img != nullptr)
{
return img->get_alpha_band();
}
else
{
return ImageData::get_alpha_band();
}
}
void ZOffsetData::set_interpolating(bool enable)
{
ImageData::set_interpolating(enable);
if (img != nullptr)
{
img->set_interpolating(enable);
}
}
int ZOffsetData::get_interpolating() const
{
if (img != nullptr)
{
return img->get_interpolating();
}
else
{
return ImageData::get_interpolating();
}
}
}