Skip to content

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

@antonfirsov

Description

@antonfirsov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions