Skip to content

Commit

Permalink
Moved Colorize to IMagickImageCreateOperations.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Nov 11, 2024
1 parent d4f4736 commit a899eb5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 32 deletions.
18 changes: 18 additions & 0 deletions src/Magick.NET.Core/IMagickImageCloneMutator{TQuantumType}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,22 @@ namespace ImageMagick;
public interface IMagickImageCloneMutator<TQuantumType> : IMagickImageCreateOperations<TQuantumType>
where TQuantumType : struct, IConvertible
{
/// <summary>
/// Colorize image with the specified color, using specified percent alpha.
/// </summary>
/// <param name="color">The color to use.</param>
/// <param name="alpha">The alpha percentage.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void Colorize(IMagickColor<TQuantumType> color, Percentage alpha);

/// <summary>
/// Colorize image with the specified color, using specified percent alpha for red, green,
/// and blue quantums.
/// </summary>
/// <param name="color">The color to use.</param>
/// <param name="alphaRed">The alpha percentage for red.</param>
/// <param name="alphaGreen">The alpha percentage for green.</param>
/// <param name="alphaBlue">The alpha percentage for blue.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void Colorize(IMagickColor<TQuantumType> color, Percentage alphaRed, Percentage alphaGreen, Percentage alphaBlue);
}
19 changes: 0 additions & 19 deletions src/Magick.NET.Core/IMagickImage{TQuantumType}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,6 @@ public partial interface IMagickImage<TQuantumType> : IMagickImage, IComparable<
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void ColorAlpha(IMagickColor<TQuantumType> color);

/// <summary>
/// Colorize image with the specified color, using specified percent alpha.
/// </summary>
/// <param name="color">The color to use.</param>
/// <param name="alpha">The alpha percentage.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void Colorize(IMagickColor<TQuantumType> color, Percentage alpha);

/// <summary>
/// Colorize image with the specified color, using specified percent alpha for red, green,
/// and blue quantums.
/// </summary>
/// <param name="color">The color to use.</param>
/// <param name="alphaRed">The alpha percentage for red.</param>
/// <param name="alphaGreen">The alpha percentage for green.</param>
/// <param name="alphaBlue">The alpha percentage for blue.</param>
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
void Colorize(IMagickColor<TQuantumType> color, Percentage alphaRed, Percentage alphaGreen, Percentage alphaBlue);

/// <summary>
/// Forces all pixels in the color range to white otherwise black.
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions src/Magick.NET/MagickImage.CloneMutator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.

using System;
using System.Globalization;
using ImageMagick.Drawing;

#if Q8
Expand Down Expand Up @@ -178,6 +179,25 @@ public void Clamp()
public void Clamp(Channels channels)
=> SetResult(NativeMagickImage.Clamp(channels));

public void Colorize(IMagickColor<QuantumType> color, Percentage alpha)
{
Throw.IfNegative(nameof(alpha), alpha);

Colorize(color, alpha, alpha, alpha);
}

public void Colorize(IMagickColor<QuantumType> color, Percentage alphaRed, Percentage alphaGreen, Percentage alphaBlue)
{
Throw.IfNull(nameof(color), color);
Throw.IfNegative(nameof(alphaRed), alphaRed);
Throw.IfNegative(nameof(alphaGreen), alphaGreen);
Throw.IfNegative(nameof(alphaBlue), alphaBlue);

var blend = string.Format(CultureInfo.InvariantCulture, "{0}/{1}/{2}", alphaRed.ToInt32(), alphaGreen.ToInt32(), alphaBlue.ToInt32());

SetResult(NativeMagickImage.Colorize(color, blend));
}

public void Resize(uint width, uint height)
=> Resize(new MagickGeometry(width, height));

Expand Down
15 changes: 4 additions & 11 deletions src/Magick.NET/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1785,9 +1785,8 @@ public void ColorDecisionList(string fileName)
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void Colorize(IMagickColor<QuantumType> color, Percentage alpha)
{
Throw.IfNegative(nameof(alpha), alpha);

Colorize(color, alpha, alpha, alpha);
using var mutator = new Mutator(_nativeInstance);
mutator.Colorize(color, alpha, alpha, alpha);
}

/// <summary>
Expand All @@ -1801,14 +1800,8 @@ public void Colorize(IMagickColor<QuantumType> color, Percentage alpha)
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
public void Colorize(IMagickColor<QuantumType> color, Percentage alphaRed, Percentage alphaGreen, Percentage alphaBlue)
{
Throw.IfNull(nameof(color), color);
Throw.IfNegative(nameof(alphaRed), alphaRed);
Throw.IfNegative(nameof(alphaGreen), alphaGreen);
Throw.IfNegative(nameof(alphaBlue), alphaBlue);

var blend = string.Format(CultureInfo.InvariantCulture, "{0}/{1}/{2}", alphaRed.ToInt32(), alphaGreen.ToInt32(), alphaBlue.ToInt32());

_nativeInstance.Colorize(color, blend);
using var mutator = new Mutator(_nativeInstance);
mutator.Colorize(color, alphaRed, alphaGreen, alphaBlue);
}

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions src/Magick.NET/Native/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ private unsafe sealed partial class NativeMagickImage : NativeInstance, INativeM
public partial void ColorDecisionList(string fileName);

[Throws]
[SetInstance]
public partial void Colorize(IMagickColor<QuantumType>? color, string blend);
public partial IntPtr Colorize(IMagickColor<QuantumType>? color, string blend);

[Throws]
[SetInstance]
Expand Down

0 comments on commit a899eb5

Please sign in to comment.