Skip to content

Commit

Permalink
Simplify the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Jan 14, 2025
1 parent bb0014a commit ce274e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
15 changes: 3 additions & 12 deletions src/Magick.NET/Statistics/ChannelPerceptualHash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ public double HuPhash(ColorSpace colorSpace, int index)
{
Throw.IfOutOfRange(nameof(index), index, 7);

var huPhashList = GetHuPhashListByColorSpace(colorSpace);
if (huPhashList is null)
if (!_huPhashes.TryGetValue(colorSpace, out var huPhashList))
{
throw new ArgumentException("Invalid colorspace specified.", nameof(colorSpace));
}

return huPhashList[index];
}
Expand Down Expand Up @@ -101,16 +102,6 @@ private static double PowerOfTen(int power)
_ => 10.0,
};

private HuPhashList? GetHuPhashListByColorSpace(ColorSpace colorSpace)
{
if (_huPhashes.TryGetValue(colorSpace, out var huPhashList))
{
return huPhashList;
}

return null;
}

private void ParseHash(ColorSpace[] colorSpaces, string hash)
{
_hash = hash;
Expand Down
12 changes: 3 additions & 9 deletions src/Magick.NET/Statistics/PerceptualHash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,10 @@ internal static void DisposeList(IntPtr list)
NativePerceptualHash.DisposeList(list);
}

private static ChannelPerceptualHash? CreateChannelPerceptualHash(IMagickImage image, ColorSpace[] colorSpaces, IntPtr list, PixelChannel channel)
{
var instance = NativePerceptualHash.GetInstance(image, list, channel);
return new ChannelPerceptualHash(channel, colorSpaces, instance);
}

private void AddChannel(IMagickImage image, ColorSpace[] colorSpaces, IntPtr list, PixelChannel channel)
{
var instance = CreateChannelPerceptualHash(image, colorSpaces, list, channel);
if (instance is not null)
_channels.Add(instance.Channel, instance);
var nativeInstance = NativePerceptualHash.GetInstance(image, list, channel);
var instance = new ChannelPerceptualHash(channel, colorSpaces, nativeInstance);
_channels.Add(instance.Channel, instance);
}
}

0 comments on commit ce274e8

Please sign in to comment.