Skip to content

Conversation

@antonfirsov
Copy link
Member

@antonfirsov antonfirsov commented Apr 1, 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

This is a replacement PR for #847 introducing extended bulk conversion controlled by flags.

  • Tests, benchmarks, and SRrgbCompanding and Resize refactors have been reused from Add premultiplied bulk pixel operations #847
  • Converting from Vector4 buffers is destructive for performance, yet it's clean
  • Very basic actual optimization have been introduced for Rgb24 and Bgr24.
ResizeBicubic_Rgb24

BEFORE:

                                   Method |  Job | Runtime | SourceSize | DestSize |     Mean |      Error |    StdDev | Ratio | RatioSD | Gen 0/1k Op | Gen 1/1k Op | Gen 2/1k Op | Allocated Memory/Op |
----------------------------------------- |----- |-------- |----------- |--------- |---------:|-----------:|----------:|------:|--------:|------------:|------------:|------------:|--------------------:|
                            SystemDrawing |  Clr |     Clr |       3032 |      400 | 124.9 ms | 101.109 ms | 5.5422 ms |  1.00 |    0.00 |           - |           - |           - |              2048 B |
 'ImageSharp, MaxDegreeOfParallelism = 1' |  Clr |     Clr |       3032 |      400 | 111.9 ms |   2.431 ms | 0.1332 ms |  0.90 |    0.04 |           - |           - |           - |             45875 B |
                                          |      |         |            |          |          |            |           |       |         |             |             |             |                     |
                            SystemDrawing | Core |    Core |       3032 |      400 | 123.1 ms |  41.406 ms | 2.2696 ms |  1.00 |    0.00 |           - |           - |           - |                96 B |
 'ImageSharp, MaxDegreeOfParallelism = 1' | Core |    Core |       3032 |      400 | 101.4 ms |  19.823 ms | 1.0866 ms |  0.82 |    0.02 |           - |           - |           - |             44504 B |

AFTER:

                                   Method |  Job | Runtime | SourceSize | DestSize |      Mean |     Error |    StdDev | Ratio | RatioSD | Gen 0/1k Op | Gen 1/1k Op | Gen 2/1k Op | Allocated Memory/Op |
----------------------------------------- |----- |-------- |----------- |--------- |----------:|----------:|----------:|------:|--------:|------------:|------------:|------------:|--------------------:|
                            SystemDrawing |  Clr |     Clr |       3032 |      400 | 121.37 ms | 48.580 ms | 2.6628 ms |  1.00 |    0.00 |           - |           - |           - |              2048 B |
 'ImageSharp, MaxDegreeOfParallelism = 1' |  Clr |     Clr |       3032 |      400 |  99.36 ms | 11.356 ms | 0.6224 ms |  0.82 |    0.02 |           - |           - |           - |             45056 B |
                                          |      |         |            |          |           |           |           |       |         |             |             |             |                     |
                            SystemDrawing | Core |    Core |       3032 |      400 | 118.06 ms | 15.667 ms | 0.8587 ms |  1.00 |    0.00 |           - |           - |           - |                96 B |
 'ImageSharp, MaxDegreeOfParallelism = 1' | Core |    Core |       3032 |      400 |  92.47 ms |  5.683 ms | 0.3115 ms |  0.78 |    0.01 |           - |           - |           - |             44512 B |

/// knowing the pixel type.
/// </summary>
[Flags]
internal enum PixelConversionModifiers
Copy link
Member Author

@antonfirsov antonfirsov Apr 1, 2019

Choose a reason for hiding this comment

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

Please review my namings here!

Copy link
Member

Choose a reason for hiding this comment

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

Naming is good! 👍

@codecov
Copy link

codecov bot commented Apr 1, 2019

Codecov Report

Merging #869 into master will decrease coverage by 0.01%.
The diff coverage is 99.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #869      +/-   ##
==========================================
- Coverage   88.89%   88.87%   -0.02%     
==========================================
  Files        1014     1017       +3     
  Lines       44295    44438     +143     
  Branches     3209     3228      +19     
==========================================
+ Hits        39376    39495     +119     
+ Misses       4198     4181      -17     
- Partials      721      762      +41
Impacted Files Coverage Δ
...PixelFormats/PixelConversionModifiersExtensions.cs 100% <100%> (ø)
...ing/Processors/Convolution/ConvolutionProcessor.cs 100% <100%> (ø) ⬆️
...lFormats/Utils/Vector4Converters.RgbaCompatible.cs 91.42% <100%> (-1.6%) ⬇️
...rc/ImageSharp/PixelFormats/PixelBlender{TPixel}.cs 100% <100%> (ø) ⬆️
...xelFormats/PixelOperations/PixelOperationsTests.cs 100% <100%> (ø) ⬆️
...tions/PixelOperationsTests.Bgr24OperationsTests.cs 100% <100%> (ø) ⬆️
...ng/Processors/Transforms/Resize/ResizeProcessor.cs 96.22% <100%> (-0.23%) ⬇️
...geSharp.Tests/TestUtilities/TestImageExtensions.cs 83.26% <100%> (ø) ⬆️
...tions/Generated/Rgb24.PixelOperations.Generated.cs 89.28% <100%> (+24.51%) ⬆️
.../Jpeg/Components/Decoder/JpegImagePostProcessor.cs 93.18% <100%> (ø) ⬆️
... and 48 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 45b7490...408e196. Read the comment docs.

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.

I much, much, much prefer this approach to the tree of methods in my PR. Much easier for us to optimize single methods.

PixelConversionModifiers conversionModifiers = PixelConversionModifiers.Premultiply;
if (this.Compand)
{
conversionModifiers |= PixelConversionModifiers.Scale | PixelConversionModifiers.SRgbCompand;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could shortcut this? It's something to remember every time. (Unless that's a good thing for greater understanding?)

Copy link
Member

Choose a reason for hiding this comment

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

I think we'll leave it as-is. It's explicit and should be well understood.

Copy link
Member Author

Choose a reason for hiding this comment

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

Companding always indicates scaling (otherwise colors are incorrect), right?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the algorithm requires scaling.

/// knowing the pixel type.
/// </summary>
[Flags]
internal enum PixelConversionModifiers
Copy link
Member

Choose a reason for hiding this comment

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

Naming is good! 👍

internal static class PixelConversionModifiersExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsDefined(this PixelConversionModifiers modifiers, PixelConversionModifiers expected) =>
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

/// <summary>
/// Select <see cref="IPixel.ToScaledVector4"/> and <see cref="IPixel.FromScaledVector4"/> instead the standard (non scaled) variants.
/// </summary>
Scale = 1 << 0,
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 I keep thinking whether we should replace Scaled / Scale with Normalized / Normalize in our terminology. Seems more precize to me. Or is this wrong thinking?

Copy link
Member

Choose a reason for hiding this comment

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

Or is this wrong thinking?

Actually no. Normalization in our situation is exactly what we are doing and I think I prefer it!

It means breaking IPixel for consistency but you have my blessing to do so. I'd really like to ensure we have our naming correct for RC1.

@antonfirsov
Copy link
Member Author

I'm merging this now to unblock stuff like #870. Naming tweaks could be added in a follow-up PR.

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