diff --git a/modules/imgproc/src/drawing.cpp b/modules/imgproc/src/drawing.cpp index e5075f62c5..da34be2b9b 100644 --- a/modules/imgproc/src/drawing.cpp +++ b/modules/imgproc/src/drawing.cpp @@ -1071,275 +1071,6 @@ EllipseEx( Mat& img, Point2l center, Size2l axes, * Polygons filling * \****************************************************************************************/ -//Endian macros stolen from SQLITE -#if (defined(i386) || defined(__i386__) || defined(_M_IX86) || \ - defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \ - defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \ - defined(__arm__) || defined(__aarch64__) || defined(_LITTLE_ENDIAN) || defined(LITTLE_ENDIAN)) -# define OPENCV_BYTEORDER 1234 -# define OPENCV_BIGENDIAN 0 -# define OPENCV_LITTLEENDIAN 1 -#elif (defined(sparc) || defined(__ppc__) || defined(_BIG_ENDIAN) || defined(BIG_ENDIAN)) -# define OPENCV_BYTEORDER 4321 -# define OPENCV_BIGENDIAN 1 -# define OPENCV_LITTLEENDIAN 0 -#endif - -#if !defined(OPENCV_BYTEORDER) -# define OPENCV_BYTEORDER 0 -static const int opencvOne = 1; -# define OPENCV_BIGENDIAN (*((const char *)(&opencvOne))==0) -# define OPENCV_LITTLEENDIAN (*((const char *)(&opencvOne))==1) -#endif - -# if defined(_MSC_VER) && _MSC_VER>=1400 -# if !defined(_WIN32_WCE) -# include -# pragma intrinsic(_byteswap_ushort) -# pragma intrinsic(_byteswap_ulong) -# pragma intrinsic(_byteswap_uint64) -# pragma intrinsic(_ReadWriteBarrier) -# else -# include -# endif -# endif - -static inline uint16_t opencvLittleToHost16(const uchar* p){ -#if OPENCV_BYTEORDER==1234 - uint16_t x; - memcpy(&x,p,sizeof(x)); - return x; -#elif OPENCV_BYTEORDER==4321 && defined(__GNUC__) - uint16_t x; - memcpy(&x,p,sizeof(x)); - return (p[0]<<8) | (p[1]>>8); -#elif OPENCV_BYTEORDER==4321 && defined(_MSC_VER) && _MSC_VER>=1300 - uint16_t x; - memcpy(&x,p,sizeof(x)); - return _byteswap_ushort(x); -#elif OPENCV_LITTLEENDIAN - return x; -#else - return (p[0]<<8) | (p[1]>>8); -#endif -} - -/* -static inline uint16_t opencvLittleToHost16(uint16_t x){ -#if OPENCV_LITTLEENDIAN - return x; -#else - return opencvLittleToHost16((const uchar*)&x); -#endif -} -*/ - -static inline uint32_t opencvLittleToHost32(const uchar* p){ -#if OPENCV_BYTEORDER==1234 - uint32_t x; - memcpy(&x,p,sizeof(x)); - return x; -#elif OPENCV_BYTEORDER==4321 && defined(__GNUC__) - uint32_t x; - memcpy(&x,p,sizeof(x)); - return __builtin_bswap32(x); -#elif OPENCV_BYTEORDER==4321 && defined(_MSC_VER) && _MSC_VER>=1300 - uint32_t x; - memcpy(&x,p,sizeof(x)); - return _byteswap_ulong(x); -#elif OPENCV_LITTLEENDIAN - return x; -#else - return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]; -#endif -} - -static inline uint32_t opencvLittleToHost32(uint32_t x){ -#if OPENCV_LITTLEENDIAN - return x; -#else - return opencvLittleToHost32((const uchar*)&x); -#endif -} - -static inline uint64_t opencvLittleToHost64(const uchar* p){ -#if OPENCV_BYTEORDER==1234 - uint64_t x; - memcpy(&x,p,sizeof(x)); - return x; -#elif OPENCV_BYTEORDER==4321 && defined(__GNUC__) - uint64_t x; - memcpy(&x,p,sizeof(x)); - return __builtin_bswap64(x); -#elif OPENCV_BYTEORDER==4321 && defined(_MSC_VER) && _MSC_VER>=1300 - uint64_t x; - memcpy(&x,p,sizeof(x)); - return _byteswap_uint64(x); -#elif OPENCV_LITTLEENDIAN - return x; -#else - return (p[0]<<56) | (p[1]<<40) | (p[2]<<24) | (p[3]<<8) | (p[4]>>8) | (p[5]>>24) | (p[6]>>40) | (p[7]>>56); -#endif -} - -static inline uint64_t opencvLittleToHost64(uint64_t x){ -#if OPENCV_LITTLEENDIAN - return x; -#else - return opencvLittleToHost64((const uchar*)&x); -#endif -} - -/* helper macros: filling horizontal row */ -#define is_aligned(POINTER, BYTE_COUNT) (((uintptr_t)(const void *)(POINTER)) % (BYTE_COUNT) == 0) - -/*#define ICV_HLINE( ptr, xl, xr, color, pix_size ) \ -{ \ - uchar* hline_ptr = (uchar*)(ptr) + (xl)*(pix_size); \ - uchar* hline_max_ptr = (uchar*)(ptr) + (xr)*(pix_size); \ - \ - for( ; hline_ptr <= hline_max_ptr; hline_ptr += (pix_size))\ - { \ - int hline_j; \ - for( hline_j = 0; hline_j < (pix_size); hline_j++ ) \ - { \ - hline_ptr[hline_j] = ((uchar*)color)[hline_j]; \ - } \ - } \ -}*/ - -/* -template -static inline void icv_hline_impl(uchar* ptr, size_t xl, size_t xr, const uchar* color, unsigned pix_size_) -{ - const unsigned pix_size = pix_size_forced ? pix_size_forced : pix_size_; - - uchar* hline_ptr = ptr + xl*pix_size; - uchar* hline_max_ptr = ptr + xr*pix_size; - - for ( ; hline_ptr <= hline_max_ptr; hline_ptr += pix_size) - { - for (unsigned c = 0; c < pix_size; c++) - { - hline_ptr[c] = color[c]; - } - } -} - -#define ICV_HLINE( ptr, xl, xr, color, pix_size ) \ -{ \ - if (pix_size == 1) \ - icv_hline_impl<1>((uchar*)ptr, (xl), (xr), (const uchar*)color,pix_size); \ - else if (pix_size == 3) \ - icv_hline_impl<3>((uchar*)ptr, (xl), (xr), (const uchar*)color, pix_size); \ - else if (pix_size == 4) \ - icv_hline_impl<4>((uchar*)ptr, (xl), (xr), (const uchar*)color, pix_size); \ - else \ - icv_hline_impl<0>((uchar*)ptr, (xl), (xr), (const uchar*)color, pix_size); \ -} -*/ - -/* -#define ICV_HLINE( ptr, xl, xr, color, pix_size ) \ -if((pix_size) == 1) \ -{ \ - uchar* hline_ptr = (uchar*)(ptr) + (xl); \ - uchar* hline_max_ptr = (uchar*)(ptr) + (xr); \ - uchar hline_c = *(const uchar*)(color); \ - \ - memset(hline_ptr, hline_c, (hline_max_ptr - hline_ptr) + 1); \ -} \ -else if((pix_size) == 3) \ -{ \ - uchar* hline_ptr = (uchar*)(ptr) + (xl)*3; \ - uchar* hline_end = (uchar*)(ptr) + (xr+1)*3; \ - uchar* hbody24_start = std::min(hline_end, (uchar*)(24*(((uintptr_t)(hline_ptr)+23)/24))); \ - uchar* hbody24_end = std::min(hline_end, (uchar*)(24*(((uintptr_t)(hline_end))/24))); \ - uchar* hbody12_start = std::min(hline_end, (uchar*)(12*(((uintptr_t)(hline_ptr)+11)/12))); \ - uchar* hbody12_end = std::min(hline_end, (uchar*)(12*(((uintptr_t)(hline_end))/12))); \ - if (hbody24_start < hbody24_end) \ - { \ - int offset = ((uintptr_t)(hbody24_start-hline_ptr))%3; \ - uint64_t c4[3]; \ - uchar* ptrC4 = reinterpret_cast(&c4); \ - ptrC4[0] = ((uchar*)(color))[(offset++)%3]; \ - ptrC4[1] = ((uchar*)(color))[(offset++)%3]; \ - ptrC4[2] = ((uchar*)(color))[(offset++)%3]; \ - memcpy(&ptrC4[3], &ptrC4[0], 3); \ - memcpy(&ptrC4[6], &ptrC4[0], 6); \ - memcpy(&ptrC4[12], &ptrC4[0], 12); \ - c4[0] = opencvLittleToHost64(c4[0]); \ - c4[1] = opencvLittleToHost64(c4[1]); \ - c4[2] = opencvLittleToHost64(c4[2]); \ - for(offset = 0 ; hline_ptr < hbody24_start; offset = (offset+1)%3)\ - *hline_ptr++ = ((uchar*)(color))[offset]; \ - for(uint64_t* ptr64 = reinterpret_cast(hbody24_start), *ptr64End = reinterpret_cast(hbody24_end) ; ptr64(&c4); \ - ptrC4[0] = ((uchar*)(color))[(offset++)%3]; \ - ptrC4[1] = ((uchar*)(color))[(offset++)%3]; \ - ptrC4[2] = ((uchar*)(color))[(offset++)%3]; \ - memcpy(&ptrC4[3], &ptrC4[0], 3); \ - memcpy(&ptrC4[6], &ptrC4[0], 6); \ - c4[0] = opencvLittleToHost32(c4[0]); \ - c4[1] = opencvLittleToHost32(c4[1]); \ - c4[2] = opencvLittleToHost32(c4[2]); \ - for(offset = 0 ; hline_ptr < hbody12_start; offset = (offset+1)%3)\ - *hline_ptr++ = ((uchar*)(color))[offset]; \ - for(uint32_t* ptr32 = reinterpret_cast(hbody12_start), *ptr32End = reinterpret_cast(hbody12_end) ; ptr32(&c4); - ptrC4[0] = ((uchar*)(color))[(offset++)%3]; - ptrC4[1] = ((uchar*)(color))[(offset++)%3]; - ptrC4[2] = ((uchar*)(color))[(offset++)%3]; - memcpy(&ptrC4[3], &ptrC4[0], 3); - memcpy(&ptrC4[6], &ptrC4[0], 6); - memcpy(&ptrC4[12], &ptrC4[0], 12); - c4[0] = opencvLittleToHost64(c4[0]); - c4[1] = opencvLittleToHost64(c4[1]); - c4[2] = opencvLittleToHost64(c4[2]); - for(offset = 0 ; hline_ptr < hbody24_start; offset = (offset+1)%3) - *hline_ptr++ = ((uchar*)(color))[offset]; - for(uint64_t* ptr64 = reinterpret_cast(hbody24_start), *ptr64End = reinterpret_cast(hbody24_end) ; ptr64(&c4); - ptrC4[0] = ((uchar*)(color))[(offset++)%3]; - ptrC4[1] = ((uchar*)(color))[(offset++)%3]; - ptrC4[2] = ((uchar*)(color))[(offset++)%3]; - memcpy(&ptrC4[3], &ptrC4[0], 3); - memcpy(&ptrC4[6], &ptrC4[0], 6); - c4[0] = opencvLittleToHost32(c4[0]); - c4[1] = opencvLittleToHost32(c4[1]); - c4[2] = opencvLittleToHost32(c4[2]); - for(offset = 0 ; hline_ptr < hbody12_start; offset = (offset+1)%3) - *hline_ptr++ = ((uchar*)(color))[offset]; - for(uint32_t* ptr32 = reinterpret_cast(hbody12_start), *ptr32End = reinterpret_cast(hbody12_end) ; ptr32(&c4); - ptrC4[0] = ((uchar*)(color))[(offset++)%6]; - ptrC4[1] = ((uchar*)(color))[(offset++)%6]; - ptrC4[2] = ((uchar*)(color))[(offset++)%6]; - ptrC4[3] = ((uchar*)(color))[(offset++)%6]; - ptrC4[4] = ((uchar*)(color))[(offset++)%6]; - ptrC4[5] = ((uchar*)(color))[(offset++)%6]; - memcpy(&ptrC4[6], &ptrC4[0], 6); - memcpy(&ptrC4[12], &ptrC4[0], 12); - c4[0] = opencvLittleToHost64(c4[0]); - c4[1] = opencvLittleToHost64(c4[1]); - c4[2] = opencvLittleToHost64(c4[2]); - for(offset = 0 ; hline_ptr < hbody24_start; offset = (offset+1)%6) - *hline_ptr++ = ((uchar*)(color))[offset]; - for(uint64_t* ptr64 = reinterpret_cast(hbody24_start), *ptr64End = reinterpret_cast(hbody24_end) ; ptr64(&c4); - ptrC4[0] = ((uchar*)(color))[(offset++)%6]; - ptrC4[1] = ((uchar*)(color))[(offset++)%6]; - ptrC4[2] = ((uchar*)(color))[(offset++)%6]; - ptrC4[3] = ((uchar*)(color))[(offset++)%6]; - ptrC4[4] = ((uchar*)(color))[(offset++)%6]; - ptrC4[5] = ((uchar*)(color))[(offset++)%6]; - memcpy(&ptrC4[6], &ptrC4[0], 6); - c4[0] = opencvLittleToHost32(c4[0]); - c4[1] = opencvLittleToHost32(c4[1]); - c4[2] = opencvLittleToHost32(c4[2]); - for(offset = 0 ; hline_ptr < hbody12_start; offset = (offset+1)%6) - *hline_ptr++ = ((uchar*)(color))[offset]; - for(uint32_t* ptr32 = reinterpret_cast(hbody12_start), *ptr32End = reinterpret_cast(hbody12_end) ; ptr32(color), pix_size); - else if (pix_size == 1) - ICV_HLINE_1(ptr, xl, xr, reinterpret_cast(color)); - else if (pix_size == 2) - ICV_HLINE_2(ptr, xl, xr, reinterpret_cast(color)); - else if (pix_size == 3) - ICV_HLINE_3(ptr, xl, xr, reinterpret_cast(color)); - else if (pix_size == 4) - ICV_HLINE_4(ptr, xl, xr, reinterpret_cast(color)); - else if (pix_size == 6) - ICV_HLINE_6(ptr, xl, xr, reinterpret_cast(color)); - else if (pix_size == 8) - ICV_HLINE_8(ptr, xl, xr, reinterpret_cast(color)); - //timings do not show relevant improvement when element_size >= 12 - /*else if (pix_size == 12) - ICV_HLINE_12(ptr, xl, xr, reinterpret_cast(color)); - else if (pix_size == 16) - ICV_HLINE_16(ptr, xl, xr, reinterpret_cast(color)); - else if (pix_size == 24) - ICV_HLINE_24(ptr, xl, xr, reinterpret_cast(color)); - else if (pix_size == 32) - ICV_HLINE_32(ptr, xl, xr, reinterpret_cast(color));*/ - else - ICV_HLINE_X(ptr, xl, xr, reinterpret_cast(color), pix_size); + ICV_HLINE_X(ptr, xl, xr, reinterpret_cast(color), pix_size); } //end ICV_HLINE()