@@ -14,135 +14,151 @@ namespace SixLabors.ImageSharp.PixelFormats;
14
14
public interface IPixel < TSelf > : IPixel , IEquatable < TSelf >
15
15
where TSelf : unmanaged, IPixel < TSelf >
16
16
{
17
- /// <summary>
18
- /// Gets the pixel type information.
19
- /// </summary>
20
- /// <returns>The <see cref="PixelTypeInfo"/>.</returns>
21
- #pragma warning disable CA1000
22
- static abstract PixelTypeInfo GetPixelTypeInfo ( ) ;
23
- #pragma warning restore CA1000
24
-
25
17
/// <summary>
26
18
/// Creates a <see cref="PixelOperations{TPixel}"/> instance for this pixel type.
27
19
/// This method is not intended to be consumed directly. Use <see cref="PixelOperations{TPixel}.Instance"/> instead.
28
20
/// </summary>
29
21
/// <returns>The <see cref="PixelOperations{TPixel}"/> instance.</returns>
30
22
PixelOperations < TSelf > CreatePixelOperations ( ) ;
31
- }
32
23
33
- /// <summary>
34
- /// A base interface for all pixels, defining the mandatory operations to be implemented by a pixel type.
35
- /// </summary>
36
- public interface IPixel
37
- {
38
- /// <summary>
39
- /// Initializes the pixel instance from a generic ("scaled") <see cref="Vector4"/>.
40
- /// </summary>
41
- /// <param name="vector">The vector to load the pixel from.</param>
42
- void FromScaledVector4 ( Vector4 vector ) ;
24
+ #pragma warning disable CA1000 // Do not declare static members on generic types
43
25
44
26
/// <summary>
45
- /// Expands the pixel into a generic ("scaled") <see cref="Vector4"/> representation
46
- /// with values scaled and clamped between <value>0</value> and <value>1</value>.
47
- /// The vector components are typically expanded in least to greatest significance order.
27
+ /// Gets the pixel type information.
48
28
/// </summary>
49
- /// <returns>The <see cref="Vector4 "/>.</returns>
50
- Vector4 ToScaledVector4 ( ) ;
29
+ /// <returns>The <see cref="PixelTypeInfo "/>.</returns>
30
+ static abstract PixelTypeInfo GetPixelTypeInfo ( ) ;
51
31
52
32
/// <summary>
53
- /// Initializes the pixel instance from a <see cref="Vector4"/> which is specific to the current pixel type .
33
+ /// Initializes the pixel instance from a generic scaled <see cref="Vector4"/>.
54
34
/// </summary>
55
- /// <param name="vector">The vector to load the pixel from.</param>
56
- void FromVector4 ( Vector4 vector ) ;
35
+ /// <param name="source">The vector to load the pixel from.</param>
36
+ /// <returns>The <typeparamref name="TSelf"/>.</returns>
37
+ static abstract TSelf FromScaledVector4 ( Vector4 source ) ;
57
38
58
39
/// <summary>
59
- /// Expands the pixel into a <see cref="Vector4"/> which is specific to the current pixel type.
60
- /// The vector components are typically expanded in least to greatest significance order.
40
+ /// Initializes the pixel instance from a <see cref="Vector4"/> which is specific to the current pixel type.
61
41
/// </summary>
62
- /// <returns>The <see cref="Vector4"/>.</returns>
63
- Vector4 ToVector4 ( ) ;
42
+ /// <param name="source">The vector to load the pixel from.</param>
43
+ /// <returns>The <typeparamref name="TSelf"/>.</returns>
44
+ static abstract TSelf FromVector4 ( Vector4 source ) ;
64
45
65
46
/// <summary>
66
47
/// Initializes the pixel instance from an <see cref="Argb32"/> value.
67
48
/// </summary>
68
49
/// <param name="source">The <see cref="Argb32"/> value.</param>
69
- void FromArgb32 ( Argb32 source ) ;
50
+ /// <returns>The <typeparamref name="TSelf"/>.</returns>
51
+ static virtual TSelf FromArgb32 ( Argb32 source ) => TSelf . FromScaledVector4 ( source . ToScaledVector4 ( ) ) ;
70
52
71
53
/// <summary>
72
54
/// Initializes the pixel instance from an <see cref="Bgra5551"/> value.
73
55
/// </summary>
74
56
/// <param name="source">The <see cref="Bgra5551"/> value.</param>
75
- void FromBgra5551 ( Bgra5551 source ) ;
57
+ /// <returns>The <typeparamref name="TSelf"/>.</returns>
58
+ static virtual TSelf FromBgra5551 ( Bgra5551 source ) => TSelf . FromScaledVector4 ( source . ToScaledVector4 ( ) ) ;
76
59
77
60
/// <summary>
78
61
/// Initializes the pixel instance from an <see cref="Bgr24"/> value.
79
62
/// </summary>
80
63
/// <param name="source">The <see cref="Bgr24"/> value.</param>
81
- void FromBgr24 ( Bgr24 source ) ;
64
+ /// <returns>The <typeparamref name="TSelf"/>.</returns>
65
+ static virtual TSelf FromBgr24 ( Bgr24 source ) => TSelf . FromScaledVector4 ( source . ToScaledVector4 ( ) ) ;
82
66
83
67
/// <summary>
84
68
/// Initializes the pixel instance from an <see cref="Bgra32"/> value.
85
69
/// </summary>
86
70
/// <param name="source">The <see cref="Bgra32"/> value.</param>
87
- void FromBgra32 ( Bgra32 source ) ;
71
+ /// <returns>The <typeparamref name="TSelf"/>.</returns>
72
+ static virtual TSelf FromBgra32 ( Bgra32 source ) => TSelf . FromScaledVector4 ( source . ToScaledVector4 ( ) ) ;
88
73
89
74
/// <summary>
90
75
/// Initializes the pixel instance from an <see cref="Abgr32"/> value.
91
76
/// </summary>
92
77
/// <param name="source">The <see cref="Abgr32"/> value.</param>
93
- void FromAbgr32 ( Abgr32 source ) ;
78
+ /// <returns>The <typeparamref name="TSelf"/>.</returns>
79
+ static virtual TSelf FromAbgr32 ( Abgr32 source ) => TSelf . FromScaledVector4 ( source . ToScaledVector4 ( ) ) ;
94
80
95
81
/// <summary>
96
82
/// Initializes the pixel instance from an <see cref="L8"/> value.
97
83
/// </summary>
98
84
/// <param name="source">The <see cref="L8"/> value.</param>
99
- void FromL8 ( L8 source ) ;
85
+ /// <returns>The <typeparamref name="TSelf"/>.</returns>
86
+ static virtual TSelf FromL8 ( L8 source ) => TSelf . FromScaledVector4 ( source . ToScaledVector4 ( ) ) ;
100
87
101
88
/// <summary>
102
89
/// Initializes the pixel instance from an <see cref="L16"/> value.
103
90
/// </summary>
104
91
/// <param name="source">The <see cref="L16"/> value.</param>
105
- void FromL16 ( L16 source ) ;
92
+ /// <returns>The <typeparamref name="TSelf"/>.</returns>
93
+ static virtual TSelf FromL16 ( L16 source ) => TSelf . FromScaledVector4 ( source . ToScaledVector4 ( ) ) ;
106
94
107
95
/// <summary>
108
96
/// Initializes the pixel instance from an <see cref="La16"/> value.
109
97
/// </summary>
110
98
/// <param name="source">The <see cref="La16"/> value.</param>
111
- void FromLa16 ( La16 source ) ;
99
+ /// <returns>The <typeparamref name="TSelf"/>.</returns>
100
+ static virtual TSelf FromLa16 ( La16 source ) => TSelf . FromScaledVector4 ( source . ToScaledVector4 ( ) ) ;
112
101
113
102
/// <summary>
114
103
/// Initializes the pixel instance from an <see cref="La32"/> value.
115
104
/// </summary>
116
105
/// <param name="source">The <see cref="La32"/> value.</param>
117
- void FromLa32 ( La32 source ) ;
106
+ /// <returns>The <typeparamref name="TSelf"/>.</returns>
107
+ static virtual TSelf FromLa32 ( La32 source ) => TSelf . FromScaledVector4 ( source . ToScaledVector4 ( ) ) ;
118
108
119
109
/// <summary>
120
110
/// Initializes the pixel instance from an <see cref="Rgb24"/> value.
121
111
/// </summary>
122
112
/// <param name="source">The <see cref="Rgb24"/> value.</param>
123
- void FromRgb24 ( Rgb24 source ) ;
113
+ /// <returns>The <typeparamref name="TSelf"/>.</returns>
114
+ static virtual TSelf FromRgb24 ( Rgb24 source ) => TSelf . FromScaledVector4 ( source . ToScaledVector4 ( ) ) ;
124
115
125
116
/// <summary>
126
117
/// Initializes the pixel instance from an <see cref="Rgba32"/> value.
127
118
/// </summary>
128
119
/// <param name="source">The <see cref="Rgba32"/> value.</param>
129
- void FromRgba32 ( Rgba32 source ) ;
130
-
131
- /// <summary>
132
- /// Convert the pixel instance into <see cref="Rgba32"/> representation.
133
- /// </summary>
134
- /// <param name="dest">The reference to the destination <see cref="Rgba32"/> pixel</param>
135
- void ToRgba32 ( ref Rgba32 dest ) ;
120
+ /// <returns>The <typeparamref name="TSelf"/>.</returns>
121
+ static virtual TSelf FromRgba32 ( Rgba32 source ) => TSelf . FromScaledVector4 ( source . ToScaledVector4 ( ) ) ;
136
122
137
123
/// <summary>
138
124
/// Initializes the pixel instance from an <see cref="Rgb48"/> value.
139
125
/// </summary>
140
126
/// <param name="source">The <see cref="Rgb48"/> value.</param>
141
- void FromRgb48 ( Rgb48 source ) ;
127
+ /// <returns>The <typeparamref name="TSelf"/>.</returns>
128
+ static virtual TSelf FromRgb48 ( Rgb48 source ) => TSelf . FromScaledVector4 ( source . ToScaledVector4 ( ) ) ;
142
129
143
130
/// <summary>
144
131
/// Initializes the pixel instance from an <see cref="Rgba64"/> value.
145
132
/// </summary>
146
133
/// <param name="source">The <see cref="Rgba64"/> value.</param>
147
- void FromRgba64 ( Rgba64 source ) ;
134
+ /// <returns>The <typeparamref name="TSelf"/>.</returns>
135
+ static virtual TSelf FromRgba64 ( Rgba64 source ) => TSelf . FromScaledVector4 ( source . ToScaledVector4 ( ) ) ;
136
+ #pragma warning restore CA1000 // Do not declare static members on generic types
137
+ }
138
+
139
+ /// <summary>
140
+ /// A base interface for all pixels, defining the mandatory operations to be implemented by a pixel type.
141
+ /// </summary>
142
+ public interface IPixel
143
+ {
144
+ /// <summary>
145
+ /// Convert the pixel instance into <see cref="Rgba32"/> representation.
146
+ /// </summary>
147
+ /// <returns>The <see cref="Rgba32"/></returns>
148
+ virtual Rgba32 ToRgba32 ( ) => Rgba32 . FromScaledVector4 ( this . ToVector4 ( ) ) ;
149
+
150
+ /// <summary>
151
+ /// Expands the pixel into a generic ("scaled") <see cref="Vector4"/> representation
152
+ /// with values scaled and clamped between <value>0</value> and <value>1</value>.
153
+ /// The vector components are typically expanded in least to greatest significance order.
154
+ /// </summary>
155
+ /// <returns>The <see cref="Vector4"/>.</returns>
156
+ Vector4 ToScaledVector4 ( ) ;
157
+
158
+ /// <summary>
159
+ /// Expands the pixel into a <see cref="Vector4"/> which is specific to the current pixel type.
160
+ /// The vector components are typically expanded in least to greatest significance order.
161
+ /// </summary>
162
+ /// <returns>The <see cref="Vector4"/>.</returns>
163
+ Vector4 ToVector4 ( ) ;
148
164
}
0 commit comments