Browse Source

Store only eight bytes per line

pull/1819/head
Brian Popow 5 years ago
parent
commit
835ecead49
  1. 21
      src/ImageSharp/Formats/Webp/Lossy/Vp8Encoding.cs

21
src/ImageSharp/Formats/Webp/Lossy/Vp8Encoding.cs

@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
/// <summary> /// <summary>
/// Methods for encoding a VP8 frame. /// Methods for encoding a VP8 frame.
/// </summary> /// </summary>
internal static class Vp8Encoding internal static unsafe class Vp8Encoding
{ {
private const int KC1 = 20091 + (1 << 16); private const int KC1 = 20091 + (1 << 16);
@ -69,6 +69,8 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
public static readonly Vector128<short> K1 = Vector128.Create((short)20091).AsInt16(); public static readonly Vector128<short> K1 = Vector128.Create((short)20091).AsInt16();
public static readonly Vector128<short> K2 = Vector128.Create((short)-30068).AsInt16(); public static readonly Vector128<short> K2 = Vector128.Create((short)-30068).AsInt16();
public static readonly Vector128<short> Four = Vector128.Create((short)4);
#endif #endif
static Vp8Encoding() static Vp8Encoding()
@ -85,6 +87,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
{ {
#if SUPPORTS_RUNTIME_INTRINSICS #if SUPPORTS_RUNTIME_INTRINSICS
if (Sse2.IsSupported) if (Sse2.IsSupported)
//if (false)
{ {
// This implementation makes use of 16-bit fixed point versions of two // This implementation makes use of 16-bit fixed point versions of two
// multiply constants: // multiply constants:
@ -165,8 +168,7 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
// Horizontal pass and subsequent transpose. // Horizontal pass and subsequent transpose.
// First pass, c and d calculations are longer because of the "trick" multiplications. // First pass, c and d calculations are longer because of the "trick" multiplications.
var four = Vector128.Create((short)4); Vector128<short> dc = Sse2.Add(t0.AsInt16(), Four);
Vector128<short> dc = Sse2.Add(t0.AsInt16(), four);
a = Sse2.Add(dc, t2.AsInt16()); a = Sse2.Add(dc, t2.AsInt16());
b = Sse2.Subtract(dc, t2.AsInt16()); b = Sse2.Subtract(dc, t2.AsInt16());
@ -243,11 +245,14 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossy
if (doTwo) if (doTwo)
{ {
// Store eight bytes/pixels per line. // Store eight bytes/pixels per line.
ref byte outputRef = ref MemoryMarshal.GetReference(dst); // TODO: avoid pinning, if possible.
Unsafe.As<byte, Vector128<byte>>(ref outputRef) = ref0; fixed (byte* dstPtr = dst)
Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref outputRef, WebpConstants.Bps)) = ref1; {
Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref outputRef, WebpConstants.Bps * 2)) = ref2; Sse2.StoreScalar((long*)dstPtr, ref0.AsInt64());
Unsafe.As<byte, Vector128<byte>>(ref Unsafe.Add(ref outputRef, WebpConstants.Bps * 3)) = ref3; Sse2.StoreScalar((long*)(dstPtr + WebpConstants.Bps), ref0.AsInt64());
Sse2.StoreScalar((long*)(dstPtr + (WebpConstants.Bps * 2)), ref0.AsInt64());
Sse2.StoreScalar((long*)(dstPtr + (WebpConstants.Bps * 3)), ref0.AsInt64());
}
} }
else else
{ {

Loading…
Cancel
Save