-
-
Notifications
You must be signed in to change notification settings - Fork 888
Pixel-agnostic Drawing processors and extensions #910
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
Conversation
# Conflicts: # src/ImageSharp/Color/Color.Conversions.cs
Codecov Report
@@ Coverage Diff @@
## master #910 +/- ##
==========================================
- Coverage 89.29% 89.13% -0.16%
==========================================
Files 1079 1083 +4
Lines 47631 47394 -237
Branches 3273 3293 +20
==========================================
- Hits 42530 42243 -287
- Misses 4387 4398 +11
- Partials 714 753 +39
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks go to me, nothing jumping out to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really great stuff. A massive improvement in the surface API.
I'm happy for this to go in, but have added a few questions for you to ponder over.
| /// <param name="ratio">Where should it be? 0 is at the start, 1 at the end of the Gradient.</param> | ||
| /// <param name="color">What color should be used at that point?</param> | ||
| public ColorStop(float ratio, TPixel color) | ||
| public ColorStop(float ratio, in Color color) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love that we can now use readonly structs here.
| public static DenseMatrix<TPixel> ToPixelMatrix<TPixel>(this DenseMatrix<Color> colorMatrix, Configuration configuration) | ||
| where TPixel : struct, IPixel<TPixel> | ||
| { | ||
| DenseMatrix<TPixel> result = new DenseMatrix<TPixel>(colorMatrix.Columns, colorMatrix.Rows); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API synergy! 😄
| /// <typeparam name="TPixel">The type of the color.</typeparam> | ||
| public interface IPen<TPixel> : IPen | ||
| where TPixel : struct, IPixel<TPixel> | ||
| public interface IPen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So much nicer
| Image<TPixel> image, | ||
| RectangleF region, | ||
| GraphicsOptions options, | ||
| bool shouldDisposeImage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When do we need to dispose the source?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we draw an image of a different pixel type, we create a temporary copy, which should be disposed by the brush applicator.
| float distance = (float)Math.Sqrt( | ||
| Math.Pow(x4 - this.start.X, 2) | ||
| + Math.Pow(y4 - this.start.Y, 2)); | ||
| float distance = (float)Math.Sqrt(Math.Pow(x4 - this.start.X, 2) + Math.Pow(y4 - this.start.Y, 2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MathF?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hope I won't forget this next time I touch the code.
| /// </summary> | ||
| /// <typeparam name="TPixelBg">The pixel format of destination image.</typeparam> | ||
| /// <typeparam name="TPixelFg">The pixel format of source image.</typeparam> | ||
| internal class DrawImageProcessor<TPixelBg, TPixelFg> : ImageProcessor<TPixelBg> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting one. I personally find Fg and Bg far less confusing than the compositing standard of Src and Dst but others might argue the inconsistency in language causes confusion.
They're wrong of course 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That naming totally confused me, had to rename this in order to avoid making a mistake.
| where TPixel : struct, IPixel<TPixel> | ||
| => source.Fill(new SolidBrush<TPixel>(color), shape); | ||
| public static IImageProcessingContext | ||
| Fill(this IImageProcessingContext source, Color color, RectangleF shape) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we incorporate the overload performance fixes from #838 here? Merging after could cause conflicts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, did notice that. We should merge that PR ASAP, I'll have a look in the next few days.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to create better overloads another day :)
| where TPixel : struct, IPixel<TPixel> | ||
| { | ||
| TPixel red = NamedColors<TPixel>.Red; | ||
| Color red = Color.Red; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can clearly see how much nicer the API is to work with in the tests.
|
I'm merging this now, because I have more stuff in my queue. We can apply #838 later. |
Pixel-agnostic Drawing processors and extensions
Prerequisites
Description
Continue work on #907 by getting rid of generics in drawing API-s:
IBrushandIPenare no longer generic. All pixel-specific work is delegated toBrushApplicator<TPixel>Coloris being used as color parameter for drawing processorsImageof different pixel type inImageBrush. (A clone image is created in these cases for the applicator.)IImageProcessor<T>usages have been dropped from tests and benchmarksNot in scope
Removing all obsolete generic types. A cleanup PR will follow.