Speedup and reduced memory usage for Colour Propagation

This commit is contained in:
heckflosse
2015-10-10 01:05:08 +02:00
parent 9dc786f0ea
commit b1dd9dd59a
3 changed files with 477 additions and 324 deletions

View File

@@ -23,7 +23,7 @@
* Usage: * Usage:
* *
* array2D<type> name (X-size,Y-size); * array2D<type> name (X-size,Y-size);
* array2D<type> name (X-size,Y-size type ** data); * array2D<type> name (X-size,Y-size,type ** data);
* *
* creates an array which is valid within the normal C/C++ scope "{ ... }" * creates an array which is valid within the normal C/C++ scope "{ ... }"
* *
@@ -75,7 +75,7 @@ private:
T ** ptr; T ** ptr;
T * data; T * data;
bool lock; // useful lock to ensure data is not changed anymore. bool lock; // useful lock to ensure data is not changed anymore.
void ar_realloc(int w, int h) void ar_realloc(int w, int h, int offset = 0)
{ {
if ((ptr) && ((h > y) || (4 * h < y))) { if ((ptr) && ((h > y) || (4 * h < y))) {
delete[] ptr; delete[] ptr;
@@ -92,14 +92,14 @@ private:
} }
if (data == NULL) { if (data == NULL) {
data = new T[h * w]; data = new T[h * w + offset];
} }
x = w; x = w;
y = h; y = h;
for (int i = 0; i < h; i++) { for (int i = 0; i < h; i++) {
ptr[i] = data + w * i; ptr[i] = data + offset + w * i;
} }
owner = 1; owner = 1;
@@ -184,6 +184,19 @@ public:
} }
} }
void free()
{
if ((owner) && (data)) {
delete[] data;
data = NULL;
}
if (ptr) {
delete [] ptr;
ptr = NULL;
}
}
// use with indices // use with indices
T * operator[](int index) T * operator[](int index)
{ {
@@ -207,7 +220,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 flgs = 0) void operator()(int w, int h, unsigned int flgs = 0, int offset = 0)
{ {
flags = flgs; flags = flgs;
@@ -223,10 +236,10 @@ public:
lock = flags & ARRAY2D_LOCK_DATA; lock = flags & ARRAY2D_LOCK_DATA;
ar_realloc(w, h); ar_realloc(w, h, offset);
if (flags & ARRAY2D_CLEAR_DATA) { if (flags & ARRAY2D_CLEAR_DATA) {
memset(data, 0, w * h * sizeof(T)); memset(data + offset, 0, w * h * sizeof(T));
} }
} }
@@ -298,10 +311,10 @@ private:
array2D<T> list[num]; array2D<T> list[num];
public: public:
multi_array2D(int x, int y, int flags = 0) multi_array2D(int x, int y, int flags = 0, int offset = 0)
{ {
for (size_t i = 0; i < num; i++) { for (size_t i = 0; i < num; i++) {
list[i](x, y, flags); list[i](x, y, flags, (i + 1) * offset);
} }
} }
@@ -312,11 +325,7 @@ public:
array2D<T> & operator[](int index) array2D<T> & operator[](int index)
{ {
if (static_cast<size_t>(index) >= num) { assert(static_cast<size_t>(index) < num);
printf("index %0u is out of range[0..%0lu]", index, num - 1);
raise( SIGSEGV);
}
return list[index]; return list[index];
} }
}; };

File diff suppressed because it is too large Load Diff

View File

@@ -224,8 +224,8 @@ public:
} }
static void inverse33 (const double (*coeff)[3], double (*icoeff)[3]); static void inverse33 (const double (*coeff)[3], double (*icoeff)[3]);
void boxblur2(float** src, float** dst, int H, int W, int box ); void boxblur2(float** src, float** dst, float** temp, int H, int W, int box );
void boxblur_resamp(float **src, float **dst, int H, int W, int box, int samp ); void boxblur_resamp(float **src, float **dst, float** temp, int H, int W, int box, int samp );
//void boxblur_resamp(float **red, float **green, float **blue, int H, int W, float thresh[3], float max[3], //void boxblur_resamp(float **red, float **green, float **blue, int H, int W, float thresh[3], float max[3],
// multi_array2D<float,3> & hfsize, multi_array2D<float,3> & hilite, int box ); // multi_array2D<float,3> & hfsize, multi_array2D<float,3> & hilite, int box );