Skip to content

Commit

Permalink
Added method to remove the settings to IKmeansSettingsExtensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Jul 26, 2020
1 parent 58657b9 commit da8c087
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Magick.NET/Shared/Extensions/IKmeansSettingsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@ public static void SetImageArtifacts(this IKmeansSettings self, IMagickImage<Qua
if (!string.IsNullOrEmpty(self.SeedColors))
image.SetArtifact("kmeans:seed-colors", self.SeedColors);
}

public static void RemoveImageArtifacts(this IKmeansSettings self, IMagickImage<QuantumType> image)
{
if (!string.IsNullOrEmpty(self.SeedColors))
image.RemoveArtifact("kmeans:seed-colors");
}
}
}
2 changes: 2 additions & 0 deletions src/Magick.NET/Shared/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3747,6 +3747,8 @@ public void Kmeans(IKmeansSettings settings)
settings.SetImageArtifacts(this);

_nativeInstance.Kmeans(settings.NumberColors, settings.MaxIterations, settings.Tolerance);

settings.RemoveImageArtifacts(this);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2013-2020 Dirk Lemstra <https://github.com/dlemstra/Magick.NET/>
//
// Licensed under the ImageMagick License (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
//
// https://www.imagemagick.org/script/license.php
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.

using ImageMagick;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Magick.NET.Tests
{
public partial class IKmeansSettingsExtensionsTests
{
[TestClass]
public class TheRemoveImageArtifactsMethod
{
[TestMethod]
public void ShouldRemoveSeedColors()
{
using (var image = new MagickImage())
{
var settings = new KmeansSettings()
{
SeedColors = "red;blue",
};

settings.SetImageArtifacts(image);
settings.RemoveImageArtifacts(image);

Assert.IsNull(image.GetArtifact("kmeans:seed-colors"));
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2013-2020 Dirk Lemstra <https://github.com/dlemstra/Magick.NET/>
//
// Licensed under the ImageMagick License (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
//
// https://www.imagemagick.org/script/license.php
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.

using ImageMagick;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Magick.NET.Tests
{
public partial class IKmeansSettingsExtensionsTests
{
[TestClass]
public class TheSetImageArtifactsMethod
{
[TestMethod]
public void ShouldNotSetTheAttributesWhenTheyAreNotSpecified()
{
using (var image = new MagickImage())
{
var settings = new KmeansSettings();

settings.SetImageArtifacts(image);

Assert.IsNull(image.GetArtifact("kmeans:seed-colors"));
}
}

[TestMethod]
public void ShouldSetSeedColors()
{
using (var image = new MagickImage())
{
var settings = new KmeansSettings()
{
SeedColors = "red;blue",
};

settings.SetImageArtifacts(image);

Assert.AreEqual("red;blue", image.GetArtifact("kmeans:seed-colors"));
}
}
}
}
}

0 comments on commit da8c087

Please sign in to comment.