Skip to content
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

Improve accessability of Span<T> methods on Image<T> / ImageFrame<T> #1164

Closed
antonfirsov opened this issue Apr 4, 2020 · 0 comments · Fixed by #1172
Closed

Improve accessability of Span<T> methods on Image<T> / ImageFrame<T> #1164

antonfirsov opened this issue Apr 4, 2020 · 0 comments · Fixed by #1172
Labels
Milestone

Comments

@antonfirsov
Copy link
Member

antonfirsov commented Apr 4, 2020

Problems

We have two, somewhat related issues to address:

  1. AdvancedImageExtensions.GetPixelSpan is now obsolete, and there is no convenient way to get a single pixel span for memory interop use-cases
  2. Keeping the pixel span methods in AdvancedImageExtensions leads to poor discoverability. With all the Roslyn analyzers we have today, to detect Span<T> misuse, I no longer consider them unsafe or "advanced". I suggest to make them instance members on Image<TPixel> and ImageFrame<TPixel>. Note: this does not apply for Memory<T> or IMemoryGroup<T> stuff, since persisting heap-references to the pixel memory has some nontrivial consequences.

Proposal

Redifine Span<TPixel> methods as following:

public class Image<TPixel>
{
    public bool TryGetSinglePixelSpan(out Span<TPixel> pixelSpan);
    public Span<TPixel> GetPixelRowSpan(int rowIndex);
}

public class ImageFrame<TPixel>
{
    public bool TryGetSinglePixelSpan(out Span<TPixel> span);
    public Span<TPixel> GetPixelRowSpan(int rowIndex);       
}

Update: Fixed copy/paste errors in the proposal.

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 a pull request may close this issue.

1 participant