Browse Source

InBytes->InBytesSqrt, InPixels->InPixelsSqrt

pull/1109/head
Anton Firszov 6 years ago
parent
commit
55c6ae51fe
  1. 3
      src/ImageSharp/ImageSharp.csproj
  2. 6
      tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs
  3. 8
      tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs
  4. 2
      tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs
  5. 4
      tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
  6. 2
      tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs
  7. 16
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs
  8. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs
  9. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  10. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs
  11. 4
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  12. 2
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
  13. 4
      tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs
  14. 2
      tests/ImageSharp.Tests/Formats/Tga/TgaEncoderTests.cs
  15. 3
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj
  16. 12
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

3
src/ImageSharp/ImageSharp.csproj

@ -10,7 +10,8 @@
<VersionPrefix Condition="$(packageversion) != ''">$(packageversion)</VersionPrefix>
<VersionPrefix Condition="$(packageversion) == ''">0.0.1</VersionPrefix>
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1;netstandard2.1;netstandard2.0;netstandard1.3;net472</TargetFrameworks>
<!-- <TargetFrameworks>netcoreapp3.1;netcoreapp2.1;netstandard2.1;netstandard2.0;netstandard1.3;net472</TargetFrameworks>-->
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

6
tests/ImageSharp.Tests/Advanced/AdvancedImageExtensionsTests.cs

@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests.Advanced
public void OwnedMemory_PixelDataIsCorrect<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InPixels(200);
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(200);
using Image<TPixel> image = provider.GetImage();
@ -106,7 +106,7 @@ namespace SixLabors.ImageSharp.Tests.Advanced
public void GetPixelRowMemory_PixelDataIsCorrect<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InPixels(200);
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(200);
using Image<TPixel> image = provider.GetImage();
@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Tests.Advanced
public void GetPixelRowSpan_ShouldReferenceSpanOfMemory<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InPixels(200);
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(200);
using Image<TPixel> image = provider.GetImage();

8
tests/ImageSharp.Tests/Formats/Bmp/BmpDecoderTests.cs

@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
if (!string.IsNullOrEmpty(nonContiguousBuffersStr))
{
provider.LimitAllocatorBufferCapacity().InPixels(100);
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100);
}
using Image<TPixel> image = provider.GetImage(BmpDecoder);
@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
public void BmpDecoder_DegenerateMemoryRequest_ShouldTranslateTo_ImageFormatException<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InPixels(10);
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10);
ImageFormatException ex = Assert.Throws<ImageFormatException>(() => provider.GetImage(BmpDecoder));
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
}
@ -261,7 +261,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
{
if (enforceDiscontiguousBuffers)
{
provider.LimitAllocatorBufferCapacity().InBytes(400);
provider.LimitAllocatorBufferCapacity().InBytesSqrt(400);
}
using (Image<TPixel> image = provider.GetImage(new BmpDecoder { RleSkippedPixelHandling = RleSkippedPixelHandling.FirstColorOfPalette }))
@ -283,7 +283,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
{
if (enforceNonContiguous)
{
provider.LimitAllocatorBufferCapacity().InBytes(400);
provider.LimitAllocatorBufferCapacity().InBytesSqrt(400);
}
using (Image<TPixel> image = provider.GetImage(new BmpDecoder { RleSkippedPixelHandling = RleSkippedPixelHandling.Black }))

2
tests/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs

@ -246,7 +246,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Bmp
public void Encode_WorksWithDiscontiguousBuffers<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel)
where TPixel : struct, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InBytes(100);
provider.LimitAllocatorBufferCapacity().InBytesSqrt(100);
TestBmpEncoderCore(provider, bitsPerPixel);
}

4
tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs

@ -175,7 +175,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
public void GifDecoder_DegenerateMemoryRequest_ShouldTranslateTo_ImageFormatException<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InPixels(10);
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10);
ImageFormatException ex = Assert.Throws<ImageFormatException>(() => provider.GetImage(GifDecoder));
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
}
@ -190,7 +190,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
{
TestImageProvider<TPixel> provider = BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
provider.LimitAllocatorBufferCapacity().InPixels(100);
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100);
using Image<TPixel> image = provider.GetImage(GifDecoder);
image.DebugSave(provider);

2
tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs

@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Gif
{
if (limitAllocationBuffer)
{
provider.LimitAllocatorBufferCapacity().InPixels(100);
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100);
}
using (Image<TPixel> image = provider.GetImage())

16
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs

@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
{
[Theory]
[WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32, false)]
// [WithFile(TestImages.Jpeg.Baseline.Calliphora, PixelTypes.Rgba32, true)]
[WithFile(TestImages.Jpeg.Baseline.Calliphora, PixelTypes.Rgba32, true)]
public void DecodeBaselineJpeg<TPixel>(TestImageProvider<TPixel> provider, bool enforceDiscontiguousBuffers)
where TPixel : struct, IPixel<TPixel>
{
@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
if (!string.IsNullOrEmpty(nonContiguousBuffersStr))
{
provider.LimitAllocatorBufferCapacity().InBytes(200);
provider.LimitAllocatorBufferCapacity().InBytesSqrt(200);
}
using Image<TPixel> image = provider.GetImage(JpegDecoder);
@ -40,11 +40,13 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
}
string providerDump = BasicSerializer.Serialize(provider);
RemoteExecutor.Invoke(
RunTest,
providerDump,
enforceDiscontiguousBuffers ? "Disco" : string.Empty)
.Dispose();
RunTest(providerDump, enforceDiscontiguousBuffers ? "Disco" : string.Empty);
// RemoteExecutor.Invoke(
// RunTest,
// providerDump,
// enforceDiscontiguousBuffers ? "Disco" : string.Empty)
// .Dispose();
}
[Theory]

