@@ -19,7 +19,7 @@ public partial struct Rgba128 : IPixel<Rgba128>, IEquatable<Rgba128>
1919{
2020 private const float InvMax = 1.0f / uint . MaxValue ;
2121
22- private const double Max = uint . MaxValue ;
22+ private const float Max = uint . MaxValue ;
2323
2424 /// <summary>
2525 /// Gets the red component.
@@ -94,62 +94,86 @@ public Rgba128(uint r, uint g, uint b, uint a)
9494 public static Rgba128 FromScaledVector4 ( Vector4 source ) => FromVector4 ( source ) ;
9595
9696 /// <inheritdoc/>
97- public static Rgba128 FromVector4 ( Vector4 source ) => FromVector4 ( source ) ;
97+ public static Rgba128 FromVector4 ( Vector4 source )
98+ {
99+ source = Numerics . Clamp ( source , Vector4 . Zero , Vector4 . One ) * Max ;
100+ return new Rgba128 ( ( uint ) MathF . Round ( source . X ) , ( uint ) MathF . Round ( source . Y ) , ( uint ) MathF . Round ( source . Z ) , ( uint ) MathF . Round ( source . W ) ) ;
101+ }
98102
99103 /// <inheritdoc/>
100- public static Rgba128 FromAbgr32 ( Abgr32 source ) => new ( source . R , source . G , source . B , source . A ) ;
104+ public static Rgba128 FromAbgr32 ( Abgr32 source )
105+ => new ( ColorNumerics . From8BitTo32Bit ( source . R ) , ColorNumerics . From8BitTo32Bit ( source . G ) , ColorNumerics . From8BitTo32Bit ( source . B ) , ColorNumerics . From8BitTo32Bit ( source . A ) ) ;
101106
102107 /// <inheritdoc/>
103- public static Rgba128 FromArgb32 ( Argb32 source ) => new ( source . R , source . G , source . B , source . A ) ;
108+ public static Rgba128 FromArgb32 ( Argb32 source )
109+ => new ( ColorNumerics . From8BitTo32Bit ( source . R ) , ColorNumerics . From8BitTo32Bit ( source . G ) , ColorNumerics . From8BitTo32Bit ( source . B ) , ColorNumerics . From8BitTo32Bit ( source . A ) ) ;
104110
105111 /// <inheritdoc/>
106112 public static Rgba128 FromBgra5551 ( Bgra5551 source ) => FromScaledVector4 ( source . ToScaledVector4 ( ) ) ;
107113
108114 /// <inheritdoc/>
109- public static Rgba128 FromBgr24 ( Bgr24 source ) => new ( source . R , source . G , source . B , uint . MaxValue ) ;
115+ public static Rgba128 FromBgr24 ( Bgr24 source )
116+ => new ( ColorNumerics . From8BitTo32Bit ( source . R ) , ColorNumerics . From8BitTo32Bit ( source . G ) , ColorNumerics . From8BitTo32Bit ( source . B ) , uint . MaxValue ) ;
110117
111118 /// <inheritdoc/>
112- public static Rgba128 FromBgra32 ( Bgra32 source ) => new ( source . R , source . G , source . B , source . A ) ;
119+ public static Rgba128 FromBgra32 ( Bgra32 source )
120+ => new ( ColorNumerics . From8BitTo32Bit ( source . R ) , ColorNumerics . From8BitTo32Bit ( source . G ) , ColorNumerics . From8BitTo32Bit ( source . B ) , ColorNumerics . From8BitTo32Bit ( source . A ) ) ;
113121
114122 /// <inheritdoc/>
115123 public static Rgba128 FromL8 ( L8 source )
116124 {
117- ushort rgb = ColorNumerics . From8BitTo16Bit ( source . PackedValue ) ;
125+ uint rgb = ColorNumerics . From8BitTo32Bit ( source . PackedValue ) ;
118126 return new Rgba128 ( rgb , rgb , rgb , rgb ) ;
119127 }
120128
121129 /// <inheritdoc/>
122- public static Rgba128 FromL16 ( L16 source ) => new ( source . PackedValue , source . PackedValue , source . PackedValue , source . PackedValue ) ;
130+ public static Rgba128 FromL16 ( L16 source )
131+ {
132+ uint rgb = ColorNumerics . From16BitTo32Bit ( source . PackedValue ) ;
133+ return new ( rgb , rgb , rgb , rgb ) ;
134+ }
123135
124136 /// <inheritdoc/>
125- public static Rgba128 FromLa16 ( La16 source ) => new ( source . PackedValue , source . PackedValue , source . PackedValue , source . PackedValue ) ;
137+ public static Rgba128 FromLa16 ( La16 source )
138+ {
139+ uint rgb = ColorNumerics . From8BitTo32Bit ( ( byte ) source . PackedValue ) ;
140+ return new ( rgb , rgb , rgb , rgb ) ;
141+ }
126142
127143 /// <inheritdoc/>
128- public static Rgba128 FromLa32 ( La32 source ) => new ( source . L , source . L , source . L , source . L ) ;
144+ public static Rgba128 FromLa32 ( La32 source )
145+ {
146+ uint rgb = ColorNumerics . From16BitTo32Bit ( source . L ) ;
147+ return new ( rgb , rgb , rgb , rgb ) ;
148+ }
129149
130150 /// <inheritdoc/>
131- public static Rgba128 FromRgb24 ( Rgb24 source ) => new ( source . R , source . G , source . B , uint . MaxValue ) ;
151+ public static Rgba128 FromRgb24 ( Rgb24 source )
152+ => new ( ColorNumerics . From8BitTo32Bit ( source . R ) , ColorNumerics . From8BitTo32Bit ( source . G ) , ColorNumerics . From8BitTo32Bit ( source . B ) , uint . MaxValue ) ;
132153
133154 /// <inheritdoc/>
134- public static Rgba128 FromRgba32 ( Rgba32 source ) => new ( source . R , source . G , source . B , source . A ) ;
155+ public static Rgba128 FromRgba32 ( Rgba32 source )
156+ => new ( ColorNumerics . From8BitTo32Bit ( source . R ) , ColorNumerics . From8BitTo32Bit ( source . G ) , ColorNumerics . From8BitTo32Bit ( source . B ) , ColorNumerics . From8BitTo32Bit ( source . A ) ) ;
135157
136158 /// <inheritdoc/>
137- public static Rgba128 FromRgb48 ( Rgb48 source ) => new ( source . R , source . G , source . B , uint . MaxValue ) ;
159+ public static Rgba128 FromRgb48 ( Rgb48 source )
160+ => new ( ColorNumerics . From16BitTo32Bit ( source . R ) , ColorNumerics . From16BitTo32Bit ( source . G ) , ColorNumerics . From16BitTo32Bit ( source . B ) , uint . MaxValue ) ;
138161
139162 /// <inheritdoc/>
140- public static Rgba128 FromRgba64 ( Rgba64 source ) => new ( source . R , source . G , source . B , source . A ) ;
163+ public static Rgba128 FromRgba64 ( Rgba64 source )
164+ => new ( ColorNumerics . From16BitTo32Bit ( source . R ) , ColorNumerics . From16BitTo32Bit ( source . G ) , ColorNumerics . From16BitTo32Bit ( source . B ) , ColorNumerics . From16BitTo32Bit ( source . A ) ) ;
141165
142166 /// <inheritdoc/>
143167 public static PixelTypeInfo GetPixelTypeInfo ( ) => PixelTypeInfo . Create < Rgba128 > (
144- PixelComponentInfo . Create < Rgba128 > ( 4 , 32 , 32 , 32 ) ,
145- PixelColorType . RGB ,
168+ PixelComponentInfo . Create < Rgba128 > ( 4 , 32 , 32 , 32 , 32 ) ,
169+ PixelColorType . RGB | PixelColorType . Alpha ,
146170 PixelAlphaRepresentation . Unassociated ) ;
147171
148172 /// <inheritdoc/>
149- public readonly Rgba32 ToRgba32 ( ) => throw new NotImplementedException ( ) ;
173+ public readonly Rgba32 ToRgba32 ( ) => Rgba32 . FromRgba128 ( this ) ;
150174
151175 /// <inheritdoc/>
152- public readonly Vector4 ToScaledVector4 ( ) => throw new NotImplementedException ( ) ;
176+ public readonly Vector4 ToScaledVector4 ( ) => this . ToVector4 ( ) ;
153177
154178 /// <inheritdoc />
155179 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
0 commit comments