Browse Source

removed CleanPooler

af/merge-core
Anton Firszov 9 years ago
parent
commit
aaac1359b6
  1. 7
      src/ImageSharp/Formats/Jpg/Components/Decoder/JpegPixelArea.cs
  2. 15
      src/ImageSharp/Formats/Jpg/Components/Decoder/YCbCrImage.cs
  3. 30
      src/ImageSharp/Formats/Jpg/Utils/CleanPooler.cs

7
src/ImageSharp/Formats/Jpg/Components/Decoder/JpegPixelArea.cs

@ -4,6 +4,7 @@
// </copyright>
namespace ImageSharp.Formats.Jpg
{
using System.Buffers;
using System.Runtime.CompilerServices;
/// <summary>
@ -75,7 +76,7 @@ namespace ImageSharp.Formats.Jpg
public static JpegPixelArea CreatePooled(int width, int height)
{
int size = width * height;
var pixels = CleanPooler<byte>.RentCleanArray(size);
var pixels = BytePool.Rent(size);
return new JpegPixelArea(pixels, width, 0);
}
@ -89,10 +90,12 @@ namespace ImageSharp.Formats.Jpg
return;
}
CleanPooler<byte>.ReturnArray(this.Pixels);
BytePool.Return(this.Pixels);
this.Pixels = null;
}
private static ArrayPool<byte> BytePool => ArrayPool<byte>.Shared;
/// <summary>
/// Gets the subarea that belongs to the Block8x8 defined by block indices
/// </summary>

15
src/ImageSharp/Formats/Jpg/Components/Decoder/YCbCrImage.cs

@ -5,6 +5,7 @@
namespace ImageSharp.Formats.Jpg
{
using System;
using System.Buffers;
/// <summary>
/// Represents an image made up of three color components (luminance, blue chroma, red chroma)
@ -21,9 +22,9 @@ namespace ImageSharp.Formats.Jpg
{
int cw, ch;
YCbCrSize(width, height, ratio, out cw, out ch);
this.YPixels = CleanPooler<byte>.RentCleanArray(width * height);
this.CbPixels = CleanPooler<byte>.RentCleanArray(cw * ch);
this.CrPixels = CleanPooler<byte>.RentCleanArray(cw * ch);
this.YPixels = BytePool.Rent(width * height);
this.CbPixels = BytePool.Rent(cw * ch);
this.CrPixels = BytePool.Rent(cw * ch);
this.Ratio = ratio;
this.YOffset = 0;
this.COffset = 0;
@ -67,6 +68,8 @@ namespace ImageSharp.Formats.Jpg
YCbCrSubsampleRatio410,
}
private static ArrayPool<byte> BytePool => ArrayPool<byte>.Shared;
/// <summary>
/// Gets an offseted <see cref="JpegPixelArea" /> to the Cb channel
/// </summary>
@ -128,9 +131,9 @@ namespace ImageSharp.Formats.Jpg
/// </summary>
public void Dispose()
{
CleanPooler<byte>.ReturnArray(this.YPixels);
CleanPooler<byte>.ReturnArray(this.CrPixels);
CleanPooler<byte>.ReturnArray(this.CbPixels);
BytePool.Return(this.YPixels);
BytePool.Return(this.CrPixels);
BytePool.Return(this.CbPixels);
}
/// <summary>

30
src/ImageSharp/Formats/Jpg/Utils/CleanPooler.cs

@ -1,30 +0,0 @@
// <copyright file="CleanPooler.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Formats
{
using System.Buffers;
/// <summary>
/// Wraps <see cref="ArrayPool{T}"/> to always provide arrays initialized with default(T)
/// </summary>
/// <typeparam name="T">The element type</typeparam>
internal class CleanPooler<T>
{
private static readonly ArrayPool<T> Pool = ArrayPool<T>.Create();
/// <summary>
/// Rents a clean array
/// </summary>
/// <param name="minimumLength">The minimum array length</param>
/// <returns>A clean array of T</returns>
public static T[] RentCleanArray(int minimumLength) => Pool.Rent(minimumLength);
/// <summary>
/// Retursn array to the pool
/// </summary>
/// <param name="array">The array</param>
public static void ReturnArray(T[] array) => Pool.Return(array, true);
}
}
Loading…
Cancel
Save