Browse Source

Optimize and fix warnings.

pull/1554/head
James Jackson-South 5 years ago
parent
commit
ac3eb80374
  1. 17
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
  2. 11
      src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs
  3. 5
      tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Scale16X16To8X8.cs
  4. 2
      tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs
  5. 2
      tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs

17
src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs

@ -153,10 +153,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// </summary>
[MethodImpl(InliningOptions.ShortMethod)]
public void Clear()
{
// The cheapest way to do this in C#:
this = default;
}
=> this = default; // The cheapest way to do this in C#:
/// <summary>
/// Load raw 32bit floating point data from source.
@ -178,9 +175,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// <param name="source">Source</param>
[MethodImpl(InliningOptions.ShortMethod)]
public static unsafe void LoadFrom(Block8x8F* blockPtr, Span<float> source)
{
blockPtr->LoadFrom(source);
}
=> blockPtr->LoadFrom(source);
/// <summary>
/// Load raw 32bit floating point data from source
@ -234,9 +229,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// <param name="dest">The destination.</param>
[MethodImpl(InliningOptions.ShortMethod)]
public static unsafe void ScaledCopyTo(Block8x8F* blockPtr, Span<float> dest)
{
blockPtr->ScaledCopyTo(dest);
}
=> blockPtr->ScaledCopyTo(dest);
/// <summary>
/// Copy raw 32bit floating point data to dest
@ -437,7 +430,6 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
/// <param name="blockPtr">The block pointer.</param>
/// <param name="qtPtr">The qt pointer.</param>
/// <param name="unzigPtr">Unzig pointer</param>
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void DequantizeBlock(Block8x8F* blockPtr, Block8x8F* qtPtr, byte* unzigPtr)
{
float* b = (float*)blockPtr;
@ -565,7 +557,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
ref Vector256<float> bBase = ref Unsafe.AsRef(Unsafe.As<Vector4, Vector256<float>>(ref b.V0L));
ref Vector256<float> aEnd = ref Unsafe.Add(ref aBase, 8);
while (Unsafe.IsAddressLessThan(ref aBase, ref aEnd))
do
{
Vector256<float> voff = Avx.Multiply(Avx.Min(Avx.Max(vnegOne, aBase), vone), vadd);
Unsafe.Add(ref aBase, 0) = Avx.Add(Avx.Divide(aBase, bBase), voff);
@ -573,6 +565,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
aBase = ref Unsafe.Add(ref aBase, 1);
bBase = ref Unsafe.Add(ref bBase, 1);
}
while (Unsafe.IsAddressLessThan(ref aBase, ref aEnd));
}
else
#endif

11
src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs

@ -78,14 +78,15 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Update(Buffer2D<T> buffer, int startY)
{
int y = startY;
int height = buffer.Height;
// We don't actually have to assign values outside of the
// frame pixel buffer since they are never requested.
for (int i = 0; i < 8 && y < height; i++)
int y = startY;
int yEnd = Math.Min(y + 8, buffer.Height);
int i = 0;
while (y < yEnd)
{
this[i] = buffer.GetRowSpan(y++);
this[i++] = buffer.GetRowSpan(y++);
}
}

5
tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_Scale16X16To8X8.cs

@ -1,3 +1,6 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
using System;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.Formats.Jpeg.Components;
@ -15,7 +18,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Format.Jpeg.Components
{
var random = new Random();
float[] f = new float[8*8];
float[] f = new float[8 * 8];
for (int i = 0; i < f.Length; i++)
{
f[i] = (float)random.NextDouble();

2
tests/ImageSharp.Tests/Image/ImageTests.WrapMemory.cs

@ -375,7 +375,7 @@ namespace SixLabors.ImageSharp.Tests
var array = new Rgba32[size];
var memory = new Memory<Rgba32>(array);
Image.WrapMemory(memory, height, width);
Image.WrapMemory(memory, height, width);
}
private class TestMemoryOwner<T> : IMemoryOwner<T>

2
tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs

@ -263,7 +263,7 @@ namespace SixLabors.ImageSharp.Tests
private static string GetNetCoreVersion()
{
Assembly assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
string[] assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
string[] assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
{

Loading…
Cancel
Save