Skip to content

Commit e31ff00

Browse files
authored
Merge pull request #27599 from chacha21:drawing_stack_alloc
optimize some drawing with stack allocation #27599 Some drawings can try a stack allocation instead of a std::vector ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [X] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
1 parent 03fbfc7 commit e31ff00

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

modules/imgproc/src/drawing.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,9 +2034,12 @@ void fillPoly( InputOutputArray _img, const Point** pts, const int* npts, int nc
20342034
edges.reserve( total + 1 );
20352035
for (i = 0; i < ncontours; i++)
20362036
{
2037-
if (npts[i] > 0 && pts[i])
2037+
const Point* currentContour = pts[i];
2038+
const int currentContourLength = npts[i];
2039+
if ( (currentContourLength > 0) && currentContour )
20382040
{
2039-
std::vector<Point2l> _pts(pts[i], pts[i] + npts[i]);
2041+
AutoBuffer<Point2l> _pts(currentContourLength);
2042+
std::copy(currentContour, currentContour+currentContourLength, _pts.data());
20402043
CollectPolyEdges(img, _pts.data(), npts[i], edges, buf, line_type, shift, offset);
20412044
}
20422045
}
@@ -2063,8 +2066,11 @@ void polylines( InputOutputArray _img, const Point* const* pts, const int* npts,
20632066

20642067
for( int i = 0; i < ncontours; i++ )
20652068
{
2066-
std::vector<Point2l> _pts(pts[i], pts[i]+npts[i]);
2067-
PolyLine( img, _pts.data(), npts[i], isClosed, buf, thickness, line_type, shift );
2069+
const Point* currentContour = pts[i];
2070+
const int currentContourLength = npts[i];
2071+
AutoBuffer<Point2l> _pts(currentContourLength);
2072+
std::copy(currentContour, currentContour+currentContourLength, _pts.data());
2073+
PolyLine( img, _pts.data(), currentContourLength, isClosed, buf, thickness, line_type, shift );
20682074
}
20692075
}
20702076

0 commit comments

Comments
 (0)