Skip to content

Conversation

@JimBobSquarePants
Copy link
Member

@JimBobSquarePants JimBobSquarePants commented Sep 17, 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

Touches. #967

  • Refactors the image processors to make the interfaces and base classes public.
  • Removes double pixel processor creation.
  • Simplified cloned target image creation.

I've marked this as draft as I want to do something more extreme and remove ICloningImageProcessor<TPixel> moving the interface method into the base class. This makes additional methods impossible to test against though via mocking.

Changed my mind and figured out a better way to create contracts for cloned/regular processors.

Thoughts please!

@codecov
Copy link

codecov bot commented Sep 17, 2019

Codecov Report

Merging #1011 into master will increase coverage by <.01%.
The diff coverage is 91.22%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1011      +/-   ##
==========================================
+ Coverage   89.86%   89.86%   +<.01%     
==========================================
  Files        1098     1099       +1     
  Lines       48832    48836       +4     
  Branches     3435     3439       +4     
==========================================
+ Hits        43881    43888       +7     
+ Misses       4249     4246       -3     
  Partials      702      702
Impacted Files Coverage Δ
.../Processing/Processors/Transforms/SkewProcessor.cs 84.61% <ø> (ø) ⬆️
...ng/Processors/Transforms/Resize/ResizeProcessor.cs 100% <ø> (ø) ⬆️
...rp/Processing/Processors/ImageProcessor{TPixel}.cs 100% <ø> (ø) ⬆️
src/ImageSharp/Advanced/AotCompilerTools.cs 0% <0%> (ø) ⬆️
...ing/Processors/Transforms/CropProcessor{TPixel}.cs 100% <100%> (ø) ⬆️
...ors/Convolution/EdgeDetector2DProcessor{TPixel}.cs 100% <100%> (ø) ⬆️
...arp/Processing/Processors/CloningImageProcessor.cs 100% <100%> (ø)
...rocessing/Processors/Transforms/RotateProcessor.cs 100% <100%> (ø) ⬆️
...ocessors/Transforms/AutoOrientProcessor{TPixel}.cs 85.29% <100%> (ø) ⬆️
.../Processors/Transforms/AffineTransformProcessor.cs 100% <100%> (ø) ⬆️
... and 16 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 b004888...464598c. Read the comment docs.

@antonfirsov
Copy link
Member

I had an idea a few weeks ago for the same point. Actually, I had two options in my mind, and wanted to ask for input to decide which one is better, but I haven't got the the chance to present them so far.

This solution is a third option actually 😄 I will have a deeper look at it now, but I can't promise I can summarize my thoughts properly tonight.

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.

Pointing out a few not-so-nice points. I remember I had ideas to solve them, when I was thinking about the problem (and faced other non-trivial questions afterwards), I'm just dead tired to recall those ideas now 😄
We'll be back tomorrow!

@JimBobSquarePants
Copy link
Member Author

This solution is a third option actually 😄 I will have a deeper look at it now, but I can't promise I can summarize my thoughts properly tonight.

Excellent. Looking forward to seeing what you come up with. I'm going to replace the Mocks with dummy pass-through instances so I can demonstrate my intent in the interim and continue to provide coverage.

@JimBobSquarePants JimBobSquarePants marked this pull request as ready for review September 19, 2019 14:32
@JimBobSquarePants JimBobSquarePants changed the title WIP: Make processors public, refactor cloning. Make processors public, refactor cloning. Sep 19, 2019
{
var test = new OctreeFrameQuantizer<TPixel>(new OctreeQuantizer(false));
test.AotGetPalette();
using (var test = new OctreeFrameQuantizer<TPixel>(new OctreeQuantizer(false)))
Copy link
Member Author

Choose a reason for hiding this comment

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

Spotted these when removing the AOT CreateDestination method. No longer required as not virtual.


/// <inheritdoc/>
public Image<TPixel> CloneAndApply()
Image<TPixel> ICloningImageProcessor<TPixel>.CloneAndExecute()
Copy link
Member Author

Choose a reason for hiding this comment

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

Hidden so not to clutter child classes.

{
}

private Image<TPixel> CreateTarget()
Copy link
Member Author

Choose a reason for hiding this comment

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

This method was identical in every implementation. The only different was where the target size came from.

ParallelHelper.IterateRows(
targetBounds,
this.Configuration,
configuration,
Copy link
Member Author

Choose a reason for hiding this comment

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

Spotted we were capturing the whole class in the lambda

Copy link
Member

Choose a reason for hiding this comment

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

I don't get the difference. this.Configuration also returns a Configuration instance.

Also: capturing the whole class is not necessarily evil. Or is it? Am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

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

Bad practice as I understand that can lead to negative performance and issues since capturing variables affects the lifetime of those captures.

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.

@JimBobSquarePants the current state might be good enough actually, but if you don't mind, let's keep it open for another few days.
Hope I get the chance to check it once again with a fresh mind. (Sunday probably.)
Maybe we can clean up / simplify even more.

throw new ImageProcessingException($"An error occurred when processing the image using {this.GetType().Name}. The processor changed the number of frames.");
}
Image<TPixel> clone = this.CreateTarget();
this.CheckFrameCount(this.Source, clone);
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if the checks are necessary. The centralized cloning logic should guarantee that the frame counts are matching.

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 actually thought that but was too lazy to check and just merged the code into a single method

Copy link
Member

Choose a reason for hiding this comment

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

It's an iterative way to delete bloated code 😉

@JimBobSquarePants
Copy link
Member Author

Setting a countdown on this one. I want to keep progressing.

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.

Agree, it's more important now to progress, than to polish everything. I'm struggling to find time this week, improvements could be added later in a separate PR.

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.

2 participants