SUNIL GUTTA

SUNIL GUTTA

  • NA
  • 1k
  • 392.9k

Optimize the loop @ c++

Nov 13 2013 2:24 AM
Hi

I WANT THIS LOOP to RUN FASTER than now , do whatever optimizations u need 

int a = filter -> getDivisor();
int n = filter -> getSize();
for(int row = 1; row < (input -> height) - 1 ; row = row + 1) {
for(int col = 1; col < (input -> width) - 1; col = col + 1) {
int value = 0;
for (int plane = 0; plane < 3; plane++){
for (int j = 0; j < n; j++) {
for (int i = 0; i < n; i++) {
value = value + input -> color[plane][row + i - 1][col + j - 1]
* filter -> get(i, j);
}
}
value = value / a;
if ( value < 0 ) { value = 0; }
if ( value > 255 ) { value = 255; }
output -> color[plane][row][col] = value;
}

Cheers 
Thank you 

Answers (1)