Added a test for incremental codec decodes
This commit is contained in:
Родитель
732a89daf3
Коммит
10b72b3043
|
@ -41,6 +41,59 @@ namespace SkiaSharp.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DecodePartialImage ()
|
||||
{
|
||||
// read the data here, so we can fake a throttle/download
|
||||
var path = Path.Combine (PathToImages, "baboon.png");
|
||||
var fileData = File.ReadAllBytes (path);
|
||||
SKColor[] correctBytes;
|
||||
using (var bitmap = SKBitmap.Decode (path)) {
|
||||
correctBytes = bitmap.Pixels;
|
||||
}
|
||||
|
||||
int offset = 0;
|
||||
int maxCount = 1024 * 4;
|
||||
|
||||
// the "download" stream needs some data
|
||||
var downloadStream = new MemoryStream ();
|
||||
downloadStream.Write (fileData, offset, maxCount);
|
||||
downloadStream.Position -= maxCount;
|
||||
offset += maxCount;
|
||||
|
||||
using (var codec = SKCodec.Create (new SKManagedStream (downloadStream))) {
|
||||
var info = new SKImageInfo (codec.Info.Width, codec.Info.Height);
|
||||
|
||||
// the bitmap to be decoded
|
||||
using (var incremental = new SKBitmap (info)) {
|
||||
|
||||
// start decoding
|
||||
IntPtr length;
|
||||
var pixels = incremental.GetPixels (out length);
|
||||
var result = codec.StartIncrementalDecode (info, pixels, info.RowBytes);
|
||||
|
||||
// make sure the start was successful
|
||||
Assert.AreEqual (SKCodecResult.Success, result);
|
||||
result = SKCodecResult.IncompleteInput;
|
||||
|
||||
while (result == SKCodecResult.IncompleteInput) {
|
||||
// decode the rest
|
||||
int rowsDecoded = 0;
|
||||
result = codec.IncrementalDecode (out rowsDecoded);
|
||||
|
||||
// write some more data to the stream
|
||||
maxCount = Math.Min (maxCount, fileData.Length - offset);
|
||||
downloadStream.Write (fileData, offset, maxCount);
|
||||
downloadStream.Position -= maxCount;
|
||||
offset += maxCount;
|
||||
}
|
||||
|
||||
// compare to original
|
||||
CollectionAssert.AreEqual (correctBytes, incremental.Pixels);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BitmapDecodesCorrectly ()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче