|
|
@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public Vector4 ToVector4() |
|
|
public Vector4 ToVector4() |
|
|
{ |
|
|
{ |
|
|
return new Vector4(this.R / Max, this.G / Max, this.B / Max, this.A / Max); |
|
|
return new Vector4(this.R, this.G, this.B, this.A) / Max; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
/// <inheritdoc />
|
|
|
@ -213,21 +213,20 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public void ToRgb24(ref Rgb24 dest) |
|
|
public void ToRgb24(ref Rgb24 dest) |
|
|
{ |
|
|
{ |
|
|
Vector4 vector = this.ToVector4() * 255F; |
|
|
dest.R = (byte)(((this.R * 255) + 32895) >> 16); |
|
|
dest.R = (byte)MathF.Round(vector.X); |
|
|
dest.G = (byte)(((this.G * 255) + 32895) >> 16); |
|
|
dest.G = (byte)MathF.Round(vector.Y); |
|
|
dest.B = (byte)(((this.B * 255) + 32895) >> 16); |
|
|
dest.B = (byte)MathF.Round(vector.Z); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
/// <inheritdoc />
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public void ToRgba32(ref Rgba32 dest) |
|
|
public void ToRgba32(ref Rgba32 dest) |
|
|
{ |
|
|
{ |
|
|
Vector4 vector = this.ToVector4() * 255F; |
|
|
// Taken from libpng pngtran.c line: 2419
|
|
|
dest.R = (byte)MathF.Round(vector.X); |
|
|
dest.R = (byte)(((this.R * 255) + 32895) >> 16); |
|
|
dest.G = (byte)MathF.Round(vector.Y); |
|
|
dest.G = (byte)(((this.G * 255) + 32895) >> 16); |
|
|
dest.B = (byte)MathF.Round(vector.Z); |
|
|
dest.B = (byte)(((this.B * 255) + 32895) >> 16); |
|
|
dest.A = (byte)MathF.Round(vector.W); |
|
|
dest.A = (byte)(((this.A * 255) + 32895) >> 16); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
/// <inheritdoc/>
|
|
|
@ -250,32 +249,29 @@ namespace SixLabors.ImageSharp.PixelFormats |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public void ToArgb32(ref Argb32 dest) |
|
|
public void ToArgb32(ref Argb32 dest) |
|
|
{ |
|
|
{ |
|
|
Vector4 vector = this.ToVector4() * 255F; |
|
|
dest.R = (byte)(((this.R * 255) + 32895) >> 16); |
|
|
dest.R = (byte)MathF.Round(vector.X); |
|
|
dest.G = (byte)(((this.G * 255) + 32895) >> 16); |
|
|
dest.G = (byte)MathF.Round(vector.Y); |
|
|
dest.B = (byte)(((this.B * 255) + 32895) >> 16); |
|
|
dest.B = (byte)MathF.Round(vector.Z); |
|
|
dest.A = (byte)(((this.A * 255) + 32895) >> 16); |
|
|
dest.A = (byte)MathF.Round(vector.W); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
/// <inheritdoc />
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public void ToBgr24(ref Bgr24 dest) |
|
|
public void ToBgr24(ref Bgr24 dest) |
|
|
{ |
|
|
{ |
|
|
Vector4 vector = this.ToVector4() * 255F; |
|
|
dest.R = (byte)(((this.R * 255) + 32895) >> 16); |
|
|
dest.R = (byte)MathF.Round(vector.X); |
|
|
dest.G = (byte)(((this.G * 255) + 32895) >> 16); |
|
|
dest.G = (byte)MathF.Round(vector.Y); |
|
|
dest.B = (byte)(((this.B * 255) + 32895) >> 16); |
|
|
dest.B = (byte)MathF.Round(vector.Z); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
/// <inheritdoc />
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
public void ToBgra32(ref Bgra32 dest) |
|
|
public void ToBgra32(ref Bgra32 dest) |
|
|
{ |
|
|
{ |
|
|
Vector4 vector = this.ToVector4() * 255F; |
|
|
dest.R = (byte)(((this.R * 255) + 32895) >> 16); |
|
|
dest.R = (byte)MathF.Round(vector.X); |
|
|
dest.G = (byte)(((this.G * 255) + 32895) >> 16); |
|
|
dest.G = (byte)MathF.Round(vector.Y); |
|
|
dest.B = (byte)(((this.B * 255) + 32895) >> 16); |
|
|
dest.B = (byte)MathF.Round(vector.Z); |
|
|
dest.A = (byte)(((this.A * 255) + 32895) >> 16); |
|
|
dest.A = (byte)MathF.Round(vector.W); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
/// <inheritdoc />
|
|
|
|