| 13 | |
| 14 | template <typename T, size_t ch> |
| 15 | void flip( |
| 16 | const T* __restrict src, T* __restrict dst, const size_t rows, |
| 17 | const size_t cols, const size_t src_step, const size_t dst_step, bool vertical, |
| 18 | bool horizontal) { |
| 19 | for (size_t sr = 0; sr < rows; ++sr) { |
| 20 | const T* sptr = src + sr * src_step; |
| 21 | size_t dr = (vertical ? rows - sr - 1 : sr); |
| 22 | T* dptr = dst + dr * dst_step; |
| 23 | if (!horizontal) { |
| 24 | memcpy(dptr, sptr, sizeof(T) * cols * ch); |
| 25 | } else { |
| 26 | size_t sc = 0; |
| 27 | size_t dc = cols * ch; |
| 28 | for (; sc + 8 * ch <= cols * ch; sc += 8 * ch, dc -= 8 * ch) { |
| 29 | rep(c, ch) dptr[dc - 1 * ch + c] = sptr[sc + 0 * ch + c]; |
| 30 | rep(c, ch) dptr[dc - 2 * ch + c] = sptr[sc + 1 * ch + c]; |
| 31 | rep(c, ch) dptr[dc - 3 * ch + c] = sptr[sc + 2 * ch + c]; |
| 32 | rep(c, ch) dptr[dc - 4 * ch + c] = sptr[sc + 3 * ch + c]; |
| 33 | rep(c, ch) dptr[dc - 5 * ch + c] = sptr[sc + 4 * ch + c]; |
| 34 | rep(c, ch) dptr[dc - 6 * ch + c] = sptr[sc + 5 * ch + c]; |
| 35 | rep(c, ch) dptr[dc - 7 * ch + c] = sptr[sc + 6 * ch + c]; |
| 36 | rep(c, ch) dptr[dc - 8 * ch + c] = sptr[sc + 7 * ch + c]; |
| 37 | } |
| 38 | for (; sc < cols * ch; sc += ch, dc -= ch) { |
| 39 | rep(c, ch) dptr[dc - ch + c] = sptr[sc + c]; |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | } // namespace flip_internal |
| 46 | |