Skip to content

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

@jongleur1983

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.

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