Skip to content

Conversation

@antonfirsov
Copy link
Member

@antonfirsov antonfirsov commented May 16, 2019

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

Continue work on #907 by getting rid of generics in drawing API-s:

  • Drawing tests have been refactored and extended with validations
  • IBrush and IPen are no longer generic. All pixel-specific work is delegated to BrushApplicator<TPixel>
  • Color is being used as color parameter for drawing processors
  • It's allowed to use Image of different pixel type in ImageBrush. (A clone image is created in these cases for the applicator.)
  • Unnecessary IImageProcessor<T> usages have been dropped from tests and benchmarks

Not in scope

Removing all obsolete generic types. A cleanup PR will follow.

@antonfirsov antonfirsov requested a review from tocsoft May 16, 2019 23:12
@codecov
Copy link

codecov bot commented May 17, 2019

Codecov Report

Merging #910 into master will decrease coverage by 0.15%.
The diff coverage is 94.98%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/ImageSharp/Image{TPixel}.cs 88.63% <ø> (-0.26%) ⬇️
.../TestUtilities/ImageProviders/TestImageProvider.cs 84.78% <ø> (ø) ⬆️
...rocessing/Processors/Transforms/RotateFlipTests.cs 100% <ø> (ø) ⬆️
...harp.Tests/TestUtilities/ImagingTestCaseUtility.cs 96.63% <ø> (ø) ⬆️
...ors/Convolution/Basic1ParameterConvolutionTests.cs 100% <ø> (ø) ⬆️
...ssing/Processors/Binarization/BinaryDitherTests.cs 100% <ø> (ø) ⬆️
...ities/Attributes/WithSolidFilledImagesAttribute.cs 100% <ø> (ø) ⬆️
...Processing/Extensions/FillPathBuilderExtensions.cs 0% <0%> (ø)
...g/Processing/Extensions/DrawRectangleExtensions.cs 0% <0%> (ø)
...ageSharp.Tests/Drawing/Paths/DrawPathCollection.cs 100% <100%> (ø) ⬆️
... and 115 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 451186c...0395300. Read the comment docs.

Copy link
Member

@tocsoft tocsoft left a 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

Copy link
Member

@JimBobSquarePants JimBobSquarePants left a 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)
Copy link
Member

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);
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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?

Copy link
Member Author

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));
Copy link
Member

Choose a reason for hiding this comment

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

MathF?

Copy link
Member Author

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>
Copy link
Member

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 😄

Copy link
Member Author

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) =>
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Contributor

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;
Copy link
Member

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.

@antonfirsov
Copy link
Member Author

I'm merging this now, because I have more stuff in my queue. We can apply #838 later.

@antonfirsov antonfirsov merged commit ef736e0 into master May 19, 2019
@JimBobSquarePants JimBobSquarePants deleted the af/refactor-drawing branch September 3, 2019 11:14
antonfirsov added a commit to antonfirsov/ImageSharp that referenced this pull request Nov 11, 2019
Pixel-agnostic Drawing processors and extensions
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.

5 participants