# HG changeset patch # User Alain Mazy # Date 1557751824 -7200 # Node ID 9345710bbf12eb291fa19dbab42487f19051a25c # Parent ea299aca479bdd21cb1997254a489ceb81135b93 check limits in fillpolygon diff -r ea299aca479b -r 9345710bbf12 Core/Images/ImageProcessing.cpp --- a/Core/Images/ImageProcessing.cpp Tue May 07 13:21:41 2019 +0200 +++ b/Core/Images/ImageProcessing.cpp Mon May 13 14:50:24 2019 +0200 @@ -1433,6 +1433,11 @@ size_t cpSize = points.size(); for (size_t i = 0; i < points.size(); i++) { + if (points[i].GetX() < 0 || points[i].GetX() >= imageWidth + || points[i].GetY() < 0 || points[i].GetY() >= imageHeight) + { + throw Orthanc::OrthancException(ErrorCode_ParameterOutOfRange); + } cpx.push_back((double)points[i].GetX()); cpy.push_back((double)points[i].GetY()); } diff -r ea299aca479b -r 9345710bbf12 UnitTestsSources/ImageProcessingTests.cpp --- a/UnitTestsSources/ImageProcessingTests.cpp Tue May 07 13:21:41 2019 +0200 +++ b/UnitTestsSources/ImageProcessingTests.cpp Mon May 13 14:50:24 2019 +0200 @@ -223,3 +223,41 @@ ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, 1, 2)); ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, 2, 4)); } + +TYPED_TEST(TestIntegerImageTraits, FillPolygonLargerThandImage) +{ + ImageAccessor& image = this->GetImage(); + + ImageProcessing::Set(image, 0); + + std::vector points; + points.push_back(ImageProcessing::ImagePoint(0, 0)); + points.push_back(ImageProcessing::ImagePoint(image.GetWidth(),0)); + points.push_back(ImageProcessing::ImagePoint(image.GetWidth(),image.GetHeight())); + points.push_back(ImageProcessing::ImagePoint(0,image.GetHeight())); + + ASSERT_THROW(Orthanc::ImageProcessing::FillPolygon(image, points, 255), Orthanc::OrthancException); + + // inside polygon (note: we don't test too close from the edges since the current algo is taking some margin from the edges and might be improved in that sense) + ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, 0, 0)); + ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, image.GetWidth()-1, 0)); +} + +TYPED_TEST(TestIntegerImageTraits, FillPolygonFullImage) +{ + ImageAccessor& image = this->GetImage(); + + ImageProcessing::Set(image, 0); + + std::vector points; + points.push_back(ImageProcessing::ImagePoint(0, 0)); + points.push_back(ImageProcessing::ImagePoint(image.GetWidth() - 1,0)); + points.push_back(ImageProcessing::ImagePoint(image.GetWidth() - 1,image.GetHeight() - 1)); + points.push_back(ImageProcessing::ImagePoint(0,image.GetHeight() - 1)); + + Orthanc::ImageProcessing::FillPolygon(image, points, 255); + + // inside polygon (note: we don't test too close from the edges since the current algo is taking some margin from the edges and might be improved in that sense) + ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, 1, 1)); + ASSERT_FLOAT_EQ(255, TestFixture::ImageTraits::GetFloatPixel(image, image.GetWidth() - 2, image.GetHeight() - 2)); +}