|
|
|
@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Utils |
|
|
|
{ |
|
|
|
rgba.PackedValue = r | (g << 16) | (b << 32) | (a << 48); |
|
|
|
var vec = rgba.ToVector4(); |
|
|
|
return UnPremultiply(vec, color); |
|
|
|
return UnPremultiply(ref vec, color); |
|
|
|
} |
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
@ -85,7 +85,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Utils |
|
|
|
public static TPixel ColorScaleTo24Bit<TPixel>(ulong r, ulong g, ulong b, ulong a, TPixel color) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
var colorVector = new Vector4(r * Scale24Bit, g * Scale24Bit, b * Scale24Bit, a * Scale24Bit); |
|
|
|
Vector4 colorVector = new Vector4(r, g, b, a) * Scale24Bit; |
|
|
|
color.FromVector4(colorVector); |
|
|
|
return color; |
|
|
|
} |
|
|
|
@ -94,8 +94,8 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Utils |
|
|
|
public static TPixel ColorScaleTo24BitPremultiplied<TPixel>(ulong r, ulong g, ulong b, ulong a, TPixel color) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
var colorVector = new Vector4(r * Scale24Bit, g * Scale24Bit, b * Scale24Bit, a * Scale24Bit); |
|
|
|
return UnPremultiply(colorVector, color); |
|
|
|
Vector4 colorVector = new Vector4(r, g, b, a) * Scale24Bit; |
|
|
|
return UnPremultiply(ref colorVector, color); |
|
|
|
} |
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
@ -111,7 +111,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Utils |
|
|
|
public static TPixel ColorScaleTo32Bit<TPixel>(ulong r, ulong g, ulong b, ulong a, TPixel color) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
var colorVector = new Vector4(r * Scale32Bit, g * Scale32Bit, b * Scale32Bit, a * Scale32Bit); |
|
|
|
Vector4 colorVector = new Vector4(r, g, b, a) * Scale32Bit; |
|
|
|
color.FromVector4(colorVector); |
|
|
|
return color; |
|
|
|
} |
|
|
|
@ -120,8 +120,8 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Utils |
|
|
|
public static TPixel ColorScaleTo32BitPremultiplied<TPixel>(ulong r, ulong g, ulong b, ulong a, TPixel color) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
var colorVector = new Vector4(r * Scale32Bit, g * Scale32Bit, b * Scale32Bit, a * Scale32Bit); |
|
|
|
return UnPremultiply(colorVector, color); |
|
|
|
Vector4 colorVector = new Vector4(r, g, b, a) * Scale32Bit; |
|
|
|
return UnPremultiply(ref colorVector, color); |
|
|
|
} |
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
@ -152,22 +152,11 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Utils |
|
|
|
} |
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static void UnPremultiplyRow<TPixel>(Span<Vector4> vectors, Span<TPixel> pixelRow, TPixel color) |
|
|
|
public static TPixel UnPremultiply<TPixel>(ref Vector4 vector, TPixel color) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
for (int x = 0; x < vectors.Length; x++) |
|
|
|
{ |
|
|
|
Vector4 vec = vectors[x]; |
|
|
|
pixelRow[x] = UnPremultiply(vec, color); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static TPixel UnPremultiply<TPixel>(Vector4 vec, TPixel color) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
float invW = 1.0f / vec.W; |
|
|
|
color.FromVector4(new Vector4(vec.X * invW, vec.Y * invW, vec.Z * invW, vec.W)); |
|
|
|
Numerics.UnPremultiply(ref vector); |
|
|
|
color.FromVector4(vector); |
|
|
|
|
|
|
|
return color; |
|
|
|
} |
|
|
|
|