v4 Promote PixelTypeInfo to TPixel #2534
Unanswered
JimBobSquarePants
asked this question in
Ideas
Replies: 2 comments 5 replies
-
does public interface IPixel<TSelf> : IPixel, IEquatable<TSelf>
where TSelf : unmanaged, IPixel<TSelf>
{
static abstract int BytesPerPixel { get; }
static abstract uint ComponentCount { get; }
... etc
}
public struct Rgba32 : IPixel<Rgba32>
{
public static int BytesPerPixel { get; } = Unsafe.SizeOf<TPixel>() * 8;
public static int ComponentCount{ get; } = 4;
} |
Beta Was this translation helpful? Give feedback.
3 replies
-
I'd like to also add information to the type to express how components are represented. This would allow us to create conversions to Something like the following: public enum PixelComponentPrecision
{
Byte, // 8-bit unsigned integer
Short, // 16-bit signed integer
UShort, // 16-bit unsigned integer
Int, // 32-bit signed integer
UInt, // 32-bit unsigned integer
Float, // 32-bit floating point
Double, // 64-bit floating point
Half, // 16-bit floating point
// ... any other numeric types you might need
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Motivation
PixelTypeInfo
is a type used to determine various qualities of a giveTPixel
format in order to drive correct behavior for pixel operation. The type is currently loosely coupled withTPixel
types being lazily invoked on creation ofPixelOperations<T>
.With C#11 we are able to implement static abstract methods in interfaces, which allows us to reimplement the type as the result of a static method on the generic type. This tightly couples the information making it far more useful in multiple scenarios. In addition, it removes the overhead of lazily invoking the type.
Implementation
The signature of the type would be changed to a generic one in addition to changing the type to a value type readonly struct.
This allows us greater scope for further expansion of the type properties and performance improvements.
Limitations
None known.
Beta Was this translation helpful? Give feedback.
All reactions