Added members to decode a particular frame

- binding
 - tests
This commit is contained in:
Matthew Leibowitz 2016-11-26 08:24:25 +02:00
Родитель 59fa0b1205
Коммит 38413b6377
9 изменённых файлов: 102 добавлений и 5 удалений

Просмотреть файл

@ -925,6 +925,12 @@ namespace SkiaSharp
FrameIndex = 0;
HasPriorFrame = false;
}
public SKCodecOptions (int frameIndex, bool hasPriorFrame) {
ZeroInitialized = SKZeroInitialized.No;
Subset = null;
FrameIndex = frameIndex;
HasPriorFrame = hasPriorFrame;
}
public SKZeroInitialized ZeroInitialized { get; set; }
public SKRectI? Subset { get; set; }
public bool HasSubset => Subset != null;
@ -932,6 +938,22 @@ namespace SkiaSharp
public bool HasPriorFrame { get; set; }
}
[StructLayout(LayoutKind.Sequential)]
public struct SKCodecFrameInfo {
private IntPtr requiredFrame;
private IntPtr duration;
public int RequiredFrame {
get { return (int)requiredFrame; }
set { requiredFrame = (IntPtr)value; }
}
public int Duration {
get { return (int)duration; }
set { duration = (IntPtr)value; }
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SKPoint {
private float x, y;
@ -2922,7 +2944,6 @@ typeMask = Mask.Scale | Mask.RectStaysRect
break;
default:
throw new ArgumentOutOfRangeException (nameof (color));
break;
}
}

Просмотреть файл

@ -80,6 +80,19 @@ namespace SkiaSharp
}
}
public int RepetitionCount => SkiaApi.sk_codec_get_repetition_count (Handle);
public int FrameCount => SkiaApi.sk_codec_get_frame_count (Handle);
public SKCodecFrameInfo[] FrameInfo {
get {
var length = SkiaApi.sk_codec_get_frame_count (Handle);
var info = new SKCodecFrameInfo [length];
SkiaApi.sk_codec_get_frame_info (Handle, info);
return info;
}
}
public SKCodecResult GetPixels (out byte[] pixels)
{
return GetPixels (Info, out pixels);
@ -107,6 +120,12 @@ namespace SkiaSharp
}
}
public unsafe SKCodecResult GetPixels (SKImageInfo info, IntPtr pixels, int rowBytes, SKCodecOptions options)
{
var colorTableCount = 0;
return GetPixels (info, pixels, rowBytes, options, IntPtr.Zero, ref colorTableCount);
}
public unsafe SKCodecResult GetPixels (SKImageInfo info, IntPtr pixels, int rowBytes, SKCodecOptions options, IntPtr colorTable, ref int colorTableCount)
{
if (pixels == IntPtr.Zero)
@ -125,6 +144,12 @@ namespace SkiaSharp
return SkiaApi.sk_codec_get_pixels (Handle, ref info, pixels, (IntPtr)rowBytes, ref nativeOptions, colorTable, ref colorTableCount);
}
public SKCodecResult GetPixels (SKImageInfo info, IntPtr pixels, SKCodecOptions options)
{
var colorTableCount = 0;
return GetPixels (info, pixels, options, IntPtr.Zero, ref colorTableCount);
}
public SKCodecResult GetPixels (SKImageInfo info, IntPtr pixels, SKCodecOptions options, IntPtr colorTable, ref int colorTableCount)
{
return GetPixels (info, pixels, info.RowBytes, options, colorTable, ref colorTableCount);

Просмотреть файл

@ -1059,6 +1059,12 @@ namespace SkiaSharp
public extern static SKCodecResult sk_codec_start_incremental_decode(sk_codec_t codec, ref SKImageInfo info, IntPtr pixels, IntPtr rowBytes, IntPtr optionsZero, IntPtr ctableZero, IntPtr ctableCountZero);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static SKCodecResult sk_codec_incremental_decode(sk_codec_t codec, out int rowsDecoded);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static int sk_codec_get_repetition_count(sk_codec_t codec);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static int sk_codec_get_frame_count(sk_codec_t codec);
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
public extern static void sk_codec_get_frame_info(sk_codec_t codec, [Out] SKCodecFrameInfo[] frameInfo);
// Bitmap
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]

2
externals/skia поставляемый

@ -1 +1 @@
Subproject commit 559dead6d57212457b989be1eae6c13ac8d43274
Subproject commit 707ac58f0208b7bc8fb7cc008f4f8003be39b870

Двоичные данные
samples/SkiaSharpSample.Shared/Media/animated-heart.gif Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 15 KiB

Просмотреть файл

@ -24,6 +24,7 @@ namespace SkiaSharpSample
public static Stream NinePatch => Embedded.Load("nine-patch.png");
public static Stream BabyTux => Embedded.Load("baby_tux.webp");
public static Stream LogosSvg => Embedded.Load("logos.svg");
public static Stream AnimatedHeartGif => Embedded.Load("animated-heart.gif");
}
public static class Fonts

Просмотреть файл

@ -59,15 +59,14 @@
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Media\adobe-dng.dng" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Media\baby_tux.webp" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Media\baboon.png" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Media\color-wheel.png" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Media\embedded-font.ttf" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Media\nine-patch.png" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Media\logos.svg" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Media\animated-heart.gif" />
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)Media\content-font.ttf" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Media\logos.svg" />
</ItemGroup>
</Project>

Просмотреть файл

@ -175,6 +175,10 @@
<Link>images\logos.svg</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\..\samples\SkiaSharpSample.Shared\Media\animated-heart.gif">
<Link>images\animated-heart.gif</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -31,6 +31,47 @@ namespace SkiaSharp.Tests
}
}
[Test]
public void GetGifFrames ()
{
const int FrameCount = 16;
var stream = new SKFileStream (Path.Combine (PathToImages, "animated-heart.gif"));
using (var codec = SKCodec.Create (stream)) {
Assert.AreEqual (-1, codec.RepetitionCount);
var frameInfos = codec.FrameInfo;
Assert.AreEqual (FrameCount, frameInfos.Length);
Assert.AreEqual (-1, frameInfos [0].RequiredFrame);
var cachedFrames = new SKBitmap [FrameCount];
var info = new SKImageInfo (codec.Info.Width, codec.Info.Height);
var decode = new Action<SKBitmap, bool, int> ((bm, cached, index) => {
if (cached) {
var requiredFrame = frameInfos [index].RequiredFrame;
if (requiredFrame != -1) {
Assert.IsTrue (cachedFrames [requiredFrame].CopyTo (bm));
}
}
var opts = new SKCodecOptions (index, cached);
var result = codec.GetPixels (info, bm.GetPixels (), opts);
Assert.AreEqual (SKCodecResult.Success, result);
});
for (var i = 0; i < FrameCount; i++) {
var cachedFrame = cachedFrames [i] = new SKBitmap (info);
decode (cachedFrame, true, i);
var uncachedFrame = new SKBitmap (info);
decode (uncachedFrame, false, i);
CollectionAssert.AreEqual (cachedFrame.Bytes, uncachedFrame.Bytes);
}
}
}
[Test]
public void GetEncodedInfo ()
{