From e1c60230c477d5df38e5c81f96ee61ff37086194 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Fri, 17 Jun 2016 22:54:08 +0200 Subject: [PATCH] Updated to the bits based on m52 --- README.md | 9 +- binding/Binding/Binding.projitems | 2 +- binding/Binding/Definitions.cs | 114 ++++++++-- binding/Binding/SKBitmap.cs | 74 ++++--- binding/Binding/SKCanvas.cs | 4 +- binding/Binding/SKCodec.cs | 116 ++++++++++ binding/Binding/SKColorFilter.cs | 6 +- binding/Binding/SKData.cs | 12 +- binding/Binding/SKDocument.cs | 6 +- binding/Binding/SKImage.cs | 6 +- binding/Binding/SKImageDecoder.cs | 198 ------------------ binding/Binding/SKImageFilter.cs | 16 +- binding/Binding/SKMaskFilter.cs | 6 +- binding/Binding/SKObject.cs | 25 +-- binding/Binding/SKPaint.cs | 18 +- binding/Binding/SKPath.cs | 10 +- binding/Binding/SKPicture.cs | 6 +- binding/Binding/SKPictureRecorder.cs | 8 +- binding/Binding/SKShader.cs | 14 +- binding/Binding/SKStream.cs | 12 +- binding/Binding/SKString.cs | 10 +- binding/Binding/SKSurface.cs | 8 +- binding/Binding/SKTypeface.cs | 6 +- binding/Binding/SkiaApi.cs | 78 +++---- depot_tools | 2 +- .../libSkiaSharp_windows/libSkiaSharp.vcxproj | 21 +- .../libSkiaSharp_windows/libSkiaSharp_x64.sln | 56 +++-- .../libSkiaSharp_windows/libSkiaSharp_x86.sln | 65 ++++-- native-builds/src/SkManagedStream.cpp | 2 +- native-builds/src/SkiaKeeper.c | 4 +- samples/SharedDemo/SkiaSharp.Demos.cs | 19 +- samples/Skia.WindowsDesktop.Demo/SkiaView.cs | 2 +- skia | 2 +- .../SkiaSharp.Desktop.Tests.csproj | 47 +++++ tests/Tests/SKCodecTest.cs | 79 +++++++ tests/Tests/SKStringTest.cs | 11 +- tests/Tests/SKSurfaceTest.cs | 6 +- tests/Tests/SKTest.cs | 8 +- tests/Tests/SKTypefaceTest.cs | 4 +- 39 files changed, 617 insertions(+), 475 deletions(-) create mode 100644 binding/Binding/SKCodec.cs delete mode 100644 binding/Binding/SKImageDecoder.cs create mode 100644 tests/Tests/SKCodecTest.cs diff --git a/README.md b/README.md index ae047c1b6..a23c9c581 100644 --- a/README.md +++ b/README.md @@ -77,9 +77,12 @@ There are several targets available: Here are some links to show the differences in our code as compared to Google's. -What version are we on? [**m49**](https://github.com/google/skia/tree/chrome/m49) -Are we up-to-date with Google? [Compare](https://github.com/mono/skia/compare/xamarin-mobile-bindings...google:chrome/m49) -What have we added? [Compare](https://github.com/google/skia/compare/chrome/m49...mono:xamarin-mobile-bindings) +What version are we on? [**m52**](https://github.com/google/skia/tree/chrome/m52) +Are we up-to-date with Google? [Compare](https://github.com/mono/skia/compare/xamarin-mobile-bindings...google:chrome/m52) +What have we added? [Compare](https://github.com/google/skia/compare/chrome/m52...mono:xamarin-mobile-bindings) + +WIP: https://github.com/mono/skia/compare/update-google-skia...google:chrome/m52 +Diff: https://github.com/google/skia/compare/chrome/m52...mono:update-google-skia ## Where is Windows Phone 8 / Store 8 diff --git a/binding/Binding/Binding.projitems b/binding/Binding/Binding.projitems index 9076bd842..6f1c338bd 100644 --- a/binding/Binding/Binding.projitems +++ b/binding/Binding/Binding.projitems @@ -31,7 +31,7 @@ - + diff --git a/binding/Binding/Definitions.cs b/binding/Binding/Definitions.cs index ff83349ab..bda8d63b8 100644 --- a/binding/Binding/Definitions.cs +++ b/binding/Binding/Definitions.cs @@ -44,18 +44,29 @@ using System.Globalization; namespace SkiaSharp { - public enum SKImageDecoderResult { - Failure = 0, - PartialSuccess = 1, - Success = 2 + public enum SKCodecResult { + Success, + IncompleteInput, + InvalidConversion, + InvalidScale, + InvalidParameters, + InvalidInput, + CouldNotRewind, + Unimplemented, } - public enum SKImageDecoderMode { - DecodeBounds, - DecodePixels + public enum SKCodecOrigin { + TopLeft = 1, + TopRight = 2, + BottomRight = 3, + BottomLeft = 4, + LeftTop = 5, + RightTop = 6, + RightBottom = 7, + LeftBottom = 8, } - public enum SKImageDecoderFormat { + public enum SKEncodedFormat { Unknown, Bmp, Gif, @@ -67,6 +78,7 @@ namespace SkiaSharp Pkm, Ktx, Astc, + Dng, } public partial struct SKColor { @@ -143,11 +155,14 @@ namespace SkiaSharp public enum SKColorType { Unknown, - Rgba_8888, - Bgra_8888, - Alpha_8, - Rgb_565, - N_32 + Alpha8, + Rgb565, + Argb4444, + Rgba8888, + Bgra8888, + Index8, + Gray8, + RgbaF16 } public enum SKColorProfileType { @@ -156,6 +171,7 @@ namespace SkiaSharp } public enum SKAlphaType { + Unknown, Opaque, Premul, Unpremul @@ -308,11 +324,43 @@ namespace SkiaSharp [StructLayout(LayoutKind.Sequential)] public struct SKImageInfo { public static SKImageInfo Empty; + public static SKColorType PlatformColorType; + + static SKImageInfo () + { + var isUnix = Environment.OSVersion.Platform == PlatformID.MacOSX || Environment.OSVersion.Platform == PlatformID.Unix; + if (isUnix) { + // Unix depends on the CPU endianess, but we use RGBA + PlatformColorType = SKColorType.Rgba8888; + } else { + // Windows is always BGRA + PlatformColorType = SKColorType.Bgra8888; + } + } public int Width; public int Height; public SKColorType ColorType; public SKAlphaType AlphaType; + public SKColorProfileType ColorProfileType; + + public SKImageInfo (int width, int height) + { + this.Width = width; + this.Height = height; + this.ColorType = PlatformColorType; + this.AlphaType = SKAlphaType.Premul; + this.ColorProfileType = SKColorProfileType.Linear; + } + + public SKImageInfo (int width, int height, SKColorType colorType) + { + this.Width = width; + this.Height = height; + this.ColorType = colorType; + this.AlphaType = SKAlphaType.Premul; + this.ColorProfileType = SKColorProfileType.Linear; + } public SKImageInfo (int width, int height, SKColorType colorType, SKAlphaType alphaType) { @@ -320,6 +368,16 @@ namespace SkiaSharp this.Height = height; this.ColorType = colorType; this.AlphaType = alphaType; + this.ColorProfileType = SKColorProfileType.Linear; + } + + public SKImageInfo (int width, int height, SKColorType colorType, SKAlphaType alphaType, SKColorProfileType colorProfileType) + { + this.Width = width; + this.Height = height; + this.ColorType = colorType; + this.AlphaType = alphaType; + this.ColorProfileType = colorProfileType; } public int BytesPerPixel { @@ -327,19 +385,27 @@ namespace SkiaSharp switch (ColorType) { case SKColorType.Unknown: return 0; - case SKColorType.Alpha_8: + case SKColorType.Alpha8: + case SKColorType.Index8: + case SKColorType.Gray8: return 1; - case SKColorType.Rgb_565: + case SKColorType.Rgb565: + case SKColorType.Argb4444: return 2; - case SKColorType.Bgra_8888: - case SKColorType.Rgba_8888: - case SKColorType.N_32: + case SKColorType.Bgra8888: + case SKColorType.Rgba8888: return 4; + case SKColorType.RgbaF16: + return 8; } throw new ArgumentOutOfRangeException ("ColorType"); } } + public int BytesSize { + get { return Width * Height * BytesPerPixel; } + } + public int RowBytes { get { return Width * BytesPerPixel; } } @@ -366,6 +432,18 @@ namespace SkiaSharp public SKPixelGeometry PixelGeometry; } + public enum SKZeroInitialized { + Yes, + No, + } + + [StructLayout(LayoutKind.Sequential)] + public struct SKCodecOptions { + public SKZeroInitialized ZeroInitialized; + public SKRectI Subset; + public bool HasSubset; + } + [StructLayout(LayoutKind.Sequential)] public struct SKPoint { private float x, y; diff --git a/binding/Binding/SKBitmap.cs b/binding/Binding/SKBitmap.cs index da2d47b53..f5b2a0891 100644 --- a/binding/Binding/SKBitmap.cs +++ b/binding/Binding/SKBitmap.cs @@ -15,13 +15,13 @@ namespace SkiaSharp public class SKBitmap : SKObject { [Preserve] - internal SKBitmap (IntPtr handle) - : base (handle) + internal SKBitmap (IntPtr handle, bool owns) + : base (handle, owns) { } public SKBitmap () - : this (SkiaApi.sk_bitmap_new ()) + : this (SkiaApi.sk_bitmap_new (), true) { if (Handle == IntPtr.Zero) { throw new InvalidOperationException ("Unable to create a new SKBitmap instance."); @@ -29,7 +29,7 @@ namespace SkiaSharp } public SKBitmap (int width, int height, bool isOpaque = false) - : this (width, height, SKColorType.N_32, isOpaque ? SKAlphaType.Opaque : SKAlphaType.Premul) + : this (width, height, SKImageInfo.PlatformColorType, isOpaque ? SKAlphaType.Opaque : SKAlphaType.Premul) { } @@ -53,7 +53,7 @@ namespace SkiaSharp protected override void Dispose (bool disposing) { - if (Handle != IntPtr.Zero) { + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_bitmap_destructor (Handle); } @@ -219,55 +219,65 @@ namespace SkiaSharp set { SkiaApi.sk_bitmap_set_volatile (Handle, value); } } - public static SKImageInfo DecodeBounds (SKStreamRewindable stream, SKColorType pref = SKColorType.Unknown) + public static SKImageInfo DecodeBounds (SKStream stream) { - SKImageInfo info; - SKImageDecoder.DecodeStreamBounds (stream, out info, pref); - return info; + using (var codec = SKCodec.Create (stream)) { + return codec.Info; + } } - public static SKImageInfo DecodeBounds (string filename, SKColorType pref = SKColorType.Unknown) + public static SKImageInfo DecodeBounds (SKData data) { - SKImageInfo info; - SKImageDecoder.DecodeFileBounds (filename, out info, pref); - return info; + using (var codec = SKCodec.Create (data)) { + return codec.Info; + } } - public static SKImageInfo DecodeBounds (byte[] buffer, SKColorType pref = SKColorType.Unknown) + public static SKImageInfo DecodeBounds (string filename) { - SKImageInfo info; - SKImageDecoder.DecodeMemoryBounds (buffer, out info, pref); - return info; + return DecodeBounds (new SKFileStream (filename)); } - public static SKBitmap Decode (SKStreamRewindable stream, SKColorType pref = SKColorType.Unknown) + public static SKImageInfo DecodeBounds (byte[] buffer) { - var bitmap = new SKBitmap (); - if (!SKImageDecoder.DecodeStream (stream, bitmap, pref)) { + return DecodeBounds (new SKMemoryStream (buffer)); + } + + public static SKBitmap Decode (SKCodec codec) + { + var info = codec.Info; + var bitmap = new SKBitmap (info.Width, info.Height, info.ColorType, info.IsOpaque ? SKAlphaType.Opaque : SKAlphaType.Premul); + IntPtr length; + var result = codec.GetPixels (bitmap.Info, bitmap.GetPixels(out length)); + if (result != SKCodecResult.Success && result != SKCodecResult.IncompleteInput) { bitmap.Dispose (); bitmap = null; } return bitmap; } - public static SKBitmap Decode (string filename, SKColorType pref = SKColorType.Unknown) + public static SKBitmap Decode (SKStream stream) { - var bitmap = new SKBitmap (); - if (!SKImageDecoder.DecodeFile (filename, bitmap, pref)) { - bitmap.Dispose(); - bitmap = null; + using (var codec = SKCodec.Create (stream)) { + return Decode (codec); } - return bitmap; } - public static SKBitmap Decode (byte[] buffer, SKColorType pref = SKColorType.Unknown) + public static SKBitmap Decode (SKData data) { - var bitmap = new SKBitmap (); - if (!SKImageDecoder.DecodeMemory (buffer, bitmap, pref)) { - bitmap.Dispose (); - bitmap = null; + using (var codec = SKCodec.Create (data)) { + return Decode (codec); } - return bitmap; + } + + public static SKBitmap Decode (string filename) + { + return Decode (new SKFileStream (filename)); + } + + public static SKBitmap Decode (byte[] buffer) + { + return Decode (new SKMemoryStream (buffer)); } } } diff --git a/binding/Binding/SKCanvas.cs b/binding/Binding/SKCanvas.cs index 5f8d663a6..76aa35e59 100644 --- a/binding/Binding/SKCanvas.cs +++ b/binding/Binding/SKCanvas.cs @@ -14,8 +14,8 @@ namespace SkiaSharp public class SKCanvas : SKObject { [Preserve] - internal SKCanvas (IntPtr handle) - : base (handle) + internal SKCanvas (IntPtr handle, bool owns) + : base (handle, owns) { } diff --git a/binding/Binding/SKCodec.cs b/binding/Binding/SKCodec.cs new file mode 100644 index 000000000..c084be7ed --- /dev/null +++ b/binding/Binding/SKCodec.cs @@ -0,0 +1,116 @@ +// +// Bindings for SKImageDecoder +// +// Author: +// Matthew Leibowitz +// +// Copyright 2016 Xamarin Inc +// + +using System; +using System.Runtime.InteropServices; + +namespace SkiaSharp +{ + public class SKCodec : SKObject + { + [Preserve] + internal SKCodec (IntPtr handle, bool owns) + : base (handle, owns) + { + } + + protected override void Dispose (bool disposing) + { + if (Handle != IntPtr.Zero && OwnsHandle) { + SkiaApi.sk_codec_destroy (Handle); + } + + base.Dispose (disposing); + } + + public static int MinBufferedBytesNeeded { + get { return (int)SkiaApi.sk_codec_min_buffered_bytes_needed (); } + } + + public SKImageInfo Info { + get { + SKImageInfo info; + SkiaApi.sk_codec_get_info (Handle, out info); + return info; + } + } + + public SKCodecOrigin Origin { + get { return SkiaApi.sk_codec_get_origin (Handle); } + } + + public SKEncodedFormat EncodedFormat { + get { return SkiaApi.sk_codec_get_encoded_format (Handle); } + } + + public SKSizeI GetScaledDimensions (float desiredScale) + { + SKSizeI dimensions; + SkiaApi.sk_codec_get_scaled_dimensions (Handle, desiredScale, out dimensions); + return dimensions; + } + + public void GetValidSubset (ref SKRectI desiredSubset) + { + SkiaApi.sk_codec_get_valid_subset (Handle, ref desiredSubset); + } + + public byte[] Pixels { + get { + byte[] pixels = null; + var result = GetPixels (out pixels); + if (result != SKCodecResult.Success && result != SKCodecResult.IncompleteInput) { + throw new Exception (result.ToString ()); + } + return pixels; + } + } + + public SKCodecResult GetPixels (out byte[] pixels) + { + return GetPixels (Info, out pixels); + } + + public SKCodecResult GetPixels (SKImageInfo info, out byte[] pixels) + { + pixels = new byte[info.BytesSize]; + return GetPixels (info, pixels); + } + + public SKCodecResult GetPixels (SKImageInfo info, byte[] pixels) + { + GCHandle handle = default (GCHandle); + try { + handle = GCHandle.Alloc (pixels, GCHandleType.Pinned); + return GetPixels (info, handle.AddrOfPinnedObject ()); + } finally { + if (handle.IsAllocated) { + handle.Free (); + } + } + } + + public SKCodecResult GetPixels (SKImageInfo info, IntPtr pixels) + { + return SkiaApi.sk_codec_get_pixels_using_defaults (Handle, ref info, pixels, (IntPtr)info.RowBytes); + } + + public static SKCodec Create (SKStream stream) + { + var codec = GetObject (SkiaApi.sk_codec_new_from_stream (stream.Handle)); + codec.TakeOwnership (stream); + return codec; + } + + public static SKCodec Create (SKData data) + { + return GetObject (SkiaApi.sk_codec_new_from_data (data.Handle)); + } + } +} diff --git a/binding/Binding/SKColorFilter.cs b/binding/Binding/SKColorFilter.cs index 7b1acc319..7372de6d0 100644 --- a/binding/Binding/SKColorFilter.cs +++ b/binding/Binding/SKColorFilter.cs @@ -24,14 +24,14 @@ namespace SkiaSharp } [Preserve] - internal SKColorFilter(IntPtr handle) - : base (handle) + internal SKColorFilter(IntPtr handle, bool owns) + : base (handle, owns) { } protected override void Dispose(bool disposing) { - if (Handle != IntPtr.Zero) + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_colorfilter_unref(Handle); } diff --git a/binding/Binding/SKData.cs b/binding/Binding/SKData.cs index a67c6b2fb..69e3e42fe 100644 --- a/binding/Binding/SKData.cs +++ b/binding/Binding/SKData.cs @@ -17,7 +17,7 @@ namespace SkiaSharp { protected override void Dispose (bool disposing) { - if (Handle != IntPtr.Zero) { + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_data_unref (Handle); } @@ -25,13 +25,13 @@ namespace SkiaSharp } [Preserve] - internal SKData (IntPtr x) - : base (x) + internal SKData (IntPtr x, bool owns) + : base (x, owns) { } public SKData () - : this (SkiaApi.sk_data_new_empty ()) + : this (SkiaApi.sk_data_new_empty (), true) { if (Handle == IntPtr.Zero) { throw new InvalidOperationException ("Unable to create a new SKData instance."); @@ -39,7 +39,7 @@ namespace SkiaSharp } public SKData (IntPtr bytes, ulong length) - : this (IntPtr.Zero) + : this (IntPtr.Zero, true) { if (Marshal.SizeOf (typeof(IntPtr)) == 4 && length > UInt32.MaxValue) throw new ArgumentException ("length", "The length exceeds the size of pointers"); @@ -50,7 +50,7 @@ namespace SkiaSharp } public SKData (byte[] bytes) - : this (SkiaApi.sk_data_new_with_copy (bytes, (IntPtr) bytes.Length)) + : this (SkiaApi.sk_data_new_with_copy (bytes, (IntPtr) bytes.Length), true) { if (Handle == IntPtr.Zero) { throw new InvalidOperationException ("Unable to copy the SKData instance."); diff --git a/binding/Binding/SKDocument.cs b/binding/Binding/SKDocument.cs index 17cc376d1..4efd909b7 100644 --- a/binding/Binding/SKDocument.cs +++ b/binding/Binding/SKDocument.cs @@ -15,14 +15,14 @@ namespace SkiaSharp public const float DefaultRasterDpi = 72.0f; [Preserve] - internal SKDocument(IntPtr handle) - : base (handle) + internal SKDocument(IntPtr handle, bool owns) + : base (handle, owns) { } protected override void Dispose (bool disposing) { - if (Handle != IntPtr.Zero) { + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_document_unref (Handle); } diff --git a/binding/Binding/SKImage.cs b/binding/Binding/SKImage.cs index 1cf5d68c6..3b953418a 100644 --- a/binding/Binding/SKImage.cs +++ b/binding/Binding/SKImage.cs @@ -26,7 +26,7 @@ namespace SkiaSharp { protected override void Dispose (bool disposing) { - if (Handle != IntPtr.Zero) { + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_image_unref (Handle); } @@ -34,8 +34,8 @@ namespace SkiaSharp } [Preserve] - internal SKImage (IntPtr x) - : base (x) + internal SKImage (IntPtr x, bool owns) + : base (x, owns) { } diff --git a/binding/Binding/SKImageDecoder.cs b/binding/Binding/SKImageDecoder.cs deleted file mode 100644 index fd7ad5ecf..000000000 --- a/binding/Binding/SKImageDecoder.cs +++ /dev/null @@ -1,198 +0,0 @@ -// -// Bindings for SKImageDecoder -// -// Author: -// Matthew Leibowitz -// -// Copyright 2016 Xamarin Inc -// - -using System; - -namespace SkiaSharp -{ - public class SKImageDecoder : SKObject - { - public SKImageDecoder(SKStreamRewindable stream) - : this(SkiaApi.sk_imagedecoder_factory(stream.Handle)) - { - if (Handle == IntPtr.Zero) { - throw new ArgumentException ("Unable to find a decoder for the stream.", "stream"); - } - } - - [Preserve] - internal SKImageDecoder(IntPtr handle) - : base(handle) - { - } - - protected override void Dispose(bool disposing) - { - if (Handle != IntPtr.Zero) - { - SkiaApi.sk_imagedecoder_destructor(Handle); - } - - base.Dispose(disposing); - } - - public SKImageDecoderFormat Format - { - get { return SkiaApi.sk_imagedecoder_get_decoder_format(Handle); } - } - - public string FormatName - { - get { return (string) GetObject (SkiaApi.sk_imagedecoder_get_format_name_from_decoder(Handle)); } - } - - public bool SkipWritingZeros - { - get { return SkiaApi.sk_imagedecoder_get_skip_writing_zeros(Handle); } - set { SkiaApi.sk_imagedecoder_set_skip_writing_zeros(Handle, value); } - } - - public bool DitherImage - { - get { return SkiaApi.sk_imagedecoder_get_dither_image(Handle); } - set { SkiaApi.sk_imagedecoder_set_dither_image(Handle, value); } - } - - public bool PreferQualityOverSpeed - { - get { return SkiaApi.sk_imagedecoder_get_prefer_quality_over_speed(Handle); } - set { SkiaApi.sk_imagedecoder_set_prefer_quality_over_speed(Handle, value); } - } - - public bool RequireUnpremultipliedColors - { - get { return SkiaApi.sk_imagedecoder_get_require_unpremultiplied_colors(Handle); } - set { SkiaApi.sk_imagedecoder_set_require_unpremultiplied_colors(Handle, value); } - } - - public int SampleSize - { - get { return SkiaApi.sk_imagedecoder_get_sample_size(Handle); } - set { SkiaApi.sk_imagedecoder_set_sample_size(Handle, value); } - } - - public bool ShouldCancelDecode - { - get { return SkiaApi.sk_imagedecoder_should_cancel_decode(Handle); } - } - - public void CancelDecode() - { - SkiaApi.sk_imagedecoder_cancel_decode(Handle); - } - - public SKImageDecoderResult Decode(SKStream stream, SKBitmap bitmap, SKColorType pref = SKColorType.Unknown, SKImageDecoderMode mode = SKImageDecoderMode.DecodePixels) - { - return SkiaApi.sk_imagedecoder_decode(Handle, stream.Handle, bitmap.Handle, pref, mode); - } - - public static SKImageDecoderFormat GetFormat(SKStreamRewindable stream) - { - return SkiaApi.sk_imagedecoder_get_stream_format(stream.Handle); - } - - public static string GetFormatName(SKImageDecoderFormat format) - { - return (string) GetObject (SkiaApi.sk_imagedecoder_get_format_name_from_format(format)); - } - - public static bool DecodeStreamBounds(SKStreamRewindable stream, out SKImageInfo info, SKColorType pref = SKColorType.Unknown) - { - SKImageDecoderFormat format = SKImageDecoderFormat.Unknown; - return DecodeStreamBounds(stream, out info, pref, ref format); - } - - public static bool DecodeStreamBounds(SKStreamRewindable stream, out SKImageInfo info, SKColorType pref, ref SKImageDecoderFormat format) - { - using (var bitmap = new SKBitmap()) - { - if (DecodeStream(stream, bitmap, pref, SKImageDecoderMode.DecodePixels, ref format)) - { - info = bitmap.Info; - return true; - } - info = SKImageInfo.Empty; - return false; - } - } - - public static bool DecodeFileBounds(string filename, out SKImageInfo info, SKColorType pref = SKColorType.Unknown) - { - SKImageDecoderFormat format = SKImageDecoderFormat.Unknown; - return DecodeFileBounds(filename, out info, pref, ref format); - } - - public static bool DecodeFileBounds(string filename, out SKImageInfo info, SKColorType pref, ref SKImageDecoderFormat format) - { - using (var bitmap = new SKBitmap()) - { - if (DecodeFile(filename, bitmap, pref, SKImageDecoderMode.DecodePixels, ref format)) - { - info = bitmap.Info; - return true; - } - info = SKImageInfo.Empty; - return false; - } - } - - public static bool DecodeMemoryBounds(byte[] buffer, out SKImageInfo info, SKColorType pref = SKColorType.Unknown) - { - SKImageDecoderFormat format = SKImageDecoderFormat.Unknown; - return DecodeMemoryBounds(buffer, out info, pref, ref format); - } - - public static bool DecodeMemoryBounds(byte[] buffer, out SKImageInfo info, SKColorType pref, ref SKImageDecoderFormat format) - { - using (var bitmap = new SKBitmap()) - { - if (DecodeMemory(buffer, bitmap, pref, SKImageDecoderMode.DecodePixels, ref format)) - { - info = bitmap.Info; - return true; - } - info = SKImageInfo.Empty; - return false; - } - } - - public static bool DecodeStream(SKStreamRewindable stream, SKBitmap bitmap, SKColorType pref = SKColorType.Unknown, SKImageDecoderMode mode = SKImageDecoderMode.DecodePixels) - { - SKImageDecoderFormat format = SKImageDecoderFormat.Unknown; - return DecodeStream(stream, bitmap, pref, mode, ref format); - } - - public static bool DecodeStream(SKStreamRewindable stream, SKBitmap bitmap, SKColorType pref, SKImageDecoderMode mode, ref SKImageDecoderFormat format) - { - return SkiaApi.sk_imagedecoder_decode_stream(stream.Handle, bitmap.Handle, pref, mode, ref format); - } - - public static bool DecodeFile(string filename, SKBitmap bitmap, SKColorType pref = SKColorType.Unknown, SKImageDecoderMode mode = SKImageDecoderMode.DecodePixels) - { - SKImageDecoderFormat format = SKImageDecoderFormat.Unknown; - return DecodeFile(filename, bitmap, pref, mode, ref format); - } - - public static bool DecodeFile(string filename, SKBitmap bitmap, SKColorType pref, SKImageDecoderMode mode, ref SKImageDecoderFormat format) - { - return SkiaApi.sk_imagedecoder_decode_file(filename, bitmap.Handle, pref, mode, ref format); - } - - public static bool DecodeMemory(byte[] buffer, SKBitmap bitmap, SKColorType pref = SKColorType.Unknown, SKImageDecoderMode mode = SKImageDecoderMode.DecodePixels) - { - SKImageDecoderFormat format = SKImageDecoderFormat.Unknown; - return DecodeMemory(buffer, bitmap, pref, mode, ref format); - } - - public static bool DecodeMemory(byte[] buffer, SKBitmap bitmap, SKColorType pref, SKImageDecoderMode mode, ref SKImageDecoderFormat format) - { - return SkiaApi.sk_imagedecoder_decode_memory(buffer, (IntPtr)buffer.Length, bitmap.Handle, pref, mode, ref format); - } - } -} diff --git a/binding/Binding/SKImageFilter.cs b/binding/Binding/SKImageFilter.cs index 59f25cc8e..13939080c 100644 --- a/binding/Binding/SKImageFilter.cs +++ b/binding/Binding/SKImageFilter.cs @@ -13,14 +13,14 @@ namespace SkiaSharp public class SKImageFilter : SKObject { [Preserve] - internal SKImageFilter(IntPtr handle) - : base(handle) + internal SKImageFilter(IntPtr handle, bool owns) + : base(handle, owns) { } protected override void Dispose(bool disposing) { - if (Handle != IntPtr.Zero) + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_imagefilter_unref(Handle); } @@ -172,24 +172,24 @@ namespace SkiaSharp public class CropRect : SKObject { - internal CropRect(IntPtr handle) - : base(handle) + internal CropRect(IntPtr handle, bool owns) + : base(handle, owns) { } public CropRect() - : this(SkiaApi.sk_imagefilter_croprect_new()) + : this(SkiaApi.sk_imagefilter_croprect_new(), true) { } public CropRect(SKRect rect, SKCropRectFlags flags = SKCropRectFlags.HasAll) - : this(SkiaApi.sk_imagefilter_croprect_new_with_rect(ref rect, flags)) + : this(SkiaApi.sk_imagefilter_croprect_new_with_rect(ref rect, flags), true) { } protected override void Dispose(bool disposing) { - if (Handle != IntPtr.Zero) + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_imagefilter_croprect_destructor(Handle); } diff --git a/binding/Binding/SKMaskFilter.cs b/binding/Binding/SKMaskFilter.cs index 2604c811e..70ef59d82 100644 --- a/binding/Binding/SKMaskFilter.cs +++ b/binding/Binding/SKMaskFilter.cs @@ -15,14 +15,14 @@ namespace SkiaSharp private const float BlurSigmaScale = 0.57735f; [Preserve] - internal SKMaskFilter (IntPtr handle) - : base (handle) + internal SKMaskFilter (IntPtr handle, bool owns) + : base (handle, owns) { } protected override void Dispose (bool disposing) { - if (Handle != IntPtr.Zero) { + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_maskfilter_unref (Handle); } diff --git a/binding/Binding/SKObject.cs b/binding/Binding/SKObject.cs index 56c3bd864..724d2c5c2 100644 --- a/binding/Binding/SKObject.cs +++ b/binding/Binding/SKObject.cs @@ -22,13 +22,6 @@ namespace SkiaSharp private readonly List ownedObjects = new List(); private IntPtr handle; - [Preserve] - internal SKObject(IntPtr handle) - { - Handle = handle; - OwnsHandle = false; - } - [Preserve] internal SKObject(IntPtr handle, bool owns) { @@ -71,16 +64,9 @@ namespace SkiaSharp } DeregisterHandle(handle, this); - handle = IntPtr.Zero; - } + handle = IntPtr.Zero;} - internal static TSkiaObject GetObject(IntPtr handle) - where TSkiaObject : SKObject - { - return GetObject(handle, null); - } - - internal static TSkiaObject GetObject(IntPtr handle, bool? owns) + internal static TSkiaObject GetObject(IntPtr handle, bool owns = true) where TSkiaObject : SKObject { if (handle == IntPtr.Zero) @@ -106,13 +92,12 @@ namespace SkiaSharp // TODO: we could probably cache this var type = typeof(TSkiaObject); var constructor = type.GetTypeInfo().DeclaredConstructors.FirstOrDefault(c => - (owns == null && c.GetParameters().Length == 1 && c.GetParameters()[0].ParameterType == typeof(IntPtr)) || - (owns != null && c.GetParameters().Length == 2 && c.GetParameters()[0].ParameterType == typeof(IntPtr) && c.GetParameters()[1].ParameterType == typeof(bool))); + c.GetParameters().Length == 2 && c.GetParameters()[0].ParameterType == typeof(IntPtr) && c.GetParameters()[1].ParameterType == typeof(bool)); if (constructor == null) { - throw new MissingMethodException($"No constructor found for {type.FullName}.ctor(System.IntPtr{(owns==null?"":", System.Boolean")})"); + throw new MissingMethodException($"No constructor found for {type.FullName}.ctor(System.IntPtr, System.Boolean)"); } - return (TSkiaObject)constructor.Invoke(owns == null ? new object[] { handle } : new object[] { handle, owns }); + return (TSkiaObject)constructor.Invoke(new object[] { handle, owns }); } internal static void RegisterHandle(IntPtr handle, SKObject instance) diff --git a/binding/Binding/SKPaint.cs b/binding/Binding/SKPaint.cs index e794a4876..008abe941 100644 --- a/binding/Binding/SKPaint.cs +++ b/binding/Binding/SKPaint.cs @@ -13,13 +13,13 @@ namespace SkiaSharp public class SKPaint : SKObject { [Preserve] - internal SKPaint (IntPtr handle) - : base (handle) + internal SKPaint (IntPtr handle, bool owns) + : base (handle, owns) { } public SKPaint () - : this (SkiaApi.sk_paint_new ()) + : this (SkiaApi.sk_paint_new (), true) { if (Handle == IntPtr.Zero) { throw new InvalidOperationException ("Unable to create a new SKPaint instance."); @@ -28,7 +28,7 @@ namespace SkiaSharp protected override void Dispose (bool disposing) { - if (Handle != IntPtr.Zero) { + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_paint_delete (Handle); } @@ -118,7 +118,7 @@ namespace SkiaSharp public SKShader Shader { get { - return GetObject(SkiaApi.sk_paint_get_shader(Handle)); + return GetObject(SkiaApi.sk_paint_get_shader(Handle), false); } set { SkiaApi.sk_paint_set_shader(Handle, value == null ? IntPtr.Zero : value.Handle); @@ -127,7 +127,7 @@ namespace SkiaSharp public SKMaskFilter MaskFilter { get { - return GetObject(SkiaApi.sk_paint_get_maskfilter(Handle)); + return GetObject(SkiaApi.sk_paint_get_maskfilter(Handle), false); } set { SkiaApi.sk_paint_set_maskfilter (Handle, value == null ? IntPtr.Zero : value.Handle); @@ -136,7 +136,7 @@ namespace SkiaSharp public SKColorFilter ColorFilter { get { - return GetObject(SkiaApi.sk_paint_get_colorfilter(Handle)); + return GetObject(SkiaApi.sk_paint_get_colorfilter(Handle), false); } set { SkiaApi.sk_paint_set_colorfilter (Handle, value == null ? IntPtr.Zero : value.Handle); @@ -145,7 +145,7 @@ namespace SkiaSharp public SKImageFilter ImageFilter { get { - return GetObject(SkiaApi.sk_paint_get_imagefilter(Handle)); + return GetObject(SkiaApi.sk_paint_get_imagefilter(Handle), false); } set { SkiaApi.sk_paint_set_imagefilter(Handle, value == null ? IntPtr.Zero : value.Handle); @@ -175,7 +175,7 @@ namespace SkiaSharp public SKTypeface Typeface { get { - return GetObject (SkiaApi.sk_paint_get_typeface (Handle)); + return GetObject (SkiaApi.sk_paint_get_typeface (Handle), false); } set { SkiaApi.sk_paint_set_typeface (Handle, value == null ? IntPtr.Zero : value.Handle); diff --git a/binding/Binding/SKPath.cs b/binding/Binding/SKPath.cs index cca60b96b..7fefde504 100644 --- a/binding/Binding/SKPath.cs +++ b/binding/Binding/SKPath.cs @@ -13,13 +13,13 @@ namespace SkiaSharp public class SKPath : SKObject { [Preserve] - internal SKPath (IntPtr handle) - : base (handle) + internal SKPath (IntPtr handle, bool owns) + : base (handle, owns) { } public SKPath () - : this (SkiaApi.sk_path_new ()) + : this (SkiaApi.sk_path_new (), true) { if (Handle == IntPtr.Zero) { throw new InvalidOperationException ("Unable to create a new SKPath instance."); @@ -27,7 +27,7 @@ namespace SkiaSharp } public SKPath(SKPath path) - : this (SkiaApi.sk_path_clone(path.Handle)) + : this (SkiaApi.sk_path_clone(path.Handle), true) { if (Handle == IntPtr.Zero) { throw new InvalidOperationException ("Unable to copy the SKPath instance."); @@ -36,7 +36,7 @@ namespace SkiaSharp protected override void Dispose (bool disposing) { - if (Handle != IntPtr.Zero) { + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_path_delete (Handle); } diff --git a/binding/Binding/SKPicture.cs b/binding/Binding/SKPicture.cs index bed9e5a29..d897ab07c 100644 --- a/binding/Binding/SKPicture.cs +++ b/binding/Binding/SKPicture.cs @@ -14,14 +14,14 @@ namespace SkiaSharp public class SKPicture : SKObject { [Preserve] - internal SKPicture (IntPtr h) - : base (h) + internal SKPicture (IntPtr h, bool owns) + : base (h, owns) { } protected override void Dispose (bool disposing) { - if (Handle != IntPtr.Zero) { + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_picture_unref (Handle); } diff --git a/binding/Binding/SKPictureRecorder.cs b/binding/Binding/SKPictureRecorder.cs index 1f1814379..27c93b324 100644 --- a/binding/Binding/SKPictureRecorder.cs +++ b/binding/Binding/SKPictureRecorder.cs @@ -15,7 +15,7 @@ namespace SkiaSharp { protected override void Dispose (bool disposing) { - if (Handle != IntPtr.Zero) { + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_picture_recorder_delete (Handle); } @@ -23,13 +23,13 @@ namespace SkiaSharp } [Preserve] - public SKPictureRecorder (IntPtr handle) - : base (handle) + public SKPictureRecorder (IntPtr handle, bool owns) + : base (handle, owns) { } public SKPictureRecorder () - : this (SkiaApi.sk_picture_recorder_new ()) + : this (SkiaApi.sk_picture_recorder_new (), true) { if (Handle == IntPtr.Zero) { throw new InvalidOperationException ("Unable to create a new SKPictureRecorder instance."); diff --git a/binding/Binding/SKShader.cs b/binding/Binding/SKShader.cs index 4c4433aa6..4f77178ca 100644 --- a/binding/Binding/SKShader.cs +++ b/binding/Binding/SKShader.cs @@ -13,14 +13,14 @@ namespace SkiaSharp public class SKShader : SKObject { [Preserve] - internal SKShader (IntPtr handle) - : base (handle) + internal SKShader (IntPtr handle, bool owns) + : base (handle, owns) { } protected override void Dispose (bool disposing) { - if (Handle != IntPtr.Zero) { + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_shader_unref (Handle); } @@ -117,14 +117,14 @@ namespace SkiaSharp return GetObject(SkiaApi.sk_shader_new_perlin_noise_turbulence(baseFrequencyX, baseFrequencyY, numOctaves, seed, ref tileSize)); } - public static SKShader CreateCompose(SKShader shaderA, SKShader shaderB) + public static SKShader CreateCompose (SKShader shaderA, SKShader shaderB) { - return GetObject(SkiaApi.sk_shader_new_compose(shaderA.Handle, shaderB.Handle)); + return GetObject (SkiaApi.sk_shader_new_compose (shaderA.Handle, shaderB.Handle)); } - public static SKShader CreateCompose(SKShader shaderA, SKShader shaderB, SKXferMode mode) + public static SKShader CreateCompose (SKShader shaderA, SKShader shaderB, SKXferMode mode) { - return GetObject(SkiaApi.sk_shader_new_compose_with_mode(shaderA.Handle, shaderB.Handle, mode)); + return GetObject (SkiaApi.sk_shader_new_compose_with_mode (shaderA.Handle, shaderB.Handle, mode)); } } } diff --git a/binding/Binding/SKStream.cs b/binding/Binding/SKStream.cs index ee8a148d8..f693feda8 100644 --- a/binding/Binding/SKStream.cs +++ b/binding/Binding/SKStream.cs @@ -12,11 +12,6 @@ namespace SkiaSharp { public abstract class SKStream : SKObject { - private SKStream (IntPtr handle) - : base (handle) - { - } - internal SKStream (IntPtr handle, bool owns) : base (handle, owns) { @@ -264,11 +259,6 @@ namespace SkiaSharp public abstract class SKWStream : SKObject { - private SKWStream (IntPtr handle) - : base (handle) - { - } - internal SKWStream (IntPtr handle, bool owns) : base (handle, owns) { @@ -418,7 +408,7 @@ namespace SkiaSharp public SKStreamAsset DetachAsStream () { - return GetObject (SkiaApi.sk_dynamicmemorywstream_detach_as_stream (Handle), true); + return GetObject (SkiaApi.sk_dynamicmemorywstream_detach_as_stream (Handle)); } protected override void Dispose (bool disposing) diff --git a/binding/Binding/SKString.cs b/binding/Binding/SKString.cs index af0984fbb..6618fd50a 100644 --- a/binding/Binding/SKString.cs +++ b/binding/Binding/SKString.cs @@ -14,13 +14,13 @@ namespace SkiaSharp internal class SKString : SKObject { [Preserve] - internal SKString (IntPtr handle) - : base (handle) + internal SKString (IntPtr handle, bool owns) + : base (handle, owns) { } public SKString () - : base (SkiaApi.sk_string_new_empty ()) + : base (SkiaApi.sk_string_new_empty (), true) { if (Handle == IntPtr.Zero) { throw new InvalidOperationException ("Unable to create a new SKString instance."); @@ -28,7 +28,7 @@ namespace SkiaSharp } public SKString (byte [] src, long length) - : base (SkiaApi.sk_string_new_with_copy (src, (IntPtr)length)) + : base (SkiaApi.sk_string_new_with_copy (src, (IntPtr)length), true) { if (Handle == IntPtr.Zero) { throw new InvalidOperationException ("Unable to copy the SKString instance."); @@ -49,7 +49,7 @@ namespace SkiaSharp protected override void Dispose (bool disposing) { - if (Handle != IntPtr.Zero) { + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_string_destructor (Handle); } diff --git a/binding/Binding/SKSurface.cs b/binding/Binding/SKSurface.cs index ad3f43a9d..1949ef19f 100644 --- a/binding/Binding/SKSurface.cs +++ b/binding/Binding/SKSurface.cs @@ -19,8 +19,8 @@ namespace SkiaSharp public static SKSurface Create (int width, int height, SKColorType colorType, SKAlphaType alphaType, IntPtr pixels, int rowBytes, SKSurfaceProps props) => Create (new SKImageInfo (width, height, colorType, alphaType), pixels, rowBytes, props); [Preserve] - internal SKSurface (IntPtr h) - : base (h) + internal SKSurface (IntPtr h, bool owns) + : base (h, owns) { } @@ -46,7 +46,7 @@ namespace SkiaSharp protected override void Dispose (bool disposing) { - if (Handle != IntPtr.Zero) { + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_surface_unref (Handle); } @@ -55,7 +55,7 @@ namespace SkiaSharp public SKCanvas Canvas { get { - return GetObject (SkiaApi.sk_surface_get_canvas (Handle)); + return GetObject (SkiaApi.sk_surface_get_canvas (Handle), false); } } diff --git a/binding/Binding/SKTypeface.cs b/binding/Binding/SKTypeface.cs index 829555f72..cefc6d5ca 100644 --- a/binding/Binding/SKTypeface.cs +++ b/binding/Binding/SKTypeface.cs @@ -14,14 +14,14 @@ namespace SkiaSharp public class SKTypeface : SKObject { [Preserve] - internal SKTypeface (IntPtr handle) - : base (handle) + internal SKTypeface (IntPtr handle, bool owns) + : base (handle, owns) { } protected override void Dispose (bool disposing) { - if (Handle != IntPtr.Zero) { + if (Handle != IntPtr.Zero && OwnsHandle) { SkiaApi.sk_typeface_unref (Handle); } diff --git a/binding/Binding/SkiaApi.cs b/binding/Binding/SkiaApi.cs index c2cbd1b2c..5db4e278b 100755 --- a/binding/Binding/SkiaApi.cs +++ b/binding/Binding/SkiaApi.cs @@ -32,11 +32,12 @@ using sk_wstream_t = System.IntPtr; using sk_wstream_dynamicmemorystream_t = System.IntPtr; using sk_wstream_filestream_t = System.IntPtr; using sk_bitmap_t = System.IntPtr; -using sk_imagedecoder_t = System.IntPtr; +using sk_codec_t = System.IntPtr; using sk_imagefilter_croprect_t = System.IntPtr; using sk_imagefilter_t = System.IntPtr; using sk_colorfilter_t = System.IntPtr; using sk_document_t = System.IntPtr; +using sk_colorspace_t = System.IntPtr; namespace SkiaSharp { @@ -713,13 +714,39 @@ namespace SkiaSharp [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] public extern static void sk_document_abort(sk_document_t document); + // Codec + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static IntPtr sk_codec_min_buffered_bytes_needed(); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static sk_codec_t sk_codec_new_from_stream(sk_stream_t stream); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static sk_codec_t sk_codec_new_from_data(sk_data_t data); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static void sk_codec_destroy(sk_codec_t codec); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static void sk_codec_get_info(sk_codec_t codec, out SKImageInfo info); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static sk_colorspace_t sk_codec_get_color_space(sk_codec_t codec); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static SKCodecOrigin sk_codec_get_origin(sk_codec_t codec); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static void sk_codec_get_scaled_dimensions(sk_codec_t codec, float desiredScale, out SKSizeI dimensions); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static void sk_codec_get_valid_subset(sk_codec_t codec, ref SKRectI desiredSubset); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static SKEncodedFormat sk_codec_get_encoded_format(sk_codec_t codec); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static SKCodecResult sk_codec_get_pixels(sk_codec_t codec, ref SKImageInfo info, IntPtr pixels, IntPtr rowBytes, SKCodecOptions options, [Out] SKColor[] ctable /*256*/, out int ctableCount); + [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] + public extern static SKCodecResult sk_codec_get_pixels_using_defaults(sk_codec_t codec, ref SKImageInfo info, IntPtr pixels, IntPtr rowBytes); + // Bitmap [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] public extern static sk_bitmap_t sk_bitmap_new(); [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] public extern static void sk_bitmap_destructor(sk_bitmap_t b); [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static bool sk_bitmap_get_info(sk_bitmap_t b, out SKImageInfo info); + public extern static void sk_bitmap_get_info(sk_bitmap_t b, out SKImageInfo info); [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] public extern static IntPtr sk_bitmap_get_pixels(sk_bitmap_t b, out IntPtr length); [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] @@ -761,53 +788,6 @@ namespace SkiaSharp [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] public extern static bool sk_bitmap_try_alloc_pixels(sk_bitmap_t cbitmap, ref SKImageInfo requestedInfo, IntPtr rowBytes); - // Image Decoder - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static void sk_imagedecoder_destructor(sk_imagedecoder_t cdecoder); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static SKImageDecoderFormat sk_imagedecoder_get_decoder_format(sk_imagedecoder_t cdecoder); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static SKImageDecoderFormat sk_imagedecoder_get_stream_format(sk_stream_streamrewindable_t cstream); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static sk_string_t sk_imagedecoder_get_format_name_from_format(SKImageDecoderFormat cformat); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static sk_string_t sk_imagedecoder_get_format_name_from_decoder(sk_imagedecoder_t cdecoder); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static bool sk_imagedecoder_get_skip_writing_zeros(sk_imagedecoder_t cdecoder); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static void sk_imagedecoder_set_skip_writing_zeros(sk_imagedecoder_t cdecoder, bool skip); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static bool sk_imagedecoder_get_dither_image(sk_imagedecoder_t cdecoder); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static void sk_imagedecoder_set_dither_image(sk_imagedecoder_t cdecoder, bool dither); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static bool sk_imagedecoder_get_prefer_quality_over_speed(sk_imagedecoder_t cdecoder); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static void sk_imagedecoder_set_prefer_quality_over_speed(sk_imagedecoder_t cdecoder, bool qualityOverSpeed); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static bool sk_imagedecoder_get_require_unpremultiplied_colors(sk_imagedecoder_t cdecoder); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static void sk_imagedecoder_set_require_unpremultiplied_colors(sk_imagedecoder_t cdecoder, bool request); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static int sk_imagedecoder_get_sample_size(sk_imagedecoder_t cdecoder); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static void sk_imagedecoder_set_sample_size(sk_imagedecoder_t cdecoder, int size); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static void sk_imagedecoder_cancel_decode(sk_imagedecoder_t cdecoder); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static bool sk_imagedecoder_should_cancel_decode(sk_imagedecoder_t cdecoder); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static SKImageDecoderResult sk_imagedecoder_decode(sk_imagedecoder_t cdecoder, sk_stream_t cstream, sk_bitmap_t bitmap, SKColorType pref, SKImageDecoderMode mode); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static sk_imagedecoder_t sk_imagedecoder_factory(sk_stream_streamrewindable_t cstream); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static bool sk_imagedecoder_decode_file(string file, sk_bitmap_t bitmap, SKColorType pref, SKImageDecoderMode mode, ref SKImageDecoderFormat format); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static bool sk_imagedecoder_decode_memory(byte[] buffer, IntPtr size, sk_bitmap_t bitmap, SKColorType pref, SKImageDecoderMode mode, ref SKImageDecoderFormat format); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static bool sk_imagedecoder_decode_memory(IntPtr buffer, IntPtr size, sk_bitmap_t bitmap, SKColorType pref, SKImageDecoderMode mode, ref SKImageDecoderFormat format); - [DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static bool sk_imagedecoder_decode_stream(sk_stream_streamrewindable_t cstream, sk_bitmap_t bitmap, SKColorType pref, SKImageDecoderMode mode, ref SKImageDecoderFormat format); } } diff --git a/depot_tools b/depot_tools index 3d3a2f6aa..8dd81ea20 160000 --- a/depot_tools +++ b/depot_tools @@ -1 +1 @@ -Subproject commit 3d3a2f6aa198c1e627704ca240967dc4ea3db617 +Subproject commit 8dd81ea20b3830a816be88d73e61db2097716548 diff --git a/native-builds/libSkiaSharp_windows/libSkiaSharp.vcxproj b/native-builds/libSkiaSharp_windows/libSkiaSharp.vcxproj index a3f56bc7e..5e979a664 100644 --- a/native-builds/libSkiaSharp_windows/libSkiaSharp.vcxproj +++ b/native-builds/libSkiaSharp_windows/libSkiaSharp.vcxproj @@ -178,6 +178,12 @@ {b7760b5e-bfa8-486b-acfd-49e3a6de8e76} + + {3e562996-8671-6cac-3138-dde7dfb70196} + + + {e6ac5ad9-ba72-e396-9af0-5bcedee32a44} + {200809b7-4c62-7592-f47e-bf262809fa50} @@ -205,9 +211,6 @@ {35bbcd7a-909d-957f-ada0-c09939e0916f} - - {95e593ce-01f6-a02e-334e-1a6c34964fa6} - {c984027d-7bfe-3d92-8d87-082486d7334e} @@ -250,9 +253,18 @@ {b8aa38a8-c1f9-7c27-270f-199d0891282c} + + {c580210b-778a-c16c-6ee0-29eac48e75c7} + + + {e94d4110-703a-d378-de0d-1567557a63a4} + {b15878d6-6997-adc9-ac65-516a7f578db2} + + {69919814-af57-8c45-e0db-2112ee2a146a} + {43c5db31-68d1-5452-4bf0-ad0ab84b2e52} @@ -274,9 +286,6 @@ {4c5035c1-74ba-cf3d-79b1-471c205a490d} - - {4844151d-e943-c99d-d340-683a26e22fc7} - diff --git a/native-builds/libSkiaSharp_windows/libSkiaSharp_x64.sln b/native-builds/libSkiaSharp_windows/libSkiaSharp_x64.sln index e924ed187..13a4c8f79 100644 --- a/native-builds/libSkiaSharp_windows/libSkiaSharp_x64.sln +++ b/native-builds/libSkiaSharp_windows/libSkiaSharp_x64.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "core", "..\..\skia\out\gyp\core.vcxproj", "{B7760B5E-BFA8-486B-ACFD-49E3A6DE8E76}" EndProject @@ -60,16 +60,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sfntly", "..\..\skia\out\gy EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "..\..\skia\out\gyp\zlib.vcxproj", "{4C5035C1-74BA-CF3D-79B1-471C205A490D}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib_x86_simd", "..\..\skia\out\gyp\zlib_x86_simd.vcxproj", "{4844151D-E943-C99D-D340-683A26E22FC7}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icuuc", "..\..\skia\out\gyp\icuuc.vcxproj", "{7F3F1A83-26A1-FAF5-C6B1-977E328C1738}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "..\..\skia\out\gyp\libpng.vcxproj", "{244A967D-9EDE-F233-1CFA-A22A1B666A3E}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng_static", "..\..\skia\out\gyp\libpng_static.vcxproj", "{35BBCD7A-909D-957F-ADA0-C09939E0916F}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng_static_neon", "..\..\skia\out\gyp\libpng_static_neon.vcxproj", "{95E593CE-01F6-A02E-334E-1A6C34964FA6}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "codec", "..\..\skia\out\gyp\codec.vcxproj", "{16F70B29-3F1A-5D36-8FD9-E069D7ED5320}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "codec_android", "..\..\skia\out\gyp\codec_android.vcxproj", "{33835BFB-8F8B-4120-2D5C-973A743F30A5}" @@ -78,6 +74,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "giflib", "..\..\skia\out\gy EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "skia_lib", "..\..\skia\out\gyp\skia_lib.vcxproj", "{70A43075-F008-E167-05C8-978BE66FE588}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "piex", "..\..\skia\out\gyp\piex.vcxproj", "{E94D4110-703A-D378-DE0D-1567557A63A4}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "piex-selector", "..\..\skia\out\gyp\piex-selector.vcxproj", "{C580210B-778A-C16C-6EE0-29EAC48E75C7}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dng_sdk", "..\..\skia\out\gyp\dng_sdk.vcxproj", "{E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dng_sdk-selector", "..\..\skia\out\gyp\dng_sdk-selector.vcxproj", "{3E562996-8671-6CAC-3138-DDE7DFB70196}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -254,12 +258,6 @@ Global {4C5035C1-74BA-CF3D-79B1-471C205A490D}.Release|Win32.ActiveCfg = Release|x64 {4C5035C1-74BA-CF3D-79B1-471C205A490D}.Release|x64.ActiveCfg = Release|x64 {4C5035C1-74BA-CF3D-79B1-471C205A490D}.Release|x64.Build.0 = Release|x64 - {4844151D-E943-C99D-D340-683A26E22FC7}.Debug|Win32.ActiveCfg = Debug|x64 - {4844151D-E943-C99D-D340-683A26E22FC7}.Debug|x64.ActiveCfg = Debug|x64 - {4844151D-E943-C99D-D340-683A26E22FC7}.Debug|x64.Build.0 = Debug|x64 - {4844151D-E943-C99D-D340-683A26E22FC7}.Release|Win32.ActiveCfg = Release|x64 - {4844151D-E943-C99D-D340-683A26E22FC7}.Release|x64.ActiveCfg = Release|x64 - {4844151D-E943-C99D-D340-683A26E22FC7}.Release|x64.Build.0 = Release|x64 {7F3F1A83-26A1-FAF5-C6B1-977E328C1738}.Debug|Win32.ActiveCfg = Debug|x64 {7F3F1A83-26A1-FAF5-C6B1-977E328C1738}.Debug|x64.ActiveCfg = Debug|x64 {7F3F1A83-26A1-FAF5-C6B1-977E328C1738}.Debug|x64.Build.0 = Debug|x64 @@ -278,12 +276,6 @@ Global {35BBCD7A-909D-957F-ADA0-C09939E0916F}.Release|Win32.ActiveCfg = Release|x64 {35BBCD7A-909D-957F-ADA0-C09939E0916F}.Release|x64.ActiveCfg = Release|x64 {35BBCD7A-909D-957F-ADA0-C09939E0916F}.Release|x64.Build.0 = Release|x64 - {95E593CE-01F6-A02E-334E-1A6C34964FA6}.Debug|Win32.ActiveCfg = Debug|x64 - {95E593CE-01F6-A02E-334E-1A6C34964FA6}.Debug|x64.ActiveCfg = Debug|x64 - {95E593CE-01F6-A02E-334E-1A6C34964FA6}.Debug|x64.Build.0 = Debug|x64 - {95E593CE-01F6-A02E-334E-1A6C34964FA6}.Release|Win32.ActiveCfg = Release|x64 - {95E593CE-01F6-A02E-334E-1A6C34964FA6}.Release|x64.ActiveCfg = Release|x64 - {95E593CE-01F6-A02E-334E-1A6C34964FA6}.Release|x64.Build.0 = Release|x64 {16F70B29-3F1A-5D36-8FD9-E069D7ED5320}.Debug|Win32.ActiveCfg = Debug|x64 {16F70B29-3F1A-5D36-8FD9-E069D7ED5320}.Debug|x64.ActiveCfg = Debug|x64 {16F70B29-3F1A-5D36-8FD9-E069D7ED5320}.Debug|x64.Build.0 = Debug|x64 @@ -308,6 +300,30 @@ Global {70A43075-F008-E167-05C8-978BE66FE588}.Release|Win32.ActiveCfg = Release|x64 {70A43075-F008-E167-05C8-978BE66FE588}.Release|x64.ActiveCfg = Release|x64 {70A43075-F008-E167-05C8-978BE66FE588}.Release|x64.Build.0 = Release|x64 + {E94D4110-703A-D378-DE0D-1567557A63A4}.Debug|Win32.ActiveCfg = Debug|x64 + {E94D4110-703A-D378-DE0D-1567557A63A4}.Debug|x64.ActiveCfg = Debug|x64 + {E94D4110-703A-D378-DE0D-1567557A63A4}.Debug|x64.Build.0 = Debug|x64 + {E94D4110-703A-D378-DE0D-1567557A63A4}.Release|Win32.ActiveCfg = Release|x64 + {E94D4110-703A-D378-DE0D-1567557A63A4}.Release|x64.ActiveCfg = Release|x64 + {E94D4110-703A-D378-DE0D-1567557A63A4}.Release|x64.Build.0 = Release|x64 + {C580210B-778A-C16C-6EE0-29EAC48E75C7}.Debug|Win32.ActiveCfg = Debug|x64 + {C580210B-778A-C16C-6EE0-29EAC48E75C7}.Debug|x64.ActiveCfg = Debug|x64 + {C580210B-778A-C16C-6EE0-29EAC48E75C7}.Debug|x64.Build.0 = Debug|x64 + {C580210B-778A-C16C-6EE0-29EAC48E75C7}.Release|Win32.ActiveCfg = Release|x64 + {C580210B-778A-C16C-6EE0-29EAC48E75C7}.Release|x64.ActiveCfg = Release|x64 + {C580210B-778A-C16C-6EE0-29EAC48E75C7}.Release|x64.Build.0 = Release|x64 + {E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44}.Debug|Win32.ActiveCfg = Debug|x64 + {E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44}.Debug|x64.ActiveCfg = Debug|x64 + {E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44}.Debug|x64.Build.0 = Debug|x64 + {E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44}.Release|Win32.ActiveCfg = Release|x64 + {E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44}.Release|x64.ActiveCfg = Release|x64 + {E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44}.Release|x64.Build.0 = Release|x64 + {3E562996-8671-6CAC-3138-DDE7DFB70196}.Debug|Win32.ActiveCfg = Debug|x64 + {3E562996-8671-6CAC-3138-DDE7DFB70196}.Debug|x64.ActiveCfg = Debug|x64 + {3E562996-8671-6CAC-3138-DDE7DFB70196}.Debug|x64.Build.0 = Debug|x64 + {3E562996-8671-6CAC-3138-DDE7DFB70196}.Release|Win32.ActiveCfg = Release|x64 + {3E562996-8671-6CAC-3138-DDE7DFB70196}.Release|x64.ActiveCfg = Release|x64 + {3E562996-8671-6CAC-3138-DDE7DFB70196}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -340,14 +356,16 @@ Global {B8AA38A8-C1F9-7C27-270F-199D0891282C} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {C06FB60B-8A24-163D-DA86-4FAD07F1771F} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {4C5035C1-74BA-CF3D-79B1-471C205A490D} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} - {4844151D-E943-C99D-D340-683A26E22FC7} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {7F3F1A83-26A1-FAF5-C6B1-977E328C1738} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {244A967D-9EDE-F233-1CFA-A22A1B666A3E} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {35BBCD7A-909D-957F-ADA0-C09939E0916F} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} - {95E593CE-01F6-A02E-334E-1A6C34964FA6} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {16F70B29-3F1A-5D36-8FD9-E069D7ED5320} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {33835BFB-8F8B-4120-2D5C-973A743F30A5} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {BA21E9D1-3D2F-7622-2E1F-FBF186FF5677} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {70A43075-F008-E167-05C8-978BE66FE588} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} + {E94D4110-703A-D378-DE0D-1567557A63A4} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} + {C580210B-778A-C16C-6EE0-29EAC48E75C7} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} + {E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} + {3E562996-8671-6CAC-3138-DDE7DFB70196} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} EndGlobalSection EndGlobal diff --git a/native-builds/libSkiaSharp_windows/libSkiaSharp_x86.sln b/native-builds/libSkiaSharp_windows/libSkiaSharp_x86.sln index 8429b5d7e..44b082fa1 100644 --- a/native-builds/libSkiaSharp_windows/libSkiaSharp_x86.sln +++ b/native-builds/libSkiaSharp_windows/libSkiaSharp_x86.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "core", "..\..\skia\out\gyp\core.vcxproj", "{B7760B5E-BFA8-486B-ACFD-49E3A6DE8E76}" EndProject @@ -60,16 +60,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sfntly", "..\..\skia\out\gy EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "..\..\skia\out\gyp\zlib.vcxproj", "{4C5035C1-74BA-CF3D-79B1-471C205A490D}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib_x86_simd", "..\..\skia\out\gyp\zlib_x86_simd.vcxproj", "{4844151D-E943-C99D-D340-683A26E22FC7}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "icuuc", "..\..\skia\out\gyp\icuuc.vcxproj", "{7F3F1A83-26A1-FAF5-C6B1-977E328C1738}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "..\..\skia\out\gyp\libpng.vcxproj", "{244A967D-9EDE-F233-1CFA-A22A1B666A3E}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng_static", "..\..\skia\out\gyp\libpng_static.vcxproj", "{35BBCD7A-909D-957F-ADA0-C09939E0916F}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng_static_neon", "..\..\skia\out\gyp\libpng_static_neon.vcxproj", "{95E593CE-01F6-A02E-334E-1A6C34964FA6}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "codec", "..\..\skia\out\gyp\codec.vcxproj", "{16F70B29-3F1A-5D36-8FD9-E069D7ED5320}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "codec_android", "..\..\skia\out\gyp\codec_android.vcxproj", "{33835BFB-8F8B-4120-2D5C-973A743F30A5}" @@ -78,6 +74,16 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "giflib", "..\..\skia\out\gy EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "skia_lib", "..\..\skia\out\gyp\skia_lib.vcxproj", "{70A43075-F008-E167-05C8-978BE66FE588}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "raw_codec", "..\..\skia\out\gyp\raw_codec.vcxproj", "{69919814-AF57-8C45-E0DB-2112EE2A146A}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dng_sdk", "..\..\skia\out\gyp\dng_sdk.vcxproj", "{E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dng_sdk-selector", "..\..\skia\out\gyp\dng_sdk-selector.vcxproj", "{3E562996-8671-6CAC-3138-DDE7DFB70196}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "piex", "..\..\skia\out\gyp\piex.vcxproj", "{E94D4110-703A-D378-DE0D-1567557A63A4}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "piex-selector", "..\..\skia\out\gyp\piex-selector.vcxproj", "{C580210B-778A-C16C-6EE0-29EAC48E75C7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -254,12 +260,6 @@ Global {4C5035C1-74BA-CF3D-79B1-471C205A490D}.Release|Win32.ActiveCfg = Release|Win32 {4C5035C1-74BA-CF3D-79B1-471C205A490D}.Release|Win32.Build.0 = Release|Win32 {4C5035C1-74BA-CF3D-79B1-471C205A490D}.Release|x64.ActiveCfg = Release|Win32 - {4844151D-E943-C99D-D340-683A26E22FC7}.Debug|Win32.ActiveCfg = Debug|Win32 - {4844151D-E943-C99D-D340-683A26E22FC7}.Debug|Win32.Build.0 = Debug|Win32 - {4844151D-E943-C99D-D340-683A26E22FC7}.Debug|x64.ActiveCfg = Debug|Win32 - {4844151D-E943-C99D-D340-683A26E22FC7}.Release|Win32.ActiveCfg = Release|Win32 - {4844151D-E943-C99D-D340-683A26E22FC7}.Release|Win32.Build.0 = Release|Win32 - {4844151D-E943-C99D-D340-683A26E22FC7}.Release|x64.ActiveCfg = Release|Win32 {7F3F1A83-26A1-FAF5-C6B1-977E328C1738}.Debug|Win32.ActiveCfg = Debug|Win32 {7F3F1A83-26A1-FAF5-C6B1-977E328C1738}.Debug|Win32.Build.0 = Debug|Win32 {7F3F1A83-26A1-FAF5-C6B1-977E328C1738}.Debug|x64.ActiveCfg = Debug|Win32 @@ -278,12 +278,6 @@ Global {35BBCD7A-909D-957F-ADA0-C09939E0916F}.Release|Win32.ActiveCfg = Release|Win32 {35BBCD7A-909D-957F-ADA0-C09939E0916F}.Release|x64.ActiveCfg = Release|Win32 {35BBCD7A-909D-957F-ADA0-C09939E0916F}.Release|Win32.Build.0 = Release|Win32 - {95E593CE-01F6-A02E-334E-1A6C34964FA6}.Debug|Win32.ActiveCfg = Debug|Win32 - {95E593CE-01F6-A02E-334E-1A6C34964FA6}.Debug|x64.ActiveCfg = Debug|Win32 - {95E593CE-01F6-A02E-334E-1A6C34964FA6}.Debug|Win32.Build.0 = Debug|Win32 - {95E593CE-01F6-A02E-334E-1A6C34964FA6}.Release|Win32.ActiveCfg = Release|Win32 - {95E593CE-01F6-A02E-334E-1A6C34964FA6}.Release|x64.ActiveCfg = Release|Win32 - {95E593CE-01F6-A02E-334E-1A6C34964FA6}.Release|Win32.Build.0 = Release|Win32 {16F70B29-3F1A-5D36-8FD9-E069D7ED5320}.Debug|Win32.ActiveCfg = Debug|Win32 {16F70B29-3F1A-5D36-8FD9-E069D7ED5320}.Debug|Win32.Build.0 = Debug|Win32 {16F70B29-3F1A-5D36-8FD9-E069D7ED5320}.Debug|x64.ActiveCfg = Debug|Win32 @@ -308,6 +302,36 @@ Global {70A43075-F008-E167-05C8-978BE66FE588}.Release|Win32.ActiveCfg = Release|Win32 {70A43075-F008-E167-05C8-978BE66FE588}.Release|Win32.Build.0 = Release|Win32 {70A43075-F008-E167-05C8-978BE66FE588}.Release|x64.ActiveCfg = Release|Win32 + {69919814-AF57-8C45-E0DB-2112EE2A146A}.Debug|Win32.ActiveCfg = Debug|Win32 + {69919814-AF57-8C45-E0DB-2112EE2A146A}.Debug|Win32.Build.0 = Debug|Win32 + {69919814-AF57-8C45-E0DB-2112EE2A146A}.Debug|x64.ActiveCfg = Debug|Win32 + {69919814-AF57-8C45-E0DB-2112EE2A146A}.Release|Win32.ActiveCfg = Release|Win32 + {69919814-AF57-8C45-E0DB-2112EE2A146A}.Release|Win32.Build.0 = Release|Win32 + {69919814-AF57-8C45-E0DB-2112EE2A146A}.Release|x64.ActiveCfg = Release|Win32 + {E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44}.Debug|Win32.ActiveCfg = Debug|Win32 + {E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44}.Debug|Win32.Build.0 = Debug|Win32 + {E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44}.Debug|x64.ActiveCfg = Debug|Win32 + {E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44}.Release|Win32.ActiveCfg = Release|Win32 + {E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44}.Release|Win32.Build.0 = Release|Win32 + {E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44}.Release|x64.ActiveCfg = Release|Win32 + {3E562996-8671-6CAC-3138-DDE7DFB70196}.Debug|Win32.ActiveCfg = Debug|Win32 + {3E562996-8671-6CAC-3138-DDE7DFB70196}.Debug|Win32.Build.0 = Debug|Win32 + {3E562996-8671-6CAC-3138-DDE7DFB70196}.Debug|x64.ActiveCfg = Debug|Win32 + {3E562996-8671-6CAC-3138-DDE7DFB70196}.Release|Win32.ActiveCfg = Release|Win32 + {3E562996-8671-6CAC-3138-DDE7DFB70196}.Release|Win32.Build.0 = Release|Win32 + {3E562996-8671-6CAC-3138-DDE7DFB70196}.Release|x64.ActiveCfg = Release|Win32 + {E94D4110-703A-D378-DE0D-1567557A63A4}.Debug|Win32.ActiveCfg = Debug|Win32 + {E94D4110-703A-D378-DE0D-1567557A63A4}.Debug|Win32.Build.0 = Debug|Win32 + {E94D4110-703A-D378-DE0D-1567557A63A4}.Debug|x64.ActiveCfg = Debug|Win32 + {E94D4110-703A-D378-DE0D-1567557A63A4}.Release|Win32.ActiveCfg = Release|Win32 + {E94D4110-703A-D378-DE0D-1567557A63A4}.Release|Win32.Build.0 = Release|Win32 + {E94D4110-703A-D378-DE0D-1567557A63A4}.Release|x64.ActiveCfg = Release|Win32 + {C580210B-778A-C16C-6EE0-29EAC48E75C7}.Debug|Win32.ActiveCfg = Debug|Win32 + {C580210B-778A-C16C-6EE0-29EAC48E75C7}.Debug|Win32.Build.0 = Debug|Win32 + {C580210B-778A-C16C-6EE0-29EAC48E75C7}.Debug|x64.ActiveCfg = Debug|Win32 + {C580210B-778A-C16C-6EE0-29EAC48E75C7}.Release|Win32.ActiveCfg = Release|Win32 + {C580210B-778A-C16C-6EE0-29EAC48E75C7}.Release|Win32.Build.0 = Release|Win32 + {C580210B-778A-C16C-6EE0-29EAC48E75C7}.Release|x64.ActiveCfg = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -340,14 +364,17 @@ Global {B8AA38A8-C1F9-7C27-270F-199D0891282C} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {C06FB60B-8A24-163D-DA86-4FAD07F1771F} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {4C5035C1-74BA-CF3D-79B1-471C205A490D} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} - {4844151D-E943-C99D-D340-683A26E22FC7} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {7F3F1A83-26A1-FAF5-C6B1-977E328C1738} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {244A967D-9EDE-F233-1CFA-A22A1B666A3E} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {35BBCD7A-909D-957F-ADA0-C09939E0916F} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} - {95E593CE-01F6-A02E-334E-1A6C34964FA6} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {16F70B29-3F1A-5D36-8FD9-E069D7ED5320} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {33835BFB-8F8B-4120-2D5C-973A743F30A5} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {BA21E9D1-3D2F-7622-2E1F-FBF186FF5677} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} {70A43075-F008-E167-05C8-978BE66FE588} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} + {69919814-AF57-8C45-E0DB-2112EE2A146A} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} + {E6AC5AD9-BA72-E396-9AF0-5BCEDEE32A44} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} + {3E562996-8671-6CAC-3138-DDE7DFB70196} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} + {E94D4110-703A-D378-DE0D-1567557A63A4} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} + {C580210B-778A-C16C-6EE0-29EAC48E75C7} = {38E1A434-8032-4721-8B8A-F4283BB56DAB} EndGlobalSection EndGlobal diff --git a/native-builds/src/SkManagedStream.cpp b/native-builds/src/SkManagedStream.cpp index 733f4cbb0..e8e1d220e 100644 --- a/native-builds/src/SkManagedStream.cpp +++ b/native-builds/src/SkManagedStream.cpp @@ -92,7 +92,7 @@ SkManagedStream* SkManagedStream::duplicate() const { SkManagedStream* SkManagedStream::fork() const { SkAutoTDelete that(fCreateNew(this)); that->seek(getPosition()); - return that.detach(); + return that.release(); } diff --git a/native-builds/src/SkiaKeeper.c b/native-builds/src/SkiaKeeper.c index ad0c61910..6daa05c90 100644 --- a/native-builds/src/SkiaKeeper.c +++ b/native-builds/src/SkiaKeeper.c @@ -22,11 +22,11 @@ // Xamarin Skia #include "xamarin/sk_x_bitmap.h" #include "xamarin/sk_x_canvas.h" +#include "xamarin/sk_x_codec.h" #include "xamarin/sk_x_colorfilter.h" #include "xamarin/sk_x_data.h" #include "xamarin/sk_x_document.h" #include "xamarin/sk_x_image.h" -#include "xamarin/sk_x_imagedecoder.h" #include "xamarin/sk_x_imagefilter.h" #include "xamarin/sk_x_maskfilter.h" #include "xamarin/sk_x_paint.h" @@ -62,7 +62,7 @@ void** KeepSkiaCSymbols () (void*)sk_colorfilter_unref, (void*)sk_data_new_from_file, (void*)sk_image_encode_specific, - (void*)sk_imagedecoder_destructor, + (void*)sk_codec_new_from_stream, (void*)sk_imagefilter_croprect_new, (void*)sk_maskfilter_new_emboss, (void*)sk_paint_is_dither, diff --git a/samples/SharedDemo/SkiaSharp.Demos.cs b/samples/SharedDemo/SkiaSharp.Demos.cs index 03e9bfebc..cea2beac9 100644 --- a/samples/SharedDemo/SkiaSharp.Demos.cs +++ b/samples/SharedDemo/SkiaSharp.Demos.cs @@ -459,32 +459,29 @@ namespace SkiaSharp // load the embedded resource stream using (var resource = assembly.GetManifestResourceStream(imageName)) using (var stream = new SKManagedStream(resource)) - using (var decoder = new SKImageDecoder(stream)) + using (var codec = SKCodec.Create(stream)) using (var paint = new SKPaint()) using (var tf = SKTypeface.FromFamilyName("Arial")) { + var info = codec.Info; + paint.IsAntialias = true; paint.TextSize = 14; paint.Typeface = tf; paint.Color = SKColors.Black; - // read / set decoder settings - decoder.DitherImage = true; - decoder.PreferQualityOverSpeed = true; - decoder.SampleSize = 2; - // decode the image - using (var bitmap = new SKBitmap()) + using (var bitmap = new SKBitmap(info.Width, info.Height, info.ColorType, info.IsOpaque ? SKAlphaType.Opaque : SKAlphaType.Premul)) { - var result = decoder.Decode(stream, bitmap); - if (result != SKImageDecoderResult.Failure) + IntPtr length; + var result = codec.GetPixels(bitmap.Info, bitmap.GetPixels(out length)); + if (result == SKCodecResult.Success || result == SKCodecResult.IncompleteInput) { - var info = bitmap.Info; var x = 25; var y = 25; canvas.DrawBitmap(bitmap, x, y); - x += info.Width + 25; + x += bitmap.Info.Width + 25; y += 14; canvas.DrawText(string.Format("Result: {0}", result), x, y, paint); diff --git a/samples/Skia.WindowsDesktop.Demo/SkiaView.cs b/samples/Skia.WindowsDesktop.Demo/SkiaView.cs index 8b241a45c..c9e1c9561 100644 --- a/samples/Skia.WindowsDesktop.Demo/SkiaView.cs +++ b/samples/Skia.WindowsDesktop.Demo/SkiaView.cs @@ -29,7 +29,7 @@ namespace Skia.WindowsDesktop.Demo using (var bitmap = new Bitmap(width, height, PixelFormat.Format32bppPArgb)) { var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bitmap.PixelFormat); - using (var surface = SKSurface.Create(width, height, SKColorType.N_32, SKAlphaType.Premul, data.Scan0, width * 4)) + using (var surface = SKSurface.Create(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, data.Scan0, width * 4)) { var skcanvas = surface.Canvas; sample.Method(skcanvas, width, height); diff --git a/skia b/skia index f930e7f75..87dc83ed5 160000 --- a/skia +++ b/skia @@ -1 +1 @@ -Subproject commit f930e7f75b71fef58c3f440f9279bc5506fab303 +Subproject commit 87dc83ed53e038dbcf23074ce4798415e254eba6 diff --git a/tests/SkiaSharp.Desktop.Tests/SkiaSharp.Desktop.Tests.csproj b/tests/SkiaSharp.Desktop.Tests/SkiaSharp.Desktop.Tests.csproj index fc7f75ef5..ef49d56f0 100644 --- a/tests/SkiaSharp.Desktop.Tests/SkiaSharp.Desktop.Tests.csproj +++ b/tests/SkiaSharp.Desktop.Tests/SkiaSharp.Desktop.Tests.csproj @@ -81,6 +81,9 @@ + + SKCodecTest.cs + SKStringTest.cs @@ -99,6 +102,50 @@ + + fonts\content-font.ttf + Always + + + fonts\Distortable.ttf + Always + + + fonts\Em.ttf + Always + + + fonts\Funkster.ttf + Always + + + fonts\HangingS.ttf + Always + + + fonts\ReallyBigA.ttf + Always + + + fonts\Roboto2-Regular_NoEmbed.ttf + Always + + + fonts\SpiderSymbol.ttf + Always + + + fonts\test.ttc + Always + + + images\baboon.png + Always + + + images\color-wheel.png + Always + diff --git a/tests/Tests/SKCodecTest.cs b/tests/Tests/SKCodecTest.cs new file mode 100644 index 000000000..2e86986cc --- /dev/null +++ b/tests/Tests/SKCodecTest.cs @@ -0,0 +1,79 @@ +using System; +using System.IO; +using System.Linq; +using NUnit.Framework; + +namespace SkiaSharp.Tests +{ + [TestFixture] + public class SKCodecTest : SKTest + { + [Test] + public void MinBufferedBytesNeededHasAValue () + { + Assert.IsTrue (SKCodec.MinBufferedBytesNeeded > 0); + } + + [Test] + public void CanCreateStreamCodec () + { + var stream = new SKFileStream (Path.Combine (PathToImages, "color-wheel.png")); + using (var codec = SKCodec.Create (stream)) { + Assert.AreEqual (SKEncodedFormat.Png, codec.EncodedFormat); + Assert.AreEqual (128, codec.Info.Width); + Assert.AreEqual (128, codec.Info.Height); + Assert.AreEqual (SKAlphaType.Unpremul, codec.Info.AlphaType); + if (IsUnix) { + Assert.AreEqual (SKColorType.Rgba8888, codec.Info.ColorType); + } else { + Assert.AreEqual (SKColorType.Bgra8888, codec.Info.ColorType); + } + } + } + + [Test] + public void CanGetPixels () + { + var stream = new SKFileStream (Path.Combine (PathToImages, "baboon.png")); + using (var codec = SKCodec.Create (stream)) { + var pixels = codec.Pixels; + Assert.AreEqual (codec.Info.BytesSize, pixels.Length); + } + } + + [Test] + public void BitmapDecodesCorrectly () + { + byte[] codecPixels; + byte[] bitmapPixels; + + using (var codec = SKCodec.Create (new SKFileStream (Path.Combine (PathToImages, "baboon.png")))) { + codecPixels = codec.Pixels; + } + + using (var bitmap = SKBitmap.Decode (Path.Combine (PathToImages, "baboon.png"))) { + bitmapPixels = bitmap.Bytes; + } + + CollectionAssert.AreEqual (codecPixels, bitmapPixels); + } + + [Test] + public void BitmapDecodesCorrectlyWithManagedStream () + { + byte[] codecPixels; + byte[] bitmapPixels; + + var stream = File.OpenRead (Path.Combine(PathToImages, "baboon.png")); + using (var codec = SKCodec.Create (new SKManagedStream (stream))) { + codecPixels = codec.Pixels; + } + + using (var bitmap = SKBitmap.Decode (Path.Combine (PathToImages, "baboon.png"))) { + bitmapPixels = bitmap.Bytes; + } + + CollectionAssert.AreEqual (codecPixels, bitmapPixels); + } + } +} diff --git a/tests/Tests/SKStringTest.cs b/tests/Tests/SKStringTest.cs index 7a4755838..bfd949d96 100644 --- a/tests/Tests/SKStringTest.cs +++ b/tests/Tests/SKStringTest.cs @@ -11,13 +11,10 @@ namespace SkiaSharp.Tests [Test] public void StringIsMarshaledCorrectly () { - var filename = Path.GetTempFileName (); - - bitmap.Save (filename, ImageFormat.Png); - - var filestream = new SKFileStream (filename); - var decoder = new SKImageDecoder (filestream); - string format1 = decoder.FormatName; + using (var typeface = SKTypeface.FromFile (Path.Combine ("fonts", "SpiderSymbol.ttf"))) + { + Assert.AreEqual ("SpiderSymbol", typeface.FamilyName, "Family name must be SpiderSymbol"); + } } } } diff --git a/tests/Tests/SKSurfaceTest.cs b/tests/Tests/SKSurfaceTest.cs index fd4a9b6bc..a71d3e07b 100644 --- a/tests/Tests/SKSurfaceTest.cs +++ b/tests/Tests/SKSurfaceTest.cs @@ -31,8 +31,8 @@ namespace SkiaSharp.Tests { var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bitmap.PixelFormat); - var surface1 = SKSurface.Create(width, height, SKColorType.N_32, SKAlphaType.Premul, data.Scan0, data.Stride); - var surface2 = SKSurface.Create(width, height, SKColorType.N_32, SKAlphaType.Premul, data.Scan0, data.Stride); + var surface1 = SKSurface.Create(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, data.Scan0, data.Stride); + var surface2 = SKSurface.Create(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, data.Scan0, data.Stride); Assert.IsNotNull(surface1); Assert.IsNotNull(surface2); @@ -51,7 +51,7 @@ namespace SkiaSharp.Tests { var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bitmap.PixelFormat); - var surface = SKSurface.Create(width, height, SKColorType.N_32, SKAlphaType.Premul, data.Scan0, data.Stride); + var surface = SKSurface.Create(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, data.Scan0, data.Stride); Assert.IsNotNull(surface); Assert.AreNotEqual(IntPtr.Zero, surface.Handle); diff --git a/tests/Tests/SKTest.cs b/tests/Tests/SKTest.cs index f0e2cfe8f..65737096c 100644 --- a/tests/Tests/SKTest.cs +++ b/tests/Tests/SKTest.cs @@ -8,9 +8,15 @@ namespace SkiaSharp.Tests [TestFixture] public abstract class SKTest { + protected const string PathToFonts = "fonts"; + protected const string PathToImages = "images"; + protected const int width = 100; protected const int height = 100; + protected static bool IsUnix => Environment.OSVersion.Platform == PlatformID.MacOSX || Environment.OSVersion.Platform == PlatformID.Unix; + protected static bool IsWindows => !IsUnix; + protected Bitmap bitmap; [SetUp] @@ -30,7 +36,7 @@ namespace SkiaSharp.Tests { var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bitmap.PixelFormat); - using (var surface = SKSurface.Create(width, height, SKColorType.N_32, SKAlphaType.Premul, data.Scan0, data.Stride)) + using (var surface = SKSurface.Create(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul, data.Scan0, data.Stride)) { draw(surface); } diff --git a/tests/Tests/SKTypefaceTest.cs b/tests/Tests/SKTypefaceTest.cs index dcf83642e..0799d055c 100644 --- a/tests/Tests/SKTypefaceTest.cs +++ b/tests/Tests/SKTypefaceTest.cs @@ -5,10 +5,8 @@ using System.IO; namespace SkiaSharp.Tests { [TestFixture] - public class SKTypefaceTest + public class SKTypefaceTest : SKTest { - const string PathToFonts = @"../../../../../skia/resources/fonts"; - static readonly string[] ExpectedTablesSpiderFont = new string[] { "FFTM", "GDEF", "OS/2", "cmap", "cvt ", "gasp", "glyf", "head", "hhea", "hmtx", "loca", "maxp", "name", "post",