Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ internal partial struct Block8x8F : IEquatable<Block8x8F>
/// <returns>The float value at the specified index</returns>
public float this[int idx]
{
[MethodImpl(InliningOptions.ShortMethod)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
GuardBlockIndex(idx);
ref float selfRef = ref Unsafe.As<Block8x8F, float>(ref this);
return Unsafe.Add(ref selfRef, idx);
}

[MethodImpl(InliningOptions.ShortMethod)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
set
{
GuardBlockIndex(idx);
Expand Down
2 changes: 1 addition & 1 deletion src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private set
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl(InliningOptions.ShortMethod)]
public void Update(Buffer2D<T> buffer, int startY)
{
// We don't actually have to assign values outside of the
Expand Down
6 changes: 3 additions & 3 deletions src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ private static void InitQuantizationTable(int i, int scale, ref Block8x8F quant)
/// <param name="bits">The packed bits.</param>
/// <param name="count">The number of bits</param>
/// <param name="emitBufferBase">The reference to the emitBuffer.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl(InliningOptions.ShortMethod)]
private void Emit(uint bits, uint count, ref byte emitBufferBase)
{
count += this.bitCount;
Expand Down Expand Up @@ -356,7 +356,7 @@ private void Emit(uint bits, uint count, ref byte emitBufferBase)
/// <param name="index">The index of the Huffman encoder</param>
/// <param name="value">The value to encode.</param>
/// <param name="emitBufferBase">The reference to the emit buffer.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl(InliningOptions.ShortMethod)]
private void EmitHuff(HuffIndex index, int value, ref byte emitBufferBase)
{
uint x = HuffmanLut.TheHuffmanLut[(int)index].Values[value];
Expand All @@ -370,7 +370,7 @@ private void EmitHuff(HuffIndex index, int value, ref byte emitBufferBase)
/// <param name="runLength">The number of copies to encode.</param>
/// <param name="value">The value to encode.</param>
/// <param name="emitBufferBase">The reference to the emit buffer.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl(InliningOptions.ShortMethod)]
private void EmitHuffRLE(HuffIndex index, int runLength, int value, ref byte emitBufferBase)
{
int a = value;
Expand Down
13 changes: 8 additions & 5 deletions tests/ImageSharp.Benchmarks/Codecs/Jpeg/EncodeJpeg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ public class EncodeJpeg
private Stream bmpStream;
private SDImage bmpDrawing;
private Image<Rgba32> bmpCore;
private MemoryStream destinationStream;

[GlobalSetup]
public void ReadImages()
{
if (this.bmpStream == null)
{
const string TestImage = TestImages.Bmp.NegHeight;
const string TestImage = TestImages.Jpeg.BenchmarkSuite.Jpeg420Exif_MidSizeYCbCr;
this.bmpStream = File.OpenRead(Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, TestImage));
this.bmpCore = Image.Load<Rgba32>(this.bmpStream);
this.bmpCore.Metadata.ExifProfile = null;
this.bmpStream.Position = 0;
this.bmpDrawing = SDImage.FromStream(this.bmpStream);
this.destinationStream = new MemoryStream();
}
}

Expand All @@ -42,15 +45,15 @@ public void Cleanup()
[Benchmark(Baseline = true, Description = "System.Drawing Jpeg")]
public void JpegSystemDrawing()
{
using var stream = new MemoryStream();
this.bmpDrawing.Save(stream, ImageFormat.Jpeg);
this.bmpDrawing.Save(this.destinationStream, ImageFormat.Jpeg);
this.destinationStream.Seek(0, SeekOrigin.Begin);
}

[Benchmark(Description = "ImageSharp Jpeg")]
public void JpegCore()
{
using var stream = new MemoryStream();
this.bmpCore.SaveAsJpeg(stream);
this.bmpCore.SaveAsJpeg(this.destinationStream);
this.destinationStream.Seek(0, SeekOrigin.Begin);
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion tests/ImageSharp.Tests.ProfilingSandbox/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ private class ConsoleOutput : ITestOutputHelper
/// </param>
public static void Main(string[] args)
{
RunJpegEncoderProfilingTests();
// RunJpegColorProfilingTests();
RunDecodeJpegProfilingTests();
// RunDecodeJpegProfilingTests();
// RunToVector4ProfilingTest();
// RunResizeProfilingTest();

Console.ReadLine();
}

private static void RunJpegEncoderProfilingTests()
{
var benchmarks = new JpegProfilingBenchmarks(new ConsoleOutput());
benchmarks.EncodeJpeg_SingleMidSize();
}

private static void RunJpegColorProfilingTests()
{
new JpegColorConverterTests(new ConsoleOutput()).BenchmarkYCbCr(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ private void DecodeJpegBenchmarkImpl(string fileName, IImageDecoder decoder, int
#pragma warning restore SA1515 // Single-line comment should be preceded by blank line
}

[Fact(Skip = ProfilingSetup.SkipProfilingTests)]
public void EncodeJpeg_SingleMidSize()
{
string path = TestFile.GetInputFileFullPath(TestImages.Jpeg.BenchmarkSuite.Jpeg420Exif_MidSizeYCbCr);
using var image = Image.Load(path);
image.Metadata.ExifProfile = null;

using var ms = new MemoryStream();
for (int i = 0; i < 30; i++)
{
image.SaveAsJpeg(ms);
ms.Seek(0, SeekOrigin.Begin);
}
}

// Benchmark, enable manually!
[Theory(Skip = ProfilingSetup.SkipProfilingTests)]
[InlineData(1, 75, JpegSubsample.Ratio420)]
Expand Down