Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize p_box3x3_f32 function #149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 39 additions & 23 deletions src/image/p_box3x3.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,51 @@
void p_box3x3_f32(const float *x, float *r, int rows, int cols)
{

int ia, ja;
float E;
int i, j;
float sum;
const float *px;
float *pr;

px = x;
pr = r;
// Initialize the output pointer to the (-1, 0) coordinate
pr = r - cols + 2;

for (ia = 1; ia <= (rows - 2); ia++) {
for (ja = 1; ja <= (cols - 2); ja++) {
E = 0;
E += (*px++);
E += (*px++);
E += (*px++);
px += cols - 3;
E += (*px++);
E += (*px++);
E += (*px++);
px += cols - 3;
E += (*px++);
E += (*px++);
E += (*px++);
px += cols - 3;
*pr = E * M_DIV9;
px += 1 - 3 * cols; // advance mask matrix in one column.
for (i = 0; i < rows; i++) {
// The first sum is calculated directly.
sum = (*px) + (*(px+1)) + (*(px+2));
if (i >= 2) {
// The first two input rows do not correspond to the bottom of any
// pixel filter, so skip this logic for those rows.
*(pr-cols+2) = (*(pr-cols+2) + sum) * M_DIV9;
}
if (i != 0 && i != rows-1) {
// The first and last input rows do not correspond to the middle
// of any pixel filter, so skip this logic for those rows.
*pr += sum;
}
if (i < rows - 2) {
// The last two input rows do not correspond to the top of any
// pixel filter, so skip this logic for those rows.
*(pr+cols-2) = sum;
}
pr++;
for (j = 3; j < cols; j++) {
// All subsequent sums (in the same row) are calculated by
// removing the leftmost value, and adding the value to the
// immediate right of the currently included values.
sum += (*(px+3)) - (*px);
if (i >= 2) {
*(pr-cols+2) = (*(pr-cols+2) + sum) * M_DIV9;
}
if (i != 0 && i != rows-1) {
*pr += sum;
}
if (i < rows - 2) {
*(pr+cols-2) = sum;
}
px++;
pr++;
}
px = px + 2; // advance pointer to the beginning of next row.
px += 3; // Advance input pointer to beginning of next row.
}

return;
}