Skip to content

Commit ce274e8

Browse files
committed
Simplify the code.
1 parent bb0014a commit ce274e8

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

src/Magick.NET/Statistics/ChannelPerceptualHash.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ public double HuPhash(ColorSpace colorSpace, int index)
4646
{
4747
Throw.IfOutOfRange(nameof(index), index, 7);
4848

49-
var huPhashList = GetHuPhashListByColorSpace(colorSpace);
50-
if (huPhashList is null)
49+
if (!_huPhashes.TryGetValue(colorSpace, out var huPhashList))
50+
{
5151
throw new ArgumentException("Invalid colorspace specified.", nameof(colorSpace));
52+
}
5253

5354
return huPhashList[index];
5455
}
@@ -101,16 +102,6 @@ private static double PowerOfTen(int power)
101102
_ => 10.0,
102103
};
103104

104-
private HuPhashList? GetHuPhashListByColorSpace(ColorSpace colorSpace)
105-
{
106-
if (_huPhashes.TryGetValue(colorSpace, out var huPhashList))
107-
{
108-
return huPhashList;
109-
}
110-
111-
return null;
112-
}
113-
114105
private void ParseHash(ColorSpace[] colorSpaces, string hash)
115106
{
116107
_hash = hash;

src/Magick.NET/Statistics/PerceptualHash.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,10 @@ internal static void DisposeList(IntPtr list)
113113
NativePerceptualHash.DisposeList(list);
114114
}
115115

116-
private static ChannelPerceptualHash? CreateChannelPerceptualHash(IMagickImage image, ColorSpace[] colorSpaces, IntPtr list, PixelChannel channel)
117-
{
118-
var instance = NativePerceptualHash.GetInstance(image, list, channel);
119-
return new ChannelPerceptualHash(channel, colorSpaces, instance);
120-
}
121-
122116
private void AddChannel(IMagickImage image, ColorSpace[] colorSpaces, IntPtr list, PixelChannel channel)
123117
{
124-
var instance = CreateChannelPerceptualHash(image, colorSpaces, list, channel);
125-
if (instance is not null)
126-
_channels.Add(instance.Channel, instance);
118+
var nativeInstance = NativePerceptualHash.GetInstance(image, list, channel);
119+
var instance = new ChannelPerceptualHash(channel, colorSpaces, nativeInstance);
120+
_channels.Add(instance.Channel, instance);
127121
}
128122
}

0 commit comments

Comments
 (0)