|
| 1 | +// This file is part of OpenCV project. |
| 2 | +// It is subject to the license terms in the LICENSE file found in the top-level directory |
| 3 | +// of this distribution and at http://opencv.org/license.html. |
| 4 | + |
| 5 | +#ifndef OPENCV_HAL_RVV_071_HPP_INCLUDED |
| 6 | +#define OPENCV_HAL_RVV_071_HPP_INCLUDED |
| 7 | + |
| 8 | +#include <limits> |
| 9 | + |
| 10 | +namespace cv { namespace cv_hal_rvv { |
| 11 | + |
| 12 | +#undef cv_hal_cvtBGRtoBGR |
| 13 | +#define cv_hal_cvtBGRtoBGR cv::cv_hal_rvv::cvtBGRtoBGR |
| 14 | + |
| 15 | +static const unsigned char index_array_32 [32] |
| 16 | + { 2, 1, 0, 3, 6, 5, 4, 7, 10, 9, 8, 11, 14, 13, 12, 15, 18, 17, 16, 19, 22, 21, 20, 23, 26, 25, 24, 27, 30, 29, 28, 31 }; |
| 17 | + |
| 18 | +static const unsigned char index_array_24 [24] |
| 19 | + { 2, 1, 0, 5, 4, 3, 8, 7, 6, 11, 10, 9, 14, 13, 12, 17, 16, 15, 20, 19, 18, 23, 22, 21 }; |
| 20 | + |
| 21 | +static void vBGRtoBGR(const unsigned char* src, unsigned char * dst, const unsigned char * index, int n, int scn, int dcn, int vsize_pixels, const int vsize) |
| 22 | +{ |
| 23 | + vuint8m2_t vec_index = vle8_v_u8m2(index, vsize); |
| 24 | + |
| 25 | + int i = 0; |
| 26 | + |
| 27 | + for ( ; i <= n-vsize; i += vsize_pixels, src += vsize, dst += vsize) |
| 28 | + { |
| 29 | + vuint8m2_t vec_src = vle8_v_u8m2(src, vsize); |
| 30 | + vuint8m2_t vec_dst = vrgather_vv_u8m2(vec_src, vec_index, vsize); |
| 31 | + vse8_v_u8m2(dst, vec_dst, vsize); |
| 32 | + } |
| 33 | + |
| 34 | + for ( ; i < n; i++, src += scn, dst += dcn ) |
| 35 | + { |
| 36 | + unsigned char t0 = src[0], t1 = src[1], t2 = src[2]; |
| 37 | + dst[2] = t0; |
| 38 | + dst[1] = t1; |
| 39 | + dst[0] = t2; |
| 40 | + if(dcn == 4) |
| 41 | + { |
| 42 | + unsigned char d = src[3]; |
| 43 | + dst[3] = d; |
| 44 | + } |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +static void sBGRtoBGR(const unsigned char* src, unsigned char * dst, int n, int scn, int dcn, int bi) |
| 49 | +{ |
| 50 | + for (int i = 0; i < n; i++, src += scn, dst += dcn) |
| 51 | + { |
| 52 | + unsigned char t0 = src[0], t1 = src[1], t2 = src[2]; |
| 53 | + dst[bi ] = t0; |
| 54 | + dst[1] = t1; |
| 55 | + dst[bi^2] = t2; |
| 56 | + if(dcn == 4) |
| 57 | + { |
| 58 | + unsigned char d = scn == 4 ? src[3] : std::numeric_limits<unsigned char>::max(); |
| 59 | + dst[3] = d; |
| 60 | + } |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +static int cvtBGRtoBGR(const unsigned char * src_data, size_t src_step, unsigned char * dst_data, size_t dst_step, int width, int height, int depth, int scn, int dcn, bool swapBlue) |
| 65 | +{ |
| 66 | + if (depth != CV_8U) |
| 67 | + { |
| 68 | + return CV_HAL_ERROR_NOT_IMPLEMENTED; |
| 69 | + } |
| 70 | + |
| 71 | + const int blueIdx = swapBlue ? 2 : 0; |
| 72 | + if (scn == dcn) |
| 73 | + { |
| 74 | + if (!swapBlue) |
| 75 | + { |
| 76 | + return CV_HAL_ERROR_NOT_IMPLEMENTED; |
| 77 | + } |
| 78 | + |
| 79 | + const int vsize_pixels = 8; |
| 80 | + |
| 81 | + if (scn == 4) |
| 82 | + { |
| 83 | + for (int i = 0; i < height; i++, src_data += src_step, dst_data += dst_step) |
| 84 | + { |
| 85 | + vBGRtoBGR(src_data, dst_data, index_array_32, width, scn, dcn, vsize_pixels, 32); |
| 86 | + } |
| 87 | + } |
| 88 | + else |
| 89 | + { |
| 90 | + for (int i = 0; i < height; i++, src_data += src_step, dst_data += dst_step) |
| 91 | + { |
| 92 | + vBGRtoBGR(src_data, dst_data, index_array_24, width, scn, dcn, vsize_pixels, 24); |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + else |
| 97 | + { |
| 98 | + for (int i = 0; i < height; i++, src_data += src_step, dst_data += dst_step) |
| 99 | + sBGRtoBGR(src_data, dst_data, width, scn, dcn, blueIdx); |
| 100 | + } |
| 101 | + |
| 102 | + return CV_HAL_ERROR_OK; |
| 103 | +} |
| 104 | + |
| 105 | +}} |
| 106 | + |
| 107 | +#endif |
0 commit comments