2
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs

@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
if (!string.IsNullOrEmpty(nonContiguousBuffersStr))
{
provider.LimitAllocatorBufferCapacity().InBytes(200);
provider.LimitAllocatorBufferCapacity().InBytesSqrt(200);
}
using Image<TPixel> image = provider.GetImage(JpegDecoder);

2
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -111,7 +111,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
public void DegenerateMemoryRequest_ShouldTranslateTo_ImageFormatException<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InBytes(10);
provider.LimitAllocatorBufferCapacity().InBytesSqrt(10);
ImageFormatException ex = Assert.Throws<ImageFormatException>(() => provider.GetImage(JpegDecoder));
this.Output.WriteLine(ex.Message);
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);

2
tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs

@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
? ImageComparer.TolerantPercentage(0.1f)
: ImageComparer.TolerantPercentage(5f);
provider.LimitAllocatorBufferCapacity().InBytes(200);
provider.LimitAllocatorBufferCapacity().InBytesSqrt(200);
TestJpegEncoderCore(provider, subsample, 100, comparer);
}

4
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -249,7 +249,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
public void PngDecoder_DegenerateMemoryRequest_ShouldTranslateTo_ImageFormatException<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InPixels(10);
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10);
ImageFormatException ex = Assert.Throws<ImageFormatException>(() => provider.GetImage(PngDecoder));
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
}
@ -264,7 +264,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
{
TestImageProvider<TPixel> provider = BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
provider.LimitAllocatorBufferCapacity().InPixels(100);
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100);
using Image<TPixel> image = provider.GetImage(PngDecoder);
image.DebugSave(provider, testOutputDetails: nonContiguousBuffersStr);

2
tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

@ -410,7 +410,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
public void Encode_WorksWithDiscontiguousBuffers<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InPixels(200);
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(200);
foreach (PngInterlaceMode interlaceMode in InterlaceMode)
{
TestPngEncoderCore(

4
tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs

@ -205,7 +205,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tga
public void TgaDecoder_DegenerateMemoryRequest_ShouldTranslateTo_ImageFormatException<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InPixels(10);
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10);
ImageFormatException ex = Assert.Throws<ImageFormatException>(() => provider.GetImage(TgaDecoder));
Assert.IsType<InvalidMemoryOperationException>(ex.InnerException);
}
@ -220,7 +220,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tga
{
TestImageProvider<TPixel> provider = BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
provider.LimitAllocatorBufferCapacity().InPixels(100);
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100);
using Image<TPixel> image = provider.GetImage(TgaDecoder);
image.DebugSave(provider, testOutputDetails: nonContiguousBuffersStr);

2
tests/ImageSharp.Tests/Formats/Tga/TgaEncoderTests.cs

@ -128,7 +128,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tga
public void Encode_WorksWithDiscontiguousBuffers<TPixel>(TestImageProvider<TPixel> provider, TgaBitsPerPixel bitsPerPixel)
where TPixel : struct, IPixel<TPixel>
{
provider.LimitAllocatorBufferCapacity().InPixels(100);
provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100);
TestTgaEncoderCore(provider, bitsPerPixel, TgaCompression.RunLength);
}

3
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -2,7 +2,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1;net472</TargetFrameworks>
<!-- <TargetFrameworks>netcoreapp3.1;netcoreapp2.1;net472</TargetFrameworks>-->
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<DebugSymbols>True</DebugSymbols>
<AssemblyName>SixLabors.ImageSharp.Tests</AssemblyName>

12
tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

@ -763,19 +763,19 @@ namespace SixLabors.ImageSharp.Tests
}
/// <summary>
/// Set the maximum buffer capacity to (areaDimensionBytes x areaDimensionBytes) bytes.
/// Set the maximum buffer capacity to bytesSqrt^2 bytes.
/// </summary>
public void InBytes(int areaDimensionBytes)
public void InBytesSqrt(int bytesSqrt)
{
this.allocator.BufferCapacityInBytes = areaDimensionBytes * areaDimensionBytes;
this.allocator.BufferCapacityInBytes = bytesSqrt * bytesSqrt;
}
/// <summary>
/// Set the maximum buffer capacity to (areaDimensionPixels x areaDimensionPixels x size of the pixel) bytes.
/// Set the maximum buffer capacity to pixelsSqrt^2 x sizeof(TPixel) bytes.
/// </summary>
public void InPixels(int areaDimensionPixels)
public void InPixelsSqrt(int pixelsSqrt)
{
this.allocator.BufferCapacityInBytes = areaDimensionPixels * areaDimensionPixels * this.pixelSizeInBytes;
this.allocator.BufferCapacityInBytes = pixelsSqrt * pixelsSqrt * this.pixelSizeInBytes;
}
}
}

Loading…
Cancel
Save