array2D: use size_t

This commit is contained in:
Ingo Weyrich 2020-07-30 14:56:26 +02:00
parent e77dac43d5
commit 584343fb36
2 changed files with 25 additions and 24 deletions

View File

@ -67,10 +67,10 @@ class array2D :
{ {
private: private:
ssize_t width, height; size_t width, height;
T** rows; T** rows;
T* data; T* data;
void ar_realloc(ssize_t w, ssize_t h, int offset = 0) void ar_realloc(size_t w, size_t h, int offset = 0)
{ {
if (rows && (h > height || 4 * h < height)) { if (rows && (h > height || 4 * h < height)) {
delete[] rows; delete[] rows;
@ -92,7 +92,7 @@ private:
data = new T[height * width + offset]; data = new T[height * width + offset];
} }
for (ssize_t i = 0; i < height; i++) { for (size_t i = 0; i < height; i++) {
rows[i] = data + offset + width * i; rows[i] = data + offset + width * i;
} }
} }
@ -105,13 +105,13 @@ public:
{ } { }
// creator type1 // creator type1
array2D(int w, int h, unsigned int flags = 0) : array2D(size_t w, size_t h, unsigned int flags = 0) :
width(w), height(h) width(w), height(h)
{ {
data = new T[height * width]; data = new T[height * width];
rows = new T*[height]; rows = new T*[height];
for (ssize_t i = 0; i < height; ++i) { for (size_t i = 0; i < height; ++i) {
rows[i] = data + i * width; rows[i] = data + i * width;
} }
@ -121,7 +121,7 @@ public:
} }
// creator type 2 // creator type 2
array2D(int w, int h, T ** source, unsigned int flags = 0) : array2D(size_t w, size_t h, T ** source, unsigned int flags = 0) :
width(w), height(h) width(w), height(h)
{ {
const bool owner = !(flags & ARRAY2D_BYREFERENCE); const bool owner = !(flags & ARRAY2D_BYREFERENCE);
@ -133,10 +133,10 @@ public:
rows = new T*[height]; rows = new T*[height];
for (ssize_t i = 0; i < height; ++i) { for (size_t i = 0; i < height; ++i) {
if (owner) { if (owner) {
rows[i] = data + i * width; rows[i] = data + i * width;
for (ssize_t j = 0; j < width; ++j) { for (size_t j = 0; j < width; ++j) {
rows[i][j] = source[i][j]; rows[i][j] = source[i][j];
} }
} else { } else {
@ -157,7 +157,7 @@ public:
#ifdef _OPENMP #ifdef _OPENMP
#pragma omp parallel for if(multiThread) #pragma omp parallel for if(multiThread)
#endif #endif
for (ssize_t i = 0; i < width * height; ++i) { for (size_t i = 0; i < width * height; ++i) {
data[i] = val; data[i] = val;
} }
} }
@ -172,13 +172,13 @@ public:
} }
// use with indices // use with indices
T * operator[](int index) T * operator[](size_t index)
{ {
assert((index >= 0) && (index < height)); assert((index >= 0) && (index < height));
return rows[index]; return rows[index];
} }
const T * operator[](int index) const const T * operator[](size_t index) const
{ {
assert((index >= 0) && (index < height)); assert((index >= 0) && (index < height));
return rows[index]; return rows[index];
@ -212,7 +212,7 @@ public:
// useful within init of parent object // useful within init of parent object
// or use as resize of 2D array // or use as resize of 2D array
void operator()(int w, int h, unsigned int flags = 0, int offset = 0) void operator()(size_t w, size_t h, unsigned int flags = 0, int offset = 0)
{ {
ar_realloc(w, h, offset); ar_realloc(w, h, offset);
@ -221,11 +221,11 @@ public:
} }
} }
int getWidth() const size_t getWidth() const
{ {
return width; return width;
} }
int getHeight() const size_t getHeight() const
{ {
return height; return height;
} }
@ -243,7 +243,7 @@ private:
array2D<T> list[num]; array2D<T> list[num];
public: public:
multi_array2D(int width, int height, int flags = 0, int offset = 0) multi_array2D(size_t width, size_t height, int flags = 0, int offset = 0)
{ {
for (size_t i = 0; i < num; ++i) { for (size_t i = 0; i < num; ++i) {
list[i](width, height, flags, (i + 1) * offset); list[i](width, height, flags, (i + 1) * offset);

View File

@ -146,8 +146,8 @@ void guidedFilter(const array2D<float> &guide, const array2D<float> &src, array2
#ifdef _OPENMP #ifdef _OPENMP
# pragma omp parallel for if (multithread) # pragma omp parallel for if (multithread)
#endif #endif
for (int y = 0; y < s.getHeight(); ++y) { for (size_t y = 0; y < s.getHeight(); ++y) {
for (int x = 0; x < s.getWidth(); ++x) { for (size_t x = 0; x < s.getWidth(); ++x) {
d[y][x] = s[y][x]; d[y][x] = s[y][x];
} }
} }
@ -164,9 +164,10 @@ void guidedFilter(const array2D<float> &guide, const array2D<float> &src, array2
const auto f_mean = const auto f_mean =
[multithread](array2D<float> &d, array2D<float> &s, int rad) -> void [multithread](array2D<float> &d, array2D<float> &s, int rad) -> void
{ {
rad = LIM(rad, 0, (min(s.getWidth(), s.getHeight()) - 1) / 2 - 1); if (rtengine::min(s.getWidth(), s.getHeight()) > 1) {
// boxblur(s, d, rad, s.getWidth(), s.getHeight(), multithread); rad = LIM<size_t>(rad, 0, (rtengine::min(s.getWidth(), s.getHeight()) - 1) / 2 - 1);
boxblur(static_cast<float**>(s), static_cast<float**>(d), rad, s.getWidth(), s.getHeight(), multithread); boxblur(static_cast<float**>(s), static_cast<float**>(d), rad, s.getWidth(), s.getHeight(), multithread);
}
}; };
array2D<float> I1(w, h); array2D<float> I1(w, h);
@ -249,8 +250,8 @@ void guidedFilterLog(const array2D<float> &guide, float base, array2D<float> &ch
#ifdef _OPENMP #ifdef _OPENMP
# pragma omp parallel for if (multithread) # pragma omp parallel for if (multithread)
#endif #endif
for (int y = 0; y < chan.getHeight(); ++y) { for (size_t y = 0; y < chan.getHeight(); ++y) {
for (int x = 0; x < chan.getWidth(); ++x) { for (size_t x = 0; x < chan.getWidth(); ++x) {
chan[y][x] = xlin2log(max(chan[y][x], 0.f), base); chan[y][x] = xlin2log(max(chan[y][x], 0.f), base);
} }
} }
@ -260,8 +261,8 @@ void guidedFilterLog(const array2D<float> &guide, float base, array2D<float> &ch
#ifdef _OPENMP #ifdef _OPENMP
# pragma omp parallel for if (multithread) # pragma omp parallel for if (multithread)
#endif #endif
for (int y = 0; y < chan.getHeight(); ++y) { for (size_t y = 0; y < chan.getHeight(); ++y) {
for (int x = 0; x < chan.getWidth(); ++x) { for (size_t x = 0; x < chan.getWidth(); ++x) {
chan[y][x] = xlog2lin(max(chan[y][x], 0.f), base); chan[y][x] = xlog2lin(max(chan[y][x], 0.f), base);
} }
} }