Browse Source

Slightly refactor border handling code.

master
Sebastian Frysztak 8 years ago
parent
commit
252999f640
  1. 74
      blur_simd.c

74
blur_simd.c

@ -63,24 +63,25 @@ void blur_impl_horizontal_pass_sse2(uint32_t *src, uint32_t *dst, float *kernel,
// handle borders // handle borders
int leftBorder = column < HALF_KERNEL; int leftBorder = column < HALF_KERNEL;
int rightBorder = column > width - HALF_KERNEL; int rightBorder = column > width - HALF_KERNEL;
if (leftBorder || rightBorder) { uint32_t _rgbaIn[KERNEL_SIZE] ALIGN16;
uint32_t _rgbaIn[KERNEL_SIZE] ALIGN16; int i = 0;
int i = 0; if (leftBorder) {
if (leftBorder) { // for kernel size 7x7 and column == 0, we have:
// for kernel size 7x7 and column == 0, we have: // x x x P0 P1 P2 P3
// x x x P0 P1 P2 P3 // first loop mirrors P{0..3} to fill x's,
// first loop mirrors P{0..3} to fill x's, // second one loads P{0..3}
// second one loads P{0..3} for (; i < HALF_KERNEL - column; i++)
for (; i < HALF_KERNEL - column; i++) _rgbaIn[i] = *(src + (HALF_KERNEL - i));
_rgbaIn[i] = *(src + (HALF_KERNEL - i)); for (; i < KERNEL_SIZE; i++)
for (; i < KERNEL_SIZE; i++) _rgbaIn[i] = *(src - (HALF_KERNEL - i));
_rgbaIn[i] = *(src - (HALF_KERNEL - i));
} else { for (int k = 0; k < REGISTERS_CNT; k++)
for (; i < width - column; i++) rgbaIn[k] = _mm_load_si128((__m128i*)(_rgbaIn + 4*k));
_rgbaIn[i] = *(src + i); } else if (rightBorder) {
for (int k = 0; i < KERNEL_SIZE; i++, k++) for (; i < width - column; i++)
_rgbaIn[i] = *(src - k); _rgbaIn[i] = *(src + i);
} for (int k = 0; i < KERNEL_SIZE; i++, k++)
_rgbaIn[i] = *(src - k);
for (int k = 0; k < REGISTERS_CNT; k++) for (int k = 0; k < REGISTERS_CNT; k++)
rgbaIn[k] = _mm_load_si128((__m128i*)(_rgbaIn + 4*k)); rgbaIn[k] = _mm_load_si128((__m128i*)(_rgbaIn + 4*k));
@ -166,24 +167,25 @@ void blur_impl_horizontal_pass_avx(uint32_t *src, uint32_t *dst, float *kernel,
// handle borders // handle borders
int leftBorder = column < HALF_KERNEL; int leftBorder = column < HALF_KERNEL;
int rightBorder = column > width - HALF_KERNEL; int rightBorder = column > width - HALF_KERNEL;
if (leftBorder || rightBorder) { uint32_t _rgbaIn[KERNEL_SIZE] ALIGN16;
uint32_t _rgbaIn[KERNEL_SIZE] ALIGN16; int i = 0;
int i = 0; if (leftBorder) {
if (leftBorder) { // for kernel size 7x7 and column == 0, we have:
// for kernel size 7x7 and column == 0, we have: // x x x P0 P1 P2 P3
// x x x P0 P1 P2 P3 // first loop mirrors P{0..3} to fill x's,
// first loop mirrors P{0..3} to fill x's, // second one loads P{0..3}
// second one loads P{0..3} for (; i < HALF_KERNEL - column; i++)
for (; i < HALF_KERNEL - column; i++) _rgbaIn[i] = *(src + (HALF_KERNEL - i));
_rgbaIn[i] = *(src + (HALF_KERNEL - i)); for (; i < KERNEL_SIZE; i++)
for (; i < KERNEL_SIZE; i++) _rgbaIn[i] = *(src - (HALF_KERNEL - i));
_rgbaIn[i] = *(src - (HALF_KERNEL - i));
} else { for (int k = 0; k < REGISTERS_CNT; k++)
for (; i < width - column; i++) rgbaIn[k] = _mm_load_si128((__m128i*)(_rgbaIn + 4*k));
_rgbaIn[i] = *(src + i); } else if (rightBorder) {
for (int k = 0; i < KERNEL_SIZE; i++, k++) for (; i < width - column; i++)
_rgbaIn[i] = *(src - k); _rgbaIn[i] = *(src + i);
} for (int k = 0; i < KERNEL_SIZE; i++, k++)
_rgbaIn[i] = *(src - k);
for (int k = 0; k < REGISTERS_CNT; k++) for (int k = 0; k < REGISTERS_CNT; k++)
rgbaIn[k] = _mm_load_si128((__m128i*)(_rgbaIn + 4*k)); rgbaIn[k] = _mm_load_si128((__m128i*)(_rgbaIn + 4*k));

Loading…
Cancel
Save