Skip to content

Instantly share code, notes, and snippets.

@uploadcare-user
Created September 14, 2017 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uploadcare-user/84374075d857a72ae4e65ec11fe2f3d4 to your computer and use it in GitHub Desktop.
Save uploadcare-user/84374075d857a72ae4e65ec11fe2f3d4 to your computer and use it in GitHub Desktop.
Unfolding loops and branching, optimization 3
for (xx = 0; xx < imOut->xsize; xx++) {
if (imIn->bands == 4) {
// Body, 4-band images
} else if (imIn->bands == 3) {
ss0 = 0.0;
ss1 = 0.0;
ss2 = 0.0;
for (x = (int) xmin; x < (int) xmax; x++) {
ss0 = ss0 + (UINT8) imIn->image[yy][x*4+0] * k[x - (int) xmin];
ss1 = ss1 + (UINT8) imIn->image[yy][x*4+1] * k[x - (int) xmin];
ss2 = ss2 + (UINT8) imIn->image[yy][x*4+2] * k[x - (int) xmin];
}
ss0 = ss0 * ww + 0.5;
ss1 = ss1 * ww + 0.5;
ss2 = ss2 * ww + 0.5;
imOut->image[yy][xx*4+0] = clip8(ss0);
imOut->image[yy][xx*4+1] = clip8(ss1);
imOut->image[yy][xx*4+2] = clip8(ss2);
} else {
// Body, 1- and 2-band images
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment