-
-
Notifications
You must be signed in to change notification settings - Fork 855
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
Add span overloads for Image.Load() and Image.DetectFormat() #618
Conversation
…loads of Image.Load()
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.
looking good, only the one item I can see and that's the dependence remaining for netstandard 2.0
src/ImageSharp/ImageSharp.csproj
Outdated
@@ -44,6 +44,9 @@ | |||
<PackageReference Include="System.Memory" Version="4.5.0" /> | |||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.0" /> | |||
</ItemGroup> | |||
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.1' "> |
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 skip this for our net standard 2.0 > targets too so you probably want to change this to '$(TargetFramework)' == 'netstandard1.3'
instead
Codecov Report
@@ Coverage Diff @@
## master #618 +/- ##
==========================================
- Coverage 88.58% 88.55% -0.04%
==========================================
Files 878 881 +3
Lines 36984 36994 +10
Branches 2627 2627
==========================================
- Hits 32762 32759 -3
- Misses 3440 3452 +12
- Partials 782 783 +1
Continue to review full report at Codecov.
|
@tocsoft good catch, fixed! |
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 good. Nice trick with UnmanagedMemoryStream
!
{ | ||
fixed (byte* ptr = &data.GetPinnableReference()) | ||
{ | ||
using (var stream = new UnmanagedMemoryStream(ptr, data.Length)) |
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.
It's unfortunate to allocate a heap object to wrap the span...
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.
Good spot, I've opened #671 to deal with it.
What do you think elsewhere? Looking good?
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.
Makes sense in the DetectFormat()
use case, thanks!
When doing a full image decoding (Image.Load(...)
), that allocation is a drop in the bucket however. Using UnmanagedMemoryStream
seemed to be the best way for "converting" a span into a Stream
.
Add span overloads for Image.Load() and Image.DetectFormat()
Prerequisites
Description
This PR implements API-s proposed in #565 by @jherby2k with the help of System.IO.UnmanagedMemoryStream which is a new dependency for targets > netstandard 1.1.
Related tests have been refactored heavily (isolation, cleanup, code share).