Created
October 11, 2012 08:04
-
-
Save inspirit/3870894 to your computer and use it in GitHub Desktop.
Const time box blur (no scale version)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void box_blur_noscale(const uint8_t* input, int32_t* out, const int w, const int h, int hwin) | |
{ | |
const int win = 2*hwin+1; | |
int *_buf = (int*)alloca((w*win+w) * sizeof(int)); | |
int* sums = _buf + w*win; | |
int* next_row = _buf; | |
int* oldest_row = _buf; | |
int i, j; | |
memset(sums, 0, w*sizeof(int)); | |
int* output = out + hwin*w - hwin; | |
for (i=0; i<h; i++) | |
{ | |
int hsum = 0; | |
const uint8_t* back = input; | |
for (j = 0; j < win-1; j++) hsum += input[j]; | |
for (; j < w; j++) | |
{ | |
hsum += input[j]; | |
next_row[j] = hsum; | |
sums[j] += hsum; | |
hsum -= *(back++); | |
} | |
if (i >= win-1) | |
{ | |
for(j = win-1; j < w; j++) | |
{ | |
hsum = sums[j]; | |
output[j] = hsum; // mult with 1/(win*win) if required | |
sums[j] = hsum - oldest_row[j]; | |
} | |
output += w; | |
oldest_row += w; | |
if (oldest_row == _buf + w*win) oldest_row = _buf; | |
} | |
input += w; | |
next_row += w; | |
if (next_row == _buf + w*win) next_row = _buf; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment