Skip to content

Introduce PixelTypeInfo.HasAlpha #1396

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();
}

Activity

  1. added this to the Future milestone on Oct 20, 2020
  2. JimBobSquarePants commented on Oct 24, 2020

    @JimBobSquarePants
    Member

    I can see us adding ChannelCount to this type at some point so I guess that would be nullable also.

  3. antonfirsov commented on Oct 24, 2020

    @antonfirsov
    MemberAuthor

    @JimBobSquarePants so you prefer the non-breaking variant? Honestly, now it looks like a safer way to go to me.
    Also allows us to extend codecs incrementally to detect PixelTypeInfo details.

  4. JimBobSquarePants commented on Oct 24, 2020

    @JimBobSquarePants
    Member

    Yeah, it's a safe clever approach. Big fan!

  5. saucecontrol commented on Oct 27, 2020

    @saucecontrol
    Contributor

    I might be misreading the purpose of this, but did you consider support for pixel formats that are already premultiplied? TIFF and DirectX (among others) support alpha in both forms.

    I recall we had a chat about this somewhere, although I've since lost track of it... I set up a generic pixel format descriptor type here which borrows heavily from WIC's pluggable pixel format model and describes alpha using an enum if you're looking for inspiration.

  6. JimBobSquarePants commented on Oct 28, 2020

    @JimBobSquarePants
    Member

    Oh I remember this stuff yeah, will definitely have to use it as a source of inspiration!

  7. antonfirsov commented on Nov 2, 2020

    @antonfirsov
    MemberAuthor

    @saucecontrol do I get this right?

    • None: has no alpha
    • Associated: has alpha, pixel is premultiplied
    • Unassociated: has alpha, pixel is not premultiplied

    @JimBobSquarePants edited my proposal, let's go with the non-breaking version + enum for PixelAlphaRepresentation.

  8. saucecontrol commented on Nov 2, 2020

    @saucecontrol
    Contributor

    Yep, that's right. DirectX uses Ignore, Premultiplied, and Straight to describe those values. I'm not sure which is more intuitive.

  9. JimBobSquarePants commented on Nov 2, 2020

    @JimBobSquarePants
    Member

    I much prefer your naming.

  10. JimBobSquarePants commented on Nov 7, 2020

    @JimBobSquarePants
    Member

    I've started this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions