Skip to content

Commit 55ee8b2

Browse files
committed
Merge pull request opencv#8182 from chacha21:drawing_performance
2 parents 0448260 + 7763a86 commit 55ee8b2

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

modules/imgproc/src/drawing.cpp

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
//M*/
4141
#include "precomp.hpp"
4242

43+
#include <stdint.h>
44+
4345
namespace cv
4446
{
4547

@@ -1069,22 +1071,36 @@ EllipseEx( Mat& img, Point2l center, Size2l axes,
10691071
* Polygons filling *
10701072
\****************************************************************************************/
10711073

1072-
/* helper macros: filling horizontal row */
1073-
#define ICV_HLINE( ptr, xl, xr, color, pix_size ) \
1074-
{ \
1075-
uchar* hline_ptr = (uchar*)(ptr) + (xl)*(pix_size); \
1076-
uchar* hline_max_ptr = (uchar*)(ptr) + (xr)*(pix_size); \
1077-
\
1078-
for( ; hline_ptr <= hline_max_ptr; hline_ptr += (pix_size))\
1079-
{ \
1080-
int hline_j; \
1081-
for( hline_j = 0; hline_j < (pix_size); hline_j++ ) \
1082-
{ \
1083-
hline_ptr[hline_j] = ((uchar*)color)[hline_j]; \
1084-
} \
1085-
} \
1074+
static inline void ICV_HLINE_X(uchar* ptr, int xl, int xr, const uchar* color, int pix_size)
1075+
{
1076+
uchar* hline_min_ptr = (uchar*)(ptr) + (xl)*(pix_size);
1077+
uchar* hline_end_ptr = (uchar*)(ptr) + (xr+1)*(pix_size);
1078+
uchar* hline_ptr = hline_min_ptr;
1079+
if (pix_size == 1)
1080+
memset(hline_min_ptr, *color, hline_end_ptr-hline_min_ptr);
1081+
else//if (pix_size != 1)
1082+
{
1083+
if (hline_min_ptr < hline_end_ptr)
1084+
{
1085+
memcpy(hline_ptr, color, pix_size);
1086+
hline_ptr += pix_size;
1087+
}//end if (hline_min_ptr < hline_end_ptr)
1088+
size_t sizeToCopy = pix_size;
1089+
while(hline_ptr < hline_end_ptr)
1090+
{
1091+
memcpy(hline_ptr, hline_min_ptr, sizeToCopy);
1092+
hline_ptr += sizeToCopy;
1093+
sizeToCopy = std::min(2*sizeToCopy, static_cast<size_t>(hline_end_ptr-hline_ptr));
1094+
}//end while(hline_ptr < hline_end_ptr)
1095+
}//end if (pix_size != 1)
10861096
}
1097+
//end ICV_HLINE_X()
10871098

1099+
static inline void ICV_HLINE(uchar* ptr, int xl, int xr, const void* color, int pix_size)
1100+
{
1101+
ICV_HLINE_X(ptr, xl, xr, reinterpret_cast<const uchar*>(color), pix_size);
1102+
}
1103+
//end ICV_HLINE()
10881104

10891105
/* filling convex polygon. v - array of vertices, ntps - number of points */
10901106
static void

0 commit comments

Comments
 (0)