diff --git a/api/reduce.cpp b/api/reduce.cpp index fbe3d427e0..4bca02847b 100644 --- a/api/reduce.cpp +++ b/api/reduce.cpp @@ -11,6 +11,7 @@ REDUCED_ARRAY::REDUCED_ARRAY() { rdata = 0; ftemp = 0; itemp = 0; + reduce_method = REDUCE_METHOD_AVG; } REDUCED_ARRAY::~REDUCED_ARRAY() { @@ -54,6 +55,7 @@ void REDUCED_ARRAY::init(int sx, int sy) { last_ry = 0; last_ry_count = 0; rdata_max = 0; + rdata_min = (float)1e20; } bool REDUCED_ARRAY::full() { @@ -86,12 +88,27 @@ void REDUCED_ARRAY::reduce_source_row(float* in, float* out) { memset(itemp, 0, rdimx*sizeof(int)); for (i=0; i 1) out[i] /= itemp[i]; + switch (reduce_method) { + case REDUCE_METHOD_AVG: + out[ri] += in[i]; + itemp[ri]++; + break; + case REDUCE_METHOD_SUM: + out[ri] += in[i]; + break; + case REDUCE_METHOD_MIN: + out[ri] = min(out[ri],in[i]); + break; + case REDUCE_METHOD_MAX: + out[ri] = max(out[ri],in[i]); + break; + } } + if (reduce_method==REDUCE_METHOD_AVG) { + for (i=0; i 1) out[i] /= itemp[i]; + } + } } void REDUCED_ARRAY::update_max(int row) { @@ -100,6 +117,7 @@ void REDUCED_ARRAY::update_max(int row) { for (i=0; i rdata_max) rdata_max = p[i]; + if (p[i] < rdata_min) rdata_min = p[i]; } } @@ -183,10 +201,10 @@ void REDUCED_ARRAY::draw_row_quad(int row) { for (i=0; i rdimy @@ -39,6 +46,7 @@ public: float draw_size[3]; float draw_deltax; float draw_deltaz; + int reduce_method; // Which method to use for data row reduction double hue0; double dhue;