Skip to content

For Pixel type conversions omit either PackFrom{otherTPixel}({otherTPixel source}) or To{OtherTPixel}(ref {otherTPixel} dest)) #730

Description

@jongleur1983

There are many TPixel types in ImageSharp.
Conversion between types can be done currently as a "push" or a "pull":
Let s be a pixel from ANY TPixel type be the source and t be the pixel of ANY TPixel type target.

Then getting the corresponding color of s converted to the target format and stored in the variable t can be done in two different ways:

t.PackFromSource(s) s.ToTarget(ref t)
both do the same: they change the value of t to the converted value of s.

Wherever one of both is used now, this can be exchanged by the other one.

I propose to only keep the first for two reasons:

  1. less "special" syntax by not needing the ref keyword here.
  2. here s is a parameter and the operation is done on t, which seems to be more obvious this way around when reading code.

For better compatibility there could even be a smooth transition between these two to keep existing code working:

All ToTarget(ref t) can be generated by using t.PackFromSource(this). Generating in partial classes still allows custom implementations of everything else. The generated methods could be marked as obsolete with a hint to use the other variant.

Activity

  1. JimBobSquarePants commented on Oct 6, 2018

    @JimBobSquarePants
    Member

    I'm happy to dump s.ToTarget(ref t) and keep t.PackFromSource(s)

    I don't think we need to use partial classes. They're really only used in low level code that's been internal for a long time.

  2. added a commit that references this issue on Oct 23, 2018
  3. added a commit that references this issue on Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions