Skip to content

Commit

Permalink
Added extra overload for the Clut method and unit test for the issue …
Browse files Browse the repository at this point in the history
…that was found and fixed for #1630.
  • Loading branch information
dlemstra committed May 18, 2024
1 parent e229605 commit 9595bcd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/Magick.NET.Core/IMagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,14 @@ Interlace Interlace
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void Clut(IMagickImage image);

/// <summary>
/// Apply a color lookup table (CLUT) to the image.
/// </summary>
/// <param name="image">The image to use.</param>
/// <param name="channels">The channel(s) to clut.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void Clut(IMagickImage image, Channels channels);

/// <summary>
/// Apply a color lookup table (CLUT) to the image.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions src/Magick.NET/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,15 @@ public IMagickImage<QuantumType> Clone(int x, int y, int width, int height)
public void Clut(IMagickImage image)
=> Clut(image, PixelInterpolateMethod.Undefined);

/// <summary>
/// Apply a color lookup table (CLUT) to the image.
/// </summary>
/// <param name="image">The image to use.</param>
/// <param name="channels">The channel(s) to clut.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void Clut(IMagickImage image, Channels channels)
=> Clut(image, PixelInterpolateMethod.Undefined, channels);

/// <summary>
/// Apply a color lookup table (CLUT) to the image.
/// </summary>
Expand Down
23 changes: 19 additions & 4 deletions tests/Magick.NET.Tests/MagickImageTests/TheClutMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,31 @@ public class TheClutMethod
[Fact]
public void ShouldApplyTheSpecifiedColorTable()
{
using var images = new MagickImageCollection();
images.Add(new MagickImage(MagickColors.Red, 1, 1));
images.Add(new MagickImage(MagickColors.Blue, 1, 1));
images.Add(new MagickImage(MagickColors.Green, 1, 1));
using var images = new MagickImageCollection
{
new MagickImage(MagickColors.Red, 1, 1),
new MagickImage(MagickColors.Blue, 1, 1),
new MagickImage(MagickColors.Green, 1, 1),
};

using var pallete = images.AppendHorizontally();
using var image = new MagickImage(Files.Builtin.Logo);
image.Clut(pallete, PixelInterpolateMethod.Catrom);

ColorAssert.Equal(MagickColors.Green, image, 400, 300);
}

[Fact]
public void ShouldUseTheSpecifiedChannels()
{
using var image = new MagickImage(Files.RedPNG);
using var black = new MagickImage(MagickColors.Black, 1, 1);
image.Clut(black, Channels.RGB);

ColorAssert.Equal(MagickColors.Black, image, 100, 100);
ColorAssert.Equal(MagickColors.Transparent, image, 230, 100);
ColorAssert.Equal(MagickColors.Black, image, 300, 100);
ColorAssert.Equal(new MagickColor("#00000080"), image, 500, 100);
}
}
}

0 comments on commit 9595bcd

Please sign in to comment.