Skip to content

Commit a899eb5

Browse files
committed
Moved Colorize to IMagickImageCreateOperations.
1 parent d4f4736 commit a899eb5

File tree

5 files changed

+43
-32
lines changed

5 files changed

+43
-32
lines changed

src/Magick.NET.Core/IMagickImageCloneMutator{TQuantumType}.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,22 @@ namespace ImageMagick;
1212
public interface IMagickImageCloneMutator<TQuantumType> : IMagickImageCreateOperations<TQuantumType>
1313
where TQuantumType : struct, IConvertible
1414
{
15+
/// <summary>
16+
/// Colorize image with the specified color, using specified percent alpha.
17+
/// </summary>
18+
/// <param name="color">The color to use.</param>
19+
/// <param name="alpha">The alpha percentage.</param>
20+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
21+
void Colorize(IMagickColor<TQuantumType> color, Percentage alpha);
22+
23+
/// <summary>
24+
/// Colorize image with the specified color, using specified percent alpha for red, green,
25+
/// and blue quantums.
26+
/// </summary>
27+
/// <param name="color">The color to use.</param>
28+
/// <param name="alphaRed">The alpha percentage for red.</param>
29+
/// <param name="alphaGreen">The alpha percentage for green.</param>
30+
/// <param name="alphaBlue">The alpha percentage for blue.</param>
31+
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
32+
void Colorize(IMagickColor<TQuantumType> color, Percentage alphaRed, Percentage alphaGreen, Percentage alphaBlue);
1533
}

src/Magick.NET.Core/IMagickImage{TQuantumType}.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,6 @@ public partial interface IMagickImage<TQuantumType> : IMagickImage, IComparable<
114114
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
115115
void ColorAlpha(IMagickColor<TQuantumType> color);
116116

117-
/// <summary>
118-
/// Colorize image with the specified color, using specified percent alpha.
119-
/// </summary>
120-
/// <param name="color">The color to use.</param>
121-
/// <param name="alpha">The alpha percentage.</param>
122-
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
123-
void Colorize(IMagickColor<TQuantumType> color, Percentage alpha);
124-
125-
/// <summary>
126-
/// Colorize image with the specified color, using specified percent alpha for red, green,
127-
/// and blue quantums.
128-
/// </summary>
129-
/// <param name="color">The color to use.</param>
130-
/// <param name="alphaRed">The alpha percentage for red.</param>
131-
/// <param name="alphaGreen">The alpha percentage for green.</param>
132-
/// <param name="alphaBlue">The alpha percentage for blue.</param>
133-
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
134-
void Colorize(IMagickColor<TQuantumType> color, Percentage alphaRed, Percentage alphaGreen, Percentage alphaBlue);
135-
136117
/// <summary>
137118
/// Forces all pixels in the color range to white otherwise black.
138119
/// </summary>

src/Magick.NET/MagickImage.CloneMutator.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
5+
using System.Globalization;
56
using ImageMagick.Drawing;
67

78
#if Q8
@@ -178,6 +179,25 @@ public void Clamp()
178179
public void Clamp(Channels channels)
179180
=> SetResult(NativeMagickImage.Clamp(channels));
180181

182+
public void Colorize(IMagickColor<QuantumType> color, Percentage alpha)
183+
{
184+
Throw.IfNegative(nameof(alpha), alpha);
185+
186+
Colorize(color, alpha, alpha, alpha);
187+
}
188+
189+
public void Colorize(IMagickColor<QuantumType> color, Percentage alphaRed, Percentage alphaGreen, Percentage alphaBlue)
190+
{
191+
Throw.IfNull(nameof(color), color);
192+
Throw.IfNegative(nameof(alphaRed), alphaRed);
193+
Throw.IfNegative(nameof(alphaGreen), alphaGreen);
194+
Throw.IfNegative(nameof(alphaBlue), alphaBlue);
195+
196+
var blend = string.Format(CultureInfo.InvariantCulture, "{0}/{1}/{2}", alphaRed.ToInt32(), alphaGreen.ToInt32(), alphaBlue.ToInt32());
197+
198+
SetResult(NativeMagickImage.Colorize(color, blend));
199+
}
200+
181201
public void Resize(uint width, uint height)
182202
=> Resize(new MagickGeometry(width, height));
183203

src/Magick.NET/MagickImage.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,9 +1785,8 @@ public void ColorDecisionList(string fileName)
17851785
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
17861786
public void Colorize(IMagickColor<QuantumType> color, Percentage alpha)
17871787
{
1788-
Throw.IfNegative(nameof(alpha), alpha);
1789-
1790-
Colorize(color, alpha, alpha, alpha);
1788+
using var mutator = new Mutator(_nativeInstance);
1789+
mutator.Colorize(color, alpha, alpha, alpha);
17911790
}
17921791

17931792
/// <summary>
@@ -1801,14 +1800,8 @@ public void Colorize(IMagickColor<QuantumType> color, Percentage alpha)
18011800
/// <exception cref="MagickException">Thrown when an error is raised by ImageMagick.</exception>
18021801
public void Colorize(IMagickColor<QuantumType> color, Percentage alphaRed, Percentage alphaGreen, Percentage alphaBlue)
18031802
{
1804-
Throw.IfNull(nameof(color), color);
1805-
Throw.IfNegative(nameof(alphaRed), alphaRed);
1806-
Throw.IfNegative(nameof(alphaGreen), alphaGreen);
1807-
Throw.IfNegative(nameof(alphaBlue), alphaBlue);
1808-
1809-
var blend = string.Format(CultureInfo.InvariantCulture, "{0}/{1}/{2}", alphaRed.ToInt32(), alphaGreen.ToInt32(), alphaBlue.ToInt32());
1810-
1811-
_nativeInstance.Colorize(color, blend);
1803+
using var mutator = new Mutator(_nativeInstance);
1804+
mutator.Colorize(color, alphaRed, alphaGreen, alphaBlue);
18121805
}
18131806

18141807
/// <summary>

src/Magick.NET/Native/MagickImage.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ private unsafe sealed partial class NativeMagickImage : NativeInstance, INativeM
313313
public partial void ColorDecisionList(string fileName);
314314

315315
[Throws]
316-
[SetInstance]
317-
public partial void Colorize(IMagickColor<QuantumType>? color, string blend);
316+
public partial IntPtr Colorize(IMagickColor<QuantumType>? color, string blend);
318317

319318
[Throws]
320319
[SetInstance]

0 commit comments

Comments
 (0)