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

Public Vector4 to/from conversions #1050

Merged
merged 6 commits into from
Dec 17, 2019
Merged

Public Vector4 to/from conversions #1050

merged 6 commits into from
Dec 17, 2019

Conversation

Sergio0694
Copy link
Member

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

As discussed with @antonfirsov, I've made the following APIs public:

  • PixelOperations<TPixel>.FromVector4Destructive
  • PixelOperations<TPixel>.ToVector4

Overloads are included as well. I also made the PixelConversionModifiers enum public, otherwise two of those overloads would've been blocked from being exposed.

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.

Mostly good, but we need to make 100% sure the generated files do not break the build, if you can't bring life to your T4 generator, I will take care of it later.

@@ -83,7 +83,7 @@ public partial class PixelOperations<TPixel>
/// <param name="configuration">A <see cref="Configuration"/> to configure internal operations</param>
/// <param name="sourcePixels">The <see cref="Span{T}"/> to the source colors.</param>
/// <param name="destVectors">The <see cref="Span{T}"/> to the destination vectors.</param>
internal virtual void ToVector4(
public virtual void ToVector4(
Copy link
Member

Choose a reason for hiding this comment

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

This method should not be virtual.

Copy link
Member Author

@Sergio0694 Sergio0694 Nov 11, 2019

Choose a reason for hiding this comment

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

Wait, this method is actually overridden by some pixel-format-specific implementations of PixelOperations<TPixel>, like for RgbaVector, Rgba32 and others. It's also in the GenerateRgba32CompatibleVector4ConversionMethods part in the _Common.ttinclide file.

I don't think we can remove that virtual right now, given the rest of the codebase as it is now. That is, unless you have some refactoring in mind to make that possible 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we're gonna have to have a think about this!

Copy link
Member

@antonfirsov antonfirsov Dec 17, 2019

Choose a reason for hiding this comment

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

@Sergio0694 I did not have the chance to check the code, but if this method is overriden, it's a mistake. At the bottom of the call stack, all scenarios shall be covered with a single virtual overload which is taking the most arguments, the shorter overloads shall be non-virtual wrappers only.

Otherwise everything else LGTM, if someone can confirm that T4 generation is working.

Copy link
Member Author

@Sergio0694 Sergio0694 Dec 17, 2019

Choose a reason for hiding this comment

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

@antonfirsov So, I'm not sure how to proceed here. From what I see, even before my changes in this branch, that virtual ToVector4 method was already being overridden in virtually all the pixel-format specific PixelOperations<TPixel> classes.
For instance, this happens both in the explicit RgbaVector and Rgba32 types, as well as in all the generated pixel-format classes (eg. here in Argb32.Generated).

I'm not sure how to proceed here if you want to remove the virtual modifier: as far as I can see, right now each pixel-format is returning an instance of its own PixelOperations<TPixel> private class, exposed as PixelOperations<TPixel>, so that when the methods are called on that instance, the right overload for the specific pixel-format is called. And I mean, this makes sense, and it looks great. My question is: if you want to remove the virtual modifier from the default implementation of those methods in the base PixelOperations<TPixel> class, how can we then have each pixel-format call its own custom version of those APIs?

PixelOperations<TPixel> is not abstract so we can't even just set that method as abstract from there and have each pixel-format specific class implement it. Plus as far as I know there are some pixel-formats that do fallback on that base implementation, so this wouldn't work either.

I might very well be missing something here, I'm confused 🤔

Copy link
Member

@JimBobSquarePants JimBobSquarePants Dec 17, 2019

Choose a reason for hiding this comment

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

@Sergio0694 I think you were looking at the wrong method. The one highlighted by @antonfirsov does not have any overloads. I've removed the virtual keyword from it and regenerated the templated code.

Once this builds I'm happy to merge it.

Copy link
Member Author

Choose a reason for hiding this comment

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

@JimBobSquarePants @antonfirsov Ooof I was looking at the wrong overload 🤦‍♂️
I did have the feeling I was being stupid, sorry to have wasted your time on this!
Happy to hear the rest of the PR was ok though, thanks for merging it! 😊

Copy link
Member

Choose a reason for hiding this comment

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

Haha no worries, easy mistake to make!

@Sergio0694
Copy link
Member Author

Sergio0694 commented Nov 11, 2019

Mh, not not sure why the build failed there, I'll see if I can repro this on my end and try to fix it.

@JimBobSquarePants JimBobSquarePants added this to the 1.0.0-rc1 milestone Nov 12, 2019
@JimBobSquarePants
Copy link
Member

@Sergio0694 What's with the commit history from July?

@Sergio0694
Copy link
Member Author

@JimBobSquarePants I think that's because I created this branch from my existing fork of ImageSharp, which hadn't been updated since my bokeh blur processor got merged, so I think those commits are from the initial merge I did to get my fork back in sync with the current official master.

@codecov
Copy link

codecov bot commented Nov 12, 2019

Codecov Report

Merging #1050 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1050   +/-   ##
=======================================
  Coverage   90.03%   90.03%           
=======================================
  Files        1145     1145           
  Lines       51762    51762           
  Branches     3783     3783           
=======================================
  Hits        46605    46605           
  Misses       4402     4402           
  Partials      755      755
Impacted Files Coverage Δ
...ats/PixelImplementations/Rgba32.PixelOperations.cs 100% <ø> (ø) ⬆️
...tions/Generated/Rgb48.PixelOperations.Generated.cs 100% <ø> (ø) ⬆️
...PixelImplementations/RgbaVector.PixelOperations.cs 100% <ø> (ø) ⬆️
...tions/Generated/Rgb24.PixelOperations.Generated.cs 100% <ø> (ø) ⬆️
...ions/Generated/Rgba64.PixelOperations.Generated.cs 100% <ø> (ø) ⬆️
...ions/Generated/Bgra32.PixelOperations.Generated.cs 100% <ø> (ø) ⬆️
...ions/Generated/Argb32.PixelOperations.Generated.cs 100% <ø> (ø) ⬆️
...tions/Generated/Bgr24.PixelOperations.Generated.cs 100% <ø> (ø) ⬆️
...ions/Generated/Rgba32.PixelOperations.Generated.cs 100% <ø> (ø) ⬆️
...ns/Generated/Bgra5551.PixelOperations.Generated.cs 98.16% <ø> (ø) ⬆️
... and 1 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 a42e30f...3cb8988. Read the comment docs.

@JimBobSquarePants
Copy link
Member

@Sergio0694 Still haven't managed to properly sit down and evaluate this. Rest assured though I will do asap.

@Sergio0694
Copy link
Member Author

@JimBobSquarePants Hey, I was just about to ask you for a status update on this! Glad to hear it's still on your radar, that's awesome! And no worries, there's no rush, I just wanted to make sure this would make it into the next beta/RC build 😄

@JimBobSquarePants JimBobSquarePants merged commit 7fcefa6 into SixLabors:master Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants