Skip to content

Introduce PixelTypeInfo.HasAlpha #1396

@antonfirsov

Description

@antonfirsov

Motivation

By introducing a property to observe whether a given pixel type has an alpha, we can then use it in our processors to omit unnecessary alpha premultiplication. Might be also interesting for users working with Image.Identify.

We need to make sure it's value is properly filled:

  • In decoders with Identify implementations (PNG, BMP)
  • For all built-in pixel formats (IPixel-s)

API alternatives

In #1394 (reply in thread) I forgot that extending IPixel is actually a breaking change. Non-breaking variant:

internal enum PixelAlphaRepresentation
{
    None,
    Associated,
    Unassociated
}

public class PixelTypeInfo
{
     // 'null' means unknown/not implemented
     public PixelAlphaRepresentation? AlphaRepresentation { get; }    
}

public PixelOperations<TPixel>
{
     // Return AlphaRepresentation == null by default, but for important pixel types, introduce proper overrides with T4:
     public virtual PixelTypeInfo GetPixelTypeInfo();
}

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions