Browse Source

pooling JpegDecoderCore.DecodedBlocks + made Sandbox46 executable

af/merge-core
Anton Firszov 9 years ago
parent
commit
f3471dd36f
  1. 1
      src/ImageSharp.Formats.Jpeg/Components/Block8x8F.cs
  2. 22
      src/ImageSharp.Formats.Jpeg/JpegDecoderCore.cs
  3. 9
      tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj
  4. 24
      tests/ImageSharp.Sandbox46/Program.cs

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

@ -6,6 +6,7 @@
namespace ImageSharp.Formats.Jpg
{
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

22
src/ImageSharp.Formats.Jpeg/JpegDecoderCore.cs

@ -5,6 +5,7 @@
namespace ImageSharp.Formats
{
using System;
using System.Buffers;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
@ -21,6 +22,11 @@ namespace ImageSharp.Formats
/// </summary>
public const int MaxComponents = 4;
/// <summary>
/// The maximum number of quantization tables
/// </summary>
public const int MaxTq = 3;
// Complex value type field + mutable + available to other classes = the field MUST NOT be private :P
#pragma warning disable SA1401 // FieldsMustBePrivate
/// <summary>
@ -35,9 +41,10 @@ namespace ImageSharp.Formats
#pragma warning restore SA401
/// <summary>
/// The maximum number of quantization tables
/// The <see cref="ArrayPool{T}"/> used to pool data in <see cref="DecodedBlocks"/>.
/// Should always clean arrays when returning!
/// </summary>
private const int MaxTq = 3;
private static readonly ArrayPool<Block8x8F> BlockPool = ArrayPool<Block8x8F>.Create();
/// <summary>
/// The App14 marker color-space
@ -406,6 +413,15 @@ namespace ImageSharp.Formats
this.HuffmanTrees[i].Dispose();
}
for (int i = 0; i < this.DecodedBlocks.Length; i++)
{
Block8x8F[] blockArray = this.DecodedBlocks[i];
if (blockArray != null)
{
BlockPool.Return(blockArray, true);
}
}
this.ycbcrImage?.Dispose();
this.Bytes.Dispose();
this.grayImage.ReturnPooled();
@ -1407,7 +1423,7 @@ namespace ImageSharp.Formats
{
int size = this.TotalMCUCount * this.ComponentArray[i].HorizontalFactor
* this.ComponentArray[i].VerticalFactor;
this.DecodedBlocks[i] = new Block8x8F[size];
this.DecodedBlocks[i] = BlockPool.Rent(size);
}
}

9
tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj

@ -6,7 +6,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{96188137-5FA6-4924-AB6E-4EFF79C6E0BB}</ProjectGuid>
<OutputType>Library</OutputType>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ImageSharp</RootNamespace>
<AssemblyName>ImageSharp.Sandbox46</AssemblyName>
@ -34,6 +34,9 @@
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<StartupObject>ImageSharp.Sandbox46.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
@ -199,6 +202,7 @@
<Compile Include="..\ImageSharp.Tests\TestUtilities\TestUtilityExtensions.cs">
<Link>Tests\TestUtilities\TestUtilityExtensions.cs</Link>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
@ -208,6 +212,9 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<Folder Include="Benchmarks\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>

24
tests/ImageSharp.Sandbox46/Program.cs

@ -0,0 +1,24 @@
// <copyright file="Program.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Sandbox46
{
using System;
public class Program
{
/// <summary>
/// The main entry point. Useful for executing benchmarks and performance unit tests manually,
/// when the IDE test runners lack some of the functionality. Eg.: it's not possible to run JetBrains memory profiler for unit tests.
/// </summary>
/// <param name="args">
/// The arguments to pass to the program.
/// </param>
public static void Main(string[] args)
{
Console.WriteLine("Hello.");
}
}
}
Loading…
Cancel
Save