Browse Source

Merge branch 'master' into js/multi-bit-png-encoding

af/merge-core
James Jackson-South 7 years ago
committed by GitHub
parent
commit
fe5eb6895d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/ImageSharp/Image.Decode.cs
  2. 33
      tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs

2
src/ImageSharp/Image.Decode.cs

@ -30,7 +30,7 @@ namespace SixLabors.ImageSharp
return null;
}
using (IManagedByteBuffer buffer = config.MemoryAllocator.AllocateManagedByteBuffer(maxHeaderSize))
using (IManagedByteBuffer buffer = config.MemoryAllocator.AllocateManagedByteBuffer(maxHeaderSize, AllocationOptions.Clean))
{
long startPosition = stream.Position;
stream.Read(buffer.Array, 0, maxHeaderSize);

33
tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs

@ -2,17 +2,15 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Moq;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Gif;
using Moq;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
@ -27,7 +25,7 @@ namespace SixLabors.ImageSharp.Tests
{
this.DefaultFormatsManager = Configuration.CreateDefaultInstance().ImageFormatsManager;
this.FormatsManagerEmpty = new ImageFormatManager();
}
}
[Fact]
public void IfAutoloadWellKnownFormatsIsTrueAllFormatsAreLoaded()
@ -114,7 +112,7 @@ namespace SixLabors.ImageSharp.Tests
IImageDecoder found2 = this.FormatsManagerEmpty.FindDecoder(TestFormat.GlobalTestFormat);
Assert.Equal(decoder2, found2);
Assert.NotEqual(found, found2);
}
}
[Fact]
public void AddFormatCallsConfig()
@ -125,5 +123,24 @@ namespace SixLabors.ImageSharp.Tests
provider.Verify(x => x.Configure(config));
}
[Fact]
public void DetectFormatAllocatesCleanBuffer()
{
byte[] jpegImage;
using (var buffer = new MemoryStream())
{
using (var image = new Image<Rgba32>(100, 100))
{
image.SaveAsJpeg(buffer);
jpegImage = buffer.ToArray();
}
}
byte[] invalidImage = { 1, 2, 3 };
Assert.Equal(Image.DetectFormat(jpegImage), JpegFormat.Instance);
Assert.True(Image.DetectFormat(invalidImage) is null);
}
}
}

Loading…
Cancel
Save