Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Numerics class and Refactor Clamp Utils #1436

Merged
merged 11 commits into from
Nov 23, 2020

Conversation

JimBobSquarePants
Copy link
Member

@JimBobSquarePants JimBobSquarePants commented Nov 23, 2020

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

There's a lot of cosmetic changes here but very little functional. I've been wanting to do a major cleanup for a while.

  • Introduce Numerics utility method to consolidate non-image specific maths magritings several from ImageMaths.
  • Replaces Clamp extension methods with static Numerics impl
  • Migrates Vector4 FastClamp to Numerics.
  • Added vectorized Clamp(Span, min, max) methods (As yet unused but have plans).
  • General renaming for consistency.

@JimBobSquarePants JimBobSquarePants added this to the 1.1.0 milestone Nov 23, 2020
@JimBobSquarePants JimBobSquarePants requested a review from a team November 23, 2020 01:21
@codecov
Copy link

codecov bot commented Nov 23, 2020

Codecov Report

Merging #1436 (d6f4821) into master (9b7df13) will increase coverage by 0.05%.
The diff coverage is 84.13%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1436      +/-   ##
==========================================
+ Coverage   83.63%   83.68%   +0.05%     
==========================================
  Files         733      732       -1     
  Lines       31922    31984      +62     
  Branches     3590     3605      +15     
==========================================
+ Hits        26697    26766      +69     
+ Misses       4511     4505       -6     
+ Partials      714      713       -1     
Flag Coverage Δ
unittests 83.68% <84.13%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...c/ImageSharp/ColorSpaces/Companding/LCompanding.cs 0.00% <0.00%> (ø)
...arp/Common/Helpers/SimdUtils.BasicIntrinsics256.cs 98.21% <ø> (ø)
...arp/Common/Helpers/SimdUtils.ExtendedIntrinsics.cs 72.60% <0.00%> (ø)
...ts/PixelBlenders/DefaultPixelBlenders.Generated.cs 15.74% <ø> (ø)
src/ImageSharp/Primitives/ComplexVector4.cs 57.14% <ø> (ø)
...s/Binarization/BinaryThresholdProcessor{TPixel}.cs 96.96% <0.00%> (ø)
...Processing/Processors/Transforms/TransformUtils.cs 93.93% <ø> (ø)
...ats/PixelBlenders/PorterDuffFunctions.Generated.cs 11.73% <8.33%> (ø)
...mageSharp/Common/Helpers/SimdUtils.HwIntrinsics.cs 97.80% <83.33%> (ø)
...rc/ImageSharp/Processing/AffineTransformBuilder.cs 87.23% <85.71%> (ø)
... and 78 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b7df13...d6f4821. Read the comment docs.

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with suggestion:
We may want to move all Color/Pixel related numeric operations from ImageMath and Vector4Utils to a separate ColorNumerics class and probably get rid of Vector4Utils as a result. Cohesion around the Vector4 type itself is no good cohesion here.

ImageMaths.UpscaleFrom8BitTo16Bit(g),
ImageMaths.UpscaleFrom8BitTo16Bit(b),
ImageMaths.UpscaleFrom8BitTo16Bit(a));
ImageMath.UpscaleFrom8BitTo16Bit(r),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this to Numerics too. Or to a separate ColorNumerics (or similarly named) class.

@@ -59,7 +59,7 @@ internal static class DenseMatrixUtils
ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column);
vector.W = target.W;

Vector4Utilities.UnPremultiply(ref vector);
Vector4Utils.UnPremultiply(ref vector);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Numerics or ColorNumerics ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move both to Numerics.

src/ImageSharp/Common/Helpers/Numerics.cs Outdated Show resolved Hide resolved
@@ -30,7 +30,7 @@ public SkewProcessor(float degreesX, float degreesY, Size sourceSize)
/// <param name="sourceSize">The source image size</param>
public SkewProcessor(float degreesX, float degreesY, IResampler sampler, Size sourceSize)
: this(
TransformUtilities.CreateSkewMatrixDegrees(degreesX, degreesY, sourceSize),
TransformUtils.CreateSkewMatrixDegrees(degreesX, degreesY, sourceSize),
Copy link
Member

@antonfirsov antonfirsov Nov 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we are back to the Utils postfix convention? Agreed, shorter is better here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah less typing. Unfortunately there's a public GeometryUtilities class I couldn't change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably shouldn't have left that public for the 2 methods it has.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... We shouldn't. Annoyed at myself for not spotting it.

@JimBobSquarePants JimBobSquarePants merged commit 0e0dc2a into master Nov 23, 2020
@JimBobSquarePants JimBobSquarePants deleted the js/clamp-utils branch November 23, 2020 13:57
JimBobSquarePants added a commit that referenced this pull request Mar 13, 2021
Introduce Numerics class and Refactor Clamp Utils
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants